1 1.1 christos /* This file is automatically generated. DO NOT EDIT! */ 2 1.11 christos /* Generated from: NetBSD: mknative-gdb,v 1.17 2024/08/18 03:47:55 rin Exp */ 3 1.8 christos /* Generated from: NetBSD: mknative.common,v 1.16 2018/04/15 15:13:37 christos Exp */ 4 1.1 christos 5 1.1 christos /* JIT declarations for GDB, the GNU Debugger. 6 1.1 christos 7 1.11 christos Copyright (C) 2011-2024 Free Software Foundation, Inc. 8 1.1 christos 9 1.1 christos This file is part of GDB. 10 1.1 christos 11 1.1 christos This program is free software; you can redistribute it and/or modify 12 1.1 christos it under the terms of the GNU General Public License as published by 13 1.1 christos the Free Software Foundation; either version 3 of the License, or 14 1.1 christos (at your option) any later version. 15 1.1 christos 16 1.1 christos This program is distributed in the hope that it will be useful, 17 1.1 christos but WITHOUT ANY WARRANTY; without even the implied warranty of 18 1.1 christos MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 1.1 christos GNU General Public License for more details. 20 1.1 christos 21 1.1 christos You should have received a copy of the GNU General Public License 22 1.1 christos along with this program. If not, see <http://www.gnu.org/licenses/>. */ 23 1.1 christos 24 1.1 christos #ifndef GDB_JIT_READER_H 25 1.1 christos #define GDB_JIT_READER_H 26 1.1 christos 27 1.1 christos #ifdef __cplusplus 28 1.1 christos extern "C" { 29 1.1 christos #endif 30 1.1 christos 31 1.1 christos /* Versioning information. See gdb_reader_funcs. */ 32 1.1 christos 33 1.1 christos #define GDB_READER_INTERFACE_VERSION 1 34 1.1 christos 35 1.1 christos /* Readers must be released under a GPL compatible license. To 36 1.1 christos declare that the reader is indeed released under a GPL compatible 37 1.1 christos license, invoke the macro GDB_DECLARE_GPL_COMPATIBLE in a source 38 1.1 christos file. */ 39 1.1 christos 40 1.1 christos #ifdef __cplusplus 41 1.1 christos #define GDB_DECLARE_GPL_COMPATIBLE_READER \ 42 1.1 christos extern "C" { \ 43 1.1 christos extern int plugin_is_GPL_compatible (void); \ 44 1.1 christos extern int plugin_is_GPL_compatible (void) \ 45 1.1 christos { \ 46 1.1 christos return 0; \ 47 1.1 christos } \ 48 1.1 christos } 49 1.1 christos 50 1.1 christos #else 51 1.1 christos 52 1.1 christos #define GDB_DECLARE_GPL_COMPATIBLE_READER \ 53 1.1 christos extern int plugin_is_GPL_compatible (void); \ 54 1.1 christos extern int plugin_is_GPL_compatible (void) \ 55 1.1 christos { \ 56 1.1 christos return 0; \ 57 1.1 christos } 58 1.1 christos 59 1.1 christos #endif 60 1.1 christos 61 1.1 christos /* Represents an address on the target system. */ 62 1.1 christos 63 1.1 christos typedef unsigned long long GDB_CORE_ADDR; 64 1.1 christos 65 1.1 christos /* Return status codes. */ 66 1.1 christos 67 1.1 christos enum gdb_status { 68 1.1 christos GDB_FAIL = 0, 69 1.1 christos GDB_SUCCESS = 1 70 1.1 christos }; 71 1.1 christos 72 1.1 christos struct gdb_object; 73 1.1 christos struct gdb_symtab; 74 1.1 christos struct gdb_block; 75 1.1 christos struct gdb_symbol_callbacks; 76 1.1 christos 77 1.1 christos /* An array of these are used to represent a map from code addresses to line 78 1.1 christos numbers in the source file. */ 79 1.1 christos 80 1.1 christos struct gdb_line_mapping 81 1.1 christos { 82 1.1 christos int line; 83 1.1 christos GDB_CORE_ADDR pc; 84 1.1 christos }; 85 1.1 christos 86 1.1 christos /* Create a new GDB code object. Each code object can have one or 87 1.1 christos more symbol tables, each representing a compiled source file. */ 88 1.1 christos 89 1.1 christos typedef struct gdb_object *(gdb_object_open) (struct gdb_symbol_callbacks *cb); 90 1.1 christos 91 1.1 christos /* The callback used to create new symbol table. CB is the 92 1.1 christos gdb_symbol_callbacks which the structure is part of. FILE_NAME is 93 1.1 christos an (optionally NULL) file name to associate with this new symbol 94 1.1 christos table. 95 1.1 christos 96 1.1 christos Returns a new instance to gdb_symtab that can later be passed to 97 1.1 christos gdb_block_new, gdb_symtab_add_line_mapping and gdb_symtab_close. */ 98 1.1 christos 99 1.1 christos typedef struct gdb_symtab *(gdb_symtab_open) (struct gdb_symbol_callbacks *cb, 100 1.1 christos struct gdb_object *obj, 101 1.1 christos const char *file_name); 102 1.1 christos 103 1.1 christos /* Creates a new block in a given symbol table. A symbol table is a 104 1.1 christos forest of blocks, each block representing an code address range and 105 1.1 christos a corresponding (optionally NULL) NAME. In case the block 106 1.1 christos corresponds to a function, the NAME passed should be the name of 107 1.1 christos the function. 108 1.1 christos 109 1.1 christos If the new block to be created is a child of (i.e. is nested in) 110 1.1 christos another block, the parent block can be passed in PARENT. SYMTAB is 111 1.1 christos the symbol table the new block is to belong in. BEGIN, END is the 112 1.1 christos code address range the block corresponds to. 113 1.1 christos 114 1.1 christos Returns a new instance of gdb_block, which, as of now, has no use. 115 1.1 christos Note that the gdb_block returned must not be freed by the 116 1.1 christos caller. */ 117 1.1 christos 118 1.1 christos typedef struct gdb_block *(gdb_block_open) (struct gdb_symbol_callbacks *cb, 119 1.1 christos struct gdb_symtab *symtab, 120 1.1 christos struct gdb_block *parent, 121 1.1 christos GDB_CORE_ADDR begin, 122 1.1 christos GDB_CORE_ADDR end, 123 1.1 christos const char *name); 124 1.1 christos 125 1.1 christos /* Adds a PC to line number mapping for the symbol table SYMTAB. 126 1.1 christos NLINES is the number of elements in LINES, each element 127 1.1 christos corresponding to one (PC, line) pair. */ 128 1.1 christos 129 1.1 christos typedef void (gdb_symtab_add_line_mapping) (struct gdb_symbol_callbacks *cb, 130 1.1 christos struct gdb_symtab *symtab, 131 1.1 christos int nlines, 132 1.1 christos struct gdb_line_mapping *lines); 133 1.1 christos 134 1.1 christos /* Close the symtab SYMTAB. This signals to GDB that no more blocks 135 1.1 christos will be opened on this symtab. */ 136 1.1 christos 137 1.1 christos typedef void (gdb_symtab_close) (struct gdb_symbol_callbacks *cb, 138 1.1 christos struct gdb_symtab *symtab); 139 1.1 christos 140 1.1 christos 141 1.1 christos /* Closes the gdb_object OBJ and adds the emitted information into 142 1.1 christos GDB's internal structures. Once this is done, the debug 143 1.1 christos information will be picked up and used; this will usually be the 144 1.1 christos last operation in gdb_read_debug_info. */ 145 1.1 christos 146 1.1 christos typedef void (gdb_object_close) (struct gdb_symbol_callbacks *cb, 147 1.1 christos struct gdb_object *obj); 148 1.1 christos 149 1.1 christos /* Reads LEN bytes from TARGET_MEM in the target's virtual address 150 1.1 christos space into GDB_BUF. 151 1.1 christos 152 1.1 christos Returns GDB_FAIL on failure, and GDB_SUCCESS on success. */ 153 1.1 christos 154 1.1 christos typedef enum gdb_status (gdb_target_read) (GDB_CORE_ADDR target_mem, 155 1.1 christos void *gdb_buf, int len); 156 1.1 christos 157 1.1 christos /* The list of callbacks that are passed to read. These callbacks are 158 1.1 christos to be used to construct the symbol table. The functions have been 159 1.1 christos described above. */ 160 1.1 christos 161 1.1 christos struct gdb_symbol_callbacks 162 1.1 christos { 163 1.1 christos gdb_object_open *object_open; 164 1.1 christos gdb_symtab_open *symtab_open; 165 1.1 christos gdb_block_open *block_open; 166 1.1 christos gdb_symtab_close *symtab_close; 167 1.1 christos gdb_object_close *object_close; 168 1.1 christos 169 1.1 christos gdb_symtab_add_line_mapping *line_mapping_add; 170 1.1 christos gdb_target_read *target_read; 171 1.1 christos 172 1.1 christos /* For internal use by GDB. */ 173 1.1 christos void *priv_data; 174 1.1 christos }; 175 1.1 christos 176 1.1 christos /* Forward declaration. */ 177 1.1 christos 178 1.1 christos struct gdb_reg_value; 179 1.1 christos 180 1.1 christos /* A function of this type is used to free a gdb_reg_value. See the 181 1.1 christos comment on `free' in struct gdb_reg_value. */ 182 1.1 christos 183 1.1 christos typedef void (gdb_reg_value_free) (struct gdb_reg_value *); 184 1.1 christos 185 1.1 christos /* Denotes the value of a register. */ 186 1.1 christos 187 1.1 christos struct gdb_reg_value 188 1.1 christos { 189 1.1 christos /* The size of the register in bytes. The reader need not set this 190 1.1 christos field. This will be set for (defined) register values being read 191 1.1 christos from GDB using reg_get. */ 192 1.1 christos int size; 193 1.1 christos 194 1.1 christos /* Set to non-zero if the value for the register is known. The 195 1.1 christos registers for which the reader does not call reg_set are also 196 1.1 christos assumed to be undefined */ 197 1.1 christos int defined; 198 1.1 christos 199 1.1 christos /* Since gdb_reg_value is a variable sized structure, it will 200 1.1 christos usually be allocated on the heap. This function is expected to 201 1.1 christos contain the corresponding "free" function. 202 1.1 christos 203 1.1 christos When a pointer to gdb_reg_value is being sent from GDB to the 204 1.1 christos reader (via gdb_unwind_reg_get), the reader is expected to call 205 1.1 christos this function (with the same gdb_reg_value as argument) once it 206 1.1 christos is done with the value. 207 1.1 christos 208 1.1 christos When the function sends the a gdb_reg_value to GDB (via 209 1.1 christos gdb_unwind_reg_set), it is expected to set this field to point to 210 1.1 christos an appropriate cleanup routine (or to NULL if no cleanup is 211 1.1 christos required). */ 212 1.1 christos gdb_reg_value_free *free; 213 1.1 christos 214 1.1 christos /* The value of the register. */ 215 1.1 christos unsigned char value[1]; 216 1.1 christos }; 217 1.1 christos 218 1.1 christos /* get_frame_id in gdb_reader_funcs is to return a gdb_frame_id 219 1.1 christos corresponding to the current frame. The registers corresponding to 220 1.1 christos the current frame can be read using reg_get. Calling get_frame_id 221 1.1 christos on a particular frame should return the same gdb_frame_id 222 1.1 christos throughout its lifetime (i.e. till before it gets unwound). One 223 1.1 christos way to do this is by having the CODE_ADDRESS point to the 224 1.1 christos function's first instruction and STACK_ADDRESS point to the value 225 1.1 christos of the stack pointer when entering the function. */ 226 1.1 christos 227 1.1 christos struct gdb_frame_id 228 1.1 christos { 229 1.1 christos GDB_CORE_ADDR code_address; 230 1.1 christos GDB_CORE_ADDR stack_address; 231 1.1 christos }; 232 1.1 christos 233 1.1 christos /* Forward declaration. */ 234 1.1 christos 235 1.1 christos struct gdb_unwind_callbacks; 236 1.1 christos 237 1.1 christos /* Returns the value of a particular register in the current frame. 238 1.1 christos The current frame is the frame that needs to be unwound into the 239 1.1 christos outer (earlier) frame. 240 1.1 christos 241 1.1 christos CB is the struct gdb_unwind_callbacks * the callback belongs to. 242 1.1 christos REGNUM is the DWARF register number of the register that needs to 243 1.1 christos be unwound. 244 1.1 christos 245 1.1 christos Returns the gdb_reg_value corresponding to the register requested. 246 1.1 christos In case the value of the register has been optimized away or 247 1.1 christos otherwise unavailable, the defined flag in the returned 248 1.1 christos gdb_reg_value will be zero. */ 249 1.1 christos 250 1.1 christos typedef struct gdb_reg_value *(gdb_unwind_reg_get) 251 1.1 christos (struct gdb_unwind_callbacks *cb, int regnum); 252 1.1 christos 253 1.1 christos /* Sets the previous value of a particular register. REGNUM is the 254 1.1 christos (DWARF) register number whose value is to be set. VAL is the value 255 1.1 christos the register is to be set to. 256 1.1 christos 257 1.1 christos VAL is *not* copied, so the memory allocated to it cannot be 258 1.1 christos reused. Once GDB no longer needs the value, it is deallocated 259 1.1 christos using the FREE function (see gdb_reg_value). 260 1.1 christos 261 1.1 christos A register can also be "set" to an undefined value by setting the 262 1.1 christos defined in VAL to zero. */ 263 1.1 christos 264 1.1 christos typedef void (gdb_unwind_reg_set) (struct gdb_unwind_callbacks *cb, int regnum, 265 1.1 christos struct gdb_reg_value *val); 266 1.1 christos 267 1.1 christos /* This struct is passed to unwind in gdb_reader_funcs, and is to be 268 1.1 christos used to unwind the current frame (current being the frame whose 269 1.1 christos registers can be read using reg_get) into the earlier frame. The 270 1.1 christos functions have been described above. */ 271 1.1 christos 272 1.1 christos struct gdb_unwind_callbacks 273 1.1 christos { 274 1.1 christos gdb_unwind_reg_get *reg_get; 275 1.1 christos gdb_unwind_reg_set *reg_set; 276 1.1 christos gdb_target_read *target_read; 277 1.1 christos 278 1.1 christos /* For internal use by GDB. */ 279 1.1 christos void *priv_data; 280 1.1 christos }; 281 1.1 christos 282 1.1 christos /* Forward declaration. */ 283 1.1 christos 284 1.1 christos struct gdb_reader_funcs; 285 1.1 christos 286 1.1 christos /* Parse the debug info off a block of memory, pointed to by MEMORY 287 1.1 christos (already copied to GDB's address space) and MEMORY_SZ bytes long. 288 1.1 christos The implementation has to use the functions in CB to actually emit 289 1.1 christos the parsed data into GDB. SELF is the same structure returned by 290 1.1 christos gdb_init_reader. 291 1.1 christos 292 1.1 christos Return GDB_FAIL on failure and GDB_SUCCESS on success. */ 293 1.1 christos 294 1.1 christos typedef enum gdb_status (gdb_read_debug_info) (struct gdb_reader_funcs *self, 295 1.1 christos struct gdb_symbol_callbacks *cb, 296 1.1 christos void *memory, long memory_sz); 297 1.1 christos 298 1.1 christos /* Unwind the current frame, CB is the set of unwind callbacks that 299 1.1 christos are to be used to do this. 300 1.1 christos 301 1.1 christos Return GDB_FAIL on failure and GDB_SUCCESS on success. */ 302 1.1 christos 303 1.1 christos typedef enum gdb_status (gdb_unwind_frame) (struct gdb_reader_funcs *self, 304 1.1 christos struct gdb_unwind_callbacks *cb); 305 1.1 christos 306 1.1 christos /* Return the frame ID corresponding to the current frame, using C to 307 1.1 christos read the current register values. See the comment on struct 308 1.1 christos gdb_frame_id. */ 309 1.1 christos 310 1.1 christos typedef struct gdb_frame_id (gdb_get_frame_id) (struct gdb_reader_funcs *self, 311 1.1 christos struct gdb_unwind_callbacks *c); 312 1.1 christos 313 1.1 christos /* Called when a reader is being unloaded. This function should also 314 1.1 christos free SELF, if required. */ 315 1.1 christos 316 1.1 christos typedef void (gdb_destroy_reader) (struct gdb_reader_funcs *self); 317 1.1 christos 318 1.1 christos /* Called when the reader is loaded. Must either return a properly 319 1.1 christos populated gdb_reader_funcs or NULL. The memory allocated for the 320 1.1 christos gdb_reader_funcs is to be managed by the reader itself (i.e. if it 321 1.1 christos is allocated from the heap, it must also be freed in 322 1.1 christos gdb_destroy_reader). */ 323 1.1 christos 324 1.1 christos extern struct gdb_reader_funcs *gdb_init_reader (void); 325 1.1 christos 326 1.1 christos /* Pointer to the functions which implement the reader's 327 1.1 christos functionality. The individual functions have been documented 328 1.1 christos above. 329 1.1 christos 330 1.1 christos None of the fields are optional. */ 331 1.1 christos 332 1.1 christos struct gdb_reader_funcs 333 1.1 christos { 334 1.1 christos /* Must be set to GDB_READER_INTERFACE_VERSION. */ 335 1.1 christos int reader_version; 336 1.1 christos 337 1.1 christos /* For use by the reader. */ 338 1.1 christos void *priv_data; 339 1.1 christos 340 1.1 christos gdb_read_debug_info *read; 341 1.1 christos gdb_unwind_frame *unwind; 342 1.1 christos gdb_get_frame_id *get_frame_id; 343 1.1 christos gdb_destroy_reader *destroy; 344 1.1 christos }; 345 1.1 christos 346 1.1 christos #ifdef __cplusplus 347 1.1 christos } /* extern "C" */ 348 1.1 christos #endif 349 1.1 christos 350 1.1 christos #endif 351