xref: /netbsd-src/external/gpl3/gdb/lib/libgdb/arch/sh3eb/jit-reader.h (revision 22ebeae4b2252475e0ebe332f69734639cb946ea)
184e9dd17Smrg /* 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  */
387816d4fSchristos /* Generated from: NetBSD: mknative.common,v 1.16 2018/04/15 15:13:37 christos Exp  */
484e9dd17Smrg 
584e9dd17Smrg /* JIT declarations for GDB, the GNU Debugger.
684e9dd17Smrg 
7*22ebeae4Schristos    Copyright (C) 2011-2024 Free Software Foundation, Inc.
884e9dd17Smrg 
984e9dd17Smrg    This file is part of GDB.
1084e9dd17Smrg 
1184e9dd17Smrg    This program is free software; you can redistribute it and/or modify
1284e9dd17Smrg    it under the terms of the GNU General Public License as published by
1384e9dd17Smrg    the Free Software Foundation; either version 3 of the License, or
1484e9dd17Smrg    (at your option) any later version.
1584e9dd17Smrg 
1684e9dd17Smrg    This program is distributed in the hope that it will be useful,
1784e9dd17Smrg    but WITHOUT ANY WARRANTY; without even the implied warranty of
1884e9dd17Smrg    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
1984e9dd17Smrg    GNU General Public License for more details.
2084e9dd17Smrg 
2184e9dd17Smrg    You should have received a copy of the GNU General Public License
2284e9dd17Smrg    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
2384e9dd17Smrg 
2484e9dd17Smrg #ifndef GDB_JIT_READER_H
2584e9dd17Smrg #define GDB_JIT_READER_H
2684e9dd17Smrg 
2784e9dd17Smrg #ifdef __cplusplus
2884e9dd17Smrg extern "C" {
2984e9dd17Smrg #endif
3084e9dd17Smrg 
3184e9dd17Smrg /* Versioning information.  See gdb_reader_funcs.  */
3284e9dd17Smrg 
3384e9dd17Smrg #define GDB_READER_INTERFACE_VERSION 1
3484e9dd17Smrg 
3584e9dd17Smrg /* Readers must be released under a GPL compatible license.  To
3684e9dd17Smrg    declare that the reader is indeed released under a GPL compatible
3784e9dd17Smrg    license, invoke the macro GDB_DECLARE_GPL_COMPATIBLE in a source
3884e9dd17Smrg    file.  */
3984e9dd17Smrg 
4084e9dd17Smrg #ifdef __cplusplus
4184e9dd17Smrg #define GDB_DECLARE_GPL_COMPATIBLE_READER       \
4284e9dd17Smrg   extern "C" {                                  \
4384e9dd17Smrg   extern int plugin_is_GPL_compatible (void);   \
4484e9dd17Smrg   extern int plugin_is_GPL_compatible (void)    \
4584e9dd17Smrg   {                                             \
4684e9dd17Smrg     return 0;                                   \
4784e9dd17Smrg   }                                             \
4884e9dd17Smrg   }
4984e9dd17Smrg 
5084e9dd17Smrg #else
5184e9dd17Smrg 
5284e9dd17Smrg #define GDB_DECLARE_GPL_COMPATIBLE_READER       \
5384e9dd17Smrg   extern int plugin_is_GPL_compatible (void);   \
5484e9dd17Smrg   extern int plugin_is_GPL_compatible (void)    \
5584e9dd17Smrg   {                                             \
5684e9dd17Smrg     return 0;                                   \
5784e9dd17Smrg   }
5884e9dd17Smrg 
5984e9dd17Smrg #endif
6084e9dd17Smrg 
6184e9dd17Smrg /* Represents an address on the target system.  */
6284e9dd17Smrg 
6384e9dd17Smrg typedef unsigned long long GDB_CORE_ADDR;
6484e9dd17Smrg 
6584e9dd17Smrg /* Return status codes.  */
6684e9dd17Smrg 
6784e9dd17Smrg enum gdb_status {
6884e9dd17Smrg   GDB_FAIL = 0,
6984e9dd17Smrg   GDB_SUCCESS = 1
7084e9dd17Smrg };
7184e9dd17Smrg 
7284e9dd17Smrg struct gdb_object;
7384e9dd17Smrg struct gdb_symtab;
7484e9dd17Smrg struct gdb_block;
7584e9dd17Smrg struct gdb_symbol_callbacks;
7684e9dd17Smrg 
7784e9dd17Smrg /* An array of these are used to represent a map from code addresses to line
7884e9dd17Smrg    numbers in the source file.  */
7984e9dd17Smrg 
8084e9dd17Smrg struct gdb_line_mapping
8184e9dd17Smrg {
8284e9dd17Smrg   int line;
8384e9dd17Smrg   GDB_CORE_ADDR pc;
8484e9dd17Smrg };
8584e9dd17Smrg 
8684e9dd17Smrg /* Create a new GDB code object.  Each code object can have one or
8784e9dd17Smrg    more symbol tables, each representing a compiled source file.  */
8884e9dd17Smrg 
8984e9dd17Smrg typedef struct gdb_object *(gdb_object_open) (struct gdb_symbol_callbacks *cb);
9084e9dd17Smrg 
9184e9dd17Smrg /* The callback used to create new symbol table.  CB is the
9284e9dd17Smrg    gdb_symbol_callbacks which the structure is part of.  FILE_NAME is
9384e9dd17Smrg    an (optionally NULL) file name to associate with this new symbol
9484e9dd17Smrg    table.
9584e9dd17Smrg 
9684e9dd17Smrg    Returns a new instance to gdb_symtab that can later be passed to
9784e9dd17Smrg    gdb_block_new, gdb_symtab_add_line_mapping and gdb_symtab_close.  */
9884e9dd17Smrg 
9984e9dd17Smrg typedef struct gdb_symtab *(gdb_symtab_open) (struct gdb_symbol_callbacks *cb,
10084e9dd17Smrg                                               struct gdb_object *obj,
10184e9dd17Smrg                                               const char *file_name);
10284e9dd17Smrg 
10384e9dd17Smrg /* Creates a new block in a given symbol table.  A symbol table is a
10484e9dd17Smrg    forest of blocks, each block representing an code address range and
10584e9dd17Smrg    a corresponding (optionally NULL) NAME.  In case the block
10684e9dd17Smrg    corresponds to a function, the NAME passed should be the name of
10784e9dd17Smrg    the function.
10884e9dd17Smrg 
10984e9dd17Smrg    If the new block to be created is a child of (i.e. is nested in)
11084e9dd17Smrg    another block, the parent block can be passed in PARENT.  SYMTAB is
11184e9dd17Smrg    the symbol table the new block is to belong in.  BEGIN, END is the
11284e9dd17Smrg    code address range the block corresponds to.
11384e9dd17Smrg 
11484e9dd17Smrg    Returns a new instance of gdb_block, which, as of now, has no use.
11584e9dd17Smrg    Note that the gdb_block returned must not be freed by the
11684e9dd17Smrg    caller.  */
11784e9dd17Smrg 
11884e9dd17Smrg typedef struct gdb_block *(gdb_block_open) (struct gdb_symbol_callbacks *cb,
11984e9dd17Smrg                                             struct gdb_symtab *symtab,
12084e9dd17Smrg                                             struct gdb_block *parent,
12184e9dd17Smrg                                             GDB_CORE_ADDR begin,
12284e9dd17Smrg                                             GDB_CORE_ADDR end,
12384e9dd17Smrg                                             const char *name);
12484e9dd17Smrg 
12584e9dd17Smrg /* Adds a PC to line number mapping for the symbol table SYMTAB.
12684e9dd17Smrg    NLINES is the number of elements in LINES, each element
12784e9dd17Smrg    corresponding to one (PC, line) pair.  */
12884e9dd17Smrg 
12984e9dd17Smrg typedef void (gdb_symtab_add_line_mapping) (struct gdb_symbol_callbacks *cb,
13084e9dd17Smrg                                             struct gdb_symtab *symtab,
13184e9dd17Smrg                                             int nlines,
13284e9dd17Smrg                                             struct gdb_line_mapping *lines);
13384e9dd17Smrg 
13484e9dd17Smrg /* Close the symtab SYMTAB.  This signals to GDB that no more blocks
13584e9dd17Smrg    will be opened on this symtab.  */
13684e9dd17Smrg 
13784e9dd17Smrg typedef void (gdb_symtab_close) (struct gdb_symbol_callbacks *cb,
13884e9dd17Smrg                                  struct gdb_symtab *symtab);
13984e9dd17Smrg 
14084e9dd17Smrg 
14184e9dd17Smrg /* Closes the gdb_object OBJ and adds the emitted information into
14284e9dd17Smrg    GDB's internal structures.  Once this is done, the debug
14384e9dd17Smrg    information will be picked up and used; this will usually be the
14484e9dd17Smrg    last operation in gdb_read_debug_info.  */
14584e9dd17Smrg 
14684e9dd17Smrg typedef void (gdb_object_close) (struct gdb_symbol_callbacks *cb,
14784e9dd17Smrg                                  struct gdb_object *obj);
14884e9dd17Smrg 
14984e9dd17Smrg /* Reads LEN bytes from TARGET_MEM in the target's virtual address
15084e9dd17Smrg    space into GDB_BUF.
15184e9dd17Smrg 
15284e9dd17Smrg    Returns GDB_FAIL on failure, and GDB_SUCCESS on success.  */
15384e9dd17Smrg 
15484e9dd17Smrg typedef enum gdb_status (gdb_target_read) (GDB_CORE_ADDR target_mem,
15584e9dd17Smrg                                            void *gdb_buf, int len);
15684e9dd17Smrg 
15784e9dd17Smrg /* The list of callbacks that are passed to read.  These callbacks are
15884e9dd17Smrg    to be used to construct the symbol table.  The functions have been
15984e9dd17Smrg    described above.  */
16084e9dd17Smrg 
16184e9dd17Smrg struct gdb_symbol_callbacks
16284e9dd17Smrg {
16384e9dd17Smrg   gdb_object_open *object_open;
16484e9dd17Smrg   gdb_symtab_open *symtab_open;
16584e9dd17Smrg   gdb_block_open *block_open;
16684e9dd17Smrg   gdb_symtab_close *symtab_close;
16784e9dd17Smrg   gdb_object_close *object_close;
16884e9dd17Smrg 
16984e9dd17Smrg   gdb_symtab_add_line_mapping *line_mapping_add;
17084e9dd17Smrg   gdb_target_read *target_read;
17184e9dd17Smrg 
17284e9dd17Smrg   /* For internal use by GDB.  */
17384e9dd17Smrg   void *priv_data;
17484e9dd17Smrg };
17584e9dd17Smrg 
17684e9dd17Smrg /* Forward declaration.  */
17784e9dd17Smrg 
17884e9dd17Smrg struct gdb_reg_value;
17984e9dd17Smrg 
18084e9dd17Smrg /* A function of this type is used to free a gdb_reg_value.  See the
18184e9dd17Smrg    comment on `free' in struct gdb_reg_value.  */
18284e9dd17Smrg 
18384e9dd17Smrg typedef void (gdb_reg_value_free) (struct gdb_reg_value *);
18484e9dd17Smrg 
18584e9dd17Smrg /* Denotes the value of a register.  */
18684e9dd17Smrg 
18784e9dd17Smrg struct gdb_reg_value
18884e9dd17Smrg {
18984e9dd17Smrg   /* The size of the register in bytes.  The reader need not set this
19084e9dd17Smrg      field.  This will be set for (defined) register values being read
19184e9dd17Smrg      from GDB using reg_get.  */
19284e9dd17Smrg   int size;
19384e9dd17Smrg 
19484e9dd17Smrg   /* Set to non-zero if the value for the register is known.  The
19584e9dd17Smrg      registers for which the reader does not call reg_set are also
19684e9dd17Smrg      assumed to be undefined */
19784e9dd17Smrg   int defined;
19884e9dd17Smrg 
19984e9dd17Smrg   /* Since gdb_reg_value is a variable sized structure, it will
20084e9dd17Smrg      usually be allocated on the heap.  This function is expected to
20184e9dd17Smrg      contain the corresponding "free" function.
20284e9dd17Smrg 
20384e9dd17Smrg      When a pointer to gdb_reg_value is being sent from GDB to the
20484e9dd17Smrg      reader (via gdb_unwind_reg_get), the reader is expected to call
20584e9dd17Smrg      this function (with the same gdb_reg_value as argument) once it
20684e9dd17Smrg      is done with the value.
20784e9dd17Smrg 
20884e9dd17Smrg      When the function sends the a gdb_reg_value to GDB (via
20984e9dd17Smrg      gdb_unwind_reg_set), it is expected to set this field to point to
21084e9dd17Smrg      an appropriate cleanup routine (or to NULL if no cleanup is
21184e9dd17Smrg      required).  */
21284e9dd17Smrg   gdb_reg_value_free *free;
21384e9dd17Smrg 
21484e9dd17Smrg   /* The value of the register.  */
21584e9dd17Smrg   unsigned char value[1];
21684e9dd17Smrg };
21784e9dd17Smrg 
21884e9dd17Smrg /* get_frame_id in gdb_reader_funcs is to return a gdb_frame_id
21984e9dd17Smrg    corresponding to the current frame.  The registers corresponding to
22084e9dd17Smrg    the current frame can be read using reg_get.  Calling get_frame_id
22184e9dd17Smrg    on a particular frame should return the same gdb_frame_id
22284e9dd17Smrg    throughout its lifetime (i.e. till before it gets unwound).  One
22384e9dd17Smrg    way to do this is by having the CODE_ADDRESS point to the
22484e9dd17Smrg    function's first instruction and STACK_ADDRESS point to the value
22584e9dd17Smrg    of the stack pointer when entering the function.  */
22684e9dd17Smrg 
22784e9dd17Smrg struct gdb_frame_id
22884e9dd17Smrg {
22984e9dd17Smrg   GDB_CORE_ADDR code_address;
23084e9dd17Smrg   GDB_CORE_ADDR stack_address;
23184e9dd17Smrg };
23284e9dd17Smrg 
23384e9dd17Smrg /* Forward declaration.  */
23484e9dd17Smrg 
23584e9dd17Smrg struct gdb_unwind_callbacks;
23684e9dd17Smrg 
23784e9dd17Smrg /* Returns the value of a particular register in the current frame.
23884e9dd17Smrg    The current frame is the frame that needs to be unwound into the
23984e9dd17Smrg    outer (earlier) frame.
24084e9dd17Smrg 
24184e9dd17Smrg    CB is the struct gdb_unwind_callbacks * the callback belongs to.
24284e9dd17Smrg    REGNUM is the DWARF register number of the register that needs to
24384e9dd17Smrg    be unwound.
24484e9dd17Smrg 
24584e9dd17Smrg    Returns the gdb_reg_value corresponding to the register requested.
24684e9dd17Smrg    In case the value of the register has been optimized away or
24784e9dd17Smrg    otherwise unavailable, the defined flag in the returned
24884e9dd17Smrg    gdb_reg_value will be zero.  */
24984e9dd17Smrg 
25084e9dd17Smrg typedef struct gdb_reg_value *(gdb_unwind_reg_get)
25184e9dd17Smrg                               (struct gdb_unwind_callbacks *cb, int regnum);
25284e9dd17Smrg 
25384e9dd17Smrg /* Sets the previous value of a particular register.  REGNUM is the
25484e9dd17Smrg    (DWARF) register number whose value is to be set.  VAL is the value
25584e9dd17Smrg    the register is to be set to.
25684e9dd17Smrg 
25784e9dd17Smrg    VAL is *not* copied, so the memory allocated to it cannot be
25884e9dd17Smrg    reused.  Once GDB no longer needs the value, it is deallocated
25984e9dd17Smrg    using the FREE function (see gdb_reg_value).
26084e9dd17Smrg 
26184e9dd17Smrg    A register can also be "set" to an undefined value by setting the
26284e9dd17Smrg    defined in VAL to zero.  */
26384e9dd17Smrg 
26484e9dd17Smrg typedef void (gdb_unwind_reg_set) (struct gdb_unwind_callbacks *cb, int regnum,
26584e9dd17Smrg                                    struct gdb_reg_value *val);
26684e9dd17Smrg 
26784e9dd17Smrg /* This struct is passed to unwind in gdb_reader_funcs, and is to be
26884e9dd17Smrg    used to unwind the current frame (current being the frame whose
26984e9dd17Smrg    registers can be read using reg_get) into the earlier frame.  The
27084e9dd17Smrg    functions have been described above.  */
27184e9dd17Smrg 
27284e9dd17Smrg struct gdb_unwind_callbacks
27384e9dd17Smrg {
27484e9dd17Smrg   gdb_unwind_reg_get *reg_get;
27584e9dd17Smrg   gdb_unwind_reg_set *reg_set;
27684e9dd17Smrg   gdb_target_read *target_read;
27784e9dd17Smrg 
27884e9dd17Smrg   /* For internal use by GDB.  */
27984e9dd17Smrg   void *priv_data;
28084e9dd17Smrg };
28184e9dd17Smrg 
28284e9dd17Smrg /* Forward declaration.  */
28384e9dd17Smrg 
28484e9dd17Smrg struct gdb_reader_funcs;
28584e9dd17Smrg 
28684e9dd17Smrg /* Parse the debug info off a block of memory, pointed to by MEMORY
28784e9dd17Smrg    (already copied to GDB's address space) and MEMORY_SZ bytes long.
28884e9dd17Smrg    The implementation has to use the functions in CB to actually emit
28984e9dd17Smrg    the parsed data into GDB.  SELF is the same structure returned by
29084e9dd17Smrg    gdb_init_reader.
29184e9dd17Smrg 
29284e9dd17Smrg    Return GDB_FAIL on failure and GDB_SUCCESS on success.  */
29384e9dd17Smrg 
29484e9dd17Smrg typedef enum gdb_status (gdb_read_debug_info) (struct gdb_reader_funcs *self,
29584e9dd17Smrg                                                struct gdb_symbol_callbacks *cb,
29684e9dd17Smrg                                                void *memory, long memory_sz);
29784e9dd17Smrg 
29884e9dd17Smrg /* Unwind the current frame, CB is the set of unwind callbacks that
29984e9dd17Smrg    are to be used to do this.
30084e9dd17Smrg 
30184e9dd17Smrg    Return GDB_FAIL on failure and GDB_SUCCESS on success.  */
30284e9dd17Smrg 
30384e9dd17Smrg typedef enum gdb_status (gdb_unwind_frame) (struct gdb_reader_funcs *self,
30484e9dd17Smrg                                             struct gdb_unwind_callbacks *cb);
30584e9dd17Smrg 
30684e9dd17Smrg /* Return the frame ID corresponding to the current frame, using C to
30784e9dd17Smrg    read the current register values.  See the comment on struct
30884e9dd17Smrg    gdb_frame_id.  */
30984e9dd17Smrg 
31084e9dd17Smrg typedef struct gdb_frame_id (gdb_get_frame_id) (struct gdb_reader_funcs *self,
31184e9dd17Smrg                                                 struct gdb_unwind_callbacks *c);
31284e9dd17Smrg 
31384e9dd17Smrg /* Called when a reader is being unloaded.  This function should also
31484e9dd17Smrg    free SELF, if required.  */
31584e9dd17Smrg 
31684e9dd17Smrg typedef void (gdb_destroy_reader) (struct gdb_reader_funcs *self);
31784e9dd17Smrg 
31884e9dd17Smrg /* Called when the reader is loaded.  Must either return a properly
31984e9dd17Smrg    populated gdb_reader_funcs or NULL.  The memory allocated for the
32084e9dd17Smrg    gdb_reader_funcs is to be managed by the reader itself (i.e. if it
32184e9dd17Smrg    is allocated from the heap, it must also be freed in
32284e9dd17Smrg    gdb_destroy_reader).  */
32384e9dd17Smrg 
32484e9dd17Smrg extern struct gdb_reader_funcs *gdb_init_reader (void);
32584e9dd17Smrg 
32684e9dd17Smrg /* Pointer to the functions which implement the reader's
32784e9dd17Smrg    functionality.  The individual functions have been documented
32884e9dd17Smrg    above.
32984e9dd17Smrg 
33084e9dd17Smrg    None of the fields are optional.  */
33184e9dd17Smrg 
33284e9dd17Smrg struct gdb_reader_funcs
33384e9dd17Smrg {
33484e9dd17Smrg   /* Must be set to GDB_READER_INTERFACE_VERSION.  */
33584e9dd17Smrg   int reader_version;
33684e9dd17Smrg 
33784e9dd17Smrg   /* For use by the reader.  */
33884e9dd17Smrg   void *priv_data;
33984e9dd17Smrg 
34084e9dd17Smrg   gdb_read_debug_info *read;
34184e9dd17Smrg   gdb_unwind_frame *unwind;
34284e9dd17Smrg   gdb_get_frame_id *get_frame_id;
34384e9dd17Smrg   gdb_destroy_reader *destroy;
34484e9dd17Smrg };
34584e9dd17Smrg 
34684e9dd17Smrg #ifdef __cplusplus
34784e9dd17Smrg } /* extern "C" */
34884e9dd17Smrg #endif
34984e9dd17Smrg 
35084e9dd17Smrg #endif
351