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,
19 Boston, MA 02111-1307, USA.
21 Written by the Center for Software Science at the University of Utah
22 and by Cygnus Support. */
24 /* Common include file for hp_symtab_read.c and hp_psymtab_read.c.
25 This has nested includes of a bunch of stuff. */
29 /* To generate dumping code, uncomment this define. The dumping
30 itself is controlled by routine-local statics called "dumping". */
31 /* #define DUMPING 1 */
33 /* To use the quick look-up tables, uncomment this define. */
34 #define QUICK_LOOK_UP 1
36 /* To call PXDB to process un-processed files, uncomment this define. */
39 /* Forward procedure declarations */
41 void hpread_symfile_init
42 PARAMS ((struct objfile *));
45 do_pxdb PARAMS ((bfd *));
47 void hpread_build_psymtabs
48 PARAMS ((struct objfile *, struct section_offsets *, int));
50 void hpread_symfile_finish
51 PARAMS ((struct objfile *));
53 static union dnttentry *hpread_get_gntt
54 PARAMS ((int, struct objfile *));
56 static unsigned long hpread_get_textlow
57 PARAMS ((int, int, struct objfile *, int));
59 static struct partial_symtab *hpread_start_psymtab
60 PARAMS ((struct objfile *, struct section_offsets *, char *, CORE_ADDR, int,
61 struct partial_symbol **, struct partial_symbol **));
63 static struct partial_symtab *hpread_end_psymtab
64 PARAMS ((struct partial_symtab *, char **, int, int, CORE_ADDR,
65 struct partial_symtab **, int));
67 /* End of forward routine declarations */
71 /* NOTE use of system files! May not be portable. */
73 #define PXDB_SVR4 "/opt/langtools/bin/pxdb"
74 #define PXDB_BSD "/usr/bin/pxdb"
80 /* check for the existance of a file, given its full pathname */
82 file_exists (filename)
86 return (access (filename, F_OK) == 0);
91 /* Translate from the "hp_language" enumeration in hp-symtab.h
92 used in the debug info to gdb's generic enumeration in defs.h. */
95 enum hp_language in_lang;
97 if (in_lang == HP_LANGUAGE_C)
100 else if (in_lang == HP_LANGUAGE_CPLUSPLUS)
101 return language_cplus;
103 else if (in_lang == HP_LANGUAGE_F77)
104 return language_fortran;
107 return language_unknown;
110 static char main_string[] = "main";
112 /* Call PXDB to process our file.
114 Approach copied from DDE's "dbgk_run_pxdb". Note: we
115 don't check for BSD location of pxdb, nor for existance
118 NOTE: uses system function and string functions directly.
120 Return value: 1 if ok, 0 if not */
122 hpread_call_pxdb (file_name)
129 if (file_exists (PXDB_SVR4))
131 p = malloc (strlen (PXDB_SVR4) + strlen (file_name) + 2);
132 strcpy (p, PXDB_SVR4);
134 strcat (p, file_name);
136 warning ("File not processed by pxdb--about to process now.\n");
139 retval = (status == 0);
143 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);
148 } /* hpread_call_pxdb */
151 /* Return 1 if the file turns out to need pre-processing
152 by PXDB, and we have thus called PXDB to do this processing
153 and the file therefore needs to be re-loaded. Otherwise
156 hpread_pxdb_needed (sym_bfd)
159 asection *pinfo_section, *debug_section, *header_section;
160 unsigned int do_pxdb;
162 bfd_size_type header_section_size;
167 header_section = bfd_get_section_by_name (sym_bfd, "$HEADER$");
170 return 0; /* No header at all, can't recover... */
173 debug_section = bfd_get_section_by_name (sym_bfd, "$DEBUG$");
174 pinfo_section = bfd_get_section_by_name (sym_bfd, "$PINFO$");
176 if (pinfo_section && !debug_section)
178 /* Debug info with DOC, has different header format.
179 this only happens if the file was pxdbed and compiled optimized
180 otherwise the PINFO section is not there. */
181 header_section_size = bfd_section_size (objfile->obfd, header_section);
183 if (header_section_size == (bfd_size_type) sizeof (DOC_info_PXDB_header))
185 buf = alloca (sizeof (DOC_info_PXDB_header));
187 if (!bfd_get_section_contents (sym_bfd,
190 header_section_size))
191 error ("bfd_get_section_contents\n");
193 tmp = bfd_get_32 (sym_bfd, (bfd_byte *) (buf + sizeof (int) * 4));
194 pxdbed = (tmp >> 31) & 0x1;
197 error ("file debug header info invalid\n");
202 error ("invalid $HEADER$ size in executable \n");
208 /* this can be three different cases:
209 1. pxdbed and not doc
210 - DEBUG and HEADER sections are there
211 - header is PXDB_header type
212 - pxdbed flag is set to 1
214 2. not pxdbed and doc
215 - DEBUG and HEADER sections are there
216 - header is DOC_info_header type
217 - pxdbed flag is set to 0
219 3. not pxdbed and not doc
220 - DEBUG and HEADER sections are there
221 - header is XDB_header type
222 - pxdbed flag is set to 0
224 NOTE: the pxdbed flag is meaningful also in the not
225 already pxdb processed version of the header,
226 because in case on non-already processed by pxdb files
227 that same bit in the header would be always zero.
228 Why? Because the bit is the leftmost bit of a word
229 which contains a 'length' which is always a positive value
230 so that bit is never set to 1 (otherwise it would be negative)
232 Given the above, we have two choices : either we ignore the
233 size of the header itself and just look at the pxdbed field,
234 or we check the size and then we (for safety and paranoia related
235 issues) check the bit.
236 The first solution is used by DDE, the second by PXDB itself.
237 I am using the second one here, because I already wrote it,
238 and it is the end of a long day.
239 Also, using the first approach would still involve size issues
240 because we need to read in the contents of the header section, and
241 give the correct amount of stuff we want to read to the
242 get_bfd_section_contents function. */
244 /* decide which case depending on the size of the header section.
245 The size is as defined in hp-symtab.h */
247 header_section_size = bfd_section_size (objfile->obfd, header_section);
249 if (header_section_size == (bfd_size_type) sizeof (PXDB_header)) /* pxdb and not doc */
252 buf = alloca (sizeof (PXDB_header));
253 if (!bfd_get_section_contents (sym_bfd,
256 header_section_size))
257 error ("bfd_get_section_contents\n");
259 tmp = bfd_get_32 (sym_bfd, (bfd_byte *) (buf + sizeof (int) * 3));
260 pxdbed = (tmp >> 31) & 0x1;
265 error ("file debug header invalid\n");
267 else /*not pxdbed and doc OR not pxdbed and non doc */
279 } /* hpread_pxdb_needed */
283 /* Check whether the file needs to be preprocessed by pxdb.
290 /* The following code is HP-specific. The "right" way of
291 doing this is unknown, but we bet would involve a target-
292 specific pre-file-load check using a generic mechanism. */
294 /* This code will not be executed if the file is not in SOM
295 format (i.e. if compiled with gcc) */
296 if (hpread_pxdb_needed (sym_bfd))
298 /*This file has not been pre-processed. Preprocess now */
300 if (hpread_call_pxdb (sym_bfd->filename))
302 /* The call above has changed the on-disk file,
303 we can close the file anyway, because the
304 symbols will be reread in when the target is run */
314 /* Code to handle quick lookup-tables follows. */
317 /* Some useful macros */
318 #define VALID_FILE(i) ((i) < pxdb_header_p->fd_entries)
319 #define VALID_MODULE(i) ((i) < pxdb_header_p->md_entries)
320 #define VALID_PROC(i) ((i) < pxdb_header_p->pd_entries)
321 #define VALID_CLASS(i) ((i) < pxdb_header_p->cd_entries)
323 #define FILE_START(i) (qFD[i].adrStart)
324 #define MODULE_START(i) (qMD[i].adrStart)
325 #define PROC_START(i) (qPD[i].adrStart)
327 #define FILE_END(i) (qFD[i].adrEnd)
328 #define MODULE_END(i) (qMD[i].adrEnd)
329 #define PROC_END(i) (qPD[i].adrEnd)
331 #define FILE_ISYM(i) (qFD[i].isym)
332 #define MODULE_ISYM(i) (qMD[i].isym)
333 #define PROC_ISYM(i) (qPD[i].isym)
335 #define VALID_CURR_FILE (curr_fd < pxdb_header_p->fd_entries)
336 #define VALID_CURR_MODULE (curr_md < pxdb_header_p->md_entries)
337 #define VALID_CURR_PROC (curr_pd < pxdb_header_p->pd_entries)
338 #define VALID_CURR_CLASS (curr_cd < pxdb_header_p->cd_entries)
340 #define CURR_FILE_START (qFD[curr_fd].adrStart)
341 #define CURR_MODULE_START (qMD[curr_md].adrStart)
342 #define CURR_PROC_START (qPD[curr_pd].adrStart)
344 #define CURR_FILE_END (qFD[curr_fd].adrEnd)
345 #define CURR_MODULE_END (qMD[curr_md].adrEnd)
346 #define CURR_PROC_END (qPD[curr_pd].adrEnd)
348 #define CURR_FILE_ISYM (qFD[curr_fd].isym)
349 #define CURR_MODULE_ISYM (qMD[curr_md].isym)
350 #define CURR_PROC_ISYM (qPD[curr_pd].isym)
352 #define TELL_OBJFILE \
354 if( !told_objfile ) { \
356 warning ("\nIn object file \"%s\":\n", \
363 /* Keeping track of the start/end symbol table (LNTT) indices of
364 psymtabs created so far */
373 static pst_syms_struct *pst_syms_array = 0;
375 static pst_syms_count = 0;
376 static pst_syms_size = 0;
378 /* used by the TELL_OBJFILE macro */
379 static boolean told_objfile = 0;
381 /* Set up psymtab symbol index stuff */
387 pst_syms_array = (pst_syms_struct *) xmalloc (20 * sizeof (pst_syms_struct));
390 /* Clean up psymtab symbol index stuff */
396 free (pst_syms_array);
400 /* Add information about latest psymtab to symbol index table */
402 record_pst_syms (start_sym, end_sym)
406 if (++pst_syms_count > pst_syms_size)
408 pst_syms_array = (pst_syms_struct *) xrealloc (pst_syms_array,
409 2 * pst_syms_size * sizeof (pst_syms_struct));
412 pst_syms_array[pst_syms_count - 1].start = start_sym;
413 pst_syms_array[pst_syms_count - 1].end = end_sym;
416 /* Find a suitable symbol table index which can serve as the upper
417 bound of a psymtab that starts at INDEX
419 This scans backwards in the psymtab symbol index table to find a
420 "hole" in which the given index can fit. This is a heuristic!!
421 We don't search the entire table to check for multiple holes,
422 we don't care about overlaps, etc.
424 Return 0 => not found */
426 find_next_pst_start (index)
431 for (i = pst_syms_count - 1; i >= 0; i--)
432 if (pst_syms_array[i].end <= index)
433 return (i == pst_syms_count - 1) ? 0 : pst_syms_array[i + 1].start - 1;
435 if (pst_syms_array[0].start > index)
436 return pst_syms_array[0].start - 1;
443 /* Utility functions to find the ending symbol index for a psymtab */
445 /* Find the next file entry that begins beyond INDEX, and return
446 its starting symbol index - 1.
447 QFD is the file table, CURR_FD is the file entry from where to start,
448 PXDB_HEADER_P as in hpread_quick_traverse (to allow macros to work).
450 Return 0 => not found */
452 find_next_file_isym (index, qFD, curr_fd, pxdb_header_p)
454 quick_file_entry *qFD;
456 PXDB_header_ptr pxdb_header_p;
458 while (VALID_CURR_FILE)
460 if (CURR_FILE_ISYM >= index)
461 return CURR_FILE_ISYM - 1;
467 /* Find the next procedure entry that begins beyond INDEX, and return
468 its starting symbol index - 1.
469 QPD is the procedure table, CURR_PD is the proc entry from where to start,
470 PXDB_HEADER_P as in hpread_quick_traverse (to allow macros to work).
472 Return 0 => not found */
474 find_next_proc_isym (index, qPD, curr_pd, pxdb_header_p)
476 quick_procedure_entry *qPD;
478 PXDB_header_ptr pxdb_header_p;
480 while (VALID_CURR_PROC)
482 if (CURR_PROC_ISYM >= index)
483 return CURR_PROC_ISYM - 1;
489 /* Find the next module entry that begins beyond INDEX, and return
490 its starting symbol index - 1.
491 QMD is the module table, CURR_MD is the modue entry from where to start,
492 PXDB_HEADER_P as in hpread_quick_traverse (to allow macros to work).
494 Return 0 => not found */
496 find_next_module_isym (index, qMD, curr_md, pxdb_header_p)
498 quick_module_entry *qMD;
500 PXDB_header_ptr pxdb_header_p;
502 while (VALID_CURR_MODULE)
504 if (CURR_MODULE_ISYM >= index)
505 return CURR_MODULE_ISYM - 1;
511 /* Scan and record partial symbols for all functions starting from index
512 pointed to by CURR_PD_P, and between code addresses START_ADR and END_ADR.
513 Other parameters are explained in comments below. */
515 /* This used to be inline in hpread_quick_traverse, but now that we do essentially the
516 same thing for two different cases (modules and module-less files), it's better
517 organized in a separate routine, although it does take lots of arguments. pai/1997-10-08 */
520 scan_procs (curr_pd_p, qPD, max_procs, start_adr, end_adr, pst, vt_bits, objfile, section_offsets)
521 int *curr_pd_p; /* pointer to current proc index */
522 quick_procedure_entry *qPD; /* the procedure quick lookup table */
523 int max_procs; /* number of entries in proc. table */
524 CORE_ADDR start_adr; /* beginning of code range for current psymtab */
525 CORE_ADDR end_adr; /* end of code range for current psymtab */
526 struct partial_symtab *pst; /* current psymtab */
527 char *vt_bits; /* strings table of SOM debug space */
528 struct objfile *objfile; /* current object file */
529 struct section_offsets *section_offsets; /* not really used for HP-UX currently */
531 union dnttentry *dn_bufp;
532 int symbol_count = 0; /* Total number of symbols in this psymtab */
533 int curr_pd = *curr_pd_p; /* Convenience variable -- avoid dereferencing pointer all the time */
536 /* Turn this on for lots of debugging information in this routine */
537 static int dumping = 0;
543 printf ("Scan_procs called, addresses %x to %x, proc %x\n", start_adr, end_adr, curr_pd);
547 while ((CURR_PROC_START <= end_adr) && (curr_pd < max_procs))
550 char *rtn_name; /* mangled name */
551 char *rtn_dem_name; /* qualified demangled name */
555 if ((trans_lang ((enum hp_language) qPD[curr_pd].language) == language_cplus) &&
556 vt_bits[(long) qPD[curr_pd].sbAlias]) /* not a null string */
558 /* Get mangled name for the procedure, and demangle it */
559 rtn_name = &vt_bits[(long) qPD[curr_pd].sbAlias];
560 rtn_dem_name = cplus_demangle (rtn_name, DMGL_ANSI | DMGL_PARAMS);
564 rtn_name = &vt_bits[(long) qPD[curr_pd].sbProc];
568 /* Hack to get around HP C/C++ compilers' insistence on providing
569 "_MAIN_" as an alternate name for "main" */
570 if ((strcmp (rtn_name, "_MAIN_") == 0) &&
571 (strcmp (&vt_bits[(long) qPD[curr_pd].sbProc], "main") == 0))
572 rtn_dem_name = rtn_name = main_string;
577 printf ("..add %s (demangled %s), index %x to this psymtab\n", rtn_name, rtn_dem_name, curr_pd);
581 /* Check for module-spanning routines. */
582 if (CURR_PROC_END > end_adr)
585 warning ("Procedure \"%s\" [0x%x] spans file or module boundaries.", rtn_name, curr_pd);
588 /* Add this routine symbol to the list in the objfile.
589 Unfortunately we have to go to the LNTT to determine the
590 correct list to put it on. An alternative (which the
591 code used to do) would be to not check and always throw
592 it on the "static" list. But if we go that route, then
593 symbol_lookup() needs to be tweaked a bit to account
594 for the fact that the function might not be found on
595 the correct list in the psymtab. - RT */
596 dn_bufp = hpread_get_lntt (qPD[curr_pd].isym, objfile);
597 if (dn_bufp->dfunc.global)
598 add_psymbol_with_dem_name_to_list (rtn_name,
601 strlen (rtn_dem_name),
603 LOC_BLOCK, /* "I am a routine" */
604 &objfile->global_psymbols,
605 (qPD[curr_pd].adrStart + /* Starting address of rtn */
606 ANOFFSET (section_offsets, SECT_OFF_TEXT)),
608 trans_lang ((enum hp_language) qPD[curr_pd].language),
611 add_psymbol_with_dem_name_to_list (rtn_name,
614 strlen (rtn_dem_name),
616 LOC_BLOCK, /* "I am a routine" */
617 &objfile->static_psymbols,
618 (qPD[curr_pd].adrStart + /* Starting address of rtn */
619 ANOFFSET (section_offsets, SECT_OFF_TEXT)),
621 trans_lang ((enum hp_language) qPD[curr_pd].language),
625 *curr_pd_p = ++curr_pd; /* bump up count & reflect in caller */
626 } /* loop over procedures */
631 if (symbol_count == 0)
632 printf ("Scan_procs: no symbols found!\n");
640 /* Traverse the quick look-up tables, building a set of psymtabs.
642 This constructs a psymtab for modules and files in the quick lookup
645 Mostly, modules correspond to compilation units, so we try to
646 create psymtabs that correspond to modules; however, in some cases
647 a file can result in a compiled object which does not have a module
648 entry for it, so in such cases we create a psymtab for the file. */
651 hpread_quick_traverse (objfile, section_offsets, gntt_bits, vt_bits, pxdb_header_p)
652 struct objfile *objfile; /* The object file descriptor */
653 struct section_offsets *section_offsets; /* ?? Null for HP */
654 char *gntt_bits; /* GNTT entries, loaded in from the file */
655 char *vt_bits; /* VT (string) entries ditto. */
656 PXDB_header_ptr pxdb_header_p; /* Pointer to pxdb header ditto */
658 struct partial_symtab *pst;
662 quick_procedure_entry *qPD;
663 quick_file_entry *qFD;
664 quick_module_entry *qMD;
665 quick_class_entry *qCD;
669 CORE_ADDR start_adr; /* current psymtab's starting code addr */
670 CORE_ADDR end_adr; /* current psymtab's ending code addr */
671 CORE_ADDR next_mod_adr; /* next module's starting code addr */
672 int curr_pd; /* current procedure */
673 int curr_fd; /* current file */
674 int curr_md; /* current module */
675 int start_sym; /* current psymtab's starting symbol index */
676 int end_sym; /* current psymtab's ending symbol index */
677 int max_LNTT_sym_index;
679 B_TYPE *class_entered;
681 struct partial_symbol **global_syms; /* We'll be filling in the "global" */
682 struct partial_symbol **static_syms; /* and "static" tables in the objfile
683 as we go, so we need a pair of
687 /* Turn this on for lots of debugging information in this routine.
688 You get a blow-by-blow account of quick lookup table reading */
689 static int dumping = 0;
692 pst = (struct partial_symtab *) 0;
694 /* Clear out some globals */
698 /* Demangling style -- if EDG style already set, don't change it,
699 as HP style causes some problems with the KAI EDG compiler */
700 if (current_demangling_style != edg_demangling)
702 /* Otherwise, ensure that we are using HP style demangling */
703 set_demangling_style (HP_DEMANGLING_STYLE_STRING);
706 /* First we need to find the starting points of the quick
707 look-up tables in the GNTT. */
711 qPD = (quick_procedure_entry_ptr) addr;
712 addr += pxdb_header_p->pd_entries * sizeof (quick_procedure_entry);
717 printf ("\n Printing routines as we see them\n");
718 for (i = 0; VALID_PROC (i); i++)
720 idx = (long) qPD[i].sbProc;
721 printf ("%s %x..%x\n", &vt_bits[idx],
722 (int) PROC_START (i),
728 qFD = (quick_file_entry_ptr) addr;
729 addr += pxdb_header_p->fd_entries * sizeof (quick_file_entry);
734 printf ("\n Printing files as we see them\n");
735 for (i = 0; VALID_FILE (i); i++)
737 idx = (long) qFD[i].sbFile;
738 printf ("%s %x..%x\n", &vt_bits[idx],
739 (int) FILE_START (i),
745 qMD = (quick_module_entry_ptr) addr;
746 addr += pxdb_header_p->md_entries * sizeof (quick_module_entry);
751 printf ("\n Printing modules as we see them\n");
752 for (i = 0; i < pxdb_header_p->md_entries; i++)
754 idx = (long) qMD[i].sbMod;
755 printf ("%s\n", &vt_bits[idx]);
760 qCD = (quick_class_entry_ptr) addr;
761 addr += pxdb_header_p->cd_entries * sizeof (quick_class_entry);
766 printf ("\n Printing classes as we see them\n");
767 for (i = 0; VALID_CLASS (i); i++)
769 idx = (long) qCD[i].sbClass;
770 printf ("%s\n", &vt_bits[idx]);
773 printf ("\n Done with dump, on to build!\n");
777 /* We need this index only while hp-symtab-read.c expects
778 a byte offset to the end of the LNTT entries for a given
779 psymtab. Thus the need for it should go away someday.
781 When it goes away, then we won't have any need to load the
782 LNTT from the objfile at psymtab-time, and start-up will be
783 faster. To make that work, we'll need some way to create
784 a null pst for the "globals" pseudo-module. */
785 max_LNTT_sym_index = LNTT_SYMCOUNT (objfile);
787 /* Scan the module descriptors and make a psymtab for each.
789 We know the MDs, FDs and the PDs are in order by starting
790 address. We use that fact to traverse all three arrays in
791 parallel, knowing when the next PD is in a new file
792 and we need to create a new psymtab. */
793 curr_pd = 0; /* Current procedure entry */
794 curr_fd = 0; /* Current file entry */
795 curr_md = 0; /* Current module entry */
797 start_adr = 0; /* Current psymtab code range */
800 start_sym = 0; /* Current psymtab symbol range */
803 syms_in_pst = 0; /* Symbol count for psymtab */
805 /* Psts actually just have pointers into the objfile's
806 symbol table, not their own symbol tables. */
807 global_syms = objfile->global_psymbols.list;
808 static_syms = objfile->static_psymbols.list;
811 /* First skip over pseudo-entries with address 0. These represent inlined
812 routines and abstract (uninstantiated) template routines.
813 FIXME: These should be read in and available -- even if we can't set
814 breakpoints, etc., there's some information that can be presented
815 to the user. pai/1997-10-08 */
817 while (VALID_CURR_PROC && (CURR_PROC_START == 0))
820 /* Loop over files, modules, and procedures in code address order. Each
821 time we enter an iteration of this loop, curr_pd points to the first
822 unprocessed procedure, curr_fd points to the first unprocessed file, and
823 curr_md to the first unprocessed module. Each iteration of this loop
824 updates these as required -- any or all of them may be bumpd up
825 each time around. When we exit this loop, we are done with all files
826 and modules in the tables -- there may still be some procedures, however.
828 Note: This code used to loop only over module entries, under the assumption
829 that files can occur via inclusions and are thus unreliable, while a
830 compiled object always corresponds to a module. With CTTI in the HP aCC
831 compiler, it turns out that compiled objects may have only files and no
832 modules; so we have to loop over files and modules, creating psymtabs for
833 either as appropriate. Unfortunately there are some problems (notably:
834 1. the lack of "SRC_FILE_END" entries in the LNTT, 2. the lack of pointers
835 to the ending symbol indices of a module or a file) which make it quite hard
836 to do this correctly. Currently it uses a bunch of heuristics to start and
837 end psymtabs; they seem to work well with most objects generated by aCC, but
838 who knows when that will change... */
840 while (VALID_CURR_FILE || VALID_CURR_MODULE)
843 char *mod_name_string;
844 char *full_name_string;
846 /* First check for modules like "version.c", which have no code
847 in them but still have qMD entries. They also have no qFD or
848 qPD entries. Their start address is -1 and their end address
850 if (VALID_CURR_MODULE && (CURR_MODULE_START == -1) && (CURR_MODULE_END == 0))
853 mod_name_string = &vt_bits[(long) qMD[curr_md].sbMod];
857 printf ("Module with data only %s\n", mod_name_string);
860 /* We'll skip the rest (it makes error-checking easier), and
861 just make an empty pst. Right now empty psts are not put
862 in the pst chain, so all this is for naught, but later it
865 pst = hpread_start_psymtab (objfile,
866 section_offsets, /* ?? */
868 CURR_MODULE_START, /* Low text address: bogus! */
869 (CURR_MODULE_ISYM * sizeof (struct dntt_type_block)),
874 pst = hpread_end_psymtab (pst,
875 NULL, /* psymtab_include_list */
876 0, /* includes_used */
877 end_sym * sizeof (struct dntt_type_block),
878 /* byte index in LNTT of end
879 = capping symbol offset
880 = LDSYMOFF of nextfile */
882 NULL, /* dependency_list */
883 0); /* dependencies_used */
885 global_syms = objfile->global_psymbols.next;
886 static_syms = objfile->static_psymbols.next;
890 else if (VALID_CURR_MODULE &&
891 ((CURR_MODULE_START == 0) || (CURR_MODULE_START == -1) ||
892 (CURR_MODULE_END == 0) || (CURR_MODULE_END == -1)))
895 warning ("Module \"%s\" [0x%x] has non-standard addresses. It starts at 0x%x, ends at 0x%x, and will be skipped.",
896 mod_name_string, curr_md, start_adr, end_adr);
897 /* On to next module */
902 /* First check if we are looking at a file with code in it
903 that does not overlap the current module's code range */
905 if (VALID_CURR_FILE ? (VALID_CURR_MODULE ? (CURR_FILE_END < CURR_MODULE_START) : 1) : 0)
908 /* Looking at file not corresponding to any module,
909 create a psymtab for it */
910 full_name_string = &vt_bits[(long) qFD[curr_fd].sbFile];
911 start_adr = CURR_FILE_START;
912 end_adr = CURR_FILE_END;
913 start_sym = CURR_FILE_ISYM;
915 /* Check if there are any procedures not handled until now, that
916 begin before the start address of this file, and if so, adjust
917 this module's start address to include them. This handles routines that
918 are in between file or module ranges for some reason (probably
919 indicates a compiler bug */
921 if (CURR_PROC_START < start_adr)
924 warning ("Found procedure \"%s\" [0x%x] that is not in any file or module.",
925 &vt_bits[(long) qPD[curr_pd].sbProc], curr_pd);
926 start_adr = CURR_PROC_START;
927 if (CURR_PROC_ISYM < start_sym)
928 start_sym = CURR_PROC_ISYM;
931 /* Sometimes (compiler bug -- COBOL) the module end address is higher
932 than the start address of the next module, so check for that and
933 adjust accordingly */
935 if (VALID_FILE (curr_fd + 1) && (FILE_START (curr_fd + 1) <= end_adr))
938 warning ("File \"%s\" [0x%x] has ending address after starting address of next file; adjusting ending address down.",
939 full_name_string, curr_fd);
940 end_adr = FILE_START (curr_fd + 1) - 1; /* Is -4 (or -8 for 64-bit) better? */
942 if (VALID_MODULE (curr_md) && (CURR_MODULE_START <= end_adr))
945 warning ("File \"%s\" [0x%x] has ending address after starting address of next module; adjusting ending address down.",
946 full_name_string, curr_fd);
947 end_adr = CURR_MODULE_START - 1; /* Is -4 (or -8 for 64-bit) better? */
954 printf ("Make new psymtab for file %s (%x to %x).\n",
955 full_name_string, start_adr, end_adr);
958 /* Create the basic psymtab, connecting it in the list
959 for this objfile and pointing its symbol entries
960 to the current end of the symbol areas in the objfile.
962 The "ldsymoff" parameter is the byte offset in the LNTT
963 of the first symbol in this file. Some day we should
964 turn this into an index (fix in hp-symtab-read.c as well).
965 And it's not even the right byte offset, as we're using
966 the size of a union! FIXME! */
967 pst = hpread_start_psymtab (objfile,
968 section_offsets, /* ?? */
970 start_adr, /* Low text address */
971 (start_sym * sizeof (struct dntt_type_block)),
976 /* Set up to only enter each class referenced in this module once. */
977 class_entered = malloc (B_BYTES (pxdb_header_p->cd_entries));
978 B_CLRALL (class_entered, pxdb_header_p->cd_entries);
980 /* Scan the procedure descriptors for procedures in the current
981 file, based on the starting addresses. */
983 syms_in_pst = scan_procs (&curr_pd, qPD, pxdb_header_p->pd_entries,
985 pst, vt_bits, objfile, section_offsets);
987 /* Get ending symbol offset */
990 /* First check for starting index before previous psymtab */
991 if (pst_syms_count && start_sym < pst_syms_array[pst_syms_count - 1].end)
993 end_sym = find_next_pst_start (start_sym);
995 /* Look for next start index of a file or module, or procedure */
998 int next_file_isym = find_next_file_isym (start_sym, qFD, curr_fd + 1, pxdb_header_p);
999 int next_module_isym = find_next_module_isym (start_sym, qMD, curr_md, pxdb_header_p);
1000 int next_proc_isym = find_next_proc_isym (start_sym, qPD, curr_pd, pxdb_header_p);
1002 if (next_file_isym && next_module_isym)
1004 /* pick lower of next file or module start index */
1005 end_sym = min (next_file_isym, next_module_isym);
1009 /* one of them is zero, pick the other */
1010 end_sym = max (next_file_isym, next_module_isym);
1013 /* As a precaution, check next procedure index too */
1015 end_sym = next_proc_isym;
1017 end_sym = min (end_sym, next_proc_isym);
1020 /* Couldn't find procedure, file, or module, use globals as default */
1022 end_sym = pxdb_header_p->globals;
1027 printf ("File psymtab indices: %x to %x\n", start_sym, end_sym);
1031 pst = hpread_end_psymtab (pst,
1032 NULL, /* psymtab_include_list */
1033 0, /* includes_used */
1034 end_sym * sizeof (struct dntt_type_block),
1035 /* byte index in LNTT of end
1036 = capping symbol offset
1037 = LDSYMOFF of nextfile */
1038 end_adr, /* text high */
1039 NULL, /* dependency_list */
1040 0); /* dependencies_used */
1042 record_pst_syms (start_sym, end_sym);
1045 warning ("No symbols in psymtab for file \"%s\" [0x%x].", full_name_string, curr_fd);
1050 printf ("Made new psymtab for file %s (%x to %x), sym %x to %x.\n",
1051 full_name_string, start_adr, end_adr, CURR_FILE_ISYM, end_sym);
1054 /* Prepare for the next psymtab. */
1055 global_syms = objfile->global_psymbols.next;
1056 static_syms = objfile->static_psymbols.next;
1057 free (class_entered);
1060 } /* Psymtab for file */
1063 /* We have a module for which we create a psymtab */
1065 mod_name_string = &vt_bits[(long) qMD[curr_md].sbMod];
1067 /* We will include the code ranges of any files that happen to
1068 overlap with this module */
1070 /* So, first pick the lower of the file's and module's start addresses */
1071 start_adr = CURR_MODULE_START;
1072 if (VALID_CURR_FILE)
1074 if (CURR_FILE_START < CURR_MODULE_START)
1077 warning ("File \"%s\" [0x%x] crosses beginning of module \"%s\".",
1078 &vt_bits[(long) qFD[curr_fd].sbFile],
1079 curr_fd, mod_name_string);
1081 start_adr = CURR_FILE_START;
1085 /* Also pick the lower of the file's and the module's start symbol indices */
1086 start_sym = CURR_MODULE_ISYM;
1087 if (VALID_CURR_FILE && (CURR_FILE_ISYM < CURR_MODULE_ISYM))
1088 start_sym = CURR_FILE_ISYM;
1090 /* For the end address, we scan through the files till we find one
1091 that overlaps the current module but ends beyond it; if no such file exists we
1092 simply use the module's start address.
1093 (Note, if file entries themselves overlap
1094 we take the longest overlapping extension beyond the end of the module...)
1095 We assume that modules never overlap. */
1097 end_adr = CURR_MODULE_END;
1099 if (VALID_CURR_FILE)
1101 while (VALID_CURR_FILE && (CURR_FILE_START < end_adr))
1106 printf ("Maybe skipping file %s which overlaps with module %s\n",
1107 &vt_bits[(long) qFD[curr_fd].sbFile], mod_name_string);
1109 if (CURR_FILE_END > end_adr)
1112 warning ("File \"%s\" [0x%x] crosses end of module \"%s\".",
1113 &vt_bits[(long) qFD[curr_fd].sbFile],
1114 curr_fd, mod_name_string);
1115 end_adr = CURR_FILE_END;
1119 curr_fd--; /* back up after going too far */
1122 /* Sometimes (compiler bug -- COBOL) the module end address is higher
1123 than the start address of the next module, so check for that and
1124 adjust accordingly */
1126 if (VALID_MODULE (curr_md + 1) && (MODULE_START (curr_md + 1) <= end_adr))
1129 warning ("Module \"%s\" [0x%x] has ending address after starting address of next module; adjusting ending address down.",
1130 mod_name_string, curr_md);
1131 end_adr = MODULE_START (curr_md + 1) - 1; /* Is -4 (or -8 for 64-bit) better? */
1133 if (VALID_FILE (curr_fd + 1) && (FILE_START (curr_fd + 1) <= end_adr))
1136 warning ("Module \"%s\" [0x%x] has ending address after starting address of next file; adjusting ending address down.",
1137 mod_name_string, curr_md);
1138 end_adr = FILE_START (curr_fd + 1) - 1; /* Is -4 (or -8 for 64-bit) better? */
1141 /* Use one file to get the full name for the module. This
1142 situation can arise if there is executable code in a #include
1143 file. Each file with code in it gets a qFD. Files which don't
1144 contribute code don't get a qFD, even if they include files
1149 #include "rtn.h" return x;
1152 There will a qFD for "rtn.h",and a qMD for "body.c",
1153 but no qMD for "rtn.h" or qFD for "body.c"!
1155 We pick the name of the last file to overlap with this
1156 module. C convention is to put include files first. In a
1157 perfect world, we could check names and use the file whose full
1158 path name ends with the module name. */
1160 if (VALID_CURR_FILE)
1161 full_name_string = &vt_bits[(long) qFD[curr_fd].sbFile];
1163 full_name_string = mod_name_string;
1165 /* Check if there are any procedures not handled until now, that
1166 begin before the start address we have now, and if so, adjust
1167 this psymtab's start address to include them. This handles routines that
1168 are in between file or module ranges for some reason (probably
1169 indicates a compiler bug */
1171 if (CURR_PROC_START < start_adr)
1174 warning ("Found procedure \"%s\" [0x%x] that is not in any file or module.",
1175 &vt_bits[(long) qPD[curr_pd].sbProc], curr_pd);
1176 start_adr = CURR_PROC_START;
1177 if (CURR_PROC_ISYM < start_sym)
1178 start_sym = CURR_PROC_ISYM;
1184 printf ("Make new psymtab for module %s (%x to %x), using file %s\n",
1185 mod_name_string, start_adr, end_adr, full_name_string);
1188 /* Create the basic psymtab, connecting it in the list
1189 for this objfile and pointing its symbol entries
1190 to the current end of the symbol areas in the objfile.
1192 The "ldsymoff" parameter is the byte offset in the LNTT
1193 of the first symbol in this file. Some day we should
1194 turn this into an index (fix in hp-symtab-read.c as well).
1195 And it's not even the right byte offset, as we're using
1196 the size of a union! FIXME! */
1197 pst = hpread_start_psymtab (objfile,
1198 section_offsets, /* ?? */
1200 start_adr, /* Low text address */
1201 (start_sym * sizeof (struct dntt_type_block)),
1206 /* Set up to only enter each class referenced in this module once. */
1207 class_entered = malloc (B_BYTES (pxdb_header_p->cd_entries));
1208 B_CLRALL (class_entered, pxdb_header_p->cd_entries);
1210 /* Scan the procedure descriptors for procedures in the current
1211 module, based on the starting addresses. */
1213 syms_in_pst = scan_procs (&curr_pd, qPD, pxdb_header_p->pd_entries,
1215 pst, vt_bits, objfile, section_offsets);
1217 /* Get ending symbol offset */
1220 /* First check for starting index before previous psymtab */
1221 if (pst_syms_count && start_sym < pst_syms_array[pst_syms_count - 1].end)
1223 end_sym = find_next_pst_start (start_sym);
1225 /* Look for next start index of a file or module, or procedure */
1228 int next_file_isym = find_next_file_isym (start_sym, qFD, curr_fd + 1, pxdb_header_p);
1229 int next_module_isym = find_next_module_isym (start_sym, qMD, curr_md + 1, pxdb_header_p);
1230 int next_proc_isym = find_next_proc_isym (start_sym, qPD, curr_pd, pxdb_header_p);
1232 if (next_file_isym && next_module_isym)
1234 /* pick lower of next file or module start index */
1235 end_sym = min (next_file_isym, next_module_isym);
1239 /* one of them is zero, pick the other */
1240 end_sym = max (next_file_isym, next_module_isym);
1243 /* As a precaution, check next procedure index too */
1245 end_sym = next_proc_isym;
1247 end_sym = min (end_sym, next_proc_isym);
1250 /* Couldn't find procedure, file, or module, use globals as default */
1252 end_sym = pxdb_header_p->globals;
1257 printf ("Module psymtab indices: %x to %x\n", start_sym, end_sym);
1261 pst = hpread_end_psymtab (pst,
1262 NULL, /* psymtab_include_list */
1263 0, /* includes_used */
1264 end_sym * sizeof (struct dntt_type_block),
1265 /* byte index in LNTT of end
1266 = capping symbol offset
1267 = LDSYMOFF of nextfile */
1268 end_adr, /* text high */
1269 NULL, /* dependency_list */
1270 0); /* dependencies_used */
1272 record_pst_syms (start_sym, end_sym);
1275 warning ("No symbols in psymtab for module \"%s\" [0x%x].", mod_name_string, curr_md);
1280 printf ("Made new psymtab for module %s (%x to %x), sym %x to %x.\n",
1281 mod_name_string, start_adr, end_adr, CURR_MODULE_ISYM, end_sym);
1285 /* Prepare for the next psymtab. */
1286 global_syms = objfile->global_psymbols.next;
1287 static_syms = objfile->static_psymbols.next;
1288 free (class_entered);
1292 } /* psymtab for module */
1293 } /* psymtab for non-bogus file or module */
1294 } /* End of while loop over all files & modules */
1296 /* There may be some routines after all files and modules -- these will get
1297 inserted in a separate new module of their own */
1298 if (VALID_CURR_PROC)
1300 start_adr = CURR_PROC_START;
1301 end_adr = qPD[pxdb_header_p->pd_entries - 1].adrEnd;
1303 warning ("Found functions beyond end of all files and modules [0x%x].", curr_pd);
1307 printf ("Orphan functions at end, PD %d and beyond (%x to %x)\n",
1308 curr_pd, start_adr, end_adr);
1311 pst = hpread_start_psymtab (objfile,
1312 section_offsets, /* ?? */
1314 start_adr, /* Low text address */
1315 (CURR_PROC_ISYM * sizeof (struct dntt_type_block)),
1320 scan_procs (&curr_pd, qPD, pxdb_header_p->pd_entries,
1322 pst, vt_bits, objfile, section_offsets);
1324 pst = hpread_end_psymtab (pst,
1325 NULL, /* psymtab_include_list */
1326 0, /* includes_used */
1327 pxdb_header_p->globals * sizeof (struct dntt_type_block),
1328 /* byte index in LNTT of end
1329 = capping symbol offset
1330 = LDSYMOFF of nextfile */
1331 end_adr, /* text high */
1332 NULL, /* dependency_list */
1333 0); /* dependencies_used */
1338 /* Now build psts for non-module things (in the tail of
1339 the LNTT, after the last END MODULE entry).
1341 If null psts were kept on the chain, this would be
1342 a solution. FIXME */
1343 pst = hpread_start_psymtab (objfile,
1347 (pxdb_header_p->globals
1348 * sizeof (struct dntt_type_block)),
1349 objfile->global_psymbols.next,
1350 objfile->static_psymbols.next);
1351 hpread_end_psymtab (pst,
1353 (max_LNTT_sym_index * sizeof (struct dntt_type_block)),
1362 } /* End of hpread_quick_traverse. */
1365 /* Get appropriate header, based on pxdb type.
1366 Return value: 1 if ok, 0 if not */
1368 hpread_get_header (objfile, pxdb_header_p)
1369 struct objfile *objfile;
1370 PXDB_header_ptr pxdb_header_p;
1372 asection *pinfo_section, *debug_section, *header_section;
1375 /* Turn on for debugging information */
1376 static int dumping = 0;
1379 header_section = bfd_get_section_by_name (objfile->obfd, "$HEADER$");
1380 if (!header_section)
1382 /* We don't have either PINFO or DEBUG sections. But
1383 stuff like "libc.sl" has no debug info. There's no
1384 need to warn the user of this, as it may be ok. The
1385 caller will figure it out and issue any needed
1389 printf ("==No debug info at all for %s.\n", objfile->name);
1395 /* We would like either a $DEBUG$ or $PINFO$ section.
1396 Once we know which, we can understand the header
1397 data (which we have defined to suit the more common
1399 debug_section = bfd_get_section_by_name (objfile->obfd, "$DEBUG$");
1400 pinfo_section = bfd_get_section_by_name (objfile->obfd, "$PINFO$");
1403 /* The expected case: normal pxdb header. */
1404 bfd_get_section_contents (objfile->obfd, header_section,
1405 pxdb_header_p, 0, sizeof (PXDB_header));
1407 if (!pxdb_header_p->pxdbed)
1409 /* This shouldn't happen if we check in "symfile.c". */
1411 } /* DEBUG section */
1414 else if (pinfo_section)
1416 /* The DOC case; we need to translate this into a
1418 DOC_info_PXDB_header doc_header;
1423 printf ("==OOps, PINFO, let's try to handle this, %s.\n", objfile->name);
1427 bfd_get_section_contents (objfile->obfd,
1430 sizeof (DOC_info_PXDB_header));
1432 if (!doc_header.pxdbed)
1434 /* This shouldn't happen if we check in "symfile.c". */
1435 warning ("File \"%s\" not processed by pxdb!", objfile->name);
1439 /* Copy relevent fields to standard header passed in. */
1440 pxdb_header_p->pd_entries = doc_header.pd_entries;
1441 pxdb_header_p->fd_entries = doc_header.fd_entries;
1442 pxdb_header_p->md_entries = doc_header.md_entries;
1443 pxdb_header_p->pxdbed = doc_header.pxdbed;
1444 pxdb_header_p->bighdr = doc_header.bighdr;
1445 pxdb_header_p->sa_header = doc_header.sa_header;
1446 pxdb_header_p->inlined = doc_header.inlined;
1447 pxdb_header_p->globals = doc_header.globals;
1448 pxdb_header_p->time = doc_header.time;
1449 pxdb_header_p->pg_entries = doc_header.pg_entries;
1450 pxdb_header_p->functions = doc_header.functions;
1451 pxdb_header_p->files = doc_header.files;
1452 pxdb_header_p->cd_entries = doc_header.cd_entries;
1453 pxdb_header_p->aa_entries = doc_header.aa_entries;
1454 pxdb_header_p->oi_entries = doc_header.oi_entries;
1455 pxdb_header_p->version = doc_header.version;
1456 } /* PINFO section */
1462 printf ("==No debug info at all for %s.\n", objfile->name);
1470 } /* End of hpread_get_header */
1471 #endif /* QUICK_LOOK_UP */
1474 /* Initialization for reading native HP C debug symbols from OBJFILE.
1476 Its only purpose in life is to set up the symbol reader's private
1477 per-objfile data structures, and read in the raw contents of the debug
1478 sections (attaching pointers to the debug info into the private data
1481 Since BFD doesn't know how to read debug symbols in a format-independent
1482 way (and may never do so...), we have to do it ourselves. Note we may
1483 be called on a file without native HP C debugging symbols.
1485 FIXME, there should be a cleaner peephole into the BFD environment
1488 hpread_symfile_init (objfile)
1489 struct objfile *objfile;
1491 asection *vt_section, *slt_section, *lntt_section, *gntt_section;
1493 /* Allocate struct to keep track of the symfile */
1494 objfile->sym_private = (PTR)
1495 xmmalloc (objfile->md, sizeof (struct hpread_symfile_info));
1496 memset (objfile->sym_private, 0, sizeof (struct hpread_symfile_info));
1498 /* We haven't read in any types yet. */
1499 TYPE_VECTOR (objfile) = 0;
1501 /* Read in data from the $GNTT$ subspace. */
1502 gntt_section = bfd_get_section_by_name (objfile->obfd, "$GNTT$");
1507 = obstack_alloc (&objfile->symbol_obstack,
1508 bfd_section_size (objfile->obfd, gntt_section));
1510 bfd_get_section_contents (objfile->obfd, gntt_section, GNTT (objfile),
1511 0, bfd_section_size (objfile->obfd, gntt_section));
1513 GNTT_SYMCOUNT (objfile)
1514 = bfd_section_size (objfile->obfd, gntt_section)
1515 / sizeof (struct dntt_type_block);
1517 /* Read in data from the $LNTT$ subspace. Also keep track of the number
1520 FIXME: this could be moved into the psymtab-to-symtab expansion
1521 code, and save startup time. At the moment this data is
1522 still used, though. We'd need a way to tell hp-symtab-read.c
1523 whether or not to load the LNTT. */
1524 lntt_section = bfd_get_section_by_name (objfile->obfd, "$LNTT$");
1529 = obstack_alloc (&objfile->symbol_obstack,
1530 bfd_section_size (objfile->obfd, lntt_section));
1532 bfd_get_section_contents (objfile->obfd, lntt_section, LNTT (objfile),
1533 0, bfd_section_size (objfile->obfd, lntt_section));
1535 LNTT_SYMCOUNT (objfile)
1536 = bfd_section_size (objfile->obfd, lntt_section)
1537 / sizeof (struct dntt_type_block);
1539 /* Read in data from the $SLT$ subspace. $SLT$ contains information
1540 on source line numbers. */
1541 slt_section = bfd_get_section_by_name (objfile->obfd, "$SLT$");
1546 obstack_alloc (&objfile->symbol_obstack,
1547 bfd_section_size (objfile->obfd, slt_section));
1549 bfd_get_section_contents (objfile->obfd, slt_section, SLT (objfile),
1550 0, bfd_section_size (objfile->obfd, slt_section));
1552 /* Read in data from the $VT$ subspace. $VT$ contains things like
1553 names and constants. Keep track of the number of symbols in the VT. */
1554 vt_section = bfd_get_section_by_name (objfile->obfd, "$VT$");
1558 VT_SIZE (objfile) = bfd_section_size (objfile->obfd, vt_section);
1561 (char *) obstack_alloc (&objfile->symbol_obstack,
1564 bfd_get_section_contents (objfile->obfd, vt_section, VT (objfile),
1565 0, VT_SIZE (objfile));
1568 /* Scan and build partial symbols for a symbol file.
1570 The minimal symbol table (either SOM or HP a.out) has already been
1571 read in; all we need to do is setup partial symbols based on the
1572 native debugging information.
1574 Note that the minimal table is produced by the linker, and has
1575 only global routines in it; the psymtab is based on compiler-
1576 generated debug information and has non-global
1577 routines in it as well as files and class information.
1579 We assume hpread_symfile_init has been called to initialize the
1580 symbol reader's private data structures.
1582 SECTION_OFFSETS contains offsets relative to which the symbols in the
1583 various sections are (depending where the sections were actually loaded).
1584 MAINLINE is true if we are reading the main symbol table (as
1585 opposed to a shared lib or dynamically loaded file). */
1587 hpread_build_psymtabs (objfile, section_offsets, mainline)
1588 struct objfile *objfile;
1589 struct section_offsets *section_offsets;
1594 /* Turn this on to get debugging output. */
1595 static int dumping = 0;
1599 int past_first_source_file = 0;
1600 struct cleanup *old_chain;
1602 int hp_symnum, symcount, i;
1605 union dnttentry *dn_bufp;
1611 /* Current partial symtab */
1612 struct partial_symtab *pst;
1614 /* List of current psymtab's include files */
1615 char **psymtab_include_list;
1616 int includes_allocated;
1619 /* Index within current psymtab dependency list */
1620 struct partial_symtab **dependency_list;
1621 int dependencies_used, dependencies_allocated;
1623 /* Just in case the stabs reader left turds lying around. */
1624 free_pending_blocks ();
1625 make_cleanup (really_free_pendings, 0);
1627 pst = (struct partial_symtab *) 0;
1629 /* We shouldn't use alloca, instead use malloc/free. Doing so avoids
1630 a number of problems with cross compilation and creating useless holes
1631 in the stack when we have to allocate new entries. FIXME. */
1633 includes_allocated = 30;
1635 psymtab_include_list = (char **) alloca (includes_allocated *
1638 dependencies_allocated = 30;
1639 dependencies_used = 0;
1641 (struct partial_symtab **) alloca (dependencies_allocated *
1642 sizeof (struct partial_symtab *));
1644 old_chain = make_cleanup ((make_cleanup_func) free_objfile, objfile);
1646 last_source_file = 0;
1648 #ifdef QUICK_LOOK_UP
1650 /* Begin code for new-style loading of quick look-up tables. */
1652 /* elz: this checks whether the file has beeen processed by pxdb.
1653 If not we would like to try to read the psymbols in
1654 anyway, but it turns out to be not so easy. So this could
1655 actually be commented out, but I leave it in, just in case
1656 we decide to add support for non-pxdb-ed stuff in the future. */
1657 PXDB_header pxdb_header;
1658 int found_modules_in_program;
1660 if (hpread_get_header (objfile, &pxdb_header))
1662 /* Build a minimal table. No types, no global variables,
1663 no include files.... */
1666 printf ("\nNew method for %s\n", objfile->name);
1669 /* elz: quick_traverse returns true if it found
1670 some modules in the main source file, other
1672 In C and C++, all the files have MODULES entries
1673 in the LNTT, and the quick table traverse is all
1674 based on finding these MODULES entries. Without
1675 those it cannot work.
1676 It happens that F77 programs don't have MODULES
1677 so the quick traverse gets confused. F90 programs
1678 have modules, and the quick method still works.
1679 So, if modules (other than those in end.c) are
1680 not found we give up on the quick table stuff,
1681 and fall back on the slower method */
1682 found_modules_in_program = hpread_quick_traverse (objfile,
1688 discard_cleanups (old_chain);
1690 /* Set up to scan the global section of the LNTT.
1692 This field is not always correct: if there are
1693 no globals, it will point to the last record in
1694 the regular LNTT, which is usually an END MODULE.
1696 Since it might happen that there could be a file
1697 with just one global record, there's no way to
1698 tell other than by looking at the record, so that's
1700 if (found_modules_in_program)
1701 scan_start = pxdb_header.globals;
1707 printf ("\nGoing on to old method for %s\n", objfile->name);
1711 #endif /* QUICK_LOOK_UP */
1713 /* Make two passes, one over the GNTT symbols, the other for the
1716 JB comment: above isn't true--they only make one pass, over
1718 for (i = 0; i < 1; i++)
1720 int within_function = 0;
1723 symcount = GNTT_SYMCOUNT (objfile);
1725 symcount = LNTT_SYMCOUNT (objfile);
1728 for (hp_symnum = scan_start; hp_symnum < symcount; hp_symnum++)
1732 dn_bufp = hpread_get_gntt (hp_symnum, objfile);
1734 dn_bufp = hpread_get_lntt (hp_symnum, objfile);
1736 if (dn_bufp->dblock.extension)
1739 /* Only handle things which are necessary for minimal symbols.
1740 everything else is ignored. */
1741 switch (dn_bufp->dblock.kind)
1743 case DNTT_TYPE_SRCFILE:
1745 #ifdef QUICK_LOOK_UP
1746 if (scan_start == hp_symnum
1747 && symcount == hp_symnum + 1)
1749 /* If there are NO globals in an executable,
1750 PXDB's index to the globals will point to
1751 the last record in the file, which
1752 could be this record. (this happened for F77 libraries)
1753 ignore it and be done! */
1756 #endif /* QUICK_LOOK_UP */
1758 /* A source file of some kind. Note this may simply
1759 be an included file. */
1760 SET_NAMESTRING (dn_bufp, &namestring, objfile);
1762 /* Check if this is the source file we are already working
1764 if (pst && !strcmp (namestring, pst->filename))
1767 /* Check if this is an include file, if so check if we have
1768 already seen it. Add it to the include list */
1769 p = strrchr (namestring, '.');
1770 if (!strcmp (p, ".h"))
1775 for (j = 0; j < includes_used; j++)
1776 if (!strcmp (namestring, psymtab_include_list[j]))
1784 /* Add it to the list of includes seen so far and
1785 allocate more include space if necessary. */
1786 psymtab_include_list[includes_used++] = namestring;
1787 if (includes_used >= includes_allocated)
1789 char **orig = psymtab_include_list;
1791 psymtab_include_list = (char **)
1792 alloca ((includes_allocated *= 2) *
1794 memcpy ((PTR) psymtab_include_list, (PTR) orig,
1795 includes_used * sizeof (char *));
1804 pst->filename = (char *)
1805 obstack_alloc (&pst->objfile->psymbol_obstack,
1806 strlen (namestring) + 1);
1807 strcpy (pst->filename, namestring);
1814 /* This is a bonafide new source file.
1815 End the current partial symtab and start a new one. */
1817 if (pst && past_first_source_file)
1819 hpread_end_psymtab (pst, psymtab_include_list,
1822 * sizeof (struct dntt_type_block)),
1824 dependency_list, dependencies_used);
1825 pst = (struct partial_symtab *) 0;
1827 dependencies_used = 0;
1830 past_first_source_file = 1;
1832 valu = hpread_get_textlow (i, hp_symnum, objfile, symcount);
1833 valu += ANOFFSET (section_offsets, SECT_OFF_TEXT);
1834 pst = hpread_start_psymtab (objfile, section_offsets,
1837 * sizeof (struct dntt_type_block)),
1838 objfile->global_psymbols.next,
1839 objfile->static_psymbols.next);
1845 case DNTT_TYPE_MODULE:
1846 /* A source file. It's still unclear to me what the
1847 real difference between a DNTT_TYPE_SRCFILE and DNTT_TYPE_MODULE
1848 is supposed to be. */
1850 /* First end the previous psymtab */
1853 hpread_end_psymtab (pst, psymtab_include_list, includes_used,
1855 * sizeof (struct dntt_type_block)),
1857 dependency_list, dependencies_used);
1858 pst = (struct partial_symtab *) 0;
1860 dependencies_used = 0;
1864 /* Now begin a new module and a new psymtab for it */
1865 SET_NAMESTRING (dn_bufp, &namestring, objfile);
1866 valu = hpread_get_textlow (i, hp_symnum, objfile, symcount);
1867 valu += ANOFFSET (section_offsets, SECT_OFF_TEXT);
1870 pst = hpread_start_psymtab (objfile, section_offsets,
1873 * sizeof (struct dntt_type_block)),
1874 objfile->global_psymbols.next,
1875 objfile->static_psymbols.next);
1881 case DNTT_TYPE_FUNCTION:
1882 case DNTT_TYPE_ENTRY:
1883 /* The beginning of a function. DNTT_TYPE_ENTRY may also denote
1884 a secondary entry point. */
1885 valu = dn_bufp->dfunc.hiaddr + ANOFFSET (section_offsets,
1887 if (valu > texthigh)
1889 valu = dn_bufp->dfunc.lowaddr +
1890 ANOFFSET (section_offsets, SECT_OFF_TEXT);
1891 SET_NAMESTRING (dn_bufp, &namestring, objfile);
1892 if (dn_bufp->dfunc.global)
1893 add_psymbol_to_list (namestring, strlen (namestring),
1894 VAR_NAMESPACE, LOC_BLOCK,
1895 &objfile->global_psymbols, valu,
1896 0, language_unknown, objfile);
1898 add_psymbol_to_list (namestring, strlen (namestring),
1899 VAR_NAMESPACE, LOC_BLOCK,
1900 &objfile->static_psymbols, valu,
1901 0, language_unknown, objfile);
1902 within_function = 1;
1905 case DNTT_TYPE_DOC_FUNCTION:
1906 valu = dn_bufp->ddocfunc.hiaddr + ANOFFSET (section_offsets,
1908 if (valu > texthigh)
1910 valu = dn_bufp->ddocfunc.lowaddr +
1911 ANOFFSET (section_offsets, SECT_OFF_TEXT);
1912 SET_NAMESTRING (dn_bufp, &namestring, objfile);
1913 if (dn_bufp->ddocfunc.global)
1914 add_psymbol_to_list (namestring, strlen (namestring),
1915 VAR_NAMESPACE, LOC_BLOCK,
1916 &objfile->global_psymbols, valu,
1917 0, language_unknown, objfile);
1919 add_psymbol_to_list (namestring, strlen (namestring),
1920 VAR_NAMESPACE, LOC_BLOCK,
1921 &objfile->static_psymbols, valu,
1922 0, language_unknown, objfile);
1923 within_function = 1;
1926 case DNTT_TYPE_BEGIN:
1928 /* We don't check MODULE end here, because there can be
1929 symbols beyond the module end which properly belong to the
1930 current psymtab -- so we wait till the next MODULE start */
1933 #ifdef QUICK_LOOK_UP
1934 if (scan_start == hp_symnum
1935 && symcount == hp_symnum + 1)
1937 /* If there are NO globals in an executable,
1938 PXDB's index to the globals will point to
1939 the last record in the file, which is
1940 probably an END MODULE, i.e. this record.
1941 ignore it and be done! */
1944 #endif /* QUICK_LOOK_UP */
1946 /* Scope block begin/end. We only care about function
1947 and file blocks right now. */
1949 if ((dn_bufp->dend.endkind == DNTT_TYPE_FUNCTION) ||
1950 (dn_bufp->dend.endkind == DNTT_TYPE_DOC_FUNCTION))
1951 within_function = 0;
1954 case DNTT_TYPE_SVAR:
1955 case DNTT_TYPE_DVAR:
1956 case DNTT_TYPE_TYPEDEF:
1957 case DNTT_TYPE_TAGDEF:
1959 /* Variables, typedefs an the like. */
1960 enum address_class storage;
1961 namespace_enum namespace;
1963 /* Don't add locals to the partial symbol table. */
1965 && (dn_bufp->dblock.kind == DNTT_TYPE_SVAR
1966 || dn_bufp->dblock.kind == DNTT_TYPE_DVAR))
1969 /* TAGDEFs go into the structure namespace. */
1970 if (dn_bufp->dblock.kind == DNTT_TYPE_TAGDEF)
1971 namespace = STRUCT_NAMESPACE;
1973 namespace = VAR_NAMESPACE;
1975 /* What kind of "storage" does this use? */
1976 if (dn_bufp->dblock.kind == DNTT_TYPE_SVAR)
1977 storage = LOC_STATIC;
1978 else if (dn_bufp->dblock.kind == DNTT_TYPE_DVAR
1979 && dn_bufp->ddvar.regvar)
1980 storage = LOC_REGISTER;
1981 else if (dn_bufp->dblock.kind == DNTT_TYPE_DVAR)
1982 storage = LOC_LOCAL;
1984 storage = LOC_UNDEF;
1986 SET_NAMESTRING (dn_bufp, &namestring, objfile);
1989 pst = hpread_start_psymtab (objfile, section_offsets,
1992 * sizeof (struct dntt_type_block)),
1993 objfile->global_psymbols.next,
1994 objfile->static_psymbols.next);
1997 /* Compute address of the data symbol */
1998 valu = dn_bufp->dsvar.location;
1999 /* Relocate in case it's in a shared library */
2000 if (storage == LOC_STATIC)
2001 valu += ANOFFSET (section_offsets, SECT_OFF_DATA);
2003 /* Luckily, dvar, svar, typedef, and tagdef all
2004 have their "global" bit in the same place, so it works
2005 (though it's bad programming practice) to reference
2006 "dsvar.global" even though we may be looking at
2007 any of the above four types. */
2008 if (dn_bufp->dsvar.global)
2010 add_psymbol_to_list (namestring, strlen (namestring),
2012 &objfile->global_psymbols,
2014 0, language_unknown, objfile);
2018 add_psymbol_to_list (namestring, strlen (namestring),
2020 &objfile->static_psymbols,
2022 0, language_unknown, objfile);
2025 /* For TAGDEF's, the above code added the tagname to the
2026 struct namespace. This will cause tag "t" to be found
2027 on a reference of the form "(struct t) x". But for
2028 C++ classes, "t" will also be a typename, which we
2029 want to find on a reference of the form "ptype t".
2030 Therefore, we also add "t" to the var namespace.
2031 Do the same for enum's due to the way aCC generates
2032 debug info for these (see more extended comment
2033 in hp-symtab-read.c).
2034 We do the same for templates, so that "ptype t"
2035 where "t" is a template also works. */
2036 if (dn_bufp->dblock.kind == DNTT_TYPE_TAGDEF &&
2037 dn_bufp->dtype.type.dnttp.index < LNTT_SYMCOUNT (objfile))
2039 int global = dn_bufp->dtag.global;
2040 /* Look ahead to see if it's a C++ class */
2041 dn_bufp = hpread_get_lntt (dn_bufp->dtype.type.dnttp.index, objfile);
2042 if (dn_bufp->dblock.kind == DNTT_TYPE_CLASS ||
2043 dn_bufp->dblock.kind == DNTT_TYPE_ENUM ||
2044 dn_bufp->dblock.kind == DNTT_TYPE_TEMPLATE)
2048 add_psymbol_to_list (namestring, strlen (namestring),
2049 VAR_NAMESPACE, storage,
2050 &objfile->global_psymbols,
2051 dn_bufp->dsvar.location,
2052 0, language_unknown, objfile);
2056 add_psymbol_to_list (namestring, strlen (namestring),
2057 VAR_NAMESPACE, storage,
2058 &objfile->static_psymbols,
2059 dn_bufp->dsvar.location,
2060 0, language_unknown, objfile);
2067 case DNTT_TYPE_MEMENUM:
2068 case DNTT_TYPE_CONST:
2069 /* Constants and members of enumerated types. */
2070 SET_NAMESTRING (dn_bufp, &namestring, objfile);
2073 pst = hpread_start_psymtab (objfile, section_offsets,
2076 * sizeof (struct dntt_type_block)),
2077 objfile->global_psymbols.next,
2078 objfile->static_psymbols.next);
2080 if (dn_bufp->dconst.global)
2081 add_psymbol_to_list (namestring, strlen (namestring),
2082 VAR_NAMESPACE, LOC_CONST,
2083 &objfile->global_psymbols, 0,
2084 0, language_unknown, objfile);
2086 add_psymbol_to_list (namestring, strlen (namestring),
2087 VAR_NAMESPACE, LOC_CONST,
2088 &objfile->static_psymbols, 0,
2089 0, language_unknown, objfile);
2097 /* End any pending partial symbol table. */
2100 hpread_end_psymtab (pst, psymtab_include_list, includes_used,
2101 hp_symnum * sizeof (struct dntt_type_block),
2102 0, dependency_list, dependencies_used);
2105 discard_cleanups (old_chain);
2108 /* Perform any local cleanups required when we are done with a particular
2109 objfile. I.E, we are in the process of discarding all symbol information
2110 for an objfile, freeing up all memory held for it, and unlinking the
2111 objfile struct from the global list of known objfiles. */
2114 hpread_symfile_finish (objfile)
2115 struct objfile *objfile;
2117 if (objfile->sym_private != NULL)
2119 mfree (objfile->md, objfile->sym_private);
2124 /* The remaining functions are all for internal use only. */
2126 /* Various small functions to get entries in the debug symbol sections. */
2129 hpread_get_lntt (index, objfile)
2131 struct objfile *objfile;
2133 return (union dnttentry *)
2134 &(LNTT (objfile)[(index * sizeof (struct dntt_type_block))]);
2137 static union dnttentry *
2138 hpread_get_gntt (index, objfile)
2140 struct objfile *objfile;
2142 return (union dnttentry *)
2143 &(GNTT (objfile)[(index * sizeof (struct dntt_type_block))]);
2147 hpread_get_slt (index, objfile)
2149 struct objfile *objfile;
2151 return (union sltentry *) &(SLT (objfile)[index * sizeof (union sltentry)]);
2154 /* Get the low address associated with some symbol (typically the start
2155 of a particular source file or module). Since that information is not
2156 stored as part of the DNTT_TYPE_MODULE or DNTT_TYPE_SRCFILE symbol we must infer it from
2157 the existance of DNTT_TYPE_FUNCTION symbols. */
2159 static unsigned long
2160 hpread_get_textlow (global, index, objfile, symcount)
2163 struct objfile *objfile;
2166 union dnttentry *dn_bufp;
2167 struct minimal_symbol *msymbol;
2169 /* Look for a DNTT_TYPE_FUNCTION symbol. */
2170 if (index < symcount) /* symcount is the number of symbols in */
2171 { /* the dbinfo, LNTT table */
2175 dn_bufp = hpread_get_gntt (index++, objfile);
2177 dn_bufp = hpread_get_lntt (index++, objfile);
2179 while (dn_bufp->dblock.kind != DNTT_TYPE_FUNCTION
2180 && dn_bufp->dblock.kind != DNTT_TYPE_DOC_FUNCTION
2181 && dn_bufp->dblock.kind != DNTT_TYPE_END
2182 && index < symcount);
2185 /* Avoid going past a DNTT_TYPE_END when looking for a DNTT_TYPE_FUNCTION. This
2186 might happen when a sourcefile has no functions. */
2187 if (dn_bufp->dblock.kind == DNTT_TYPE_END)
2190 /* Avoid going past the end of the LNTT file */
2191 if (index == symcount)
2194 /* The minimal symbols are typically more accurate for some reason. */
2195 if (dn_bufp->dblock.kind == DNTT_TYPE_FUNCTION)
2196 msymbol = lookup_minimal_symbol (dn_bufp->dfunc.name + VT (objfile), NULL,
2198 else /* must be a DNTT_TYPE_DOC_FUNCTION */
2199 msymbol = lookup_minimal_symbol (dn_bufp->ddocfunc.name + VT (objfile), NULL,
2203 return SYMBOL_VALUE_ADDRESS (msymbol);
2205 return dn_bufp->dfunc.lowaddr;
2208 /* Allocate and partially fill a partial symtab. It will be
2209 completely filled at the end of the symbol list.
2211 SYMFILE_NAME is the name of the symbol-file we are reading from, and ADDR
2212 is the address relative to which its symbols are (incremental) or 0
2215 static struct partial_symtab *
2216 hpread_start_psymtab (objfile, section_offsets,
2217 filename, textlow, ldsymoff, global_syms, static_syms)
2218 struct objfile *objfile;
2219 struct section_offsets *section_offsets;
2223 struct partial_symbol **global_syms;
2224 struct partial_symbol **static_syms;
2226 int offset = ANOFFSET (section_offsets, SECT_OFF_TEXT);
2227 extern void hpread_psymtab_to_symtab ();
2228 struct partial_symtab *result =
2229 start_psymtab_common (objfile, section_offsets,
2230 filename, textlow, global_syms, static_syms);
2232 result->textlow += offset;
2233 result->read_symtab_private = (char *)
2234 obstack_alloc (&objfile->psymbol_obstack, sizeof (struct symloc));
2235 LDSYMOFF (result) = ldsymoff;
2236 result->read_symtab = hpread_psymtab_to_symtab;
2242 /* Close off the current usage of PST.
2243 Returns PST or NULL if the partial symtab was empty and thrown away.
2245 capping_symbol_offset --Byte index in LNTT or GNTT of the
2246 last symbol processed during the build
2247 of the previous pst.
2249 FIXME: List variables and peculiarities of same. */
2251 static struct partial_symtab *
2252 hpread_end_psymtab (pst, include_list, num_includes, capping_symbol_offset,
2253 capping_text, dependency_list, number_dependencies)
2254 struct partial_symtab *pst;
2255 char **include_list;
2257 int capping_symbol_offset;
2258 CORE_ADDR capping_text;
2259 struct partial_symtab **dependency_list;
2260 int number_dependencies;
2263 struct objfile *objfile = pst->objfile;
2264 int offset = ANOFFSET (pst->section_offsets, SECT_OFF_TEXT);
2267 /* Turn on to see what kind of a psymtab we've built. */
2268 static int dumping = 0;
2271 if (capping_symbol_offset != -1)
2272 LDSYMLEN (pst) = capping_symbol_offset - LDSYMOFF (pst);
2275 pst->texthigh = capping_text + offset;
2277 pst->n_global_syms =
2278 objfile->global_psymbols.next - (objfile->global_psymbols.list + pst->globals_offset);
2279 pst->n_static_syms =
2280 objfile->static_psymbols.next - (objfile->static_psymbols.list + pst->statics_offset);
2285 printf ("\nPst %s, LDSYMOFF %x (%x), LDSYMLEN %x (%x), globals %d, statics %d\n",
2288 LDSYMOFF (pst) / sizeof (struct dntt_type_block),
2290 LDSYMLEN (pst) / sizeof (struct dntt_type_block),
2291 pst->n_global_syms, pst->n_static_syms);
2295 pst->number_of_dependencies = number_dependencies;
2296 if (number_dependencies)
2298 pst->dependencies = (struct partial_symtab **)
2299 obstack_alloc (&objfile->psymbol_obstack,
2300 number_dependencies * sizeof (struct partial_symtab *));
2301 memcpy (pst->dependencies, dependency_list,
2302 number_dependencies * sizeof (struct partial_symtab *));
2305 pst->dependencies = 0;
2307 for (i = 0; i < num_includes; i++)
2309 struct partial_symtab *subpst =
2310 allocate_psymtab (include_list[i], objfile);
2312 subpst->section_offsets = pst->section_offsets;
2313 subpst->read_symtab_private =
2314 (char *) obstack_alloc (&objfile->psymbol_obstack,
2315 sizeof (struct symloc));
2319 subpst->texthigh = 0;
2321 /* We could save slight bits of space by only making one of these,
2322 shared by the entire set of include files. FIXME-someday. */
2323 subpst->dependencies = (struct partial_symtab **)
2324 obstack_alloc (&objfile->psymbol_obstack,
2325 sizeof (struct partial_symtab *));
2326 subpst->dependencies[0] = pst;
2327 subpst->number_of_dependencies = 1;
2329 subpst->globals_offset =
2330 subpst->n_global_syms =
2331 subpst->statics_offset =
2332 subpst->n_static_syms = 0;
2336 subpst->read_symtab = pst->read_symtab;
2339 sort_pst_symbols (pst);
2341 /* If there is already a psymtab or symtab for a file of this name, remove it.
2342 (If there is a symtab, more drastic things also happen.)
2343 This happens in VxWorks. */
2344 free_named_symtabs (pst->filename);
2346 if (num_includes == 0
2347 && number_dependencies == 0
2348 && pst->n_global_syms == 0
2349 && pst->n_static_syms == 0)
2351 /* Throw away this psymtab, it's empty. We can't deallocate it, since
2352 it is on the obstack, but we can forget to chain it on the list.
2353 Empty psymtabs happen as a result of header files which don't have
2354 any symbols in them. There can be a lot of them. But this check
2355 is wrong, in that a psymtab with N_SLINE entries but nothing else
2356 is not empty, but we don't realize that. Fixing that without slowing
2357 things down might be tricky.
2358 It's also wrong if we're using the quick look-up tables, as
2359 we can get empty psymtabs from modules with no routines in
2362 discard_psymtab (pst);
2364 /* Indicate that psymtab was thrown away. */
2365 pst = (struct partial_symtab *) NULL;
2372 /* End of hp-psymtab-read.c */
2374 /* Set indentation to 4 spaces for Emacs; this file is
2375 mostly non-GNU-ish in its style :-( */
2378 ***c - basic - offset:4