xref: /netbsd-src/external/gpl3/gdb/lib/libgdb/arch/mipsn64el/jit-reader.h (revision 22ebeae4b2252475e0ebe332f69734639cb946ea)
1475b3abcSchristos /* 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  */
3475b3abcSchristos /* Generated from: NetBSD: mknative.common,v 1.16 2018/04/15 15:13:37 christos Exp  */
4475b3abcSchristos 
5475b3abcSchristos /* JIT declarations for GDB, the GNU Debugger.
6475b3abcSchristos 
7*22ebeae4Schristos    Copyright (C) 2011-2024 Free Software Foundation, Inc.
8475b3abcSchristos 
9475b3abcSchristos    This file is part of GDB.
10475b3abcSchristos 
11475b3abcSchristos    This program is free software; you can redistribute it and/or modify
12475b3abcSchristos    it under the terms of the GNU General Public License as published by
13475b3abcSchristos    the Free Software Foundation; either version 3 of the License, or
14475b3abcSchristos    (at your option) any later version.
15475b3abcSchristos 
16475b3abcSchristos    This program is distributed in the hope that it will be useful,
17475b3abcSchristos    but WITHOUT ANY WARRANTY; without even the implied warranty of
18475b3abcSchristos    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19475b3abcSchristos    GNU General Public License for more details.
20475b3abcSchristos 
21475b3abcSchristos    You should have received a copy of the GNU General Public License
22475b3abcSchristos    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
23475b3abcSchristos 
24475b3abcSchristos #ifndef GDB_JIT_READER_H
25475b3abcSchristos #define GDB_JIT_READER_H
26475b3abcSchristos 
27475b3abcSchristos #ifdef __cplusplus
28475b3abcSchristos extern "C" {
29475b3abcSchristos #endif
30475b3abcSchristos 
31475b3abcSchristos /* Versioning information.  See gdb_reader_funcs.  */
32475b3abcSchristos 
33475b3abcSchristos #define GDB_READER_INTERFACE_VERSION 1
34475b3abcSchristos 
35475b3abcSchristos /* Readers must be released under a GPL compatible license.  To
36475b3abcSchristos    declare that the reader is indeed released under a GPL compatible
37475b3abcSchristos    license, invoke the macro GDB_DECLARE_GPL_COMPATIBLE in a source
38475b3abcSchristos    file.  */
39475b3abcSchristos 
40475b3abcSchristos #ifdef __cplusplus
41475b3abcSchristos #define GDB_DECLARE_GPL_COMPATIBLE_READER       \
42475b3abcSchristos   extern "C" {                                  \
43475b3abcSchristos   extern int plugin_is_GPL_compatible (void);   \
44475b3abcSchristos   extern int plugin_is_GPL_compatible (void)    \
45475b3abcSchristos   {                                             \
46475b3abcSchristos     return 0;                                   \
47475b3abcSchristos   }                                             \
48475b3abcSchristos   }
49475b3abcSchristos 
50475b3abcSchristos #else
51475b3abcSchristos 
52475b3abcSchristos #define GDB_DECLARE_GPL_COMPATIBLE_READER       \
53475b3abcSchristos   extern int plugin_is_GPL_compatible (void);   \
54475b3abcSchristos   extern int plugin_is_GPL_compatible (void)    \
55475b3abcSchristos   {                                             \
56475b3abcSchristos     return 0;                                   \
57475b3abcSchristos   }
58475b3abcSchristos 
59475b3abcSchristos #endif
60475b3abcSchristos 
61475b3abcSchristos /* Represents an address on the target system.  */
62475b3abcSchristos 
63475b3abcSchristos typedef unsigned long GDB_CORE_ADDR;
64475b3abcSchristos 
65475b3abcSchristos /* Return status codes.  */
66475b3abcSchristos 
67475b3abcSchristos enum gdb_status {
68475b3abcSchristos   GDB_FAIL = 0,
69475b3abcSchristos   GDB_SUCCESS = 1
70475b3abcSchristos };
71475b3abcSchristos 
72475b3abcSchristos struct gdb_object;
73475b3abcSchristos struct gdb_symtab;
74475b3abcSchristos struct gdb_block;
75475b3abcSchristos struct gdb_symbol_callbacks;
76475b3abcSchristos 
77475b3abcSchristos /* An array of these are used to represent a map from code addresses to line
78475b3abcSchristos    numbers in the source file.  */
79475b3abcSchristos 
80475b3abcSchristos struct gdb_line_mapping
81475b3abcSchristos {
82475b3abcSchristos   int line;
83475b3abcSchristos   GDB_CORE_ADDR pc;
84475b3abcSchristos };
85475b3abcSchristos 
86475b3abcSchristos /* Create a new GDB code object.  Each code object can have one or
87475b3abcSchristos    more symbol tables, each representing a compiled source file.  */
88475b3abcSchristos 
89475b3abcSchristos typedef struct gdb_object *(gdb_object_open) (struct gdb_symbol_callbacks *cb);
90475b3abcSchristos 
91475b3abcSchristos /* The callback used to create new symbol table.  CB is the
92475b3abcSchristos    gdb_symbol_callbacks which the structure is part of.  FILE_NAME is
93475b3abcSchristos    an (optionally NULL) file name to associate with this new symbol
94475b3abcSchristos    table.
95475b3abcSchristos 
96475b3abcSchristos    Returns a new instance to gdb_symtab that can later be passed to
97475b3abcSchristos    gdb_block_new, gdb_symtab_add_line_mapping and gdb_symtab_close.  */
98475b3abcSchristos 
99475b3abcSchristos typedef struct gdb_symtab *(gdb_symtab_open) (struct gdb_symbol_callbacks *cb,
100475b3abcSchristos                                               struct gdb_object *obj,
101475b3abcSchristos                                               const char *file_name);
102475b3abcSchristos 
103475b3abcSchristos /* Creates a new block in a given symbol table.  A symbol table is a
104475b3abcSchristos    forest of blocks, each block representing an code address range and
105475b3abcSchristos    a corresponding (optionally NULL) NAME.  In case the block
106475b3abcSchristos    corresponds to a function, the NAME passed should be the name of
107475b3abcSchristos    the function.
108475b3abcSchristos 
109475b3abcSchristos    If the new block to be created is a child of (i.e. is nested in)
110475b3abcSchristos    another block, the parent block can be passed in PARENT.  SYMTAB is
111475b3abcSchristos    the symbol table the new block is to belong in.  BEGIN, END is the
112475b3abcSchristos    code address range the block corresponds to.
113475b3abcSchristos 
114475b3abcSchristos    Returns a new instance of gdb_block, which, as of now, has no use.
115475b3abcSchristos    Note that the gdb_block returned must not be freed by the
116475b3abcSchristos    caller.  */
117475b3abcSchristos 
118475b3abcSchristos typedef struct gdb_block *(gdb_block_open) (struct gdb_symbol_callbacks *cb,
119475b3abcSchristos                                             struct gdb_symtab *symtab,
120475b3abcSchristos                                             struct gdb_block *parent,
121475b3abcSchristos                                             GDB_CORE_ADDR begin,
122475b3abcSchristos                                             GDB_CORE_ADDR end,
123475b3abcSchristos                                             const char *name);
124475b3abcSchristos 
125475b3abcSchristos /* Adds a PC to line number mapping for the symbol table SYMTAB.
126475b3abcSchristos    NLINES is the number of elements in LINES, each element
127475b3abcSchristos    corresponding to one (PC, line) pair.  */
128475b3abcSchristos 
129475b3abcSchristos typedef void (gdb_symtab_add_line_mapping) (struct gdb_symbol_callbacks *cb,
130475b3abcSchristos                                             struct gdb_symtab *symtab,
131475b3abcSchristos                                             int nlines,
132475b3abcSchristos                                             struct gdb_line_mapping *lines);
133475b3abcSchristos 
134475b3abcSchristos /* Close the symtab SYMTAB.  This signals to GDB that no more blocks
135475b3abcSchristos    will be opened on this symtab.  */
136475b3abcSchristos 
137475b3abcSchristos typedef void (gdb_symtab_close) (struct gdb_symbol_callbacks *cb,
138475b3abcSchristos                                  struct gdb_symtab *symtab);
139475b3abcSchristos 
140475b3abcSchristos 
141475b3abcSchristos /* Closes the gdb_object OBJ and adds the emitted information into
142475b3abcSchristos    GDB's internal structures.  Once this is done, the debug
143475b3abcSchristos    information will be picked up and used; this will usually be the
144475b3abcSchristos    last operation in gdb_read_debug_info.  */
145475b3abcSchristos 
146475b3abcSchristos typedef void (gdb_object_close) (struct gdb_symbol_callbacks *cb,
147475b3abcSchristos                                  struct gdb_object *obj);
148475b3abcSchristos 
149475b3abcSchristos /* Reads LEN bytes from TARGET_MEM in the target's virtual address
150475b3abcSchristos    space into GDB_BUF.
151475b3abcSchristos 
152475b3abcSchristos    Returns GDB_FAIL on failure, and GDB_SUCCESS on success.  */
153475b3abcSchristos 
154475b3abcSchristos typedef enum gdb_status (gdb_target_read) (GDB_CORE_ADDR target_mem,
155475b3abcSchristos                                            void *gdb_buf, int len);
156475b3abcSchristos 
157475b3abcSchristos /* The list of callbacks that are passed to read.  These callbacks are
158475b3abcSchristos    to be used to construct the symbol table.  The functions have been
159475b3abcSchristos    described above.  */
160475b3abcSchristos 
161475b3abcSchristos struct gdb_symbol_callbacks
162475b3abcSchristos {
163475b3abcSchristos   gdb_object_open *object_open;
164475b3abcSchristos   gdb_symtab_open *symtab_open;
165475b3abcSchristos   gdb_block_open *block_open;
166475b3abcSchristos   gdb_symtab_close *symtab_close;
167475b3abcSchristos   gdb_object_close *object_close;
168475b3abcSchristos 
169475b3abcSchristos   gdb_symtab_add_line_mapping *line_mapping_add;
170475b3abcSchristos   gdb_target_read *target_read;
171475b3abcSchristos 
172475b3abcSchristos   /* For internal use by GDB.  */
173475b3abcSchristos   void *priv_data;
174475b3abcSchristos };
175475b3abcSchristos 
176475b3abcSchristos /* Forward declaration.  */
177475b3abcSchristos 
178475b3abcSchristos struct gdb_reg_value;
179475b3abcSchristos 
180475b3abcSchristos /* A function of this type is used to free a gdb_reg_value.  See the
181475b3abcSchristos    comment on `free' in struct gdb_reg_value.  */
182475b3abcSchristos 
183475b3abcSchristos typedef void (gdb_reg_value_free) (struct gdb_reg_value *);
184475b3abcSchristos 
185475b3abcSchristos /* Denotes the value of a register.  */
186475b3abcSchristos 
187475b3abcSchristos struct gdb_reg_value
188475b3abcSchristos {
189475b3abcSchristos   /* The size of the register in bytes.  The reader need not set this
190475b3abcSchristos      field.  This will be set for (defined) register values being read
191475b3abcSchristos      from GDB using reg_get.  */
192475b3abcSchristos   int size;
193475b3abcSchristos 
194475b3abcSchristos   /* Set to non-zero if the value for the register is known.  The
195475b3abcSchristos      registers for which the reader does not call reg_set are also
196475b3abcSchristos      assumed to be undefined */
197475b3abcSchristos   int defined;
198475b3abcSchristos 
199475b3abcSchristos   /* Since gdb_reg_value is a variable sized structure, it will
200475b3abcSchristos      usually be allocated on the heap.  This function is expected to
201475b3abcSchristos      contain the corresponding "free" function.
202475b3abcSchristos 
203475b3abcSchristos      When a pointer to gdb_reg_value is being sent from GDB to the
204475b3abcSchristos      reader (via gdb_unwind_reg_get), the reader is expected to call
205475b3abcSchristos      this function (with the same gdb_reg_value as argument) once it
206475b3abcSchristos      is done with the value.
207475b3abcSchristos 
208475b3abcSchristos      When the function sends the a gdb_reg_value to GDB (via
209475b3abcSchristos      gdb_unwind_reg_set), it is expected to set this field to point to
210475b3abcSchristos      an appropriate cleanup routine (or to NULL if no cleanup is
211475b3abcSchristos      required).  */
212475b3abcSchristos   gdb_reg_value_free *free;
213475b3abcSchristos 
214475b3abcSchristos   /* The value of the register.  */
215475b3abcSchristos   unsigned char value[1];
216475b3abcSchristos };
217475b3abcSchristos 
218475b3abcSchristos /* get_frame_id in gdb_reader_funcs is to return a gdb_frame_id
219475b3abcSchristos    corresponding to the current frame.  The registers corresponding to
220475b3abcSchristos    the current frame can be read using reg_get.  Calling get_frame_id
221475b3abcSchristos    on a particular frame should return the same gdb_frame_id
222475b3abcSchristos    throughout its lifetime (i.e. till before it gets unwound).  One
223475b3abcSchristos    way to do this is by having the CODE_ADDRESS point to the
224475b3abcSchristos    function's first instruction and STACK_ADDRESS point to the value
225475b3abcSchristos    of the stack pointer when entering the function.  */
226475b3abcSchristos 
227475b3abcSchristos struct gdb_frame_id
228475b3abcSchristos {
229475b3abcSchristos   GDB_CORE_ADDR code_address;
230475b3abcSchristos   GDB_CORE_ADDR stack_address;
231475b3abcSchristos };
232475b3abcSchristos 
233475b3abcSchristos /* Forward declaration.  */
234475b3abcSchristos 
235475b3abcSchristos struct gdb_unwind_callbacks;
236475b3abcSchristos 
237475b3abcSchristos /* Returns the value of a particular register in the current frame.
238475b3abcSchristos    The current frame is the frame that needs to be unwound into the
239475b3abcSchristos    outer (earlier) frame.
240475b3abcSchristos 
241475b3abcSchristos    CB is the struct gdb_unwind_callbacks * the callback belongs to.
242475b3abcSchristos    REGNUM is the DWARF register number of the register that needs to
243475b3abcSchristos    be unwound.
244475b3abcSchristos 
245475b3abcSchristos    Returns the gdb_reg_value corresponding to the register requested.
246475b3abcSchristos    In case the value of the register has been optimized away or
247475b3abcSchristos    otherwise unavailable, the defined flag in the returned
248475b3abcSchristos    gdb_reg_value will be zero.  */
249475b3abcSchristos 
250475b3abcSchristos typedef struct gdb_reg_value *(gdb_unwind_reg_get)
251475b3abcSchristos                               (struct gdb_unwind_callbacks *cb, int regnum);
252475b3abcSchristos 
253475b3abcSchristos /* Sets the previous value of a particular register.  REGNUM is the
254475b3abcSchristos    (DWARF) register number whose value is to be set.  VAL is the value
255475b3abcSchristos    the register is to be set to.
256475b3abcSchristos 
257475b3abcSchristos    VAL is *not* copied, so the memory allocated to it cannot be
258475b3abcSchristos    reused.  Once GDB no longer needs the value, it is deallocated
259475b3abcSchristos    using the FREE function (see gdb_reg_value).
260475b3abcSchristos 
261475b3abcSchristos    A register can also be "set" to an undefined value by setting the
262475b3abcSchristos    defined in VAL to zero.  */
263475b3abcSchristos 
264475b3abcSchristos typedef void (gdb_unwind_reg_set) (struct gdb_unwind_callbacks *cb, int regnum,
265475b3abcSchristos                                    struct gdb_reg_value *val);
266475b3abcSchristos 
267475b3abcSchristos /* This struct is passed to unwind in gdb_reader_funcs, and is to be
268475b3abcSchristos    used to unwind the current frame (current being the frame whose
269475b3abcSchristos    registers can be read using reg_get) into the earlier frame.  The
270475b3abcSchristos    functions have been described above.  */
271475b3abcSchristos 
272475b3abcSchristos struct gdb_unwind_callbacks
273475b3abcSchristos {
274475b3abcSchristos   gdb_unwind_reg_get *reg_get;
275475b3abcSchristos   gdb_unwind_reg_set *reg_set;
276475b3abcSchristos   gdb_target_read *target_read;
277475b3abcSchristos 
278475b3abcSchristos   /* For internal use by GDB.  */
279475b3abcSchristos   void *priv_data;
280475b3abcSchristos };
281475b3abcSchristos 
282475b3abcSchristos /* Forward declaration.  */
283475b3abcSchristos 
284475b3abcSchristos struct gdb_reader_funcs;
285475b3abcSchristos 
286475b3abcSchristos /* Parse the debug info off a block of memory, pointed to by MEMORY
287475b3abcSchristos    (already copied to GDB's address space) and MEMORY_SZ bytes long.
288475b3abcSchristos    The implementation has to use the functions in CB to actually emit
289475b3abcSchristos    the parsed data into GDB.  SELF is the same structure returned by
290475b3abcSchristos    gdb_init_reader.
291475b3abcSchristos 
292475b3abcSchristos    Return GDB_FAIL on failure and GDB_SUCCESS on success.  */
293475b3abcSchristos 
294475b3abcSchristos typedef enum gdb_status (gdb_read_debug_info) (struct gdb_reader_funcs *self,
295475b3abcSchristos                                                struct gdb_symbol_callbacks *cb,
296475b3abcSchristos                                                void *memory, long memory_sz);
297475b3abcSchristos 
298475b3abcSchristos /* Unwind the current frame, CB is the set of unwind callbacks that
299475b3abcSchristos    are to be used to do this.
300475b3abcSchristos 
301475b3abcSchristos    Return GDB_FAIL on failure and GDB_SUCCESS on success.  */
302475b3abcSchristos 
303475b3abcSchristos typedef enum gdb_status (gdb_unwind_frame) (struct gdb_reader_funcs *self,
304475b3abcSchristos                                             struct gdb_unwind_callbacks *cb);
305475b3abcSchristos 
306475b3abcSchristos /* Return the frame ID corresponding to the current frame, using C to
307475b3abcSchristos    read the current register values.  See the comment on struct
308475b3abcSchristos    gdb_frame_id.  */
309475b3abcSchristos 
310475b3abcSchristos typedef struct gdb_frame_id (gdb_get_frame_id) (struct gdb_reader_funcs *self,
311475b3abcSchristos                                                 struct gdb_unwind_callbacks *c);
312475b3abcSchristos 
313475b3abcSchristos /* Called when a reader is being unloaded.  This function should also
314475b3abcSchristos    free SELF, if required.  */
315475b3abcSchristos 
316475b3abcSchristos typedef void (gdb_destroy_reader) (struct gdb_reader_funcs *self);
317475b3abcSchristos 
318475b3abcSchristos /* Called when the reader is loaded.  Must either return a properly
319475b3abcSchristos    populated gdb_reader_funcs or NULL.  The memory allocated for the
320475b3abcSchristos    gdb_reader_funcs is to be managed by the reader itself (i.e. if it
321475b3abcSchristos    is allocated from the heap, it must also be freed in
322475b3abcSchristos    gdb_destroy_reader).  */
323475b3abcSchristos 
324475b3abcSchristos extern struct gdb_reader_funcs *gdb_init_reader (void);
325475b3abcSchristos 
326475b3abcSchristos /* Pointer to the functions which implement the reader's
327475b3abcSchristos    functionality.  The individual functions have been documented
328475b3abcSchristos    above.
329475b3abcSchristos 
330475b3abcSchristos    None of the fields are optional.  */
331475b3abcSchristos 
332475b3abcSchristos struct gdb_reader_funcs
333475b3abcSchristos {
334475b3abcSchristos   /* Must be set to GDB_READER_INTERFACE_VERSION.  */
335475b3abcSchristos   int reader_version;
336475b3abcSchristos 
337475b3abcSchristos   /* For use by the reader.  */
338475b3abcSchristos   void *priv_data;
339475b3abcSchristos 
340475b3abcSchristos   gdb_read_debug_info *read;
341475b3abcSchristos   gdb_unwind_frame *unwind;
342475b3abcSchristos   gdb_get_frame_id *get_frame_id;
343475b3abcSchristos   gdb_destroy_reader *destroy;
344475b3abcSchristos };
345475b3abcSchristos 
346475b3abcSchristos #ifdef __cplusplus
347475b3abcSchristos } /* extern "C" */
348475b3abcSchristos #endif
349475b3abcSchristos 
350475b3abcSchristos #endif
351