17d62b00eSchristos /* 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 */ 37d62b00eSchristos /* Generated from: NetBSD: mknative.common,v 1.16 2018/04/15 15:13:37 christos Exp */ 47d62b00eSchristos 57d62b00eSchristos /* JIT declarations for GDB, the GNU Debugger. 67d62b00eSchristos 7*6881a400Schristos Copyright (C) 2011-2023 Free Software Foundation, Inc. 87d62b00eSchristos 97d62b00eSchristos This file is part of GDB. 107d62b00eSchristos 117d62b00eSchristos This program is free software; you can redistribute it and/or modify 127d62b00eSchristos it under the terms of the GNU General Public License as published by 137d62b00eSchristos the Free Software Foundation; either version 3 of the License, or 147d62b00eSchristos (at your option) any later version. 157d62b00eSchristos 167d62b00eSchristos This program is distributed in the hope that it will be useful, 177d62b00eSchristos but WITHOUT ANY WARRANTY; without even the implied warranty of 187d62b00eSchristos MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 197d62b00eSchristos GNU General Public License for more details. 207d62b00eSchristos 217d62b00eSchristos You should have received a copy of the GNU General Public License 227d62b00eSchristos along with this program. If not, see <http://www.gnu.org/licenses/>. */ 237d62b00eSchristos 247d62b00eSchristos #ifndef GDB_JIT_READER_H 257d62b00eSchristos #define GDB_JIT_READER_H 267d62b00eSchristos 277d62b00eSchristos #ifdef __cplusplus 287d62b00eSchristos extern "C" { 297d62b00eSchristos #endif 307d62b00eSchristos 317d62b00eSchristos /* Versioning information. See gdb_reader_funcs. */ 327d62b00eSchristos 337d62b00eSchristos #define GDB_READER_INTERFACE_VERSION 1 347d62b00eSchristos 357d62b00eSchristos /* Readers must be released under a GPL compatible license. To 367d62b00eSchristos declare that the reader is indeed released under a GPL compatible 377d62b00eSchristos license, invoke the macro GDB_DECLARE_GPL_COMPATIBLE in a source 387d62b00eSchristos file. */ 397d62b00eSchristos 407d62b00eSchristos #ifdef __cplusplus 417d62b00eSchristos #define GDB_DECLARE_GPL_COMPATIBLE_READER \ 427d62b00eSchristos extern "C" { \ 437d62b00eSchristos extern int plugin_is_GPL_compatible (void); \ 447d62b00eSchristos extern int plugin_is_GPL_compatible (void) \ 457d62b00eSchristos { \ 467d62b00eSchristos return 0; \ 477d62b00eSchristos } \ 487d62b00eSchristos } 497d62b00eSchristos 507d62b00eSchristos #else 517d62b00eSchristos 527d62b00eSchristos #define GDB_DECLARE_GPL_COMPATIBLE_READER \ 537d62b00eSchristos extern int plugin_is_GPL_compatible (void); \ 547d62b00eSchristos extern int plugin_is_GPL_compatible (void) \ 557d62b00eSchristos { \ 567d62b00eSchristos return 0; \ 577d62b00eSchristos } 587d62b00eSchristos 597d62b00eSchristos #endif 607d62b00eSchristos 617d62b00eSchristos /* Represents an address on the target system. */ 627d62b00eSchristos 637d62b00eSchristos typedef unsigned long GDB_CORE_ADDR; 647d62b00eSchristos 657d62b00eSchristos /* Return status codes. */ 667d62b00eSchristos 677d62b00eSchristos enum gdb_status { 687d62b00eSchristos GDB_FAIL = 0, 697d62b00eSchristos GDB_SUCCESS = 1 707d62b00eSchristos }; 717d62b00eSchristos 727d62b00eSchristos struct gdb_object; 737d62b00eSchristos struct gdb_symtab; 747d62b00eSchristos struct gdb_block; 757d62b00eSchristos struct gdb_symbol_callbacks; 767d62b00eSchristos 777d62b00eSchristos /* An array of these are used to represent a map from code addresses to line 787d62b00eSchristos numbers in the source file. */ 797d62b00eSchristos 807d62b00eSchristos struct gdb_line_mapping 817d62b00eSchristos { 827d62b00eSchristos int line; 837d62b00eSchristos GDB_CORE_ADDR pc; 847d62b00eSchristos }; 857d62b00eSchristos 867d62b00eSchristos /* Create a new GDB code object. Each code object can have one or 877d62b00eSchristos more symbol tables, each representing a compiled source file. */ 887d62b00eSchristos 897d62b00eSchristos typedef struct gdb_object *(gdb_object_open) (struct gdb_symbol_callbacks *cb); 907d62b00eSchristos 917d62b00eSchristos /* The callback used to create new symbol table. CB is the 927d62b00eSchristos gdb_symbol_callbacks which the structure is part of. FILE_NAME is 937d62b00eSchristos an (optionally NULL) file name to associate with this new symbol 947d62b00eSchristos table. 957d62b00eSchristos 967d62b00eSchristos Returns a new instance to gdb_symtab that can later be passed to 977d62b00eSchristos gdb_block_new, gdb_symtab_add_line_mapping and gdb_symtab_close. */ 987d62b00eSchristos 997d62b00eSchristos typedef struct gdb_symtab *(gdb_symtab_open) (struct gdb_symbol_callbacks *cb, 1007d62b00eSchristos struct gdb_object *obj, 1017d62b00eSchristos const char *file_name); 1027d62b00eSchristos 1037d62b00eSchristos /* Creates a new block in a given symbol table. A symbol table is a 1047d62b00eSchristos forest of blocks, each block representing an code address range and 1057d62b00eSchristos a corresponding (optionally NULL) NAME. In case the block 1067d62b00eSchristos corresponds to a function, the NAME passed should be the name of 1077d62b00eSchristos the function. 1087d62b00eSchristos 1097d62b00eSchristos If the new block to be created is a child of (i.e. is nested in) 1107d62b00eSchristos another block, the parent block can be passed in PARENT. SYMTAB is 1117d62b00eSchristos the symbol table the new block is to belong in. BEGIN, END is the 1127d62b00eSchristos code address range the block corresponds to. 1137d62b00eSchristos 1147d62b00eSchristos Returns a new instance of gdb_block, which, as of now, has no use. 1157d62b00eSchristos Note that the gdb_block returned must not be freed by the 1167d62b00eSchristos caller. */ 1177d62b00eSchristos 1187d62b00eSchristos typedef struct gdb_block *(gdb_block_open) (struct gdb_symbol_callbacks *cb, 1197d62b00eSchristos struct gdb_symtab *symtab, 1207d62b00eSchristos struct gdb_block *parent, 1217d62b00eSchristos GDB_CORE_ADDR begin, 1227d62b00eSchristos GDB_CORE_ADDR end, 1237d62b00eSchristos const char *name); 1247d62b00eSchristos 1257d62b00eSchristos /* Adds a PC to line number mapping for the symbol table SYMTAB. 1267d62b00eSchristos NLINES is the number of elements in LINES, each element 1277d62b00eSchristos corresponding to one (PC, line) pair. */ 1287d62b00eSchristos 1297d62b00eSchristos typedef void (gdb_symtab_add_line_mapping) (struct gdb_symbol_callbacks *cb, 1307d62b00eSchristos struct gdb_symtab *symtab, 1317d62b00eSchristos int nlines, 1327d62b00eSchristos struct gdb_line_mapping *lines); 1337d62b00eSchristos 1347d62b00eSchristos /* Close the symtab SYMTAB. This signals to GDB that no more blocks 1357d62b00eSchristos will be opened on this symtab. */ 1367d62b00eSchristos 1377d62b00eSchristos typedef void (gdb_symtab_close) (struct gdb_symbol_callbacks *cb, 1387d62b00eSchristos struct gdb_symtab *symtab); 1397d62b00eSchristos 1407d62b00eSchristos 1417d62b00eSchristos /* Closes the gdb_object OBJ and adds the emitted information into 1427d62b00eSchristos GDB's internal structures. Once this is done, the debug 1437d62b00eSchristos information will be picked up and used; this will usually be the 1447d62b00eSchristos last operation in gdb_read_debug_info. */ 1457d62b00eSchristos 1467d62b00eSchristos typedef void (gdb_object_close) (struct gdb_symbol_callbacks *cb, 1477d62b00eSchristos struct gdb_object *obj); 1487d62b00eSchristos 1497d62b00eSchristos /* Reads LEN bytes from TARGET_MEM in the target's virtual address 1507d62b00eSchristos space into GDB_BUF. 1517d62b00eSchristos 1527d62b00eSchristos Returns GDB_FAIL on failure, and GDB_SUCCESS on success. */ 1537d62b00eSchristos 1547d62b00eSchristos typedef enum gdb_status (gdb_target_read) (GDB_CORE_ADDR target_mem, 1557d62b00eSchristos void *gdb_buf, int len); 1567d62b00eSchristos 1577d62b00eSchristos /* The list of callbacks that are passed to read. These callbacks are 1587d62b00eSchristos to be used to construct the symbol table. The functions have been 1597d62b00eSchristos described above. */ 1607d62b00eSchristos 1617d62b00eSchristos struct gdb_symbol_callbacks 1627d62b00eSchristos { 1637d62b00eSchristos gdb_object_open *object_open; 1647d62b00eSchristos gdb_symtab_open *symtab_open; 1657d62b00eSchristos gdb_block_open *block_open; 1667d62b00eSchristos gdb_symtab_close *symtab_close; 1677d62b00eSchristos gdb_object_close *object_close; 1687d62b00eSchristos 1697d62b00eSchristos gdb_symtab_add_line_mapping *line_mapping_add; 1707d62b00eSchristos gdb_target_read *target_read; 1717d62b00eSchristos 1727d62b00eSchristos /* For internal use by GDB. */ 1737d62b00eSchristos void *priv_data; 1747d62b00eSchristos }; 1757d62b00eSchristos 1767d62b00eSchristos /* Forward declaration. */ 1777d62b00eSchristos 1787d62b00eSchristos struct gdb_reg_value; 1797d62b00eSchristos 1807d62b00eSchristos /* A function of this type is used to free a gdb_reg_value. See the 1817d62b00eSchristos comment on `free' in struct gdb_reg_value. */ 1827d62b00eSchristos 1837d62b00eSchristos typedef void (gdb_reg_value_free) (struct gdb_reg_value *); 1847d62b00eSchristos 1857d62b00eSchristos /* Denotes the value of a register. */ 1867d62b00eSchristos 1877d62b00eSchristos struct gdb_reg_value 1887d62b00eSchristos { 1897d62b00eSchristos /* The size of the register in bytes. The reader need not set this 1907d62b00eSchristos field. This will be set for (defined) register values being read 1917d62b00eSchristos from GDB using reg_get. */ 1927d62b00eSchristos int size; 1937d62b00eSchristos 1947d62b00eSchristos /* Set to non-zero if the value for the register is known. The 1957d62b00eSchristos registers for which the reader does not call reg_set are also 1967d62b00eSchristos assumed to be undefined */ 1977d62b00eSchristos int defined; 1987d62b00eSchristos 1997d62b00eSchristos /* Since gdb_reg_value is a variable sized structure, it will 2007d62b00eSchristos usually be allocated on the heap. This function is expected to 2017d62b00eSchristos contain the corresponding "free" function. 2027d62b00eSchristos 2037d62b00eSchristos When a pointer to gdb_reg_value is being sent from GDB to the 2047d62b00eSchristos reader (via gdb_unwind_reg_get), the reader is expected to call 2057d62b00eSchristos this function (with the same gdb_reg_value as argument) once it 2067d62b00eSchristos is done with the value. 2077d62b00eSchristos 2087d62b00eSchristos When the function sends the a gdb_reg_value to GDB (via 2097d62b00eSchristos gdb_unwind_reg_set), it is expected to set this field to point to 2107d62b00eSchristos an appropriate cleanup routine (or to NULL if no cleanup is 2117d62b00eSchristos required). */ 2127d62b00eSchristos gdb_reg_value_free *free; 2137d62b00eSchristos 2147d62b00eSchristos /* The value of the register. */ 2157d62b00eSchristos unsigned char value[1]; 2167d62b00eSchristos }; 2177d62b00eSchristos 2187d62b00eSchristos /* get_frame_id in gdb_reader_funcs is to return a gdb_frame_id 2197d62b00eSchristos corresponding to the current frame. The registers corresponding to 2207d62b00eSchristos the current frame can be read using reg_get. Calling get_frame_id 2217d62b00eSchristos on a particular frame should return the same gdb_frame_id 2227d62b00eSchristos throughout its lifetime (i.e. till before it gets unwound). One 2237d62b00eSchristos way to do this is by having the CODE_ADDRESS point to the 2247d62b00eSchristos function's first instruction and STACK_ADDRESS point to the value 2257d62b00eSchristos of the stack pointer when entering the function. */ 2267d62b00eSchristos 2277d62b00eSchristos struct gdb_frame_id 2287d62b00eSchristos { 2297d62b00eSchristos GDB_CORE_ADDR code_address; 2307d62b00eSchristos GDB_CORE_ADDR stack_address; 2317d62b00eSchristos }; 2327d62b00eSchristos 2337d62b00eSchristos /* Forward declaration. */ 2347d62b00eSchristos 2357d62b00eSchristos struct gdb_unwind_callbacks; 2367d62b00eSchristos 2377d62b00eSchristos /* Returns the value of a particular register in the current frame. 2387d62b00eSchristos The current frame is the frame that needs to be unwound into the 2397d62b00eSchristos outer (earlier) frame. 2407d62b00eSchristos 2417d62b00eSchristos CB is the struct gdb_unwind_callbacks * the callback belongs to. 2427d62b00eSchristos REGNUM is the DWARF register number of the register that needs to 2437d62b00eSchristos be unwound. 2447d62b00eSchristos 2457d62b00eSchristos Returns the gdb_reg_value corresponding to the register requested. 2467d62b00eSchristos In case the value of the register has been optimized away or 2477d62b00eSchristos otherwise unavailable, the defined flag in the returned 2487d62b00eSchristos gdb_reg_value will be zero. */ 2497d62b00eSchristos 2507d62b00eSchristos typedef struct gdb_reg_value *(gdb_unwind_reg_get) 2517d62b00eSchristos (struct gdb_unwind_callbacks *cb, int regnum); 2527d62b00eSchristos 2537d62b00eSchristos /* Sets the previous value of a particular register. REGNUM is the 2547d62b00eSchristos (DWARF) register number whose value is to be set. VAL is the value 2557d62b00eSchristos the register is to be set to. 2567d62b00eSchristos 2577d62b00eSchristos VAL is *not* copied, so the memory allocated to it cannot be 2587d62b00eSchristos reused. Once GDB no longer needs the value, it is deallocated 2597d62b00eSchristos using the FREE function (see gdb_reg_value). 2607d62b00eSchristos 2617d62b00eSchristos A register can also be "set" to an undefined value by setting the 2627d62b00eSchristos defined in VAL to zero. */ 2637d62b00eSchristos 2647d62b00eSchristos typedef void (gdb_unwind_reg_set) (struct gdb_unwind_callbacks *cb, int regnum, 2657d62b00eSchristos struct gdb_reg_value *val); 2667d62b00eSchristos 2677d62b00eSchristos /* This struct is passed to unwind in gdb_reader_funcs, and is to be 2687d62b00eSchristos used to unwind the current frame (current being the frame whose 2697d62b00eSchristos registers can be read using reg_get) into the earlier frame. The 2707d62b00eSchristos functions have been described above. */ 2717d62b00eSchristos 2727d62b00eSchristos struct gdb_unwind_callbacks 2737d62b00eSchristos { 2747d62b00eSchristos gdb_unwind_reg_get *reg_get; 2757d62b00eSchristos gdb_unwind_reg_set *reg_set; 2767d62b00eSchristos gdb_target_read *target_read; 2777d62b00eSchristos 2787d62b00eSchristos /* For internal use by GDB. */ 2797d62b00eSchristos void *priv_data; 2807d62b00eSchristos }; 2817d62b00eSchristos 2827d62b00eSchristos /* Forward declaration. */ 2837d62b00eSchristos 2847d62b00eSchristos struct gdb_reader_funcs; 2857d62b00eSchristos 2867d62b00eSchristos /* Parse the debug info off a block of memory, pointed to by MEMORY 2877d62b00eSchristos (already copied to GDB's address space) and MEMORY_SZ bytes long. 2887d62b00eSchristos The implementation has to use the functions in CB to actually emit 2897d62b00eSchristos the parsed data into GDB. SELF is the same structure returned by 2907d62b00eSchristos gdb_init_reader. 2917d62b00eSchristos 2927d62b00eSchristos Return GDB_FAIL on failure and GDB_SUCCESS on success. */ 2937d62b00eSchristos 2947d62b00eSchristos typedef enum gdb_status (gdb_read_debug_info) (struct gdb_reader_funcs *self, 2957d62b00eSchristos struct gdb_symbol_callbacks *cb, 2967d62b00eSchristos void *memory, long memory_sz); 2977d62b00eSchristos 2987d62b00eSchristos /* Unwind the current frame, CB is the set of unwind callbacks that 2997d62b00eSchristos are to be used to do this. 3007d62b00eSchristos 3017d62b00eSchristos Return GDB_FAIL on failure and GDB_SUCCESS on success. */ 3027d62b00eSchristos 3037d62b00eSchristos typedef enum gdb_status (gdb_unwind_frame) (struct gdb_reader_funcs *self, 3047d62b00eSchristos struct gdb_unwind_callbacks *cb); 3057d62b00eSchristos 3067d62b00eSchristos /* Return the frame ID corresponding to the current frame, using C to 3077d62b00eSchristos read the current register values. See the comment on struct 3087d62b00eSchristos gdb_frame_id. */ 3097d62b00eSchristos 3107d62b00eSchristos typedef struct gdb_frame_id (gdb_get_frame_id) (struct gdb_reader_funcs *self, 3117d62b00eSchristos struct gdb_unwind_callbacks *c); 3127d62b00eSchristos 3137d62b00eSchristos /* Called when a reader is being unloaded. This function should also 3147d62b00eSchristos free SELF, if required. */ 3157d62b00eSchristos 3167d62b00eSchristos typedef void (gdb_destroy_reader) (struct gdb_reader_funcs *self); 3177d62b00eSchristos 3187d62b00eSchristos /* Called when the reader is loaded. Must either return a properly 3197d62b00eSchristos populated gdb_reader_funcs or NULL. The memory allocated for the 3207d62b00eSchristos gdb_reader_funcs is to be managed by the reader itself (i.e. if it 3217d62b00eSchristos is allocated from the heap, it must also be freed in 3227d62b00eSchristos gdb_destroy_reader). */ 3237d62b00eSchristos 3247d62b00eSchristos extern struct gdb_reader_funcs *gdb_init_reader (void); 3257d62b00eSchristos 3267d62b00eSchristos /* Pointer to the functions which implement the reader's 3277d62b00eSchristos functionality. The individual functions have been documented 3287d62b00eSchristos above. 3297d62b00eSchristos 3307d62b00eSchristos None of the fields are optional. */ 3317d62b00eSchristos 3327d62b00eSchristos struct gdb_reader_funcs 3337d62b00eSchristos { 3347d62b00eSchristos /* Must be set to GDB_READER_INTERFACE_VERSION. */ 3357d62b00eSchristos int reader_version; 3367d62b00eSchristos 3377d62b00eSchristos /* For use by the reader. */ 3387d62b00eSchristos void *priv_data; 3397d62b00eSchristos 3407d62b00eSchristos gdb_read_debug_info *read; 3417d62b00eSchristos gdb_unwind_frame *unwind; 3427d62b00eSchristos gdb_get_frame_id *get_frame_id; 3437d62b00eSchristos gdb_destroy_reader *destroy; 3447d62b00eSchristos }; 3457d62b00eSchristos 3467d62b00eSchristos #ifdef __cplusplus 3477d62b00eSchristos } /* extern "C" */ 3487d62b00eSchristos #endif 3497d62b00eSchristos 3507d62b00eSchristos #endif 351