GDB (xrefs)

/tmp/gdb-8.1/gdb/gdbcore.h
Go to the documentation of this file.
1 /* Machine independent variables that describe the core file under GDB.
2
3 Copyright (C) 1986-2018 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 /* Interface routines for core, executable, etc. */
21
22 #if !defined (GDBCORE_H)
23 #define GDBCORE_H 1
24
25 struct type;
26 struct regcache;
27
28 #include "bfd.h"
29 #include "exec.h"
30 #include "target.h"
31
32 /* Nonzero if there is a core file. */
33
34 extern int have_core_file_p (void);
35
36 /* Report a memory error with error(). */
37
38 extern void memory_error (enum target_xfer_status status, CORE_ADDR memaddr);
39
40 /* The string 'memory_error' would use as exception message. */
41
42 extern std::string memory_error_message (enum target_xfer_status err,
43 struct gdbarch *gdbarch,
44 CORE_ADDR memaddr);
45
46 /* Like target_read_memory, but report an error if can't read. */
47
48 extern void read_memory (CORE_ADDR memaddr, gdb_byte *myaddr, ssize_t len);
49
50 /* Like target_read_stack, but report an error if can't read. */
51
52 extern void read_stack (CORE_ADDR memaddr, gdb_byte *myaddr, ssize_t len);
53
54 /* Like target_read_code, but report an error if can't read. */
55
56 extern void read_code (CORE_ADDR memaddr, gdb_byte *myaddr, ssize_t len);
57
58 /* Read an integer from debugged memory, given address and number of
59 bytes. */
60
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);
66
67 /* Read an unsigned integer from debugged memory, given address and
68 number of bytes. */
69
70 extern ULONGEST read_memory_unsigned_integer (CORE_ADDR memaddr,
71 int len,
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);
76
77 /* Read an integer from debugged code memory, given address,
78 number of bytes, and byte order for code. */
79
80 extern LONGEST read_code_integer (CORE_ADDR memaddr, int len,
81 enum bfd_endian byte_order);
82
83 /* Read an unsigned integer from debugged code memory, given address,
84 number of bytes, and byte order for code. */
85
86 extern ULONGEST read_code_unsigned_integer (CORE_ADDR memaddr,
87 int len,
88 enum bfd_endian byte_order);
89
90 /* Read a null-terminated string from the debuggee's memory, given
91 address, a buffer into which to place the string, and the maximum
92 available space. */
93
94 extern void read_memory_string (CORE_ADDR, char *, int);
95
96 /* Read the pointer of type TYPE at ADDR, and return the address it
97 represents. */
98
99 CORE_ADDR read_memory_typed_address (CORE_ADDR addr, struct type *type);
100
101 /* Same as target_write_memory, but report an error if can't
102 write. */
103
104 extern void write_memory (CORE_ADDR memaddr, const gdb_byte *myaddr,
105 ssize_t len);
106
107 /* Same as write_memory, but notify 'memory_changed' observers. */
108
109 extern void write_memory_with_notification (CORE_ADDR memaddr,
110 const bfd_byte *myaddr,
111 ssize_t len);
112
113 /* Store VALUE at ADDR in the inferior as a LEN-byte unsigned integer. */
114 extern void write_memory_unsigned_integer (CORE_ADDR addr, int len,
115 enum bfd_endian byte_order,
116 ULONGEST value);
117
118 /* Store VALUE at ADDR in the inferior as a LEN-byte unsigned integer. */
119 extern void write_memory_signed_integer (CORE_ADDR addr, int len,
120 enum bfd_endian byte_order,
121 LONGEST value);
122
123 /* Hook for `exec_file_command' command to call. */
124
125 extern void (*deprecated_exec_file_display_hook) (const char *filename);
126
127 /* Hook for "file_command", which is more useful than above
128 (because it is invoked AFTER symbols are read, not before). */
129
130 extern void (*deprecated_file_changed_hook) (const char *filename);
131
132 extern void specify_exec_file_hook (void (*hook) (const char *filename));
133
134 /* Binary File Diddler for the core file. */
135
136 extern bfd *core_bfd;
137
138 extern struct target_ops *core_target;
139
140 /* Whether to open exec and core files read-only or read-write. */
141
142 extern int write_files;
143
144 extern void core_file_command (const char *filename, int from_tty);
145
146 extern void exec_file_attach (const char *filename, int from_tty);
147
148 /* If the filename of the main executable is unknown, attempt to
149 determine it. If a filename is determined, proceed as though
150 it was just specified with the "file" command. Do nothing if
151 the filename of the main executable is already known.
152 DEFER_BP_RESET uses SYMFILE_DEFER_BP_RESET for the main symbol file. */
153
154 extern void exec_file_locate_attach (int pid, int defer_bp_reset, int from_tty);
155
156 extern void exec_file_clear (int from_tty);
157
158 extern void validate_files (void);
159
160 /* The current default bfd target. */
161
162 extern char *gnutarget;
163
164 extern void set_gnutarget (const char *);
165
166 /* Structure to keep track of core register reading functions for
167 various core file types. */
168
169 struct core_fns
170 {
171
172 /* BFD flavour that a core file handler is prepared to read. This
173 can be used by the handler's core tasting function as a first
174 level filter to reject BFD's that don't have the right
175 flavour. */
176
177 enum bfd_flavour core_flavour;
178
179 /* Core file handler function to call to recognize corefile
180 formats that BFD rejects. Some core file format just don't fit
181 into the BFD model, or may require other resources to identify
182 them, that simply aren't available to BFD (such as symbols from
183 another file). Returns nonzero if the handler recognizes the
184 format, zero otherwise. */
185
186 int (*check_format) (bfd *);
187
188 /* Core file handler function to call to ask if it can handle a
189 given core file format or not. Returns zero if it can't,
190 nonzero otherwise. */
191
192 int (*core_sniffer) (struct core_fns *, bfd *);
193
194 /* Extract the register values out of the core file and supply them
195 into REGCACHE.
196
197 CORE_REG_SECT points to the register values themselves, read into
198 memory.
199
200 CORE_REG_SIZE is the size of that area.
201
202 WHICH says which set of registers we are handling:
203 0 --- integer registers
204 2 --- floating-point registers, on machines where they are
205 discontiguous
206 3 --- extended floating-point registers, on machines where
207 these are present in yet a third area. (GNU/Linux uses
208 this to get at the SSE registers.)
209
210 REG_ADDR is the offset from u.u_ar0 to the register values relative to
211 core_reg_sect. This is used with old-fashioned core files to locate the
212 registers in a large upage-plus-stack ".reg" section. Original upage
213 address X is at location core_reg_sect+x+reg_addr. */
214
215 void (*core_read_registers) (struct regcache *regcache,
216 char *core_reg_sect,
217 unsigned core_reg_size,
218 int which, CORE_ADDR reg_addr);
219
220 /* Finds the next struct core_fns. They are allocated and
221 initialized in whatever module implements the functions pointed
222 to; an initializer calls deprecated_add_core_fns to add them to
223 the global chain. */
224
225 struct core_fns *next;
226
227 };
228
229 /* Build either a single-thread or multi-threaded section name for
230 PTID.
231
232 If ptid's lwp member is zero, we want to do the single-threaded
233 thing: look for a section named NAME (as passed to the
234 constructor). If ptid's lwp member is non-zero, we'll want do the
235 multi-threaded thing: look for a section named "NAME/LWP", where
236 LWP is the shortest ASCII decimal representation of ptid's lwp
237 member. */
238
239 class thread_section_name
240 {
241 public:
242 /* NAME is the single-threaded section name. If PTID represents an
243 LWP, then the build section name is "NAME/LWP", otherwise it's
244 just "NAME" unmodified. */
245 thread_section_name (const char *name, ptid_t ptid)
246 {
247 if (ptid.lwp_p ())
248 {
249 m_storage = string_printf ("%s/%ld", name, ptid.lwp ());
250 m_section_name = m_storage.c_str ();
251 }
252 else
253 m_section_name = name;
254 }
255
256 /* Return the computed section name. The result is valid as long as
257 this thread_section_name object is live. */
258 const char *c_str () const
259 { return m_section_name; }
260
261 DISABLE_COPY_AND_ASSIGN (thread_section_name);
262
263 private:
264 /* Either a pointer into M_STORAGE, or a pointer to the name passed
265 as parameter to the constructor. */
266 const char *m_section_name;
267 /* If we need to build a new section name, this is where we store
268 it. */
269 std::string m_storage;
270 };
271
272 /* NOTE: cagney/2004-04-05: Replaced by "regset.h" and
273 regset_from_core_section(). */
274 extern void deprecated_add_core_fns (struct core_fns *cf);
275 extern int default_core_sniffer (struct core_fns *cf, bfd * abfd);
276 extern int default_check_format (bfd * abfd);
277
278 #endif /* !defined (GDBCORE_H) */
memory_error_message
std::string memory_error_message(enum target_xfer_status err, struct gdbarch *gdbarch, CORE_ADDR memaddr)
Definition: corefile.c:181
err
mach_port_t mach_port_t name mach_port_t mach_port_t name kern_return_t err
Definition: gnu-nat.c:1822
gdbarch
Definition: gdbarch.c:127
string
const char * string
Definition: signals.c:50
read_code
void read_code(CORE_ADDR memaddr, gdb_byte *myaddr, ssize_t len)
Definition: corefile.c:274
read_memory
void read_memory(CORE_ADDR memaddr, gdb_byte *myaddr, ssize_t len)
Definition: corefile.c:258
deprecated_add_core_fns
void deprecated_add_core_fns(struct core_fns *cf)
Definition: corelow.c:102
ptid_t::lwp
constexpr long lwp() const
Definition: ptid.h:63
core_fns::core_read_registers
void(* core_read_registers)(struct regcache *regcache, char *core_reg_sect, unsigned core_reg_size, int which, CORE_ADDR reg_addr)
Definition: gdbcore.h:215
default_check_format
int default_check_format(bfd *abfd)
Definition: corelow.c:162
CORE_ADDR
bfd_vma CORE_ADDR
Definition: common-types.h:41
read_memory_integer
LONGEST read_memory_integer(CORE_ADDR memaddr, int len, enum bfd_endian byte_order)
Definition: corefile.c:316
pid
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:1824
regcache::regcache
regcache(gdbarch *gdbarch)
Definition: regcache.h:235
core_fns
Definition: gdbcore.h:169
core_fns::next
struct core_fns * next
Definition: gdbcore.h:225
core_target
struct target_ops * core_target
Definition: corefile.c:58
read_stack
void read_stack(CORE_ADDR memaddr, gdb_byte *myaddr, ssize_t len)
Definition: corefile.c:266
write_files
int write_files
Definition: exec.c:62
read_code_integer
LONGEST read_code_integer(CORE_ADDR memaddr, int len, enum bfd_endian byte_order)
Definition: corefile.c:336
thread_section_name::DISABLE_COPY_AND_ASSIGN
DISABLE_COPY_AND_ASSIGN(thread_section_name)
thread_section_name::thread_section_name
thread_section_name(const char *name, ptid_t ptid)
Definition: gdbcore.h:245
write_memory
void write_memory(CORE_ADDR memaddr, const gdb_byte *myaddr, ssize_t len)
Definition: corefile.c:394
safe_read_memory_unsigned_integer
int safe_read_memory_unsigned_integer(CORE_ADDR memaddr, int len, enum bfd_endian byte_order, ULONGEST *return_value)
Definition: corefile.c:302
exec_file_clear
void exec_file_clear(int from_tty)
Definition: exec.c:121
core_bfd
bfd * core_bfd
Definition: corefile.c:54
name
const char *const name
Definition: aarch64-tdep.c:76
memory_error
void memory_error(enum target_xfer_status status, CORE_ADDR memaddr)
Definition: corefile.c:205
target_ops
Definition: target.h:412
read_memory_unsigned_integer
ULONGEST read_memory_unsigned_integer(CORE_ADDR memaddr, int len, enum bfd_endian byte_order)
Definition: corefile.c:326
ptid_t
Definition: ptid.h:35
core_fns::core_sniffer
int(* core_sniffer)(struct core_fns *, bfd *)
Definition: gdbcore.h:192
target_xfer_status
target_xfer_status
Definition: target.h:206
type
Definition: gdbtypes.h:749
thread_section_name::m_storage
std::string m_storage
Definition: gdbcore.h:269
read_memory_string
void read_memory_string(CORE_ADDR, char *, int)
Definition: corefile.c:356
status
mach_port_t mach_port_t name mach_port_t mach_port_t name kern_return_t int status
Definition: gnu-nat.c:1822
validate_files
void validate_files(void)
Definition: corefile.c:153
core_file_command
void core_file_command(const char *filename, int from_tty)
Definition: corefile.c:64
thread_section_name::c_str
const char * c_str() const
Definition: gdbcore.h:258
core_fns::check_format
int(* check_format)(bfd *)
Definition: gdbcore.h:186
value
Definition: value.c:169
write_memory_signed_integer
void write_memory_signed_integer(CORE_ADDR addr, int len, enum bfd_endian byte_order, LONGEST value)
Definition: corefile.c:430
gdb_byte
bfd_byte gdb_byte
Definition: common-types.h:38
read_code_unsigned_integer
ULONGEST read_code_unsigned_integer(CORE_ADDR memaddr, int len, enum bfd_endian byte_order)
Definition: corefile.c:346
thread_section_name::m_section_name
const char * m_section_name
Definition: gdbcore.h:266
exec.h
ptid_t::lwp_p
constexpr bool lwp_p() const
Definition: ptid.h:58
core_fns::core_flavour
enum bfd_flavour core_flavour
Definition: gdbcore.h:177
deprecated_exec_file_display_hook
void(* deprecated_exec_file_display_hook)(const char *filename)
Definition: corefile.c:47
target.h
read_memory_typed_address
CORE_ADDR read_memory_typed_address(CORE_ADDR addr, struct type *type)
Definition: corefile.c:383
string_printf
std::string string_printf(const char *fmt,...)
Definition: common-utils.c:150
specify_exec_file_hook
void specify_exec_file_hook(void(*hook)(const char *filename))
write_memory_with_notification
void write_memory_with_notification(CORE_ADDR memaddr, const bfd_byte *myaddr, ssize_t len)
Definition: corefile.c:407
ULONGEST
unsigned long long ULONGEST
Definition: common-types.h:53
have_core_file_p
int have_core_file_p(void)
default_core_sniffer
int default_core_sniffer(struct core_fns *cf, bfd *abfd)
Definition: corelow.c:113
regcache
Definition: regcache.h:232
set_gnutarget
void set_gnutarget(const char *)
Definition: corefile.c:497
exec_file_locate_attach
void exec_file_locate_attach(int pid, int defer_bp_reset, int from_tty)
Definition: exec.c:191
exec_file_attach
void exec_file_attach(const char *filename, int from_tty)
Definition: exec.c:244
gnutarget
char * gnutarget
Definition: corefile.c:442
thread_section_name
Definition: gdbcore.h:239
LONGEST
long long LONGEST
Definition: common-types.h:52
safe_read_memory_integer
int safe_read_memory_integer(CORE_ADDR memaddr, int len, enum bfd_endian byte_order, LONGEST *return_value)
Definition: corefile.c:284
deprecated_file_changed_hook
void(* deprecated_file_changed_hook)(const char *filename)
Definition: exec.c:48
write_memory_unsigned_integer
void write_memory_unsigned_integer(CORE_ADDR addr, int len, enum bfd_endian byte_order, ULONGEST value)
Definition: corefile.c:417