gdb/jit-reader.h - gdb

Data types defined

Macros defined

Source code

  1. /* JIT declarations for GDB, the GNU Debugger.

  2.    Copyright (C) 2011-2014 Free Software Foundation, Inc.

  3.    This file is part of GDB.

  4.    This program is free software; you can redistribute it and/or modify
  5.    it under the terms of the GNU General Public License as published by
  6.    the Free Software Foundation; either version 3 of the License, or
  7.    (at your option) any later version.

  8.    This program is distributed in the hope that it will be useful,
  9.    but WITHOUT ANY WARRANTY; without even the implied warranty of
  10.    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  11.    GNU General Public License for more details.

  12.    You should have received a copy of the GNU General Public License
  13.    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */

  14. #ifndef GDB_JIT_READER_H
  15. #define GDB_JIT_READER_H

  16. #ifdef __cplusplus
  17. extern "C" {
  18. #endif

  19. /* Versioning information.  See gdb_reader_funcs.  */

  20. #define GDB_READER_INTERFACE_VERSION 1

  21. /* Readers must be released under a GPL compatible license.  To
  22.    declare that the reader is indeed released under a GPL compatible
  23.    license, invoke the macro GDB_DECLARE_GPL_COMPATIBLE in a source
  24.    file.  */

  25. #ifdef __cplusplus
  26. #define GDB_DECLARE_GPL_COMPATIBLE_READER       \
  27.   extern "C" {                                  \
  28.   extern int plugin_is_GPL_compatible (void);   \
  29.   extern int plugin_is_GPL_compatible (void)    \
  30.   {                                             \
  31.     return 0;                                   \
  32.   }                                             \
  33.   }

  34. #else

  35. #define GDB_DECLARE_GPL_COMPATIBLE_READER       \
  36.   extern int plugin_is_GPL_compatible (void);   \
  37.   extern int plugin_is_GPL_compatible (void)    \
  38.   {                                             \
  39.     return 0;                                   \
  40.   }

  41. #endif

  42. /* Represents an address on the target system.  */

  43. typedef unsigned long GDB_CORE_ADDR;

  44. /* Return status codes.  */

  45. enum gdb_status {
  46.   GDB_FAIL = 0,
  47.   GDB_SUCCESS = 1
  48. };

  49. struct gdb_object;
  50. struct gdb_symtab;
  51. struct gdb_block;
  52. struct gdb_symbol_callbacks;

  53. /* An array of these are used to represent a map from code addresses to line
  54.    numbers in the source file.  */

  55. struct gdb_line_mapping
  56. {
  57.   int line;
  58.   GDB_CORE_ADDR pc;
  59. };

  60. /* Create a new GDB code object.  Each code object can have one or
  61.    more symbol tables, each representing a compiled source file.  */

  62. typedef struct gdb_object *(gdb_object_open) (struct gdb_symbol_callbacks *cb);

  63. /* The callback used to create new symbol table.  CB is the
  64.    gdb_symbol_callbacks which the structure is part of.  FILE_NAME is
  65.    an (optionally NULL) file name to associate with this new symbol
  66.    table.

  67.    Returns a new instance to gdb_symtab that can later be passed to
  68.    gdb_block_new, gdb_symtab_add_line_mapping and gdb_symtab_close.  */

  69. typedef struct gdb_symtab *(gdb_symtab_open) (struct gdb_symbol_callbacks *cb,
  70.                                               struct gdb_object *obj,
  71.                                               const char *file_name);

  72. /* Creates a new block in a given symbol table.  A symbol table is a
  73.    forest of blocks, each block representing an code address range and
  74.    a corresponding (optionally NULL) NAME.  In case the block
  75.    corresponds to a function, the NAME passed should be the name of
  76.    the function.

  77.    If the new block to be created is a child of (i.e. is nested in)
  78.    another block, the parent block can be passed in PARENT.  SYMTAB is
  79.    the symbol table the new block is to belong in.  BEGIN, END is the
  80.    code address range the block corresponds to.

  81.    Returns a new instance of gdb_block, which, as of now, has no use.
  82.    Note that the gdb_block returned must not be freed by the
  83.    caller.  */

  84. typedef struct gdb_block *(gdb_block_open) (struct gdb_symbol_callbacks *cb,
  85.                                             struct gdb_symtab *symtab,
  86.                                             struct gdb_block *parent,
  87.                                             GDB_CORE_ADDR begin,
  88.                                             GDB_CORE_ADDR end,
  89.                                             const char *name);

  90. /* Adds a PC to line number mapping for the symbol table SYMTAB.
  91.    NLINES is the number of elements in LINES, each element
  92.    corresponding to one (PC, line) pair.  */

  93. typedef void (gdb_symtab_add_line_mapping) (struct gdb_symbol_callbacks *cb,
  94.                                             struct gdb_symtab *symtab,
  95.                                             int nlines,
  96.                                             struct gdb_line_mapping *lines);

  97. /* Close the symtab SYMTAB.  This signals to GDB that no more blocks
  98.    will be opened on this symtab.  */

  99. typedef void (gdb_symtab_close) (struct gdb_symbol_callbacks *cb,
  100.                                  struct gdb_symtab *symtab);


  101. /* Closes the gdb_object OBJ and adds the emitted information into
  102.    GDB's internal structures.  Once this is done, the debug
  103.    information will be picked up and used; this will usually be the
  104.    last operation in gdb_read_debug_info.  */

  105. typedef void (gdb_object_close) (struct gdb_symbol_callbacks *cb,
  106.                                  struct gdb_object *obj);

  107. /* Reads LEN bytes from TARGET_MEM in the target's virtual address
  108.    space into GDB_BUF.

  109.    Returns GDB_FAIL on failure, and GDB_SUCCESS on success.  */

  110. typedef enum gdb_status (gdb_target_read) (GDB_CORE_ADDR target_mem,
  111.                                            void *gdb_buf, int len);

  112. /* The list of callbacks that are passed to read.  These callbacks are
  113.    to be used to construct the symbol table.  The functions have been
  114.    described above.  */

  115. struct gdb_symbol_callbacks
  116. {
  117.   gdb_object_open *object_open;
  118.   gdb_symtab_open *symtab_open;
  119.   gdb_block_open *block_open;
  120.   gdb_symtab_close *symtab_close;
  121.   gdb_object_close *object_close;

  122.   gdb_symtab_add_line_mapping *line_mapping_add;
  123.   gdb_target_read *target_read;

  124.   /* For internal use by GDB.  */
  125.   void *priv_data;
  126. };

  127. /* Forward declaration.  */

  128. struct gdb_reg_value;

  129. /* A function of this type is used to free a gdb_reg_value.  See the
  130.    comment on `free' in struct gdb_reg_value.  */

  131. typedef void (gdb_reg_value_free) (struct gdb_reg_value *);

  132. /* Denotes the value of a register.  */

  133. struct gdb_reg_value
  134. {
  135.   /* The size of the register in bytes.  The reader need not set this
  136.      field.  This will be set for (defined) register values being read
  137.      from GDB using reg_get.  */
  138.   int size;

  139.   /* Set to non-zero if the value for the register is known.  The
  140.      registers for which the reader does not call reg_set are also
  141.      assumed to be undefined */
  142.   int defined;

  143.   /* Since gdb_reg_value is a variable sized structure, it will
  144.      usually be allocated on the heap.  This function is expected to
  145.      contain the corresponding "free" function.

  146.      When a pointer to gdb_reg_value is being sent from GDB to the
  147.      reader (via gdb_unwind_reg_get), the reader is expected to call
  148.      this function (with the same gdb_reg_value as argument) once it
  149.      is done with the value.

  150.      When the function sends the a gdb_reg_value to GDB (via
  151.      gdb_unwind_reg_set), it is expected to set this field to point to
  152.      an appropriate cleanup routine (or to NULL if no cleanup is
  153.      required).  */
  154.   gdb_reg_value_free *free;

  155.   /* The value of the register.  */
  156.   unsigned char value[1];
  157. };

  158. /* get_frame_id in gdb_reader_funcs is to return a gdb_frame_id
  159.    corresponding to the current frame.  The registers corresponding to
  160.    the current frame can be read using reg_get.  Calling get_frame_id
  161.    on a particular frame should return the same gdb_frame_id
  162.    throughout its lifetime (i.e. till before it gets unwound).  One
  163.    way to do this is by having the CODE_ADDRESS point to the
  164.    function's first instruction and STACK_ADDRESS point to the value
  165.    of the stack pointer when entering the function.  */

  166. struct gdb_frame_id
  167. {
  168.   GDB_CORE_ADDR code_address;
  169.   GDB_CORE_ADDR stack_address;
  170. };

  171. /* Forward declaration.  */

  172. struct gdb_unwind_callbacks;

  173. /* Returns the value of a particular register in the current frame.
  174.    The current frame is the frame that needs to be unwound into the
  175.    outer (earlier) frame.

  176.    CB is the struct gdb_unwind_callbacks * the callback belongs to.
  177.    REGNUM is the DWARF register number of the register that needs to
  178.    be unwound.

  179.    Returns the gdb_reg_value corresponding to the register requested.
  180.    In case the value of the register has been optimized away or
  181.    otherwise unavailable, the defined flag in the returned
  182.    gdb_reg_value will be zero.  */

  183. typedef struct gdb_reg_value *(gdb_unwind_reg_get)
  184.                               (struct gdb_unwind_callbacks *cb, int regnum);

  185. /* Sets the previous value of a particular register.  REGNUM is the
  186.    (DWARF) register number whose value is to be setVAL is the value
  187.    the register is to be set to.

  188.    VAL is *not* copied, so the memory allocated to it cannot be
  189.    reused.  Once GDB no longer needs the value, it is deallocated
  190.    using the FREE function (see gdb_reg_value).

  191.    A register can also be "set" to an undefined value by setting the
  192.    defined in VAL to zero.  */

  193. typedef void (gdb_unwind_reg_set) (struct gdb_unwind_callbacks *cb, int regnum,
  194.                                    struct gdb_reg_value *val);

  195. /* This struct is passed to unwind in gdb_reader_funcs, and is to be
  196.    used to unwind the current frame (current being the frame whose
  197.    registers can be read using reg_get) into the earlier frame.  The
  198.    functions have been described above.  */

  199. struct gdb_unwind_callbacks
  200. {
  201.   gdb_unwind_reg_get *reg_get;
  202.   gdb_unwind_reg_set *reg_set;
  203.   gdb_target_read *target_read;

  204.   /* For internal use by GDB.  */
  205.   void *priv_data;
  206. };

  207. /* Forward declaration.  */

  208. struct gdb_reader_funcs;

  209. /* Parse the debug info off a block of memory, pointed to by MEMORY
  210.    (already copied to GDB's address space) and MEMORY_SZ bytes long.
  211.    The implementation has to use the functions in CB to actually emit
  212.    the parsed data into GDB.  SELF is the same structure returned by
  213.    gdb_init_reader.

  214.    Return GDB_FAIL on failure and GDB_SUCCESS on success.  */

  215. typedef enum gdb_status (gdb_read_debug_info) (struct gdb_reader_funcs *self,
  216.                                                struct gdb_symbol_callbacks *cb,
  217.                                                void *memory, long memory_sz);

  218. /* Unwind the current frame, CB is the set of unwind callbacks that
  219.    are to be used to do this.

  220.    Return GDB_FAIL on failure and GDB_SUCCESS on success.  */

  221. typedef enum gdb_status (gdb_unwind_frame) (struct gdb_reader_funcs *self,
  222.                                             struct gdb_unwind_callbacks *cb);

  223. /* Return the frame ID corresponding to the current frame, using C to
  224.    read the current register values.  See the comment on struct
  225.    gdb_frame_id.  */

  226. typedef struct gdb_frame_id (gdb_get_frame_id) (struct gdb_reader_funcs *self,
  227.                                                 struct gdb_unwind_callbacks *c);

  228. /* Called when a reader is being unloaded.  This function should also
  229.    free SELF, if required.  */

  230. typedef void (gdb_destroy_reader) (struct gdb_reader_funcs *self);

  231. /* Called when the reader is loaded.  Must either return a properly
  232.    populated gdb_reader_funcs or NULL.  The memory allocated for the
  233.    gdb_reader_funcs is to be managed by the reader itself (i.e. if it
  234.    is allocated from the heap, it must also be freed in
  235.    gdb_destroy_reader).  */

  236. extern struct gdb_reader_funcs *gdb_init_reader (void);

  237. /* Pointer to the functions which implement the reader's
  238.    functionality.  The individual functions have been documented
  239.    above.

  240.    None of the fields are optional.  */

  241. struct gdb_reader_funcs
  242. {
  243.   /* Must be set to GDB_READER_INTERFACE_VERSION.  */
  244.   int reader_version;

  245.   /* For use by the reader.  */
  246.   void *priv_data;

  247.   gdb_read_debug_info *read;
  248.   gdb_unwind_frame *unwind;
  249.   gdb_get_frame_id *get_frame_id;
  250.   gdb_destroy_reader *destroy;
  251. };

  252. #ifdef __cplusplus
  253. } /* extern "C" */
  254. #endif

  255. #endif