gdb: remove the silent parameter from exit_inferior_1 and cleanup
[binutils-gdb.git] / gdb / corelow.c
1 /* Core dump and executable file functions below target vector, for GDB.
2
3 Copyright (C) 1986-2023 Free Software Foundation, Inc.
4
5 This file is part of GDB.
6
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3 of the License, or
10 (at your option) any later version.
11
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with this program. If not, see <http://www.gnu.org/licenses/>. */
19
20 #include "defs.h"
21 #include "arch-utils.h"
22 #include <signal.h>
23 #include <fcntl.h>
24 #include "frame.h" /* required by inferior.h */
25 #include "inferior.h"
26 #include "infrun.h"
27 #include "symtab.h"
28 #include "command.h"
29 #include "bfd.h"
30 #include "target.h"
31 #include "process-stratum-target.h"
32 #include "gdbcore.h"
33 #include "gdbthread.h"
34 #include "regcache.h"
35 #include "regset.h"
36 #include "symfile.h"
37 #include "exec.h"
38 #include "readline/tilde.h"
39 #include "solib.h"
40 #include "solist.h"
41 #include "filenames.h"
42 #include "progspace.h"
43 #include "objfiles.h"
44 #include "gdb_bfd.h"
45 #include "completer.h"
46 #include "gdbsupport/filestuff.h"
47 #include "build-id.h"
48 #include "gdbsupport/pathstuff.h"
49 #include "gdbsupport/scoped_fd.h"
50 #include "debuginfod-support.h"
51 #include <unordered_map>
52 #include <unordered_set>
53 #include "gdbcmd.h"
54 #include "xml-tdesc.h"
55 #include "memtag.h"
56
57 #ifndef O_LARGEFILE
58 #define O_LARGEFILE 0
59 #endif
60
61 /* The core file target. */
62
63 static const target_info core_target_info = {
64 "core",
65 N_("Local core dump file"),
66 N_("Use a core file as a target.\n\
67 Specify the filename of the core file.")
68 };
69
70 class core_target final : public process_stratum_target
71 {
72 public:
73 core_target ();
74
75 const target_info &info () const override
76 { return core_target_info; }
77
78 void close () override;
79 void detach (inferior *, int) override;
80 void fetch_registers (struct regcache *, int) override;
81
82 enum target_xfer_status xfer_partial (enum target_object object,
83 const char *annex,
84 gdb_byte *readbuf,
85 const gdb_byte *writebuf,
86 ULONGEST offset, ULONGEST len,
87 ULONGEST *xfered_len) override;
88 void files_info () override;
89
90 bool thread_alive (ptid_t ptid) override;
91 const struct target_desc *read_description () override;
92
93 std::string pid_to_str (ptid_t) override;
94
95 const char *thread_name (struct thread_info *) override;
96
97 bool has_all_memory () override { return true; }
98 bool has_memory () override;
99 bool has_stack () override;
100 bool has_registers () override;
101 bool has_execution (inferior *inf) override { return false; }
102
103 bool info_proc (const char *, enum info_proc_what) override;
104
105 bool supports_memory_tagging () override;
106
107 /* Core file implementation of fetch_memtags. Fetch the memory tags from
108 core file notes. */
109 bool fetch_memtags (CORE_ADDR address, size_t len,
110 gdb::byte_vector &tags, int type) override;
111
112 /* A few helpers. */
113
114 /* Getter, see variable definition. */
115 struct gdbarch *core_gdbarch ()
116 {
117 return m_core_gdbarch;
118 }
119
120 /* See definition. */
121 void get_core_register_section (struct regcache *regcache,
122 const struct regset *regset,
123 const char *name,
124 int section_min_size,
125 const char *human_name,
126 bool required);
127
128 /* See definition. */
129 void info_proc_mappings (struct gdbarch *gdbarch);
130
131 private: /* per-core data */
132
133 /* Get rid of the core inferior. */
134 void clear_core ();
135
136 /* The core's section table. Note that these target sections are
137 *not* mapped in the current address spaces' set of target
138 sections --- those should come only from pure executable or
139 shared library bfds. The core bfd sections are an implementation
140 detail of the core target, just like ptrace is for unix child
141 targets. */
142 target_section_table m_core_section_table;
143
144 /* File-backed address space mappings: some core files include
145 information about memory mapped files. */
146 target_section_table m_core_file_mappings;
147
148 /* Unavailable mappings. These correspond to pathnames which either
149 weren't found or could not be opened. Knowing these addresses can
150 still be useful. */
151 std::vector<mem_range> m_core_unavailable_mappings;
152
153 /* Build m_core_file_mappings. Called from the constructor. */
154 void build_file_mappings ();
155
156 /* Helper method for xfer_partial. */
157 enum target_xfer_status xfer_memory_via_mappings (gdb_byte *readbuf,
158 const gdb_byte *writebuf,
159 ULONGEST offset,
160 ULONGEST len,
161 ULONGEST *xfered_len);
162
163 /* FIXME: kettenis/20031023: Eventually this field should
164 disappear. */
165 struct gdbarch *m_core_gdbarch = NULL;
166 };
167
168 core_target::core_target ()
169 {
170 /* Find a first arch based on the BFD. We need the initial gdbarch so
171 we can setup the hooks to find a target description. */
172 m_core_gdbarch = gdbarch_from_bfd (core_bfd);
173
174 /* If the arch is able to read a target description from the core, it
175 could yield a more specific gdbarch. */
176 const struct target_desc *tdesc = read_description ();
177
178 if (tdesc != nullptr)
179 {
180 struct gdbarch_info info;
181 info.abfd = core_bfd;
182 info.target_desc = tdesc;
183 m_core_gdbarch = gdbarch_find_by_info (info);
184 }
185
186 if (!m_core_gdbarch
187 || !gdbarch_iterate_over_regset_sections_p (m_core_gdbarch))
188 error (_("\"%s\": Core file format not supported"),
189 bfd_get_filename (core_bfd));
190
191 /* Find the data section */
192 m_core_section_table = build_section_table (core_bfd);
193
194 build_file_mappings ();
195 }
196
197 /* Construct the target_section_table for file-backed mappings if
198 they exist.
199
200 For each unique path in the note, we'll open a BFD with a bfd
201 target of "binary". This is an unstructured bfd target upon which
202 we'll impose a structure from the mappings in the architecture-specific
203 mappings note. A BFD section is allocated and initialized for each
204 file-backed mapping.
205
206 We take care to not share already open bfds with other parts of
207 GDB; in particular, we don't want to add new sections to existing
208 BFDs. We do, however, ensure that the BFDs that we allocate here
209 will go away (be deallocated) when the core target is detached. */
210
211 void
212 core_target::build_file_mappings ()
213 {
214 std::unordered_map<std::string, struct bfd *> bfd_map;
215 std::unordered_set<std::string> unavailable_paths;
216
217 /* See linux_read_core_file_mappings() in linux-tdep.c for an example
218 read_core_file_mappings method. */
219 gdbarch_read_core_file_mappings (m_core_gdbarch, core_bfd,
220
221 /* After determining the number of mappings, read_core_file_mappings
222 will invoke this lambda. */
223 [&] (ULONGEST)
224 {
225 },
226
227 /* read_core_file_mappings will invoke this lambda for each mapping
228 that it finds. */
229 [&] (int num, ULONGEST start, ULONGEST end, ULONGEST file_ofs,
230 const char *filename, const bfd_build_id *build_id)
231 {
232 /* Architecture-specific read_core_mapping methods are expected to
233 weed out non-file-backed mappings. */
234 gdb_assert (filename != nullptr);
235
236 if (unavailable_paths.find (filename) != unavailable_paths.end ())
237 {
238 /* We have already seen some mapping for FILENAME but failed to
239 find/open the file. There is no point in trying the same
240 thing again so just record that the range [start, end) is
241 unavailable. */
242 m_core_unavailable_mappings.emplace_back (start, end - start);
243 return;
244 }
245
246 struct bfd *bfd = bfd_map[filename];
247 if (bfd == nullptr)
248 {
249 /* Use exec_file_find() to do sysroot expansion. It'll
250 also strip the potential sysroot "target:" prefix. If
251 there is no sysroot, an equivalent (possibly more
252 canonical) pathname will be provided. */
253 gdb::unique_xmalloc_ptr<char> expanded_fname
254 = exec_file_find (filename, NULL);
255
256 if (expanded_fname == nullptr && build_id != nullptr)
257 debuginfod_exec_query (build_id->data, build_id->size,
258 filename, &expanded_fname);
259
260 if (expanded_fname == nullptr)
261 {
262 m_core_unavailable_mappings.emplace_back (start, end - start);
263 unavailable_paths.insert (filename);
264 warning (_("Can't open file %s during file-backed mapping "
265 "note processing"),
266 filename);
267 return;
268 }
269
270 bfd = bfd_openr (expanded_fname.get (), "binary");
271
272 if (bfd == nullptr || !bfd_check_format (bfd, bfd_object))
273 {
274 m_core_unavailable_mappings.emplace_back (start, end - start);
275 unavailable_paths.insert (filename);
276 warning (_("Can't open file %s which was expanded to %s "
277 "during file-backed mapping note processing"),
278 filename, expanded_fname.get ());
279
280 if (bfd != nullptr)
281 bfd_close (bfd);
282 return;
283 }
284 /* Ensure that the bfd will be closed when core_bfd is closed.
285 This can be checked before/after a core file detach via
286 "maint info bfds". */
287 gdb_bfd_record_inclusion (core_bfd, bfd);
288 bfd_map[filename] = bfd;
289 }
290
291 /* Make new BFD section. All sections have the same name,
292 which is permitted by bfd_make_section_anyway(). */
293 asection *sec = bfd_make_section_anyway (bfd, "load");
294 if (sec == nullptr)
295 error (_("Can't make section"));
296 sec->filepos = file_ofs;
297 bfd_set_section_flags (sec, SEC_READONLY | SEC_HAS_CONTENTS);
298 bfd_set_section_size (sec, end - start);
299 bfd_set_section_vma (sec, start);
300 bfd_set_section_lma (sec, start);
301 bfd_set_section_alignment (sec, 2);
302
303 /* Set target_section fields. */
304 m_core_file_mappings.emplace_back (start, end, sec);
305
306 /* If this is a bfd of a shared library, record its soname
307 and build id. */
308 if (build_id != nullptr)
309 {
310 gdb::unique_xmalloc_ptr<char> soname
311 = gdb_bfd_read_elf_soname (bfd->filename);
312 if (soname != nullptr)
313 set_cbfd_soname_build_id (current_program_space->cbfd,
314 soname.get (), build_id);
315 }
316 });
317
318 normalize_mem_ranges (&m_core_unavailable_mappings);
319 }
320
321 /* An arbitrary identifier for the core inferior. */
322 #define CORELOW_PID 1
323
324 void
325 core_target::clear_core ()
326 {
327 if (core_bfd)
328 {
329 switch_to_no_thread (); /* Avoid confusion from thread
330 stuff. */
331 exit_inferior (current_inferior ());
332
333 /* Clear out solib state while the bfd is still open. See
334 comments in clear_solib in solib.c. */
335 clear_solib ();
336
337 current_program_space->cbfd.reset (nullptr);
338 }
339 }
340
341 /* Close the core target. */
342
343 void
344 core_target::close ()
345 {
346 clear_core ();
347
348 /* Core targets are heap-allocated (see core_target_open), so here
349 we delete ourselves. */
350 delete this;
351 }
352
353 /* Look for sections whose names start with `.reg/' so that we can
354 extract the list of threads in a core file. */
355
356 /* If ASECT is a section whose name begins with '.reg/' then extract the
357 lwpid after the '/' and create a new thread in INF.
358
359 If REG_SECT is not nullptr, and the both ASECT and REG_SECT point at the
360 same position in the parent bfd object then switch to the newly created
361 thread, otherwise, the selected thread is left unchanged. */
362
363 static void
364 add_to_thread_list (asection *asect, asection *reg_sect, inferior *inf)
365 {
366 if (!startswith (bfd_section_name (asect), ".reg/"))
367 return;
368
369 int lwpid = atoi (bfd_section_name (asect) + 5);
370 ptid_t ptid (inf->pid, lwpid);
371 thread_info *thr = add_thread (inf->process_target (), ptid);
372
373 /* Warning, Will Robinson, looking at BFD private data! */
374
375 if (reg_sect != NULL
376 && asect->filepos == reg_sect->filepos) /* Did we find .reg? */
377 switch_to_thread (thr); /* Yes, make it current. */
378 }
379
380 /* Issue a message saying we have no core to debug, if FROM_TTY. */
381
382 static void
383 maybe_say_no_core_file_now (int from_tty)
384 {
385 if (from_tty)
386 gdb_printf (_("No core file now.\n"));
387 }
388
389 /* Backward compatibility with old way of specifying core files. */
390
391 void
392 core_file_command (const char *filename, int from_tty)
393 {
394 dont_repeat (); /* Either way, seems bogus. */
395
396 if (filename == NULL)
397 {
398 if (core_bfd != NULL)
399 {
400 target_detach (current_inferior (), from_tty);
401 gdb_assert (core_bfd == NULL);
402 }
403 else
404 maybe_say_no_core_file_now (from_tty);
405 }
406 else
407 core_target_open (filename, from_tty);
408 }
409
410 /* A vmcore file is a core file created by the Linux kernel at the point of
411 a crash. Each thread in the core file represents a real CPU core, and
412 the lwpid for each thread is the pid of the process that was running on
413 that core at the moment of the crash.
414
415 However, not every CPU core will have been running a process, some cores
416 will be idle. For these idle cores the CPU writes an lwpid of 0. And
417 of course, multiple cores might be idle, so there could be multiple
418 threads with an lwpid of 0.
419
420 The problem is GDB doesn't really like threads with an lwpid of 0; GDB
421 presents such a thread as a process rather than a thread. And GDB
422 certainly doesn't like multiple threads having the same lwpid, each time
423 a new thread is seen with the same lwpid the earlier thread (with the
424 same lwpid) will be deleted.
425
426 This function addresses both of these problems by assigning a fake lwpid
427 to any thread with an lwpid of 0.
428
429 GDB finds the lwpid information by looking at the bfd section names
430 which include the lwpid, e.g. .reg/NN where NN is the lwpid. This
431 function looks though all the section names looking for sections named
432 .reg/NN. If any sections are found where NN == 0, then we assign a new
433 unique value of NN. Then, in a second pass, any sections ending /0 are
434 assigned their new number.
435
436 Remember, a core file may contain multiple register sections for
437 different register sets, but the sets are always grouped by thread, so
438 we can figure out which registers should be assigned the same new
439 lwpid. For example, consider a core file containing:
440
441 .reg/0, .reg2/0, .reg/0, .reg2/0
442
443 This represents two threads, each thread contains a .reg and .reg2
444 register set. The .reg represents the start of each thread. After
445 renaming the sections will now look like this:
446
447 .reg/1, .reg2/1, .reg/2, .reg2/2
448
449 After calling this function the rest of the core file handling code can
450 treat this core file just like any other core file. */
451
452 static void
453 rename_vmcore_idle_reg_sections (bfd *abfd, inferior *inf)
454 {
455 /* Map from the bfd section to its lwpid (the /NN number). */
456 std::vector<std::pair<asection *, int>> sections_and_lwpids;
457
458 /* The set of all /NN numbers found. Needed so we can easily find unused
459 numbers in the case that we need to rename some sections. */
460 std::unordered_set<int> all_lwpids;
461
462 /* A count of how many sections called .reg/0 we have found. */
463 unsigned zero_lwpid_count = 0;
464
465 /* Look for all the .reg sections. Record the section object and the
466 lwpid which is extracted from the section name. Spot if any have an
467 lwpid of zero. */
468 for (asection *sect : gdb_bfd_sections (core_bfd))
469 {
470 if (startswith (bfd_section_name (sect), ".reg/"))
471 {
472 int lwpid = atoi (bfd_section_name (sect) + 5);
473 sections_and_lwpids.emplace_back (sect, lwpid);
474 all_lwpids.insert (lwpid);
475 if (lwpid == 0)
476 zero_lwpid_count++;
477 }
478 }
479
480 /* If every ".reg/NN" section has a non-zero lwpid then we don't need to
481 do any renaming. */
482 if (zero_lwpid_count == 0)
483 return;
484
485 /* Assign a new number to any .reg sections with an lwpid of 0. */
486 int new_lwpid = 1;
487 for (auto &sect_and_lwpid : sections_and_lwpids)
488 if (sect_and_lwpid.second == 0)
489 {
490 while (all_lwpids.find (new_lwpid) != all_lwpids.end ())
491 new_lwpid++;
492 sect_and_lwpid.second = new_lwpid;
493 new_lwpid++;
494 }
495
496 /* Now update the names of any sections with an lwpid of 0. This is
497 more than just the .reg sections we originally found. */
498 std::string replacement_lwpid_str;
499 auto iter = sections_and_lwpids.begin ();
500 int replacement_lwpid = 0;
501 for (asection *sect : gdb_bfd_sections (core_bfd))
502 {
503 if (iter != sections_and_lwpids.end () && sect == iter->first)
504 {
505 gdb_assert (startswith (bfd_section_name (sect), ".reg/"));
506
507 int lwpid = atoi (bfd_section_name (sect) + 5);
508 if (lwpid == iter->second)
509 {
510 /* This section was not given a new number. */
511 gdb_assert (lwpid != 0);
512 replacement_lwpid = 0;
513 }
514 else
515 {
516 replacement_lwpid = iter->second;
517 ptid_t ptid (inf->pid, replacement_lwpid);
518 if (!replacement_lwpid_str.empty ())
519 replacement_lwpid_str += ", ";
520 replacement_lwpid_str += target_pid_to_str (ptid);
521 }
522
523 iter++;
524 }
525
526 if (replacement_lwpid != 0)
527 {
528 const char *name = bfd_section_name (sect);
529 size_t len = strlen (name);
530
531 if (strncmp (name + len - 2, "/0", 2) == 0)
532 {
533 /* This section needs a new name. */
534 std::string name_str
535 = string_printf ("%.*s/%d",
536 static_cast<int> (len - 2),
537 name, replacement_lwpid);
538 char *name_buf
539 = static_cast<char *> (bfd_alloc (abfd, name_str.size () + 1));
540 if (name_buf == nullptr)
541 error (_("failed to allocate space for section name '%s'"),
542 name_str.c_str ());
543 memcpy (name_buf, name_str.c_str(), name_str.size () + 1);
544 bfd_rename_section (sect, name_buf);
545 }
546 }
547 }
548
549 if (zero_lwpid_count == 1)
550 warning (_("found thread with pid 0, assigned replacement Target Id: %s"),
551 replacement_lwpid_str.c_str ());
552 else
553 warning (_("found threads with pid 0, assigned replacement Target Ids: %s"),
554 replacement_lwpid_str.c_str ());
555 }
556
557 /* Locate (and load) an executable file (and symbols) given the core file
558 BFD ABFD. */
559
560 static void
561 locate_exec_from_corefile_build_id (bfd *abfd, int from_tty)
562 {
563 const bfd_build_id *build_id = build_id_bfd_get (abfd);
564 if (build_id == nullptr)
565 return;
566
567 gdb_bfd_ref_ptr execbfd
568 = build_id_to_exec_bfd (build_id->size, build_id->data);
569
570 if (execbfd == nullptr)
571 {
572 /* Attempt to query debuginfod for the executable. */
573 gdb::unique_xmalloc_ptr<char> execpath;
574 scoped_fd fd = debuginfod_exec_query (build_id->data, build_id->size,
575 abfd->filename, &execpath);
576
577 if (fd.get () >= 0)
578 {
579 execbfd = gdb_bfd_open (execpath.get (), gnutarget);
580
581 if (execbfd == nullptr)
582 warning (_("\"%s\" from debuginfod cannot be opened as bfd: %s"),
583 execpath.get (),
584 gdb_bfd_errmsg (bfd_get_error (), nullptr).c_str ());
585 else if (!build_id_verify (execbfd.get (), build_id->size,
586 build_id->data))
587 execbfd.reset (nullptr);
588 }
589 }
590
591 if (execbfd != nullptr)
592 {
593 exec_file_attach (bfd_get_filename (execbfd.get ()), from_tty);
594 symbol_file_add_main (bfd_get_filename (execbfd.get ()),
595 symfile_add_flag (from_tty ? SYMFILE_VERBOSE : 0));
596 }
597 }
598
599 /* See gdbcore.h. */
600
601 void
602 core_target_open (const char *arg, int from_tty)
603 {
604 const char *p;
605 int siggy;
606 int scratch_chan;
607 int flags;
608
609 target_preopen (from_tty);
610 if (!arg)
611 {
612 if (core_bfd)
613 error (_("No core file specified. (Use `detach' "
614 "to stop debugging a core file.)"));
615 else
616 error (_("No core file specified."));
617 }
618
619 gdb::unique_xmalloc_ptr<char> filename (tilde_expand (arg));
620 if (strlen (filename.get ()) != 0
621 && !IS_ABSOLUTE_PATH (filename.get ()))
622 filename = make_unique_xstrdup (gdb_abspath (filename.get ()).c_str ());
623
624 flags = O_BINARY | O_LARGEFILE;
625 if (write_files)
626 flags |= O_RDWR;
627 else
628 flags |= O_RDONLY;
629 scratch_chan = gdb_open_cloexec (filename.get (), flags, 0).release ();
630 if (scratch_chan < 0)
631 perror_with_name (filename.get ());
632
633 gdb_bfd_ref_ptr temp_bfd (gdb_bfd_fopen (filename.get (), gnutarget,
634 write_files ? FOPEN_RUB : FOPEN_RB,
635 scratch_chan));
636 if (temp_bfd == NULL)
637 perror_with_name (filename.get ());
638
639 if (!bfd_check_format (temp_bfd.get (), bfd_core))
640 {
641 /* Do it after the err msg */
642 /* FIXME: should be checking for errors from bfd_close (for one
643 thing, on error it does not free all the storage associated
644 with the bfd). */
645 error (_("\"%s\" is not a core dump: %s"),
646 filename.get (), bfd_errmsg (bfd_get_error ()));
647 }
648
649 current_program_space->cbfd = std::move (temp_bfd);
650
651 core_target *target = new core_target ();
652
653 /* Own the target until it is successfully pushed. */
654 target_ops_up target_holder (target);
655
656 validate_files ();
657
658 /* If we have no exec file, try to set the architecture from the
659 core file. We don't do this unconditionally since an exec file
660 typically contains more information that helps us determine the
661 architecture than a core file. */
662 if (!current_program_space->exec_bfd ())
663 set_gdbarch_from_file (core_bfd);
664
665 current_inferior ()->push_target (std::move (target_holder));
666
667 switch_to_no_thread ();
668
669 /* Need to flush the register cache (and the frame cache) from a
670 previous debug session. If inferior_ptid ends up the same as the
671 last debug session --- e.g., b foo; run; gcore core1; step; gcore
672 core2; core core1; core core2 --- then there's potential for
673 get_current_regcache to return the cached regcache of the
674 previous session, and the frame cache being stale. */
675 registers_changed ();
676
677 /* Find (or fake) the pid for the process in this core file, and
678 initialise the current inferior with that pid. */
679 bool fake_pid_p = false;
680 int pid = bfd_core_file_pid (core_bfd);
681 if (pid == 0)
682 {
683 fake_pid_p = true;
684 pid = CORELOW_PID;
685 }
686
687 inferior *inf = current_inferior ();
688 gdb_assert (inf->pid == 0);
689 inferior_appeared (inf, pid);
690 inf->fake_pid_p = fake_pid_p;
691
692 /* Rename any .reg/0 sections, giving them each a fake lwpid. */
693 rename_vmcore_idle_reg_sections (core_bfd, inf);
694
695 /* Build up thread list from BFD sections, and possibly set the
696 current thread to the .reg/NN section matching the .reg
697 section. */
698 asection *reg_sect = bfd_get_section_by_name (core_bfd, ".reg");
699 for (asection *sect : gdb_bfd_sections (core_bfd))
700 add_to_thread_list (sect, reg_sect, inf);
701
702 if (inferior_ptid == null_ptid)
703 {
704 /* Either we found no .reg/NN section, and hence we have a
705 non-threaded core (single-threaded, from gdb's perspective),
706 or for some reason add_to_thread_list couldn't determine
707 which was the "main" thread. The latter case shouldn't
708 usually happen, but we're dealing with input here, which can
709 always be broken in different ways. */
710 thread_info *thread = first_thread_of_inferior (inf);
711
712 if (thread == NULL)
713 thread = add_thread_silent (target, ptid_t (CORELOW_PID));
714
715 switch_to_thread (thread);
716 }
717
718 if (current_program_space->exec_bfd () == nullptr)
719 locate_exec_from_corefile_build_id (core_bfd, from_tty);
720
721 post_create_inferior (from_tty);
722
723 /* Now go through the target stack looking for threads since there
724 may be a thread_stratum target loaded on top of target core by
725 now. The layer above should claim threads found in the BFD
726 sections. */
727 try
728 {
729 target_update_thread_list ();
730 }
731
732 catch (const gdb_exception_error &except)
733 {
734 exception_print (gdb_stderr, except);
735 }
736
737 p = bfd_core_file_failing_command (core_bfd);
738 if (p)
739 gdb_printf (_("Core was generated by `%s'.\n"), p);
740
741 /* Clearing any previous state of convenience variables. */
742 clear_exit_convenience_vars ();
743
744 siggy = bfd_core_file_failing_signal (core_bfd);
745 if (siggy > 0)
746 {
747 gdbarch *core_gdbarch = target->core_gdbarch ();
748
749 /* If we don't have a CORE_GDBARCH to work with, assume a native
750 core (map gdb_signal from host signals). If we do have
751 CORE_GDBARCH to work with, but no gdb_signal_from_target
752 implementation for that gdbarch, as a fallback measure,
753 assume the host signal mapping. It'll be correct for native
754 cores, but most likely incorrect for cross-cores. */
755 enum gdb_signal sig = (core_gdbarch != NULL
756 && gdbarch_gdb_signal_from_target_p (core_gdbarch)
757 ? gdbarch_gdb_signal_from_target (core_gdbarch,
758 siggy)
759 : gdb_signal_from_host (siggy));
760
761 gdb_printf (_("Program terminated with signal %s, %s"),
762 gdb_signal_to_name (sig), gdb_signal_to_string (sig));
763 if (gdbarch_report_signal_info_p (core_gdbarch))
764 gdbarch_report_signal_info (core_gdbarch, current_uiout, sig);
765 gdb_printf (_(".\n"));
766
767 /* Set the value of the internal variable $_exitsignal,
768 which holds the signal uncaught by the inferior. */
769 set_internalvar_integer (lookup_internalvar ("_exitsignal"),
770 siggy);
771 }
772
773 /* Fetch all registers from core file. */
774 target_fetch_registers (get_current_regcache (), -1);
775
776 /* Now, set up the frame cache, and print the top of stack. */
777 reinit_frame_cache ();
778 print_stack_frame (get_selected_frame (NULL), 1, SRC_AND_LOC, 1);
779
780 /* Current thread should be NUM 1 but the user does not know that.
781 If a program is single threaded gdb in general does not mention
782 anything about threads. That is why the test is >= 2. */
783 if (thread_count (target) >= 2)
784 {
785 try
786 {
787 thread_command (NULL, from_tty);
788 }
789 catch (const gdb_exception_error &except)
790 {
791 exception_print (gdb_stderr, except);
792 }
793 }
794 }
795
796 void
797 core_target::detach (inferior *inf, int from_tty)
798 {
799 /* Get rid of the core. Don't rely on core_target::close doing it,
800 because target_detach may be called with core_target's refcount > 1,
801 meaning core_target::close may not be called yet by the
802 unpush_target call below. */
803 clear_core ();
804
805 /* Note that 'this' may be dangling after this call. unpush_target
806 closes the target if the refcount reaches 0, and our close
807 implementation deletes 'this'. */
808 inf->unpush_target (this);
809
810 /* Clear the register cache and the frame cache. */
811 registers_changed ();
812 reinit_frame_cache ();
813 maybe_say_no_core_file_now (from_tty);
814 }
815
816 /* Try to retrieve registers from a section in core_bfd, and supply
817 them to REGSET.
818
819 If ptid's lwp member is zero, do the single-threaded
820 thing: look for a section named NAME. If ptid's lwp
821 member is non-zero, do the multi-threaded thing: look for a section
822 named "NAME/LWP", where LWP is the shortest ASCII decimal
823 representation of ptid's lwp member.
824
825 HUMAN_NAME is a human-readable name for the kind of registers the
826 NAME section contains, for use in error messages.
827
828 If REQUIRED is true, print an error if the core file doesn't have a
829 section by the appropriate name. Otherwise, just do nothing. */
830
831 void
832 core_target::get_core_register_section (struct regcache *regcache,
833 const struct regset *regset,
834 const char *name,
835 int section_min_size,
836 const char *human_name,
837 bool required)
838 {
839 gdb_assert (regset != nullptr);
840
841 struct bfd_section *section;
842 bfd_size_type size;
843 bool variable_size_section = (regset->flags & REGSET_VARIABLE_SIZE);
844
845 thread_section_name section_name (name, regcache->ptid ());
846
847 section = bfd_get_section_by_name (core_bfd, section_name.c_str ());
848 if (! section)
849 {
850 if (required)
851 warning (_("Couldn't find %s registers in core file."),
852 human_name);
853 return;
854 }
855
856 size = bfd_section_size (section);
857 if (size < section_min_size)
858 {
859 warning (_("Section `%s' in core file too small."),
860 section_name.c_str ());
861 return;
862 }
863 if (size != section_min_size && !variable_size_section)
864 {
865 warning (_("Unexpected size of section `%s' in core file."),
866 section_name.c_str ());
867 }
868
869 gdb::byte_vector contents (size);
870 if (!bfd_get_section_contents (core_bfd, section, contents.data (),
871 (file_ptr) 0, size))
872 {
873 warning (_("Couldn't read %s registers from `%s' section in core file."),
874 human_name, section_name.c_str ());
875 return;
876 }
877
878 regset->supply_regset (regset, regcache, -1, contents.data (), size);
879 }
880
881 /* Data passed to gdbarch_iterate_over_regset_sections's callback. */
882 struct get_core_registers_cb_data
883 {
884 core_target *target;
885 struct regcache *regcache;
886 };
887
888 /* Callback for get_core_registers that handles a single core file
889 register note section. */
890
891 static void
892 get_core_registers_cb (const char *sect_name, int supply_size, int collect_size,
893 const struct regset *regset,
894 const char *human_name, void *cb_data)
895 {
896 gdb_assert (regset != nullptr);
897
898 auto *data = (get_core_registers_cb_data *) cb_data;
899 bool required = false;
900 bool variable_size_section = (regset->flags & REGSET_VARIABLE_SIZE);
901
902 if (!variable_size_section)
903 gdb_assert (supply_size == collect_size);
904
905 if (strcmp (sect_name, ".reg") == 0)
906 {
907 required = true;
908 if (human_name == NULL)
909 human_name = "general-purpose";
910 }
911 else if (strcmp (sect_name, ".reg2") == 0)
912 {
913 if (human_name == NULL)
914 human_name = "floating-point";
915 }
916
917 data->target->get_core_register_section (data->regcache, regset, sect_name,
918 supply_size, human_name, required);
919 }
920
921 /* Get the registers out of a core file. This is the machine-
922 independent part. Fetch_core_registers is the machine-dependent
923 part, typically implemented in the xm-file for each
924 architecture. */
925
926 /* We just get all the registers, so we don't use regno. */
927
928 void
929 core_target::fetch_registers (struct regcache *regcache, int regno)
930 {
931 if (!(m_core_gdbarch != nullptr
932 && gdbarch_iterate_over_regset_sections_p (m_core_gdbarch)))
933 {
934 gdb_printf (gdb_stderr,
935 "Can't fetch registers from this type of core file\n");
936 return;
937 }
938
939 struct gdbarch *gdbarch = regcache->arch ();
940 get_core_registers_cb_data data = { this, regcache };
941 gdbarch_iterate_over_regset_sections (gdbarch,
942 get_core_registers_cb,
943 (void *) &data, NULL);
944
945 /* Mark all registers not found in the core as unavailable. */
946 for (int i = 0; i < gdbarch_num_regs (regcache->arch ()); i++)
947 if (regcache->get_register_status (i) == REG_UNKNOWN)
948 regcache->raw_supply (i, NULL);
949 }
950
951 void
952 core_target::files_info ()
953 {
954 print_section_info (&m_core_section_table, core_bfd);
955 }
956 \f
957 /* Helper method for core_target::xfer_partial. */
958
959 enum target_xfer_status
960 core_target::xfer_memory_via_mappings (gdb_byte *readbuf,
961 const gdb_byte *writebuf,
962 ULONGEST offset, ULONGEST len,
963 ULONGEST *xfered_len)
964 {
965 enum target_xfer_status xfer_status;
966
967 xfer_status = (section_table_xfer_memory_partial
968 (readbuf, writebuf,
969 offset, len, xfered_len,
970 m_core_file_mappings));
971
972 if (xfer_status == TARGET_XFER_OK || m_core_unavailable_mappings.empty ())
973 return xfer_status;
974
975 /* There are instances - e.g. when debugging within a docker
976 container using the AUFS storage driver - where the pathnames
977 obtained from the note section are incorrect. Despite the path
978 being wrong, just knowing the start and end addresses of the
979 mappings is still useful; we can attempt an access of the file
980 stratum constrained to the address ranges corresponding to the
981 unavailable mappings. */
982
983 ULONGEST memaddr = offset;
984 ULONGEST memend = offset + len;
985
986 for (const auto &mr : m_core_unavailable_mappings)
987 {
988 if (address_in_mem_range (memaddr, &mr))
989 {
990 if (!address_in_mem_range (memend, &mr))
991 len = mr.start + mr.length - memaddr;
992
993 xfer_status = this->beneath ()->xfer_partial (TARGET_OBJECT_MEMORY,
994 NULL,
995 readbuf,
996 writebuf,
997 offset,
998 len,
999 xfered_len);
1000 break;
1001 }
1002 }
1003
1004 return xfer_status;
1005 }
1006
1007 enum target_xfer_status
1008 core_target::xfer_partial (enum target_object object, const char *annex,
1009 gdb_byte *readbuf, const gdb_byte *writebuf,
1010 ULONGEST offset, ULONGEST len, ULONGEST *xfered_len)
1011 {
1012 switch (object)
1013 {
1014 case TARGET_OBJECT_MEMORY:
1015 {
1016 enum target_xfer_status xfer_status;
1017
1018 /* Try accessing memory contents from core file data,
1019 restricting consideration to those sections for which
1020 the BFD section flag SEC_HAS_CONTENTS is set. */
1021 auto has_contents_cb = [] (const struct target_section *s)
1022 {
1023 return ((s->the_bfd_section->flags & SEC_HAS_CONTENTS) != 0);
1024 };
1025 xfer_status = section_table_xfer_memory_partial
1026 (readbuf, writebuf,
1027 offset, len, xfered_len,
1028 m_core_section_table,
1029 has_contents_cb);
1030 if (xfer_status == TARGET_XFER_OK)
1031 return TARGET_XFER_OK;
1032
1033 /* Check file backed mappings. If they're available, use
1034 core file provided mappings (e.g. from .note.linuxcore.file
1035 or the like) as this should provide a more accurate
1036 result. If not, check the stratum beneath us, which should
1037 be the file stratum.
1038
1039 We also check unavailable mappings due to Docker/AUFS driver
1040 issues. */
1041 if (!m_core_file_mappings.empty ()
1042 || !m_core_unavailable_mappings.empty ())
1043 {
1044 xfer_status = xfer_memory_via_mappings (readbuf, writebuf, offset,
1045 len, xfered_len);
1046 }
1047 else
1048 xfer_status = this->beneath ()->xfer_partial (object, annex, readbuf,
1049 writebuf, offset, len,
1050 xfered_len);
1051 if (xfer_status == TARGET_XFER_OK)
1052 return TARGET_XFER_OK;
1053
1054 /* Finally, attempt to access data in core file sections with
1055 no contents. These will typically read as all zero. */
1056 auto no_contents_cb = [&] (const struct target_section *s)
1057 {
1058 return !has_contents_cb (s);
1059 };
1060 xfer_status = section_table_xfer_memory_partial
1061 (readbuf, writebuf,
1062 offset, len, xfered_len,
1063 m_core_section_table,
1064 no_contents_cb);
1065
1066 return xfer_status;
1067 }
1068 case TARGET_OBJECT_AUXV:
1069 if (readbuf)
1070 {
1071 /* When the aux vector is stored in core file, BFD
1072 represents this with a fake section called ".auxv". */
1073
1074 struct bfd_section *section;
1075 bfd_size_type size;
1076
1077 section = bfd_get_section_by_name (core_bfd, ".auxv");
1078 if (section == NULL)
1079 return TARGET_XFER_E_IO;
1080
1081 size = bfd_section_size (section);
1082 if (offset >= size)
1083 return TARGET_XFER_EOF;
1084 size -= offset;
1085 if (size > len)
1086 size = len;
1087
1088 if (size == 0)
1089 return TARGET_XFER_EOF;
1090 if (!bfd_get_section_contents (core_bfd, section, readbuf,
1091 (file_ptr) offset, size))
1092 {
1093 warning (_("Couldn't read NT_AUXV note in core file."));
1094 return TARGET_XFER_E_IO;
1095 }
1096
1097 *xfered_len = (ULONGEST) size;
1098 return TARGET_XFER_OK;
1099 }
1100 return TARGET_XFER_E_IO;
1101
1102 case TARGET_OBJECT_WCOOKIE:
1103 if (readbuf)
1104 {
1105 /* When the StackGhost cookie is stored in core file, BFD
1106 represents this with a fake section called
1107 ".wcookie". */
1108
1109 struct bfd_section *section;
1110 bfd_size_type size;
1111
1112 section = bfd_get_section_by_name (core_bfd, ".wcookie");
1113 if (section == NULL)
1114 return TARGET_XFER_E_IO;
1115
1116 size = bfd_section_size (section);
1117 if (offset >= size)
1118 return TARGET_XFER_EOF;
1119 size -= offset;
1120 if (size > len)
1121 size = len;
1122
1123 if (size == 0)
1124 return TARGET_XFER_EOF;
1125 if (!bfd_get_section_contents (core_bfd, section, readbuf,
1126 (file_ptr) offset, size))
1127 {
1128 warning (_("Couldn't read StackGhost cookie in core file."));
1129 return TARGET_XFER_E_IO;
1130 }
1131
1132 *xfered_len = (ULONGEST) size;
1133 return TARGET_XFER_OK;
1134
1135 }
1136 return TARGET_XFER_E_IO;
1137
1138 case TARGET_OBJECT_LIBRARIES:
1139 if (m_core_gdbarch != nullptr
1140 && gdbarch_core_xfer_shared_libraries_p (m_core_gdbarch))
1141 {
1142 if (writebuf)
1143 return TARGET_XFER_E_IO;
1144 else
1145 {
1146 *xfered_len = gdbarch_core_xfer_shared_libraries (m_core_gdbarch,
1147 readbuf,
1148 offset, len);
1149
1150 if (*xfered_len == 0)
1151 return TARGET_XFER_EOF;
1152 else
1153 return TARGET_XFER_OK;
1154 }
1155 }
1156 return TARGET_XFER_E_IO;
1157
1158 case TARGET_OBJECT_LIBRARIES_AIX:
1159 if (m_core_gdbarch != nullptr
1160 && gdbarch_core_xfer_shared_libraries_aix_p (m_core_gdbarch))
1161 {
1162 if (writebuf)
1163 return TARGET_XFER_E_IO;
1164 else
1165 {
1166 *xfered_len
1167 = gdbarch_core_xfer_shared_libraries_aix (m_core_gdbarch,
1168 readbuf, offset,
1169 len);
1170
1171 if (*xfered_len == 0)
1172 return TARGET_XFER_EOF;
1173 else
1174 return TARGET_XFER_OK;
1175 }
1176 }
1177 return TARGET_XFER_E_IO;
1178
1179 case TARGET_OBJECT_SIGNAL_INFO:
1180 if (readbuf)
1181 {
1182 if (m_core_gdbarch != nullptr
1183 && gdbarch_core_xfer_siginfo_p (m_core_gdbarch))
1184 {
1185 LONGEST l = gdbarch_core_xfer_siginfo (m_core_gdbarch, readbuf,
1186 offset, len);
1187
1188 if (l >= 0)
1189 {
1190 *xfered_len = l;
1191 if (l == 0)
1192 return TARGET_XFER_EOF;
1193 else
1194 return TARGET_XFER_OK;
1195 }
1196 }
1197 }
1198 return TARGET_XFER_E_IO;
1199
1200 default:
1201 return this->beneath ()->xfer_partial (object, annex, readbuf,
1202 writebuf, offset, len,
1203 xfered_len);
1204 }
1205 }
1206
1207 \f
1208
1209 /* Okay, let's be honest: threads gleaned from a core file aren't
1210 exactly lively, are they? On the other hand, if we don't claim
1211 that each & every one is alive, then we don't get any of them
1212 to appear in an "info thread" command, which is quite a useful
1213 behaviour.
1214 */
1215 bool
1216 core_target::thread_alive (ptid_t ptid)
1217 {
1218 return true;
1219 }
1220
1221 /* Ask the current architecture what it knows about this core file.
1222 That will be used, in turn, to pick a better architecture. This
1223 wrapper could be avoided if targets got a chance to specialize
1224 core_target. */
1225
1226 const struct target_desc *
1227 core_target::read_description ()
1228 {
1229 /* If the core file contains a target description note then we will use
1230 that in preference to anything else. */
1231 bfd_size_type tdesc_note_size = 0;
1232 struct bfd_section *tdesc_note_section
1233 = bfd_get_section_by_name (core_bfd, ".gdb-tdesc");
1234 if (tdesc_note_section != nullptr)
1235 tdesc_note_size = bfd_section_size (tdesc_note_section);
1236 if (tdesc_note_size > 0)
1237 {
1238 gdb::char_vector contents (tdesc_note_size + 1);
1239 if (bfd_get_section_contents (core_bfd, tdesc_note_section,
1240 contents.data (), (file_ptr) 0,
1241 tdesc_note_size))
1242 {
1243 /* Ensure we have a null terminator. */
1244 contents[tdesc_note_size] = '\0';
1245 const struct target_desc *result
1246 = string_read_description_xml (contents.data ());
1247 if (result != nullptr)
1248 return result;
1249 }
1250 }
1251
1252 if (m_core_gdbarch && gdbarch_core_read_description_p (m_core_gdbarch))
1253 {
1254 const struct target_desc *result;
1255
1256 result = gdbarch_core_read_description (m_core_gdbarch, this, core_bfd);
1257 if (result != NULL)
1258 return result;
1259 }
1260
1261 return this->beneath ()->read_description ();
1262 }
1263
1264 std::string
1265 core_target::pid_to_str (ptid_t ptid)
1266 {
1267 struct inferior *inf;
1268 int pid;
1269
1270 /* The preferred way is to have a gdbarch/OS specific
1271 implementation. */
1272 if (m_core_gdbarch != nullptr
1273 && gdbarch_core_pid_to_str_p (m_core_gdbarch))
1274 return gdbarch_core_pid_to_str (m_core_gdbarch, ptid);
1275
1276 /* Otherwise, if we don't have one, we'll just fallback to
1277 "process", with normal_pid_to_str. */
1278
1279 /* Try the LWPID field first. */
1280 pid = ptid.lwp ();
1281 if (pid != 0)
1282 return normal_pid_to_str (ptid_t (pid));
1283
1284 /* Otherwise, this isn't a "threaded" core -- use the PID field, but
1285 only if it isn't a fake PID. */
1286 inf = find_inferior_ptid (this, ptid);
1287 if (inf != NULL && !inf->fake_pid_p)
1288 return normal_pid_to_str (ptid);
1289
1290 /* No luck. We simply don't have a valid PID to print. */
1291 return "<main task>";
1292 }
1293
1294 const char *
1295 core_target::thread_name (struct thread_info *thr)
1296 {
1297 if (m_core_gdbarch != nullptr
1298 && gdbarch_core_thread_name_p (m_core_gdbarch))
1299 return gdbarch_core_thread_name (m_core_gdbarch, thr);
1300 return NULL;
1301 }
1302
1303 bool
1304 core_target::has_memory ()
1305 {
1306 return (core_bfd != NULL);
1307 }
1308
1309 bool
1310 core_target::has_stack ()
1311 {
1312 return (core_bfd != NULL);
1313 }
1314
1315 bool
1316 core_target::has_registers ()
1317 {
1318 return (core_bfd != NULL);
1319 }
1320
1321 /* Implement the to_info_proc method. */
1322
1323 bool
1324 core_target::info_proc (const char *args, enum info_proc_what request)
1325 {
1326 struct gdbarch *gdbarch = get_current_arch ();
1327
1328 /* Since this is the core file target, call the 'core_info_proc'
1329 method on gdbarch, not 'info_proc'. */
1330 if (gdbarch_core_info_proc_p (gdbarch))
1331 gdbarch_core_info_proc (gdbarch, args, request);
1332
1333 return true;
1334 }
1335
1336 /* Implementation of the "supports_memory_tagging" target_ops method. */
1337
1338 bool
1339 core_target::supports_memory_tagging ()
1340 {
1341 /* Look for memory tag sections. If they exist, that means this core file
1342 supports memory tagging. */
1343
1344 return (bfd_get_section_by_name (core_bfd, "memtag") != nullptr);
1345 }
1346
1347 /* Implementation of the "fetch_memtags" target_ops method. */
1348
1349 bool
1350 core_target::fetch_memtags (CORE_ADDR address, size_t len,
1351 gdb::byte_vector &tags, int type)
1352 {
1353 struct gdbarch *gdbarch = target_gdbarch ();
1354
1355 /* Make sure we have a way to decode the memory tag notes. */
1356 if (!gdbarch_decode_memtag_section_p (gdbarch))
1357 error (_("gdbarch_decode_memtag_section not implemented for this "
1358 "architecture."));
1359
1360 memtag_section_info info;
1361 info.memtag_section = nullptr;
1362
1363 while (get_next_core_memtag_section (core_bfd, info.memtag_section,
1364 address, info))
1365 {
1366 size_t adjusted_length
1367 = (address + len < info.end_address) ? len : (info.end_address - address);
1368
1369 /* Decode the memory tag note and return the tags. */
1370 gdb::byte_vector tags_read
1371 = gdbarch_decode_memtag_section (gdbarch, info.memtag_section, type,
1372 address, adjusted_length);
1373
1374 /* Transfer over the tags that have been read. */
1375 tags.insert (tags.end (), tags_read.begin (), tags_read.end ());
1376
1377 /* ADDRESS + LEN may cross the boundaries of a particular memory tag
1378 segment. Check if we need to fetch tags from a different section. */
1379 if (!tags_read.empty () && (address + len) < info.end_address)
1380 return true;
1381
1382 /* There are more tags to fetch. Update ADDRESS and LEN. */
1383 len -= (info.end_address - address);
1384 address = info.end_address;
1385 }
1386
1387 return false;
1388 }
1389
1390 /* Get a pointer to the current core target. If not connected to a
1391 core target, return NULL. */
1392
1393 static core_target *
1394 get_current_core_target ()
1395 {
1396 target_ops *proc_target = current_inferior ()->process_target ();
1397 return dynamic_cast<core_target *> (proc_target);
1398 }
1399
1400 /* Display file backed mappings from core file. */
1401
1402 void
1403 core_target::info_proc_mappings (struct gdbarch *gdbarch)
1404 {
1405 if (!m_core_file_mappings.empty ())
1406 {
1407 gdb_printf (_("Mapped address spaces:\n\n"));
1408 if (gdbarch_addr_bit (gdbarch) == 32)
1409 {
1410 gdb_printf ("\t%10s %10s %10s %10s %s\n",
1411 "Start Addr",
1412 " End Addr",
1413 " Size", " Offset", "objfile");
1414 }
1415 else
1416 {
1417 gdb_printf (" %18s %18s %10s %10s %s\n",
1418 "Start Addr",
1419 " End Addr",
1420 " Size", " Offset", "objfile");
1421 }
1422 }
1423
1424 for (const target_section &tsp : m_core_file_mappings)
1425 {
1426 ULONGEST start = tsp.addr;
1427 ULONGEST end = tsp.endaddr;
1428 ULONGEST file_ofs = tsp.the_bfd_section->filepos;
1429 const char *filename = bfd_get_filename (tsp.the_bfd_section->owner);
1430
1431 if (gdbarch_addr_bit (gdbarch) == 32)
1432 gdb_printf ("\t%10s %10s %10s %10s %s\n",
1433 paddress (gdbarch, start),
1434 paddress (gdbarch, end),
1435 hex_string (end - start),
1436 hex_string (file_ofs),
1437 filename);
1438 else
1439 gdb_printf (" %18s %18s %10s %10s %s\n",
1440 paddress (gdbarch, start),
1441 paddress (gdbarch, end),
1442 hex_string (end - start),
1443 hex_string (file_ofs),
1444 filename);
1445 }
1446 }
1447
1448 /* Implement "maintenance print core-file-backed-mappings" command.
1449
1450 If mappings are loaded, the results should be similar to the
1451 mappings shown by "info proc mappings". This command is mainly a
1452 debugging tool for GDB developers to make sure that the expected
1453 mappings are present after loading a core file. For Linux, the
1454 output provided by this command will be very similar (if not
1455 identical) to that provided by "info proc mappings". This is not
1456 necessarily the case for other OSes which might provide
1457 more/different information in the "info proc mappings" output. */
1458
1459 static void
1460 maintenance_print_core_file_backed_mappings (const char *args, int from_tty)
1461 {
1462 core_target *targ = get_current_core_target ();
1463 if (targ != nullptr)
1464 targ->info_proc_mappings (targ->core_gdbarch ());
1465 }
1466
1467 void _initialize_corelow ();
1468 void
1469 _initialize_corelow ()
1470 {
1471 add_target (core_target_info, core_target_open, filename_completer);
1472 add_cmd ("core-file-backed-mappings", class_maintenance,
1473 maintenance_print_core_file_backed_mappings,
1474 _("Print core file's file-backed mappings."),
1475 &maintenanceprintlist);
1476 }