Home | History | Annotate | Line # | Download | only in gdb
      1 /* Legacy support routines for building symbol tables in GDB's internal format.
      2    Copyright (C) 1986-2024 Free Software Foundation, Inc.
      3 
      4    This file is part of GDB.
      5 
      6    This program is free software; you can redistribute it and/or modify
      7    it under the terms of the GNU General Public License as published by
      8    the Free Software Foundation; either version 3 of the License, or
      9    (at your option) any later version.
     10 
     11    This program is distributed in the hope that it will be useful,
     12    but WITHOUT ANY WARRANTY; without even the implied warranty of
     13    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     14    GNU General Public License for more details.
     15 
     16    You should have received a copy of the GNU General Public License
     17    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
     18 
     19 #include "buildsym-legacy.h"
     20 #include "symtab.h"
     21 
     22 /* The work-in-progress of the compunit we are building.
     23    This is created first, before any subfiles by start_compunit_symtab.  */
     24 
     25 static struct buildsym_compunit *buildsym_compunit;
     26 
     27 void
     28 record_debugformat (const char *format)
     29 {
     30   buildsym_compunit->record_debugformat (format);
     31 }
     32 
     33 void
     34 record_producer (const char *producer)
     35 {
     36   buildsym_compunit->record_producer (producer);
     37 }
     38 
     39 
     40 
     42 /* See buildsym.h.  */
     43 
     44 void
     45 set_last_source_file (const char *name)
     46 {
     47   gdb_assert (buildsym_compunit != nullptr || name == nullptr);
     48   if (buildsym_compunit != nullptr)
     49     buildsym_compunit->set_last_source_file (name);
     50 }
     51 
     52 /* See buildsym.h.  */
     53 
     54 const char *
     55 get_last_source_file ()
     56 {
     57   if (buildsym_compunit == nullptr)
     58     return nullptr;
     59   return buildsym_compunit->get_last_source_file ();
     60 }
     61 
     62 /* See buildsym.h.  */
     63 
     64 void
     65 set_last_source_start_addr (CORE_ADDR addr)
     66 {
     67   gdb_assert (buildsym_compunit != nullptr);
     68   buildsym_compunit->set_last_source_start_addr (addr);
     69 }
     70 
     71 /* See buildsym.h.  */
     72 
     73 CORE_ADDR
     74 get_last_source_start_addr ()
     75 {
     76   gdb_assert (buildsym_compunit != nullptr);
     77   return buildsym_compunit->get_last_source_start_addr ();
     78 }
     79 
     80 /* See buildsym.h.  */
     81 
     82 bool
     83 outermost_context_p ()
     84 {
     85   gdb_assert (buildsym_compunit != nullptr);
     86   return buildsym_compunit->outermost_context_p ();
     87 }
     88 
     89 /* See buildsym.h.  */
     90 
     91 int
     92 get_context_stack_depth ()
     93 {
     94   gdb_assert (buildsym_compunit != nullptr);
     95   return buildsym_compunit->get_context_stack_depth ();
     96 }
     97 
     98 /* See buildsym.h.  */
     99 
    100 struct subfile *
    101 get_current_subfile ()
    102 {
    103   gdb_assert (buildsym_compunit != nullptr);
    104   return buildsym_compunit->get_current_subfile ();
    105 }
    106 
    107 /* See buildsym.h.  */
    108 
    109 struct pending **
    110 get_local_symbols ()
    111 {
    112   gdb_assert (buildsym_compunit != nullptr);
    113   return buildsym_compunit->get_local_symbols ();
    114 }
    115 
    116 /* See buildsym.h.  */
    117 
    118 struct pending **
    119 get_file_symbols ()
    120 {
    121   gdb_assert (buildsym_compunit != nullptr);
    122   return buildsym_compunit->get_file_symbols ();
    123 }
    124 
    125 /* See buildsym.h.  */
    126 
    127 struct pending **
    128 get_global_symbols ()
    129 {
    130   gdb_assert (buildsym_compunit != nullptr);
    131   return buildsym_compunit->get_global_symbols ();
    132 }
    133 
    134 void
    135 start_subfile (const char *name)
    136 {
    137   gdb_assert (buildsym_compunit != nullptr);
    138   buildsym_compunit->start_subfile (name);
    139 }
    140 
    141 void
    142 patch_subfile_names (struct subfile *subfile, const char *name)
    143 {
    144   gdb_assert (buildsym_compunit != nullptr);
    145   buildsym_compunit->patch_subfile_names (subfile, name);
    146 }
    147 
    148 void
    149 push_subfile ()
    150 {
    151   gdb_assert (buildsym_compunit != nullptr);
    152   buildsym_compunit->push_subfile ();
    153 }
    154 
    155 const char *
    156 pop_subfile ()
    157 {
    158   gdb_assert (buildsym_compunit != nullptr);
    159   return buildsym_compunit->pop_subfile ();
    160 }
    161 
    162 /* Delete the buildsym compunit.  */
    163 
    164 static void
    165 free_buildsym_compunit (void)
    166 {
    167   if (buildsym_compunit == NULL)
    168     return;
    169   delete buildsym_compunit;
    170   buildsym_compunit = NULL;
    171 }
    172 
    173 struct compunit_symtab *
    174 end_compunit_symtab (CORE_ADDR end_addr)
    175 {
    176   gdb_assert (buildsym_compunit != nullptr);
    177   struct compunit_symtab *result
    178     = buildsym_compunit->end_compunit_symtab (end_addr);
    179   free_buildsym_compunit ();
    180   return result;
    181 }
    182 
    183 struct context_stack *
    184 push_context (int desc, CORE_ADDR valu)
    185 {
    186   gdb_assert (buildsym_compunit != nullptr);
    187   return buildsym_compunit->push_context (desc, valu);
    188 }
    189 
    190 struct context_stack
    191 pop_context ()
    192 {
    193   gdb_assert (buildsym_compunit != nullptr);
    194   return buildsym_compunit->pop_context ();
    195 }
    196 
    197 struct block *
    198 finish_block (struct symbol *symbol, struct pending_block *old_blocks,
    199 	      const struct dynamic_prop *static_link,
    200 	      CORE_ADDR start, CORE_ADDR end)
    201 {
    202   gdb_assert (buildsym_compunit != nullptr);
    203   return buildsym_compunit->finish_block (symbol, old_blocks, static_link,
    204 					  start, end);
    205 }
    206 
    207 void
    208 record_line (struct subfile *subfile, int line, unrelocated_addr pc)
    209 {
    210   gdb_assert (buildsym_compunit != nullptr);
    211   /* Assume every line entry is a statement start, that is a good place to
    212      put a breakpoint for that line number.  */
    213   buildsym_compunit->record_line (subfile, line, pc, LEF_IS_STMT);
    214 }
    215 
    216 /* Start a new compunit_symtab for a new source file in OBJFILE.  Called, for
    217    example, when a stabs symbol of type N_SO is seen, or when a DWARF
    218    DW_TAG_compile_unit DIE is seen.  It indicates the start of data for one
    219    original source file.
    220 
    221    NAME is the name of the file (cannot be NULL).  COMP_DIR is the
    222    directory in which the file was compiled (or NULL if not known).
    223    START_ADDR is the lowest address of objects in the file (or 0 if
    224    not known).  LANGUAGE is the language of the source file, or
    225    language_unknown if not known, in which case it'll be deduced from
    226    the filename.  */
    227 
    228 struct compunit_symtab *
    229 start_compunit_symtab (struct objfile *objfile, const char *name,
    230 		       const char *comp_dir, CORE_ADDR start_addr,
    231 		       enum language language)
    232 {
    233   /* These should have been reset either by successful completion of building
    234      a symtab, or by the scoped_free_pendings destructor.  */
    235   gdb_assert (buildsym_compunit == nullptr);
    236 
    237   buildsym_compunit = new struct buildsym_compunit (objfile, name, comp_dir,
    238 						    language, start_addr);
    239 
    240   return buildsym_compunit->get_compunit_symtab ();
    241 }
    242 
    243 /* At end of reading syms, or in case of quit, ensure everything
    244    associated with building symtabs is freed.
    245 
    246    N.B. This is *not* intended to be used when building psymtabs.  Some debug
    247    info readers call this anyway, which is harmless if confusing.  */
    248 
    249 scoped_free_pendings::~scoped_free_pendings ()
    250 {
    251   free_buildsym_compunit ();
    252 }
    253 
    254 /* See buildsym-legacy.h.  */
    255 
    256 struct buildsym_compunit *
    257 get_buildsym_compunit ()
    258 {
    259   gdb_assert (buildsym_compunit != nullptr);
    260   return buildsym_compunit;
    261 }
    262