xref: /netbsd-src/external/gpl3/gdb/lib/libgdb/arch/riscv64/jit-reader.h (revision 22ebeae4b2252475e0ebe332f69734639cb946ea)
106dfa844Sskrll /* 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  */
306dfa844Sskrll /* Generated from: NetBSD: mknative.common,v 1.16 2018/04/15 15:13:37 christos Exp  */
406dfa844Sskrll 
506dfa844Sskrll /* JIT declarations for GDB, the GNU Debugger.
606dfa844Sskrll 
7*22ebeae4Schristos    Copyright (C) 2011-2024 Free Software Foundation, Inc.
806dfa844Sskrll 
906dfa844Sskrll    This file is part of GDB.
1006dfa844Sskrll 
1106dfa844Sskrll    This program is free software; you can redistribute it and/or modify
1206dfa844Sskrll    it under the terms of the GNU General Public License as published by
1306dfa844Sskrll    the Free Software Foundation; either version 3 of the License, or
1406dfa844Sskrll    (at your option) any later version.
1506dfa844Sskrll 
1606dfa844Sskrll    This program is distributed in the hope that it will be useful,
1706dfa844Sskrll    but WITHOUT ANY WARRANTY; without even the implied warranty of
1806dfa844Sskrll    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
1906dfa844Sskrll    GNU General Public License for more details.
2006dfa844Sskrll 
2106dfa844Sskrll    You should have received a copy of the GNU General Public License
2206dfa844Sskrll    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
2306dfa844Sskrll 
2406dfa844Sskrll #ifndef GDB_JIT_READER_H
2506dfa844Sskrll #define GDB_JIT_READER_H
2606dfa844Sskrll 
2706dfa844Sskrll #ifdef __cplusplus
2806dfa844Sskrll extern "C" {
2906dfa844Sskrll #endif
3006dfa844Sskrll 
3106dfa844Sskrll /* Versioning information.  See gdb_reader_funcs.  */
3206dfa844Sskrll 
3306dfa844Sskrll #define GDB_READER_INTERFACE_VERSION 1
3406dfa844Sskrll 
3506dfa844Sskrll /* Readers must be released under a GPL compatible license.  To
3606dfa844Sskrll    declare that the reader is indeed released under a GPL compatible
3706dfa844Sskrll    license, invoke the macro GDB_DECLARE_GPL_COMPATIBLE in a source
3806dfa844Sskrll    file.  */
3906dfa844Sskrll 
4006dfa844Sskrll #ifdef __cplusplus
4106dfa844Sskrll #define GDB_DECLARE_GPL_COMPATIBLE_READER       \
4206dfa844Sskrll   extern "C" {                                  \
4306dfa844Sskrll   extern int plugin_is_GPL_compatible (void);   \
4406dfa844Sskrll   extern int plugin_is_GPL_compatible (void)    \
4506dfa844Sskrll   {                                             \
4606dfa844Sskrll     return 0;                                   \
4706dfa844Sskrll   }                                             \
4806dfa844Sskrll   }
4906dfa844Sskrll 
5006dfa844Sskrll #else
5106dfa844Sskrll 
5206dfa844Sskrll #define GDB_DECLARE_GPL_COMPATIBLE_READER       \
5306dfa844Sskrll   extern int plugin_is_GPL_compatible (void);   \
5406dfa844Sskrll   extern int plugin_is_GPL_compatible (void)    \
5506dfa844Sskrll   {                                             \
5606dfa844Sskrll     return 0;                                   \
5706dfa844Sskrll   }
5806dfa844Sskrll 
5906dfa844Sskrll #endif
6006dfa844Sskrll 
6106dfa844Sskrll /* Represents an address on the target system.  */
6206dfa844Sskrll 
6306dfa844Sskrll typedef unsigned long GDB_CORE_ADDR;
6406dfa844Sskrll 
6506dfa844Sskrll /* Return status codes.  */
6606dfa844Sskrll 
6706dfa844Sskrll enum gdb_status {
6806dfa844Sskrll   GDB_FAIL = 0,
6906dfa844Sskrll   GDB_SUCCESS = 1
7006dfa844Sskrll };
7106dfa844Sskrll 
7206dfa844Sskrll struct gdb_object;
7306dfa844Sskrll struct gdb_symtab;
7406dfa844Sskrll struct gdb_block;
7506dfa844Sskrll struct gdb_symbol_callbacks;
7606dfa844Sskrll 
7706dfa844Sskrll /* An array of these are used to represent a map from code addresses to line
7806dfa844Sskrll    numbers in the source file.  */
7906dfa844Sskrll 
8006dfa844Sskrll struct gdb_line_mapping
8106dfa844Sskrll {
8206dfa844Sskrll   int line;
8306dfa844Sskrll   GDB_CORE_ADDR pc;
8406dfa844Sskrll };
8506dfa844Sskrll 
8606dfa844Sskrll /* Create a new GDB code object.  Each code object can have one or
8706dfa844Sskrll    more symbol tables, each representing a compiled source file.  */
8806dfa844Sskrll 
8906dfa844Sskrll typedef struct gdb_object *(gdb_object_open) (struct gdb_symbol_callbacks *cb);
9006dfa844Sskrll 
9106dfa844Sskrll /* The callback used to create new symbol table.  CB is the
9206dfa844Sskrll    gdb_symbol_callbacks which the structure is part of.  FILE_NAME is
9306dfa844Sskrll    an (optionally NULL) file name to associate with this new symbol
9406dfa844Sskrll    table.
9506dfa844Sskrll 
9606dfa844Sskrll    Returns a new instance to gdb_symtab that can later be passed to
9706dfa844Sskrll    gdb_block_new, gdb_symtab_add_line_mapping and gdb_symtab_close.  */
9806dfa844Sskrll 
9906dfa844Sskrll typedef struct gdb_symtab *(gdb_symtab_open) (struct gdb_symbol_callbacks *cb,
10006dfa844Sskrll                                               struct gdb_object *obj,
10106dfa844Sskrll                                               const char *file_name);
10206dfa844Sskrll 
10306dfa844Sskrll /* Creates a new block in a given symbol table.  A symbol table is a
10406dfa844Sskrll    forest of blocks, each block representing an code address range and
10506dfa844Sskrll    a corresponding (optionally NULL) NAME.  In case the block
10606dfa844Sskrll    corresponds to a function, the NAME passed should be the name of
10706dfa844Sskrll    the function.
10806dfa844Sskrll 
10906dfa844Sskrll    If the new block to be created is a child of (i.e. is nested in)
11006dfa844Sskrll    another block, the parent block can be passed in PARENT.  SYMTAB is
11106dfa844Sskrll    the symbol table the new block is to belong in.  BEGIN, END is the
11206dfa844Sskrll    code address range the block corresponds to.
11306dfa844Sskrll 
11406dfa844Sskrll    Returns a new instance of gdb_block, which, as of now, has no use.
11506dfa844Sskrll    Note that the gdb_block returned must not be freed by the
11606dfa844Sskrll    caller.  */
11706dfa844Sskrll 
11806dfa844Sskrll typedef struct gdb_block *(gdb_block_open) (struct gdb_symbol_callbacks *cb,
11906dfa844Sskrll                                             struct gdb_symtab *symtab,
12006dfa844Sskrll                                             struct gdb_block *parent,
12106dfa844Sskrll                                             GDB_CORE_ADDR begin,
12206dfa844Sskrll                                             GDB_CORE_ADDR end,
12306dfa844Sskrll                                             const char *name);
12406dfa844Sskrll 
12506dfa844Sskrll /* Adds a PC to line number mapping for the symbol table SYMTAB.
12606dfa844Sskrll    NLINES is the number of elements in LINES, each element
12706dfa844Sskrll    corresponding to one (PC, line) pair.  */
12806dfa844Sskrll 
12906dfa844Sskrll typedef void (gdb_symtab_add_line_mapping) (struct gdb_symbol_callbacks *cb,
13006dfa844Sskrll                                             struct gdb_symtab *symtab,
13106dfa844Sskrll                                             int nlines,
13206dfa844Sskrll                                             struct gdb_line_mapping *lines);
13306dfa844Sskrll 
13406dfa844Sskrll /* Close the symtab SYMTAB.  This signals to GDB that no more blocks
13506dfa844Sskrll    will be opened on this symtab.  */
13606dfa844Sskrll 
13706dfa844Sskrll typedef void (gdb_symtab_close) (struct gdb_symbol_callbacks *cb,
13806dfa844Sskrll                                  struct gdb_symtab *symtab);
13906dfa844Sskrll 
14006dfa844Sskrll 
14106dfa844Sskrll /* Closes the gdb_object OBJ and adds the emitted information into
14206dfa844Sskrll    GDB's internal structures.  Once this is done, the debug
14306dfa844Sskrll    information will be picked up and used; this will usually be the
14406dfa844Sskrll    last operation in gdb_read_debug_info.  */
14506dfa844Sskrll 
14606dfa844Sskrll typedef void (gdb_object_close) (struct gdb_symbol_callbacks *cb,
14706dfa844Sskrll                                  struct gdb_object *obj);
14806dfa844Sskrll 
14906dfa844Sskrll /* Reads LEN bytes from TARGET_MEM in the target's virtual address
15006dfa844Sskrll    space into GDB_BUF.
15106dfa844Sskrll 
15206dfa844Sskrll    Returns GDB_FAIL on failure, and GDB_SUCCESS on success.  */
15306dfa844Sskrll 
15406dfa844Sskrll typedef enum gdb_status (gdb_target_read) (GDB_CORE_ADDR target_mem,
15506dfa844Sskrll                                            void *gdb_buf, int len);
15606dfa844Sskrll 
15706dfa844Sskrll /* The list of callbacks that are passed to read.  These callbacks are
15806dfa844Sskrll    to be used to construct the symbol table.  The functions have been
15906dfa844Sskrll    described above.  */
16006dfa844Sskrll 
16106dfa844Sskrll struct gdb_symbol_callbacks
16206dfa844Sskrll {
16306dfa844Sskrll   gdb_object_open *object_open;
16406dfa844Sskrll   gdb_symtab_open *symtab_open;
16506dfa844Sskrll   gdb_block_open *block_open;
16606dfa844Sskrll   gdb_symtab_close *symtab_close;
16706dfa844Sskrll   gdb_object_close *object_close;
16806dfa844Sskrll 
16906dfa844Sskrll   gdb_symtab_add_line_mapping *line_mapping_add;
17006dfa844Sskrll   gdb_target_read *target_read;
17106dfa844Sskrll 
17206dfa844Sskrll   /* For internal use by GDB.  */
17306dfa844Sskrll   void *priv_data;
17406dfa844Sskrll };
17506dfa844Sskrll 
17606dfa844Sskrll /* Forward declaration.  */
17706dfa844Sskrll 
17806dfa844Sskrll struct gdb_reg_value;
17906dfa844Sskrll 
18006dfa844Sskrll /* A function of this type is used to free a gdb_reg_value.  See the
18106dfa844Sskrll    comment on `free' in struct gdb_reg_value.  */
18206dfa844Sskrll 
18306dfa844Sskrll typedef void (gdb_reg_value_free) (struct gdb_reg_value *);
18406dfa844Sskrll 
18506dfa844Sskrll /* Denotes the value of a register.  */
18606dfa844Sskrll 
18706dfa844Sskrll struct gdb_reg_value
18806dfa844Sskrll {
18906dfa844Sskrll   /* The size of the register in bytes.  The reader need not set this
19006dfa844Sskrll      field.  This will be set for (defined) register values being read
19106dfa844Sskrll      from GDB using reg_get.  */
19206dfa844Sskrll   int size;
19306dfa844Sskrll 
19406dfa844Sskrll   /* Set to non-zero if the value for the register is known.  The
19506dfa844Sskrll      registers for which the reader does not call reg_set are also
19606dfa844Sskrll      assumed to be undefined */
19706dfa844Sskrll   int defined;
19806dfa844Sskrll 
19906dfa844Sskrll   /* Since gdb_reg_value is a variable sized structure, it will
20006dfa844Sskrll      usually be allocated on the heap.  This function is expected to
20106dfa844Sskrll      contain the corresponding "free" function.
20206dfa844Sskrll 
20306dfa844Sskrll      When a pointer to gdb_reg_value is being sent from GDB to the
20406dfa844Sskrll      reader (via gdb_unwind_reg_get), the reader is expected to call
20506dfa844Sskrll      this function (with the same gdb_reg_value as argument) once it
20606dfa844Sskrll      is done with the value.
20706dfa844Sskrll 
20806dfa844Sskrll      When the function sends the a gdb_reg_value to GDB (via
20906dfa844Sskrll      gdb_unwind_reg_set), it is expected to set this field to point to
21006dfa844Sskrll      an appropriate cleanup routine (or to NULL if no cleanup is
21106dfa844Sskrll      required).  */
21206dfa844Sskrll   gdb_reg_value_free *free;
21306dfa844Sskrll 
21406dfa844Sskrll   /* The value of the register.  */
21506dfa844Sskrll   unsigned char value[1];
21606dfa844Sskrll };
21706dfa844Sskrll 
21806dfa844Sskrll /* get_frame_id in gdb_reader_funcs is to return a gdb_frame_id
21906dfa844Sskrll    corresponding to the current frame.  The registers corresponding to
22006dfa844Sskrll    the current frame can be read using reg_get.  Calling get_frame_id
22106dfa844Sskrll    on a particular frame should return the same gdb_frame_id
22206dfa844Sskrll    throughout its lifetime (i.e. till before it gets unwound).  One
22306dfa844Sskrll    way to do this is by having the CODE_ADDRESS point to the
22406dfa844Sskrll    function's first instruction and STACK_ADDRESS point to the value
22506dfa844Sskrll    of the stack pointer when entering the function.  */
22606dfa844Sskrll 
22706dfa844Sskrll struct gdb_frame_id
22806dfa844Sskrll {
22906dfa844Sskrll   GDB_CORE_ADDR code_address;
23006dfa844Sskrll   GDB_CORE_ADDR stack_address;
23106dfa844Sskrll };
23206dfa844Sskrll 
23306dfa844Sskrll /* Forward declaration.  */
23406dfa844Sskrll 
23506dfa844Sskrll struct gdb_unwind_callbacks;
23606dfa844Sskrll 
23706dfa844Sskrll /* Returns the value of a particular register in the current frame.
23806dfa844Sskrll    The current frame is the frame that needs to be unwound into the
23906dfa844Sskrll    outer (earlier) frame.
24006dfa844Sskrll 
24106dfa844Sskrll    CB is the struct gdb_unwind_callbacks * the callback belongs to.
24206dfa844Sskrll    REGNUM is the DWARF register number of the register that needs to
24306dfa844Sskrll    be unwound.
24406dfa844Sskrll 
24506dfa844Sskrll    Returns the gdb_reg_value corresponding to the register requested.
24606dfa844Sskrll    In case the value of the register has been optimized away or
24706dfa844Sskrll    otherwise unavailable, the defined flag in the returned
24806dfa844Sskrll    gdb_reg_value will be zero.  */
24906dfa844Sskrll 
25006dfa844Sskrll typedef struct gdb_reg_value *(gdb_unwind_reg_get)
25106dfa844Sskrll                               (struct gdb_unwind_callbacks *cb, int regnum);
25206dfa844Sskrll 
25306dfa844Sskrll /* Sets the previous value of a particular register.  REGNUM is the
25406dfa844Sskrll    (DWARF) register number whose value is to be set.  VAL is the value
25506dfa844Sskrll    the register is to be set to.
25606dfa844Sskrll 
25706dfa844Sskrll    VAL is *not* copied, so the memory allocated to it cannot be
25806dfa844Sskrll    reused.  Once GDB no longer needs the value, it is deallocated
25906dfa844Sskrll    using the FREE function (see gdb_reg_value).
26006dfa844Sskrll 
26106dfa844Sskrll    A register can also be "set" to an undefined value by setting the
26206dfa844Sskrll    defined in VAL to zero.  */
26306dfa844Sskrll 
26406dfa844Sskrll typedef void (gdb_unwind_reg_set) (struct gdb_unwind_callbacks *cb, int regnum,
26506dfa844Sskrll                                    struct gdb_reg_value *val);
26606dfa844Sskrll 
26706dfa844Sskrll /* This struct is passed to unwind in gdb_reader_funcs, and is to be
26806dfa844Sskrll    used to unwind the current frame (current being the frame whose
26906dfa844Sskrll    registers can be read using reg_get) into the earlier frame.  The
27006dfa844Sskrll    functions have been described above.  */
27106dfa844Sskrll 
27206dfa844Sskrll struct gdb_unwind_callbacks
27306dfa844Sskrll {
27406dfa844Sskrll   gdb_unwind_reg_get *reg_get;
27506dfa844Sskrll   gdb_unwind_reg_set *reg_set;
27606dfa844Sskrll   gdb_target_read *target_read;
27706dfa844Sskrll 
27806dfa844Sskrll   /* For internal use by GDB.  */
27906dfa844Sskrll   void *priv_data;
28006dfa844Sskrll };
28106dfa844Sskrll 
28206dfa844Sskrll /* Forward declaration.  */
28306dfa844Sskrll 
28406dfa844Sskrll struct gdb_reader_funcs;
28506dfa844Sskrll 
28606dfa844Sskrll /* Parse the debug info off a block of memory, pointed to by MEMORY
28706dfa844Sskrll    (already copied to GDB's address space) and MEMORY_SZ bytes long.
28806dfa844Sskrll    The implementation has to use the functions in CB to actually emit
28906dfa844Sskrll    the parsed data into GDB.  SELF is the same structure returned by
29006dfa844Sskrll    gdb_init_reader.
29106dfa844Sskrll 
29206dfa844Sskrll    Return GDB_FAIL on failure and GDB_SUCCESS on success.  */
29306dfa844Sskrll 
29406dfa844Sskrll typedef enum gdb_status (gdb_read_debug_info) (struct gdb_reader_funcs *self,
29506dfa844Sskrll                                                struct gdb_symbol_callbacks *cb,
29606dfa844Sskrll                                                void *memory, long memory_sz);
29706dfa844Sskrll 
29806dfa844Sskrll /* Unwind the current frame, CB is the set of unwind callbacks that
29906dfa844Sskrll    are to be used to do this.
30006dfa844Sskrll 
30106dfa844Sskrll    Return GDB_FAIL on failure and GDB_SUCCESS on success.  */
30206dfa844Sskrll 
30306dfa844Sskrll typedef enum gdb_status (gdb_unwind_frame) (struct gdb_reader_funcs *self,
30406dfa844Sskrll                                             struct gdb_unwind_callbacks *cb);
30506dfa844Sskrll 
30606dfa844Sskrll /* Return the frame ID corresponding to the current frame, using C to
30706dfa844Sskrll    read the current register values.  See the comment on struct
30806dfa844Sskrll    gdb_frame_id.  */
30906dfa844Sskrll 
31006dfa844Sskrll typedef struct gdb_frame_id (gdb_get_frame_id) (struct gdb_reader_funcs *self,
31106dfa844Sskrll                                                 struct gdb_unwind_callbacks *c);
31206dfa844Sskrll 
31306dfa844Sskrll /* Called when a reader is being unloaded.  This function should also
31406dfa844Sskrll    free SELF, if required.  */
31506dfa844Sskrll 
31606dfa844Sskrll typedef void (gdb_destroy_reader) (struct gdb_reader_funcs *self);
31706dfa844Sskrll 
31806dfa844Sskrll /* Called when the reader is loaded.  Must either return a properly
31906dfa844Sskrll    populated gdb_reader_funcs or NULL.  The memory allocated for the
32006dfa844Sskrll    gdb_reader_funcs is to be managed by the reader itself (i.e. if it
32106dfa844Sskrll    is allocated from the heap, it must also be freed in
32206dfa844Sskrll    gdb_destroy_reader).  */
32306dfa844Sskrll 
32406dfa844Sskrll extern struct gdb_reader_funcs *gdb_init_reader (void);
32506dfa844Sskrll 
32606dfa844Sskrll /* Pointer to the functions which implement the reader's
32706dfa844Sskrll    functionality.  The individual functions have been documented
32806dfa844Sskrll    above.
32906dfa844Sskrll 
33006dfa844Sskrll    None of the fields are optional.  */
33106dfa844Sskrll 
33206dfa844Sskrll struct gdb_reader_funcs
33306dfa844Sskrll {
33406dfa844Sskrll   /* Must be set to GDB_READER_INTERFACE_VERSION.  */
33506dfa844Sskrll   int reader_version;
33606dfa844Sskrll 
33706dfa844Sskrll   /* For use by the reader.  */
33806dfa844Sskrll   void *priv_data;
33906dfa844Sskrll 
34006dfa844Sskrll   gdb_read_debug_info *read;
34106dfa844Sskrll   gdb_unwind_frame *unwind;
34206dfa844Sskrll   gdb_get_frame_id *get_frame_id;
34306dfa844Sskrll   gdb_destroy_reader *destroy;
34406dfa844Sskrll };
34506dfa844Sskrll 
34606dfa844Sskrll #ifdef __cplusplus
34706dfa844Sskrll } /* extern "C" */
34806dfa844Sskrll #endif
34906dfa844Sskrll 
35006dfa844Sskrll #endif
351