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