xref: /netbsd-src/external/gpl3/gdb/lib/libgdb/arch/aarch64eb/jit-reader.h (revision 22ebeae4b2252475e0ebe332f69734639cb946ea)
1393045b2Srin /* 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  */
3393045b2Srin /* Generated from: NetBSD: mknative.common,v 1.16 2018/04/15 15:13:37 christos Exp  */
4393045b2Srin 
5393045b2Srin /* JIT declarations for GDB, the GNU Debugger.
6393045b2Srin 
7*22ebeae4Schristos    Copyright (C) 2011-2024 Free Software Foundation, Inc.
8393045b2Srin 
9393045b2Srin    This file is part of GDB.
10393045b2Srin 
11393045b2Srin    This program is free software; you can redistribute it and/or modify
12393045b2Srin    it under the terms of the GNU General Public License as published by
13393045b2Srin    the Free Software Foundation; either version 3 of the License, or
14393045b2Srin    (at your option) any later version.
15393045b2Srin 
16393045b2Srin    This program is distributed in the hope that it will be useful,
17393045b2Srin    but WITHOUT ANY WARRANTY; without even the implied warranty of
18393045b2Srin    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19393045b2Srin    GNU General Public License for more details.
20393045b2Srin 
21393045b2Srin    You should have received a copy of the GNU General Public License
22393045b2Srin    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
23393045b2Srin 
24393045b2Srin #ifndef GDB_JIT_READER_H
25393045b2Srin #define GDB_JIT_READER_H
26393045b2Srin 
27393045b2Srin #ifdef __cplusplus
28393045b2Srin extern "C" {
29393045b2Srin #endif
30393045b2Srin 
31393045b2Srin /* Versioning information.  See gdb_reader_funcs.  */
32393045b2Srin 
33393045b2Srin #define GDB_READER_INTERFACE_VERSION 1
34393045b2Srin 
35393045b2Srin /* Readers must be released under a GPL compatible license.  To
36393045b2Srin    declare that the reader is indeed released under a GPL compatible
37393045b2Srin    license, invoke the macro GDB_DECLARE_GPL_COMPATIBLE in a source
38393045b2Srin    file.  */
39393045b2Srin 
40393045b2Srin #ifdef __cplusplus
41393045b2Srin #define GDB_DECLARE_GPL_COMPATIBLE_READER       \
42393045b2Srin   extern "C" {                                  \
43393045b2Srin   extern int plugin_is_GPL_compatible (void);   \
44393045b2Srin   extern int plugin_is_GPL_compatible (void)    \
45393045b2Srin   {                                             \
46393045b2Srin     return 0;                                   \
47393045b2Srin   }                                             \
48393045b2Srin   }
49393045b2Srin 
50393045b2Srin #else
51393045b2Srin 
52393045b2Srin #define GDB_DECLARE_GPL_COMPATIBLE_READER       \
53393045b2Srin   extern int plugin_is_GPL_compatible (void);   \
54393045b2Srin   extern int plugin_is_GPL_compatible (void)    \
55393045b2Srin   {                                             \
56393045b2Srin     return 0;                                   \
57393045b2Srin   }
58393045b2Srin 
59393045b2Srin #endif
60393045b2Srin 
61393045b2Srin /* Represents an address on the target system.  */
62393045b2Srin 
63393045b2Srin typedef unsigned long GDB_CORE_ADDR;
64393045b2Srin 
65393045b2Srin /* Return status codes.  */
66393045b2Srin 
67393045b2Srin enum gdb_status {
68393045b2Srin   GDB_FAIL = 0,
69393045b2Srin   GDB_SUCCESS = 1
70393045b2Srin };
71393045b2Srin 
72393045b2Srin struct gdb_object;
73393045b2Srin struct gdb_symtab;
74393045b2Srin struct gdb_block;
75393045b2Srin struct gdb_symbol_callbacks;
76393045b2Srin 
77393045b2Srin /* An array of these are used to represent a map from code addresses to line
78393045b2Srin    numbers in the source file.  */
79393045b2Srin 
80393045b2Srin struct gdb_line_mapping
81393045b2Srin {
82393045b2Srin   int line;
83393045b2Srin   GDB_CORE_ADDR pc;
84393045b2Srin };
85393045b2Srin 
86393045b2Srin /* Create a new GDB code object.  Each code object can have one or
87393045b2Srin    more symbol tables, each representing a compiled source file.  */
88393045b2Srin 
89393045b2Srin typedef struct gdb_object *(gdb_object_open) (struct gdb_symbol_callbacks *cb);
90393045b2Srin 
91393045b2Srin /* The callback used to create new symbol table.  CB is the
92393045b2Srin    gdb_symbol_callbacks which the structure is part of.  FILE_NAME is
93393045b2Srin    an (optionally NULL) file name to associate with this new symbol
94393045b2Srin    table.
95393045b2Srin 
96393045b2Srin    Returns a new instance to gdb_symtab that can later be passed to
97393045b2Srin    gdb_block_new, gdb_symtab_add_line_mapping and gdb_symtab_close.  */
98393045b2Srin 
99393045b2Srin typedef struct gdb_symtab *(gdb_symtab_open) (struct gdb_symbol_callbacks *cb,
100393045b2Srin                                               struct gdb_object *obj,
101393045b2Srin                                               const char *file_name);
102393045b2Srin 
103393045b2Srin /* Creates a new block in a given symbol table.  A symbol table is a
104393045b2Srin    forest of blocks, each block representing an code address range and
105393045b2Srin    a corresponding (optionally NULL) NAME.  In case the block
106393045b2Srin    corresponds to a function, the NAME passed should be the name of
107393045b2Srin    the function.
108393045b2Srin 
109393045b2Srin    If the new block to be created is a child of (i.e. is nested in)
110393045b2Srin    another block, the parent block can be passed in PARENT.  SYMTAB is
111393045b2Srin    the symbol table the new block is to belong in.  BEGIN, END is the
112393045b2Srin    code address range the block corresponds to.
113393045b2Srin 
114393045b2Srin    Returns a new instance of gdb_block, which, as of now, has no use.
115393045b2Srin    Note that the gdb_block returned must not be freed by the
116393045b2Srin    caller.  */
117393045b2Srin 
118393045b2Srin typedef struct gdb_block *(gdb_block_open) (struct gdb_symbol_callbacks *cb,
119393045b2Srin                                             struct gdb_symtab *symtab,
120393045b2Srin                                             struct gdb_block *parent,
121393045b2Srin                                             GDB_CORE_ADDR begin,
122393045b2Srin                                             GDB_CORE_ADDR end,
123393045b2Srin                                             const char *name);
124393045b2Srin 
125393045b2Srin /* Adds a PC to line number mapping for the symbol table SYMTAB.
126393045b2Srin    NLINES is the number of elements in LINES, each element
127393045b2Srin    corresponding to one (PC, line) pair.  */
128393045b2Srin 
129393045b2Srin typedef void (gdb_symtab_add_line_mapping) (struct gdb_symbol_callbacks *cb,
130393045b2Srin                                             struct gdb_symtab *symtab,
131393045b2Srin                                             int nlines,
132393045b2Srin                                             struct gdb_line_mapping *lines);
133393045b2Srin 
134393045b2Srin /* Close the symtab SYMTAB.  This signals to GDB that no more blocks
135393045b2Srin    will be opened on this symtab.  */
136393045b2Srin 
137393045b2Srin typedef void (gdb_symtab_close) (struct gdb_symbol_callbacks *cb,
138393045b2Srin                                  struct gdb_symtab *symtab);
139393045b2Srin 
140393045b2Srin 
141393045b2Srin /* Closes the gdb_object OBJ and adds the emitted information into
142393045b2Srin    GDB's internal structures.  Once this is done, the debug
143393045b2Srin    information will be picked up and used; this will usually be the
144393045b2Srin    last operation in gdb_read_debug_info.  */
145393045b2Srin 
146393045b2Srin typedef void (gdb_object_close) (struct gdb_symbol_callbacks *cb,
147393045b2Srin                                  struct gdb_object *obj);
148393045b2Srin 
149393045b2Srin /* Reads LEN bytes from TARGET_MEM in the target's virtual address
150393045b2Srin    space into GDB_BUF.
151393045b2Srin 
152393045b2Srin    Returns GDB_FAIL on failure, and GDB_SUCCESS on success.  */
153393045b2Srin 
154393045b2Srin typedef enum gdb_status (gdb_target_read) (GDB_CORE_ADDR target_mem,
155393045b2Srin                                            void *gdb_buf, int len);
156393045b2Srin 
157393045b2Srin /* The list of callbacks that are passed to read.  These callbacks are
158393045b2Srin    to be used to construct the symbol table.  The functions have been
159393045b2Srin    described above.  */
160393045b2Srin 
161393045b2Srin struct gdb_symbol_callbacks
162393045b2Srin {
163393045b2Srin   gdb_object_open *object_open;
164393045b2Srin   gdb_symtab_open *symtab_open;
165393045b2Srin   gdb_block_open *block_open;
166393045b2Srin   gdb_symtab_close *symtab_close;
167393045b2Srin   gdb_object_close *object_close;
168393045b2Srin 
169393045b2Srin   gdb_symtab_add_line_mapping *line_mapping_add;
170393045b2Srin   gdb_target_read *target_read;
171393045b2Srin 
172393045b2Srin   /* For internal use by GDB.  */
173393045b2Srin   void *priv_data;
174393045b2Srin };
175393045b2Srin 
176393045b2Srin /* Forward declaration.  */
177393045b2Srin 
178393045b2Srin struct gdb_reg_value;
179393045b2Srin 
180393045b2Srin /* A function of this type is used to free a gdb_reg_value.  See the
181393045b2Srin    comment on `free' in struct gdb_reg_value.  */
182393045b2Srin 
183393045b2Srin typedef void (gdb_reg_value_free) (struct gdb_reg_value *);
184393045b2Srin 
185393045b2Srin /* Denotes the value of a register.  */
186393045b2Srin 
187393045b2Srin struct gdb_reg_value
188393045b2Srin {
189393045b2Srin   /* The size of the register in bytes.  The reader need not set this
190393045b2Srin      field.  This will be set for (defined) register values being read
191393045b2Srin      from GDB using reg_get.  */
192393045b2Srin   int size;
193393045b2Srin 
194393045b2Srin   /* Set to non-zero if the value for the register is known.  The
195393045b2Srin      registers for which the reader does not call reg_set are also
196393045b2Srin      assumed to be undefined */
197393045b2Srin   int defined;
198393045b2Srin 
199393045b2Srin   /* Since gdb_reg_value is a variable sized structure, it will
200393045b2Srin      usually be allocated on the heap.  This function is expected to
201393045b2Srin      contain the corresponding "free" function.
202393045b2Srin 
203393045b2Srin      When a pointer to gdb_reg_value is being sent from GDB to the
204393045b2Srin      reader (via gdb_unwind_reg_get), the reader is expected to call
205393045b2Srin      this function (with the same gdb_reg_value as argument) once it
206393045b2Srin      is done with the value.
207393045b2Srin 
208393045b2Srin      When the function sends the a gdb_reg_value to GDB (via
209393045b2Srin      gdb_unwind_reg_set), it is expected to set this field to point to
210393045b2Srin      an appropriate cleanup routine (or to NULL if no cleanup is
211393045b2Srin      required).  */
212393045b2Srin   gdb_reg_value_free *free;
213393045b2Srin 
214393045b2Srin   /* The value of the register.  */
215393045b2Srin   unsigned char value[1];
216393045b2Srin };
217393045b2Srin 
218393045b2Srin /* get_frame_id in gdb_reader_funcs is to return a gdb_frame_id
219393045b2Srin    corresponding to the current frame.  The registers corresponding to
220393045b2Srin    the current frame can be read using reg_get.  Calling get_frame_id
221393045b2Srin    on a particular frame should return the same gdb_frame_id
222393045b2Srin    throughout its lifetime (i.e. till before it gets unwound).  One
223393045b2Srin    way to do this is by having the CODE_ADDRESS point to the
224393045b2Srin    function's first instruction and STACK_ADDRESS point to the value
225393045b2Srin    of the stack pointer when entering the function.  */
226393045b2Srin 
227393045b2Srin struct gdb_frame_id
228393045b2Srin {
229393045b2Srin   GDB_CORE_ADDR code_address;
230393045b2Srin   GDB_CORE_ADDR stack_address;
231393045b2Srin };
232393045b2Srin 
233393045b2Srin /* Forward declaration.  */
234393045b2Srin 
235393045b2Srin struct gdb_unwind_callbacks;
236393045b2Srin 
237393045b2Srin /* Returns the value of a particular register in the current frame.
238393045b2Srin    The current frame is the frame that needs to be unwound into the
239393045b2Srin    outer (earlier) frame.
240393045b2Srin 
241393045b2Srin    CB is the struct gdb_unwind_callbacks * the callback belongs to.
242393045b2Srin    REGNUM is the DWARF register number of the register that needs to
243393045b2Srin    be unwound.
244393045b2Srin 
245393045b2Srin    Returns the gdb_reg_value corresponding to the register requested.
246393045b2Srin    In case the value of the register has been optimized away or
247393045b2Srin    otherwise unavailable, the defined flag in the returned
248393045b2Srin    gdb_reg_value will be zero.  */
249393045b2Srin 
250393045b2Srin typedef struct gdb_reg_value *(gdb_unwind_reg_get)
251393045b2Srin                               (struct gdb_unwind_callbacks *cb, int regnum);
252393045b2Srin 
253393045b2Srin /* Sets the previous value of a particular register.  REGNUM is the
254393045b2Srin    (DWARF) register number whose value is to be set.  VAL is the value
255393045b2Srin    the register is to be set to.
256393045b2Srin 
257393045b2Srin    VAL is *not* copied, so the memory allocated to it cannot be
258393045b2Srin    reused.  Once GDB no longer needs the value, it is deallocated
259393045b2Srin    using the FREE function (see gdb_reg_value).
260393045b2Srin 
261393045b2Srin    A register can also be "set" to an undefined value by setting the
262393045b2Srin    defined in VAL to zero.  */
263393045b2Srin 
264393045b2Srin typedef void (gdb_unwind_reg_set) (struct gdb_unwind_callbacks *cb, int regnum,
265393045b2Srin                                    struct gdb_reg_value *val);
266393045b2Srin 
267393045b2Srin /* This struct is passed to unwind in gdb_reader_funcs, and is to be
268393045b2Srin    used to unwind the current frame (current being the frame whose
269393045b2Srin    registers can be read using reg_get) into the earlier frame.  The
270393045b2Srin    functions have been described above.  */
271393045b2Srin 
272393045b2Srin struct gdb_unwind_callbacks
273393045b2Srin {
274393045b2Srin   gdb_unwind_reg_get *reg_get;
275393045b2Srin   gdb_unwind_reg_set *reg_set;
276393045b2Srin   gdb_target_read *target_read;
277393045b2Srin 
278393045b2Srin   /* For internal use by GDB.  */
279393045b2Srin   void *priv_data;
280393045b2Srin };
281393045b2Srin 
282393045b2Srin /* Forward declaration.  */
283393045b2Srin 
284393045b2Srin struct gdb_reader_funcs;
285393045b2Srin 
286393045b2Srin /* Parse the debug info off a block of memory, pointed to by MEMORY
287393045b2Srin    (already copied to GDB's address space) and MEMORY_SZ bytes long.
288393045b2Srin    The implementation has to use the functions in CB to actually emit
289393045b2Srin    the parsed data into GDB.  SELF is the same structure returned by
290393045b2Srin    gdb_init_reader.
291393045b2Srin 
292393045b2Srin    Return GDB_FAIL on failure and GDB_SUCCESS on success.  */
293393045b2Srin 
294393045b2Srin typedef enum gdb_status (gdb_read_debug_info) (struct gdb_reader_funcs *self,
295393045b2Srin                                                struct gdb_symbol_callbacks *cb,
296393045b2Srin                                                void *memory, long memory_sz);
297393045b2Srin 
298393045b2Srin /* Unwind the current frame, CB is the set of unwind callbacks that
299393045b2Srin    are to be used to do this.
300393045b2Srin 
301393045b2Srin    Return GDB_FAIL on failure and GDB_SUCCESS on success.  */
302393045b2Srin 
303393045b2Srin typedef enum gdb_status (gdb_unwind_frame) (struct gdb_reader_funcs *self,
304393045b2Srin                                             struct gdb_unwind_callbacks *cb);
305393045b2Srin 
306393045b2Srin /* Return the frame ID corresponding to the current frame, using C to
307393045b2Srin    read the current register values.  See the comment on struct
308393045b2Srin    gdb_frame_id.  */
309393045b2Srin 
310393045b2Srin typedef struct gdb_frame_id (gdb_get_frame_id) (struct gdb_reader_funcs *self,
311393045b2Srin                                                 struct gdb_unwind_callbacks *c);
312393045b2Srin 
313393045b2Srin /* Called when a reader is being unloaded.  This function should also
314393045b2Srin    free SELF, if required.  */
315393045b2Srin 
316393045b2Srin typedef void (gdb_destroy_reader) (struct gdb_reader_funcs *self);
317393045b2Srin 
318393045b2Srin /* Called when the reader is loaded.  Must either return a properly
319393045b2Srin    populated gdb_reader_funcs or NULL.  The memory allocated for the
320393045b2Srin    gdb_reader_funcs is to be managed by the reader itself (i.e. if it
321393045b2Srin    is allocated from the heap, it must also be freed in
322393045b2Srin    gdb_destroy_reader).  */
323393045b2Srin 
324393045b2Srin extern struct gdb_reader_funcs *gdb_init_reader (void);
325393045b2Srin 
326393045b2Srin /* Pointer to the functions which implement the reader's
327393045b2Srin    functionality.  The individual functions have been documented
328393045b2Srin    above.
329393045b2Srin 
330393045b2Srin    None of the fields are optional.  */
331393045b2Srin 
332393045b2Srin struct gdb_reader_funcs
333393045b2Srin {
334393045b2Srin   /* Must be set to GDB_READER_INTERFACE_VERSION.  */
335393045b2Srin   int reader_version;
336393045b2Srin 
337393045b2Srin   /* For use by the reader.  */
338393045b2Srin   void *priv_data;
339393045b2Srin 
340393045b2Srin   gdb_read_debug_info *read;
341393045b2Srin   gdb_unwind_frame *unwind;
342393045b2Srin   gdb_get_frame_id *get_frame_id;
343393045b2Srin   gdb_destroy_reader *destroy;
344393045b2Srin };
345393045b2Srin 
346393045b2Srin #ifdef __cplusplus
347393045b2Srin } /* extern "C" */
348393045b2Srin #endif
349393045b2Srin 
350393045b2Srin #endif
351