1 /* Machine independent variables that describe the core file under GDB.
3 Copyright (C) 1986-2024 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/>. */
20 /* Interface routines for core, executable, etc. */
22 #if !defined (GDBCORE_H)
32 /* Nonzero if there is a core file. */
34 extern int have_core_file_p (void);
36 /* Report a memory error with error(). */
38 extern void memory_error (enum target_xfer_status status
, CORE_ADDR memaddr
);
40 /* The string 'memory_error' would use as exception message. */
42 extern std::string
memory_error_message (enum target_xfer_status err
,
43 struct gdbarch
*gdbarch
,
46 /* Like target_read_memory, but report an error if can't read. */
48 extern void read_memory (CORE_ADDR memaddr
, gdb_byte
*myaddr
, ssize_t len
);
50 /* Like target_read_stack, but report an error if can't read. */
52 extern void read_stack (CORE_ADDR memaddr
, gdb_byte
*myaddr
, ssize_t len
);
54 /* Like target_read_code, but report an error if can't read. */
56 extern void read_code (CORE_ADDR memaddr
, gdb_byte
*myaddr
, ssize_t len
);
58 /* Read an integer from debugged memory, given address and number of
61 extern LONGEST
read_memory_integer (CORE_ADDR memaddr
,
62 int len
, enum bfd_endian byte_order
);
63 extern int safe_read_memory_integer (CORE_ADDR memaddr
, int len
,
64 enum bfd_endian byte_order
,
65 LONGEST
*return_value
);
67 /* Read an unsigned integer from debugged memory, given address and
70 extern ULONGEST
read_memory_unsigned_integer (CORE_ADDR memaddr
,
72 enum bfd_endian byte_order
);
73 extern int safe_read_memory_unsigned_integer (CORE_ADDR memaddr
, int len
,
74 enum bfd_endian byte_order
,
75 ULONGEST
*return_value
);
77 /* Read an integer from debugged code memory, given address,
78 number of bytes, and byte order for code. */
80 extern LONGEST
read_code_integer (CORE_ADDR memaddr
, int len
,
81 enum bfd_endian byte_order
);
83 /* Read an unsigned integer from debugged code memory, given address,
84 number of bytes, and byte order for code. */
86 extern ULONGEST
read_code_unsigned_integer (CORE_ADDR memaddr
,
88 enum bfd_endian byte_order
);
90 /* Read the pointer of type TYPE at ADDR, and return the address it
93 CORE_ADDR
read_memory_typed_address (CORE_ADDR addr
, struct type
*type
);
95 /* Same as target_write_memory, but report an error if can't
98 extern void write_memory (CORE_ADDR memaddr
, const gdb_byte
*myaddr
,
101 /* Same as write_memory, but notify 'memory_changed' observers. */
103 extern void write_memory_with_notification (CORE_ADDR memaddr
,
104 const bfd_byte
*myaddr
,
107 /* Store VALUE at ADDR in the inferior as a LEN-byte unsigned integer. */
108 extern void write_memory_unsigned_integer (CORE_ADDR addr
, int len
,
109 enum bfd_endian byte_order
,
112 /* Store VALUE at ADDR in the inferior as a LEN-byte unsigned integer. */
113 extern void write_memory_signed_integer (CORE_ADDR addr
, int len
,
114 enum bfd_endian byte_order
,
118 /* Hook for "file_command", which is more useful than above
119 (because it is invoked AFTER symbols are read, not before). */
121 extern void (*deprecated_file_changed_hook
) (const char *filename
);
123 /* Whether to open exec and core files read-only or read-write. */
125 extern bool write_files
;
127 /* Open and set up the core file bfd. */
129 extern void core_target_open (const char *arg
, int from_tty
);
131 extern void core_file_command (const char *filename
, int from_tty
);
133 extern void exec_file_attach (const char *filename
, int from_tty
);
135 /* If the filename of the main executable is unknown, attempt to
136 determine it. If a filename is determined, proceed as though
137 it was just specified with the "file" command. Do nothing if
138 the filename of the main executable is already known.
139 DEFER_BP_RESET uses SYMFILE_DEFER_BP_RESET for the main symbol file. */
141 extern void exec_file_locate_attach (int pid
, int defer_bp_reset
, int from_tty
);
143 extern void validate_files (void);
145 /* Give the user a message if the current exec file does not match the exec
146 file determined from the target. In case of mismatch, ask the user
147 if the exec file determined from target must be loaded. */
148 extern void validate_exec_file (int from_tty
);
150 /* The current default bfd target. */
152 extern const char *gnutarget
;
154 extern void set_gnutarget (const char *);
156 /* Build either a single-thread or multi-threaded section name for
159 If ptid's lwp member is zero, we want to do the single-threaded
160 thing: look for a section named NAME (as passed to the
161 constructor). If ptid's lwp member is non-zero, we'll want do the
162 multi-threaded thing: look for a section named "NAME/LWP", where
163 LWP is the shortest ASCII decimal representation of ptid's lwp
166 class thread_section_name
169 /* NAME is the single-threaded section name. If PTID represents an
170 LWP, then the build section name is "NAME/LWP", otherwise it's
171 just "NAME" unmodified. */
172 thread_section_name (const char *name
, ptid_t ptid
)
176 m_storage
= string_printf ("%s/%ld", name
, ptid
.lwp ());
177 m_section_name
= m_storage
.c_str ();
180 m_section_name
= name
;
183 /* Return the computed section name. The result is valid as long as
184 this thread_section_name object is live. */
185 const char *c_str () const
186 { return m_section_name
; }
188 DISABLE_COPY_AND_ASSIGN (thread_section_name
);
191 /* Either a pointer into M_STORAGE, or a pointer to the name passed
192 as parameter to the constructor. */
193 const char *m_section_name
;
194 /* If we need to build a new section name, this is where we store
196 std::string m_storage
;
199 /* Type returned from core_target_find_mapped_file. Holds information
200 about a mapped file that was processed when a core file was initially
202 struct core_target_mapped_file_info
204 /* Constructor. BUILD_ID is not nullptr, and is the build-id for the
205 mapped file. FILENAME is the location of the file that GDB loaded to
206 provide the mapped file. This might be different from the name of the
207 mapped file mentioned in the core file, e.g. if GDB downloads a file
208 from debuginfod then FILENAME would point into the debuginfod client
209 cache. The FILENAME can be the empty string if GDB was unable to find
210 a file to provide the mapped file. */
212 core_target_mapped_file_info (const bfd_build_id
*build_id
,
213 const std::string filename
)
214 : m_build_id (build_id
),
215 m_filename (filename
)
217 gdb_assert (m_build_id
!= nullptr);
220 /* The build-id for this mapped file. */
228 /* The file GDB used to provide this mapped file. */
237 const bfd_build_id
*m_build_id
= nullptr;
238 const std::string m_filename
;
241 /* If the current inferior has a core_target for its process target, then
242 lookup information about a mapped file that was discovered when the
243 core file was loaded.
245 The FILENAME is the file we're looking for. The ADDR, if provided, is a
246 mapped address within the inferior which is known to be part of the file
249 As an example, when loading shared libraries this function can be
250 called, in that case FILENAME will be the name of the shared library
251 that GDB is trying to load and ADDR will be an inferior address which is
252 part of the shared library we are looking for.
254 This function looks for a mapped file which matches FILENAME and/or
255 which covers ADDR and returns information about that file.
257 The returned information includes the name of the mapped file if known
258 and the build-id for the mapped file if known.
261 std::optional
<core_target_mapped_file_info
>
262 core_target_find_mapped_file (const char *filename
,
263 std::optional
<CORE_ADDR
> addr
);
265 #endif /* !defined (GDBCORE_H) */