2012-02-01 Gary Benson <gbenson@redhat.com>
[platform/upstream/binutils.git] / gdb / symtab.h
1 /* Symbol table definitions for GDB.
2
3    Copyright (C) 1986, 1988-2004, 2007-2012 Free Software Foundation,
4    Inc.
5
6    This file is part of GDB.
7
8    This program is free software; you can redistribute it and/or modify
9    it under the terms of the GNU General Public License as published by
10    the Free Software Foundation; either version 3 of the License, or
11    (at your option) any later version.
12
13    This program is distributed in the hope that it will be useful,
14    but WITHOUT ANY WARRANTY; without even the implied warranty of
15    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16    GNU General Public License for more details.
17
18    You should have received a copy of the GNU General Public License
19    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
20
21 #if !defined (SYMTAB_H)
22 #define SYMTAB_H 1
23
24 #include "vec.h"
25
26 /* Opaque declarations.  */
27 struct ui_file;
28 struct frame_info;
29 struct symbol;
30 struct obstack;
31 struct objfile;
32 struct block;
33 struct blockvector;
34 struct axs_value;
35 struct agent_expr;
36 struct program_space;
37 struct language_defn;
38
39 /* Some of the structures in this file are space critical.
40    The space-critical structures are:
41
42      struct general_symbol_info
43      struct symbol
44      struct partial_symbol
45
46    These structures are laid out to encourage good packing.
47    They use ENUM_BITFIELD and short int fields, and they order the
48    structure members so that fields less than a word are next
49    to each other so they can be packed together.  */
50
51 /* Rearranged: used ENUM_BITFIELD and rearranged field order in
52    all the space critical structures (plus struct minimal_symbol).
53    Memory usage dropped from 99360768 bytes to 90001408 bytes.
54    I measured this with before-and-after tests of
55    "HEAD-old-gdb -readnow HEAD-old-gdb" and
56    "HEAD-new-gdb -readnow HEAD-old-gdb" on native i686-pc-linux-gnu,
57    red hat linux 8, with LD_LIBRARY_PATH=/usr/lib/debug,
58    typing "maint space 1" at the first command prompt.
59
60    Here is another measurement (from andrew c):
61      # no /usr/lib/debug, just plain glibc, like a normal user
62      gdb HEAD-old-gdb
63      (gdb) break internal_error
64      (gdb) run
65      (gdb) maint internal-error
66      (gdb) backtrace
67      (gdb) maint space 1
68
69    gdb gdb_6_0_branch  2003-08-19  space used: 8896512
70    gdb HEAD            2003-08-19  space used: 8904704
71    gdb HEAD            2003-08-21  space used: 8396800 (+symtab.h)
72    gdb HEAD            2003-08-21  space used: 8265728 (+gdbtypes.h)
73
74    The third line shows the savings from the optimizations in symtab.h.
75    The fourth line shows the savings from the optimizations in
76    gdbtypes.h.  Both optimizations are in gdb HEAD now.
77
78    --chastain 2003-08-21  */
79
80 /* Struct for storing C++ specific information.  Allocated when needed.  */
81
82 struct cplus_specific
83 {
84   char *demangled_name;
85 };
86
87 /* Define a structure for the information that is common to all symbol types,
88    including minimal symbols, partial symbols, and full symbols.  In a
89    multilanguage environment, some language specific information may need to
90    be recorded along with each symbol.  */
91
92 /* This structure is space critical.  See space comments at the top.  */
93
94 struct general_symbol_info
95 {
96   /* Name of the symbol.  This is a required field.  Storage for the
97      name is allocated on the objfile_obstack for the associated
98      objfile.  For languages like C++ that make a distinction between
99      the mangled name and demangled name, this is the mangled
100      name.  */
101
102   char *name;
103
104   /* Value of the symbol.  Which member of this union to use, and what
105      it means, depends on what kind of symbol this is and its
106      SYMBOL_CLASS.  See comments there for more details.  All of these
107      are in host byte order (though what they point to might be in
108      target byte order, e.g. LOC_CONST_BYTES).  */
109
110   union
111   {
112     /* The fact that this is a long not a LONGEST mainly limits the
113        range of a LOC_CONST.  Since LOC_CONST_BYTES exists, I'm not
114        sure that is a big deal.  */
115     long ivalue;
116
117     struct block *block;
118
119     gdb_byte *bytes;
120
121     CORE_ADDR address;
122
123     /* For opaque typedef struct chain.  */
124
125     struct symbol *chain;
126   }
127   value;
128
129   /* Since one and only one language can apply, wrap the language specific
130      information inside a union.  */
131
132   union
133   {
134     /* This is used by languages which wish to store a demangled name.
135        currently used by Ada, Java, and Objective C.  */
136     struct mangled_lang
137     {
138       char *demangled_name;
139     }
140     mangled_lang;
141
142     struct cplus_specific *cplus_specific;
143   }
144   language_specific;
145
146   /* Record the source code language that applies to this symbol.
147      This is used to select one of the fields from the language specific
148      union above.  */
149
150   ENUM_BITFIELD(language) language : 8;
151
152   /* Which section is this symbol in?  This is an index into
153      section_offsets for this objfile.  Negative means that the symbol
154      does not get relocated relative to a section.
155      Disclaimer: currently this is just used for xcoff, so don't
156      expect all symbol-reading code to set it correctly (the ELF code
157      also tries to set it correctly).  */
158
159   short section;
160
161   /* The section associated with this symbol.  It can be NULL.  */
162
163   struct obj_section *obj_section;
164 };
165
166 extern void symbol_set_demangled_name (struct general_symbol_info *, char *,
167                                        struct objfile *);
168
169 extern char *symbol_get_demangled_name (const struct general_symbol_info *);
170
171 extern CORE_ADDR symbol_overlayed_address (CORE_ADDR, struct obj_section *);
172
173 /* Note that all the following SYMBOL_* macros are used with the
174    SYMBOL argument being either a partial symbol, a minimal symbol or
175    a full symbol.  All three types have a ginfo field.  In particular
176    the SYMBOL_SET_LANGUAGE, SYMBOL_DEMANGLED_NAME, etc.
177    macros cannot be entirely substituted by
178    functions, unless the callers are changed to pass in the ginfo
179    field only, instead of the SYMBOL parameter.  */
180
181 #define SYMBOL_VALUE(symbol)            (symbol)->ginfo.value.ivalue
182 #define SYMBOL_VALUE_ADDRESS(symbol)    (symbol)->ginfo.value.address
183 #define SYMBOL_VALUE_BYTES(symbol)      (symbol)->ginfo.value.bytes
184 #define SYMBOL_BLOCK_VALUE(symbol)      (symbol)->ginfo.value.block
185 #define SYMBOL_VALUE_CHAIN(symbol)      (symbol)->ginfo.value.chain
186 #define SYMBOL_LANGUAGE(symbol)         (symbol)->ginfo.language
187 #define SYMBOL_SECTION(symbol)          (symbol)->ginfo.section
188 #define SYMBOL_OBJ_SECTION(symbol)      (symbol)->ginfo.obj_section
189
190 /* Initializes the language dependent portion of a symbol
191    depending upon the language for the symbol.  */
192 #define SYMBOL_SET_LANGUAGE(symbol,language) \
193   (symbol_set_language (&(symbol)->ginfo, (language)))
194 extern void symbol_set_language (struct general_symbol_info *symbol,
195                                  enum language language);
196
197 /* Set just the linkage name of a symbol; do not try to demangle
198    it.  Used for constructs which do not have a mangled name,
199    e.g. struct tags.  Unlike SYMBOL_SET_NAMES, linkage_name must
200    be terminated and either already on the objfile's obstack or
201    permanently allocated.  */
202 #define SYMBOL_SET_LINKAGE_NAME(symbol,linkage_name) \
203   (symbol)->ginfo.name = (linkage_name)
204
205 /* Set the linkage and natural names of a symbol, by demangling
206    the linkage name.  */
207 #define SYMBOL_SET_NAMES(symbol,linkage_name,len,copy_name,objfile)     \
208   symbol_set_names (&(symbol)->ginfo, linkage_name, len, copy_name, objfile)
209 extern void symbol_set_names (struct general_symbol_info *symbol,
210                               const char *linkage_name, int len, int copy_name,
211                               struct objfile *objfile);
212
213 /* Now come lots of name accessor macros.  Short version as to when to
214    use which: Use SYMBOL_NATURAL_NAME to refer to the name of the
215    symbol in the original source code.  Use SYMBOL_LINKAGE_NAME if you
216    want to know what the linker thinks the symbol's name is.  Use
217    SYMBOL_PRINT_NAME for output.  Use SYMBOL_DEMANGLED_NAME if you
218    specifically need to know whether SYMBOL_NATURAL_NAME and
219    SYMBOL_LINKAGE_NAME are different.  */
220
221 /* Return SYMBOL's "natural" name, i.e. the name that it was called in
222    the original source code.  In languages like C++ where symbols may
223    be mangled for ease of manipulation by the linker, this is the
224    demangled name.  */
225
226 #define SYMBOL_NATURAL_NAME(symbol) \
227   (symbol_natural_name (&(symbol)->ginfo))
228 extern char *symbol_natural_name (const struct general_symbol_info *symbol);
229
230 /* Return SYMBOL's name from the point of view of the linker.  In
231    languages like C++ where symbols may be mangled for ease of
232    manipulation by the linker, this is the mangled name; otherwise,
233    it's the same as SYMBOL_NATURAL_NAME.  */
234
235 #define SYMBOL_LINKAGE_NAME(symbol)     (symbol)->ginfo.name
236
237 /* Return the demangled name for a symbol based on the language for
238    that symbol.  If no demangled name exists, return NULL.  */
239 #define SYMBOL_DEMANGLED_NAME(symbol) \
240   (symbol_demangled_name (&(symbol)->ginfo))
241 extern char *symbol_demangled_name (const struct general_symbol_info *symbol);
242
243 /* Macro that returns a version of the name of a symbol that is
244    suitable for output.  In C++ this is the "demangled" form of the
245    name if demangle is on and the "mangled" form of the name if
246    demangle is off.  In other languages this is just the symbol name.
247    The result should never be NULL.  Don't use this for internal
248    purposes (e.g. storing in a hashtable): it's only suitable for output.
249
250    N.B. symbol may be anything with a ginfo member,
251    e.g., struct symbol or struct minimal_symbol.  */
252
253 #define SYMBOL_PRINT_NAME(symbol)                                       \
254   (demangle ? SYMBOL_NATURAL_NAME (symbol) : SYMBOL_LINKAGE_NAME (symbol))
255 extern int demangle;
256
257 /* Macro that returns the name to be used when sorting and searching symbols.
258    In  C++, Chill, and Java, we search for the demangled form of a name,
259    and so sort symbols accordingly.  In Ada, however, we search by mangled
260    name.  If there is no distinct demangled name, then SYMBOL_SEARCH_NAME
261    returns the same value (same pointer) as SYMBOL_LINKAGE_NAME.  */
262 #define SYMBOL_SEARCH_NAME(symbol)                                       \
263    (symbol_search_name (&(symbol)->ginfo))
264 extern char *symbol_search_name (const struct general_symbol_info *);
265
266 /* Return non-zero if NAME matches the "search" name of SYMBOL.
267    Whitespace and trailing parentheses are ignored.
268    See strcmp_iw for details about its behavior.  */
269 #define SYMBOL_MATCHES_SEARCH_NAME(symbol, name)                        \
270   (strcmp_iw (SYMBOL_SEARCH_NAME (symbol), (name)) == 0)
271
272 /* Classification types for a minimal symbol.  These should be taken as
273    "advisory only", since if gdb can't easily figure out a
274    classification it simply selects mst_unknown.  It may also have to
275    guess when it can't figure out which is a better match between two
276    types (mst_data versus mst_bss) for example.  Since the minimal
277    symbol info is sometimes derived from the BFD library's view of a
278    file, we need to live with what information bfd supplies.  */
279
280 enum minimal_symbol_type
281 {
282   mst_unknown = 0,              /* Unknown type, the default */
283   mst_text,                     /* Generally executable instructions */
284   mst_text_gnu_ifunc,           /* Executable code returning address
285                                    of executable code */
286   mst_slot_got_plt,             /* GOT entries for .plt sections */
287   mst_data,                     /* Generally initialized data */
288   mst_bss,                      /* Generally uninitialized data */
289   mst_abs,                      /* Generally absolute (nonrelocatable) */
290   /* GDB uses mst_solib_trampoline for the start address of a shared
291      library trampoline entry.  Breakpoints for shared library functions
292      are put there if the shared library is not yet loaded.
293      After the shared library is loaded, lookup_minimal_symbol will
294      prefer the minimal symbol from the shared library (usually
295      a mst_text symbol) over the mst_solib_trampoline symbol, and the
296      breakpoints will be moved to their true address in the shared
297      library via breakpoint_re_set.  */
298   mst_solib_trampoline,         /* Shared library trampoline code */
299   /* For the mst_file* types, the names are only guaranteed to be unique
300      within a given .o file.  */
301   mst_file_text,                /* Static version of mst_text */
302   mst_file_data,                /* Static version of mst_data */
303   mst_file_bss                  /* Static version of mst_bss */
304 };
305
306 /* Define a simple structure used to hold some very basic information about
307    all defined global symbols (text, data, bss, abs, etc).  The only required
308    information is the general_symbol_info.
309
310    In many cases, even if a file was compiled with no special options for
311    debugging at all, as long as was not stripped it will contain sufficient
312    information to build a useful minimal symbol table using this structure.
313    Even when a file contains enough debugging information to build a full
314    symbol table, these minimal symbols are still useful for quickly mapping
315    between names and addresses, and vice versa.  They are also sometimes
316    used to figure out what full symbol table entries need to be read in.  */
317
318 struct minimal_symbol
319 {
320
321   /* The general symbol info required for all types of symbols.
322
323      The SYMBOL_VALUE_ADDRESS contains the address that this symbol
324      corresponds to.  */
325
326   struct general_symbol_info ginfo;
327
328   /* Size of this symbol.  end_psymtab in dbxread.c uses this
329      information to calculate the end of the partial symtab based on the
330      address of the last symbol plus the size of the last symbol.  */
331
332   unsigned long size;
333
334   /* Which source file is this symbol in?  Only relevant for mst_file_*.  */
335   const char *filename;
336
337   /* Classification type for this minimal symbol.  */
338
339   ENUM_BITFIELD(minimal_symbol_type) type : 8;
340
341   /* Two flag bits provided for the use of the target.  */
342   unsigned int target_flag_1 : 1;
343   unsigned int target_flag_2 : 1;
344
345   /* Minimal symbols with the same hash key are kept on a linked
346      list.  This is the link.  */
347
348   struct minimal_symbol *hash_next;
349
350   /* Minimal symbols are stored in two different hash tables.  This is
351      the `next' pointer for the demangled hash table.  */
352
353   struct minimal_symbol *demangled_hash_next;
354 };
355
356 #define MSYMBOL_TARGET_FLAG_1(msymbol)  (msymbol)->target_flag_1
357 #define MSYMBOL_TARGET_FLAG_2(msymbol)  (msymbol)->target_flag_2
358 #define MSYMBOL_SIZE(msymbol)           (msymbol)->size
359 #define MSYMBOL_TYPE(msymbol)           (msymbol)->type
360
361 #include "minsyms.h"
362
363 \f
364
365 /* Represent one symbol name; a variable, constant, function or typedef.  */
366
367 /* Different name domains for symbols.  Looking up a symbol specifies a
368    domain and ignores symbol definitions in other name domains.  */
369
370 typedef enum domain_enum_tag
371 {
372   /* UNDEF_DOMAIN is used when a domain has not been discovered or
373      none of the following apply.  This usually indicates an error either
374      in the symbol information or in gdb's handling of symbols.  */
375
376   UNDEF_DOMAIN,
377
378   /* VAR_DOMAIN is the usual domain.  In C, this contains variables,
379      function names, typedef names and enum type values.  */
380
381   VAR_DOMAIN,
382
383   /* STRUCT_DOMAIN is used in C to hold struct, union and enum type names.
384      Thus, if `struct foo' is used in a C program, it produces a symbol named
385      `foo' in the STRUCT_DOMAIN.  */
386
387   STRUCT_DOMAIN,
388
389   /* LABEL_DOMAIN may be used for names of labels (for gotos).  */
390
391   LABEL_DOMAIN
392 } domain_enum;
393
394 /* Searching domains, used for `search_symbols'.  Element numbers are
395    hardcoded in GDB, check all enum uses before changing it.  */
396
397 enum search_domain
398 {
399   /* Everything in VAR_DOMAIN minus FUNCTIONS_DOMAIN and
400      TYPES_DOMAIN.  */
401   VARIABLES_DOMAIN = 0,
402
403   /* All functions -- for some reason not methods, though.  */
404   FUNCTIONS_DOMAIN = 1,
405
406   /* All defined types */
407   TYPES_DOMAIN = 2,
408
409   /* Any type.  */
410   ALL_DOMAIN = 3
411 };
412
413 /* An address-class says where to find the value of a symbol.  */
414
415 enum address_class
416 {
417   /* Not used; catches errors.  */
418
419   LOC_UNDEF,
420
421   /* Value is constant int SYMBOL_VALUE, host byteorder.  */
422
423   LOC_CONST,
424
425   /* Value is at fixed address SYMBOL_VALUE_ADDRESS.  */
426
427   LOC_STATIC,
428
429   /* Value is in register.  SYMBOL_VALUE is the register number
430      in the original debug format.  SYMBOL_REGISTER_OPS holds a
431      function that can be called to transform this into the
432      actual register number this represents in a specific target
433      architecture (gdbarch).
434
435      For some symbol formats (stabs, for some compilers at least),
436      the compiler generates two symbols, an argument and a register.
437      In some cases we combine them to a single LOC_REGISTER in symbol
438      reading, but currently not for all cases (e.g. it's passed on the
439      stack and then loaded into a register).  */
440
441   LOC_REGISTER,
442
443   /* It's an argument; the value is at SYMBOL_VALUE offset in arglist.  */
444
445   LOC_ARG,
446
447   /* Value address is at SYMBOL_VALUE offset in arglist.  */
448
449   LOC_REF_ARG,
450
451   /* Value is in specified register.  Just like LOC_REGISTER except the
452      register holds the address of the argument instead of the argument
453      itself.  This is currently used for the passing of structs and unions
454      on sparc and hppa.  It is also used for call by reference where the
455      address is in a register, at least by mipsread.c.  */
456
457   LOC_REGPARM_ADDR,
458
459   /* Value is a local variable at SYMBOL_VALUE offset in stack frame.  */
460
461   LOC_LOCAL,
462
463   /* Value not used; definition in SYMBOL_TYPE.  Symbols in the domain
464      STRUCT_DOMAIN all have this class.  */
465
466   LOC_TYPEDEF,
467
468   /* Value is address SYMBOL_VALUE_ADDRESS in the code.  */
469
470   LOC_LABEL,
471
472   /* In a symbol table, value is SYMBOL_BLOCK_VALUE of a `struct block'.
473      In a partial symbol table, SYMBOL_VALUE_ADDRESS is the start address
474      of the block.  Function names have this class.  */
475
476   LOC_BLOCK,
477
478   /* Value is a constant byte-sequence pointed to by SYMBOL_VALUE_BYTES, in
479      target byte order.  */
480
481   LOC_CONST_BYTES,
482
483   /* Value is at fixed address, but the address of the variable has
484      to be determined from the minimal symbol table whenever the
485      variable is referenced.
486      This happens if debugging information for a global symbol is
487      emitted and the corresponding minimal symbol is defined
488      in another object file or runtime common storage.
489      The linker might even remove the minimal symbol if the global
490      symbol is never referenced, in which case the symbol remains
491      unresolved.
492      
493      GDB would normally find the symbol in the minimal symbol table if it will
494      not find it in the full symbol table.  But a reference to an external
495      symbol in a local block shadowing other definition requires full symbol
496      without possibly having its address available for LOC_STATIC.  Testcase
497      is provided as `gdb.dwarf2/dw2-unresolved.exp'.  */
498
499   LOC_UNRESOLVED,
500
501   /* The variable does not actually exist in the program.
502      The value is ignored.  */
503
504   LOC_OPTIMIZED_OUT,
505
506   /* The variable's address is computed by a set of location
507      functions (see "struct symbol_computed_ops" below).  */
508   LOC_COMPUTED,
509 };
510
511 /* The methods needed to implement LOC_COMPUTED.  These methods can
512    use the symbol's .aux_value for additional per-symbol information.
513
514    At present this is only used to implement location expressions.  */
515
516 struct symbol_computed_ops
517 {
518
519   /* Return the value of the variable SYMBOL, relative to the stack
520      frame FRAME.  If the variable has been optimized out, return
521      zero.
522
523      Iff `read_needs_frame (SYMBOL)' is zero, then FRAME may be zero.  */
524
525   struct value *(*read_variable) (struct symbol * symbol,
526                                   struct frame_info * frame);
527
528   /* Read variable SYMBOL like read_variable at (callee) FRAME's function
529      entry.  SYMBOL should be a function parameter, otherwise
530      NO_ENTRY_VALUE_ERROR will be thrown.  */
531   struct value *(*read_variable_at_entry) (struct symbol *symbol,
532                                            struct frame_info *frame);
533
534   /* Return non-zero if we need a frame to find the value of the SYMBOL.  */
535   int (*read_needs_frame) (struct symbol * symbol);
536
537   /* Write to STREAM a natural-language description of the location of
538      SYMBOL, in the context of ADDR.  */
539   void (*describe_location) (struct symbol * symbol, CORE_ADDR addr,
540                              struct ui_file * stream);
541
542   /* Tracepoint support.  Append bytecodes to the tracepoint agent
543      expression AX that push the address of the object SYMBOL.  Set
544      VALUE appropriately.  Note --- for objects in registers, this
545      needn't emit any code; as long as it sets VALUE properly, then
546      the caller will generate the right code in the process of
547      treating this as an lvalue or rvalue.  */
548
549   void (*tracepoint_var_ref) (struct symbol *symbol, struct gdbarch *gdbarch,
550                               struct agent_expr *ax, struct axs_value *value);
551 };
552
553 /* Functions used with LOC_REGISTER and LOC_REGPARM_ADDR.  */
554
555 struct symbol_register_ops
556 {
557   int (*register_number) (struct symbol *symbol, struct gdbarch *gdbarch);
558 };
559
560 /* This structure is space critical.  See space comments at the top.  */
561
562 struct symbol
563 {
564
565   /* The general symbol info required for all types of symbols.  */
566
567   struct general_symbol_info ginfo;
568
569   /* Data type of value */
570
571   struct type *type;
572
573   /* The symbol table containing this symbol.  This is the file
574      associated with LINE.  It can be NULL during symbols read-in but it is
575      never NULL during normal operation.  */
576   struct symtab *symtab;
577
578   /* Domain code.  */
579
580   ENUM_BITFIELD(domain_enum_tag) domain : 6;
581
582   /* Address class */
583   /* NOTE: cagney/2003-11-02: The fields "aclass" and "ops" contain
584      overlapping information.  By creating a per-aclass ops vector, or
585      using the aclass as an index into an ops table, the aclass and
586      ops fields can be merged.  The latter, for instance, would shave
587      32-bits from each symbol (relative to a symbol lookup, any table
588      index overhead would be in the noise).  */
589
590   ENUM_BITFIELD(address_class) aclass : 6;
591
592   /* Whether this is an argument.  */
593
594   unsigned is_argument : 1;
595
596   /* Whether this is an inlined function (class LOC_BLOCK only).  */
597   unsigned is_inlined : 1;
598
599   /* True if this is a C++ function symbol with template arguments.
600      In this case the symbol is really a "struct template_symbol".  */
601   unsigned is_cplus_template_function : 1;
602
603   /* Line number of this symbol's definition, except for inlined
604      functions.  For an inlined function (class LOC_BLOCK and
605      SYMBOL_INLINED set) this is the line number of the function's call
606      site.  Inlined function symbols are not definitions, and they are
607      never found by symbol table lookup.
608
609      FIXME: Should we really make the assumption that nobody will try
610      to debug files longer than 64K lines?  What about machine
611      generated programs?  */
612
613   unsigned short line;
614
615   /* Method's for symbol's of this class.  */
616   /* NOTE: cagney/2003-11-02: See comment above attached to "aclass".  */
617
618   union
619     {
620       /* Used with LOC_COMPUTED.  */
621       const struct symbol_computed_ops *ops_computed;
622
623       /* Used with LOC_REGISTER and LOC_REGPARM_ADDR.  */
624       const struct symbol_register_ops *ops_register;
625     } ops;
626
627   /* An arbitrary data pointer, allowing symbol readers to record
628      additional information on a per-symbol basis.  Note that this data
629      must be allocated using the same obstack as the symbol itself.  */
630   /* So far it is only used by LOC_COMPUTED to
631      find the location information.  For a LOC_BLOCK symbol
632      for a function in a compilation unit compiled with DWARF 2
633      information, this is information used internally by the DWARF 2
634      code --- specifically, the location expression for the frame
635      base for this function.  */
636   /* FIXME drow/2003-02-21: For the LOC_BLOCK case, it might be better
637      to add a magic symbol to the block containing this information,
638      or to have a generic debug info annotation slot for symbols.  */
639
640   void *aux_value;
641
642   struct symbol *hash_next;
643 };
644
645
646 #define SYMBOL_DOMAIN(symbol)   (symbol)->domain
647 #define SYMBOL_CLASS(symbol)            (symbol)->aclass
648 #define SYMBOL_IS_ARGUMENT(symbol)      (symbol)->is_argument
649 #define SYMBOL_INLINED(symbol)          (symbol)->is_inlined
650 #define SYMBOL_IS_CPLUS_TEMPLATE_FUNCTION(symbol) \
651   (symbol)->is_cplus_template_function
652 #define SYMBOL_TYPE(symbol)             (symbol)->type
653 #define SYMBOL_LINE(symbol)             (symbol)->line
654 #define SYMBOL_SYMTAB(symbol)           (symbol)->symtab
655 #define SYMBOL_COMPUTED_OPS(symbol)     (symbol)->ops.ops_computed
656 #define SYMBOL_REGISTER_OPS(symbol)     (symbol)->ops.ops_register
657 #define SYMBOL_LOCATION_BATON(symbol)   (symbol)->aux_value
658
659 /* An instance of this type is used to represent a C++ template
660    function.  It includes a "struct symbol" as a kind of base class;
661    users downcast to "struct template_symbol *" when needed.  A symbol
662    is really of this type iff SYMBOL_IS_CPLUS_TEMPLATE_FUNCTION is
663    true.  */
664
665 struct template_symbol
666 {
667   /* The base class.  */
668   struct symbol base;
669
670   /* The number of template arguments.  */
671   int n_template_arguments;
672
673   /* The template arguments.  This is an array with
674      N_TEMPLATE_ARGUMENTS elements.  */
675   struct symbol **template_arguments;
676 };
677
678 \f
679 /* Each item represents a line-->pc (or the reverse) mapping.  This is
680    somewhat more wasteful of space than one might wish, but since only
681    the files which are actually debugged are read in to core, we don't
682    waste much space.  */
683
684 struct linetable_entry
685 {
686   int line;
687   CORE_ADDR pc;
688 };
689
690 /* The order of entries in the linetable is significant.  They should
691    be sorted by increasing values of the pc field.  If there is more than
692    one entry for a given pc, then I'm not sure what should happen (and
693    I not sure whether we currently handle it the best way).
694
695    Example: a C for statement generally looks like this
696
697    10   0x100   - for the init/test part of a for stmt.
698    20   0x200
699    30   0x300
700    10   0x400   - for the increment part of a for stmt.
701
702    If an entry has a line number of zero, it marks the start of a PC
703    range for which no line number information is available.  It is
704    acceptable, though wasteful of table space, for such a range to be
705    zero length.  */
706
707 struct linetable
708 {
709   int nitems;
710
711   /* Actually NITEMS elements.  If you don't like this use of the
712      `struct hack', you can shove it up your ANSI (seriously, if the
713      committee tells us how to do it, we can probably go along).  */
714   struct linetable_entry item[1];
715 };
716
717 /* How to relocate the symbols from each section in a symbol file.
718    Each struct contains an array of offsets.
719    The ordering and meaning of the offsets is file-type-dependent;
720    typically it is indexed by section numbers or symbol types or
721    something like that.
722
723    To give us flexibility in changing the internal representation
724    of these offsets, the ANOFFSET macro must be used to insert and
725    extract offset values in the struct.  */
726
727 struct section_offsets
728 {
729   CORE_ADDR offsets[1];         /* As many as needed.  */
730 };
731
732 #define ANOFFSET(secoff, whichone) \
733   ((whichone == -1)                       \
734    ? (internal_error (__FILE__, __LINE__, \
735                       _("Section index is uninitialized")), -1) \
736    : secoff->offsets[whichone])
737
738 /* The size of a section_offsets table for N sections.  */
739 #define SIZEOF_N_SECTION_OFFSETS(n) \
740   (sizeof (struct section_offsets) \
741    + sizeof (((struct section_offsets *) 0)->offsets) * ((n)-1))
742
743 /* Each source file or header is represented by a struct symtab.
744    These objects are chained through the `next' field.  */
745
746 struct symtab
747 {
748   /* Unordered chain of all existing symtabs of this objfile.  */
749
750   struct symtab *next;
751
752   /* List of all symbol scope blocks for this symtab.  May be shared
753      between different symtabs (and normally is for all the symtabs
754      in a given compilation unit).  */
755
756   struct blockvector *blockvector;
757
758   /* Table mapping core addresses to line numbers for this file.
759      Can be NULL if none.  Never shared between different symtabs.  */
760
761   struct linetable *linetable;
762
763   /* Section in objfile->section_offsets for the blockvector and
764      the linetable.  Probably always SECT_OFF_TEXT.  */
765
766   int block_line_section;
767
768   /* If several symtabs share a blockvector, exactly one of them
769      should be designated the primary, so that the blockvector
770      is relocated exactly once by objfile_relocate.  */
771
772   unsigned int primary : 1;
773
774   /* Symtab has been compiled with both optimizations and debug info so that
775      GDB may stop skipping prologues as variables locations are valid already
776      at function entry points.  */
777
778   unsigned int locations_valid : 1;
779
780   /* DWARF unwinder for this CU is valid even for epilogues (PC at the return
781      instruction).  This is supported by GCC since 4.5.0.  */
782
783   unsigned int epilogue_unwind_valid : 1;
784
785   /* The macro table for this symtab.  Like the blockvector, this
786      may be shared between different symtabs --- and normally is for
787      all the symtabs in a given compilation unit.  */
788   struct macro_table *macro_table;
789
790   /* Name of this source file.  */
791
792   char *filename;
793
794   /* Directory in which it was compiled, or NULL if we don't know.  */
795
796   char *dirname;
797
798   /* Total number of lines found in source file.  */
799
800   int nlines;
801
802   /* line_charpos[N] is the position of the (N-1)th line of the
803      source file.  "position" means something we can lseek() to; it
804      is not guaranteed to be useful any other way.  */
805
806   int *line_charpos;
807
808   /* Language of this source file.  */
809
810   enum language language;
811
812   /* String that identifies the format of the debugging information, such
813      as "stabs", "dwarf 1", "dwarf 2", "coff", etc.  This is mostly useful
814      for automated testing of gdb but may also be information that is
815      useful to the user.  */
816
817   const char *debugformat;
818
819   /* String of producer version information.  May be zero.  */
820
821   const char *producer;
822
823   /* Full name of file as found by searching the source path.
824      NULL if not yet known.  */
825
826   char *fullname;
827
828   /* Object file from which this symbol information was read.  */
829
830   struct objfile *objfile;
831
832   /* struct call_site entries for this compilation unit or NULL.  */
833
834   htab_t call_site_htab;
835 };
836
837 #define BLOCKVECTOR(symtab)     (symtab)->blockvector
838 #define LINETABLE(symtab)       (symtab)->linetable
839 #define SYMTAB_PSPACE(symtab)   (symtab)->objfile->pspace
840 \f
841
842 /* The virtual function table is now an array of structures which have the
843    form { int16 offset, delta; void *pfn; }. 
844
845    In normal virtual function tables, OFFSET is unused.
846    DELTA is the amount which is added to the apparent object's base
847    address in order to point to the actual object to which the
848    virtual function should be applied.
849    PFN is a pointer to the virtual function.
850
851    Note that this macro is g++ specific (FIXME).  */
852
853 #define VTBL_FNADDR_OFFSET 2
854
855 /* External variables and functions for the objects described above.  */
856
857 /* True if we are nested inside psymtab_to_symtab.  */
858
859 extern int currently_reading_symtab;
860
861 /* symtab.c lookup functions */
862
863 extern const char multiple_symbols_ask[];
864 extern const char multiple_symbols_all[];
865 extern const char multiple_symbols_cancel[];
866
867 const char *multiple_symbols_select_mode (void);
868
869 int symbol_matches_domain (enum language symbol_language, 
870                            domain_enum symbol_domain,
871                            domain_enum domain);
872
873 /* lookup a symbol table by source file name.  */
874
875 extern struct symtab *lookup_symtab (const char *);
876
877 /* lookup a symbol by name (optional block) in language.  */
878
879 extern struct symbol *lookup_symbol_in_language (const char *,
880                                                  const struct block *,
881                                                  const domain_enum,
882                                                  enum language,
883                                                  int *);
884
885 /* lookup a symbol by name (optional block, optional symtab)
886    in the current language.  */
887
888 extern struct symbol *lookup_symbol (const char *, const struct block *,
889                                      const domain_enum, int *);
890
891 /* A default version of lookup_symbol_nonlocal for use by languages
892    that can't think of anything better to do.  */
893
894 extern struct symbol *basic_lookup_symbol_nonlocal (const char *,
895                                                     const struct block *,
896                                                     const domain_enum);
897
898 /* Some helper functions for languages that need to write their own
899    lookup_symbol_nonlocal functions.  */
900
901 /* Lookup a symbol in the static block associated to BLOCK, if there
902    is one; do nothing if BLOCK is NULL or a global block.  */
903
904 extern struct symbol *lookup_symbol_static (const char *name,
905                                             const struct block *block,
906                                             const domain_enum domain);
907
908 /* Lookup a symbol in all files' global blocks (searching psymtabs if
909    necessary).  */
910
911 extern struct symbol *lookup_symbol_global (const char *name,
912                                             const struct block *block,
913                                             const domain_enum domain);
914
915 /* Lookup a symbol within the block BLOCK.  This, unlike
916    lookup_symbol_block, will set SYMTAB and BLOCK_FOUND correctly, and
917    will fix up the symbol if necessary.  */
918
919 extern struct symbol *lookup_symbol_aux_block (const char *name,
920                                                const struct block *block,
921                                                const domain_enum domain);
922
923 extern struct symbol *lookup_language_this (const struct language_defn *lang,
924                                             const struct block *block);
925
926 /* Lookup a symbol only in the file static scope of all the objfiles.  */
927
928 struct symbol *lookup_static_symbol_aux (const char *name,
929                                          const domain_enum domain);
930
931
932 /* lookup a symbol by name, within a specified block.  */
933
934 extern struct symbol *lookup_block_symbol (const struct block *, const char *,
935                                            const domain_enum);
936
937 /* lookup a [struct, union, enum] by name, within a specified block.  */
938
939 extern struct type *lookup_struct (const char *, struct block *);
940
941 extern struct type *lookup_union (const char *, struct block *);
942
943 extern struct type *lookup_enum (const char *, struct block *);
944
945 /* from blockframe.c: */
946
947 /* lookup the function symbol corresponding to the address.  */
948
949 extern struct symbol *find_pc_function (CORE_ADDR);
950
951 /* lookup the function corresponding to the address and section.  */
952
953 extern struct symbol *find_pc_sect_function (CORE_ADDR, struct obj_section *);
954
955 extern int find_pc_partial_function_gnu_ifunc (CORE_ADDR pc, char **name,
956                                                CORE_ADDR *address,
957                                                CORE_ADDR *endaddr,
958                                                int *is_gnu_ifunc_p);
959
960 /* lookup function from address, return name, start addr and end addr.  */
961
962 extern int find_pc_partial_function (CORE_ADDR, char **, CORE_ADDR *,
963                                      CORE_ADDR *);
964
965 extern void clear_pc_function_cache (void);
966
967 /* lookup partial symbol table by address and section.  */
968
969 extern struct symtab *find_pc_sect_symtab_via_partial (CORE_ADDR,
970                                                        struct obj_section *);
971
972 /* lookup full symbol table by address.  */
973
974 extern struct symtab *find_pc_symtab (CORE_ADDR);
975
976 /* lookup full symbol table by address and section.  */
977
978 extern struct symtab *find_pc_sect_symtab (CORE_ADDR, struct obj_section *);
979
980 extern int find_pc_line_pc_range (CORE_ADDR, CORE_ADDR *, CORE_ADDR *);
981
982 extern void reread_symbols (void);
983
984 extern struct type *lookup_transparent_type (const char *);
985 extern struct type *basic_lookup_transparent_type (const char *);
986
987
988 /* Macro for name of symbol to indicate a file compiled with gcc.  */
989 #ifndef GCC_COMPILED_FLAG_SYMBOL
990 #define GCC_COMPILED_FLAG_SYMBOL "gcc_compiled."
991 #endif
992
993 /* Macro for name of symbol to indicate a file compiled with gcc2.  */
994 #ifndef GCC2_COMPILED_FLAG_SYMBOL
995 #define GCC2_COMPILED_FLAG_SYMBOL "gcc2_compiled."
996 #endif
997
998 extern int in_gnu_ifunc_stub (CORE_ADDR pc);
999
1000 /* Functions for resolving STT_GNU_IFUNC symbols which are implemented only
1001    for ELF symbol files.  */
1002
1003 struct gnu_ifunc_fns
1004 {
1005   /* See elf_gnu_ifunc_resolve_addr for its real implementation.  */
1006   CORE_ADDR (*gnu_ifunc_resolve_addr) (struct gdbarch *gdbarch, CORE_ADDR pc);
1007
1008   /* See elf_gnu_ifunc_resolve_name for its real implementation.  */
1009   int (*gnu_ifunc_resolve_name) (const char *function_name,
1010                                  CORE_ADDR *function_address_p);
1011
1012   /* See elf_gnu_ifunc_resolver_stop for its real implementation.  */
1013   void (*gnu_ifunc_resolver_stop) (struct breakpoint *b);
1014
1015   /* See elf_gnu_ifunc_resolver_return_stop for its real implementation.  */
1016   void (*gnu_ifunc_resolver_return_stop) (struct breakpoint *b);
1017 };
1018
1019 #define gnu_ifunc_resolve_addr gnu_ifunc_fns_p->gnu_ifunc_resolve_addr
1020 #define gnu_ifunc_resolve_name gnu_ifunc_fns_p->gnu_ifunc_resolve_name
1021 #define gnu_ifunc_resolver_stop gnu_ifunc_fns_p->gnu_ifunc_resolver_stop
1022 #define gnu_ifunc_resolver_return_stop \
1023   gnu_ifunc_fns_p->gnu_ifunc_resolver_return_stop
1024
1025 extern const struct gnu_ifunc_fns *gnu_ifunc_fns_p;
1026
1027 extern CORE_ADDR find_solib_trampoline_target (struct frame_info *, CORE_ADDR);
1028
1029 struct symtab_and_line
1030 {
1031   /* The program space of this sal.  */
1032   struct program_space *pspace;
1033
1034   struct symtab *symtab;
1035   struct obj_section *section;
1036   /* Line number.  Line numbers start at 1 and proceed through symtab->nlines.
1037      0 is never a valid line number; it is used to indicate that line number
1038      information is not available.  */
1039   int line;
1040
1041   CORE_ADDR pc;
1042   CORE_ADDR end;
1043   int explicit_pc;
1044   int explicit_line;
1045 };
1046
1047 extern void init_sal (struct symtab_and_line *sal);
1048
1049 struct symtabs_and_lines
1050 {
1051   struct symtab_and_line *sals;
1052   int nelts;
1053 };
1054 \f
1055
1056
1057 /* Some types and macros needed for exception catchpoints.
1058    Can't put these in target.h because symtab_and_line isn't
1059    known there.  This file will be included by breakpoint.c,
1060    hppa-tdep.c, etc.  */
1061
1062 /* Enums for exception-handling support.  */
1063 enum exception_event_kind
1064 {
1065   EX_EVENT_THROW,
1066   EX_EVENT_CATCH
1067 };
1068
1069 \f
1070
1071 /* Given a pc value, return line number it is in.  Second arg nonzero means
1072    if pc is on the boundary use the previous statement's line number.  */
1073
1074 extern struct symtab_and_line find_pc_line (CORE_ADDR, int);
1075
1076 /* Same function, but specify a section as well as an address.  */
1077
1078 extern struct symtab_and_line find_pc_sect_line (CORE_ADDR,
1079                                                  struct obj_section *, int);
1080
1081 /* Given a symtab and line number, return the pc there.  */
1082
1083 extern int find_line_pc (struct symtab *, int, CORE_ADDR *);
1084
1085 extern int find_line_pc_range (struct symtab_and_line, CORE_ADDR *,
1086                                CORE_ADDR *);
1087
1088 extern void resolve_sal_pc (struct symtab_and_line *);
1089
1090 /* Given a string, return the line specified by it.  For commands like "list"
1091    and "breakpoint".  */
1092
1093 extern struct symtabs_and_lines decode_line_spec (char *, int);
1094
1095 extern struct symtabs_and_lines decode_line_spec_1 (char *, int);
1096
1097 /* Symmisc.c */
1098
1099 void maintenance_print_symbols (char *, int);
1100
1101 void maintenance_print_psymbols (char *, int);
1102
1103 void maintenance_print_msymbols (char *, int);
1104
1105 void maintenance_print_objfiles (char *, int);
1106
1107 void maintenance_info_symtabs (char *, int);
1108
1109 void maintenance_info_psymtabs (char *, int);
1110
1111 void maintenance_check_symtabs (char *, int);
1112
1113 /* maint.c */
1114
1115 void maintenance_print_statistics (char *, int);
1116
1117 /* Symbol-reading stuff in symfile.c and solib.c.  */
1118
1119 extern void clear_solib (void);
1120
1121 /* source.c */
1122
1123 extern int identify_source_line (struct symtab *, int, int, CORE_ADDR);
1124
1125 extern void print_source_lines (struct symtab *, int, int, int);
1126
1127 extern void forget_cached_source_info_for_objfile (struct objfile *);
1128 extern void forget_cached_source_info (void);
1129
1130 extern void select_source_symtab (struct symtab *);
1131
1132 extern char **default_make_symbol_completion_list_break_on
1133   (char *text, char *word, const char *break_on);
1134 extern char **default_make_symbol_completion_list (char *, char *);
1135 extern char **make_symbol_completion_list (char *, char *);
1136 extern char **make_symbol_completion_list_fn (struct cmd_list_element *,
1137                                               char *, char *);
1138
1139 extern char **make_file_symbol_completion_list (char *, char *, char *);
1140
1141 extern char **make_source_files_completion_list (char *, char *);
1142
1143 /* symtab.c */
1144
1145 int matching_obj_sections (struct obj_section *, struct obj_section *);
1146
1147 extern const char *find_main_filename (void);
1148
1149 extern struct symtab *find_line_symtab (struct symtab *, int, int *, int *);
1150
1151 extern struct symtab_and_line find_function_start_sal (struct symbol *sym,
1152                                                        int);
1153
1154 extern void skip_prologue_sal (struct symtab_and_line *);
1155
1156 /* symfile.c */
1157
1158 extern void clear_symtab_users (int add_flags);
1159
1160 extern enum language deduce_language_from_filename (const char *);
1161
1162 /* symtab.c */
1163
1164 extern int in_prologue (struct gdbarch *gdbarch,
1165                         CORE_ADDR pc, CORE_ADDR func_start);
1166
1167 extern CORE_ADDR skip_prologue_using_sal (struct gdbarch *gdbarch,
1168                                           CORE_ADDR func_addr);
1169
1170 extern struct symbol *fixup_symbol_section (struct symbol *,
1171                                             struct objfile *);
1172
1173 /* Symbol searching */
1174
1175 /* When using search_symbols, a list of the following structs is returned.
1176    Callers must free the search list using free_search_symbols!  */
1177 struct symbol_search
1178 {
1179   /* The block in which the match was found.  Could be, for example,
1180      STATIC_BLOCK or GLOBAL_BLOCK.  */
1181   int block;
1182
1183   /* Information describing what was found.
1184
1185      If symtab abd symbol are NOT NULL, then information was found
1186      for this match.  */
1187   struct symtab *symtab;
1188   struct symbol *symbol;
1189
1190   /* If msymbol is non-null, then a match was made on something for
1191      which only minimal_symbols exist.  */
1192   struct minimal_symbol *msymbol;
1193
1194   /* A link to the next match, or NULL for the end.  */
1195   struct symbol_search *next;
1196 };
1197
1198 extern void search_symbols (char *, enum search_domain, int, char **,
1199                             struct symbol_search **);
1200 extern void free_search_symbols (struct symbol_search *);
1201 extern struct cleanup *make_cleanup_free_search_symbols (struct symbol_search
1202                                                          *);
1203
1204 /* The name of the ``main'' function.
1205    FIXME: cagney/2001-03-20: Can't make main_name() const since some
1206    of the calling code currently assumes that the string isn't
1207    const.  */
1208 extern void set_main_name (const char *name);
1209 extern /*const */ char *main_name (void);
1210 extern enum language language_of_main;
1211
1212 /* Check global symbols in objfile.  */
1213 struct symbol *lookup_global_symbol_from_objfile (const struct objfile *,
1214                                                   const char *name,
1215                                                   const domain_enum domain);
1216
1217 /* Return 1 if the supplied producer string matches the ARM RealView
1218    compiler (armcc).  */
1219 int producer_is_realview (const char *producer);
1220
1221 void fixup_section (struct general_symbol_info *ginfo,
1222                     CORE_ADDR addr, struct objfile *objfile);
1223
1224 struct objfile *lookup_objfile_from_block (const struct block *block);
1225
1226 extern int basenames_may_differ;
1227
1228 int compare_filenames_for_search (const char *filename,
1229                                   const char *search_name,
1230                                   int search_len);
1231
1232 int iterate_over_some_symtabs (const char *name,
1233                                const char *full_path,
1234                                const char *real_path,
1235                                int (*callback) (struct symtab *symtab,
1236                                                 void *data),
1237                                void *data,
1238                                struct symtab *first,
1239                                struct symtab *after_last);
1240
1241 void iterate_over_symtabs (const char *name,
1242                            int (*callback) (struct symtab *symtab,
1243                                             void *data),
1244                            void *data);
1245
1246 DEF_VEC_I (CORE_ADDR);
1247
1248 VEC (CORE_ADDR) *find_pcs_for_symtab_line (struct symtab *symtab, int line,
1249                                            struct linetable_entry **best_entry);
1250
1251 /* Callback for LA_ITERATE_OVER_SYMBOLS.  The callback will be called
1252    once per matching symbol SYM, with DATA being the argument of the
1253    same name that was passed to LA_ITERATE_OVER_SYMBOLS.  The callback
1254    should return nonzero to indicate that LA_ITERATE_OVER_SYMBOLS
1255    should continue iterating, or zero to indicate that the iteration
1256    should end.  */
1257
1258 typedef int (symbol_found_callback_ftype) (struct symbol *sym, void *data);
1259
1260 void iterate_over_symbols (const struct block *block, const char *name,
1261                            const domain_enum domain,
1262                            symbol_found_callback_ftype *callback,
1263                            void *data);
1264
1265 struct cleanup *demangle_for_lookup (const char *name, enum language lang,
1266                                      const char **result_name);
1267
1268 #endif /* !defined(SYMTAB_H) */