gdb/minsyms.h - gdb

Data types defined

Macros defined

Source code

  1. /* Minimal symbol table definitions for GDB.

  2.    Copyright (C) 2011-2015 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 MINSYMS_H
  15. #define MINSYMS_H

  16. /* Several lookup functions return both a minimal symbol and the
  17.    objfile in which it is found.  This structure is used in these
  18.    cases.  */

  19. struct bound_minimal_symbol
  20. {
  21.   /* The minimal symbol that was found, or NULL if no minimal symbol
  22.      was found.  */

  23.   struct minimal_symbol *minsym;

  24.   /* If MINSYM is not NULL, then this is the objfile in which the
  25.      symbol is defined.  */

  26.   struct objfile *objfile;
  27. };

  28. /* This header declares most of the API for dealing with minimal
  29.    symbols and minimal symbol tables.  A few things are declared
  30.    elsewhere; see below.

  31.    A minimal symbol is a symbol for which there is no direct debug
  32.    information.  For example, for an ELF binary, minimal symbols are
  33.    created from the ELF symbol table.

  34.    For the definition of the minimal symbol structure, see struct
  35.    minimal_symbol in symtab.h.

  36.    Minimal symbols are stored in tables attached to an objfile; see
  37.    objfiles.h for details.  Code should generally treat these tables
  38.    as opaque and use functions provided by minsyms.c to inspect them.
  39. */

  40. /* Prepare to start collecting minimal symbols.  This should be called
  41.    by a symbol reader to initialize the minimal symbol module.
  42.    Currently, minimal symbol table creation is not reentrant; it
  43.    relies on global (static) variables in minsyms.c.  */

  44. void init_minimal_symbol_collection (void);

  45. /* Return a cleanup which is used to clean up the global state left
  46.    over by minimal symbol creation.  After calling
  47.    init_minimal_symbol_collection, a symbol reader should call this
  48.    function.  Then, after all minimal symbols have been read,
  49.    regardless of whether they are installed or not, the cleanup
  50.    returned by this function should be run.  */

  51. struct cleanup *make_cleanup_discard_minimal_symbols (void);

  52. /* Record a new minimal symbol.  This is the "full" entry point;
  53.    simpler convenience entry points are also provided below.

  54.    This returns a new minimal symbol.  It is ok to modify the returned
  55.    minimal symbol (though generally not necessary).  It is not ok,
  56.    though, to stash the pointer anywhere; as minimal symbols may be
  57.    moved after creation.  The memory for the returned minimal symbol
  58.    is still owned by the minsyms.c code, and should not be freed.

  59.    Arguments are:

  60.    NAME - the symbol's name
  61.    NAME_LEN - the length of the name
  62.    COPY_NAME - if true, the minsym code must make a copy of NAME.  If
  63.    false, then NAME must be NUL-terminated, and must have a lifetime
  64.    that is at least as long as OBJFILE's lifetime.
  65.    ADDRESS - the address of the symbol
  66.    MS_TYPE - the type of the symbol
  67.    SECTION - the symbol's section
  68.    appropriate obj_section for the minimal symbol.  This can be NULL.
  69.    OBJFILE - the objfile associated with the minimal symbol.  */

  70. struct minimal_symbol *prim_record_minimal_symbol_full
  71.     (const char *name,
  72.      int name_len,
  73.      int copy_name,
  74.      CORE_ADDR address,
  75.      enum minimal_symbol_type ms_type,
  76.      int section,
  77.      struct objfile *objfile);

  78. /* Like prim_record_minimal_symbol_full, but:
  79.    - uses strlen to compute NAME_LEN,
  80.    - passes COPY_NAME = 1,
  81.    - and passes a default SECTION, depending on the type

  82.    This variant does not return the new symbol.  */

  83. void prim_record_minimal_symbol (const char *, CORE_ADDR,
  84.                                  enum minimal_symbol_type,
  85.                                  struct objfile *);

  86. /* Like prim_record_minimal_symbol_full, but:
  87.    - uses strlen to compute NAME_LEN,
  88.    - passes COPY_NAME = 1.  */

  89. struct minimal_symbol *prim_record_minimal_symbol_and_info
  90.     (const char *,
  91.      CORE_ADDR,
  92.      enum minimal_symbol_type,
  93.      int section,
  94.      struct objfile *);

  95. /* Install the minimal symbols that have been collected into the given
  96.    objfile.  After this is called, the cleanup returned by
  97.    make_cleanup_discard_minimal_symbols should be run in order to
  98.    clean up global state.  */

  99. void install_minimal_symbols (struct objfile *);

  100. /* Create the terminating entry of OBJFILE's minimal symbol table.
  101.    If OBJFILE->msymbols is zero, allocate a single entry from
  102.    OBJFILE->objfile_obstack; otherwise, just initialize
  103.    OBJFILE->msymbols[OBJFILE->minimal_symbol_count].  */

  104. void terminate_minimal_symbol_table (struct objfile *objfile);



  105. /* Compute a hash code for the string argument.  */

  106. unsigned int msymbol_hash (const char *);

  107. /* Like msymbol_hash, but compute a hash code that is compatible with
  108.    strcmp_iw.  */

  109. unsigned int msymbol_hash_iw (const char *);

  110. /* Compute the next hash value from previous HASH and the character C.  This
  111.    is only a GDB in-memory computed value with no external files compatibility
  112.    requirements.  */

  113. #define SYMBOL_HASH_NEXT(hash, c)                        \
  114.   ((hash) * 67 + tolower ((unsigned char) (c)) - 113)



  115. /* Look through all the current minimal symbol tables and find the
  116.    first minimal symbol that matches NAME.  If OBJF is non-NULL, limit
  117.    the search to that objfile.  If SFILE is non-NULL, the only
  118.    file-scope symbols considered will be from that source file (global
  119.    symbols are still preferred).  Returns a bound minimal symbol that
  120.    matches, or an empty bound minimal symbol if no match is found.  */

  121. struct bound_minimal_symbol lookup_minimal_symbol (const char *,
  122.                                                    const char *,
  123.                                                    struct objfile *);

  124. /* Like lookup_minimal_symbol, but searches all files and
  125.    objfiles.  */

  126. struct bound_minimal_symbol lookup_bound_minimal_symbol (const char *);

  127. /* Find the minimal symbol named NAME, and return both the minsym
  128.    struct and its objfile.  This only checks the linkage name.  */

  129. struct bound_minimal_symbol lookup_minimal_symbol_and_objfile (const char *);

  130. /* Look through all the current minimal symbol tables and find the
  131.    first minimal symbol that matches NAME and has text type.  If OBJF
  132.    is non-NULL, limit the search to that objfile.  Returns a bound
  133.    minimal symbol that matches, or an "empty" bound minimal symbol
  134.    otherwise.

  135.    This function only searches the mangled (linkage) names.  */

  136. struct bound_minimal_symbol lookup_minimal_symbol_text (const char *,
  137.                                                         struct objfile *);

  138. /* Look through all the current minimal symbol tables and find the
  139.    first minimal symbol that matches NAME and is a solib trampoline.
  140.    If OBJF is non-NULL, limit the search to that objfile.  Returns a
  141.    pointer to the minimal symbol that matches, or NULL if no match is
  142.    found.

  143.    This function only searches the mangled (linkage) names.  */

  144. struct bound_minimal_symbol lookup_minimal_symbol_solib_trampoline
  145.     (const char *,
  146.      struct objfile *);

  147. /* Look through all the current minimal symbol tables and find the
  148.    first minimal symbol that matches NAME and PC.  If OBJF is non-NULL,
  149.    limit the search to that objfile.  Returns a pointer to the minimal
  150.    symbol that matches, or NULL if no match is found.  */

  151. struct minimal_symbol *lookup_minimal_symbol_by_pc_name
  152.     (CORE_ADDR, const char *, struct objfile *);

  153. /* Search through the minimal symbol table for each objfile and find
  154.    the symbol whose address is the largest address that is still less
  155.    than or equal to PC, and which matches SECTION.

  156.    If SECTION is NULL, this uses the result of find_pc_section
  157.    instead.

  158.    The result has a non-NULL 'minsym' member if such a symbol is
  159.    found, or NULL if PC is not in a suitable range.  */

  160. struct bound_minimal_symbol lookup_minimal_symbol_by_pc_section
  161.     (CORE_ADDR,
  162.      struct obj_section *);

  163. /* Backward compatibility: search through the minimal symbol table
  164.    for a matching PC (no section given).

  165.    This is a wrapper that calls lookup_minimal_symbol_by_pc_section
  166.    with a NULL section argument.  */

  167. struct bound_minimal_symbol lookup_minimal_symbol_by_pc (CORE_ADDR);

  168. /* Iterate over all the minimal symbols in the objfile OBJF which
  169.    match NAME.  Both the ordinary and demangled names of each symbol
  170.    are considered.  The caller is responsible for canonicalizing NAME,
  171.    should that need to be done.

  172.    For each matching symbol, CALLBACK is called with the symbol and
  173.    USER_DATA as arguments.  */

  174. void iterate_over_minimal_symbols (struct objfile *objf,
  175.                                    const char *name,
  176.                                    void (*callback) (struct minimal_symbol *,
  177.                                                      void *),
  178.                                    void *user_data);

  179. /* Compute the upper bound of MINSYM.  The upper bound is the last
  180.    address thought to be part of the symbol.  If the symbol has a
  181.    size, it is used.  Otherwise use the lesser of the next minimal
  182.    symbol in the same section, or the end of the section, as the end
  183.    of the function.  */

  184. CORE_ADDR minimal_symbol_upper_bound (struct bound_minimal_symbol minsym);

  185. #endif /* MINSYMS_H */