gdb/
[platform/upstream/binutils.git] / gdb / symfile.h
1 /* Definitions for reading symbol files into GDB.
2
3    Copyright (C) 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999,
4    2000, 2001, 2002, 2003, 2004, 2007, 2008, 2009, 2010, 2011
5    Free Software Foundation, Inc.
6
7    This file is part of GDB.
8
9    This program is free software; you can redistribute it and/or modify
10    it under the terms of the GNU General Public License as published by
11    the Free Software Foundation; either version 3 of the License, or
12    (at your option) any later version.
13
14    This program is distributed in the hope that it will be useful,
15    but WITHOUT ANY WARRANTY; without even the implied warranty of
16    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17    GNU General Public License for more details.
18
19    You should have received a copy of the GNU General Public License
20    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
21
22 #if !defined (SYMFILE_H)
23 #define SYMFILE_H
24
25 /* This file requires that you first include "bfd.h".  */
26 #include "symtab.h"
27
28 /* Opaque declarations.  */
29 struct target_section;
30 struct objfile;
31 struct obj_section;
32 struct obstack;
33 struct block;
34
35 /* Comparison function for symbol look ups.  */
36
37 typedef int (symbol_compare_ftype) (const char *string1,
38                                     const char *string2);
39
40 /* Partial symbols are stored in the psymbol_cache and pointers to
41    them are kept in a dynamically grown array that is obtained from
42    malloc and grown as necessary via realloc.  Each objfile typically
43    has two of these, one for global symbols and one for static
44    symbols.  Although this adds a level of indirection for storing or
45    accessing the partial symbols, it allows us to throw away duplicate
46    psymbols and set all pointers to the single saved instance.  */
47
48 struct psymbol_allocation_list
49 {
50
51   /* Pointer to beginning of dynamically allocated array of pointers
52      to partial symbols.  The array is dynamically expanded as
53      necessary to accommodate more pointers.  */
54
55   struct partial_symbol **list;
56
57   /* Pointer to next available slot in which to store a pointer to a
58      partial symbol.  */
59
60   struct partial_symbol **next;
61
62   /* Number of allocated pointer slots in current dynamic array (not
63      the number of bytes of storage).  The "next" pointer will always
64      point somewhere between list[0] and list[size], and when at
65      list[size] the array will be expanded on the next attempt to
66      store a pointer.  */
67
68   int size;
69 };
70
71 /* Define an array of addresses to accommodate non-contiguous dynamic
72    loading of modules.  This is for use when entering commands, so we
73    can keep track of the section names until we read the file and can
74    map them to bfd sections.  This structure is also used by solib.c
75    to communicate the section addresses in shared objects to
76    symbol_file_add ().  */
77
78 struct section_addr_info
79 {
80   /* The number of sections for which address information is
81      available.  */
82   size_t num_sections;
83   /* Sections whose names are file format dependent.  */
84   struct other_sections
85   {
86     CORE_ADDR addr;
87     char *name;
88
89     /* SECTINDEX must be valid for associated BFD if ADDR is not zero.  */
90     int sectindex;
91   } other[1];
92 };
93
94
95 /* A table listing the load segments in a symfile, and which segment
96    each BFD section belongs to.  */
97 struct symfile_segment_data
98 {
99   /* How many segments are present in this file.  If there are
100      two, the text segment is the first one and the data segment
101      is the second one.  */
102   int num_segments;
103
104   /* If NUM_SEGMENTS is greater than zero, the original base address
105      of each segment.  */
106   CORE_ADDR *segment_bases;
107
108   /* If NUM_SEGMENTS is greater than zero, the memory size of each
109      segment.  */
110   CORE_ADDR *segment_sizes;
111
112   /* If NUM_SEGMENTS is greater than zero, this is an array of entries
113      recording which segment contains each BFD section.
114      SEGMENT_INFO[I] is S+1 if the I'th BFD section belongs to segment
115      S, or zero if it is not in any segment.  */
116   int *segment_info;
117 };
118
119 /* The "quick" symbol functions exist so that symbol readers can
120    avoiding an initial read of all the symbols.  For example, symbol
121    readers might choose to use the "partial symbol table" utilities,
122    which is one implementation of the quick symbol functions.
123
124    The quick symbol functions are generally opaque: the underlying
125    representation is hidden from the caller.
126
127    In general, these functions should only look at whatever special
128    index the symbol reader creates -- looking through the symbol
129    tables themselves is handled by generic code.  If a function is
130    defined as returning a "symbol table", this means that the function
131    should only return a newly-created symbol table; it should not
132    examine pre-existing ones.
133
134    The exact list of functions here was determined in an ad hoc way
135    based on gdb's history.  */
136
137 struct quick_symbol_functions
138 {
139   /* Return true if this objfile has any "partial" symbols
140      available.  */
141   int (*has_symbols) (struct objfile *objfile);
142
143   /* Return the symbol table for the "last" file appearing in
144      OBJFILE.  */
145   struct symtab *(*find_last_source_symtab) (struct objfile *objfile);
146
147   /* Forget all cached full file names for OBJFILE.  */
148   void (*forget_cached_source_info) (struct objfile *objfile);
149
150   /* Look up the symbol table, in OBJFILE, of a source file named
151      NAME.  If there is no '/' in the name, a match after a '/' in the
152      symbol table's file name will also work.  FULL_PATH is the
153      absolute file name, and REAL_PATH is the same, run through
154      gdb_realpath.
155
156      If no such symbol table can be found, returns 0.
157
158      Otherwise, sets *RESULT to the symbol table and returns 1.  This
159      might return 1 and set *RESULT to NULL if the requested file is
160      an include file that does not have a symtab of its own.  */
161   int (*lookup_symtab) (struct objfile *objfile,
162                         const char *name,
163                         const char *full_path,
164                         const char *real_path,
165                         struct symtab **result);
166
167   /* Check to see if the symbol is defined in a "partial" symbol table
168      of OBJFILE.  KIND should be either GLOBAL_BLOCK or STATIC_BLOCK,
169      depending on whether we want to search global symbols or static
170      symbols.  NAME is the name of the symbol to look for.  DOMAIN
171      indicates what sort of symbol to search for.
172
173      Returns the newly-expanded symbol table in which the symbol is
174      defined, or NULL if no such symbol table exists.  */
175   struct symtab *(*lookup_symbol) (struct objfile *objfile,
176                                    int kind, const char *name,
177                                    domain_enum domain);
178
179   /* This is called to expand symbol tables before looking up a
180      symbol.  A backend can choose to implement this and then have its
181      `lookup_symbol' hook always return NULL, or the reverse.  (It
182      doesn't make sense to implement both.)  The arguments are as for
183      `lookup_symbol'.  */
184   void (*pre_expand_symtabs_matching) (struct objfile *objfile,
185                                        enum block_enum block_kind,
186                                        const char *name,
187                                        domain_enum domain);
188
189   /* Print statistics about any indices loaded for OBJFILE.  The
190      statistics should be printed to gdb_stdout.  This is used for
191      "maint print statistics".  */
192   void (*print_stats) (struct objfile *objfile);
193
194   /* Dump any indices loaded for OBJFILE.  The dump should go to
195      gdb_stdout.  This is used for "maint print objfiles".  */
196   void (*dump) (struct objfile *objfile);
197
198   /* This is called by objfile_relocate to relocate any indices loaded
199      for OBJFILE.  */
200   void (*relocate) (struct objfile *objfile,
201                     struct section_offsets *new_offsets,
202                     struct section_offsets *delta);
203
204   /* Find all the symbols in OBJFILE named FUNC_NAME, and ensure that
205      the corresponding symbol tables are loaded.  */
206   void (*expand_symtabs_for_function) (struct objfile *objfile,
207                                        const char *func_name);
208
209   /* Read all symbol tables associated with OBJFILE.  */
210   void (*expand_all_symtabs) (struct objfile *objfile);
211
212   /* Read all symbol tables associated with OBJFILE which have the
213      file name FILENAME.
214      This is for the purposes of examining code only, e.g., expand_line_sal.
215      The routine may ignore debug info that is known to not be useful with
216      code, e.g., DW_TAG_type_unit for dwarf debug info.  */
217   void (*expand_symtabs_with_filename) (struct objfile *objfile,
218                                         const char *filename);
219
220   /* Return the file name of the file holding the symbol in OBJFILE
221      named NAME.  If no such symbol exists in OBJFILE, return NULL.  */
222   const char *(*find_symbol_file) (struct objfile *objfile, const char *name);
223
224   /* Find global or static symbols in all tables that are in NAMESPACE 
225      and for which MATCH (symbol name, NAME) == 0, passing each to 
226      CALLBACK, reading in partial symbol symbol tables as needed.  Look
227      through global symbols if GLOBAL and otherwise static symbols.
228      Passes NAME, NAMESPACE, and DATA to CALLBACK with each symbol
229      found.  After each block is processed, passes NULL to CALLBACK.
230      MATCH must be weaker than strcmp_iw in the sense that
231      strcmp_iw(x,y) == 0 --> MATCH(x,y) == 0.  ORDERED_COMPARE, if
232      non-null, must be an ordering relation compatible with strcmp_iw
233      in the sense that  
234             strcmp(x,y) == 0 --> ORDERED_COMPARE(x,y) == 0 
235      and 
236             strcmp(x,y) <= 0 --> ORDERED_COMPARE(x,y) <= 0
237      (allowing strcmp(x,y) < 0 while ORDERED_COMPARE(x, y) == 0).
238      CALLBACK returns 0 to indicate that the scan should continue, or
239      non-zero to indicate that the scan should be terminated.  */
240
241   void (*map_matching_symbols) (const char *name, domain_enum namespace,
242                                 struct objfile *, int global,
243                                 int (*callback) (struct block *,
244                                                  struct symbol *, void *),
245                                 void *data,
246                                 symbol_compare_ftype *match,
247                                 symbol_compare_ftype *ordered_compare);
248
249   /* Expand all symbol tables in OBJFILE matching some criteria.
250
251      FILE_MATCHER is called for each file in OBJFILE.  The file name
252      and the DATA argument are passed to it.  If it returns zero, this
253      file is skipped.  If FILE_MATCHER is NULL such file is not skipped.
254
255      Otherwise, if KIND does not match this symbol is skipped.
256      
257      If even KIND matches, then NAME_MATCHER is called for each symbol defined
258      in the file.  The symbol's "natural" name and DATA are passed to
259      NAME_MATCHER.
260
261      If NAME_MATCHER returns zero, then this symbol is skipped.
262
263      Otherwise, this symbol's symbol table is expanded.
264
265      DATA is user data that is passed unmodified to the callback
266      functions.  */
267   void (*expand_symtabs_matching) (struct objfile *objfile,
268                                    int (*file_matcher) (const char *, void *),
269                                    int (*name_matcher) (const char *, void *),
270                                    enum search_domain kind,
271                                    void *data);
272
273   /* Return the symbol table from OBJFILE that contains PC and
274      SECTION.  Return NULL if there is no such symbol table.  This
275      should return the symbol table that contains a symbol whose
276      address exactly matches PC, or, if there is no exact match, the
277      symbol table that contains a symbol whose address is closest to
278      PC.  */
279   struct symtab *(*find_pc_sect_symtab) (struct objfile *objfile,
280                                          struct minimal_symbol *msymbol,
281                                          CORE_ADDR pc,
282                                          struct obj_section *section,
283                                          int warn_if_readin);
284
285   /* Call a callback for every file defined in OBJFILE whose symtab is
286      not already read in.  FUN is the callback.  It is passed the file's name,
287      the file's full name, and the DATA passed to this function.  */
288   void (*map_symbol_filenames) (struct objfile *objfile,
289                                 void (*fun) (const char *, const char *,
290                                              void *),
291                                 void *data);
292 };
293
294 /* Structure to keep track of symbol reading functions for various
295    object file types.  */
296
297 struct sym_fns
298 {
299
300   /* BFD flavour that we handle, or (as a special kludge, see
301      xcoffread.c, (enum bfd_flavour)-1 for xcoff).  */
302
303   enum bfd_flavour sym_flavour;
304
305   /* Initializes anything that is global to the entire symbol table.
306      It is called during symbol_file_add, when we begin debugging an
307      entirely new program.  */
308
309   void (*sym_new_init) (struct objfile *);
310
311   /* Reads any initial information from a symbol file, and initializes
312      the struct sym_fns SF in preparation for sym_read().  It is
313      called every time we read a symbol file for any reason.  */
314
315   void (*sym_init) (struct objfile *);
316
317   /* sym_read (objfile, symfile_flags) Reads a symbol file into a psymtab
318      (or possibly a symtab).  OBJFILE is the objfile struct for the
319      file we are reading.  SYMFILE_FLAGS are the flags passed to
320      symbol_file_add & co.  */
321
322   void (*sym_read) (struct objfile *, int);
323
324   /* Read the partial symbols for an objfile.  This may be NULL, in
325      which case gdb assumes that sym_read already read the partial
326      symbols.  This may only be non-NULL if the objfile actually does
327      have debuginfo available.  */
328
329   void (*sym_read_psymbols) (struct objfile *);
330
331   /* Called when we are finished with an objfile.  Should do all
332      cleanup that is specific to the object file format for the
333      particular objfile.  */
334
335   void (*sym_finish) (struct objfile *);
336
337   /* This function produces a file-dependent section_offsets
338      structure, allocated in the objfile's storage, and based on the
339      parameter.  The parameter is currently a CORE_ADDR (FIXME!) for
340      backward compatibility with the higher levels of GDB.  It should
341      probably be changed to a string, where NULL means the default,
342      and others are parsed in a file dependent way.  */
343
344   void (*sym_offsets) (struct objfile *, struct section_addr_info *);
345
346   /* This function produces a format-independent description of
347      the segments of ABFD.  Each segment is a unit of the file
348      which may be relocated independently.  */
349
350   struct symfile_segment_data *(*sym_segments) (bfd *abfd);
351
352   /* This function should read the linetable from the objfile when
353      the line table cannot be read while processing the debugging
354      information.  */
355
356   void (*sym_read_linetable) (void);
357
358   /* Relocate the contents of a debug section SECTP.  The
359      contents are stored in BUF if it is non-NULL, or returned in a
360      malloc'd buffer otherwise.  */
361
362   bfd_byte *(*sym_relocate) (struct objfile *, asection *sectp, bfd_byte *buf);
363
364   /* The "quick" (aka partial) symbol functions for this symbol
365      reader.  */
366   const struct quick_symbol_functions *qf;
367 };
368
369 extern struct section_addr_info *
370   build_section_addr_info_from_objfile (const struct objfile *objfile);
371
372 extern void relative_addr_info_to_section_offsets
373   (struct section_offsets *section_offsets, int num_sections,
374    struct section_addr_info *addrs);
375
376 extern void addr_info_make_relative (struct section_addr_info *addrs,
377                                      bfd *abfd);
378
379 /* The default version of sym_fns.sym_offsets for readers that don't
380    do anything special.  */
381
382 extern void default_symfile_offsets (struct objfile *objfile,
383                                      struct section_addr_info *);
384
385 /* The default version of sym_fns.sym_segments for readers that don't
386    do anything special.  */
387
388 extern struct symfile_segment_data *default_symfile_segments (bfd *abfd);
389
390 /* The default version of sym_fns.sym_relocate for readers that don't
391    do anything special.  */
392
393 extern bfd_byte *default_symfile_relocate (struct objfile *objfile,
394                                            asection *sectp, bfd_byte *buf);
395
396 extern struct symtab *allocate_symtab (const char *, struct objfile *);
397
398 extern void add_symtab_fns (const struct sym_fns *);
399
400 /* This enum encodes bit-flags passed as ADD_FLAGS parameter to
401    syms_from_objfile, symbol_file_add, etc.  */
402
403 enum symfile_add_flags
404   {
405     /* Be chatty about what you are doing.  */
406     SYMFILE_VERBOSE = 1 << 1,
407
408     /* This is the main symbol file (as opposed to symbol file for dynamically
409        loaded code).  */
410     SYMFILE_MAINLINE = 1 << 2,
411
412     /* Do not call breakpoint_re_set when adding this symbol file.  */
413     SYMFILE_DEFER_BP_RESET = 1 << 3,
414
415     /* Do not immediately read symbols for this file.  By default,
416        symbols are read when the objfile is created.  */
417     SYMFILE_NO_READ = 1 << 4
418   };
419
420 extern void syms_from_objfile (struct objfile *,
421                                struct section_addr_info *,
422                                struct section_offsets *, int, int);
423
424 extern void new_symfile_objfile (struct objfile *, int);
425
426 extern struct objfile *symbol_file_add (char *, int,
427                                         struct section_addr_info *, int);
428
429 extern struct objfile *symbol_file_add_from_bfd (bfd *, int,
430                                                  struct section_addr_info *,
431                                                  int, struct objfile *parent);
432
433 extern void symbol_file_add_separate (bfd *, int, struct objfile *);
434
435 extern char *find_separate_debug_file_by_debuglink (struct objfile *);
436
437 /* Create a new section_addr_info, with room for NUM_SECTIONS.  */
438
439 extern struct section_addr_info *alloc_section_addr_info (size_t
440                                                           num_sections);
441
442 /* Build (allocate and populate) a section_addr_info struct from an
443    existing section table.  */
444
445 extern struct section_addr_info
446   *build_section_addr_info_from_section_table (const struct target_section
447                                                *start,
448                                                const struct target_section
449                                                *end);
450
451 /* Free all memory allocated by
452    build_section_addr_info_from_section_table.  */
453
454 extern void free_section_addr_info (struct section_addr_info *);
455
456
457 /* Make a copy of the string at PTR with SIZE characters in the symbol
458    obstack (and add a null character at the end in the copy).  Returns
459    the address of the copy.  */
460
461 extern char *obsavestring (const char *, int, struct obstack *);
462
463 /* Concatenate NULL terminated variable argument list of `const char
464    *' strings; return the new string.  Space is found in the OBSTACKP.
465    Argument list must be terminated by a sentinel expression `(char *)
466    NULL'.  */
467
468 extern char *obconcat (struct obstack *obstackp, ...) ATTRIBUTE_SENTINEL;
469
470                         /*   Variables   */
471
472 /* If non-zero, shared library symbols will be added automatically
473    when the inferior is created, new libraries are loaded, or when
474    attaching to the inferior.  This is almost always what users will
475    want to have happen; but for very large programs, the startup time
476    will be excessive, and so if this is a problem, the user can clear
477    this flag and then add the shared library symbols as needed.  Note
478    that there is a potential for confusion, since if the shared
479    library symbols are not loaded, commands like "info fun" will *not*
480    report all the functions that are actually present.  */
481
482 extern int auto_solib_add;
483
484 /* From symfile.c */
485
486 extern void set_initial_language (void);
487
488 extern void find_lowest_section (bfd *, asection *, void *);
489
490 extern bfd *symfile_bfd_open (char *);
491
492 extern bfd *bfd_open_maybe_remote (const char *);
493
494 extern int get_section_index (struct objfile *, char *);
495
496 /* Utility functions for overlay sections: */
497 extern enum overlay_debugging_state
498 {
499   ovly_off,
500   ovly_on,
501   ovly_auto
502 } overlay_debugging;
503 extern int overlay_cache_invalid;
504
505 /* Return the "mapped" overlay section containing the PC.  */
506 extern struct obj_section *find_pc_mapped_section (CORE_ADDR);
507
508 /* Return any overlay section containing the PC (even in its LMA
509    region).  */
510 extern struct obj_section *find_pc_overlay (CORE_ADDR);
511
512 /* Return true if the section is an overlay.  */
513 extern int section_is_overlay (struct obj_section *);
514
515 /* Return true if the overlay section is currently "mapped".  */
516 extern int section_is_mapped (struct obj_section *);
517
518 /* Return true if pc belongs to section's VMA.  */
519 extern CORE_ADDR pc_in_mapped_range (CORE_ADDR, struct obj_section *);
520
521 /* Return true if pc belongs to section's LMA.  */
522 extern CORE_ADDR pc_in_unmapped_range (CORE_ADDR, struct obj_section *);
523
524 /* Map an address from a section's LMA to its VMA.  */
525 extern CORE_ADDR overlay_mapped_address (CORE_ADDR, struct obj_section *);
526
527 /* Map an address from a section's VMA to its LMA.  */
528 extern CORE_ADDR overlay_unmapped_address (CORE_ADDR, struct obj_section *);
529
530 /* Convert an address in an overlay section (force into VMA range).  */
531 extern CORE_ADDR symbol_overlayed_address (CORE_ADDR, struct obj_section *);
532
533 /* Load symbols from a file.  */
534 extern void symbol_file_add_main (char *args, int from_tty);
535
536 /* Clear GDB symbol tables.  */
537 extern void symbol_file_clear (int from_tty);
538
539 /* Default overlay update function.  */
540 extern void simple_overlay_update (struct obj_section *);
541
542 extern bfd_byte *symfile_relocate_debug_section (struct objfile *, asection *,
543                                                  bfd_byte *);
544
545 extern int symfile_map_offsets_to_segments (bfd *,
546                                             struct symfile_segment_data *,
547                                             struct section_offsets *,
548                                             int, const CORE_ADDR *);
549 struct symfile_segment_data *get_symfile_segment_data (bfd *abfd);
550 void free_symfile_segment_data (struct symfile_segment_data *data);
551
552 extern struct cleanup *increment_reading_symtab (void);
553
554 /* From dwarf2read.c */
555
556 extern int dwarf2_has_info (struct objfile *);
557
558 extern int dwarf2_initialize_objfile (struct objfile *);
559 extern void dwarf2_build_psymtabs (struct objfile *);
560 extern void dwarf2_build_frame_info (struct objfile *);
561
562 void dwarf2_free_objfile (struct objfile *);
563
564 /* From mdebugread.c */
565
566 /* Hack to force structures to exist before use in parameter list.  */
567 struct ecoff_debug_hack
568 {
569   struct ecoff_debug_swap *a;
570   struct ecoff_debug_info *b;
571 };
572
573 extern void mdebug_build_psymtabs (struct objfile *,
574                                    const struct ecoff_debug_swap *,
575                                    struct ecoff_debug_info *);
576
577 extern void elfmdebug_build_psymtabs (struct objfile *,
578                                       const struct ecoff_debug_swap *,
579                                       asection *);
580
581 #endif /* !defined(SYMFILE_H) */