1 /* Read hp debug symbols and convert to internal format, for GDB.
2 Copyright 1993, 1996, 1998, 1999 Free Software Foundation, Inc.
4 This file is part of GDB.
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.
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.
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.
20 Written by the Center for Software Science at the University of Utah
21 and by Cygnus Support. */
23 /* Common include file for hp_symtab_read.c and hp_psymtab_read.c.
24 This has nested includes of a bunch of stuff. */
28 /* To generate dumping code, uncomment this define. The dumping
29 itself is controlled by routine-local statics called "dumping". */
30 /* #define DUMPING 1 */
32 /* To use the quick look-up tables, uncomment this define. */
33 #define QUICK_LOOK_UP 1
35 /* To call PXDB to process un-processed files, uncomment this define. */
38 /* Forward procedure declarations */
40 void hpread_symfile_init
41 PARAMS ((struct objfile *));
44 do_pxdb PARAMS ((bfd *));
46 void hpread_build_psymtabs
47 PARAMS ((struct objfile *, struct section_offsets *, int));
49 void hpread_symfile_finish
50 PARAMS ((struct objfile *));
52 static union dnttentry *hpread_get_gntt
53 PARAMS ((int, struct objfile *));
55 static unsigned long hpread_get_textlow
56 PARAMS ((int, int, struct objfile *, int));
58 static struct partial_symtab *hpread_start_psymtab
59 PARAMS ((struct objfile *, struct section_offsets *, char *, CORE_ADDR, int,
60 struct partial_symbol **, struct partial_symbol **));
62 static struct partial_symtab *hpread_end_psymtab
63 PARAMS ((struct partial_symtab *, char **, int, int, CORE_ADDR,
64 struct partial_symtab **, int));
66 /* End of forward routine declarations */
70 /* NOTE use of system files! May not be portable. */
72 #define PXDB_SVR4 "/opt/langtools/bin/pxdb"
73 #define PXDB_BSD "/usr/bin/pxdb"
79 /* check for the existance of a file, given its full pathname */
81 file_exists (filename)
85 return (access (filename, F_OK) == 0);
90 /* Translate from the "hp_language" enumeration in hp-symtab.h
91 used in the debug info to gdb's generic enumeration in defs.h. */
94 enum hp_language in_lang;
96 if (in_lang == HP_LANGUAGE_C)
99 else if (in_lang == HP_LANGUAGE_CPLUSPLUS)
100 return language_cplus;
102 else if (in_lang == HP_LANGUAGE_F77)
103 return language_fortran;
106 return language_unknown;
109 static char main_string[] = "main";
111 /* Call PXDB to process our file.
113 Approach copied from DDE's "dbgk_run_pxdb". Note: we
114 don't check for BSD location of pxdb, nor for existance
117 NOTE: uses system function and string functions directly.
119 Return value: 1 if ok, 0 if not */
121 hpread_call_pxdb (file_name)
128 if (file_exists (PXDB_SVR4))
130 p = malloc (strlen (PXDB_SVR4) + strlen (file_name) + 2);
131 strcpy (p, PXDB_SVR4);
133 strcat (p, file_name);
135 warning ("File not processed by pxdb--about to process now.\n");
138 retval = (status == 0);
142 warning ("pxdb not found at standard location: /opt/langtools/bin\ngdb will not be able to debug %s.\nPlease install pxdb at the above location and then restart gdb.\nYou can also run pxdb on %s with the command\n\"pxdb %s\" and then restart gdb.", file_name, file_name, file_name);
147 } /* hpread_call_pxdb */
150 /* Return 1 if the file turns out to need pre-processing
151 by PXDB, and we have thus called PXDB to do this processing
152 and the file therefore needs to be re-loaded. Otherwise
155 hpread_pxdb_needed (sym_bfd)
158 asection *pinfo_section, *debug_section, *header_section;
159 unsigned int do_pxdb;
161 bfd_size_type header_section_size;
166 header_section = bfd_get_section_by_name (sym_bfd, "$HEADER$");
169 return 0; /* No header at all, can't recover... */
172 debug_section = bfd_get_section_by_name (sym_bfd, "$DEBUG$");
173 pinfo_section = bfd_get_section_by_name (sym_bfd, "$PINFO$");
175 if (pinfo_section && !debug_section)
177 /* Debug info with DOC, has different header format.
178 this only happens if the file was pxdbed and compiled optimized
179 otherwise the PINFO section is not there. */
180 header_section_size = bfd_section_size (objfile->obfd, header_section);
182 if (header_section_size == (bfd_size_type) sizeof (DOC_info_PXDB_header))
184 buf = alloca (sizeof (DOC_info_PXDB_header));
186 if (!bfd_get_section_contents (sym_bfd,
189 header_section_size))
190 error ("bfd_get_section_contents\n");
192 tmp = bfd_get_32 (sym_bfd, (bfd_byte *) (buf + sizeof (int) * 4));
193 pxdbed = (tmp >> 31) & 0x1;
196 error ("file debug header info invalid\n");
201 error ("invalid $HEADER$ size in executable \n");
207 /* this can be three different cases:
208 1. pxdbed and not doc
209 - DEBUG and HEADER sections are there
210 - header is PXDB_header type
211 - pxdbed flag is set to 1
213 2. not pxdbed and doc
214 - DEBUG and HEADER sections are there
215 - header is DOC_info_header type
216 - pxdbed flag is set to 0
218 3. not pxdbed and not doc
219 - DEBUG and HEADER sections are there
220 - header is XDB_header type
221 - pxdbed flag is set to 0
223 NOTE: the pxdbed flag is meaningful also in the not
224 already pxdb processed version of the header,
225 because in case on non-already processed by pxdb files
226 that same bit in the header would be always zero.
227 Why? Because the bit is the leftmost bit of a word
228 which contains a 'length' which is always a positive value
229 so that bit is never set to 1 (otherwise it would be negative)
231 Given the above, we have two choices : either we ignore the
232 size of the header itself and just look at the pxdbed field,
233 or we check the size and then we (for safety and paranoia related
234 issues) check the bit.
235 The first solution is used by DDE, the second by PXDB itself.
236 I am using the second one here, because I already wrote it,
237 and it is the end of a long day.
238 Also, using the first approach would still involve size issues
239 because we need to read in the contents of the header section, and
240 give the correct amount of stuff we want to read to the
241 get_bfd_section_contents function. */
243 /* decide which case depending on the size of the header section.
244 The size is as defined in hp-symtab.h */
246 header_section_size = bfd_section_size (objfile->obfd, header_section);
248 if (header_section_size == (bfd_size_type) sizeof (PXDB_header)) /* pxdb and not doc */
251 buf = alloca (sizeof (PXDB_header));
252 if (!bfd_get_section_contents (sym_bfd,
255 header_section_size))
256 error ("bfd_get_section_contents\n");
258 tmp = bfd_get_32 (sym_bfd, (bfd_byte *) (buf + sizeof (int) * 3));
259 pxdbed = (tmp >> 31) & 0x1;
264 error ("file debug header invalid\n");
266 else /*not pxdbed and doc OR not pxdbed and non doc */
278 } /* hpread_pxdb_needed */
282 /* Check whether the file needs to be preprocessed by pxdb.
289 /* The following code is HP-specific. The "right" way of
290 doing this is unknown, but we bet would involve a target-
291 specific pre-file-load check using a generic mechanism. */
293 /* This code will not be executed if the file is not in SOM
294 format (i.e. if compiled with gcc) */
295 if (hpread_pxdb_needed (sym_bfd))
297 /*This file has not been pre-processed. Preprocess now */
299 if (hpread_call_pxdb (sym_bfd->filename))
301 /* The call above has changed the on-disk file,
302 we can close the file anyway, because the
303 symbols will be reread in when the target is run */
313 /* Code to handle quick lookup-tables follows. */
316 /* Some useful macros */
317 #define VALID_FILE(i) ((i) < pxdb_header_p->fd_entries)
318 #define VALID_MODULE(i) ((i) < pxdb_header_p->md_entries)
319 #define VALID_PROC(i) ((i) < pxdb_header_p->pd_entries)
320 #define VALID_CLASS(i) ((i) < pxdb_header_p->cd_entries)
322 #define FILE_START(i) (qFD[i].adrStart)
323 #define MODULE_START(i) (qMD[i].adrStart)
324 #define PROC_START(i) (qPD[i].adrStart)
326 #define FILE_END(i) (qFD[i].adrEnd)
327 #define MODULE_END(i) (qMD[i].adrEnd)
328 #define PROC_END(i) (qPD[i].adrEnd)
330 #define FILE_ISYM(i) (qFD[i].isym)
331 #define MODULE_ISYM(i) (qMD[i].isym)
332 #define PROC_ISYM(i) (qPD[i].isym)
334 #define VALID_CURR_FILE (curr_fd < pxdb_header_p->fd_entries)
335 #define VALID_CURR_MODULE (curr_md < pxdb_header_p->md_entries)
336 #define VALID_CURR_PROC (curr_pd < pxdb_header_p->pd_entries)
337 #define VALID_CURR_CLASS (curr_cd < pxdb_header_p->cd_entries)
339 #define CURR_FILE_START (qFD[curr_fd].adrStart)
340 #define CURR_MODULE_START (qMD[curr_md].adrStart)
341 #define CURR_PROC_START (qPD[curr_pd].adrStart)
343 #define CURR_FILE_END (qFD[curr_fd].adrEnd)
344 #define CURR_MODULE_END (qMD[curr_md].adrEnd)
345 #define CURR_PROC_END (qPD[curr_pd].adrEnd)
347 #define CURR_FILE_ISYM (qFD[curr_fd].isym)
348 #define CURR_MODULE_ISYM (qMD[curr_md].isym)
349 #define CURR_PROC_ISYM (qPD[curr_pd].isym)
351 #define TELL_OBJFILE \
353 if( !told_objfile ) { \
355 warning ("\nIn object file \"%s\":\n", \
362 /* Keeping track of the start/end symbol table (LNTT) indices of
363 psymtabs created so far */
372 static pst_syms_struct *pst_syms_array = 0;
374 static pst_syms_count = 0;
375 static pst_syms_size = 0;
377 /* used by the TELL_OBJFILE macro */
378 static boolean told_objfile = 0;
380 /* Set up psymtab symbol index stuff */
386 pst_syms_array = (pst_syms_struct *) xmalloc (20 * sizeof (pst_syms_struct));
389 /* Clean up psymtab symbol index stuff */
395 free (pst_syms_array);
399 /* Add information about latest psymtab to symbol index table */
401 record_pst_syms (start_sym, end_sym)
405 if (++pst_syms_count > pst_syms_size)
407 pst_syms_array = (pst_syms_struct *) xrealloc (pst_syms_array,
408 2 * pst_syms_size * sizeof (pst_syms_struct));
411 pst_syms_array[pst_syms_count - 1].start = start_sym;
412 pst_syms_array[pst_syms_count - 1].end = end_sym;
415 /* Find a suitable symbol table index which can serve as the upper
416 bound of a psymtab that starts at INDEX
418 This scans backwards in the psymtab symbol index table to find a
419 "hole" in which the given index can fit. This is a heuristic!!
420 We don't search the entire table to check for multiple holes,
421 we don't care about overlaps, etc.
423 Return 0 => not found */
425 find_next_pst_start (index)
430 for (i = pst_syms_count - 1; i >= 0; i--)
431 if (pst_syms_array[i].end <= index)
432 return (i == pst_syms_count - 1) ? 0 : pst_syms_array[i + 1].start - 1;
434 if (pst_syms_array[0].start > index)
435 return pst_syms_array[0].start - 1;
442 /* Utility functions to find the ending symbol index for a psymtab */
444 /* Find the next file entry that begins beyond INDEX, and return
445 its starting symbol index - 1.
446 QFD is the file table, CURR_FD is the file entry from where to start,
447 PXDB_HEADER_P as in hpread_quick_traverse (to allow macros to work).
449 Return 0 => not found */
451 find_next_file_isym (index, qFD, curr_fd, pxdb_header_p)
453 quick_file_entry *qFD;
455 PXDB_header_ptr pxdb_header_p;
457 while (VALID_CURR_FILE)
459 if (CURR_FILE_ISYM >= index)
460 return CURR_FILE_ISYM - 1;
466 /* Find the next procedure entry that begins beyond INDEX, and return
467 its starting symbol index - 1.
468 QPD is the procedure table, CURR_PD is the proc entry from where to start,
469 PXDB_HEADER_P as in hpread_quick_traverse (to allow macros to work).
471 Return 0 => not found */
473 find_next_proc_isym (index, qPD, curr_pd, pxdb_header_p)
475 quick_procedure_entry *qPD;
477 PXDB_header_ptr pxdb_header_p;
479 while (VALID_CURR_PROC)
481 if (CURR_PROC_ISYM >= index)
482 return CURR_PROC_ISYM - 1;
488 /* Find the next module entry that begins beyond INDEX, and return
489 its starting symbol index - 1.
490 QMD is the module table, CURR_MD is the modue entry from where to start,
491 PXDB_HEADER_P as in hpread_quick_traverse (to allow macros to work).
493 Return 0 => not found */
495 find_next_module_isym (index, qMD, curr_md, pxdb_header_p)
497 quick_module_entry *qMD;
499 PXDB_header_ptr pxdb_header_p;
501 while (VALID_CURR_MODULE)
503 if (CURR_MODULE_ISYM >= index)
504 return CURR_MODULE_ISYM - 1;
510 /* Scan and record partial symbols for all functions starting from index
511 pointed to by CURR_PD_P, and between code addresses START_ADR and END_ADR.
512 Other parameters are explained in comments below. */
514 /* This used to be inline in hpread_quick_traverse, but now that we do essentially the
515 same thing for two different cases (modules and module-less files), it's better
516 organized in a separate routine, although it does take lots of arguments. pai/1997-10-08 */
519 scan_procs (curr_pd_p, qPD, max_procs, start_adr, end_adr, pst, vt_bits, objfile, section_offsets)
520 int *curr_pd_p; /* pointer to current proc index */
521 quick_procedure_entry *qPD; /* the procedure quick lookup table */
522 int max_procs; /* number of entries in proc. table */
523 CORE_ADDR start_adr; /* beginning of code range for current psymtab */
524 CORE_ADDR end_adr; /* end of code range for current psymtab */
525 struct partial_symtab *pst; /* current psymtab */
526 char *vt_bits; /* strings table of SOM debug space */
527 struct objfile *objfile; /* current object file */
528 struct section_offsets *section_offsets; /* not really used for HP-UX currently */
530 union dnttentry *dn_bufp;
531 int symbol_count = 0; /* Total number of symbols in this psymtab */
532 int curr_pd = *curr_pd_p; /* Convenience variable -- avoid dereferencing pointer all the time */
535 /* Turn this on for lots of debugging information in this routine */
536 static int dumping = 0;
542 printf ("Scan_procs called, addresses %x to %x, proc %x\n", start_adr, end_adr, curr_pd);
546 while ((CURR_PROC_START <= end_adr) && (curr_pd < max_procs))
549 char *rtn_name; /* mangled name */
550 char *rtn_dem_name; /* qualified demangled name */
554 if ((trans_lang ((enum hp_language) qPD[curr_pd].language) == language_cplus) &&
555 vt_bits[(long) qPD[curr_pd].sbAlias]) /* not a null string */
557 /* Get mangled name for the procedure, and demangle it */
558 rtn_name = &vt_bits[(long) qPD[curr_pd].sbAlias];
559 rtn_dem_name = cplus_demangle (rtn_name, DMGL_ANSI | DMGL_PARAMS);
563 rtn_name = &vt_bits[(long) qPD[curr_pd].sbProc];
567 /* Hack to get around HP C/C++ compilers' insistence on providing
568 "_MAIN_" as an alternate name for "main" */
569 if ((strcmp (rtn_name, "_MAIN_") == 0) &&
570 (strcmp (&vt_bits[(long) qPD[curr_pd].sbProc], "main") == 0))
571 rtn_dem_name = rtn_name = main_string;
576 printf ("..add %s (demangled %s), index %x to this psymtab\n", rtn_name, rtn_dem_name, curr_pd);
580 /* Check for module-spanning routines. */
581 if (CURR_PROC_END > end_adr)
584 warning ("Procedure \"%s\" [0x%x] spans file or module boundaries.", rtn_name, curr_pd);
587 /* Add this routine symbol to the list in the objfile.
588 Unfortunately we have to go to the LNTT to determine the
589 correct list to put it on. An alternative (which the
590 code used to do) would be to not check and always throw
591 it on the "static" list. But if we go that route, then
592 symbol_lookup() needs to be tweaked a bit to account
593 for the fact that the function might not be found on
594 the correct list in the psymtab. - RT */
595 dn_bufp = hpread_get_lntt (qPD[curr_pd].isym, objfile);
596 if (dn_bufp->dfunc.global)
597 add_psymbol_with_dem_name_to_list (rtn_name,
600 strlen (rtn_dem_name),
602 LOC_BLOCK, /* "I am a routine" */
603 &objfile->global_psymbols,
604 (qPD[curr_pd].adrStart + /* Starting address of rtn */
605 ANOFFSET (section_offsets, SECT_OFF_TEXT)),
607 trans_lang ((enum hp_language) qPD[curr_pd].language),
610 add_psymbol_with_dem_name_to_list (rtn_name,
613 strlen (rtn_dem_name),
615 LOC_BLOCK, /* "I am a routine" */
616 &objfile->static_psymbols,
617 (qPD[curr_pd].adrStart + /* Starting address of rtn */
618 ANOFFSET (section_offsets, SECT_OFF_TEXT)),
620 trans_lang ((enum hp_language) qPD[curr_pd].language),
624 *curr_pd_p = ++curr_pd; /* bump up count & reflect in caller */
625 } /* loop over procedures */
630 if (symbol_count == 0)
631 printf ("Scan_procs: no symbols found!\n");
639 /* Traverse the quick look-up tables, building a set of psymtabs.
641 This constructs a psymtab for modules and files in the quick lookup
644 Mostly, modules correspond to compilation units, so we try to
645 create psymtabs that correspond to modules; however, in some cases
646 a file can result in a compiled object which does not have a module
647 entry for it, so in such cases we create a psymtab for the file. */
650 hpread_quick_traverse (objfile, section_offsets, gntt_bits, vt_bits, pxdb_header_p)
651 struct objfile *objfile; /* The object file descriptor */
652 struct section_offsets *section_offsets; /* ?? Null for HP */
653 char *gntt_bits; /* GNTT entries, loaded in from the file */
654 char *vt_bits; /* VT (string) entries ditto. */
655 PXDB_header_ptr pxdb_header_p; /* Pointer to pxdb header ditto */
657 struct partial_symtab *pst;
661 quick_procedure_entry *qPD;
662 quick_file_entry *qFD;
663 quick_module_entry *qMD;
664 quick_class_entry *qCD;
668 CORE_ADDR start_adr; /* current psymtab's starting code addr */
669 CORE_ADDR end_adr; /* current psymtab's ending code addr */
670 CORE_ADDR next_mod_adr; /* next module's starting code addr */
671 int curr_pd; /* current procedure */
672 int curr_fd; /* current file */
673 int curr_md; /* current module */
674 int start_sym; /* current psymtab's starting symbol index */
675 int end_sym; /* current psymtab's ending symbol index */
676 int max_LNTT_sym_index;
678 B_TYPE *class_entered;
680 struct partial_symbol **global_syms; /* We'll be filling in the "global" */
681 struct partial_symbol **static_syms; /* and "static" tables in the objfile
682 as we go, so we need a pair of
686 /* Turn this on for lots of debugging information in this routine.
687 You get a blow-by-blow account of quick lookup table reading */
688 static int dumping = 0;
691 pst = (struct partial_symtab *) 0;
693 /* Clear out some globals */
697 /* Demangling style -- if EDG style already set, don't change it,
698 as HP style causes some problems with the KAI EDG compiler */
699 if (current_demangling_style != edg_demangling)
701 /* Otherwise, ensure that we are using HP style demangling */
702 set_demangling_style (HP_DEMANGLING_STYLE_STRING);
705 /* First we need to find the starting points of the quick
706 look-up tables in the GNTT. */
710 qPD = (quick_procedure_entry_ptr) addr;
711 addr += pxdb_header_p->pd_entries * sizeof (quick_procedure_entry);
716 printf ("\n Printing routines as we see them\n");
717 for (i = 0; VALID_PROC (i); i++)
719 idx = (long) qPD[i].sbProc;
720 printf ("%s %x..%x\n", &vt_bits[idx],
721 (int) PROC_START (i),
727 qFD = (quick_file_entry_ptr) addr;
728 addr += pxdb_header_p->fd_entries * sizeof (quick_file_entry);
733 printf ("\n Printing files as we see them\n");
734 for (i = 0; VALID_FILE (i); i++)
736 idx = (long) qFD[i].sbFile;
737 printf ("%s %x..%x\n", &vt_bits[idx],
738 (int) FILE_START (i),
744 qMD = (quick_module_entry_ptr) addr;
745 addr += pxdb_header_p->md_entries * sizeof (quick_module_entry);
750 printf ("\n Printing modules as we see them\n");
751 for (i = 0; i < pxdb_header_p->md_entries; i++)
753 idx = (long) qMD[i].sbMod;
754 printf ("%s\n", &vt_bits[idx]);
759 qCD = (quick_class_entry_ptr) addr;
760 addr += pxdb_header_p->cd_entries * sizeof (quick_class_entry);
765 printf ("\n Printing classes as we see them\n");
766 for (i = 0; VALID_CLASS (i); i++)
768 idx = (long) qCD[i].sbClass;
769 printf ("%s\n", &vt_bits[idx]);
772 printf ("\n Done with dump, on to build!\n");
776 /* We need this index only while hp-symtab-read.c expects
777 a byte offset to the end of the LNTT entries for a given
778 psymtab. Thus the need for it should go away someday.
780 When it goes away, then we won't have any need to load the
781 LNTT from the objfile at psymtab-time, and start-up will be
782 faster. To make that work, we'll need some way to create
783 a null pst for the "globals" pseudo-module. */
784 max_LNTT_sym_index = LNTT_SYMCOUNT (objfile);
786 /* Scan the module descriptors and make a psymtab for each.
788 We know the MDs, FDs and the PDs are in order by starting
789 address. We use that fact to traverse all three arrays in
790 parallel, knowing when the next PD is in a new file
791 and we need to create a new psymtab. */
792 curr_pd = 0; /* Current procedure entry */
793 curr_fd = 0; /* Current file entry */
794 curr_md = 0; /* Current module entry */
796 start_adr = 0; /* Current psymtab code range */
799 start_sym = 0; /* Current psymtab symbol range */
802 syms_in_pst = 0; /* Symbol count for psymtab */
804 /* Psts actually just have pointers into the objfile's
805 symbol table, not their own symbol tables. */
806 global_syms = objfile->global_psymbols.list;
807 static_syms = objfile->static_psymbols.list;
810 /* First skip over pseudo-entries with address 0. These represent inlined
811 routines and abstract (uninstantiated) template routines.
812 FIXME: These should be read in and available -- even if we can't set
813 breakpoints, etc., there's some information that can be presented
814 to the user. pai/1997-10-08 */
816 while (VALID_CURR_PROC && (CURR_PROC_START == 0))
819 /* Loop over files, modules, and procedures in code address order. Each
820 time we enter an iteration of this loop, curr_pd points to the first
821 unprocessed procedure, curr_fd points to the first unprocessed file, and
822 curr_md to the first unprocessed module. Each iteration of this loop
823 updates these as required -- any or all of them may be bumpd up
824 each time around. When we exit this loop, we are done with all files
825 and modules in the tables -- there may still be some procedures, however.
827 Note: This code used to loop only over module entries, under the assumption
828 that files can occur via inclusions and are thus unreliable, while a
829 compiled object always corresponds to a module. With CTTI in the HP aCC
830 compiler, it turns out that compiled objects may have only files and no
831 modules; so we have to loop over files and modules, creating psymtabs for
832 either as appropriate. Unfortunately there are some problems (notably:
833 1. the lack of "SRC_FILE_END" entries in the LNTT, 2. the lack of pointers
834 to the ending symbol indices of a module or a file) which make it quite hard
835 to do this correctly. Currently it uses a bunch of heuristics to start and
836 end psymtabs; they seem to work well with most objects generated by aCC, but
837 who knows when that will change... */
839 while (VALID_CURR_FILE || VALID_CURR_MODULE)
842 char *mod_name_string;
843 char *full_name_string;
845 /* First check for modules like "version.c", which have no code
846 in them but still have qMD entries. They also have no qFD or
847 qPD entries. Their start address is -1 and their end address
849 if (VALID_CURR_MODULE && (CURR_MODULE_START == -1) && (CURR_MODULE_END == 0))
852 mod_name_string = &vt_bits[(long) qMD[curr_md].sbMod];
856 printf ("Module with data only %s\n", mod_name_string);
859 /* We'll skip the rest (it makes error-checking easier), and
860 just make an empty pst. Right now empty psts are not put
861 in the pst chain, so all this is for naught, but later it
864 pst = hpread_start_psymtab (objfile,
865 section_offsets, /* ?? */
867 CURR_MODULE_START, /* Low text address: bogus! */
868 (CURR_MODULE_ISYM * sizeof (struct dntt_type_block)),
873 pst = hpread_end_psymtab (pst,
874 NULL, /* psymtab_include_list */
875 0, /* includes_used */
876 end_sym * sizeof (struct dntt_type_block),
877 /* byte index in LNTT of end
878 = capping symbol offset
879 = LDSYMOFF of nextfile */
881 NULL, /* dependency_list */
882 0); /* dependencies_used */
884 global_syms = objfile->global_psymbols.next;
885 static_syms = objfile->static_psymbols.next;
889 else if (VALID_CURR_MODULE &&
890 ((CURR_MODULE_START == 0) || (CURR_MODULE_START == -1) ||
891 (CURR_MODULE_END == 0) || (CURR_MODULE_END == -1)))
894 warning ("Module \"%s\" [0x%x] has non-standard addresses. It starts at 0x%x, ends at 0x%x, and will be skipped.",
895 mod_name_string, curr_md, start_adr, end_adr);
896 /* On to next module */
901 /* First check if we are looking at a file with code in it
902 that does not overlap the current module's code range */
904 if (VALID_CURR_FILE ? (VALID_CURR_MODULE ? (CURR_FILE_END < CURR_MODULE_START) : 1) : 0)
907 /* Looking at file not corresponding to any module,
908 create a psymtab for it */
909 full_name_string = &vt_bits[(long) qFD[curr_fd].sbFile];
910 start_adr = CURR_FILE_START;
911 end_adr = CURR_FILE_END;
912 start_sym = CURR_FILE_ISYM;
914 /* Check if there are any procedures not handled until now, that
915 begin before the start address of this file, and if so, adjust
916 this module's start address to include them. This handles routines that
917 are in between file or module ranges for some reason (probably
918 indicates a compiler bug */
920 if (CURR_PROC_START < start_adr)
923 warning ("Found procedure \"%s\" [0x%x] that is not in any file or module.",
924 &vt_bits[(long) qPD[curr_pd].sbProc], curr_pd);
925 start_adr = CURR_PROC_START;
926 if (CURR_PROC_ISYM < start_sym)
927 start_sym = CURR_PROC_ISYM;
930 /* Sometimes (compiler bug -- COBOL) the module end address is higher
931 than the start address of the next module, so check for that and
932 adjust accordingly */
934 if (VALID_FILE (curr_fd + 1) && (FILE_START (curr_fd + 1) <= end_adr))
937 warning ("File \"%s\" [0x%x] has ending address after starting address of next file; adjusting ending address down.",
938 full_name_string, curr_fd);
939 end_adr = FILE_START (curr_fd + 1) - 1; /* Is -4 (or -8 for 64-bit) better? */
941 if (VALID_MODULE (curr_md) && (CURR_MODULE_START <= end_adr))
944 warning ("File \"%s\" [0x%x] has ending address after starting address of next module; adjusting ending address down.",
945 full_name_string, curr_fd);
946 end_adr = CURR_MODULE_START - 1; /* Is -4 (or -8 for 64-bit) better? */
953 printf ("Make new psymtab for file %s (%x to %x).\n",
954 full_name_string, start_adr, end_adr);
957 /* Create the basic psymtab, connecting it in the list
958 for this objfile and pointing its symbol entries
959 to the current end of the symbol areas in the objfile.
961 The "ldsymoff" parameter is the byte offset in the LNTT
962 of the first symbol in this file. Some day we should
963 turn this into an index (fix in hp-symtab-read.c as well).
964 And it's not even the right byte offset, as we're using
965 the size of a union! FIXME! */
966 pst = hpread_start_psymtab (objfile,
967 section_offsets, /* ?? */
969 start_adr, /* Low text address */
970 (start_sym * sizeof (struct dntt_type_block)),
975 /* Set up to only enter each class referenced in this module once. */
976 class_entered = malloc (B_BYTES (pxdb_header_p->cd_entries));
977 B_CLRALL (class_entered, pxdb_header_p->cd_entries);
979 /* Scan the procedure descriptors for procedures in the current
980 file, based on the starting addresses. */
982 syms_in_pst = scan_procs (&curr_pd, qPD, pxdb_header_p->pd_entries,
984 pst, vt_bits, objfile, section_offsets);
986 /* Get ending symbol offset */
989 /* First check for starting index before previous psymtab */
990 if (pst_syms_count && start_sym < pst_syms_array[pst_syms_count - 1].end)
992 end_sym = find_next_pst_start (start_sym);
994 /* Look for next start index of a file or module, or procedure */
997 int next_file_isym = find_next_file_isym (start_sym, qFD, curr_fd + 1, pxdb_header_p);
998 int next_module_isym = find_next_module_isym (start_sym, qMD, curr_md, pxdb_header_p);
999 int next_proc_isym = find_next_proc_isym (start_sym, qPD, curr_pd, pxdb_header_p);
1001 if (next_file_isym && next_module_isym)
1003 /* pick lower of next file or module start index */
1004 end_sym = min (next_file_isym, next_module_isym);
1008 /* one of them is zero, pick the other */
1009 end_sym = max (next_file_isym, next_module_isym);
1012 /* As a precaution, check next procedure index too */
1014 end_sym = next_proc_isym;
1016 end_sym = min (end_sym, next_proc_isym);
1019 /* Couldn't find procedure, file, or module, use globals as default */
1021 end_sym = pxdb_header_p->globals;
1026 printf ("File psymtab indices: %x to %x\n", start_sym, end_sym);
1030 pst = hpread_end_psymtab (pst,
1031 NULL, /* psymtab_include_list */
1032 0, /* includes_used */
1033 end_sym * sizeof (struct dntt_type_block),
1034 /* byte index in LNTT of end
1035 = capping symbol offset
1036 = LDSYMOFF of nextfile */
1037 end_adr, /* text high */
1038 NULL, /* dependency_list */
1039 0); /* dependencies_used */
1041 record_pst_syms (start_sym, end_sym);
1044 warning ("No symbols in psymtab for file \"%s\" [0x%x].", full_name_string, curr_fd);
1049 printf ("Made new psymtab for file %s (%x to %x), sym %x to %x.\n",
1050 full_name_string, start_adr, end_adr, CURR_FILE_ISYM, end_sym);
1053 /* Prepare for the next psymtab. */
1054 global_syms = objfile->global_psymbols.next;
1055 static_syms = objfile->static_psymbols.next;
1056 free (class_entered);
1059 } /* Psymtab for file */
1062 /* We have a module for which we create a psymtab */
1064 mod_name_string = &vt_bits[(long) qMD[curr_md].sbMod];
1066 /* We will include the code ranges of any files that happen to
1067 overlap with this module */
1069 /* So, first pick the lower of the file's and module's start addresses */
1070 start_adr = CURR_MODULE_START;
1071 if (VALID_CURR_FILE)
1073 if (CURR_FILE_START < CURR_MODULE_START)
1076 warning ("File \"%s\" [0x%x] crosses beginning of module \"%s\".",
1077 &vt_bits[(long) qFD[curr_fd].sbFile],
1078 curr_fd, mod_name_string);
1080 start_adr = CURR_FILE_START;
1084 /* Also pick the lower of the file's and the module's start symbol indices */
1085 start_sym = CURR_MODULE_ISYM;
1086 if (VALID_CURR_FILE && (CURR_FILE_ISYM < CURR_MODULE_ISYM))
1087 start_sym = CURR_FILE_ISYM;
1089 /* For the end address, we scan through the files till we find one
1090 that overlaps the current module but ends beyond it; if no such file exists we
1091 simply use the module's start address.
1092 (Note, if file entries themselves overlap
1093 we take the longest overlapping extension beyond the end of the module...)
1094 We assume that modules never overlap. */
1096 end_adr = CURR_MODULE_END;
1098 if (VALID_CURR_FILE)
1100 while (VALID_CURR_FILE && (CURR_FILE_START < end_adr))
1105 printf ("Maybe skipping file %s which overlaps with module %s\n",
1106 &vt_bits[(long) qFD[curr_fd].sbFile], mod_name_string);
1108 if (CURR_FILE_END > end_adr)
1111 warning ("File \"%s\" [0x%x] crosses end of module \"%s\".",
1112 &vt_bits[(long) qFD[curr_fd].sbFile],
1113 curr_fd, mod_name_string);
1114 end_adr = CURR_FILE_END;
1118 curr_fd--; /* back up after going too far */
1121 /* Sometimes (compiler bug -- COBOL) the module end address is higher
1122 than the start address of the next module, so check for that and
1123 adjust accordingly */
1125 if (VALID_MODULE (curr_md + 1) && (MODULE_START (curr_md + 1) <= end_adr))
1128 warning ("Module \"%s\" [0x%x] has ending address after starting address of next module; adjusting ending address down.",
1129 mod_name_string, curr_md);
1130 end_adr = MODULE_START (curr_md + 1) - 1; /* Is -4 (or -8 for 64-bit) better? */
1132 if (VALID_FILE (curr_fd + 1) && (FILE_START (curr_fd + 1) <= end_adr))
1135 warning ("Module \"%s\" [0x%x] has ending address after starting address of next file; adjusting ending address down.",
1136 mod_name_string, curr_md);
1137 end_adr = FILE_START (curr_fd + 1) - 1; /* Is -4 (or -8 for 64-bit) better? */
1140 /* Use one file to get the full name for the module. This
1141 situation can arise if there is executable code in a #include
1142 file. Each file with code in it gets a qFD. Files which don't
1143 contribute code don't get a qFD, even if they include files
1148 #include "rtn.h" return x;
1151 There will a qFD for "rtn.h",and a qMD for "body.c",
1152 but no qMD for "rtn.h" or qFD for "body.c"!
1154 We pick the name of the last file to overlap with this
1155 module. C convention is to put include files first. In a
1156 perfect world, we could check names and use the file whose full
1157 path name ends with the module name. */
1159 if (VALID_CURR_FILE)
1160 full_name_string = &vt_bits[(long) qFD[curr_fd].sbFile];
1162 full_name_string = mod_name_string;
1164 /* Check if there are any procedures not handled until now, that
1165 begin before the start address we have now, and if so, adjust
1166 this psymtab's start address to include them. This handles routines that
1167 are in between file or module ranges for some reason (probably
1168 indicates a compiler bug */
1170 if (CURR_PROC_START < start_adr)
1173 warning ("Found procedure \"%s\" [0x%x] that is not in any file or module.",
1174 &vt_bits[(long) qPD[curr_pd].sbProc], curr_pd);
1175 start_adr = CURR_PROC_START;
1176 if (CURR_PROC_ISYM < start_sym)
1177 start_sym = CURR_PROC_ISYM;
1183 printf ("Make new psymtab for module %s (%x to %x), using file %s\n",
1184 mod_name_string, start_adr, end_adr, full_name_string);
1187 /* Create the basic psymtab, connecting it in the list
1188 for this objfile and pointing its symbol entries
1189 to the current end of the symbol areas in the objfile.
1191 The "ldsymoff" parameter is the byte offset in the LNTT
1192 of the first symbol in this file. Some day we should
1193 turn this into an index (fix in hp-symtab-read.c as well).
1194 And it's not even the right byte offset, as we're using
1195 the size of a union! FIXME! */
1196 pst = hpread_start_psymtab (objfile,
1197 section_offsets, /* ?? */
1199 start_adr, /* Low text address */
1200 (start_sym * sizeof (struct dntt_type_block)),
1205 /* Set up to only enter each class referenced in this module once. */
1206 class_entered = malloc (B_BYTES (pxdb_header_p->cd_entries));
1207 B_CLRALL (class_entered, pxdb_header_p->cd_entries);
1209 /* Scan the procedure descriptors for procedures in the current
1210 module, based on the starting addresses. */
1212 syms_in_pst = scan_procs (&curr_pd, qPD, pxdb_header_p->pd_entries,
1214 pst, vt_bits, objfile, section_offsets);
1216 /* Get ending symbol offset */
1219 /* First check for starting index before previous psymtab */
1220 if (pst_syms_count && start_sym < pst_syms_array[pst_syms_count - 1].end)
1222 end_sym = find_next_pst_start (start_sym);
1224 /* Look for next start index of a file or module, or procedure */
1227 int next_file_isym = find_next_file_isym (start_sym, qFD, curr_fd + 1, pxdb_header_p);
1228 int next_module_isym = find_next_module_isym (start_sym, qMD, curr_md + 1, pxdb_header_p);
1229 int next_proc_isym = find_next_proc_isym (start_sym, qPD, curr_pd, pxdb_header_p);
1231 if (next_file_isym && next_module_isym)
1233 /* pick lower of next file or module start index */
1234 end_sym = min (next_file_isym, next_module_isym);
1238 /* one of them is zero, pick the other */
1239 end_sym = max (next_file_isym, next_module_isym);
1242 /* As a precaution, check next procedure index too */
1244 end_sym = next_proc_isym;
1246 end_sym = min (end_sym, next_proc_isym);
1249 /* Couldn't find procedure, file, or module, use globals as default */
1251 end_sym = pxdb_header_p->globals;
1256 printf ("Module psymtab indices: %x to %x\n", start_sym, end_sym);
1260 pst = hpread_end_psymtab (pst,
1261 NULL, /* psymtab_include_list */
1262 0, /* includes_used */
1263 end_sym * sizeof (struct dntt_type_block),
1264 /* byte index in LNTT of end
1265 = capping symbol offset
1266 = LDSYMOFF of nextfile */
1267 end_adr, /* text high */
1268 NULL, /* dependency_list */
1269 0); /* dependencies_used */
1271 record_pst_syms (start_sym, end_sym);
1274 warning ("No symbols in psymtab for module \"%s\" [0x%x].", mod_name_string, curr_md);
1279 printf ("Made new psymtab for module %s (%x to %x), sym %x to %x.\n",
1280 mod_name_string, start_adr, end_adr, CURR_MODULE_ISYM, end_sym);
1284 /* Prepare for the next psymtab. */
1285 global_syms = objfile->global_psymbols.next;
1286 static_syms = objfile->static_psymbols.next;
1287 free (class_entered);
1291 } /* psymtab for module */
1292 } /* psymtab for non-bogus file or module */
1293 } /* End of while loop over all files & modules */
1295 /* There may be some routines after all files and modules -- these will get
1296 inserted in a separate new module of their own */
1297 if (VALID_CURR_PROC)
1299 start_adr = CURR_PROC_START;
1300 end_adr = qPD[pxdb_header_p->pd_entries - 1].adrEnd;
1302 warning ("Found functions beyond end of all files and modules [0x%x].", curr_pd);
1306 printf ("Orphan functions at end, PD %d and beyond (%x to %x)\n",
1307 curr_pd, start_adr, end_adr);
1310 pst = hpread_start_psymtab (objfile,
1311 section_offsets, /* ?? */
1313 start_adr, /* Low text address */
1314 (CURR_PROC_ISYM * sizeof (struct dntt_type_block)),
1319 scan_procs (&curr_pd, qPD, pxdb_header_p->pd_entries,
1321 pst, vt_bits, objfile, section_offsets);
1323 pst = hpread_end_psymtab (pst,
1324 NULL, /* psymtab_include_list */
1325 0, /* includes_used */
1326 pxdb_header_p->globals * sizeof (struct dntt_type_block),
1327 /* byte index in LNTT of end
1328 = capping symbol offset
1329 = LDSYMOFF of nextfile */
1330 end_adr, /* text high */
1331 NULL, /* dependency_list */
1332 0); /* dependencies_used */
1337 /* Now build psts for non-module things (in the tail of
1338 the LNTT, after the last END MODULE entry).
1340 If null psts were kept on the chain, this would be
1341 a solution. FIXME */
1342 pst = hpread_start_psymtab (objfile,
1346 (pxdb_header_p->globals
1347 * sizeof (struct dntt_type_block)),
1348 objfile->global_psymbols.next,
1349 objfile->static_psymbols.next);
1350 hpread_end_psymtab (pst,
1352 (max_LNTT_sym_index * sizeof (struct dntt_type_block)),
1361 } /* End of hpread_quick_traverse. */
1364 /* Get appropriate header, based on pxdb type.
1365 Return value: 1 if ok, 0 if not */
1367 hpread_get_header (objfile, pxdb_header_p)
1368 struct objfile *objfile;
1369 PXDB_header_ptr pxdb_header_p;
1371 asection *pinfo_section, *debug_section, *header_section;
1374 /* Turn on for debugging information */
1375 static int dumping = 0;
1378 header_section = bfd_get_section_by_name (objfile->obfd, "$HEADER$");
1379 if (!header_section)
1381 /* We don't have either PINFO or DEBUG sections. But
1382 stuff like "libc.sl" has no debug info. There's no
1383 need to warn the user of this, as it may be ok. The
1384 caller will figure it out and issue any needed
1388 printf ("==No debug info at all for %s.\n", objfile->name);
1394 /* We would like either a $DEBUG$ or $PINFO$ section.
1395 Once we know which, we can understand the header
1396 data (which we have defined to suit the more common
1398 debug_section = bfd_get_section_by_name (objfile->obfd, "$DEBUG$");
1399 pinfo_section = bfd_get_section_by_name (objfile->obfd, "$PINFO$");
1402 /* The expected case: normal pxdb header. */
1403 bfd_get_section_contents (objfile->obfd, header_section,
1404 pxdb_header_p, 0, sizeof (PXDB_header));
1406 if (!pxdb_header_p->pxdbed)
1408 /* This shouldn't happen if we check in "symfile.c". */
1410 } /* DEBUG section */
1413 else if (pinfo_section)
1415 /* The DOC case; we need to translate this into a
1417 DOC_info_PXDB_header doc_header;
1422 printf ("==OOps, PINFO, let's try to handle this, %s.\n", objfile->name);
1426 bfd_get_section_contents (objfile->obfd,
1429 sizeof (DOC_info_PXDB_header));
1431 if (!doc_header.pxdbed)
1433 /* This shouldn't happen if we check in "symfile.c". */
1434 warning ("File \"%s\" not processed by pxdb!", objfile->name);
1438 /* Copy relevent fields to standard header passed in. */
1439 pxdb_header_p->pd_entries = doc_header.pd_entries;
1440 pxdb_header_p->fd_entries = doc_header.fd_entries;
1441 pxdb_header_p->md_entries = doc_header.md_entries;
1442 pxdb_header_p->pxdbed = doc_header.pxdbed;
1443 pxdb_header_p->bighdr = doc_header.bighdr;
1444 pxdb_header_p->sa_header = doc_header.sa_header;
1445 pxdb_header_p->inlined = doc_header.inlined;
1446 pxdb_header_p->globals = doc_header.globals;
1447 pxdb_header_p->time = doc_header.time;
1448 pxdb_header_p->pg_entries = doc_header.pg_entries;
1449 pxdb_header_p->functions = doc_header.functions;
1450 pxdb_header_p->files = doc_header.files;
1451 pxdb_header_p->cd_entries = doc_header.cd_entries;
1452 pxdb_header_p->aa_entries = doc_header.aa_entries;
1453 pxdb_header_p->oi_entries = doc_header.oi_entries;
1454 pxdb_header_p->version = doc_header.version;
1455 } /* PINFO section */
1461 printf ("==No debug info at all for %s.\n", objfile->name);
1469 } /* End of hpread_get_header */
1470 #endif /* QUICK_LOOK_UP */
1473 /* Initialization for reading native HP C debug symbols from OBJFILE.
1475 Its only purpose in life is to set up the symbol reader's private
1476 per-objfile data structures, and read in the raw contents of the debug
1477 sections (attaching pointers to the debug info into the private data
1480 Since BFD doesn't know how to read debug symbols in a format-independent
1481 way (and may never do so...), we have to do it ourselves. Note we may
1482 be called on a file without native HP C debugging symbols.
1484 FIXME, there should be a cleaner peephole into the BFD environment
1487 hpread_symfile_init (objfile)
1488 struct objfile *objfile;
1490 asection *vt_section, *slt_section, *lntt_section, *gntt_section;
1492 /* Allocate struct to keep track of the symfile */
1493 objfile->sym_private = (PTR)
1494 xmmalloc (objfile->md, sizeof (struct hpread_symfile_info));
1495 memset (objfile->sym_private, 0, sizeof (struct hpread_symfile_info));
1497 /* We haven't read in any types yet. */
1498 TYPE_VECTOR (objfile) = 0;
1500 /* Read in data from the $GNTT$ subspace. */
1501 gntt_section = bfd_get_section_by_name (objfile->obfd, "$GNTT$");
1506 = obstack_alloc (&objfile->symbol_obstack,
1507 bfd_section_size (objfile->obfd, gntt_section));
1509 bfd_get_section_contents (objfile->obfd, gntt_section, GNTT (objfile),
1510 0, bfd_section_size (objfile->obfd, gntt_section));
1512 GNTT_SYMCOUNT (objfile)
1513 = bfd_section_size (objfile->obfd, gntt_section)
1514 / sizeof (struct dntt_type_block);
1516 /* Read in data from the $LNTT$ subspace. Also keep track of the number
1519 FIXME: this could be moved into the psymtab-to-symtab expansion
1520 code, and save startup time. At the moment this data is
1521 still used, though. We'd need a way to tell hp-symtab-read.c
1522 whether or not to load the LNTT. */
1523 lntt_section = bfd_get_section_by_name (objfile->obfd, "$LNTT$");
1528 = obstack_alloc (&objfile->symbol_obstack,
1529 bfd_section_size (objfile->obfd, lntt_section));
1531 bfd_get_section_contents (objfile->obfd, lntt_section, LNTT (objfile),
1532 0, bfd_section_size (objfile->obfd, lntt_section));
1534 LNTT_SYMCOUNT (objfile)
1535 = bfd_section_size (objfile->obfd, lntt_section)
1536 / sizeof (struct dntt_type_block);
1538 /* Read in data from the $SLT$ subspace. $SLT$ contains information
1539 on source line numbers. */
1540 slt_section = bfd_get_section_by_name (objfile->obfd, "$SLT$");
1545 obstack_alloc (&objfile->symbol_obstack,
1546 bfd_section_size (objfile->obfd, slt_section));
1548 bfd_get_section_contents (objfile->obfd, slt_section, SLT (objfile),
1549 0, bfd_section_size (objfile->obfd, slt_section));
1551 /* Read in data from the $VT$ subspace. $VT$ contains things like
1552 names and constants. Keep track of the number of symbols in the VT. */
1553 vt_section = bfd_get_section_by_name (objfile->obfd, "$VT$");
1557 VT_SIZE (objfile) = bfd_section_size (objfile->obfd, vt_section);
1560 (char *) obstack_alloc (&objfile->symbol_obstack,
1563 bfd_get_section_contents (objfile->obfd, vt_section, VT (objfile),
1564 0, VT_SIZE (objfile));
1567 /* Scan and build partial symbols for a symbol file.
1569 The minimal symbol table (either SOM or HP a.out) has already been
1570 read in; all we need to do is setup partial symbols based on the
1571 native debugging information.
1573 Note that the minimal table is produced by the linker, and has
1574 only global routines in it; the psymtab is based on compiler-
1575 generated debug information and has non-global
1576 routines in it as well as files and class information.
1578 We assume hpread_symfile_init has been called to initialize the
1579 symbol reader's private data structures.
1581 SECTION_OFFSETS contains offsets relative to which the symbols in the
1582 various sections are (depending where the sections were actually loaded).
1583 MAINLINE is true if we are reading the main symbol table (as
1584 opposed to a shared lib or dynamically loaded file). */
1586 hpread_build_psymtabs (objfile, section_offsets, mainline)
1587 struct objfile *objfile;
1588 struct section_offsets *section_offsets;
1593 /* Turn this on to get debugging output. */
1594 static int dumping = 0;
1598 int past_first_source_file = 0;
1599 struct cleanup *old_chain;
1601 int hp_symnum, symcount, i;
1604 union dnttentry *dn_bufp;
1610 /* Current partial symtab */
1611 struct partial_symtab *pst;
1613 /* List of current psymtab's include files */
1614 char **psymtab_include_list;
1615 int includes_allocated;
1618 /* Index within current psymtab dependency list */
1619 struct partial_symtab **dependency_list;
1620 int dependencies_used, dependencies_allocated;
1622 /* Just in case the stabs reader left turds lying around. */
1623 free_pending_blocks ();
1624 make_cleanup ((make_cleanup_func) really_free_pendings, 0);
1626 pst = (struct partial_symtab *) 0;
1628 /* We shouldn't use alloca, instead use malloc/free. Doing so avoids
1629 a number of problems with cross compilation and creating useless holes
1630 in the stack when we have to allocate new entries. FIXME. */
1632 includes_allocated = 30;
1634 psymtab_include_list = (char **) alloca (includes_allocated *
1637 dependencies_allocated = 30;
1638 dependencies_used = 0;
1640 (struct partial_symtab **) alloca (dependencies_allocated *
1641 sizeof (struct partial_symtab *));
1643 old_chain = make_cleanup ((make_cleanup_func) free_objfile, objfile);
1645 last_source_file = 0;
1647 #ifdef QUICK_LOOK_UP
1649 /* Begin code for new-style loading of quick look-up tables. */
1651 /* elz: this checks whether the file has beeen processed by pxdb.
1652 If not we would like to try to read the psymbols in
1653 anyway, but it turns out to be not so easy. So this could
1654 actually be commented out, but I leave it in, just in case
1655 we decide to add support for non-pxdb-ed stuff in the future. */
1656 PXDB_header pxdb_header;
1657 int found_modules_in_program;
1659 if (hpread_get_header (objfile, &pxdb_header))
1661 /* Build a minimal table. No types, no global variables,
1662 no include files.... */
1665 printf ("\nNew method for %s\n", objfile->name);
1668 /* elz: quick_traverse returns true if it found
1669 some modules in the main source file, other
1671 In C and C++, all the files have MODULES entries
1672 in the LNTT, and the quick table traverse is all
1673 based on finding these MODULES entries. Without
1674 those it cannot work.
1675 It happens that F77 programs don't have MODULES
1676 so the quick traverse gets confused. F90 programs
1677 have modules, and the quick method still works.
1678 So, if modules (other than those in end.c) are
1679 not found we give up on the quick table stuff,
1680 and fall back on the slower method */
1681 found_modules_in_program = hpread_quick_traverse (objfile,
1687 discard_cleanups (old_chain);
1689 /* Set up to scan the global section of the LNTT.
1691 This field is not always correct: if there are
1692 no globals, it will point to the last record in
1693 the regular LNTT, which is usually an END MODULE.
1695 Since it might happen that there could be a file
1696 with just one global record, there's no way to
1697 tell other than by looking at the record, so that's
1699 if (found_modules_in_program)
1700 scan_start = pxdb_header.globals;
1706 printf ("\nGoing on to old method for %s\n", objfile->name);
1710 #endif /* QUICK_LOOK_UP */
1712 /* Make two passes, one over the GNTT symbols, the other for the
1715 JB comment: above isn't true--they only make one pass, over
1717 for (i = 0; i < 1; i++)
1719 int within_function = 0;
1722 symcount = GNTT_SYMCOUNT (objfile);
1724 symcount = LNTT_SYMCOUNT (objfile);
1727 for (hp_symnum = scan_start; hp_symnum < symcount; hp_symnum++)
1731 dn_bufp = hpread_get_gntt (hp_symnum, objfile);
1733 dn_bufp = hpread_get_lntt (hp_symnum, objfile);
1735 if (dn_bufp->dblock.extension)
1738 /* Only handle things which are necessary for minimal symbols.
1739 everything else is ignored. */
1740 switch (dn_bufp->dblock.kind)
1742 case DNTT_TYPE_SRCFILE:
1744 #ifdef QUICK_LOOK_UP
1745 if (scan_start == hp_symnum
1746 && symcount == hp_symnum + 1)
1748 /* If there are NO globals in an executable,
1749 PXDB's index to the globals will point to
1750 the last record in the file, which
1751 could be this record. (this happened for F77 libraries)
1752 ignore it and be done! */
1755 #endif /* QUICK_LOOK_UP */
1757 /* A source file of some kind. Note this may simply
1758 be an included file. */
1759 SET_NAMESTRING (dn_bufp, &namestring, objfile);
1761 /* Check if this is the source file we are already working
1763 if (pst && !strcmp (namestring, pst->filename))
1766 /* Check if this is an include file, if so check if we have
1767 already seen it. Add it to the include list */
1768 p = strrchr (namestring, '.');
1769 if (!strcmp (p, ".h"))
1774 for (j = 0; j < includes_used; j++)
1775 if (!strcmp (namestring, psymtab_include_list[j]))
1783 /* Add it to the list of includes seen so far and
1784 allocate more include space if necessary. */
1785 psymtab_include_list[includes_used++] = namestring;
1786 if (includes_used >= includes_allocated)
1788 char **orig = psymtab_include_list;
1790 psymtab_include_list = (char **)
1791 alloca ((includes_allocated *= 2) *
1793 memcpy ((PTR) psymtab_include_list, (PTR) orig,
1794 includes_used * sizeof (char *));
1803 pst->filename = (char *)
1804 obstack_alloc (&pst->objfile->psymbol_obstack,
1805 strlen (namestring) + 1);
1806 strcpy (pst->filename, namestring);
1813 /* This is a bonafide new source file.
1814 End the current partial symtab and start a new one. */
1816 if (pst && past_first_source_file)
1818 hpread_end_psymtab (pst, psymtab_include_list,
1821 * sizeof (struct dntt_type_block)),
1823 dependency_list, dependencies_used);
1824 pst = (struct partial_symtab *) 0;
1826 dependencies_used = 0;
1829 past_first_source_file = 1;
1831 valu = hpread_get_textlow (i, hp_symnum, objfile, symcount);
1832 valu += ANOFFSET (section_offsets, SECT_OFF_TEXT);
1833 pst = hpread_start_psymtab (objfile, section_offsets,
1836 * sizeof (struct dntt_type_block)),
1837 objfile->global_psymbols.next,
1838 objfile->static_psymbols.next);
1844 case DNTT_TYPE_MODULE:
1845 /* A source file. It's still unclear to me what the
1846 real difference between a DNTT_TYPE_SRCFILE and DNTT_TYPE_MODULE
1847 is supposed to be. */
1849 /* First end the previous psymtab */
1852 hpread_end_psymtab (pst, psymtab_include_list, includes_used,
1854 * sizeof (struct dntt_type_block)),
1856 dependency_list, dependencies_used);
1857 pst = (struct partial_symtab *) 0;
1859 dependencies_used = 0;
1863 /* Now begin a new module and a new psymtab for it */
1864 SET_NAMESTRING (dn_bufp, &namestring, objfile);
1865 valu = hpread_get_textlow (i, hp_symnum, objfile, symcount);
1866 valu += ANOFFSET (section_offsets, SECT_OFF_TEXT);
1869 pst = hpread_start_psymtab (objfile, section_offsets,
1872 * sizeof (struct dntt_type_block)),
1873 objfile->global_psymbols.next,
1874 objfile->static_psymbols.next);
1880 case DNTT_TYPE_FUNCTION:
1881 case DNTT_TYPE_ENTRY:
1882 /* The beginning of a function. DNTT_TYPE_ENTRY may also denote
1883 a secondary entry point. */
1884 valu = dn_bufp->dfunc.hiaddr + ANOFFSET (section_offsets,
1886 if (valu > texthigh)
1888 valu = dn_bufp->dfunc.lowaddr +
1889 ANOFFSET (section_offsets, SECT_OFF_TEXT);
1890 SET_NAMESTRING (dn_bufp, &namestring, objfile);
1891 if (dn_bufp->dfunc.global)
1892 add_psymbol_to_list (namestring, strlen (namestring),
1893 VAR_NAMESPACE, LOC_BLOCK,
1894 &objfile->global_psymbols, valu,
1895 0, language_unknown, objfile);
1897 add_psymbol_to_list (namestring, strlen (namestring),
1898 VAR_NAMESPACE, LOC_BLOCK,
1899 &objfile->static_psymbols, valu,
1900 0, language_unknown, objfile);
1901 within_function = 1;
1904 case DNTT_TYPE_DOC_FUNCTION:
1905 valu = dn_bufp->ddocfunc.hiaddr + ANOFFSET (section_offsets,
1907 if (valu > texthigh)
1909 valu = dn_bufp->ddocfunc.lowaddr +
1910 ANOFFSET (section_offsets, SECT_OFF_TEXT);
1911 SET_NAMESTRING (dn_bufp, &namestring, objfile);
1912 if (dn_bufp->ddocfunc.global)
1913 add_psymbol_to_list (namestring, strlen (namestring),
1914 VAR_NAMESPACE, LOC_BLOCK,
1915 &objfile->global_psymbols, valu,
1916 0, language_unknown, objfile);
1918 add_psymbol_to_list (namestring, strlen (namestring),
1919 VAR_NAMESPACE, LOC_BLOCK,
1920 &objfile->static_psymbols, valu,
1921 0, language_unknown, objfile);
1922 within_function = 1;
1925 case DNTT_TYPE_BEGIN:
1927 /* We don't check MODULE end here, because there can be
1928 symbols beyond the module end which properly belong to the
1929 current psymtab -- so we wait till the next MODULE start */
1932 #ifdef QUICK_LOOK_UP
1933 if (scan_start == hp_symnum
1934 && symcount == hp_symnum + 1)
1936 /* If there are NO globals in an executable,
1937 PXDB's index to the globals will point to
1938 the last record in the file, which is
1939 probably an END MODULE, i.e. this record.
1940 ignore it and be done! */
1943 #endif /* QUICK_LOOK_UP */
1945 /* Scope block begin/end. We only care about function
1946 and file blocks right now. */
1948 if ((dn_bufp->dend.endkind == DNTT_TYPE_FUNCTION) ||
1949 (dn_bufp->dend.endkind == DNTT_TYPE_DOC_FUNCTION))
1950 within_function = 0;
1953 case DNTT_TYPE_SVAR:
1954 case DNTT_TYPE_DVAR:
1955 case DNTT_TYPE_TYPEDEF:
1956 case DNTT_TYPE_TAGDEF:
1958 /* Variables, typedefs an the like. */
1959 enum address_class storage;
1960 namespace_enum namespace;
1962 /* Don't add locals to the partial symbol table. */
1964 && (dn_bufp->dblock.kind == DNTT_TYPE_SVAR
1965 || dn_bufp->dblock.kind == DNTT_TYPE_DVAR))
1968 /* TAGDEFs go into the structure namespace. */
1969 if (dn_bufp->dblock.kind == DNTT_TYPE_TAGDEF)
1970 namespace = STRUCT_NAMESPACE;
1972 namespace = VAR_NAMESPACE;
1974 /* What kind of "storage" does this use? */
1975 if (dn_bufp->dblock.kind == DNTT_TYPE_SVAR)
1976 storage = LOC_STATIC;
1977 else if (dn_bufp->dblock.kind == DNTT_TYPE_DVAR
1978 && dn_bufp->ddvar.regvar)
1979 storage = LOC_REGISTER;
1980 else if (dn_bufp->dblock.kind == DNTT_TYPE_DVAR)
1981 storage = LOC_LOCAL;
1983 storage = LOC_UNDEF;
1985 SET_NAMESTRING (dn_bufp, &namestring, objfile);
1988 pst = hpread_start_psymtab (objfile, section_offsets,
1991 * sizeof (struct dntt_type_block)),
1992 objfile->global_psymbols.next,
1993 objfile->static_psymbols.next);
1996 /* Compute address of the data symbol */
1997 valu = dn_bufp->dsvar.location;
1998 /* Relocate in case it's in a shared library */
1999 if (storage == LOC_STATIC)
2000 valu += ANOFFSET (section_offsets, SECT_OFF_DATA);
2002 /* Luckily, dvar, svar, typedef, and tagdef all
2003 have their "global" bit in the same place, so it works
2004 (though it's bad programming practice) to reference
2005 "dsvar.global" even though we may be looking at
2006 any of the above four types. */
2007 if (dn_bufp->dsvar.global)
2009 add_psymbol_to_list (namestring, strlen (namestring),
2011 &objfile->global_psymbols,
2013 0, language_unknown, objfile);
2017 add_psymbol_to_list (namestring, strlen (namestring),
2019 &objfile->static_psymbols,
2021 0, language_unknown, objfile);
2024 /* For TAGDEF's, the above code added the tagname to the
2025 struct namespace. This will cause tag "t" to be found
2026 on a reference of the form "(struct t) x". But for
2027 C++ classes, "t" will also be a typename, which we
2028 want to find on a reference of the form "ptype t".
2029 Therefore, we also add "t" to the var namespace.
2030 Do the same for enum's due to the way aCC generates
2031 debug info for these (see more extended comment
2032 in hp-symtab-read.c).
2033 We do the same for templates, so that "ptype t"
2034 where "t" is a template also works. */
2035 if (dn_bufp->dblock.kind == DNTT_TYPE_TAGDEF &&
2036 dn_bufp->dtype.type.dnttp.index < LNTT_SYMCOUNT (objfile))
2038 int global = dn_bufp->dtag.global;
2039 /* Look ahead to see if it's a C++ class */
2040 dn_bufp = hpread_get_lntt (dn_bufp->dtype.type.dnttp.index, objfile);
2041 if (dn_bufp->dblock.kind == DNTT_TYPE_CLASS ||
2042 dn_bufp->dblock.kind == DNTT_TYPE_ENUM ||
2043 dn_bufp->dblock.kind == DNTT_TYPE_TEMPLATE)
2047 add_psymbol_to_list (namestring, strlen (namestring),
2048 VAR_NAMESPACE, storage,
2049 &objfile->global_psymbols,
2050 dn_bufp->dsvar.location,
2051 0, language_unknown, objfile);
2055 add_psymbol_to_list (namestring, strlen (namestring),
2056 VAR_NAMESPACE, storage,
2057 &objfile->static_psymbols,
2058 dn_bufp->dsvar.location,
2059 0, language_unknown, objfile);
2066 case DNTT_TYPE_MEMENUM:
2067 case DNTT_TYPE_CONST:
2068 /* Constants and members of enumerated types. */
2069 SET_NAMESTRING (dn_bufp, &namestring, objfile);
2072 pst = hpread_start_psymtab (objfile, section_offsets,
2075 * sizeof (struct dntt_type_block)),
2076 objfile->global_psymbols.next,
2077 objfile->static_psymbols.next);
2079 if (dn_bufp->dconst.global)
2080 add_psymbol_to_list (namestring, strlen (namestring),
2081 VAR_NAMESPACE, LOC_CONST,
2082 &objfile->global_psymbols, 0,
2083 0, language_unknown, objfile);
2085 add_psymbol_to_list (namestring, strlen (namestring),
2086 VAR_NAMESPACE, LOC_CONST,
2087 &objfile->static_psymbols, 0,
2088 0, language_unknown, objfile);
2096 /* End any pending partial symbol table. */
2099 hpread_end_psymtab (pst, psymtab_include_list, includes_used,
2100 hp_symnum * sizeof (struct dntt_type_block),
2101 0, dependency_list, dependencies_used);
2104 discard_cleanups (old_chain);
2107 /* Perform any local cleanups required when we are done with a particular
2108 objfile. I.E, we are in the process of discarding all symbol information
2109 for an objfile, freeing up all memory held for it, and unlinking the
2110 objfile struct from the global list of known objfiles. */
2113 hpread_symfile_finish (objfile)
2114 struct objfile *objfile;
2116 if (objfile->sym_private != NULL)
2118 mfree (objfile->md, objfile->sym_private);
2123 /* The remaining functions are all for internal use only. */
2125 /* Various small functions to get entries in the debug symbol sections. */
2128 hpread_get_lntt (index, objfile)
2130 struct objfile *objfile;
2132 return (union dnttentry *)
2133 &(LNTT (objfile)[(index * sizeof (struct dntt_type_block))]);
2136 static union dnttentry *
2137 hpread_get_gntt (index, objfile)
2139 struct objfile *objfile;
2141 return (union dnttentry *)
2142 &(GNTT (objfile)[(index * sizeof (struct dntt_type_block))]);
2146 hpread_get_slt (index, objfile)
2148 struct objfile *objfile;
2150 return (union sltentry *) &(SLT (objfile)[index * sizeof (union sltentry)]);
2153 /* Get the low address associated with some symbol (typically the start
2154 of a particular source file or module). Since that information is not
2155 stored as part of the DNTT_TYPE_MODULE or DNTT_TYPE_SRCFILE symbol we must infer it from
2156 the existance of DNTT_TYPE_FUNCTION symbols. */
2158 static unsigned long
2159 hpread_get_textlow (global, index, objfile, symcount)
2162 struct objfile *objfile;
2165 union dnttentry *dn_bufp;
2166 struct minimal_symbol *msymbol;
2168 /* Look for a DNTT_TYPE_FUNCTION symbol. */
2169 if (index < symcount) /* symcount is the number of symbols in */
2170 { /* the dbinfo, LNTT table */
2174 dn_bufp = hpread_get_gntt (index++, objfile);
2176 dn_bufp = hpread_get_lntt (index++, objfile);
2178 while (dn_bufp->dblock.kind != DNTT_TYPE_FUNCTION
2179 && dn_bufp->dblock.kind != DNTT_TYPE_DOC_FUNCTION
2180 && dn_bufp->dblock.kind != DNTT_TYPE_END
2181 && index < symcount);
2184 /* Avoid going past a DNTT_TYPE_END when looking for a DNTT_TYPE_FUNCTION. This
2185 might happen when a sourcefile has no functions. */
2186 if (dn_bufp->dblock.kind == DNTT_TYPE_END)
2189 /* Avoid going past the end of the LNTT file */
2190 if (index == symcount)
2193 /* The minimal symbols are typically more accurate for some reason. */
2194 if (dn_bufp->dblock.kind == DNTT_TYPE_FUNCTION)
2195 msymbol = lookup_minimal_symbol (dn_bufp->dfunc.name + VT (objfile), NULL,
2197 else /* must be a DNTT_TYPE_DOC_FUNCTION */
2198 msymbol = lookup_minimal_symbol (dn_bufp->ddocfunc.name + VT (objfile), NULL,
2202 return SYMBOL_VALUE_ADDRESS (msymbol);
2204 return dn_bufp->dfunc.lowaddr;
2207 /* Allocate and partially fill a partial symtab. It will be
2208 completely filled at the end of the symbol list.
2210 SYMFILE_NAME is the name of the symbol-file we are reading from, and ADDR
2211 is the address relative to which its symbols are (incremental) or 0
2214 static struct partial_symtab *
2215 hpread_start_psymtab (objfile, section_offsets,
2216 filename, textlow, ldsymoff, global_syms, static_syms)
2217 struct objfile *objfile;
2218 struct section_offsets *section_offsets;
2222 struct partial_symbol **global_syms;
2223 struct partial_symbol **static_syms;
2225 int offset = ANOFFSET (section_offsets, SECT_OFF_TEXT);
2226 extern void hpread_psymtab_to_symtab ();
2227 struct partial_symtab *result =
2228 start_psymtab_common (objfile, section_offsets,
2229 filename, textlow, global_syms, static_syms);
2231 result->textlow += offset;
2232 result->read_symtab_private = (char *)
2233 obstack_alloc (&objfile->psymbol_obstack, sizeof (struct symloc));
2234 LDSYMOFF (result) = ldsymoff;
2235 result->read_symtab = hpread_psymtab_to_symtab;
2241 /* Close off the current usage of PST.
2242 Returns PST or NULL if the partial symtab was empty and thrown away.
2244 capping_symbol_offset --Byte index in LNTT or GNTT of the
2245 last symbol processed during the build
2246 of the previous pst.
2248 FIXME: List variables and peculiarities of same. */
2250 static struct partial_symtab *
2251 hpread_end_psymtab (pst, include_list, num_includes, capping_symbol_offset,
2252 capping_text, dependency_list, number_dependencies)
2253 struct partial_symtab *pst;
2254 char **include_list;
2256 int capping_symbol_offset;
2257 CORE_ADDR capping_text;
2258 struct partial_symtab **dependency_list;
2259 int number_dependencies;
2262 struct objfile *objfile = pst->objfile;
2263 int offset = ANOFFSET (pst->section_offsets, SECT_OFF_TEXT);
2266 /* Turn on to see what kind of a psymtab we've built. */
2267 static int dumping = 0;
2270 if (capping_symbol_offset != -1)
2271 LDSYMLEN (pst) = capping_symbol_offset - LDSYMOFF (pst);
2274 pst->texthigh = capping_text + offset;
2276 pst->n_global_syms =
2277 objfile->global_psymbols.next - (objfile->global_psymbols.list + pst->globals_offset);
2278 pst->n_static_syms =
2279 objfile->static_psymbols.next - (objfile->static_psymbols.list + pst->statics_offset);
2284 printf ("\nPst %s, LDSYMOFF %x (%x), LDSYMLEN %x (%x), globals %d, statics %d\n",
2287 LDSYMOFF (pst) / sizeof (struct dntt_type_block),
2289 LDSYMLEN (pst) / sizeof (struct dntt_type_block),
2290 pst->n_global_syms, pst->n_static_syms);
2294 pst->number_of_dependencies = number_dependencies;
2295 if (number_dependencies)
2297 pst->dependencies = (struct partial_symtab **)
2298 obstack_alloc (&objfile->psymbol_obstack,
2299 number_dependencies * sizeof (struct partial_symtab *));
2300 memcpy (pst->dependencies, dependency_list,
2301 number_dependencies * sizeof (struct partial_symtab *));
2304 pst->dependencies = 0;
2306 for (i = 0; i < num_includes; i++)
2308 struct partial_symtab *subpst =
2309 allocate_psymtab (include_list[i], objfile);
2311 subpst->section_offsets = pst->section_offsets;
2312 subpst->read_symtab_private =
2313 (char *) obstack_alloc (&objfile->psymbol_obstack,
2314 sizeof (struct symloc));
2318 subpst->texthigh = 0;
2320 /* We could save slight bits of space by only making one of these,
2321 shared by the entire set of include files. FIXME-someday. */
2322 subpst->dependencies = (struct partial_symtab **)
2323 obstack_alloc (&objfile->psymbol_obstack,
2324 sizeof (struct partial_symtab *));
2325 subpst->dependencies[0] = pst;
2326 subpst->number_of_dependencies = 1;
2328 subpst->globals_offset =
2329 subpst->n_global_syms =
2330 subpst->statics_offset =
2331 subpst->n_static_syms = 0;
2335 subpst->read_symtab = pst->read_symtab;
2338 sort_pst_symbols (pst);
2340 /* If there is already a psymtab or symtab for a file of this name, remove it.
2341 (If there is a symtab, more drastic things also happen.)
2342 This happens in VxWorks. */
2343 free_named_symtabs (pst->filename);
2345 if (num_includes == 0
2346 && number_dependencies == 0
2347 && pst->n_global_syms == 0
2348 && pst->n_static_syms == 0)
2350 /* Throw away this psymtab, it's empty. We can't deallocate it, since
2351 it is on the obstack, but we can forget to chain it on the list.
2352 Empty psymtabs happen as a result of header files which don't have
2353 any symbols in them. There can be a lot of them. But this check
2354 is wrong, in that a psymtab with N_SLINE entries but nothing else
2355 is not empty, but we don't realize that. Fixing that without slowing
2356 things down might be tricky.
2357 It's also wrong if we're using the quick look-up tables, as
2358 we can get empty psymtabs from modules with no routines in
2361 discard_psymtab (pst);
2363 /* Indicate that psymtab was thrown away. */
2364 pst = (struct partial_symtab *) NULL;
2371 /* End of hp-psymtab-read.c */
2373 /* Set indentation to 4 spaces for Emacs; this file is
2374 mostly non-GNU-ish in its style :-( */
2377 ***c - basic - offset:4