1 1.1 christos /* Machine independent variables that describe the core file under GDB. 2 1.1 christos 3 1.11 christos Copyright (C) 1986-2024 Free Software Foundation, Inc. 4 1.1 christos 5 1.1 christos This file is part of GDB. 6 1.1 christos 7 1.1 christos This program is free software; you can redistribute it and/or modify 8 1.1 christos it under the terms of the GNU General Public License as published by 9 1.1 christos the Free Software Foundation; either version 3 of the License, or 10 1.1 christos (at your option) any later version. 11 1.1 christos 12 1.1 christos This program is distributed in the hope that it will be useful, 13 1.1 christos but WITHOUT ANY WARRANTY; without even the implied warranty of 14 1.1 christos MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 1.1 christos GNU General Public License for more details. 16 1.1 christos 17 1.1 christos You should have received a copy of the GNU General Public License 18 1.1 christos along with this program. If not, see <http://www.gnu.org/licenses/>. */ 19 1.1 christos 20 1.1 christos /* Interface routines for core, executable, etc. */ 21 1.1 christos 22 1.12 christos #ifndef GDB_GDBCORE_H 23 1.12 christos #define GDB_GDBCORE_H 24 1.1 christos 25 1.1 christos struct type; 26 1.1 christos struct regcache; 27 1.1 christos 28 1.1 christos #include "bfd.h" 29 1.1 christos #include "exec.h" 30 1.1 christos #include "target.h" 31 1.1 christos 32 1.1 christos /* Nonzero if there is a core file. */ 33 1.1 christos 34 1.1 christos extern int have_core_file_p (void); 35 1.1 christos 36 1.1 christos /* Report a memory error with error(). */ 37 1.1 christos 38 1.3 christos extern void memory_error (enum target_xfer_status status, CORE_ADDR memaddr); 39 1.1 christos 40 1.8 christos /* The string 'memory_error' would use as exception message. */ 41 1.1 christos 42 1.8 christos extern std::string memory_error_message (enum target_xfer_status err, 43 1.8 christos struct gdbarch *gdbarch, 44 1.8 christos CORE_ADDR memaddr); 45 1.1 christos 46 1.1 christos /* Like target_read_memory, but report an error if can't read. */ 47 1.1 christos 48 1.1 christos extern void read_memory (CORE_ADDR memaddr, gdb_byte *myaddr, ssize_t len); 49 1.1 christos 50 1.1 christos /* Like target_read_stack, but report an error if can't read. */ 51 1.1 christos 52 1.1 christos extern void read_stack (CORE_ADDR memaddr, gdb_byte *myaddr, ssize_t len); 53 1.1 christos 54 1.1 christos /* Like target_read_code, but report an error if can't read. */ 55 1.1 christos 56 1.1 christos extern void read_code (CORE_ADDR memaddr, gdb_byte *myaddr, ssize_t len); 57 1.1 christos 58 1.1 christos /* Read an integer from debugged memory, given address and number of 59 1.1 christos bytes. */ 60 1.1 christos 61 1.1 christos extern LONGEST read_memory_integer (CORE_ADDR memaddr, 62 1.1 christos int len, enum bfd_endian byte_order); 63 1.1 christos extern int safe_read_memory_integer (CORE_ADDR memaddr, int len, 64 1.1 christos enum bfd_endian byte_order, 65 1.1 christos LONGEST *return_value); 66 1.1 christos 67 1.1 christos /* Read an unsigned integer from debugged memory, given address and 68 1.1 christos number of bytes. */ 69 1.1 christos 70 1.1 christos extern ULONGEST read_memory_unsigned_integer (CORE_ADDR memaddr, 71 1.1 christos int len, 72 1.1 christos enum bfd_endian byte_order); 73 1.6 christos extern int safe_read_memory_unsigned_integer (CORE_ADDR memaddr, int len, 74 1.6 christos enum bfd_endian byte_order, 75 1.6 christos ULONGEST *return_value); 76 1.1 christos 77 1.1 christos /* Read an integer from debugged code memory, given address, 78 1.1 christos number of bytes, and byte order for code. */ 79 1.1 christos 80 1.1 christos extern LONGEST read_code_integer (CORE_ADDR memaddr, int len, 81 1.1 christos enum bfd_endian byte_order); 82 1.1 christos 83 1.1 christos /* Read an unsigned integer from debugged code memory, given address, 84 1.1 christos number of bytes, and byte order for code. */ 85 1.1 christos 86 1.1 christos extern ULONGEST read_code_unsigned_integer (CORE_ADDR memaddr, 87 1.1 christos int len, 88 1.1 christos enum bfd_endian byte_order); 89 1.1 christos 90 1.1 christos /* Read the pointer of type TYPE at ADDR, and return the address it 91 1.1 christos represents. */ 92 1.1 christos 93 1.1 christos CORE_ADDR read_memory_typed_address (CORE_ADDR addr, struct type *type); 94 1.1 christos 95 1.5 christos /* Same as target_write_memory, but report an error if can't 96 1.5 christos write. */ 97 1.1 christos 98 1.1 christos extern void write_memory (CORE_ADDR memaddr, const gdb_byte *myaddr, 99 1.1 christos ssize_t len); 100 1.1 christos 101 1.1 christos /* Same as write_memory, but notify 'memory_changed' observers. */ 102 1.1 christos 103 1.1 christos extern void write_memory_with_notification (CORE_ADDR memaddr, 104 1.1 christos const bfd_byte *myaddr, 105 1.1 christos ssize_t len); 106 1.1 christos 107 1.1 christos /* Store VALUE at ADDR in the inferior as a LEN-byte unsigned integer. */ 108 1.1 christos extern void write_memory_unsigned_integer (CORE_ADDR addr, int len, 109 1.10 christos enum bfd_endian byte_order, 110 1.1 christos ULONGEST value); 111 1.1 christos 112 1.1 christos /* Store VALUE at ADDR in the inferior as a LEN-byte unsigned integer. */ 113 1.1 christos extern void write_memory_signed_integer (CORE_ADDR addr, int len, 114 1.10 christos enum bfd_endian byte_order, 115 1.10 christos LONGEST value); 116 1.1 christos 117 1.1 christos 119 1.1 christos /* Hook for "file_command", which is more useful than above 120 1.1 christos (because it is invoked AFTER symbols are read, not before). */ 121 1.8 christos 122 1.1 christos extern void (*deprecated_file_changed_hook) (const char *filename); 123 1.1 christos 124 1.1 christos /* Whether to open exec and core files read-only or read-write. */ 125 1.9 christos 126 1.1 christos extern bool write_files; 127 1.8 christos 128 1.1 christos extern void core_file_command (const char *filename, int from_tty); 129 1.3 christos 130 1.1 christos extern void exec_file_attach (const char *filename, int from_tty); 131 1.5 christos 132 1.5 christos /* If the filename of the main executable is unknown, attempt to 133 1.5 christos determine it. If a filename is determined, proceed as though 134 1.6 christos it was just specified with the "file" command. Do nothing if 135 1.6 christos the filename of the main executable is already known. 136 1.5 christos DEFER_BP_RESET uses SYMFILE_DEFER_BP_RESET for the main symbol file. */ 137 1.6 christos 138 1.5 christos extern void exec_file_locate_attach (int pid, int defer_bp_reset, int from_tty); 139 1.1 christos 140 1.1 christos extern void validate_files (void); 141 1.9 christos 142 1.9 christos /* Give the user a message if the current exec file does not match the exec 143 1.9 christos file determined from the target. In case of mismatch, ask the user 144 1.9 christos if the exec file determined from target must be loaded. */ 145 1.9 christos extern void validate_exec_file (int from_tty); 146 1.1 christos 147 1.1 christos /* The current default bfd target. */ 148 1.9 christos 149 1.1 christos extern const char *gnutarget; 150 1.7 christos 151 1.1 christos extern void set_gnutarget (const char *); 152 1.8 christos 153 1.8 christos /* Build either a single-thread or multi-threaded section name for 154 1.8 christos PTID. 155 1.8 christos 156 1.8 christos If ptid's lwp member is zero, we want to do the single-threaded 157 1.8 christos thing: look for a section named NAME (as passed to the 158 1.8 christos constructor). If ptid's lwp member is non-zero, we'll want do the 159 1.8 christos multi-threaded thing: look for a section named "NAME/LWP", where 160 1.8 christos LWP is the shortest ASCII decimal representation of ptid's lwp 161 1.8 christos member. */ 162 1.8 christos 163 1.8 christos class thread_section_name 164 1.8 christos { 165 1.8 christos public: 166 1.8 christos /* NAME is the single-threaded section name. If PTID represents an 167 1.8 christos LWP, then the build section name is "NAME/LWP", otherwise it's 168 1.8 christos just "NAME" unmodified. */ 169 1.8 christos thread_section_name (const char *name, ptid_t ptid) 170 1.8 christos { 171 1.8 christos if (ptid.lwp_p ()) 172 1.8 christos { 173 1.8 christos m_storage = string_printf ("%s/%ld", name, ptid.lwp ()); 174 1.8 christos m_section_name = m_storage.c_str (); 175 1.8 christos } 176 1.8 christos else 177 1.8 christos m_section_name = name; 178 1.8 christos } 179 1.8 christos 180 1.8 christos /* Return the computed section name. The result is valid as long as 181 1.8 christos this thread_section_name object is live. */ 182 1.8 christos const char *c_str () const 183 1.8 christos { return m_section_name; } 184 1.8 christos 185 1.8 christos DISABLE_COPY_AND_ASSIGN (thread_section_name); 186 1.8 christos 187 1.8 christos private: 188 1.8 christos /* Either a pointer into M_STORAGE, or a pointer to the name passed 189 1.8 christos as parameter to the constructor. */ 190 1.8 christos const char *m_section_name; 191 1.8 christos /* If we need to build a new section name, this is where we store 192 1.8 christos it. */ 193 1.8 christos std::string m_storage; 194 1.8 christos }; 195 1.12 christos 196 1.12 christos /* Type returned from core_target_find_mapped_file. Holds information 197 1.12 christos about a mapped file that was processed when a core file was initially 198 1.12 christos loaded. */ 199 1.12 christos struct core_target_mapped_file_info 200 1.12 christos { 201 1.12 christos /* Constructor. BUILD_ID is not nullptr, and is the build-id for the 202 1.12 christos mapped file. FILENAME is the location of the file that GDB loaded to 203 1.12 christos provide the mapped file. This might be different from the name of the 204 1.12 christos mapped file mentioned in the core file, e.g. if GDB downloads a file 205 1.12 christos from debuginfod then FILENAME would point into the debuginfod client 206 1.12 christos cache. The FILENAME can be the empty string if GDB was unable to find 207 1.12 christos a file to provide the mapped file. */ 208 1.12 christos 209 1.12 christos core_target_mapped_file_info (const bfd_build_id *build_id, 210 1.12 christos const std::string filename) 211 1.12 christos : m_build_id (build_id), 212 1.12 christos m_filename (filename) 213 1.12 christos { 214 1.12 christos gdb_assert (m_build_id != nullptr); 215 1.12 christos } 216 1.12 christos 217 1.12 christos /* The build-id for this mapped file. */ 218 1.12 christos 219 1.12 christos const bfd_build_id * 220 1.12 christos build_id () const 221 1.12 christos { 222 1.12 christos return m_build_id; 223 1.12 christos } 224 1.12 christos 225 1.12 christos /* The file GDB used to provide this mapped file. */ 226 1.12 christos 227 1.12 christos const std::string & 228 1.12 christos filename () const 229 1.12 christos { 230 1.12 christos return m_filename; 231 1.12 christos } 232 1.12 christos 233 1.12 christos private: 234 1.12 christos const bfd_build_id *m_build_id = nullptr; 235 1.12 christos const std::string m_filename; 236 1.12 christos }; 237 1.12 christos 238 1.12 christos /* If the current inferior has a core_target for its process target, then 239 1.12 christos lookup information about a mapped file that was discovered when the 240 1.12 christos core file was loaded. 241 1.12 christos 242 1.12 christos The FILENAME is the file we're looking for. The ADDR, if provided, is a 243 1.12 christos mapped address within the inferior which is known to be part of the file 244 1.12 christos we are looking for. 245 1.12 christos 246 1.12 christos As an example, when loading shared libraries this function can be 247 1.12 christos called, in that case FILENAME will be the name of the shared library 248 1.12 christos that GDB is trying to load and ADDR will be an inferior address which is 249 1.12 christos part of the shared library we are looking for. 250 1.12 christos 251 1.12 christos This function looks for a mapped file which matches FILENAME and/or 252 1.12 christos which covers ADDR and returns information about that file. 253 1.12 christos 254 1.12 christos The returned information includes the name of the mapped file if known 255 1.12 christos and the build-id for the mapped file if known. 256 1.12 christos 257 1.12 christos */ 258 1.12 christos std::optional<core_target_mapped_file_info> 259 1.12 christos core_target_find_mapped_file (const char *filename, 260 1.12 christos std::optional<CORE_ADDR> addr); 261 1.12 christos 262 #endif /* GDB_GDBCORE_H */ 263