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