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