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