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