xref: /netbsd-src/external/gpl3/gdb.old/lib/libgdb/arch/m68k/jit-reader.h (revision 8b657b0747480f8989760d71343d6dd33f8d4cf9)
10c04591cSchristos /* This file is automatically generated.  DO NOT EDIT! */
2*8b657b07Schristos /* Generated from: NetBSD: mknative-gdb,v 1.16 2023/07/31 17:09:59 christos Exp  */
347c37bc2Schristos /* Generated from: NetBSD: mknative.common,v 1.16 2018/04/15 15:13:37 christos Exp  */
40c04591cSchristos 
50c04591cSchristos /* JIT declarations for GDB, the GNU Debugger.
60c04591cSchristos 
7*8b657b07Schristos    Copyright (C) 2011-2023 Free Software Foundation, Inc.
80c04591cSchristos 
90c04591cSchristos    This file is part of GDB.
100c04591cSchristos 
110c04591cSchristos    This program is free software; you can redistribute it and/or modify
120c04591cSchristos    it under the terms of the GNU General Public License as published by
130c04591cSchristos    the Free Software Foundation; either version 3 of the License, or
140c04591cSchristos    (at your option) any later version.
150c04591cSchristos 
160c04591cSchristos    This program is distributed in the hope that it will be useful,
170c04591cSchristos    but WITHOUT ANY WARRANTY; without even the implied warranty of
180c04591cSchristos    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
190c04591cSchristos    GNU General Public License for more details.
200c04591cSchristos 
210c04591cSchristos    You should have received a copy of the GNU General Public License
220c04591cSchristos    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
230c04591cSchristos 
240c04591cSchristos #ifndef GDB_JIT_READER_H
250c04591cSchristos #define GDB_JIT_READER_H
260c04591cSchristos 
270c04591cSchristos #ifdef __cplusplus
280c04591cSchristos extern "C" {
290c04591cSchristos #endif
300c04591cSchristos 
310c04591cSchristos /* Versioning information.  See gdb_reader_funcs.  */
320c04591cSchristos 
330c04591cSchristos #define GDB_READER_INTERFACE_VERSION 1
340c04591cSchristos 
350c04591cSchristos /* Readers must be released under a GPL compatible license.  To
360c04591cSchristos    declare that the reader is indeed released under a GPL compatible
370c04591cSchristos    license, invoke the macro GDB_DECLARE_GPL_COMPATIBLE in a source
380c04591cSchristos    file.  */
390c04591cSchristos 
400c04591cSchristos #ifdef __cplusplus
410c04591cSchristos #define GDB_DECLARE_GPL_COMPATIBLE_READER       \
420c04591cSchristos   extern "C" {                                  \
430c04591cSchristos   extern int plugin_is_GPL_compatible (void);   \
440c04591cSchristos   extern int plugin_is_GPL_compatible (void)    \
450c04591cSchristos   {                                             \
460c04591cSchristos     return 0;                                   \
470c04591cSchristos   }                                             \
480c04591cSchristos   }
490c04591cSchristos 
500c04591cSchristos #else
510c04591cSchristos 
520c04591cSchristos #define GDB_DECLARE_GPL_COMPATIBLE_READER       \
530c04591cSchristos   extern int plugin_is_GPL_compatible (void);   \
540c04591cSchristos   extern int plugin_is_GPL_compatible (void)    \
550c04591cSchristos   {                                             \
560c04591cSchristos     return 0;                                   \
570c04591cSchristos   }
580c04591cSchristos 
590c04591cSchristos #endif
600c04591cSchristos 
610c04591cSchristos /* Represents an address on the target system.  */
620c04591cSchristos 
630c04591cSchristos typedef unsigned long long GDB_CORE_ADDR;
640c04591cSchristos 
650c04591cSchristos /* Return status codes.  */
660c04591cSchristos 
670c04591cSchristos enum gdb_status {
680c04591cSchristos   GDB_FAIL = 0,
690c04591cSchristos   GDB_SUCCESS = 1
700c04591cSchristos };
710c04591cSchristos 
720c04591cSchristos struct gdb_object;
730c04591cSchristos struct gdb_symtab;
740c04591cSchristos struct gdb_block;
750c04591cSchristos struct gdb_symbol_callbacks;
760c04591cSchristos 
770c04591cSchristos /* An array of these are used to represent a map from code addresses to line
780c04591cSchristos    numbers in the source file.  */
790c04591cSchristos 
800c04591cSchristos struct gdb_line_mapping
810c04591cSchristos {
820c04591cSchristos   int line;
830c04591cSchristos   GDB_CORE_ADDR pc;
840c04591cSchristos };
850c04591cSchristos 
860c04591cSchristos /* Create a new GDB code object.  Each code object can have one or
870c04591cSchristos    more symbol tables, each representing a compiled source file.  */
880c04591cSchristos 
890c04591cSchristos typedef struct gdb_object *(gdb_object_open) (struct gdb_symbol_callbacks *cb);
900c04591cSchristos 
910c04591cSchristos /* The callback used to create new symbol table.  CB is the
920c04591cSchristos    gdb_symbol_callbacks which the structure is part of.  FILE_NAME is
930c04591cSchristos    an (optionally NULL) file name to associate with this new symbol
940c04591cSchristos    table.
950c04591cSchristos 
960c04591cSchristos    Returns a new instance to gdb_symtab that can later be passed to
970c04591cSchristos    gdb_block_new, gdb_symtab_add_line_mapping and gdb_symtab_close.  */
980c04591cSchristos 
990c04591cSchristos typedef struct gdb_symtab *(gdb_symtab_open) (struct gdb_symbol_callbacks *cb,
1000c04591cSchristos                                               struct gdb_object *obj,
1010c04591cSchristos                                               const char *file_name);
1020c04591cSchristos 
1030c04591cSchristos /* Creates a new block in a given symbol table.  A symbol table is a
1040c04591cSchristos    forest of blocks, each block representing an code address range and
1050c04591cSchristos    a corresponding (optionally NULL) NAME.  In case the block
1060c04591cSchristos    corresponds to a function, the NAME passed should be the name of
1070c04591cSchristos    the function.
1080c04591cSchristos 
1090c04591cSchristos    If the new block to be created is a child of (i.e. is nested in)
1100c04591cSchristos    another block, the parent block can be passed in PARENT.  SYMTAB is
1110c04591cSchristos    the symbol table the new block is to belong in.  BEGIN, END is the
1120c04591cSchristos    code address range the block corresponds to.
1130c04591cSchristos 
1140c04591cSchristos    Returns a new instance of gdb_block, which, as of now, has no use.
1150c04591cSchristos    Note that the gdb_block returned must not be freed by the
1160c04591cSchristos    caller.  */
1170c04591cSchristos 
1180c04591cSchristos typedef struct gdb_block *(gdb_block_open) (struct gdb_symbol_callbacks *cb,
1190c04591cSchristos                                             struct gdb_symtab *symtab,
1200c04591cSchristos                                             struct gdb_block *parent,
1210c04591cSchristos                                             GDB_CORE_ADDR begin,
1220c04591cSchristos                                             GDB_CORE_ADDR end,
1230c04591cSchristos                                             const char *name);
1240c04591cSchristos 
1250c04591cSchristos /* Adds a PC to line number mapping for the symbol table SYMTAB.
1260c04591cSchristos    NLINES is the number of elements in LINES, each element
1270c04591cSchristos    corresponding to one (PC, line) pair.  */
1280c04591cSchristos 
1290c04591cSchristos typedef void (gdb_symtab_add_line_mapping) (struct gdb_symbol_callbacks *cb,
1300c04591cSchristos                                             struct gdb_symtab *symtab,
1310c04591cSchristos                                             int nlines,
1320c04591cSchristos                                             struct gdb_line_mapping *lines);
1330c04591cSchristos 
1340c04591cSchristos /* Close the symtab SYMTAB.  This signals to GDB that no more blocks
1350c04591cSchristos    will be opened on this symtab.  */
1360c04591cSchristos 
1370c04591cSchristos typedef void (gdb_symtab_close) (struct gdb_symbol_callbacks *cb,
1380c04591cSchristos                                  struct gdb_symtab *symtab);
1390c04591cSchristos 
1400c04591cSchristos 
1410c04591cSchristos /* Closes the gdb_object OBJ and adds the emitted information into
1420c04591cSchristos    GDB's internal structures.  Once this is done, the debug
1430c04591cSchristos    information will be picked up and used; this will usually be the
1440c04591cSchristos    last operation in gdb_read_debug_info.  */
1450c04591cSchristos 
1460c04591cSchristos typedef void (gdb_object_close) (struct gdb_symbol_callbacks *cb,
1470c04591cSchristos                                  struct gdb_object *obj);
1480c04591cSchristos 
1490c04591cSchristos /* Reads LEN bytes from TARGET_MEM in the target's virtual address
1500c04591cSchristos    space into GDB_BUF.
1510c04591cSchristos 
1520c04591cSchristos    Returns GDB_FAIL on failure, and GDB_SUCCESS on success.  */
1530c04591cSchristos 
1540c04591cSchristos typedef enum gdb_status (gdb_target_read) (GDB_CORE_ADDR target_mem,
1550c04591cSchristos                                            void *gdb_buf, int len);
1560c04591cSchristos 
1570c04591cSchristos /* The list of callbacks that are passed to read.  These callbacks are
1580c04591cSchristos    to be used to construct the symbol table.  The functions have been
1590c04591cSchristos    described above.  */
1600c04591cSchristos 
1610c04591cSchristos struct gdb_symbol_callbacks
1620c04591cSchristos {
1630c04591cSchristos   gdb_object_open *object_open;
1640c04591cSchristos   gdb_symtab_open *symtab_open;
1650c04591cSchristos   gdb_block_open *block_open;
1660c04591cSchristos   gdb_symtab_close *symtab_close;
1670c04591cSchristos   gdb_object_close *object_close;
1680c04591cSchristos 
1690c04591cSchristos   gdb_symtab_add_line_mapping *line_mapping_add;
1700c04591cSchristos   gdb_target_read *target_read;
1710c04591cSchristos 
1720c04591cSchristos   /* For internal use by GDB.  */
1730c04591cSchristos   void *priv_data;
1740c04591cSchristos };
1750c04591cSchristos 
1760c04591cSchristos /* Forward declaration.  */
1770c04591cSchristos 
1780c04591cSchristos struct gdb_reg_value;
1790c04591cSchristos 
1800c04591cSchristos /* A function of this type is used to free a gdb_reg_value.  See the
1810c04591cSchristos    comment on `free' in struct gdb_reg_value.  */
1820c04591cSchristos 
1830c04591cSchristos typedef void (gdb_reg_value_free) (struct gdb_reg_value *);
1840c04591cSchristos 
1850c04591cSchristos /* Denotes the value of a register.  */
1860c04591cSchristos 
1870c04591cSchristos struct gdb_reg_value
1880c04591cSchristos {
1890c04591cSchristos   /* The size of the register in bytes.  The reader need not set this
1900c04591cSchristos      field.  This will be set for (defined) register values being read
1910c04591cSchristos      from GDB using reg_get.  */
1920c04591cSchristos   int size;
1930c04591cSchristos 
1940c04591cSchristos   /* Set to non-zero if the value for the register is known.  The
1950c04591cSchristos      registers for which the reader does not call reg_set are also
1960c04591cSchristos      assumed to be undefined */
1970c04591cSchristos   int defined;
1980c04591cSchristos 
1990c04591cSchristos   /* Since gdb_reg_value is a variable sized structure, it will
2000c04591cSchristos      usually be allocated on the heap.  This function is expected to
2010c04591cSchristos      contain the corresponding "free" function.
2020c04591cSchristos 
2030c04591cSchristos      When a pointer to gdb_reg_value is being sent from GDB to the
2040c04591cSchristos      reader (via gdb_unwind_reg_get), the reader is expected to call
2050c04591cSchristos      this function (with the same gdb_reg_value as argument) once it
2060c04591cSchristos      is done with the value.
2070c04591cSchristos 
2080c04591cSchristos      When the function sends the a gdb_reg_value to GDB (via
2090c04591cSchristos      gdb_unwind_reg_set), it is expected to set this field to point to
2100c04591cSchristos      an appropriate cleanup routine (or to NULL if no cleanup is
2110c04591cSchristos      required).  */
2120c04591cSchristos   gdb_reg_value_free *free;
2130c04591cSchristos 
2140c04591cSchristos   /* The value of the register.  */
2150c04591cSchristos   unsigned char value[1];
2160c04591cSchristos };
2170c04591cSchristos 
2180c04591cSchristos /* get_frame_id in gdb_reader_funcs is to return a gdb_frame_id
2190c04591cSchristos    corresponding to the current frame.  The registers corresponding to
2200c04591cSchristos    the current frame can be read using reg_get.  Calling get_frame_id
2210c04591cSchristos    on a particular frame should return the same gdb_frame_id
2220c04591cSchristos    throughout its lifetime (i.e. till before it gets unwound).  One
2230c04591cSchristos    way to do this is by having the CODE_ADDRESS point to the
2240c04591cSchristos    function's first instruction and STACK_ADDRESS point to the value
2250c04591cSchristos    of the stack pointer when entering the function.  */
2260c04591cSchristos 
2270c04591cSchristos struct gdb_frame_id
2280c04591cSchristos {
2290c04591cSchristos   GDB_CORE_ADDR code_address;
2300c04591cSchristos   GDB_CORE_ADDR stack_address;
2310c04591cSchristos };
2320c04591cSchristos 
2330c04591cSchristos /* Forward declaration.  */
2340c04591cSchristos 
2350c04591cSchristos struct gdb_unwind_callbacks;
2360c04591cSchristos 
2370c04591cSchristos /* Returns the value of a particular register in the current frame.
2380c04591cSchristos    The current frame is the frame that needs to be unwound into the
2390c04591cSchristos    outer (earlier) frame.
2400c04591cSchristos 
2410c04591cSchristos    CB is the struct gdb_unwind_callbacks * the callback belongs to.
2420c04591cSchristos    REGNUM is the DWARF register number of the register that needs to
2430c04591cSchristos    be unwound.
2440c04591cSchristos 
2450c04591cSchristos    Returns the gdb_reg_value corresponding to the register requested.
2460c04591cSchristos    In case the value of the register has been optimized away or
2470c04591cSchristos    otherwise unavailable, the defined flag in the returned
2480c04591cSchristos    gdb_reg_value will be zero.  */
2490c04591cSchristos 
2500c04591cSchristos typedef struct gdb_reg_value *(gdb_unwind_reg_get)
2510c04591cSchristos                               (struct gdb_unwind_callbacks *cb, int regnum);
2520c04591cSchristos 
2530c04591cSchristos /* Sets the previous value of a particular register.  REGNUM is the
2540c04591cSchristos    (DWARF) register number whose value is to be set.  VAL is the value
2550c04591cSchristos    the register is to be set to.
2560c04591cSchristos 
2570c04591cSchristos    VAL is *not* copied, so the memory allocated to it cannot be
2580c04591cSchristos    reused.  Once GDB no longer needs the value, it is deallocated
2590c04591cSchristos    using the FREE function (see gdb_reg_value).
2600c04591cSchristos 
2610c04591cSchristos    A register can also be "set" to an undefined value by setting the
2620c04591cSchristos    defined in VAL to zero.  */
2630c04591cSchristos 
2640c04591cSchristos typedef void (gdb_unwind_reg_set) (struct gdb_unwind_callbacks *cb, int regnum,
2650c04591cSchristos                                    struct gdb_reg_value *val);
2660c04591cSchristos 
2670c04591cSchristos /* This struct is passed to unwind in gdb_reader_funcs, and is to be
2680c04591cSchristos    used to unwind the current frame (current being the frame whose
2690c04591cSchristos    registers can be read using reg_get) into the earlier frame.  The
2700c04591cSchristos    functions have been described above.  */
2710c04591cSchristos 
2720c04591cSchristos struct gdb_unwind_callbacks
2730c04591cSchristos {
2740c04591cSchristos   gdb_unwind_reg_get *reg_get;
2750c04591cSchristos   gdb_unwind_reg_set *reg_set;
2760c04591cSchristos   gdb_target_read *target_read;
2770c04591cSchristos 
2780c04591cSchristos   /* For internal use by GDB.  */
2790c04591cSchristos   void *priv_data;
2800c04591cSchristos };
2810c04591cSchristos 
2820c04591cSchristos /* Forward declaration.  */
2830c04591cSchristos 
2840c04591cSchristos struct gdb_reader_funcs;
2850c04591cSchristos 
2860c04591cSchristos /* Parse the debug info off a block of memory, pointed to by MEMORY
2870c04591cSchristos    (already copied to GDB's address space) and MEMORY_SZ bytes long.
2880c04591cSchristos    The implementation has to use the functions in CB to actually emit
2890c04591cSchristos    the parsed data into GDB.  SELF is the same structure returned by
2900c04591cSchristos    gdb_init_reader.
2910c04591cSchristos 
2920c04591cSchristos    Return GDB_FAIL on failure and GDB_SUCCESS on success.  */
2930c04591cSchristos 
2940c04591cSchristos typedef enum gdb_status (gdb_read_debug_info) (struct gdb_reader_funcs *self,
2950c04591cSchristos                                                struct gdb_symbol_callbacks *cb,
2960c04591cSchristos                                                void *memory, long memory_sz);
2970c04591cSchristos 
2980c04591cSchristos /* Unwind the current frame, CB is the set of unwind callbacks that
2990c04591cSchristos    are to be used to do this.
3000c04591cSchristos 
3010c04591cSchristos    Return GDB_FAIL on failure and GDB_SUCCESS on success.  */
3020c04591cSchristos 
3030c04591cSchristos typedef enum gdb_status (gdb_unwind_frame) (struct gdb_reader_funcs *self,
3040c04591cSchristos                                             struct gdb_unwind_callbacks *cb);
3050c04591cSchristos 
3060c04591cSchristos /* Return the frame ID corresponding to the current frame, using C to
3070c04591cSchristos    read the current register values.  See the comment on struct
3080c04591cSchristos    gdb_frame_id.  */
3090c04591cSchristos 
3100c04591cSchristos typedef struct gdb_frame_id (gdb_get_frame_id) (struct gdb_reader_funcs *self,
3110c04591cSchristos                                                 struct gdb_unwind_callbacks *c);
3120c04591cSchristos 
3130c04591cSchristos /* Called when a reader is being unloaded.  This function should also
3140c04591cSchristos    free SELF, if required.  */
3150c04591cSchristos 
3160c04591cSchristos typedef void (gdb_destroy_reader) (struct gdb_reader_funcs *self);
3170c04591cSchristos 
3180c04591cSchristos /* Called when the reader is loaded.  Must either return a properly
3190c04591cSchristos    populated gdb_reader_funcs or NULL.  The memory allocated for the
3200c04591cSchristos    gdb_reader_funcs is to be managed by the reader itself (i.e. if it
3210c04591cSchristos    is allocated from the heap, it must also be freed in
3220c04591cSchristos    gdb_destroy_reader).  */
3230c04591cSchristos 
3240c04591cSchristos extern struct gdb_reader_funcs *gdb_init_reader (void);
3250c04591cSchristos 
3260c04591cSchristos /* Pointer to the functions which implement the reader's
3270c04591cSchristos    functionality.  The individual functions have been documented
3280c04591cSchristos    above.
3290c04591cSchristos 
3300c04591cSchristos    None of the fields are optional.  */
3310c04591cSchristos 
3320c04591cSchristos struct gdb_reader_funcs
3330c04591cSchristos {
3340c04591cSchristos   /* Must be set to GDB_READER_INTERFACE_VERSION.  */
3350c04591cSchristos   int reader_version;
3360c04591cSchristos 
3370c04591cSchristos   /* For use by the reader.  */
3380c04591cSchristos   void *priv_data;
3390c04591cSchristos 
3400c04591cSchristos   gdb_read_debug_info *read;
3410c04591cSchristos   gdb_unwind_frame *unwind;
3420c04591cSchristos   gdb_get_frame_id *get_frame_id;
3430c04591cSchristos   gdb_destroy_reader *destroy;
3440c04591cSchristos };
3450c04591cSchristos 
3460c04591cSchristos #ifdef __cplusplus
3470c04591cSchristos } /* extern "C" */
3480c04591cSchristos #endif
3490c04591cSchristos 
3500c04591cSchristos #endif
351