1 /* Core dump and executable file functions below target vector, for GDB.
3 Copyright (C) 1986-2019 Free Software Foundation, Inc.
5 This file is part of GDB.
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.
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.
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/>. */
21 #include "arch-utils.h"
24 #include "frame.h" /* required by inferior.h */
31 #include "process-stratum-target.h"
33 #include "gdbthread.h"
38 #include "readline/readline.h"
40 #include "filenames.h"
41 #include "progspace.h"
44 #include "completer.h"
45 #include "common/filestuff.h"
51 static core_fns
*sniff_core_bfd (gdbarch
*core_gdbarch
,
54 /* The core file target. */
56 static const target_info core_target_info
= {
58 N_("Local core dump file"),
59 N_("Use a core file as a target. Specify the filename of the core file.")
62 class core_target final
: public process_stratum_target
66 ~core_target () override
;
68 const target_info
&info () const override
69 { return core_target_info
; }
71 void close () override
;
72 void detach (inferior
*, int) override
;
73 void fetch_registers (struct regcache
*, int) override
;
75 enum target_xfer_status
xfer_partial (enum target_object object
,
78 const gdb_byte
*writebuf
,
79 ULONGEST offset
, ULONGEST len
,
80 ULONGEST
*xfered_len
) override
;
81 void files_info () override
;
83 bool thread_alive (ptid_t ptid
) override
;
84 const struct target_desc
*read_description () override
;
86 std::string
pid_to_str (ptid_t
) override
;
88 const char *thread_name (struct thread_info
*) override
;
90 bool has_all_memory () override
{ return false; }
91 bool has_memory () override
;
92 bool has_stack () override
;
93 bool has_registers () override
;
94 bool has_execution (ptid_t
) override
{ return false; }
96 bool info_proc (const char *, enum info_proc_what
) override
;
100 /* Getter, see variable definition. */
101 struct gdbarch
*core_gdbarch ()
103 return m_core_gdbarch
;
106 /* See definition. */
107 void get_core_register_section (struct regcache
*regcache
,
108 const struct regset
*regset
,
110 int section_min_size
,
112 const char *human_name
,
115 private: /* per-core data */
117 /* The core's section table. Note that these target sections are
118 *not* mapped in the current address spaces' set of target
119 sections --- those should come only from pure executable or
120 shared library bfds. The core bfd sections are an implementation
121 detail of the core target, just like ptrace is for unix child
123 target_section_table m_core_section_table
{};
125 /* The core_fns for a core file handler that is prepared to read the
126 core file currently open on core_bfd. */
127 core_fns
*m_core_vec
= NULL
;
129 /* FIXME: kettenis/20031023: Eventually this field should
131 struct gdbarch
*m_core_gdbarch
= NULL
;
134 core_target::core_target ()
136 m_core_gdbarch
= gdbarch_from_bfd (core_bfd
);
138 /* Find a suitable core file handler to munch on core_bfd */
139 m_core_vec
= sniff_core_bfd (m_core_gdbarch
, core_bfd
);
141 /* Find the data section */
142 if (build_section_table (core_bfd
,
143 &m_core_section_table
.sections
,
144 &m_core_section_table
.sections_end
))
145 error (_("\"%s\": Can't find sections: %s"),
146 bfd_get_filename (core_bfd
), bfd_errmsg (bfd_get_error ()));
149 core_target::~core_target ()
151 xfree (m_core_section_table
.sections
);
154 /* List of all available core_fns. On gdb startup, each core file
155 register reader calls deprecated_add_core_fns() to register
156 information on each core format it is prepared to read. */
158 static struct core_fns
*core_file_fns
= NULL
;
160 static int gdb_check_format (bfd
*);
162 static void add_to_thread_list (bfd
*, asection
*, void *);
164 /* An arbitrary identifier for the core inferior. */
165 #define CORELOW_PID 1
167 /* Link a new core_fns into the global core_file_fns list. Called on
168 gdb startup by the _initialize routine in each core file register
169 reader, to register information about each format the reader is
170 prepared to handle. */
173 deprecated_add_core_fns (struct core_fns
*cf
)
175 cf
->next
= core_file_fns
;
179 /* The default function that core file handlers can use to examine a
180 core file BFD and decide whether or not to accept the job of
181 reading the core file. */
184 default_core_sniffer (struct core_fns
*our_fns
, bfd
*abfd
)
188 result
= (bfd_get_flavour (abfd
) == our_fns
-> core_flavour
);
192 /* Walk through the list of core functions to find a set that can
193 handle the core file open on ABFD. Returns pointer to set that is
196 static struct core_fns
*
197 sniff_core_bfd (struct gdbarch
*core_gdbarch
, bfd
*abfd
)
200 struct core_fns
*yummy
= NULL
;
203 /* Don't sniff if we have support for register sets in
205 if (core_gdbarch
&& gdbarch_iterate_over_regset_sections_p (core_gdbarch
))
208 for (cf
= core_file_fns
; cf
!= NULL
; cf
= cf
->next
)
210 if (cf
->core_sniffer (cf
, abfd
))
218 warning (_("\"%s\": ambiguous core format, %d handlers match"),
219 bfd_get_filename (abfd
), matches
);
221 else if (matches
== 0)
222 error (_("\"%s\": no core file handler recognizes format"),
223 bfd_get_filename (abfd
));
228 /* The default is to reject every core file format we see. Either
229 BFD has to recognize it, or we have to provide a function in the
230 core file handler that recognizes it. */
233 default_check_format (bfd
*abfd
)
238 /* Attempt to recognize core file formats that BFD rejects. */
241 gdb_check_format (bfd
*abfd
)
245 for (cf
= core_file_fns
; cf
!= NULL
; cf
= cf
->next
)
247 if (cf
->check_format (abfd
))
255 /* Close the core target. */
258 core_target::close ()
262 inferior_ptid
= null_ptid
; /* Avoid confusion from thread
264 exit_inferior_silent (current_inferior ());
266 /* Clear out solib state while the bfd is still open. See
267 comments in clear_solib in solib.c. */
270 current_program_space
->cbfd
.reset (nullptr);
273 /* Core targets are heap-allocated (see core_target_open), so here
274 we delete ourselves. */
278 /* Look for sections whose names start with `.reg/' so that we can
279 extract the list of threads in a core file. */
282 add_to_thread_list (bfd
*abfd
, asection
*asect
, void *reg_sect_arg
)
287 asection
*reg_sect
= (asection
*) reg_sect_arg
;
288 bool fake_pid_p
= false;
289 struct inferior
*inf
;
291 if (!startswith (bfd_section_name (abfd
, asect
), ".reg/"))
294 core_tid
= atoi (bfd_section_name (abfd
, asect
) + 5);
296 pid
= bfd_core_file_pid (core_bfd
);
305 inf
= current_inferior ();
308 inferior_appeared (inf
, pid
);
309 inf
->fake_pid_p
= fake_pid_p
;
312 ptid
= ptid_t (pid
, lwpid
, 0);
316 /* Warning, Will Robinson, looking at BFD private data! */
319 && asect
->filepos
== reg_sect
->filepos
) /* Did we find .reg? */
320 inferior_ptid
= ptid
; /* Yes, make it current. */
323 /* Issue a message saying we have no core to debug, if FROM_TTY. */
326 maybe_say_no_core_file_now (int from_tty
)
329 printf_filtered (_("No core file now.\n"));
332 /* Backward compatability with old way of specifying core files. */
335 core_file_command (const char *filename
, int from_tty
)
337 dont_repeat (); /* Either way, seems bogus. */
339 if (filename
== NULL
)
341 if (core_bfd
!= NULL
)
343 target_detach (current_inferior (), from_tty
);
344 gdb_assert (core_bfd
== NULL
);
347 maybe_say_no_core_file_now (from_tty
);
350 core_target_open (filename
, from_tty
);
356 core_target_open (const char *arg
, int from_tty
)
363 target_preopen (from_tty
);
367 error (_("No core file specified. (Use `detach' "
368 "to stop debugging a core file.)"));
370 error (_("No core file specified."));
373 gdb::unique_xmalloc_ptr
<char> filename (tilde_expand (arg
));
374 if (!IS_ABSOLUTE_PATH (filename
.get ()))
375 filename
.reset (concat (current_directory
, "/",
376 filename
.get (), (char *) NULL
));
378 flags
= O_BINARY
| O_LARGEFILE
;
383 scratch_chan
= gdb_open_cloexec (filename
.get (), flags
, 0);
384 if (scratch_chan
< 0)
385 perror_with_name (filename
.get ());
387 gdb_bfd_ref_ptr
temp_bfd (gdb_bfd_fopen (filename
.get (), gnutarget
,
388 write_files
? FOPEN_RUB
: FOPEN_RB
,
390 if (temp_bfd
== NULL
)
391 perror_with_name (filename
.get ());
393 if (!bfd_check_format (temp_bfd
.get (), bfd_core
)
394 && !gdb_check_format (temp_bfd
.get ()))
396 /* Do it after the err msg */
397 /* FIXME: should be checking for errors from bfd_close (for one
398 thing, on error it does not free all the storage associated
400 error (_("\"%s\" is not a core dump: %s"),
401 filename
.get (), bfd_errmsg (bfd_get_error ()));
404 current_program_space
->cbfd
= std::move (temp_bfd
);
406 core_target
*target
= new core_target ();
408 /* Own the target until it is successfully pushed. */
409 target_ops_up
target_holder (target
);
413 /* If we have no exec file, try to set the architecture from the
414 core file. We don't do this unconditionally since an exec file
415 typically contains more information that helps us determine the
416 architecture than a core file. */
418 set_gdbarch_from_file (core_bfd
);
420 push_target (std::move (target_holder
));
422 inferior_ptid
= null_ptid
;
424 /* Need to flush the register cache (and the frame cache) from a
425 previous debug session. If inferior_ptid ends up the same as the
426 last debug session --- e.g., b foo; run; gcore core1; step; gcore
427 core2; core core1; core core2 --- then there's potential for
428 get_current_regcache to return the cached regcache of the
429 previous session, and the frame cache being stale. */
430 registers_changed ();
432 /* Build up thread list from BFD sections, and possibly set the
433 current thread to the .reg/NN section matching the .reg
435 bfd_map_over_sections (core_bfd
, add_to_thread_list
,
436 bfd_get_section_by_name (core_bfd
, ".reg"));
438 if (inferior_ptid
== null_ptid
)
440 /* Either we found no .reg/NN section, and hence we have a
441 non-threaded core (single-threaded, from gdb's perspective),
442 or for some reason add_to_thread_list couldn't determine
443 which was the "main" thread. The latter case shouldn't
444 usually happen, but we're dealing with input here, which can
445 always be broken in different ways. */
446 thread_info
*thread
= first_thread_of_inferior (current_inferior ());
450 inferior_appeared (current_inferior (), CORELOW_PID
);
451 inferior_ptid
= ptid_t (CORELOW_PID
);
452 add_thread_silent (inferior_ptid
);
455 switch_to_thread (thread
);
458 post_create_inferior (target
, from_tty
);
460 /* Now go through the target stack looking for threads since there
461 may be a thread_stratum target loaded on top of target core by
462 now. The layer above should claim threads found in the BFD
466 target_update_thread_list ();
469 catch (const gdb_exception_error
&except
)
471 exception_print (gdb_stderr
, except
);
474 p
= bfd_core_file_failing_command (core_bfd
);
476 printf_filtered (_("Core was generated by `%s'.\n"), p
);
478 /* Clearing any previous state of convenience variables. */
479 clear_exit_convenience_vars ();
481 siggy
= bfd_core_file_failing_signal (core_bfd
);
484 gdbarch
*core_gdbarch
= target
->core_gdbarch ();
486 /* If we don't have a CORE_GDBARCH to work with, assume a native
487 core (map gdb_signal from host signals). If we do have
488 CORE_GDBARCH to work with, but no gdb_signal_from_target
489 implementation for that gdbarch, as a fallback measure,
490 assume the host signal mapping. It'll be correct for native
491 cores, but most likely incorrect for cross-cores. */
492 enum gdb_signal sig
= (core_gdbarch
!= NULL
493 && gdbarch_gdb_signal_from_target_p (core_gdbarch
)
494 ? gdbarch_gdb_signal_from_target (core_gdbarch
,
496 : gdb_signal_from_host (siggy
));
498 printf_filtered (_("Program terminated with signal %s, %s.\n"),
499 gdb_signal_to_name (sig
), gdb_signal_to_string (sig
));
501 /* Set the value of the internal variable $_exitsignal,
502 which holds the signal uncaught by the inferior. */
503 set_internalvar_integer (lookup_internalvar ("_exitsignal"),
507 /* Fetch all registers from core file. */
508 target_fetch_registers (get_current_regcache (), -1);
510 /* Now, set up the frame cache, and print the top of stack. */
511 reinit_frame_cache ();
512 print_stack_frame (get_selected_frame (NULL
), 1, SRC_AND_LOC
, 1);
514 /* Current thread should be NUM 1 but the user does not know that.
515 If a program is single threaded gdb in general does not mention
516 anything about threads. That is why the test is >= 2. */
517 if (thread_count () >= 2)
521 thread_command (NULL
, from_tty
);
523 catch (const gdb_exception_error
&except
)
525 exception_print (gdb_stderr
, except
);
531 core_target::detach (inferior
*inf
, int from_tty
)
533 /* Note that 'this' is dangling after this call. unpush_target
534 closes the target, and our close implementation deletes
536 unpush_target (this);
538 reinit_frame_cache ();
539 maybe_say_no_core_file_now (from_tty
);
542 /* Try to retrieve registers from a section in core_bfd, and supply
543 them to m_core_vec->core_read_registers, as the register set
546 If ptid's lwp member is zero, do the single-threaded
547 thing: look for a section named NAME. If ptid's lwp
548 member is non-zero, do the multi-threaded thing: look for a section
549 named "NAME/LWP", where LWP is the shortest ASCII decimal
550 representation of ptid's lwp member.
552 HUMAN_NAME is a human-readable name for the kind of registers the
553 NAME section contains, for use in error messages.
555 If REQUIRED is true, print an error if the core file doesn't have a
556 section by the appropriate name. Otherwise, just do nothing. */
559 core_target::get_core_register_section (struct regcache
*regcache
,
560 const struct regset
*regset
,
562 int section_min_size
,
564 const char *human_name
,
567 struct bfd_section
*section
;
570 bool variable_size_section
= (regset
!= NULL
571 && regset
->flags
& REGSET_VARIABLE_SIZE
);
573 thread_section_name
section_name (name
, regcache
->ptid ());
575 section
= bfd_get_section_by_name (core_bfd
, section_name
.c_str ());
579 warning (_("Couldn't find %s registers in core file."),
584 size
= bfd_section_size (core_bfd
, section
);
585 if (size
< section_min_size
)
587 warning (_("Section `%s' in core file too small."),
588 section_name
.c_str ());
591 if (size
!= section_min_size
&& !variable_size_section
)
593 warning (_("Unexpected size of section `%s' in core file."),
594 section_name
.c_str ());
597 contents
= (char *) alloca (size
);
598 if (! bfd_get_section_contents (core_bfd
, section
, contents
,
601 warning (_("Couldn't read %s registers from `%s' section in core file."),
602 human_name
, section_name
.c_str ());
608 regset
->supply_regset (regset
, regcache
, -1, contents
, size
);
612 gdb_assert (m_core_vec
!= nullptr);
613 m_core_vec
->core_read_registers (regcache
, contents
, size
, which
,
615 bfd_section_vma (core_bfd
, section
)));
618 /* Data passed to gdbarch_iterate_over_regset_sections's callback. */
619 struct get_core_registers_cb_data
622 struct regcache
*regcache
;
625 /* Callback for get_core_registers that handles a single core file
626 register note section. */
629 get_core_registers_cb (const char *sect_name
, int supply_size
, int collect_size
,
630 const struct regset
*regset
,
631 const char *human_name
, void *cb_data
)
633 auto *data
= (get_core_registers_cb_data
*) cb_data
;
634 bool required
= false;
635 bool variable_size_section
= (regset
!= NULL
636 && regset
->flags
& REGSET_VARIABLE_SIZE
);
638 if (!variable_size_section
)
639 gdb_assert (supply_size
== collect_size
);
641 if (strcmp (sect_name
, ".reg") == 0)
644 if (human_name
== NULL
)
645 human_name
= "general-purpose";
647 else if (strcmp (sect_name
, ".reg2") == 0)
649 if (human_name
== NULL
)
650 human_name
= "floating-point";
653 /* The 'which' parameter is only used when no regset is provided.
654 Thus we just set it to -1. */
655 data
->target
->get_core_register_section (data
->regcache
, regset
, sect_name
,
656 supply_size
, -1, human_name
,
660 /* Get the registers out of a core file. This is the machine-
661 independent part. Fetch_core_registers is the machine-dependent
662 part, typically implemented in the xm-file for each
665 /* We just get all the registers, so we don't use regno. */
668 core_target::fetch_registers (struct regcache
*regcache
, int regno
)
671 struct gdbarch
*gdbarch
;
673 if (!(m_core_gdbarch
!= nullptr
674 && gdbarch_iterate_over_regset_sections_p (m_core_gdbarch
))
675 && (m_core_vec
== NULL
|| m_core_vec
->core_read_registers
== NULL
))
677 fprintf_filtered (gdb_stderr
,
678 "Can't fetch registers from this type of core file\n");
682 gdbarch
= regcache
->arch ();
683 if (gdbarch_iterate_over_regset_sections_p (gdbarch
))
685 get_core_registers_cb_data data
= { this, regcache
};
686 gdbarch_iterate_over_regset_sections (gdbarch
,
687 get_core_registers_cb
,
688 (void *) &data
, NULL
);
692 get_core_register_section (regcache
, NULL
,
693 ".reg", 0, 0, "general-purpose", 1);
694 get_core_register_section (regcache
, NULL
,
695 ".reg2", 0, 2, "floating-point", 0);
698 /* Mark all registers not found in the core as unavailable. */
699 for (i
= 0; i
< gdbarch_num_regs (regcache
->arch ()); i
++)
700 if (regcache
->get_register_status (i
) == REG_UNKNOWN
)
701 regcache
->raw_supply (i
, NULL
);
705 core_target::files_info ()
707 print_section_info (&m_core_section_table
, core_bfd
);
720 add_to_spuid_list (bfd
*abfd
, asection
*asect
, void *list_p
)
722 struct spuid_list
*list
= (struct spuid_list
*) list_p
;
723 enum bfd_endian byte_order
724 = bfd_big_endian (abfd
) ? BFD_ENDIAN_BIG
: BFD_ENDIAN_LITTLE
;
727 sscanf (bfd_section_name (abfd
, asect
), "SPU/%d/regs%n", &fd
, &pos
);
731 if (list
->pos
>= list
->offset
&& list
->pos
+ 4 <= list
->offset
+ list
->len
)
733 store_unsigned_integer (list
->buf
+ list
->pos
- list
->offset
,
740 enum target_xfer_status
741 core_target::xfer_partial (enum target_object object
, const char *annex
,
742 gdb_byte
*readbuf
, const gdb_byte
*writebuf
,
743 ULONGEST offset
, ULONGEST len
, ULONGEST
*xfered_len
)
747 case TARGET_OBJECT_MEMORY
:
748 return (section_table_xfer_memory_partial
750 offset
, len
, xfered_len
,
751 m_core_section_table
.sections
,
752 m_core_section_table
.sections_end
,
755 case TARGET_OBJECT_AUXV
:
758 /* When the aux vector is stored in core file, BFD
759 represents this with a fake section called ".auxv". */
761 struct bfd_section
*section
;
764 section
= bfd_get_section_by_name (core_bfd
, ".auxv");
766 return TARGET_XFER_E_IO
;
768 size
= bfd_section_size (core_bfd
, section
);
770 return TARGET_XFER_EOF
;
776 return TARGET_XFER_EOF
;
777 if (!bfd_get_section_contents (core_bfd
, section
, readbuf
,
778 (file_ptr
) offset
, size
))
780 warning (_("Couldn't read NT_AUXV note in core file."));
781 return TARGET_XFER_E_IO
;
784 *xfered_len
= (ULONGEST
) size
;
785 return TARGET_XFER_OK
;
787 return TARGET_XFER_E_IO
;
789 case TARGET_OBJECT_WCOOKIE
:
792 /* When the StackGhost cookie is stored in core file, BFD
793 represents this with a fake section called
796 struct bfd_section
*section
;
799 section
= bfd_get_section_by_name (core_bfd
, ".wcookie");
801 return TARGET_XFER_E_IO
;
803 size
= bfd_section_size (core_bfd
, section
);
805 return TARGET_XFER_EOF
;
811 return TARGET_XFER_EOF
;
812 if (!bfd_get_section_contents (core_bfd
, section
, readbuf
,
813 (file_ptr
) offset
, size
))
815 warning (_("Couldn't read StackGhost cookie in core file."));
816 return TARGET_XFER_E_IO
;
819 *xfered_len
= (ULONGEST
) size
;
820 return TARGET_XFER_OK
;
823 return TARGET_XFER_E_IO
;
825 case TARGET_OBJECT_LIBRARIES
:
826 if (m_core_gdbarch
!= nullptr
827 && gdbarch_core_xfer_shared_libraries_p (m_core_gdbarch
))
830 return TARGET_XFER_E_IO
;
833 *xfered_len
= gdbarch_core_xfer_shared_libraries (m_core_gdbarch
,
837 if (*xfered_len
== 0)
838 return TARGET_XFER_EOF
;
840 return TARGET_XFER_OK
;
845 case TARGET_OBJECT_LIBRARIES_AIX
:
846 if (m_core_gdbarch
!= nullptr
847 && gdbarch_core_xfer_shared_libraries_aix_p (m_core_gdbarch
))
850 return TARGET_XFER_E_IO
;
854 = gdbarch_core_xfer_shared_libraries_aix (m_core_gdbarch
,
858 if (*xfered_len
== 0)
859 return TARGET_XFER_EOF
;
861 return TARGET_XFER_OK
;
866 case TARGET_OBJECT_SPU
:
867 if (readbuf
&& annex
)
869 /* When the SPU contexts are stored in a core file, BFD
870 represents this with a fake section called
873 struct bfd_section
*section
;
875 char sectionstr
[100];
877 xsnprintf (sectionstr
, sizeof sectionstr
, "SPU/%s", annex
);
879 section
= bfd_get_section_by_name (core_bfd
, sectionstr
);
881 return TARGET_XFER_E_IO
;
883 size
= bfd_section_size (core_bfd
, section
);
885 return TARGET_XFER_EOF
;
891 return TARGET_XFER_EOF
;
892 if (!bfd_get_section_contents (core_bfd
, section
, readbuf
,
893 (file_ptr
) offset
, size
))
895 warning (_("Couldn't read SPU section in core file."));
896 return TARGET_XFER_E_IO
;
899 *xfered_len
= (ULONGEST
) size
;
900 return TARGET_XFER_OK
;
904 /* NULL annex requests list of all present spuids. */
905 struct spuid_list list
;
908 list
.offset
= offset
;
912 bfd_map_over_sections (core_bfd
, add_to_spuid_list
, &list
);
914 if (list
.written
== 0)
915 return TARGET_XFER_EOF
;
918 *xfered_len
= (ULONGEST
) list
.written
;
919 return TARGET_XFER_OK
;
922 return TARGET_XFER_E_IO
;
924 case TARGET_OBJECT_SIGNAL_INFO
:
927 if (m_core_gdbarch
!= nullptr
928 && gdbarch_core_xfer_siginfo_p (m_core_gdbarch
))
930 LONGEST l
= gdbarch_core_xfer_siginfo (m_core_gdbarch
, readbuf
,
937 return TARGET_XFER_EOF
;
939 return TARGET_XFER_OK
;
943 return TARGET_XFER_E_IO
;
946 return this->beneath ()->xfer_partial (object
, annex
, readbuf
,
947 writebuf
, offset
, len
,
954 /* Okay, let's be honest: threads gleaned from a core file aren't
955 exactly lively, are they? On the other hand, if we don't claim
956 that each & every one is alive, then we don't get any of them
957 to appear in an "info thread" command, which is quite a useful
961 core_target::thread_alive (ptid_t ptid
)
966 /* Ask the current architecture what it knows about this core file.
967 That will be used, in turn, to pick a better architecture. This
968 wrapper could be avoided if targets got a chance to specialize
971 const struct target_desc
*
972 core_target::read_description ()
974 if (m_core_gdbarch
&& gdbarch_core_read_description_p (m_core_gdbarch
))
976 const struct target_desc
*result
;
978 result
= gdbarch_core_read_description (m_core_gdbarch
, this, core_bfd
);
983 return this->beneath ()->read_description ();
987 core_target::pid_to_str (ptid_t ptid
)
989 struct inferior
*inf
;
992 /* The preferred way is to have a gdbarch/OS specific
994 if (m_core_gdbarch
!= nullptr
995 && gdbarch_core_pid_to_str_p (m_core_gdbarch
))
996 return gdbarch_core_pid_to_str (m_core_gdbarch
, ptid
);
998 /* Otherwise, if we don't have one, we'll just fallback to
999 "process", with normal_pid_to_str. */
1001 /* Try the LWPID field first. */
1004 return normal_pid_to_str (ptid_t (pid
));
1006 /* Otherwise, this isn't a "threaded" core -- use the PID field, but
1007 only if it isn't a fake PID. */
1008 inf
= find_inferior_ptid (ptid
);
1009 if (inf
!= NULL
&& !inf
->fake_pid_p
)
1010 return normal_pid_to_str (ptid
);
1012 /* No luck. We simply don't have a valid PID to print. */
1013 return "<main task>";
1017 core_target::thread_name (struct thread_info
*thr
)
1019 if (m_core_gdbarch
!= nullptr
1020 && gdbarch_core_thread_name_p (m_core_gdbarch
))
1021 return gdbarch_core_thread_name (m_core_gdbarch
, thr
);
1026 core_target::has_memory ()
1028 return (core_bfd
!= NULL
);
1032 core_target::has_stack ()
1034 return (core_bfd
!= NULL
);
1038 core_target::has_registers ()
1040 return (core_bfd
!= NULL
);
1043 /* Implement the to_info_proc method. */
1046 core_target::info_proc (const char *args
, enum info_proc_what request
)
1048 struct gdbarch
*gdbarch
= get_current_arch ();
1050 /* Since this is the core file target, call the 'core_info_proc'
1051 method on gdbarch, not 'info_proc'. */
1052 if (gdbarch_core_info_proc_p (gdbarch
))
1053 gdbarch_core_info_proc (gdbarch
, args
, request
);
1059 _initialize_corelow (void)
1061 add_target (core_target_info
, core_target_open
, filename_completer
);