GDB (xrefs)
Loading...
Searching...
No Matches
/tmp/gdb-13.1/gdb/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, CORE_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
261 {
263 }
264
266 {
267 m_local_using_directives = new_local;
268 }
269
271 {
273 }
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 section, int expandable);
331
332 struct compunit_symtab *end_compunit_symtab (CORE_ADDR end_addr, int section);
333
334 struct compunit_symtab *end_expandable_symtab (CORE_ADDR end_addr,
335 int section);
336
337 void augment_type_symtab ();
338
339private:
340
341 void record_pending_block (struct block *block, struct pending_block *opblock);
342
343 struct block *finish_block_internal (struct symbol *symbol,
344 struct pending **listhead,
345 struct pending_block *old_blocks,
346 const struct dynamic_prop *static_link,
347 CORE_ADDR start, CORE_ADDR end,
348 int is_global, int expandable);
349
350 struct blockvector *make_blockvector ();
351
353
355 (struct block *static_block, int section, int expandable);
356
357 /* The objfile we're reading debug info from. */
359
360 /* List of subfiles (source files).
361 Files are added to the front of the list.
362 This is important mostly for the language determination hacks we use,
363 which iterate over previously added files. */
364 struct subfile *m_subfiles = nullptr;
365
366 /* The subfile of the main source file. */
367 struct subfile *m_main_subfile = nullptr;
368
369 /* Name of source file whose symbol data we are now processing. This
370 comes from a symbol of type N_SO for stabs. For DWARF it comes
371 from the DW_AT_name attribute of a DW_TAG_compile_unit DIE. */
372 gdb::unique_xmalloc_ptr<char> m_last_source_file;
373
374 /* E.g., DW_AT_comp_dir if DWARF. Space for this is malloc'd. */
375 std::string m_comp_dir;
376
377 /* Space for this is not malloc'd, and is assumed to have at least
378 the same lifetime as objfile. */
379 const char *m_producer = nullptr;
380
381 /* Space for this is not malloc'd, and is assumed to have at least
382 the same lifetime as objfile. */
383 const char *m_debugformat = nullptr;
384
385 /* The compunit we are building. */
387
388 /* Language of this compunit_symtab. */
390
391 /* The macro table for the compilation unit whose symbols we're
392 currently reading. */
393 struct macro_table *m_pending_macros = nullptr;
394
395 /* True if symtab has line number info. This prevents an otherwise
396 empty symtab from being tossed. */
398
399 /* Core address of start of text of current source file. This too
400 comes from the N_SO symbol. For Dwarf it typically comes from the
401 DW_AT_low_pc attribute of a DW_TAG_compile_unit DIE. */
403
404 /* Stack of subfile names. */
405 std::vector<const char *> m_subfile_stack;
406
407 /* The "using" directives local to lexical context. */
409
410 /* Global "using" directives. */
412
413 /* The stack of contexts that are pushed by push_context and popped
414 by pop_context. */
415 std::vector<struct context_stack> m_context_stack;
416
417 struct subfile *m_current_subfile = nullptr;
418
419 /* The mutable address map for the compilation unit whose symbols
420 we're currently reading. The symtabs' shared blockvector will
421 point to a fixed copy of this. */
423
424 /* True if we recorded any ranges in the addrmap that are different
425 from those in the blockvector already. We set this to false when
426 we start processing a symfile, and if it's still false at the
427 end, then we just toss the addrmap. */
429
430 /* An obstack used for allocating pending blocks. */
432
433 /* Pointer to the head of a linked list of symbol blocks which have
434 already been finalized (lexical contexts already closed) and which
435 are just waiting to be built into a blockvector when finalizing the
436 associated symtab. */
438
439 /* Pending static symbols and types at the top level. */
440 struct pending *m_file_symbols = nullptr;
441
442 /* Pending global functions and variables. */
443 struct pending *m_global_symbols = nullptr;
444
445 /* Pending symbols that are local to the lexical context. */
446 struct pending *m_local_symbols = nullptr;
447};
448
449
450
451extern void add_symbol_to_list (struct symbol *symbol,
452 struct pending **listhead);
453
454extern struct symbol *find_symbol_in_list (struct pending *list,
455 char *name, int length);
456
457#endif /* defined (BUILDSYM_H) */
const char *const name
Definition: aarch64-tdep.c:67
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:1862
Definition: block.h:109
struct objfile * m_objfile
Definition: buildsym.h:358
void push_subfile()
Definition: buildsym.c:610
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:372
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:415
struct using_direct ** get_local_using_directives()
Definition: buildsym.h:260
CORE_ADDR m_last_source_start_addr
Definition: buildsym.h:402
void start_subfile(const char *name, const char *name_for_id)
Definition: buildsym.c:491
struct pending * m_local_symbols
Definition: buildsym.h:446
struct context_stack * get_current_context_stack()
Definition: buildsym.h:280
const char * m_debugformat
Definition: buildsym.h:383
bool m_have_line_numbers
Definition: buildsym.h:397
void record_pending_block(struct block *block, struct pending_block *opblock)
Definition: buildsym.c:176
struct pending * m_file_symbols
Definition: buildsym.h:440
const char * get_last_source_file()
Definition: buildsym.h:189
std::string m_comp_dir
Definition: buildsym.h:375
struct using_direct * m_local_using_directives
Definition: buildsym.h:408
void watch_main_source_file_lossage()
Definition: buildsym.c:688
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:390
struct pending * m_global_symbols
Definition: buildsym.h:443
struct subfile * m_subfiles
Definition: buildsym.h:364
struct blockvector * make_blockvector()
Definition: buildsym.c:425
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
struct compunit_symtab * end_compunit_symtab_with_blockvector(struct block *static_block, int section, int expandable)
Definition: buildsym.c:857
auto_obstack m_pending_block_obstack
Definition: buildsym.h:431
struct using_direct * m_global_using_directives
Definition: buildsym.h:411
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
void set_last_source_file(const char *name)
Definition: buildsym.h:183
bool outermost_context_p() const
Definition: buildsym.h:275
struct compunit_symtab * end_compunit_symtab_from_static_block(struct block *static_block, int section, int expandable)
Definition: buildsym.c:1025
struct compunit_symtab * m_compunit_symtab
Definition: buildsym.h:386
struct compunit_symtab * end_compunit_symtab(CORE_ADDR end_addr, int section)
Definition: buildsym.c:1070
struct block * end_compunit_symtab_get_static_block(CORE_ADDR end_addr, int expandable, int required)
Definition: buildsym.c:764
void set_last_source_start_addr(CORE_ADDR addr)
Definition: buildsym.h:250
struct addrmap_mutable m_pending_addrmap
Definition: buildsym.h:422
void augment_type_symtab()
Definition: buildsym.c:1116
struct pending ** get_file_symbols()
Definition: buildsym.h:302
bool m_pending_addrmap_interesting
Definition: buildsym.h:428
void record_line(struct subfile *subfile, int line, CORE_ADDR pc, linetable_entry_flags flags)
Definition: buildsym.c:630
void start_subfile(const char *name)
Definition: buildsym.h:231
std::vector< const char * > m_subfile_stack
Definition: buildsym.h:405
struct subfile * m_current_subfile
Definition: buildsym.h:417
const char * m_producer
Definition: buildsym.h:379
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:437
enum language m_language
Definition: buildsym.h:389
int get_context_stack_depth() const
Definition: buildsym.h:287
struct subfile * m_main_subfile
Definition: buildsym.h:367
struct context_stack pop_context()
Definition: buildsym.c:1180
struct pending ** get_global_symbols()
Definition: buildsym.h:307
struct subfile * get_current_subfile()
Definition: buildsym.h:292
struct compunit_symtab * end_expandable_symtab(CORE_ADDR end_addr, int section)
Definition: buildsym.c:1082
void patch_subfile_names(struct subfile *subfile, const char *name)
Definition: buildsym.c:570
const char * pop_subfile()
Definition: buildsym.c:618
void record_block_range(struct block *block, CORE_ADDR start, CORE_ADDR end_inclusive)
Definition: buildsym.c:408
struct macro_table * m_pending_macros
Definition: buildsym.h:393
struct context_stack * push_context(int desc, CORE_ADDR valu)
Definition: buildsym.c:1158
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
struct subfile * next
Definition: buildsym.h:56