GDB (API)
|
00001 /* JIT declarations for GDB, the GNU Debugger. 00002 00003 Copyright (C) 2011-2013 Free Software Foundation, Inc. 00004 00005 This file is part of GDB. 00006 00007 This program is free software; you can redistribute it and/or modify 00008 it under the terms of the GNU General Public License as published by 00009 the Free Software Foundation; either version 3 of the License, or 00010 (at your option) any later version. 00011 00012 This program is distributed in the hope that it will be useful, 00013 but WITHOUT ANY WARRANTY; without even the implied warranty of 00014 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00015 GNU General Public License for more details. 00016 00017 You should have received a copy of the GNU General Public License 00018 along with this program. If not, see <http://www.gnu.org/licenses/>. */ 00019 00020 #ifndef GDB_JIT_READER_H 00021 #define GDB_JIT_READER_H 00022 00023 #ifdef __cplusplus 00024 extern "C" { 00025 #endif 00026 00027 /* Versioning information. See gdb_reader_funcs. */ 00028 00029 #define GDB_READER_INTERFACE_VERSION 1 00030 00031 /* Readers must be released under a GPL compatible license. To 00032 declare that the reader is indeed released under a GPL compatible 00033 license, invoke the macro GDB_DECLARE_GPL_COMPATIBLE in a source 00034 file. */ 00035 00036 #ifdef __cplusplus 00037 #define GDB_DECLARE_GPL_COMPATIBLE_READER \ 00038 extern "C" { \ 00039 extern int plugin_is_GPL_compatible (void); \ 00040 extern int plugin_is_GPL_compatible (void) \ 00041 { \ 00042 return 0; \ 00043 } \ 00044 } 00045 00046 #else 00047 00048 #define GDB_DECLARE_GPL_COMPATIBLE_READER \ 00049 extern int plugin_is_GPL_compatible (void); \ 00050 extern int plugin_is_GPL_compatible (void) \ 00051 { \ 00052 return 0; \ 00053 } 00054 00055 #endif 00056 00057 /* Represents an address on the target system. */ 00058 00059 typedef unsigned long long GDB_CORE_ADDR; 00060 00061 /* Return status codes. */ 00062 00063 enum gdb_status { 00064 GDB_FAIL = 0, 00065 GDB_SUCCESS = 1 00066 }; 00067 00068 struct gdb_object; 00069 struct gdb_symtab; 00070 struct gdb_block; 00071 struct gdb_symbol_callbacks; 00072 00073 /* An array of these are used to represent a map from code addresses to line 00074 numbers in the source file. */ 00075 00076 struct gdb_line_mapping 00077 { 00078 int line; 00079 GDB_CORE_ADDR pc; 00080 }; 00081 00082 /* Create a new GDB code object. Each code object can have one or 00083 more symbol tables, each representing a compiled source file. */ 00084 00085 typedef struct gdb_object *(gdb_object_open) (struct gdb_symbol_callbacks *cb); 00086 00087 /* The callback used to create new symbol table. CB is the 00088 gdb_symbol_callbacks which the structure is part of. FILE_NAME is 00089 an (optionally NULL) file name to associate with this new symbol 00090 table. 00091 00092 Returns a new instance to gdb_symtab that can later be passed to 00093 gdb_block_new, gdb_symtab_add_line_mapping and gdb_symtab_close. */ 00094 00095 typedef struct gdb_symtab *(gdb_symtab_open) (struct gdb_symbol_callbacks *cb, 00096 struct gdb_object *obj, 00097 const char *file_name); 00098 00099 /* Creates a new block in a given symbol table. A symbol table is a 00100 forest of blocks, each block representing an code address range and 00101 a corresponding (optionally NULL) NAME. In case the block 00102 corresponds to a function, the NAME passed should be the name of 00103 the function. 00104 00105 If the new block to be created is a child of (i.e. is nested in) 00106 another block, the parent block can be passed in PARENT. SYMTAB is 00107 the symbol table the new block is to belong in. BEGIN, END is the 00108 code address range the block corresponds to. 00109 00110 Returns a new instance of gdb_block, which, as of now, has no use. 00111 Note that the gdb_block returned must not be freed by the 00112 caller. */ 00113 00114 typedef struct gdb_block *(gdb_block_open) (struct gdb_symbol_callbacks *cb, 00115 struct gdb_symtab *symtab, 00116 struct gdb_block *parent, 00117 GDB_CORE_ADDR begin, 00118 GDB_CORE_ADDR end, 00119 const char *name); 00120 00121 /* Adds a PC to line number mapping for the symbol table SYMTAB. 00122 NLINES is the number of elements in LINES, each element 00123 corresponding to one (PC, line) pair. */ 00124 00125 typedef void (gdb_symtab_add_line_mapping) (struct gdb_symbol_callbacks *cb, 00126 struct gdb_symtab *symtab, 00127 int nlines, 00128 struct gdb_line_mapping *lines); 00129 00130 /* Close the symtab SYMTAB. This signals to GDB that no more blocks 00131 will be opened on this symtab. */ 00132 00133 typedef void (gdb_symtab_close) (struct gdb_symbol_callbacks *cb, 00134 struct gdb_symtab *symtab); 00135 00136 00137 /* Closes the gdb_object OBJ and adds the emitted information into 00138 GDB's internal structures. Once this is done, the debug 00139 information will be picked up and used; this will usually be the 00140 last operation in gdb_read_debug_info. */ 00141 00142 typedef void (gdb_object_close) (struct gdb_symbol_callbacks *cb, 00143 struct gdb_object *obj); 00144 00145 /* Reads LEN bytes from TARGET_MEM in the target's virtual address 00146 space into GDB_BUF. 00147 00148 Returns GDB_FAIL on failure, and GDB_SUCCESS on success. */ 00149 00150 typedef enum gdb_status (gdb_target_read) (GDB_CORE_ADDR target_mem, 00151 void *gdb_buf, int len); 00152 00153 /* The list of callbacks that are passed to read. These callbacks are 00154 to be used to construct the symbol table. The functions have been 00155 described above. */ 00156 00157 struct gdb_symbol_callbacks 00158 { 00159 gdb_object_open *object_open; 00160 gdb_symtab_open *symtab_open; 00161 gdb_block_open *block_open; 00162 gdb_symtab_close *symtab_close; 00163 gdb_object_close *object_close; 00164 00165 gdb_symtab_add_line_mapping *line_mapping_add; 00166 gdb_target_read *target_read; 00167 00168 /* For internal use by GDB. */ 00169 void *priv_data; 00170 }; 00171 00172 /* Forward declaration. */ 00173 00174 struct gdb_reg_value; 00175 00176 /* A function of this type is used to free a gdb_reg_value. See the 00177 comment on `free' in struct gdb_reg_value. */ 00178 00179 typedef void (gdb_reg_value_free) (struct gdb_reg_value *); 00180 00181 /* Denotes the value of a register. */ 00182 00183 struct gdb_reg_value 00184 { 00185 /* The size of the register in bytes. The reader need not set this 00186 field. This will be set for (defined) register values being read 00187 from GDB using reg_get. */ 00188 int size; 00189 00190 /* Set to non-zero if the value for the register is known. The 00191 registers for which the reader does not call reg_set are also 00192 assumed to be undefined */ 00193 int defined; 00194 00195 /* Since gdb_reg_value is a variable sized structure, it will 00196 usually be allocated on the heap. This function is expected to 00197 contain the corresponding "free" function. 00198 00199 When a pointer to gdb_reg_value is being sent from GDB to the 00200 reader (via gdb_unwind_reg_get), the reader is expected to call 00201 this function (with the same gdb_reg_value as argument) once it 00202 is done with the value. 00203 00204 When the function sends the a gdb_reg_value to GDB (via 00205 gdb_unwind_reg_set), it is expected to set this field to point to 00206 an appropriate cleanup routine (or to NULL if no cleanup is 00207 required). */ 00208 gdb_reg_value_free *free; 00209 00210 /* The value of the register. */ 00211 unsigned char value[1]; 00212 }; 00213 00214 /* get_frame_id in gdb_reader_funcs is to return a gdb_frame_id 00215 corresponding to the current frame. The registers corresponding to 00216 the current frame can be read using reg_get. Calling get_frame_id 00217 on a particular frame should return the same gdb_frame_id 00218 throughout its lifetime (i.e. till before it gets unwound). One 00219 way to do this is by having the CODE_ADDRESS point to the 00220 function's first instruction and STACK_ADDRESS point to the value 00221 of the stack pointer when entering the function. */ 00222 00223 struct gdb_frame_id 00224 { 00225 GDB_CORE_ADDR code_address; 00226 GDB_CORE_ADDR stack_address; 00227 }; 00228 00229 /* Forward declaration. */ 00230 00231 struct gdb_unwind_callbacks; 00232 00233 /* Returns the value of a particular register in the current frame. 00234 The current frame is the frame that needs to be unwound into the 00235 outer (earlier) frame. 00236 00237 CB is the struct gdb_unwind_callbacks * the callback belongs to. 00238 REGNUM is the DWARF register number of the register that needs to 00239 be unwound. 00240 00241 Returns the gdb_reg_value corresponding to the register requested. 00242 In case the value of the register has been optimized away or 00243 otherwise unavailable, the defined flag in the returned 00244 gdb_reg_value will be zero. */ 00245 00246 typedef struct gdb_reg_value *(gdb_unwind_reg_get) 00247 (struct gdb_unwind_callbacks *cb, int regnum); 00248 00249 /* Sets the previous value of a particular register. REGNUM is the 00250 (DWARF) register number whose value is to be set. VAL is the value 00251 the register is to be set to. 00252 00253 VAL is *not* copied, so the memory allocated to it cannot be 00254 reused. Once GDB no longer needs the value, it is deallocated 00255 using the FREE function (see gdb_reg_value). 00256 00257 A register can also be "set" to an undefined value by setting the 00258 defined in VAL to zero. */ 00259 00260 typedef void (gdb_unwind_reg_set) (struct gdb_unwind_callbacks *cb, int regnum, 00261 struct gdb_reg_value *val); 00262 00263 /* This struct is passed to unwind in gdb_reader_funcs, and is to be 00264 used to unwind the current frame (current being the frame whose 00265 registers can be read using reg_get) into the earlier frame. The 00266 functions have been described above. */ 00267 00268 struct gdb_unwind_callbacks 00269 { 00270 gdb_unwind_reg_get *reg_get; 00271 gdb_unwind_reg_set *reg_set; 00272 gdb_target_read *target_read; 00273 00274 /* For internal use by GDB. */ 00275 void *priv_data; 00276 }; 00277 00278 /* Forward declaration. */ 00279 00280 struct gdb_reader_funcs; 00281 00282 /* Parse the debug info off a block of memory, pointed to by MEMORY 00283 (already copied to GDB's address space) and MEMORY_SZ bytes long. 00284 The implementation has to use the functions in CB to actually emit 00285 the parsed data into GDB. SELF is the same structure returned by 00286 gdb_init_reader. 00287 00288 Return GDB_FAIL on failure and GDB_SUCCESS on success. */ 00289 00290 typedef enum gdb_status (gdb_read_debug_info) (struct gdb_reader_funcs *self, 00291 struct gdb_symbol_callbacks *cb, 00292 void *memory, long memory_sz); 00293 00294 /* Unwind the current frame, CB is the set of unwind callbacks that 00295 are to be used to do this. 00296 00297 Return GDB_FAIL on failure and GDB_SUCCESS on success. */ 00298 00299 typedef enum gdb_status (gdb_unwind_frame) (struct gdb_reader_funcs *self, 00300 struct gdb_unwind_callbacks *cb); 00301 00302 /* Return the frame ID corresponding to the current frame, using C to 00303 read the current register values. See the comment on struct 00304 gdb_frame_id. */ 00305 00306 typedef struct gdb_frame_id (gdb_get_frame_id) (struct gdb_reader_funcs *self, 00307 struct gdb_unwind_callbacks *c); 00308 00309 /* Called when a reader is being unloaded. This function should also 00310 free SELF, if required. */ 00311 00312 typedef void (gdb_destroy_reader) (struct gdb_reader_funcs *self); 00313 00314 /* Called when the reader is loaded. Must either return a properly 00315 populated gdb_reader_funcs or NULL. The memory allocated for the 00316 gdb_reader_funcs is to be managed by the reader itself (i.e. if it 00317 is allocated from the heap, it must also be freed in 00318 gdb_destroy_reader). */ 00319 00320 extern struct gdb_reader_funcs *gdb_init_reader (void); 00321 00322 /* Pointer to the functions which implement the reader's 00323 functionality. The individual functions have been documented 00324 above. 00325 00326 None of the fields are optional. */ 00327 00328 struct gdb_reader_funcs 00329 { 00330 /* Must be set to GDB_READER_INTERFACE_VERSION. */ 00331 int reader_version; 00332 00333 /* For use by the reader. */ 00334 void *priv_data; 00335 00336 gdb_read_debug_info *read; 00337 gdb_unwind_frame *unwind; 00338 gdb_get_frame_id *get_frame_id; 00339 gdb_destroy_reader *destroy; 00340 }; 00341 00342 #ifdef __cplusplus 00343 } /* extern "C" */ 00344 #endif 00345 00346 #endif