GDB (xrefs)
Loading...
Searching...
No Matches
buildsym.h
Go to the documentation of this file.
1/* Build symbol tables in GDB's internal format.
2 Copyright (C) 1986-2023 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#if !defined (BUILDSYM_H)
20#define BUILDSYM_H 1
21
22#include "gdbsupport/gdb_obstack.h"
23#include "symtab.h"
24#include "addrmap.h"
25
26struct objfile;
27struct symbol;
28struct addrmap;
29struct compunit_symtab;
30enum language;
31
32/* This module provides definitions used for creating and adding to
33 the symbol table. These routines are called from various symbol-
34 file-reading routines.
35
36 They originated in dbxread.c of gdb-4.2, and were split out to
37 make xcoffread.c more maintainable by sharing code. */
38
39struct block;
40struct pending_block;
41
42struct dynamic_prop;
43
44/* The list of sub-source-files within the current individual
45 compilation. Each file gets its own symtab with its own linetable
46 and associated info, but they all share one blockvector. */
47
48struct subfile
49{
50 subfile () = default;
51
52 /* There's nothing wrong with copying a subfile, but we don't need to, so use
53 this to avoid copying one by mistake. */
55
56 struct subfile *next = nullptr;
57 std::string name;
58
59 /* This field is analoguous in function to symtab::filename_for_id.
60
61 It is used to look up existing subfiles in calls to start_subfile. */
62 std::string name_for_id;
63
64 std::vector<linetable_entry> line_vector_entries;
66 struct symtab *symtab = nullptr;
67};
68
69using subfile_up = std::unique_ptr<subfile>;
70
71/* Record the symbols defined for each context in a list. We don't
72 create a struct block for the context until we know how long to
73 make it. */
74
75#define PENDINGSIZE 100
76
77struct pending
78 {
79 struct pending *next;
80 int nsyms;
82 };
83
84/* Stack representing unclosed lexical contexts (that will become
85 blocks, eventually). */
86
88 {
89 /* Outer locals at the time we entered */
90
91 struct pending *locals;
92
93 /* Pending using directives at the time we entered. */
94
96
97 /* Pointer into blocklist as of entry */
98
100
101 /* Name of function, if any, defining context */
102
103 struct symbol *name;
104
105 /* Expression that computes the frame base of the lexically enclosing
106 function, if any. NULL otherwise. */
107
109
110 /* PC where this context starts */
111
112 CORE_ADDR start_addr;
113
114 /* Temp slot for exception handling. */
115
116 CORE_ADDR end_addr;
117
118 /* For error-checking matching push/pop */
119
120 int depth;
121
122 };
123
124/* Flags associated with a linetable entry. */
125
126enum linetable_entry_flag : unsigned
127{
128 /* Indicates this PC is a good location to place a breakpoint at LINE. */
129 LEF_IS_STMT = 1 << 1,
130
131 /* Indicates this PC is a good location to place a breakpoint at the first
132 instruction past a function prologue. */
134};
135DEF_ENUM_FLAGS_TYPE (enum linetable_entry_flag, linetable_entry_flags);
136
137
138/* Buildsym's counterpart to struct compunit_symtab. */
139
141{
142 /* Start recording information about a primary source file (IOW, not an
143 included source file).
144
145 COMP_DIR is the directory in which the compilation unit was compiled
146 (or NULL if not known).
147
148 NAME and NAME_FOR_ID have the same purpose as for the start_subfile
149 method. */
150
151 buildsym_compunit (struct objfile *objfile_, const char *name,
152 const char *comp_dir_, const char *name_for_id,
153 enum language language_, CORE_ADDR last_addr);
154
155 /* Same as above, but passes NAME for NAME_FOR_ID. */
156
157 buildsym_compunit (struct objfile *objfile_, const char *name,
158 const char *comp_dir_, enum language language_,
159 CORE_ADDR last_addr)
160 : buildsym_compunit (objfile_, name, comp_dir_, name, language_, last_addr)
161 {}
162
163 /* Reopen an existing compunit_symtab so that additional symbols can
164 be added to it. Arguments are as for the main constructor. CUST
165 is the expandable compunit_symtab to be reopened. */
166
167 buildsym_compunit (struct objfile *objfile_, const char *name,
168 const char *comp_dir_, enum language language_,
169 CORE_ADDR last_addr, struct compunit_symtab *cust)
170 : m_objfile (objfile_),
171 m_last_source_file (name == nullptr ? nullptr : xstrdup (name)),
172 m_comp_dir (comp_dir_ == nullptr ? "" : comp_dir_),
173 m_compunit_symtab (cust),
174 m_language (language_),
175 m_last_source_start_addr (last_addr)
176 {
177 }
178
180
182
183 void set_last_source_file (const char *name)
184 {
185 char *new_name = name == NULL ? NULL : xstrdup (name);
186 m_last_source_file.reset (new_name);
187 }
188
189 const char *get_last_source_file ()
190 {
191 return m_last_source_file.get ();
192 }
193
194 struct macro_table *get_macro_table ();
195
197 {
198 struct macro_table *result = m_pending_macros;
199 m_pending_macros = nullptr;
200 return result;
201 }
202
203 /* This function is called to discard any pending blocks. */
204
206 {
208 m_pending_blocks = nullptr;
209 }
210
211 struct block *finish_block (struct symbol *symbol,
212 struct pending_block *old_blocks,
213 const struct dynamic_prop *static_link,
214 CORE_ADDR start, CORE_ADDR end);
215
216 void record_block_range (struct block *block,
217 CORE_ADDR start, CORE_ADDR end_inclusive);
218
219 /* Start recording information about source code that comes from a source
220 file. This sets the current subfile, creating it if necessary.
221
222 NAME is the user-visible name of the subfile.
223
224 NAME_FOR_ID is a name that must be stable between the different calls to
225 start_subfile referring to the same file (it is used for looking up
226 existing subfiles). It can be equal to NAME if NAME follows that rule. */
227 void start_subfile (const char *name, const char *name_for_id);
228
229 /* Same as above, but passes NAME for NAME_FOR_ID. */
230
231 void start_subfile (const char *name)
232 {
233 return start_subfile (name, name);
234 }
235
236 void patch_subfile_names (struct subfile *subfile, const char *name);
237
238 void push_subfile ();
239
240 const char *pop_subfile ();
241
242 void record_line (struct subfile *subfile, int line, unrelocated_addr pc,
243 linetable_entry_flags flags);
244
246 {
247 return m_compunit_symtab;
248 }
249
250 void set_last_source_start_addr (CORE_ADDR addr)
251 {
253 }
254
256 {
258 }
259
264
266 {
267 m_local_using_directives = new_local;
268 }
269
274
276 {
277 return m_context_stack.empty ();
278 }
279
281 {
282 if (m_context_stack.empty ())
283 return nullptr;
284 return &m_context_stack.back ();
285 }
286
288 {
289 return m_context_stack.size ();
290 }
291
293 {
294 return m_current_subfile;
295 }
296
298 {
299 return &m_local_symbols;
300 }
301
303 {
304 return &m_file_symbols;
305 }
306
308 {
309 return &m_global_symbols;
310 }
311
312 void record_debugformat (const char *format)
313 {
314 m_debugformat = format;
315 }
316
317 void record_producer (const char *producer)
318 {
319 m_producer = producer;
320 }
321
322 struct context_stack *push_context (int desc, CORE_ADDR valu);
323
324 struct context_stack pop_context ();
325
327 (CORE_ADDR end_addr, int expandable, int required);
328
330 (struct block *static_block, int expandable);
331
332 struct compunit_symtab *end_compunit_symtab (CORE_ADDR end_addr);
333
334 struct compunit_symtab *end_expandable_symtab (CORE_ADDR end_addr);
335
336 void augment_type_symtab ();
337
338private:
339
340 void record_pending_block (struct block *block, struct pending_block *opblock);
341
342 struct block *finish_block_internal (struct symbol *symbol,
343 struct pending **listhead,
344 struct pending_block *old_blocks,
345 const struct dynamic_prop *static_link,
346 CORE_ADDR start, CORE_ADDR end,
347 int is_global, int expandable);
348
349 struct blockvector *make_blockvector ();
350
352
354 (struct block *static_block, int expandable);
355
356 /* The objfile we're reading debug info from. */
358
359 /* List of subfiles (source files).
360 Files are added to the front of the list.
361 This is important mostly for the language determination hacks we use,
362 which iterate over previously added files. */
363 struct subfile *m_subfiles = nullptr;
364
365 /* The subfile of the main source file. */
366 struct subfile *m_main_subfile = nullptr;
367
368 /* Name of source file whose symbol data we are now processing. This
369 comes from a symbol of type N_SO for stabs. For DWARF it comes
370 from the DW_AT_name attribute of a DW_TAG_compile_unit DIE. */
371 gdb::unique_xmalloc_ptr<char> m_last_source_file;
372
373 /* E.g., DW_AT_comp_dir if DWARF. Space for this is malloc'd. */
374 std::string m_comp_dir;
375
376 /* Space for this is not malloc'd, and is assumed to have at least
377 the same lifetime as objfile. */
378 const char *m_producer = nullptr;
379
380 /* Space for this is not malloc'd, and is assumed to have at least
381 the same lifetime as objfile. */
382 const char *m_debugformat = nullptr;
383
384 /* The compunit we are building. */
386
387 /* Language of this compunit_symtab. */
389
390 /* The macro table for the compilation unit whose symbols we're
391 currently reading. */
392 struct macro_table *m_pending_macros = nullptr;
393
394 /* True if symtab has line number info. This prevents an otherwise
395 empty symtab from being tossed. */
397
398 /* Core address of start of text of current source file. This too
399 comes from the N_SO symbol. For Dwarf it typically comes from the
400 DW_AT_low_pc attribute of a DW_TAG_compile_unit DIE. */
402
403 /* Stack of subfile names. */
404 std::vector<const char *> m_subfile_stack;
405
406 /* The "using" directives local to lexical context. */
408
409 /* Global "using" directives. */
411
412 /* The stack of contexts that are pushed by push_context and popped
413 by pop_context. */
414 std::vector<struct context_stack> m_context_stack;
415
416 struct subfile *m_current_subfile = nullptr;
417
418 /* The mutable address map for the compilation unit whose symbols
419 we're currently reading. The symtabs' shared blockvector will
420 point to a fixed copy of this. */
422
423 /* True if we recorded any ranges in the addrmap that are different
424 from those in the blockvector already. We set this to false when
425 we start processing a symfile, and if it's still false at the
426 end, then we just toss the addrmap. */
428
429 /* An obstack used for allocating pending blocks. */
431
432 /* Pointer to the head of a linked list of symbol blocks which have
433 already been finalized (lexical contexts already closed) and which
434 are just waiting to be built into a blockvector when finalizing the
435 associated symtab. */
437
438 /* Pending static symbols and types at the top level. */
439 struct pending *m_file_symbols = nullptr;
440
441 /* Pending global functions and variables. */
442 struct pending *m_global_symbols = nullptr;
443
444 /* Pending symbols that are local to the lexical context. */
445 struct pending *m_local_symbols = nullptr;
446};
447
448
449
450extern void add_symbol_to_list (struct symbol *symbol,
451 struct pending **listhead);
452
453extern struct symbol *find_symbol_in_list (struct pending *list,
454 char *name, int length);
455
456#endif /* defined (BUILDSYM_H) */
const char *const name
static struct buildsym_compunit * buildsym_compunit
linetable_entry_flag
Definition buildsym.h:127
@ LEF_IS_STMT
Definition buildsym.h:129
@ LEF_PROLOGUE_END
Definition buildsym.h:133
DEF_ENUM_FLAGS_TYPE(enum linetable_entry_flag, linetable_entry_flags)
struct symbol * find_symbol_in_list(struct pending *list, char *name, int length)
Definition buildsym.c:150
#define PENDINGSIZE
Definition buildsym.h:75
std::unique_ptr< subfile > subfile_up
Definition buildsym.h:69
void add_symbol_to_list(struct symbol *symbol, struct pending **listhead)
Definition buildsym.c:125
language
Definition defs.h:211
@ language_unknown
Definition defs.h:212
mach_port_t kern_return_t mach_port_t mach_msg_type_name_t msgportsPoly mach_port_t kern_return_t pid_t pid mach_port_t kern_return_t mach_port_t task mach_port_t kern_return_t int flags
Definition gnu-nat.c:1861
Definition block.h:109
struct objfile * m_objfile
Definition buildsym.h:357
void push_subfile()
Definition buildsym.c:606
DISABLE_COPY_AND_ASSIGN(buildsym_compunit)
struct compunit_symtab * get_compunit_symtab()
Definition buildsym.h:245
struct macro_table * get_macro_table()
Definition buildsym.c:111
gdb::unique_xmalloc_ptr< char > m_last_source_file
Definition buildsym.h:371
CORE_ADDR get_last_source_start_addr()
Definition buildsym.h:255
struct macro_table * release_macros()
Definition buildsym.h:196
struct pending ** get_local_symbols()
Definition buildsym.h:297
void set_local_using_directives(struct using_direct *new_local)
Definition buildsym.h:265
std::vector< struct context_stack > m_context_stack
Definition buildsym.h:414
struct using_direct ** get_local_using_directives()
Definition buildsym.h:260
CORE_ADDR m_last_source_start_addr
Definition buildsym.h:401
void start_subfile(const char *name, const char *name_for_id)
Definition buildsym.c:487
struct pending * m_local_symbols
Definition buildsym.h:445
struct context_stack * get_current_context_stack()
Definition buildsym.h:280
const char * m_debugformat
Definition buildsym.h:382
bool m_have_line_numbers
Definition buildsym.h:396
struct compunit_symtab * end_compunit_symtab_from_static_block(struct block *static_block, int expandable)
Definition buildsym.c:1003
void record_pending_block(struct block *block, struct pending_block *opblock)
Definition buildsym.c:176
struct pending * m_file_symbols
Definition buildsym.h:439
const char * get_last_source_file()
Definition buildsym.h:189
std::string m_comp_dir
Definition buildsym.h:374
struct using_direct * m_local_using_directives
Definition buildsym.h:407
void watch_main_source_file_lossage()
Definition buildsym.c:684
struct block * finish_block(struct symbol *symbol, struct pending_block *old_blocks, const struct dynamic_prop *static_link, CORE_ADDR start, CORE_ADDR end)
Definition buildsym.c:386
struct pending * m_global_symbols
Definition buildsym.h:442
struct subfile * m_subfiles
Definition buildsym.h:363
struct blockvector * make_blockvector()
Definition buildsym.c:421
buildsym_compunit(struct objfile *objfile_, const char *name, const char *comp_dir_, enum language language_, CORE_ADDR last_addr, struct compunit_symtab *cust)
Definition buildsym.h:167
auto_obstack m_pending_block_obstack
Definition buildsym.h:430
void record_line(struct subfile *subfile, int line, unrelocated_addr pc, linetable_entry_flags flags)
Definition buildsym.c:626
struct using_direct * m_global_using_directives
Definition buildsym.h:410
struct block * finish_block_internal(struct symbol *symbol, struct pending **listhead, struct pending_block *old_blocks, const struct dynamic_prop *static_link, CORE_ADDR start, CORE_ADDR end, int is_global, int expandable)
Definition buildsym.c:201
buildsym_compunit(struct objfile *objfile_, const char *name, const char *comp_dir_, enum language language_, CORE_ADDR last_addr)
Definition buildsym.h:157
void record_producer(const char *producer)
Definition buildsym.h:317
struct compunit_symtab * end_expandable_symtab(CORE_ADDR end_addr)
Definition buildsym.c:1058
void set_last_source_file(const char *name)
Definition buildsym.h:183
bool outermost_context_p() const
Definition buildsym.h:275
struct compunit_symtab * m_compunit_symtab
Definition buildsym.h:385
struct block * end_compunit_symtab_get_static_block(CORE_ADDR end_addr, int expandable, int required)
Definition buildsym.c:760
struct compunit_symtab * end_compunit_symtab_with_blockvector(struct block *static_block, int expandable)
Definition buildsym.c:852
void set_last_source_start_addr(CORE_ADDR addr)
Definition buildsym.h:250
struct addrmap_mutable m_pending_addrmap
Definition buildsym.h:421
void augment_type_symtab()
Definition buildsym.c:1092
struct pending ** get_file_symbols()
Definition buildsym.h:302
bool m_pending_addrmap_interesting
Definition buildsym.h:427
void start_subfile(const char *name)
Definition buildsym.h:231
std::vector< const char * > m_subfile_stack
Definition buildsym.h:404
struct subfile * m_current_subfile
Definition buildsym.h:416
const char * m_producer
Definition buildsym.h:378
void free_pending_blocks()
Definition buildsym.h:205
void record_debugformat(const char *format)
Definition buildsym.h:312
struct pending_block * m_pending_blocks
Definition buildsym.h:436
enum language m_language
Definition buildsym.h:388
int get_context_stack_depth() const
Definition buildsym.h:287
struct subfile * m_main_subfile
Definition buildsym.h:366
struct context_stack pop_context()
Definition buildsym.c:1156
struct pending ** get_global_symbols()
Definition buildsym.h:307
struct subfile * get_current_subfile()
Definition buildsym.h:292
void patch_subfile_names(struct subfile *subfile, const char *name)
Definition buildsym.c:566
const char * pop_subfile()
Definition buildsym.c:614
void record_block_range(struct block *block, CORE_ADDR start, CORE_ADDR end_inclusive)
Definition buildsym.c:404
struct compunit_symtab * end_compunit_symtab(CORE_ADDR end_addr)
Definition buildsym.c:1046
struct macro_table * m_pending_macros
Definition buildsym.h:392
struct context_stack * push_context(int desc, CORE_ADDR valu)
Definition buildsym.c:1134
struct using_direct ** get_global_using_directives()
Definition buildsym.h:270
struct dynamic_prop * static_link
Definition buildsym.h:108
CORE_ADDR end_addr
Definition buildsym.h:116
struct pending * locals
Definition buildsym.h:91
struct using_direct * local_using_directives
Definition buildsym.h:95
struct pending_block * old_blocks
Definition buildsym.h:99
CORE_ADDR start_addr
Definition buildsym.h:112
struct symbol * name
Definition buildsym.h:103
int nsyms
Definition buildsym.h:80
struct pending * next
Definition buildsym.h:79
std::string name
Definition buildsym.h:57
DISABLE_COPY_AND_ASSIGN(subfile)
std::vector< linetable_entry > line_vector_entries
Definition buildsym.h:64
subfile()=default
std::string name_for_id
Definition buildsym.h:62
#define nullptr
Definition x86-cpuid.h:28