xref: /netbsd-src/external/gpl3/gdb/lib/libgdb/arch/powerpc/jit-reader.h (revision 22ebeae4b2252475e0ebe332f69734639cb946ea)
17bfbcd5fSchristos /* 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  */
35a254e06Schristos /* Generated from: NetBSD: mknative.common,v 1.16 2018/04/15 15:13:37 christos Exp  */
47bfbcd5fSchristos 
57bfbcd5fSchristos /* JIT declarations for GDB, the GNU Debugger.
67bfbcd5fSchristos 
7*22ebeae4Schristos    Copyright (C) 2011-2024 Free Software Foundation, Inc.
87bfbcd5fSchristos 
97bfbcd5fSchristos    This file is part of GDB.
107bfbcd5fSchristos 
117bfbcd5fSchristos    This program is free software; you can redistribute it and/or modify
127bfbcd5fSchristos    it under the terms of the GNU General Public License as published by
137bfbcd5fSchristos    the Free Software Foundation; either version 3 of the License, or
147bfbcd5fSchristos    (at your option) any later version.
157bfbcd5fSchristos 
167bfbcd5fSchristos    This program is distributed in the hope that it will be useful,
177bfbcd5fSchristos    but WITHOUT ANY WARRANTY; without even the implied warranty of
187bfbcd5fSchristos    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
197bfbcd5fSchristos    GNU General Public License for more details.
207bfbcd5fSchristos 
217bfbcd5fSchristos    You should have received a copy of the GNU General Public License
227bfbcd5fSchristos    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
237bfbcd5fSchristos 
247bfbcd5fSchristos #ifndef GDB_JIT_READER_H
257bfbcd5fSchristos #define GDB_JIT_READER_H
267bfbcd5fSchristos 
277bfbcd5fSchristos #ifdef __cplusplus
287bfbcd5fSchristos extern "C" {
297bfbcd5fSchristos #endif
307bfbcd5fSchristos 
317bfbcd5fSchristos /* Versioning information.  See gdb_reader_funcs.  */
327bfbcd5fSchristos 
337bfbcd5fSchristos #define GDB_READER_INTERFACE_VERSION 1
347bfbcd5fSchristos 
357bfbcd5fSchristos /* Readers must be released under a GPL compatible license.  To
367bfbcd5fSchristos    declare that the reader is indeed released under a GPL compatible
377bfbcd5fSchristos    license, invoke the macro GDB_DECLARE_GPL_COMPATIBLE in a source
387bfbcd5fSchristos    file.  */
397bfbcd5fSchristos 
407bfbcd5fSchristos #ifdef __cplusplus
417bfbcd5fSchristos #define GDB_DECLARE_GPL_COMPATIBLE_READER       \
427bfbcd5fSchristos   extern "C" {                                  \
437bfbcd5fSchristos   extern int plugin_is_GPL_compatible (void);   \
447bfbcd5fSchristos   extern int plugin_is_GPL_compatible (void)    \
457bfbcd5fSchristos   {                                             \
467bfbcd5fSchristos     return 0;                                   \
477bfbcd5fSchristos   }                                             \
487bfbcd5fSchristos   }
497bfbcd5fSchristos 
507bfbcd5fSchristos #else
517bfbcd5fSchristos 
527bfbcd5fSchristos #define GDB_DECLARE_GPL_COMPATIBLE_READER       \
537bfbcd5fSchristos   extern int plugin_is_GPL_compatible (void);   \
547bfbcd5fSchristos   extern int plugin_is_GPL_compatible (void)    \
557bfbcd5fSchristos   {                                             \
567bfbcd5fSchristos     return 0;                                   \
577bfbcd5fSchristos   }
587bfbcd5fSchristos 
597bfbcd5fSchristos #endif
607bfbcd5fSchristos 
617bfbcd5fSchristos /* Represents an address on the target system.  */
627bfbcd5fSchristos 
637bfbcd5fSchristos typedef unsigned long long GDB_CORE_ADDR;
647bfbcd5fSchristos 
657bfbcd5fSchristos /* Return status codes.  */
667bfbcd5fSchristos 
677bfbcd5fSchristos enum gdb_status {
687bfbcd5fSchristos   GDB_FAIL = 0,
697bfbcd5fSchristos   GDB_SUCCESS = 1
707bfbcd5fSchristos };
717bfbcd5fSchristos 
727bfbcd5fSchristos struct gdb_object;
737bfbcd5fSchristos struct gdb_symtab;
747bfbcd5fSchristos struct gdb_block;
757bfbcd5fSchristos struct gdb_symbol_callbacks;
767bfbcd5fSchristos 
777bfbcd5fSchristos /* An array of these are used to represent a map from code addresses to line
787bfbcd5fSchristos    numbers in the source file.  */
797bfbcd5fSchristos 
807bfbcd5fSchristos struct gdb_line_mapping
817bfbcd5fSchristos {
827bfbcd5fSchristos   int line;
837bfbcd5fSchristos   GDB_CORE_ADDR pc;
847bfbcd5fSchristos };
857bfbcd5fSchristos 
867bfbcd5fSchristos /* Create a new GDB code object.  Each code object can have one or
877bfbcd5fSchristos    more symbol tables, each representing a compiled source file.  */
887bfbcd5fSchristos 
897bfbcd5fSchristos typedef struct gdb_object *(gdb_object_open) (struct gdb_symbol_callbacks *cb);
907bfbcd5fSchristos 
917bfbcd5fSchristos /* The callback used to create new symbol table.  CB is the
927bfbcd5fSchristos    gdb_symbol_callbacks which the structure is part of.  FILE_NAME is
937bfbcd5fSchristos    an (optionally NULL) file name to associate with this new symbol
947bfbcd5fSchristos    table.
957bfbcd5fSchristos 
967bfbcd5fSchristos    Returns a new instance to gdb_symtab that can later be passed to
977bfbcd5fSchristos    gdb_block_new, gdb_symtab_add_line_mapping and gdb_symtab_close.  */
987bfbcd5fSchristos 
997bfbcd5fSchristos typedef struct gdb_symtab *(gdb_symtab_open) (struct gdb_symbol_callbacks *cb,
1007bfbcd5fSchristos                                               struct gdb_object *obj,
1017bfbcd5fSchristos                                               const char *file_name);
1027bfbcd5fSchristos 
1037bfbcd5fSchristos /* Creates a new block in a given symbol table.  A symbol table is a
1047bfbcd5fSchristos    forest of blocks, each block representing an code address range and
1057bfbcd5fSchristos    a corresponding (optionally NULL) NAME.  In case the block
1067bfbcd5fSchristos    corresponds to a function, the NAME passed should be the name of
1077bfbcd5fSchristos    the function.
1087bfbcd5fSchristos 
1097bfbcd5fSchristos    If the new block to be created is a child of (i.e. is nested in)
1107bfbcd5fSchristos    another block, the parent block can be passed in PARENT.  SYMTAB is
1117bfbcd5fSchristos    the symbol table the new block is to belong in.  BEGIN, END is the
1127bfbcd5fSchristos    code address range the block corresponds to.
1137bfbcd5fSchristos 
1147bfbcd5fSchristos    Returns a new instance of gdb_block, which, as of now, has no use.
1157bfbcd5fSchristos    Note that the gdb_block returned must not be freed by the
1167bfbcd5fSchristos    caller.  */
1177bfbcd5fSchristos 
1187bfbcd5fSchristos typedef struct gdb_block *(gdb_block_open) (struct gdb_symbol_callbacks *cb,
1197bfbcd5fSchristos                                             struct gdb_symtab *symtab,
1207bfbcd5fSchristos                                             struct gdb_block *parent,
1217bfbcd5fSchristos                                             GDB_CORE_ADDR begin,
1227bfbcd5fSchristos                                             GDB_CORE_ADDR end,
1237bfbcd5fSchristos                                             const char *name);
1247bfbcd5fSchristos 
1257bfbcd5fSchristos /* Adds a PC to line number mapping for the symbol table SYMTAB.
1267bfbcd5fSchristos    NLINES is the number of elements in LINES, each element
1277bfbcd5fSchristos    corresponding to one (PC, line) pair.  */
1287bfbcd5fSchristos 
1297bfbcd5fSchristos typedef void (gdb_symtab_add_line_mapping) (struct gdb_symbol_callbacks *cb,
1307bfbcd5fSchristos                                             struct gdb_symtab *symtab,
1317bfbcd5fSchristos                                             int nlines,
1327bfbcd5fSchristos                                             struct gdb_line_mapping *lines);
1337bfbcd5fSchristos 
1347bfbcd5fSchristos /* Close the symtab SYMTAB.  This signals to GDB that no more blocks
1357bfbcd5fSchristos    will be opened on this symtab.  */
1367bfbcd5fSchristos 
1377bfbcd5fSchristos typedef void (gdb_symtab_close) (struct gdb_symbol_callbacks *cb,
1387bfbcd5fSchristos                                  struct gdb_symtab *symtab);
1397bfbcd5fSchristos 
1407bfbcd5fSchristos 
1417bfbcd5fSchristos /* Closes the gdb_object OBJ and adds the emitted information into
1427bfbcd5fSchristos    GDB's internal structures.  Once this is done, the debug
1437bfbcd5fSchristos    information will be picked up and used; this will usually be the
1447bfbcd5fSchristos    last operation in gdb_read_debug_info.  */
1457bfbcd5fSchristos 
1467bfbcd5fSchristos typedef void (gdb_object_close) (struct gdb_symbol_callbacks *cb,
1477bfbcd5fSchristos                                  struct gdb_object *obj);
1487bfbcd5fSchristos 
1497bfbcd5fSchristos /* Reads LEN bytes from TARGET_MEM in the target's virtual address
1507bfbcd5fSchristos    space into GDB_BUF.
1517bfbcd5fSchristos 
1527bfbcd5fSchristos    Returns GDB_FAIL on failure, and GDB_SUCCESS on success.  */
1537bfbcd5fSchristos 
1547bfbcd5fSchristos typedef enum gdb_status (gdb_target_read) (GDB_CORE_ADDR target_mem,
1557bfbcd5fSchristos                                            void *gdb_buf, int len);
1567bfbcd5fSchristos 
1577bfbcd5fSchristos /* The list of callbacks that are passed to read.  These callbacks are
1587bfbcd5fSchristos    to be used to construct the symbol table.  The functions have been
1597bfbcd5fSchristos    described above.  */
1607bfbcd5fSchristos 
1617bfbcd5fSchristos struct gdb_symbol_callbacks
1627bfbcd5fSchristos {
1637bfbcd5fSchristos   gdb_object_open *object_open;
1647bfbcd5fSchristos   gdb_symtab_open *symtab_open;
1657bfbcd5fSchristos   gdb_block_open *block_open;
1667bfbcd5fSchristos   gdb_symtab_close *symtab_close;
1677bfbcd5fSchristos   gdb_object_close *object_close;
1687bfbcd5fSchristos 
1697bfbcd5fSchristos   gdb_symtab_add_line_mapping *line_mapping_add;
1707bfbcd5fSchristos   gdb_target_read *target_read;
1717bfbcd5fSchristos 
1727bfbcd5fSchristos   /* For internal use by GDB.  */
1737bfbcd5fSchristos   void *priv_data;
1747bfbcd5fSchristos };
1757bfbcd5fSchristos 
1767bfbcd5fSchristos /* Forward declaration.  */
1777bfbcd5fSchristos 
1787bfbcd5fSchristos struct gdb_reg_value;
1797bfbcd5fSchristos 
1807bfbcd5fSchristos /* A function of this type is used to free a gdb_reg_value.  See the
1817bfbcd5fSchristos    comment on `free' in struct gdb_reg_value.  */
1827bfbcd5fSchristos 
1837bfbcd5fSchristos typedef void (gdb_reg_value_free) (struct gdb_reg_value *);
1847bfbcd5fSchristos 
1857bfbcd5fSchristos /* Denotes the value of a register.  */
1867bfbcd5fSchristos 
1877bfbcd5fSchristos struct gdb_reg_value
1887bfbcd5fSchristos {
1897bfbcd5fSchristos   /* The size of the register in bytes.  The reader need not set this
1907bfbcd5fSchristos      field.  This will be set for (defined) register values being read
1917bfbcd5fSchristos      from GDB using reg_get.  */
1927bfbcd5fSchristos   int size;
1937bfbcd5fSchristos 
1947bfbcd5fSchristos   /* Set to non-zero if the value for the register is known.  The
1957bfbcd5fSchristos      registers for which the reader does not call reg_set are also
1967bfbcd5fSchristos      assumed to be undefined */
1977bfbcd5fSchristos   int defined;
1987bfbcd5fSchristos 
1997bfbcd5fSchristos   /* Since gdb_reg_value is a variable sized structure, it will
2007bfbcd5fSchristos      usually be allocated on the heap.  This function is expected to
2017bfbcd5fSchristos      contain the corresponding "free" function.
2027bfbcd5fSchristos 
2037bfbcd5fSchristos      When a pointer to gdb_reg_value is being sent from GDB to the
2047bfbcd5fSchristos      reader (via gdb_unwind_reg_get), the reader is expected to call
2057bfbcd5fSchristos      this function (with the same gdb_reg_value as argument) once it
2067bfbcd5fSchristos      is done with the value.
2077bfbcd5fSchristos 
2087bfbcd5fSchristos      When the function sends the a gdb_reg_value to GDB (via
2097bfbcd5fSchristos      gdb_unwind_reg_set), it is expected to set this field to point to
2107bfbcd5fSchristos      an appropriate cleanup routine (or to NULL if no cleanup is
2117bfbcd5fSchristos      required).  */
2127bfbcd5fSchristos   gdb_reg_value_free *free;
2137bfbcd5fSchristos 
2147bfbcd5fSchristos   /* The value of the register.  */
2157bfbcd5fSchristos   unsigned char value[1];
2167bfbcd5fSchristos };
2177bfbcd5fSchristos 
2187bfbcd5fSchristos /* get_frame_id in gdb_reader_funcs is to return a gdb_frame_id
2197bfbcd5fSchristos    corresponding to the current frame.  The registers corresponding to
2207bfbcd5fSchristos    the current frame can be read using reg_get.  Calling get_frame_id
2217bfbcd5fSchristos    on a particular frame should return the same gdb_frame_id
2227bfbcd5fSchristos    throughout its lifetime (i.e. till before it gets unwound).  One
2237bfbcd5fSchristos    way to do this is by having the CODE_ADDRESS point to the
2247bfbcd5fSchristos    function's first instruction and STACK_ADDRESS point to the value
2257bfbcd5fSchristos    of the stack pointer when entering the function.  */
2267bfbcd5fSchristos 
2277bfbcd5fSchristos struct gdb_frame_id
2287bfbcd5fSchristos {
2297bfbcd5fSchristos   GDB_CORE_ADDR code_address;
2307bfbcd5fSchristos   GDB_CORE_ADDR stack_address;
2317bfbcd5fSchristos };
2327bfbcd5fSchristos 
2337bfbcd5fSchristos /* Forward declaration.  */
2347bfbcd5fSchristos 
2357bfbcd5fSchristos struct gdb_unwind_callbacks;
2367bfbcd5fSchristos 
2377bfbcd5fSchristos /* Returns the value of a particular register in the current frame.
2387bfbcd5fSchristos    The current frame is the frame that needs to be unwound into the
2397bfbcd5fSchristos    outer (earlier) frame.
2407bfbcd5fSchristos 
2417bfbcd5fSchristos    CB is the struct gdb_unwind_callbacks * the callback belongs to.
2427bfbcd5fSchristos    REGNUM is the DWARF register number of the register that needs to
2437bfbcd5fSchristos    be unwound.
2447bfbcd5fSchristos 
2457bfbcd5fSchristos    Returns the gdb_reg_value corresponding to the register requested.
2467bfbcd5fSchristos    In case the value of the register has been optimized away or
2477bfbcd5fSchristos    otherwise unavailable, the defined flag in the returned
2487bfbcd5fSchristos    gdb_reg_value will be zero.  */
2497bfbcd5fSchristos 
2507bfbcd5fSchristos typedef struct gdb_reg_value *(gdb_unwind_reg_get)
2517bfbcd5fSchristos                               (struct gdb_unwind_callbacks *cb, int regnum);
2527bfbcd5fSchristos 
2537bfbcd5fSchristos /* Sets the previous value of a particular register.  REGNUM is the
2547bfbcd5fSchristos    (DWARF) register number whose value is to be set.  VAL is the value
2557bfbcd5fSchristos    the register is to be set to.
2567bfbcd5fSchristos 
2577bfbcd5fSchristos    VAL is *not* copied, so the memory allocated to it cannot be
2587bfbcd5fSchristos    reused.  Once GDB no longer needs the value, it is deallocated
2597bfbcd5fSchristos    using the FREE function (see gdb_reg_value).
2607bfbcd5fSchristos 
2617bfbcd5fSchristos    A register can also be "set" to an undefined value by setting the
2627bfbcd5fSchristos    defined in VAL to zero.  */
2637bfbcd5fSchristos 
2647bfbcd5fSchristos typedef void (gdb_unwind_reg_set) (struct gdb_unwind_callbacks *cb, int regnum,
2657bfbcd5fSchristos                                    struct gdb_reg_value *val);
2667bfbcd5fSchristos 
2677bfbcd5fSchristos /* This struct is passed to unwind in gdb_reader_funcs, and is to be
2687bfbcd5fSchristos    used to unwind the current frame (current being the frame whose
2697bfbcd5fSchristos    registers can be read using reg_get) into the earlier frame.  The
2707bfbcd5fSchristos    functions have been described above.  */
2717bfbcd5fSchristos 
2727bfbcd5fSchristos struct gdb_unwind_callbacks
2737bfbcd5fSchristos {
2747bfbcd5fSchristos   gdb_unwind_reg_get *reg_get;
2757bfbcd5fSchristos   gdb_unwind_reg_set *reg_set;
2767bfbcd5fSchristos   gdb_target_read *target_read;
2777bfbcd5fSchristos 
2787bfbcd5fSchristos   /* For internal use by GDB.  */
2797bfbcd5fSchristos   void *priv_data;
2807bfbcd5fSchristos };
2817bfbcd5fSchristos 
2827bfbcd5fSchristos /* Forward declaration.  */
2837bfbcd5fSchristos 
2847bfbcd5fSchristos struct gdb_reader_funcs;
2857bfbcd5fSchristos 
2867bfbcd5fSchristos /* Parse the debug info off a block of memory, pointed to by MEMORY
2877bfbcd5fSchristos    (already copied to GDB's address space) and MEMORY_SZ bytes long.
2887bfbcd5fSchristos    The implementation has to use the functions in CB to actually emit
2897bfbcd5fSchristos    the parsed data into GDB.  SELF is the same structure returned by
2907bfbcd5fSchristos    gdb_init_reader.
2917bfbcd5fSchristos 
2927bfbcd5fSchristos    Return GDB_FAIL on failure and GDB_SUCCESS on success.  */
2937bfbcd5fSchristos 
2947bfbcd5fSchristos typedef enum gdb_status (gdb_read_debug_info) (struct gdb_reader_funcs *self,
2957bfbcd5fSchristos                                                struct gdb_symbol_callbacks *cb,
2967bfbcd5fSchristos                                                void *memory, long memory_sz);
2977bfbcd5fSchristos 
2987bfbcd5fSchristos /* Unwind the current frame, CB is the set of unwind callbacks that
2997bfbcd5fSchristos    are to be used to do this.
3007bfbcd5fSchristos 
3017bfbcd5fSchristos    Return GDB_FAIL on failure and GDB_SUCCESS on success.  */
3027bfbcd5fSchristos 
3037bfbcd5fSchristos typedef enum gdb_status (gdb_unwind_frame) (struct gdb_reader_funcs *self,
3047bfbcd5fSchristos                                             struct gdb_unwind_callbacks *cb);
3057bfbcd5fSchristos 
3067bfbcd5fSchristos /* Return the frame ID corresponding to the current frame, using C to
3077bfbcd5fSchristos    read the current register values.  See the comment on struct
3087bfbcd5fSchristos    gdb_frame_id.  */
3097bfbcd5fSchristos 
3107bfbcd5fSchristos typedef struct gdb_frame_id (gdb_get_frame_id) (struct gdb_reader_funcs *self,
3117bfbcd5fSchristos                                                 struct gdb_unwind_callbacks *c);
3127bfbcd5fSchristos 
3137bfbcd5fSchristos /* Called when a reader is being unloaded.  This function should also
3147bfbcd5fSchristos    free SELF, if required.  */
3157bfbcd5fSchristos 
3167bfbcd5fSchristos typedef void (gdb_destroy_reader) (struct gdb_reader_funcs *self);
3177bfbcd5fSchristos 
3187bfbcd5fSchristos /* Called when the reader is loaded.  Must either return a properly
3197bfbcd5fSchristos    populated gdb_reader_funcs or NULL.  The memory allocated for the
3207bfbcd5fSchristos    gdb_reader_funcs is to be managed by the reader itself (i.e. if it
3217bfbcd5fSchristos    is allocated from the heap, it must also be freed in
3227bfbcd5fSchristos    gdb_destroy_reader).  */
3237bfbcd5fSchristos 
3247bfbcd5fSchristos extern struct gdb_reader_funcs *gdb_init_reader (void);
3257bfbcd5fSchristos 
3267bfbcd5fSchristos /* Pointer to the functions which implement the reader's
3277bfbcd5fSchristos    functionality.  The individual functions have been documented
3287bfbcd5fSchristos    above.
3297bfbcd5fSchristos 
3307bfbcd5fSchristos    None of the fields are optional.  */
3317bfbcd5fSchristos 
3327bfbcd5fSchristos struct gdb_reader_funcs
3337bfbcd5fSchristos {
3347bfbcd5fSchristos   /* Must be set to GDB_READER_INTERFACE_VERSION.  */
3357bfbcd5fSchristos   int reader_version;
3367bfbcd5fSchristos 
3377bfbcd5fSchristos   /* For use by the reader.  */
3387bfbcd5fSchristos   void *priv_data;
3397bfbcd5fSchristos 
3407bfbcd5fSchristos   gdb_read_debug_info *read;
3417bfbcd5fSchristos   gdb_unwind_frame *unwind;
3427bfbcd5fSchristos   gdb_get_frame_id *get_frame_id;
3437bfbcd5fSchristos   gdb_destroy_reader *destroy;
3447bfbcd5fSchristos };
3457bfbcd5fSchristos 
3467bfbcd5fSchristos #ifdef __cplusplus
3477bfbcd5fSchristos } /* extern "C" */
3487bfbcd5fSchristos #endif
3497bfbcd5fSchristos 
3507bfbcd5fSchristos #endif
351