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