* demangle.c (is_cplus_marker): New function, checks if a
[platform/upstream/binutils.git] / gdb / symtab.h
1 /* Symbol table definitions for GDB.
2    Copyright 1986, 1989, 1991, 1992, 1993, 1994, 1995, 1996 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 2 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, write to the Free Software
18 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  */
19
20 #if !defined (SYMTAB_H)
21 #define SYMTAB_H 1
22
23 /* Some definitions and declarations to go with use of obstacks.  */
24
25 #include "obstack.h"
26 #define obstack_chunk_alloc xmalloc
27 #define obstack_chunk_free free
28
29 /* Don't do this; it means that if some .o's are compiled with GNU C
30    and some are not (easy to do accidentally the way we configure
31    things; also it is a pain to have to "make clean" every time you
32    want to switch compilers), then GDB dies a horrible death.  */
33 /* GNU C supports enums that are bitfields.  Some compilers don't. */
34 #if 0 && defined(__GNUC__) && !defined(BYTE_BITFIELD)
35 #define BYTE_BITFIELD   :8;
36 #else
37 #define BYTE_BITFIELD   /*nothing*/
38 #endif
39
40 /* Define a structure for the information that is common to all symbol types,
41    including minimal symbols, partial symbols, and full symbols.  In a
42    multilanguage environment, some language specific information may need to
43    be recorded along with each symbol.
44
45    These fields are ordered to encourage good packing, since we frequently
46    have tens or hundreds of thousands of these.  */
47
48 struct general_symbol_info
49 {
50   /* Name of the symbol.  This is a required field.  Storage for the name is
51      allocated on the psymbol_obstack or symbol_obstack for the associated
52      objfile. */
53
54   char *name;
55
56   /* Value of the symbol.  Which member of this union to use, and what
57      it means, depends on what kind of symbol this is and its
58      SYMBOL_CLASS.  See comments there for more details.  All of these
59      are in host byte order (though what they point to might be in
60      target byte order, e.g. LOC_CONST_BYTES).  */
61
62   union
63     {
64       /* The fact that this is a long not a LONGEST mainly limits the
65          range of a LOC_CONST.  Since LOC_CONST_BYTES exists, I'm not
66          sure that is a big deal.  */
67       long ivalue;
68
69       struct block *block;
70
71       char *bytes;
72
73       CORE_ADDR address;
74
75       /* for opaque typedef struct chain */
76
77       struct symbol *chain;
78     }
79   value;
80
81   /* Since one and only one language can apply, wrap the language specific
82      information inside a union. */
83
84   union
85     {
86       struct cplus_specific      /* For C++ */
87         {
88           char *demangled_name;
89         } cplus_specific;
90       struct chill_specific      /* For Chill */
91         {
92           char *demangled_name;
93         } chill_specific;
94     } language_specific;
95
96   /* Record the source code language that applies to this symbol.
97      This is used to select one of the fields from the language specific
98      union above. */
99
100   enum language language BYTE_BITFIELD;
101
102   /* Which section is this symbol in?  This is an index into
103      section_offsets for this objfile.  Negative means that the symbol
104      does not get relocated relative to a section.
105      Disclaimer: currently this is just used for xcoff, so don't
106      expect all symbol-reading code to set it correctly (the ELF code
107      also tries to set it correctly).  */
108
109   short section;
110 };
111
112 #define SYMBOL_NAME(symbol)             (symbol)->ginfo.name
113 #define SYMBOL_VALUE(symbol)            (symbol)->ginfo.value.ivalue
114 #define SYMBOL_VALUE_ADDRESS(symbol)    (symbol)->ginfo.value.address
115 #define SYMBOL_VALUE_BYTES(symbol)      (symbol)->ginfo.value.bytes
116 #define SYMBOL_BLOCK_VALUE(symbol)      (symbol)->ginfo.value.block
117 #define SYMBOL_VALUE_CHAIN(symbol)      (symbol)->ginfo.value.chain
118 #define SYMBOL_LANGUAGE(symbol)         (symbol)->ginfo.language
119 #define SYMBOL_SECTION(symbol)          (symbol)->ginfo.section
120
121 #define SYMBOL_CPLUS_DEMANGLED_NAME(symbol)     \
122   (symbol)->ginfo.language_specific.cplus_specific.demangled_name
123
124 /* Macro that initializes the language dependent portion of a symbol
125    depending upon the language for the symbol. */
126
127 #define SYMBOL_INIT_LANGUAGE_SPECIFIC(symbol,language)                  \
128   do {                                                                  \
129     SYMBOL_LANGUAGE (symbol) = language;                                \
130     if (SYMBOL_LANGUAGE (symbol) == language_cplus)                     \
131       {                                                                 \
132         SYMBOL_CPLUS_DEMANGLED_NAME (symbol) = NULL;                    \
133       }                                                                 \
134     else if (SYMBOL_LANGUAGE (symbol) == language_chill)                \
135       {                                                                 \
136         SYMBOL_CHILL_DEMANGLED_NAME (symbol) = NULL;                    \
137       }                                                                 \
138     else                                                                \
139       {                                                                 \
140         memset (&(symbol)->ginfo.language_specific, 0,                  \
141                 sizeof ((symbol)->ginfo.language_specific));            \
142       }                                                                 \
143   } while (0)
144
145 /* Macro that attempts to initialize the demangled name for a symbol,
146    based on the language of that symbol.  If the language is set to
147    language_auto, it will attempt to find any demangling algorithm
148    that works and then set the language appropriately.  If no demangling
149    of any kind is found, the language is set back to language_unknown,
150    so we can avoid doing this work again the next time we encounter
151    the symbol.  Any required space to store the name is obtained from the
152    specified obstack. */
153
154 #define SYMBOL_INIT_DEMANGLED_NAME(symbol,obstack)                      \
155   do {                                                                  \
156     char *demangled = NULL;                                             \
157     if (SYMBOL_LANGUAGE (symbol) == language_cplus                      \
158         || SYMBOL_LANGUAGE (symbol) == language_auto)                   \
159       {                                                                 \
160         demangled =                                                     \
161           cplus_demangle (SYMBOL_NAME (symbol), DMGL_PARAMS | DMGL_ANSI);\
162         if (demangled != NULL)                                          \
163           {                                                             \
164             SYMBOL_LANGUAGE (symbol) = language_cplus;                  \
165             SYMBOL_CPLUS_DEMANGLED_NAME (symbol) =                      \
166               obsavestring (demangled, strlen (demangled), (obstack));  \
167             free (demangled);                                           \
168           }                                                             \
169         else                                                            \
170           {                                                             \
171             SYMBOL_CPLUS_DEMANGLED_NAME (symbol) = NULL;                \
172           }                                                             \
173       }                                                                 \
174     if (demangled == NULL                                               \
175         && (SYMBOL_LANGUAGE (symbol) == language_chill                  \
176             || SYMBOL_LANGUAGE (symbol) == language_auto))              \
177       {                                                                 \
178         demangled =                                                     \
179           chill_demangle (SYMBOL_NAME (symbol));                        \
180         if (demangled != NULL)                                          \
181           {                                                             \
182             SYMBOL_LANGUAGE (symbol) = language_chill;                  \
183             SYMBOL_CHILL_DEMANGLED_NAME (symbol) =                      \
184               obsavestring (demangled, strlen (demangled), (obstack));  \
185             free (demangled);                                           \
186           }                                                             \
187         else                                                            \
188           {                                                             \
189             SYMBOL_CHILL_DEMANGLED_NAME (symbol) = NULL;                \
190           }                                                             \
191       }                                                                 \
192     if (SYMBOL_LANGUAGE (symbol) == language_auto)                      \
193       {                                                                 \
194         SYMBOL_LANGUAGE (symbol) = language_unknown;                    \
195       }                                                                 \
196   } while (0)
197
198 /* Macro that returns the demangled name for a symbol based on the language
199    for that symbol.  If no demangled name exists, returns NULL. */
200
201 #define SYMBOL_DEMANGLED_NAME(symbol)                                   \
202   (SYMBOL_LANGUAGE (symbol) == language_cplus                           \
203    ? SYMBOL_CPLUS_DEMANGLED_NAME (symbol)                               \
204    : (SYMBOL_LANGUAGE (symbol) == language_chill                        \
205       ? SYMBOL_CHILL_DEMANGLED_NAME (symbol)                            \
206       : NULL))
207
208 #define SYMBOL_CHILL_DEMANGLED_NAME(symbol)                             \
209   (symbol)->ginfo.language_specific.chill_specific.demangled_name
210
211 /* Macro that returns the "natural source name" of a symbol.  In C++ this is
212    the "demangled" form of the name if demangle is on and the "mangled" form
213    of the name if demangle is off.  In other languages this is just the
214    symbol name.  The result should never be NULL. */
215
216 #define SYMBOL_SOURCE_NAME(symbol)                                      \
217   (demangle && SYMBOL_DEMANGLED_NAME (symbol) != NULL                   \
218    ? SYMBOL_DEMANGLED_NAME (symbol)                                     \
219    : SYMBOL_NAME (symbol))
220
221 /* Macro that returns the "natural assembly name" of a symbol.  In C++ this is
222    the "mangled" form of the name if demangle is off, or if demangle is on and
223    asm_demangle is off.  Otherwise if asm_demangle is on it is the "demangled"
224    form.  In other languages this is just the symbol name.  The result should
225    never be NULL. */
226
227 #define SYMBOL_LINKAGE_NAME(symbol)                                     \
228   (demangle && asm_demangle && SYMBOL_DEMANGLED_NAME (symbol) != NULL   \
229    ? SYMBOL_DEMANGLED_NAME (symbol)                                     \
230    : SYMBOL_NAME (symbol))
231
232 /* Macro that tests a symbol for a match against a specified name string.
233    First test the unencoded name, then looks for and test a C++ encoded
234    name if it exists.  Note that whitespace is ignored while attempting to
235    match a C++ encoded name, so that "foo::bar(int,long)" is the same as
236    "foo :: bar (int, long)".
237    Evaluates to zero if the match fails, or nonzero if it succeeds. */
238
239 #define SYMBOL_MATCHES_NAME(symbol, name)                               \
240   (STREQ (SYMBOL_NAME (symbol), (name))                                 \
241    || (SYMBOL_DEMANGLED_NAME (symbol) != NULL                           \
242        && strcmp_iw (SYMBOL_DEMANGLED_NAME (symbol), (name)) == 0))
243    
244 /* Macro that tests a symbol for an re-match against the last compiled regular
245    expression.  First test the unencoded name, then look for and test a C++
246    encoded name if it exists.
247    Evaluates to zero if the match fails, or nonzero if it succeeds. */
248
249 #define SYMBOL_MATCHES_REGEXP(symbol)                                   \
250   (re_exec (SYMBOL_NAME (symbol)) != 0                                  \
251    || (SYMBOL_DEMANGLED_NAME (symbol) != NULL                           \
252        && re_exec (SYMBOL_DEMANGLED_NAME (symbol)) != 0))
253    
254 /* Define a simple structure used to hold some very basic information about
255    all defined global symbols (text, data, bss, abs, etc).  The only required
256    information is the general_symbol_info.
257
258    In many cases, even if a file was compiled with no special options for
259    debugging at all, as long as was not stripped it will contain sufficient
260    information to build a useful minimal symbol table using this structure.
261    Even when a file contains enough debugging information to build a full
262    symbol table, these minimal symbols are still useful for quickly mapping
263    between names and addresses, and vice versa.  They are also sometimes
264    used to figure out what full symbol table entries need to be read in. */
265
266 struct minimal_symbol
267 {
268
269   /* The general symbol info required for all types of symbols.
270
271      The SYMBOL_VALUE_ADDRESS contains the address that this symbol
272      corresponds to.  */
273
274   struct general_symbol_info ginfo;
275
276   /* The info field is available for caching machine-specific information that
277      The AMD 29000 tdep.c uses it to remember things it has decoded from the
278      instructions in the function header, so it doesn't have to rederive the
279      info constantly (over a serial line).  It is initialized to zero and
280      stays that way until target-dependent code sets it.  Storage for any data
281      pointed to by this field should be allocated on the symbol_obstack for
282      the associated objfile.  The type would be "void *" except for reasons
283      of compatibility with older compilers.  This field is optional. */
284
285   char *info;
286
287 #ifdef SOFUN_ADDRESS_MAYBE_MISSING
288   /* Which source file is this symbol in?  Only relevant for mst_file_*.  */
289   char *filename;
290 #endif
291
292   /* Classification types for this symbol.  These should be taken as "advisory
293      only", since if gdb can't easily figure out a classification it simply
294      selects mst_unknown.  It may also have to guess when it can't figure out
295      which is a better match between two types (mst_data versus mst_bss) for
296      example.  Since the minimal symbol info is sometimes derived from the
297      BFD library's view of a file, we need to live with what information bfd
298      supplies. */
299
300   enum minimal_symbol_type
301     {
302       mst_unknown = 0,          /* Unknown type, the default */
303       mst_text,                 /* Generally executable instructions */
304       mst_data,                 /* Generally initialized data */
305       mst_bss,                  /* Generally uninitialized data */
306       mst_abs,                  /* Generally absolute (nonrelocatable) */
307       /* GDB uses mst_solib_trampoline for the start address of a shared
308          library trampoline entry.  Breakpoints for shared library functions
309          are put there if the shared library is not yet loaded.
310          After the shared library is loaded, lookup_minimal_symbol will
311          prefer the minimal symbol from the shared library (usually
312          a mst_text symbol) over the mst_solib_trampoline symbol, and the
313          breakpoints will be moved to their true address in the shared
314          library via breakpoint_re_set.  */
315       mst_solib_trampoline,     /* Shared library trampoline code */
316       /* For the mst_file* types, the names are only guaranteed to be unique
317          within a given .o file.  */
318       mst_file_text,            /* Static version of mst_text */
319       mst_file_data,            /* Static version of mst_data */
320       mst_file_bss              /* Static version of mst_bss */
321     } type BYTE_BITFIELD;
322
323 };
324
325 #define MSYMBOL_INFO(msymbol)           (msymbol)->info
326 #define MSYMBOL_TYPE(msymbol)           (msymbol)->type
327
328 \f
329 /* All of the name-scope contours of the program
330    are represented by `struct block' objects.
331    All of these objects are pointed to by the blockvector.
332
333    Each block represents one name scope.
334    Each lexical context has its own block.
335
336    The blockvector begins with some special blocks.
337    The GLOBAL_BLOCK contains all the symbols defined in this compilation
338    whose scope is the entire program linked together.
339    The STATIC_BLOCK contains all the symbols whose scope is the
340    entire compilation excluding other separate compilations.
341    Blocks starting with the FIRST_LOCAL_BLOCK are not special.
342
343    Each block records a range of core addresses for the code that
344    is in the scope of the block.  The STATIC_BLOCK and GLOBAL_BLOCK
345    give, for the range of code, the entire range of code produced
346    by the compilation that the symbol segment belongs to.
347
348    The blocks appear in the blockvector
349    in order of increasing starting-address,
350    and, within that, in order of decreasing ending-address.
351
352    This implies that within the body of one function
353    the blocks appear in the order of a depth-first tree walk.  */
354
355 struct blockvector
356 {
357   /* Number of blocks in the list.  */
358   int nblocks;
359   /* The blocks themselves.  */
360   struct block *block[1];
361 };
362
363 #define BLOCKVECTOR_NBLOCKS(blocklist) (blocklist)->nblocks
364 #define BLOCKVECTOR_BLOCK(blocklist,n) (blocklist)->block[n]
365
366 /* Special block numbers */
367
368 #define GLOBAL_BLOCK            0
369 #define STATIC_BLOCK            1
370 #define FIRST_LOCAL_BLOCK       2
371
372 struct block
373 {
374
375   /* Addresses in the executable code that are in this block.  */
376
377   CORE_ADDR startaddr;
378   CORE_ADDR endaddr;
379
380   /* The symbol that names this block, if the block is the body of a
381      function; otherwise, zero.  */
382
383   struct symbol *function;
384
385   /* The `struct block' for the containing block, or 0 if none.
386
387      The superblock of a top-level local block (i.e. a function in the
388      case of C) is the STATIC_BLOCK.  The superblock of the
389      STATIC_BLOCK is the GLOBAL_BLOCK.  */
390
391   struct block *superblock;
392
393   /* Version of GCC used to compile the function corresponding
394      to this block, or 0 if not compiled with GCC.  When possible,
395      GCC should be compatible with the native compiler, or if that
396      is not feasible, the differences should be fixed during symbol
397      reading.  As of 16 Apr 93, this flag is never used to distinguish
398      between gcc2 and the native compiler.
399
400      If there is no function corresponding to this block, this meaning
401      of this flag is undefined.  */
402
403   unsigned char gcc_compile_flag;
404
405   /* Number of local symbols.  */
406
407   int nsyms;
408
409   /* The symbols.  If some of them are arguments, then they must be
410      in the order in which we would like to print them.  */
411
412   struct symbol *sym[1];
413 };
414
415 #define BLOCK_START(bl)         (bl)->startaddr
416 #define BLOCK_END(bl)           (bl)->endaddr
417 #define BLOCK_NSYMS(bl)         (bl)->nsyms
418 #define BLOCK_SYM(bl, n)        (bl)->sym[n]
419 #define BLOCK_FUNCTION(bl)      (bl)->function
420 #define BLOCK_SUPERBLOCK(bl)    (bl)->superblock
421 #define BLOCK_GCC_COMPILED(bl)  (bl)->gcc_compile_flag
422
423 /* Nonzero if symbols of block BL should be sorted alphabetically.
424    Don't sort a block which corresponds to a function.  If we did the
425    sorting would have to preserve the order of the symbols for the
426    arguments.  */
427
428 #define BLOCK_SHOULD_SORT(bl) ((bl)->nsyms >= 40 && BLOCK_FUNCTION (bl) == NULL)
429
430 \f
431 /* Represent one symbol name; a variable, constant, function or typedef.  */
432
433 /* Different name spaces for symbols.  Looking up a symbol specifies a
434    namespace and ignores symbol definitions in other name spaces. */
435  
436 typedef enum 
437 {
438   /* UNDEF_NAMESPACE is used when a namespace has not been discovered or
439      none of the following apply.  This usually indicates an error either
440      in the symbol information or in gdb's handling of symbols. */
441
442   UNDEF_NAMESPACE,
443
444   /* VAR_NAMESPACE is the usual namespace.  In C, this contains variables,
445      function names, typedef names and enum type values. */
446
447   VAR_NAMESPACE,
448
449   /* STRUCT_NAMESPACE is used in C to hold struct, union and enum type names.
450      Thus, if `struct foo' is used in a C program, it produces a symbol named
451      `foo' in the STRUCT_NAMESPACE. */
452
453   STRUCT_NAMESPACE,
454
455   /* LABEL_NAMESPACE may be used for names of labels (for gotos);
456      currently it is not used and labels are not recorded at all.  */
457
458   LABEL_NAMESPACE
459 } namespace_enum;
460
461 /* An address-class says where to find the value of a symbol.  */
462
463 enum address_class
464 {
465   /* Not used; catches errors */
466
467   LOC_UNDEF,
468
469   /* Value is constant int SYMBOL_VALUE, host byteorder */
470
471   LOC_CONST,
472
473   /* Value is at fixed address SYMBOL_VALUE_ADDRESS */
474
475   LOC_STATIC,
476
477   /* Value is in register.  SYMBOL_VALUE is the register number.  */
478
479   LOC_REGISTER,
480
481   /* It's an argument; the value is at SYMBOL_VALUE offset in arglist.  */
482
483   LOC_ARG,
484
485   /* Value address is at SYMBOL_VALUE offset in arglist.  */
486
487   LOC_REF_ARG,
488
489   /* Value is in register number SYMBOL_VALUE.  Just like LOC_REGISTER
490      except this is an argument.  Probably the cleaner way to handle
491      this would be to separate address_class (which would include
492      separate ARG and LOCAL to deal with FRAME_ARGS_ADDRESS versus
493      FRAME_LOCALS_ADDRESS), and an is_argument flag.
494
495      For some symbol formats (stabs, for some compilers at least),
496      the compiler generates two symbols, an argument and a register.
497      In some cases we combine them to a single LOC_REGPARM in symbol
498      reading, but currently not for all cases (e.g. it's passed on the
499      stack and then loaded into a register).  */
500
501   LOC_REGPARM,
502
503   /* Value is in specified register.  Just like LOC_REGPARM except the
504      register holds the address of the argument instead of the argument
505      itself. This is currently used for the passing of structs and unions
506      on sparc and hppa.  It is also used for call by reference where the
507      address is in a register, at least by mipsread.c.  */
508
509   LOC_REGPARM_ADDR,
510
511   /* Value is a local variable at SYMBOL_VALUE offset in stack frame.  */
512
513   LOC_LOCAL,
514
515   /* Value not used; definition in SYMBOL_TYPE.  Symbols in the namespace
516      STRUCT_NAMESPACE all have this class.  */
517
518   LOC_TYPEDEF,
519
520   /* Value is address SYMBOL_VALUE_ADDRESS in the code */
521
522   LOC_LABEL,
523
524   /* In a symbol table, value is SYMBOL_BLOCK_VALUE of a `struct block'.
525      In a partial symbol table, SYMBOL_VALUE_ADDRESS is the start address
526      of the block.  Function names have this class. */
527
528   LOC_BLOCK,
529
530   /* Value is a constant byte-sequence pointed to by SYMBOL_VALUE_BYTES, in
531      target byte order.  */
532
533   LOC_CONST_BYTES,
534
535   /* Value is arg at SYMBOL_VALUE offset in stack frame. Differs from
536      LOC_LOCAL in that symbol is an argument; differs from LOC_ARG in
537      that we find it in the frame (FRAME_LOCALS_ADDRESS), not in the
538      arglist (FRAME_ARGS_ADDRESS).  Added for i960, which passes args
539      in regs then copies to frame.  */
540
541   LOC_LOCAL_ARG,
542
543   /* Value is at SYMBOL_VALUE offset from the current value of
544      register number SYMBOL_BASEREG.  This exists mainly for the same
545      things that LOC_LOCAL and LOC_ARG do; but we need to do this
546      instead because on 88k DWARF gives us the offset from the
547      frame/stack pointer, rather than the offset from the "canonical
548      frame address" used by COFF, stabs, etc., and we don't know how
549      to convert between these until we start examining prologues.
550
551      Note that LOC_BASEREG is much less general than a DWARF expression.
552      We don't need the generality (at least not yet), and storing a general
553      DWARF expression would presumably take up more space than the existing
554      scheme.  */
555
556   LOC_BASEREG,
557
558   /* Same as LOC_BASEREG but it is an argument.  */
559
560   LOC_BASEREG_ARG,
561
562   /* Value is at fixed address, but the address of the variable has
563      to be determined from the minimal symbol table whenever the
564      variable is referenced.
565      This happens if debugging information for a global symbol is
566      emitted and the corresponding minimal symbol is defined
567      in another object file or runtime common storage.
568      The linker might even remove the minimal symbol if the global
569      symbol is never referenced, in which case the symbol remains
570      unresolved.  */
571
572   LOC_UNRESOLVED,
573
574   /* The variable does not actually exist in the program.
575      The value is ignored.  */
576
577   LOC_OPTIMIZED_OUT
578 };
579
580 struct symbol
581 {
582
583   /* The general symbol info required for all types of symbols. */
584
585   struct general_symbol_info ginfo;
586
587   /* Data type of value */
588
589   struct type *type;
590
591   /* Name space code.  */
592
593   namespace_enum namespace BYTE_BITFIELD;
594
595   /* Address class */
596
597   enum address_class aclass BYTE_BITFIELD;
598
599   /* Line number of definition.  FIXME:  Should we really make the assumption
600      that nobody will try to debug files longer than 64K lines?  What about
601      machine generated programs? */
602
603   unsigned short line;
604   
605   /* Some symbols require an additional value to be recorded on a per-
606      symbol basis.  Stash those values here. */
607
608   union
609     {
610       /* Used by LOC_BASEREG and LOC_BASEREG_ARG.  */
611       short basereg;
612     }
613   aux_value;
614 };
615
616 #define SYMBOL_NAMESPACE(symbol)        (symbol)->namespace
617 #define SYMBOL_CLASS(symbol)            (symbol)->aclass
618 #define SYMBOL_TYPE(symbol)             (symbol)->type
619 #define SYMBOL_LINE(symbol)             (symbol)->line
620 #define SYMBOL_BASEREG(symbol)          (symbol)->aux_value.basereg
621 \f
622 /* A partial_symbol records the name, namespace, and address class of
623    symbols whose types we have not parsed yet.  For functions, it also
624    contains their memory address, so we can find them from a PC value.
625    Each partial_symbol sits in a partial_symtab, all of which are chained
626    on a  partial symtab list and which points to the corresponding 
627    normal symtab once the partial_symtab has been referenced.  */
628
629 struct partial_symbol
630 {
631
632   /* The general symbol info required for all types of symbols. */
633
634   struct general_symbol_info ginfo;
635
636   /* Name space code.  */
637
638   namespace_enum namespace BYTE_BITFIELD;
639
640   /* Address class (for info_symbols) */
641
642   enum address_class aclass BYTE_BITFIELD;
643
644 };
645
646 #define PSYMBOL_NAMESPACE(psymbol)      (psymbol)->namespace
647 #define PSYMBOL_CLASS(psymbol)          (psymbol)->aclass
648
649 \f
650 /* Source-file information.  This describes the relation between source files,
651    ine numbers and addresses in the program text.  */
652
653 struct sourcevector
654 {
655   int length;                   /* Number of source files described */
656   struct source *source[1];     /* Descriptions of the files */
657 };
658
659 /* Each item represents a line-->pc (or the reverse) mapping.  This is
660    somewhat more wasteful of space than one might wish, but since only
661    the files which are actually debugged are read in to core, we don't
662    waste much space.  */
663
664 struct linetable_entry
665 {
666   int line;
667   CORE_ADDR pc;
668 };
669
670 /* The order of entries in the linetable is significant.  They should
671    be sorted by increasing values of the pc field.  If there is more than
672    one entry for a given pc, then I'm not sure what should happen (and
673    I not sure whether we currently handle it the best way).
674
675    Example: a C for statement generally looks like this
676
677         10      0x100   - for the init/test part of a for stmt.
678         20      0x200
679         30      0x300
680         10      0x400   - for the increment part of a for stmt.
681
682    */
683
684 struct linetable
685 {
686   int nitems;
687
688   /* Actually NITEMS elements.  If you don't like this use of the
689      `struct hack', you can shove it up your ANSI (seriously, if the
690      committee tells us how to do it, we can probably go along).  */
691   struct linetable_entry item[1];
692 };
693
694 /* All the information on one source file.  */
695
696 struct source
697 {
698   char *name;                   /* Name of file */
699   struct linetable contents;
700 };
701
702 /* How to relocate the symbols from each section in a symbol file.
703    Each struct contains an array of offsets.
704    The ordering and meaning of the offsets is file-type-dependent;
705    typically it is indexed by section numbers or symbol types or
706    something like that.
707
708    To give us flexibility in changing the internal representation
709    of these offsets, the ANOFFSET macro must be used to insert and
710    extract offset values in the struct.  */
711
712 struct section_offsets
713   {
714     CORE_ADDR offsets[1];               /* As many as needed. */
715   };
716
717 #define ANOFFSET(secoff, whichone)      (secoff->offsets[whichone])
718
719 /* Each source file or header is represented by a struct symtab. 
720    These objects are chained through the `next' field.  */
721
722 struct symtab
723   {
724
725     /* Chain of all existing symtabs.  */
726
727     struct symtab *next;
728
729     /* List of all symbol scope blocks for this symtab.  May be shared
730        between different symtabs (and normally is for all the symtabs
731        in a given compilation unit).  */
732
733     struct blockvector *blockvector;
734
735     /* Table mapping core addresses to line numbers for this file.
736        Can be NULL if none.  Never shared between different symtabs.  */
737
738     struct linetable *linetable;
739
740     /* Section in objfile->section_offsets for the blockvector and
741        the linetable.  Probably always SECT_OFF_TEXT.  */
742
743     int block_line_section;
744
745     /* If several symtabs share a blockvector, exactly one of them
746        should be designed the primary, so that the blockvector
747        is relocated exactly once by objfile_relocate.  */
748
749     int primary;
750
751     /* Name of this source file.  */
752
753     char *filename;
754
755     /* Directory in which it was compiled, or NULL if we don't know.  */
756
757     char *dirname;
758
759     /* This component says how to free the data we point to:
760        free_contents => do a tree walk and free each object.
761        free_nothing => do nothing; some other symtab will free
762          the data this one uses.
763       free_linetable => free just the linetable.  FIXME: Is this redundant
764       with the primary field?  */
765
766     enum free_code
767       {
768         free_nothing, free_contents, free_linetable
769         }
770     free_code;
771
772     /* Pointer to one block of storage to be freed, if nonzero.  */
773     /* This is IN ADDITION to the action indicated by free_code.  */
774     
775     char *free_ptr;
776
777     /* Total number of lines found in source file.  */
778
779     int nlines;
780
781     /* line_charpos[N] is the position of the (N-1)th line of the
782        source file.  "position" means something we can lseek() to; it
783        is not guaranteed to be useful any other way.  */
784
785     int *line_charpos;
786
787     /* Language of this source file.  */
788
789     enum language language;
790
791     /* String of version information.  May be zero.  */
792
793     char *version;
794
795     /* Full name of file as found by searching the source path.
796        NULL if not yet known.  */
797
798     char *fullname;
799
800     /* Object file from which this symbol information was read.  */
801
802     struct objfile *objfile;
803
804     /* Anything extra for this symtab.  This is for target machines
805        with special debugging info of some sort (which cannot just
806        be represented in a normal symtab).  */
807
808 #if defined (EXTRA_SYMTAB_INFO)
809     EXTRA_SYMTAB_INFO
810 #endif
811
812   };
813
814 #define BLOCKVECTOR(symtab)     (symtab)->blockvector
815 #define LINETABLE(symtab)       (symtab)->linetable
816
817 \f
818 /* Each source file that has not been fully read in is represented by
819    a partial_symtab.  This contains the information on where in the
820    executable the debugging symbols for a specific file are, and a
821    list of names of global symbols which are located in this file.
822    They are all chained on partial symtab lists.
823
824    Even after the source file has been read into a symtab, the
825    partial_symtab remains around.  They are allocated on an obstack,
826    psymbol_obstack.  FIXME, this is bad for dynamic linking or VxWorks-
827    style execution of a bunch of .o's.  */
828
829 struct partial_symtab
830 {
831
832   /* Chain of all existing partial symtabs.  */
833
834   struct partial_symtab *next;
835
836   /* Name of the source file which this partial_symtab defines */
837
838   char *filename;
839
840   /* Information about the object file from which symbols should be read.  */
841
842   struct objfile *objfile;
843
844   /* Set of relocation offsets to apply to each section.  */ 
845
846   struct section_offsets *section_offsets;
847
848   /* Range of text addresses covered by this file; texthigh is the
849      beginning of the next section. */
850
851   CORE_ADDR textlow;
852   CORE_ADDR texthigh;
853
854   /* Array of pointers to all of the partial_symtab's which this one
855      depends on.  Since this array can only be set to previous or
856      the current (?) psymtab, this dependency tree is guaranteed not
857      to have any loops.  "depends on" means that symbols must be read
858      for the dependencies before being read for this psymtab; this is
859      for type references in stabs, where if foo.c includes foo.h, declarations
860      in foo.h may use type numbers defined in foo.c.  For other debugging
861      formats there may be no need to use dependencies.  */
862
863   struct partial_symtab **dependencies;
864
865   int number_of_dependencies;
866
867   /* Global symbol list.  This list will be sorted after readin to
868      improve access.  Binary search will be the usual method of
869      finding a symbol within it. globals_offset is an integer offset
870      within global_psymbols[].  */
871
872   int globals_offset;
873   int n_global_syms;
874
875   /* Static symbol list.  This list will *not* be sorted after readin;
876      to find a symbol in it, exhaustive search must be used.  This is
877      reasonable because searches through this list will eventually
878      lead to either the read in of a files symbols for real (assumed
879      to take a *lot* of time; check) or an error (and we don't care
880      how long errors take).  This is an offset and size within
881      static_psymbols[].  */
882
883   int statics_offset;
884   int n_static_syms;
885
886   /* Pointer to symtab eventually allocated for this source file, 0 if
887      !readin or if we haven't looked for the symtab after it was readin.  */
888
889   struct symtab *symtab;
890
891   /* Pointer to function which will read in the symtab corresponding to
892      this psymtab.  */
893
894   void (*read_symtab) PARAMS ((struct partial_symtab *));
895
896   /* Information that lets read_symtab() locate the part of the symbol table
897      that this psymtab corresponds to.  This information is private to the
898      format-dependent symbol reading routines.  For further detail examine
899      the various symbol reading modules.  Should really be (void *) but is
900      (char *) as with other such gdb variables.  (FIXME) */
901
902   char *read_symtab_private;
903
904   /* Non-zero if the symtab corresponding to this psymtab has been readin */
905
906   unsigned char readin;
907 };
908
909 /* A fast way to get from a psymtab to its symtab (after the first time).  */
910 #define PSYMTAB_TO_SYMTAB(pst)  \
911     ((pst) -> symtab != NULL ? (pst) -> symtab : psymtab_to_symtab (pst))
912
913 \f
914 /* The virtual function table is now an array of structures which have the
915    form { int16 offset, delta; void *pfn; }. 
916
917    In normal virtual function tables, OFFSET is unused.
918    DELTA is the amount which is added to the apparent object's base
919    address in order to point to the actual object to which the
920    virtual function should be applied.
921    PFN is a pointer to the virtual function.
922
923    Note that this macro is g++ specific (FIXME). */
924   
925 #define VTBL_FNADDR_OFFSET 2
926
927 /* Macro that yields non-zero value iff NAME is the prefix for C++ operator
928    names.  If you leave out the parenthesis here you will lose!
929    Currently 'o' 'p' CPLUS_MARKER is used for both the symbol in the
930    symbol-file and the names in gdb's symbol table.
931    Note that this macro is g++ specific (FIXME). */
932
933 #define OPNAME_PREFIX_P(NAME) \
934   ((NAME)[0] == 'o' && (NAME)[1] == 'p' && is_cplus_marker ((NAME)[2]))
935
936 /* Macro that yields non-zero value iff NAME is the prefix for C++ vtbl
937    names.  Note that this macro is g++ specific (FIXME).
938    '_vt$' is the old cfront-style vtables; '_VT$' is the new
939    style, using thunks (where '$' is really CPLUS_MARKER). */
940
941 #define VTBL_PREFIX_P(NAME) \
942   ((NAME)[0] == '_' \
943    && (((NAME)[1] == 'V' && (NAME)[2] == 'T') \
944        || ((NAME)[1] == 'v' && (NAME)[2] == 't')) \
945    && is_cplus_marker ((NAME)[3]))
946
947 /* Macro that yields non-zero value iff NAME is the prefix for C++ destructor
948    names.  Note that this macro is g++ specific (FIXME).  */
949
950 #define DESTRUCTOR_PREFIX_P(NAME) \
951   ((NAME)[0] == '_' && is_cplus_marker ((NAME)[1]) && (NAME)[2] == '_')
952
953 \f
954 /* External variables and functions for the objects described above. */
955
956 /* This symtab variable specifies the current file for printing source lines */
957
958 extern struct symtab *current_source_symtab;
959
960 /* This is the next line to print for listing source lines.  */
961
962 extern int current_source_line;
963
964 /* See the comment in symfile.c about how current_objfile is used. */
965
966 extern struct objfile *current_objfile;
967
968 /* True if we are nested inside psymtab_to_symtab. */
969
970 extern int currently_reading_symtab;
971
972 /* From utils.c.  */
973 extern int demangle;
974 extern int asm_demangle;
975
976 extern struct symtab *
977 lookup_symtab PARAMS ((char *));
978
979 extern struct symbol *
980 lookup_symbol PARAMS ((const char *, const struct block *,
981                        const namespace_enum, int *, struct symtab **));
982
983 extern struct symbol *
984 lookup_block_symbol PARAMS ((const struct block *, const char *,
985                              const namespace_enum));
986
987 extern struct type *
988 lookup_struct PARAMS ((char *, struct block *));
989
990 extern struct type *
991 lookup_union PARAMS ((char *, struct block *));
992
993 extern struct type *
994 lookup_enum PARAMS ((char *, struct block *));
995
996 extern struct symbol *
997 block_function PARAMS ((struct block *));
998
999 extern struct symbol *
1000 find_pc_function PARAMS ((CORE_ADDR));
1001
1002 extern int find_pc_partial_function
1003   PARAMS ((CORE_ADDR, char **, CORE_ADDR *, CORE_ADDR *));
1004
1005 extern void
1006 clear_pc_function_cache PARAMS ((void));
1007
1008 extern struct partial_symtab *
1009 lookup_partial_symtab PARAMS ((char *));
1010
1011 extern struct partial_symtab *
1012 find_pc_psymtab PARAMS ((CORE_ADDR));
1013
1014 extern struct symtab *
1015 find_pc_symtab PARAMS ((CORE_ADDR));
1016
1017 extern struct partial_symbol *
1018 find_pc_psymbol PARAMS ((struct partial_symtab *, CORE_ADDR));
1019
1020 extern int
1021 find_pc_line_pc_range PARAMS ((CORE_ADDR, CORE_ADDR *, CORE_ADDR *));
1022
1023 extern int
1024 contained_in PARAMS ((struct block *, struct block *));
1025
1026 extern void
1027 reread_symbols PARAMS ((void));
1028
1029 /* Macro for name of symbol to indicate a file compiled with gcc. */
1030 #ifndef GCC_COMPILED_FLAG_SYMBOL
1031 #define GCC_COMPILED_FLAG_SYMBOL "gcc_compiled."
1032 #endif
1033
1034 /* Macro for name of symbol to indicate a file compiled with gcc2. */
1035 #ifndef GCC2_COMPILED_FLAG_SYMBOL
1036 #define GCC2_COMPILED_FLAG_SYMBOL "gcc2_compiled."
1037 #endif
1038
1039 /* Functions for dealing with the minimal symbol table, really a misc
1040    address<->symbol mapping for things we don't have debug symbols for.  */
1041
1042 extern void prim_record_minimal_symbol PARAMS ((const char *, CORE_ADDR,
1043                                                 enum minimal_symbol_type,
1044                                                 struct objfile *));
1045
1046 extern struct minimal_symbol *prim_record_minimal_symbol_and_info
1047   PARAMS ((const char *, CORE_ADDR,
1048            enum minimal_symbol_type,
1049            char *info, int section,
1050            struct objfile *));
1051
1052 #ifdef SOFUN_ADDRESS_MAYBE_MISSING
1053 extern CORE_ADDR find_stab_function_addr PARAMS ((char *,
1054                                                   struct partial_symtab *,
1055                                                   struct objfile *));
1056 #endif
1057
1058 extern struct minimal_symbol *
1059 lookup_minimal_symbol PARAMS ((const char *, const char *, struct objfile *));
1060
1061 extern struct minimal_symbol *
1062 lookup_minimal_symbol_text PARAMS ((const char *, const char *, struct objfile *));
1063
1064 extern struct minimal_symbol *
1065 lookup_minimal_symbol_by_pc PARAMS ((CORE_ADDR));
1066
1067 extern struct minimal_symbol *
1068 lookup_solib_trampoline_symbol_by_pc PARAMS ((CORE_ADDR));
1069
1070 extern CORE_ADDR
1071 find_solib_trampoline_target PARAMS ((CORE_ADDR));
1072
1073 extern void
1074 init_minimal_symbol_collection PARAMS ((void));
1075
1076 extern void
1077 discard_minimal_symbols PARAMS ((int));
1078
1079 extern void
1080 install_minimal_symbols PARAMS ((struct objfile *));
1081
1082 /* Sort all the minimal symbols in OBJFILE.  */
1083
1084 extern void msymbols_sort PARAMS ((struct objfile *objfile));
1085
1086 struct symtab_and_line
1087 {
1088   struct symtab *symtab;
1089
1090   /* Line number.  Line numbers start at 1 and proceed through symtab->nlines.
1091      0 is never a valid line number; it is used to indicate that line number
1092      information is not available.  */
1093   int line;
1094
1095   CORE_ADDR pc;
1096   CORE_ADDR end;
1097 };
1098
1099 struct symtabs_and_lines
1100 {
1101   struct symtab_and_line *sals;
1102   int nelts;
1103 };
1104
1105 /* Given a pc value, return line number it is in.  Second arg nonzero means
1106    if pc is on the boundary use the previous statement's line number.  */
1107
1108 extern struct symtab_and_line
1109 find_pc_line PARAMS ((CORE_ADDR, int));
1110
1111 /* Given an address, return the nearest symbol at or below it in memory.
1112    Optionally return the symtab it's from through 2nd arg, and the
1113    address in inferior memory of the symbol through 3rd arg.  */
1114
1115 extern struct symbol *
1116 find_addr_symbol PARAMS ((CORE_ADDR, struct symtab **, CORE_ADDR *));
1117
1118 /* Given a symtab and line number, return the pc there.  */
1119
1120 extern CORE_ADDR
1121 find_line_pc PARAMS ((struct symtab *, int));
1122
1123 extern int 
1124 find_line_pc_range PARAMS ((struct symtab_and_line,
1125                             CORE_ADDR *, CORE_ADDR *));
1126
1127 extern void
1128 resolve_sal_pc PARAMS ((struct symtab_and_line *));
1129
1130 /* Given a string, return the line specified by it.  For commands like "list"
1131    and "breakpoint".  */
1132
1133 extern struct symtabs_and_lines
1134 decode_line_spec PARAMS ((char *, int));
1135
1136 extern struct symtabs_and_lines
1137 decode_line_spec_1 PARAMS ((char *, int));
1138
1139 extern struct symtabs_and_lines
1140 decode_line_1 PARAMS ((char **, int, struct symtab *, int, char ***));
1141
1142 /* Symmisc.c */
1143
1144 #if MAINTENANCE_CMDS
1145
1146 void
1147 maintenance_print_symbols PARAMS ((char *, int));
1148
1149 void
1150 maintenance_print_psymbols PARAMS ((char *, int));
1151
1152 void
1153 maintenance_print_msymbols PARAMS ((char *, int));
1154
1155 void
1156 maintenance_print_objfiles PARAMS ((char *, int));
1157
1158 void
1159 maintenance_check_symtabs PARAMS ((char *, int));
1160
1161 #endif
1162
1163 extern void
1164 free_symtab PARAMS ((struct symtab *));
1165
1166 /* Symbol-reading stuff in symfile.c and solib.c.  */
1167
1168 extern struct symtab *
1169 psymtab_to_symtab PARAMS ((struct partial_symtab *));
1170
1171 extern void
1172 clear_solib PARAMS ((void));
1173
1174 extern struct objfile *
1175 symbol_file_add PARAMS ((char *, int, CORE_ADDR, int, int, int));
1176
1177 /* source.c */
1178
1179 extern int
1180 identify_source_line PARAMS ((struct symtab *, int, int, CORE_ADDR));
1181
1182 extern void
1183 print_source_lines PARAMS ((struct symtab *, int, int, int));
1184
1185 extern void
1186 forget_cached_source_info PARAMS ((void));
1187
1188 extern void
1189 select_source_symtab PARAMS ((struct symtab *));
1190
1191 extern char **make_symbol_completion_list PARAMS ((char *, char *));
1192
1193 /* symtab.c */
1194
1195 extern struct partial_symtab *
1196 find_main_psymtab PARAMS ((void));
1197
1198 /* blockframe.c */
1199
1200 extern struct blockvector *
1201 blockvector_for_pc PARAMS ((CORE_ADDR, int *));
1202
1203 /* symfile.c */
1204
1205 extern void
1206 clear_symtab_users PARAMS ((void));
1207
1208 extern enum language
1209 deduce_language_from_filename PARAMS ((char *));
1210
1211 /* symtab.c */
1212
1213 extern int
1214 in_prologue PARAMS ((CORE_ADDR pc, CORE_ADDR func_start));
1215
1216 #endif /* !defined(SYMTAB_H) */