| 1 | /* Legacy support routines for building symbol tables in GDB's internal format. |
| 2 | Copyright (C) 1986-2019 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 "defs.h" |
| 20 | #include "buildsym-legacy.h" |
| 21 | |
| 22 | /* The work-in-progress of the compunit we are building. |
| 23 | This is created first, before any subfiles by start_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 | \f |
| 40 | |
| 41 | /* See buildsym.h. */ |
| 42 | |
| 43 | void |
| 44 | set_last_source_file (const char *name) |
| 45 | { |
| 46 | gdb_assert (buildsym_compunit != nullptr || name == nullptr); |
| 47 | if (buildsym_compunit != nullptr) |
| 48 | buildsym_compunit->set_last_source_file (name); |
| 49 | } |
| 50 | |
| 51 | /* See buildsym.h. */ |
| 52 | |
| 53 | const char * |
| 54 | get_last_source_file () |
| 55 | { |
| 56 | if (buildsym_compunit == nullptr) |
| 57 | return nullptr; |
| 58 | return buildsym_compunit->get_last_source_file (); |
| 59 | } |
| 60 | |
| 61 | /* See buildsym.h. */ |
| 62 | |
| 63 | void |
| 64 | set_last_source_start_addr (CORE_ADDR addr) |
| 65 | { |
| 66 | gdb_assert (buildsym_compunit != nullptr); |
| 67 | buildsym_compunit->set_last_source_start_addr (addr); |
| 68 | } |
| 69 | |
| 70 | /* See buildsym.h. */ |
| 71 | |
| 72 | CORE_ADDR |
| 73 | get_last_source_start_addr () |
| 74 | { |
| 75 | gdb_assert (buildsym_compunit != nullptr); |
| 76 | return buildsym_compunit->get_last_source_start_addr (); |
| 77 | } |
| 78 | |
| 79 | /* See buildsym.h. */ |
| 80 | |
| 81 | struct using_direct ** |
| 82 | get_local_using_directives () |
| 83 | { |
| 84 | gdb_assert (buildsym_compunit != nullptr); |
| 85 | return buildsym_compunit->get_local_using_directives (); |
| 86 | } |
| 87 | |
| 88 | /* See buildsym.h. */ |
| 89 | |
| 90 | void |
| 91 | set_local_using_directives (struct using_direct *new_local) |
| 92 | { |
| 93 | gdb_assert (buildsym_compunit != nullptr); |
| 94 | buildsym_compunit->set_local_using_directives (new_local); |
| 95 | } |
| 96 | |
| 97 | /* See buildsym.h. */ |
| 98 | |
| 99 | struct using_direct ** |
| 100 | get_global_using_directives () |
| 101 | { |
| 102 | gdb_assert (buildsym_compunit != nullptr); |
| 103 | return buildsym_compunit->get_global_using_directives (); |
| 104 | } |
| 105 | |
| 106 | /* See buildsym.h. */ |
| 107 | |
| 108 | bool |
| 109 | outermost_context_p () |
| 110 | { |
| 111 | gdb_assert (buildsym_compunit != nullptr); |
| 112 | return buildsym_compunit->outermost_context_p (); |
| 113 | } |
| 114 | |
| 115 | /* See buildsym.h. */ |
| 116 | |
| 117 | struct context_stack * |
| 118 | get_current_context_stack () |
| 119 | { |
| 120 | gdb_assert (buildsym_compunit != nullptr); |
| 121 | return buildsym_compunit->get_current_context_stack (); |
| 122 | } |
| 123 | |
| 124 | /* See buildsym.h. */ |
| 125 | |
| 126 | int |
| 127 | get_context_stack_depth () |
| 128 | { |
| 129 | gdb_assert (buildsym_compunit != nullptr); |
| 130 | return buildsym_compunit->get_context_stack_depth (); |
| 131 | } |
| 132 | |
| 133 | /* See buildsym.h. */ |
| 134 | |
| 135 | struct subfile * |
| 136 | get_current_subfile () |
| 137 | { |
| 138 | gdb_assert (buildsym_compunit != nullptr); |
| 139 | return buildsym_compunit->get_current_subfile (); |
| 140 | } |
| 141 | |
| 142 | /* See buildsym.h. */ |
| 143 | |
| 144 | struct pending ** |
| 145 | get_local_symbols () |
| 146 | { |
| 147 | gdb_assert (buildsym_compunit != nullptr); |
| 148 | return buildsym_compunit->get_local_symbols (); |
| 149 | } |
| 150 | |
| 151 | /* See buildsym.h. */ |
| 152 | |
| 153 | struct pending ** |
| 154 | get_file_symbols () |
| 155 | { |
| 156 | gdb_assert (buildsym_compunit != nullptr); |
| 157 | return buildsym_compunit->get_file_symbols (); |
| 158 | } |
| 159 | |
| 160 | /* See buildsym.h. */ |
| 161 | |
| 162 | struct pending ** |
| 163 | get_global_symbols () |
| 164 | { |
| 165 | gdb_assert (buildsym_compunit != nullptr); |
| 166 | return buildsym_compunit->get_global_symbols (); |
| 167 | } |
| 168 | |
| 169 | void |
| 170 | start_subfile (const char *name) |
| 171 | { |
| 172 | gdb_assert (buildsym_compunit != nullptr); |
| 173 | buildsym_compunit->start_subfile (name); |
| 174 | } |
| 175 | |
| 176 | void |
| 177 | patch_subfile_names (struct subfile *subfile, const char *name) |
| 178 | { |
| 179 | gdb_assert (buildsym_compunit != nullptr); |
| 180 | buildsym_compunit->patch_subfile_names (subfile, name); |
| 181 | } |
| 182 | |
| 183 | void |
| 184 | push_subfile () |
| 185 | { |
| 186 | gdb_assert (buildsym_compunit != nullptr); |
| 187 | buildsym_compunit->push_subfile (); |
| 188 | } |
| 189 | |
| 190 | const char * |
| 191 | pop_subfile () |
| 192 | { |
| 193 | gdb_assert (buildsym_compunit != nullptr); |
| 194 | return buildsym_compunit->pop_subfile (); |
| 195 | } |
| 196 | |
| 197 | /* Delete the buildsym compunit. */ |
| 198 | |
| 199 | static void |
| 200 | free_buildsym_compunit (void) |
| 201 | { |
| 202 | if (buildsym_compunit == NULL) |
| 203 | return; |
| 204 | delete buildsym_compunit; |
| 205 | buildsym_compunit = NULL; |
| 206 | } |
| 207 | |
| 208 | struct compunit_symtab * |
| 209 | end_symtab (CORE_ADDR end_addr, int section) |
| 210 | { |
| 211 | gdb_assert (buildsym_compunit != nullptr); |
| 212 | struct compunit_symtab *result |
| 213 | = buildsym_compunit->end_symtab (end_addr, section); |
| 214 | free_buildsym_compunit (); |
| 215 | return result; |
| 216 | } |
| 217 | |
| 218 | struct context_stack * |
| 219 | push_context (int desc, CORE_ADDR valu) |
| 220 | { |
| 221 | gdb_assert (buildsym_compunit != nullptr); |
| 222 | return buildsym_compunit->push_context (desc, valu); |
| 223 | } |
| 224 | |
| 225 | struct context_stack |
| 226 | pop_context () |
| 227 | { |
| 228 | gdb_assert (buildsym_compunit != nullptr); |
| 229 | return buildsym_compunit->pop_context (); |
| 230 | } |
| 231 | |
| 232 | struct block * |
| 233 | finish_block (struct symbol *symbol, struct pending_block *old_blocks, |
| 234 | const struct dynamic_prop *static_link, |
| 235 | CORE_ADDR start, CORE_ADDR end) |
| 236 | { |
| 237 | gdb_assert (buildsym_compunit != nullptr); |
| 238 | return buildsym_compunit->finish_block (symbol, old_blocks, static_link, |
| 239 | start, end); |
| 240 | } |
| 241 | |
| 242 | void |
| 243 | record_block_range (struct block *block, CORE_ADDR start, |
| 244 | CORE_ADDR end_inclusive) |
| 245 | { |
| 246 | gdb_assert (buildsym_compunit != nullptr); |
| 247 | buildsym_compunit->record_block_range (block, start, end_inclusive); |
| 248 | } |
| 249 | |
| 250 | void |
| 251 | record_line (struct subfile *subfile, int line, CORE_ADDR pc) |
| 252 | { |
| 253 | gdb_assert (buildsym_compunit != nullptr); |
| 254 | buildsym_compunit->record_line (subfile, line, pc); |
| 255 | } |
| 256 | |
| 257 | /* Start a new symtab for a new source file in OBJFILE. Called, for example, |
| 258 | when a stabs symbol of type N_SO is seen, or when a DWARF |
| 259 | TAG_compile_unit DIE is seen. It indicates the start of data for |
| 260 | one original source file. |
| 261 | |
| 262 | NAME is the name of the file (cannot be NULL). COMP_DIR is the |
| 263 | directory in which the file was compiled (or NULL if not known). |
| 264 | START_ADDR is the lowest address of objects in the file (or 0 if |
| 265 | not known). LANGUAGE is the language of the source file, or |
| 266 | language_unknown if not known, in which case it'll be deduced from |
| 267 | the filename. */ |
| 268 | |
| 269 | struct compunit_symtab * |
| 270 | start_symtab (struct objfile *objfile, const char *name, const char *comp_dir, |
| 271 | CORE_ADDR start_addr, enum language language) |
| 272 | { |
| 273 | /* These should have been reset either by successful completion of building |
| 274 | a symtab, or by the scoped_free_pendings destructor. */ |
| 275 | gdb_assert (buildsym_compunit == nullptr); |
| 276 | |
| 277 | buildsym_compunit = new struct buildsym_compunit (objfile, name, comp_dir, |
| 278 | language, start_addr); |
| 279 | |
| 280 | return buildsym_compunit->get_compunit_symtab (); |
| 281 | } |
| 282 | |
| 283 | /* Restart compilation for a symtab. |
| 284 | CUST is the result of end_expandable_symtab. |
| 285 | NAME, START_ADDR are the source file we are resuming with. |
| 286 | |
| 287 | This is used when a symtab is built from multiple sources. |
| 288 | The symtab is first built with start_symtab/end_expandable_symtab |
| 289 | and then for each additional piece call restart_symtab/augment_*_symtab. |
| 290 | Note: At the moment there is only augment_type_symtab. */ |
| 291 | |
| 292 | void |
| 293 | restart_symtab (struct compunit_symtab *cust, |
| 294 | const char *name, CORE_ADDR start_addr) |
| 295 | { |
| 296 | /* These should have been reset either by successful completion of building |
| 297 | a symtab, or by the scoped_free_pendings destructor. */ |
| 298 | gdb_assert (buildsym_compunit == nullptr); |
| 299 | |
| 300 | buildsym_compunit |
| 301 | = new struct buildsym_compunit (COMPUNIT_OBJFILE (cust), |
| 302 | name, |
| 303 | COMPUNIT_DIRNAME (cust), |
| 304 | compunit_language (cust), |
| 305 | start_addr, |
| 306 | cust); |
| 307 | } |
| 308 | |
| 309 | /* See buildsym.h. */ |
| 310 | |
| 311 | struct compunit_symtab * |
| 312 | buildsym_compunit_symtab (void) |
| 313 | { |
| 314 | gdb_assert (buildsym_compunit != NULL); |
| 315 | |
| 316 | return buildsym_compunit->get_compunit_symtab (); |
| 317 | } |
| 318 | |
| 319 | /* See buildsym.h. */ |
| 320 | |
| 321 | struct macro_table * |
| 322 | get_macro_table (void) |
| 323 | { |
| 324 | gdb_assert (buildsym_compunit != NULL); |
| 325 | return buildsym_compunit->get_macro_table (); |
| 326 | } |
| 327 | |
| 328 | /* At end of reading syms, or in case of quit, ensure everything |
| 329 | associated with building symtabs is freed. |
| 330 | |
| 331 | N.B. This is *not* intended to be used when building psymtabs. Some debug |
| 332 | info readers call this anyway, which is harmless if confusing. */ |
| 333 | |
| 334 | scoped_free_pendings::~scoped_free_pendings () |
| 335 | { |
| 336 | free_buildsym_compunit (); |
| 337 | } |
| 338 | |
| 339 | /* See buildsym-legacy.h. */ |
| 340 | |
| 341 | struct buildsym_compunit * |
| 342 | get_buildsym_compunit () |
| 343 | { |
| 344 | gdb_assert (buildsym_compunit != nullptr); |
| 345 | return buildsym_compunit; |
| 346 | } |