]> Git Repo - binutils.git/blob - gdb/hp-psymtab-read.c
Wed Jan 27 16:50:25 1999 Elena Zannoni <[email protected]>
[binutils.git] / gdb / hp-psymtab-read.c
1 /* Read hp debug symbols and convert to internal format, for GDB.
2    Copyright 1993, 1996, 1998, 1999 Free Software Foundation, Inc.
3
4    This file is part of GDB.
5
6    This program is free software; you can redistribute it and/or modify
7    it under the terms of the GNU General Public License as published by
8    the Free Software Foundation; either version 2 of the License, or
9    (at your option) any later version.
10
11    This program is distributed in the hope that it will be useful,
12    but WITHOUT ANY WARRANTY; without even the implied warranty of
13    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14    GNU General Public License for more details.
15
16    You should have received a copy of the GNU General Public License
17    along with this program; if not, write to the Free Software
18    Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19
20    Written by the Center for Software Science at the University of Utah
21    and by Cygnus Support.  */
22
23 /* Common include file for hp_symtab_read.c and hp_psymtab_read.c.
24    This has nested includes of a bunch of stuff. */
25 #include "hpread.h"
26 #include "demangle.h"
27
28 /* To generate dumping code, uncomment this define.  The dumping
29    itself is controlled by routine-local statics called "dumping". */
30 /* #define DUMPING         1 */
31
32 /* To use the quick look-up tables, uncomment this define. */
33 #define QUICK_LOOK_UP      0
34
35 /* To call PXDB to process un-processed files, uncomment this define. */
36 #define USE_PXDB           1
37
38 /* Forward procedure declarations */
39
40 void hpread_symfile_init
41   PARAMS ((struct objfile *));
42
43 void hpread_build_psymtabs
44   PARAMS ((struct objfile *, struct section_offsets *, int));
45
46 void hpread_symfile_finish
47   PARAMS ((struct objfile *));
48
49 static union dnttentry *hpread_get_gntt
50   PARAMS ((int, struct objfile *));
51
52 static unsigned long hpread_get_textlow
53   PARAMS ((int, int, struct objfile *, int));
54
55 static struct partial_symtab *hpread_start_psymtab
56   PARAMS ((struct objfile *, struct section_offsets *, char *, CORE_ADDR, int,
57            struct partial_symbol **, struct partial_symbol **));
58
59 static struct partial_symtab *hpread_end_psymtab
60   PARAMS ((struct partial_symtab *, char **, int, int, CORE_ADDR,
61            struct partial_symtab **, int));
62
63 /* End of forward routine declarations */
64
65 #ifdef USE_PXDB
66
67 /* NOTE use of system files!  May not be portable. */
68
69 #define PXDB_SVR4 "/opt/langtools/bin/pxdb"
70 #define PXDB_BSD  "/usr/bin/pxdb"
71
72 #include <stdlib.h>
73 #include <string.h>
74 #include <unistd.h>
75
76 /* check for the existance of a file, given its full pathname */
77 int
78 file_exists (filename)
79      char *filename;
80 {
81   if (filename)
82     return (access (filename, F_OK) == 0);
83   return 0;
84 }
85
86
87 /* Translate from the "hp_language" enumeration in hp-symtab.h
88    used in the debug info to gdb's generic enumeration in defs.h. */
89 static enum language
90 trans_lang (in_lang)
91      enum hp_language in_lang;
92 {
93   if (in_lang == HP_LANGUAGE_C)
94     return language_c;
95
96   else if (in_lang == HP_LANGUAGE_CPLUSPLUS)
97     return language_cplus;
98
99   else if (in_lang == HP_LANGUAGE_F77)
100     return language_fortran;
101
102   else
103     return language_unknown;
104 }
105
106 static char main_string[] = "main";
107 \f
108 /* Call PXDB to process our file.
109
110    Approach copied from DDE's "dbgk_run_pxdb".  Note: we
111    don't check for BSD location of pxdb, nor for existance
112    of pxdb itself, etc.
113
114    NOTE: uses system function and string functions directly.
115
116    Return value: 1 if ok, 0 if not */
117 int
118 hpread_call_pxdb (file_name)
119      char *file_name;
120 {
121   char *p;
122   int status;
123   int retval;
124
125   if (file_exists (PXDB_SVR4))
126     {
127       p = malloc (strlen (PXDB_SVR4) + strlen (file_name) + 2);
128       strcpy (p, PXDB_SVR4);
129       strcat (p, " ");
130       strcat (p, file_name);
131
132       warning ("File not processed by pxdb--about to process now.\n");
133       status = system (p);
134
135       retval = (status == 0);
136     }
137   else
138     {
139       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);
140
141       retval = 0;
142     }
143   return retval;
144 }                               /* hpread_call_pxdb */
145 \f
146
147 /* Return 1 if the file turns out to need pre-processing
148    by PXDB, and we have thus called PXDB to do this processing
149    and the file therefore needs to be re-loaded.  Otherwise
150    return 0. */
151 int
152 hpread_pxdb_needed (sym_bfd)
153      bfd *sym_bfd;
154 {
155   asection *pinfo_section, *debug_section, *header_section;
156   unsigned int do_pxdb;
157   char *buf;
158   bfd_size_type header_section_size;
159
160   unsigned long tmp;
161   unsigned int pxdbed;
162
163   header_section = bfd_get_section_by_name (sym_bfd, "$HEADER$");
164   if (!header_section)
165     {
166       return 0;                 /* No header at all, can't recover... */
167     }
168
169   debug_section = bfd_get_section_by_name (sym_bfd, "$DEBUG$");
170   pinfo_section = bfd_get_section_by_name (sym_bfd, "$PINFO$");
171
172   if (pinfo_section && !debug_section)
173     {
174       /* Debug info with DOC, has different header format. 
175          this only happens if the file was pxdbed and compiled optimized
176          otherwise the PINFO section is not there. */
177       header_section_size = bfd_section_size (objfile->obfd, header_section);
178
179       if (header_section_size == (bfd_size_type) sizeof (DOC_info_PXDB_header))
180         {
181           buf = alloca (sizeof (DOC_info_PXDB_header));
182
183           if (!bfd_get_section_contents (sym_bfd,
184                                          header_section,
185                                          buf, 0,
186                                          header_section_size))
187             error ("bfd_get_section_contents\n");
188
189           tmp = bfd_get_32 (sym_bfd, (bfd_byte *) (buf + sizeof (int) * 4));
190           pxdbed = (tmp >> 31) & 0x1;
191
192           if (!pxdbed)
193             error ("file debug header info invalid\n");
194           do_pxdb = 0;
195         }
196
197       else
198         error ("invalid $HEADER$ size in executable \n");
199     }
200
201   else
202     {
203
204       /* this can be three different cases:
205          1. pxdbed and not doc
206          - DEBUG and HEADER sections are there
207          - header is PXDB_header type
208          - pxdbed flag is set to 1
209
210          2. not pxdbed and doc
211          - DEBUG and HEADER  sections are there
212          - header is DOC_info_header type
213          - pxdbed flag is set to 0
214
215          3. not pxdbed and not doc
216          - DEBUG and HEADER sections are there
217          - header is XDB_header type
218          - pxdbed flag is set to 0
219
220          NOTE: the pxdbed flag is meaningful also in the not
221          already pxdb processed version of the header,
222          because in case on non-already processed by pxdb files
223          that same bit in the header would be always zero.
224          Why? Because the bit is the leftmost bit of a word
225          which contains a 'length' which is always a positive value
226          so that bit is never set to 1 (otherwise it would be negative)
227
228          Given the above, we have two choices : either we ignore the
229          size of the header itself and just look at the pxdbed field,
230          or we check the size and then we (for safety and paranoia related
231          issues) check the bit.
232          The first solution is used by DDE, the second by PXDB itself.
233          I am using the second one here, because I already wrote it,
234          and it is the end of a long day.
235          Also, using the first approach would still involve size issues
236          because we need to read in the contents of the header section, and
237          give the correct amount of stuff we want to read to the
238          get_bfd_section_contents function.  */
239
240       /* decide which case depending on the size of the header section.
241          The size is as defined in hp-symtab.h  */
242
243       header_section_size = bfd_section_size (objfile->obfd, header_section);
244
245       if (header_section_size == (bfd_size_type) sizeof (PXDB_header))  /* pxdb and not doc */
246         {
247
248           buf = alloca (sizeof (PXDB_header));
249           if (!bfd_get_section_contents (sym_bfd,
250                                          header_section,
251                                          buf, 0,
252                                          header_section_size))
253             error ("bfd_get_section_contents\n");
254
255           tmp = bfd_get_32 (sym_bfd, (bfd_byte *) (buf + sizeof (int) * 3));
256           pxdbed = (tmp >> 31) & 0x1;
257
258           if (pxdbed)
259             do_pxdb = 0;
260           else
261             error ("file debug header invalid\n");
262         }
263       else                      /*not pxdbed and doc OR not pxdbed and non doc */
264         do_pxdb = 1;
265     }
266
267   if (do_pxdb)
268     {
269       return 1;
270     }
271   else
272     {
273       return 0;
274     }
275 }                               /* hpread_pxdb_needed */
276
277 #endif
278
279 #ifdef QUICK_LOOK_UP
280
281 /* This flag can be set to zero to use the old
282    style psymtab (build from a scan of the LNTT)
283    or to one to try to use the quick look-up
284    tables. */
285 int psym_new_style = 1;
286 \f
287
288
289 /* Code to handle quick lookup-tables follows */
290
291
292 /* Some useful macros */
293 #define VALID_FILE(i)   ((i) < pxdb_header_p->fd_entries)
294 #define VALID_MODULE(i) ((i) < pxdb_header_p->md_entries)
295 #define VALID_PROC(i)   ((i) < pxdb_header_p->pd_entries)
296 #define VALID_CLASS(i)  ((i) < pxdb_header_p->cd_entries)
297
298 #define FILE_START(i)    (qFD[i].adrStart)
299 #define MODULE_START(i) (qMD[i].adrStart)
300 #define PROC_START(i)    (qPD[i].adrStart)
301
302 #define FILE_END(i)   (qFD[i].adrEnd)
303 #define MODULE_END(i) (qMD[i].adrEnd)
304 #define PROC_END(i)   (qPD[i].adrEnd)
305
306 #define FILE_ISYM(i)   (qFD[i].isym)
307 #define MODULE_ISYM(i) (qMD[i].isym)
308 #define PROC_ISYM(i)   (qPD[i].isym)
309
310 #define VALID_CURR_FILE    (curr_fd < pxdb_header_p->fd_entries)
311 #define VALID_CURR_MODULE  (curr_md < pxdb_header_p->md_entries)
312 #define VALID_CURR_PROC    (curr_pd < pxdb_header_p->pd_entries)
313 #define VALID_CURR_CLASS   (curr_cd < pxdb_header_p->cd_entries)
314
315 #define CURR_FILE_START     (qFD[curr_fd].adrStart)
316 #define CURR_MODULE_START   (qMD[curr_md].adrStart)
317 #define CURR_PROC_START     (qPD[curr_pd].adrStart)
318
319 #define CURR_FILE_END    (qFD[curr_fd].adrEnd)
320 #define CURR_MODULE_END  (qMD[curr_md].adrEnd)
321 #define CURR_PROC_END    (qPD[curr_pd].adrEnd)
322
323 #define CURR_FILE_ISYM    (qFD[curr_fd].isym)
324 #define CURR_MODULE_ISYM  (qMD[curr_md].isym)
325 #define CURR_PROC_ISYM    (qPD[curr_pd].isym)
326
327 #define TELL_OBJFILE                                      \
328             do {                                          \
329                if( !told_objfile ) {                      \
330                    told_objfile = 1;                      \
331                    warning ("\nIn object file \"%s\":\n", \
332                             objfile->name);               \
333                }                                          \
334             } while (0)
335 \f
336
337
338 /* Keeping track of the start/end symbol table (LNTT) indices of
339    psymtabs created so far */
340
341 typedef struct
342   {
343     int start;
344     int end;
345   }
346 pst_syms_struct;
347
348 static pst_syms_struct *pst_syms_array = 0;
349
350 static pst_syms_count = 0;
351 static pst_syms_size = 0;
352
353 /* used by the TELL_OBJFILE macro */
354 static boolean told_objfile = 0;
355
356 /* Set up psymtab symbol index stuff */
357 static void
358 init_pst_syms ()
359 {
360   pst_syms_count = 0;
361   pst_syms_size = 20;
362   pst_syms_array = (pst_syms_struct *) xmalloc (20 * sizeof (pst_syms_struct));
363 }
364
365 /* Clean up psymtab symbol index stuff */
366 static void
367 clear_pst_syms ()
368 {
369   pst_syms_count = 0;
370   pst_syms_size = 0;
371   free (pst_syms_array);
372   pst_syms_array = 0;
373 }
374
375 /* Add information about latest psymtab to symbol index table */
376 static void
377 record_pst_syms (start_sym, end_sym)
378      int start_sym;
379      int end_sym;
380 {
381   if (++pst_syms_count > pst_syms_size)
382     {
383       pst_syms_array = (pst_syms_struct *) xrealloc (pst_syms_array,
384                               2 * pst_syms_size * sizeof (pst_syms_struct));
385       pst_syms_size *= 2;
386     }
387   pst_syms_array[pst_syms_count - 1].start = start_sym;
388   pst_syms_array[pst_syms_count - 1].end = end_sym;
389 }
390
391 /* Find a suitable symbol table index which can serve as the upper
392    bound of a psymtab that starts at INDEX
393
394    This scans backwards in the psymtab symbol index table to find a
395    "hole" in which the given index can fit.  This is a heuristic!!
396    We don't search the entire table to check for multiple holes,
397    we don't care about overlaps, etc. 
398
399    Return 0 => not found */
400 static int
401 find_next_pst_start (index)
402      int index;
403 {
404   int i;
405
406   for (i = pst_syms_count - 1; i >= 0; i--)
407     if (pst_syms_array[i].end <= index)
408       return (i == pst_syms_count - 1) ? 0 : pst_syms_array[i + 1].start - 1;
409
410   if (pst_syms_array[0].start > index)
411     return pst_syms_array[0].start - 1;
412
413   return 0;
414 }
415 \f
416
417
418 /* Utility functions to find the ending symbol index for a psymtab */
419
420 /* Find the next file entry that begins beyond INDEX, and return
421    its starting symbol index - 1.
422    QFD is the file table, CURR_FD is the file entry from where to start,
423    PXDB_HEADER_P as in hpread_quick_traverse (to allow macros to work).
424
425    Return 0 => not found */
426 static int
427 find_next_file_isym (index, qFD, curr_fd, pxdb_header_p)
428      int index;
429      quick_file_entry *qFD;
430      int curr_fd;
431      PXDB_header_ptr pxdb_header_p;
432 {
433   while (VALID_CURR_FILE)
434     {
435       if (CURR_FILE_ISYM >= index)
436         return CURR_FILE_ISYM - 1;
437       curr_fd++;
438     }
439   return 0;
440 }
441
442 /* Find the next procedure entry that begins beyond INDEX, and return
443    its starting symbol index - 1.
444    QPD is the procedure table, CURR_PD is the proc entry from where to start,
445    PXDB_HEADER_P as in hpread_quick_traverse (to allow macros to work).
446
447    Return 0 => not found */
448 static int
449 find_next_proc_isym (index, qPD, curr_pd, pxdb_header_p)
450      int index;
451      quick_procedure_entry *qPD;
452      int curr_pd;
453      PXDB_header_ptr pxdb_header_p;
454 {
455   while (VALID_CURR_PROC)
456     {
457       if (CURR_PROC_ISYM >= index)
458         return CURR_PROC_ISYM - 1;
459       curr_pd++;
460     }
461   return 0;
462 }
463
464 /* Find the next module entry that begins beyond INDEX, and return
465    its starting symbol index - 1.
466    QMD is the module table, CURR_MD is the modue entry from where to start,
467    PXDB_HEADER_P as in hpread_quick_traverse (to allow macros to work).
468
469    Return 0 => not found */
470 static int
471 find_next_module_isym (index, qMD, curr_md, pxdb_header_p)
472      int index;
473      quick_module_entry *qMD;
474      int curr_md;
475      PXDB_header_ptr pxdb_header_p;
476 {
477   while (VALID_CURR_MODULE)
478     {
479       if (CURR_MODULE_ISYM >= index)
480         return CURR_MODULE_ISYM - 1;
481       curr_md++;
482     }
483   return 0;
484 }
485
486 /* Scan and record partial symbols for all functions starting from index
487    pointed to by CURR_PD_P, and between code addresses START_ADR and END_ADR.
488    Other parameters are explained in comments below. */
489
490 /* This used to be inline in hpread_quick_traverse, but now that we do essentially the
491    same thing for two different cases (modules and module-less files), it's better
492    organized in a separate routine, although it does take lots of arguments. pai/1997-10-08 */
493
494 static int
495 scan_procs (curr_pd_p, qPD, max_procs, start_adr, end_adr, pst, vt_bits, objfile, section_offsets)
496      int *curr_pd_p;            /* pointer to current proc index */
497      quick_procedure_entry *qPD;        /* the procedure quick lookup table */
498      int max_procs;             /* number of entries in proc. table */
499      CORE_ADDR start_adr;       /* beginning of code range for current psymtab */
500      CORE_ADDR end_adr;         /* end of code range for current psymtab */
501      struct partial_symtab *pst;        /* current psymtab */
502      char *vt_bits;             /* strings table of SOM debug space */
503      struct objfile *objfile;   /* current object file */
504      struct section_offsets *section_offsets;   /* not really used for HP-UX currently */
505 {
506   union dnttentry *dn_bufp;
507   int symbol_count = 0;         /* Total number of symbols in this psymtab */
508   int curr_pd = *curr_pd_p;     /* Convenience variable -- avoid dereferencing pointer all the time */
509
510 #ifdef DUMPING
511   /* Turn this on for lots of debugging information in this routine */
512   static int dumping = 0;
513 #endif
514
515 #ifdef DUMPING
516   if (dumping)
517     {
518       printf ("Scan_procs called, addresses %x to %x, proc %x\n", start_adr, end_adr, curr_pd);
519     }
520 #endif
521
522   while ((CURR_PROC_START <= end_adr) && (curr_pd < max_procs))
523     {
524
525       char *rtn_name;           /* mangled name */
526       char *rtn_dem_name;       /* qualified demangled name */
527       char *class_name;
528       int class;
529
530       if ((trans_lang ((enum hp_language) qPD[curr_pd].language) == language_cplus) &&
531           vt_bits[(long) qPD[curr_pd].sbAlias])         /* not a null string */
532         {
533           /* Get mangled name for the procedure, and demangle it */
534           rtn_name = &vt_bits[(long) qPD[curr_pd].sbAlias];
535           rtn_dem_name = cplus_demangle (rtn_name, DMGL_ANSI | DMGL_PARAMS);
536         }
537       else
538         {
539           rtn_name = &vt_bits[(long) qPD[curr_pd].sbProc];
540           rtn_dem_name = NULL;
541         }
542
543       /* Hack to get around HP C/C++ compilers' insistence on providing
544          "_MAIN_" as an alternate name for "main" */
545       if ((strcmp (rtn_name, "_MAIN_") == 0) &&
546           (strcmp (&vt_bits[(long) qPD[curr_pd].sbProc], "main") == 0))
547         rtn_dem_name = rtn_name = main_string;
548
549 #ifdef DUMPING
550       if (dumping)
551         {
552           printf ("..add %s (demangled %s), index %x to this psymtab\n", rtn_name, rtn_dem_name, curr_pd);
553         }
554 #endif
555
556       /* Check for module-spanning routines. */
557       if (CURR_PROC_END > end_adr)
558         {
559           TELL_OBJFILE;
560           warning ("Procedure \"%s\" [0x%x] spans file or module boundaries.", rtn_name, curr_pd);
561         }
562
563 /* I asked for this in the hope it would fix bug CHFts22228, but
564    later decided it's not the right fix. I'm leaving the code
565    commented out for now in case we decide we actually want to do this.
566    - RT */
567 #if 0
568       /* Check this routine--if it's a class member function,
569          add the class to the psymtab.  We only need to add
570          the class once in each module, so check. */
571       if (qPD[curr_pd].member)
572         {
573
574           class = qPD[curr_pd].icd;
575           if (!B_TST (class_entered, class))
576             {                   /* pai: (temp)  class_entered not a parameter */
577
578               class_name = &vt_bits[(long) qCD[class].sbClass];
579
580               /* Add to both the struct and var namespace */
581
582               add_psymbol_to_list (class_name,
583                                    strlen (class_name),
584                                    STRUCT_NAMESPACE,
585                                    LOC_UNDEF,   /* "I have no storage"     */
586                                    &objfile->global_psymbols,   /* assume classname is global */
587                                    0, 0,
588                                    trans_lang ((enum hp_language) qPD[curr_pd].language),
589                                    objfile);
590
591               add_psymbol_to_list (class_name,
592                                    strlen (class_name),
593                                    VAR_NAMESPACE,
594                                    LOC_UNDEF,   /* "I have no storage"     */
595                                    &objfile->global_psymbols,   /* assume classname is global */
596                                    0, 0,
597                                    trans_lang ((enum hp_language) qPD[curr_pd].language),
598                                    objfile);
599
600               B_SET (class_entered, class);     /* pai: (temp)  class_entered not a parameter */
601               symbol_count++;
602             }
603         }
604 #endif
605
606       /* Add this routine symbol to the list in the objfile. 
607          Unfortunately we have to go to the LNTT to determine the
608          correct list to put it on. An alternative (which the
609          code used to do) would be to not check and always throw
610          it on the "static" list. But if we go that route, then
611          symbol_lookup() needs to be tweaked a bit to account
612          for the fact that the function might not be found on
613          the correct list in the psymtab. - RT */
614       dn_bufp = hpread_get_lntt (qPD[curr_pd].isym, objfile);
615       if (dn_bufp->dfunc.global)
616         add_psymbol_with_dem_name_to_list (rtn_name,
617                                            strlen (rtn_name),
618                                            rtn_dem_name,
619                                            strlen (rtn_dem_name),
620                                            VAR_NAMESPACE,
621                                            LOC_BLOCK,   /* "I am a routine"        */
622                                            &objfile->global_psymbols,
623                                            (qPD[curr_pd].adrStart + /* Starting address of rtn */
624                                             ANOFFSET (section_offsets, SECT_OFF_TEXT)),
625                                            0,   /* core addr?? */
626                                            trans_lang ((enum hp_language) qPD[curr_pd].language),
627                                            objfile);
628       else
629         add_psymbol_with_dem_name_to_list (rtn_name,
630                                            strlen (rtn_name),
631                                            rtn_dem_name,
632                                            strlen (rtn_dem_name),
633                                            VAR_NAMESPACE,
634                                            LOC_BLOCK,   /* "I am a routine"        */
635                                            &objfile->static_psymbols,
636                                            (qPD[curr_pd].adrStart +  /* Starting address of rtn */
637                                             ANOFFSET (section_offsets, SECT_OFF_TEXT)),
638                                            0,   /* core addr?? */
639                                            trans_lang ((enum hp_language) qPD[curr_pd].language),
640                                            objfile);
641
642       symbol_count++;
643       *curr_pd_p = ++curr_pd;   /* bump up count & reflect in caller */
644     }                           /* loop over procedures */
645
646 #ifdef DUMPING
647   if (dumping)
648     {
649       if (symbol_count == 0)
650         printf ("Scan_procs: no symbols found!\n");
651     }
652 #endif
653
654   return symbol_count;
655 }
656
657
658 /* Traverse the quick look-up tables, building a set of psymtabs.
659
660    This constructs a psymtab for modules and files in the quick lookup
661    tables.
662
663    Mostly, modules correspond to compilation units, so we try to
664    create psymtabs that correspond to modules; however, in some cases
665    a file can result in a compiled object which does not have a module
666    entry for it, so in such cases we create a psymtab for the file.  */
667
668 int
669 hpread_quick_traverse (objfile, section_offsets, gntt_bits, vt_bits, pxdb_header_p)     
670      struct objfile *objfile;        /* The object file descriptor */
671      struct section_offsets *section_offsets; /* ?? Null for HP */
672      char *gntt_bits;                /* GNTT entries, loaded in from the file */
673      char *vt_bits;                  /* VT (string) entries ditto. */
674      PXDB_header_ptr pxdb_header_p;  /* Pointer to pxdb header ditto */
675 {
676   struct partial_symtab *pst;
677
678   char *addr;
679
680   quick_procedure_entry *qPD;
681   quick_file_entry *qFD;
682   quick_module_entry *qMD;
683   quick_class_entry *qCD;
684
685   int idx;
686   int i;
687   CORE_ADDR start_adr;          /* current psymtab's starting code addr   */
688   CORE_ADDR end_adr;            /* current psymtab's ending code addr     */
689   CORE_ADDR next_mod_adr;       /* next module's starting code addr    */
690   int curr_pd;                  /* current procedure */
691   int curr_fd;                  /* current file      */
692   int curr_md;                  /* current module    */
693   int start_sym;                /* current psymtab's starting symbol index */
694   int end_sym;                  /* current psymtab's ending symbol index   */
695   int max_LNTT_sym_index;
696   int syms_in_pst;
697   B_TYPE *class_entered;
698
699   struct partial_symbol **global_syms;  /* We'll be filling in the "global"   */
700   struct partial_symbol **static_syms;  /* and "static" tables in the objfile
701                                            as we go, so we need a pair of     
702                                            current pointers. */
703
704 #ifdef DUMPING
705   /* Turn this on for lots of debugging information in this routine.
706      You get a blow-by-blow account of quick lookup table reading */
707   static int dumping = 0;
708 #endif
709
710   pst = (struct partial_symtab *) 0;
711
712   /* Clear out some globals */
713   init_pst_syms ();
714   told_objfile = 0;
715
716   /* Demangling style -- if EDG style already set, don't change it,
717      as HP style causes some problems with the KAI EDG compiler */
718   if (current_demangling_style != edg_demangling)
719     {
720       /* Otherwise, ensure that we are using HP style demangling */
721       set_demangling_style (HP_DEMANGLING_STYLE_STRING);
722     }
723
724   /* First we need to find the starting points of the quick
725      look-up tables in the GNTT. */
726
727   addr = gntt_bits;
728
729   qPD = (quick_procedure_entry_ptr) addr;
730   addr += pxdb_header_p->pd_entries * sizeof (quick_procedure_entry);
731
732 #ifdef DUMPING
733   if (dumping)
734     {
735       printf ("\n Printing routines as we see them\n");
736       for (i = 0; VALID_PROC (i); i++)
737         {
738           idx = (long) qPD[i].sbProc;
739           printf ("%s %x..%x\n", &vt_bits[idx],
740                   (int) PROC_START (i),
741                   (int) PROC_END (i));
742         }
743     }
744 #endif
745
746   qFD = (quick_file_entry_ptr) addr;
747   addr += pxdb_header_p->fd_entries * sizeof (quick_file_entry);
748
749 #ifdef DUMPING
750   if (dumping)
751     {
752       printf ("\n Printing files as we see them\n");
753       for (i = 0; VALID_FILE (i); i++)
754         {
755           idx = (long) qFD[i].sbFile;
756           printf ("%s %x..%x\n", &vt_bits[idx],
757                   (int) FILE_START (i),
758                   (int) FILE_END (i));
759         }
760     }
761 #endif
762
763   qMD = (quick_module_entry_ptr) addr;
764   addr += pxdb_header_p->md_entries * sizeof (quick_module_entry);
765
766 #ifdef DUMPING
767   if (dumping)
768     {
769       printf ("\n Printing modules as we see them\n");
770       for (i = 0; i < pxdb_header_p->md_entries; i++)
771         {
772           idx = (long) qMD[i].sbMod;
773           printf ("%s\n", &vt_bits[idx]);
774         }
775     }
776 #endif
777
778   qCD = (quick_class_entry_ptr) addr;
779   addr += pxdb_header_p->cd_entries * sizeof (quick_class_entry);
780
781 #ifdef DUMPING
782   if (dumping)
783     {
784       printf ("\n Printing classes as we see them\n");
785       for (i = 0; VALID_CLASS (i); i++)
786         {
787           idx = (long) qCD[i].sbClass;
788           printf ("%s\n", &vt_bits[idx]);
789         }
790
791       printf ("\n Done with dump, on to build!\n");
792     }
793 #endif
794
795   /* We need this index only while hp-symtab-read.c expects
796      a byte offset to the end of the LNTT entries for a given
797      psymtab.  Thus the need for it should go away someday.
798
799      When it goes away, then we won't have any need to load the
800      LNTT from the objfile at psymtab-time, and start-up will be
801      faster.  To make that work, we'll need some way to create
802      a null pst for the "globals" pseudo-module. */
803   max_LNTT_sym_index = LNTT_SYMCOUNT (objfile);
804
805   /* Scan the module descriptors and make a psymtab for each.
806
807      We know the MDs, FDs and the PDs are in order by starting
808      address.  We use that fact to traverse all three arrays in
809      parallel, knowing when the next PD is in a new file
810      and we need to create a new psymtab. */
811   curr_pd = 0;                  /* Current procedure entry */
812   curr_fd = 0;                  /* Current file entry */
813   curr_md = 0;                  /* Current module entry */
814
815   start_adr = 0;                /* Current psymtab code range */
816   end_adr = 0;
817
818   start_sym = 0;                /* Current psymtab symbol range */
819   end_sym = 0;
820
821   syms_in_pst = 0;              /* Symbol count for psymtab */
822
823   /* Psts actually just have pointers into the objfile's
824      symbol table, not their own symbol tables. */
825   global_syms = objfile->global_psymbols.list;
826   static_syms = objfile->static_psymbols.list;
827
828 #if 0                           /* pai: (temp) we don't need this any more */
829   /* elz: if the first module we see in the table is for
830      end.c, then return immediately with false. This happens
831      for F77 programs, for which there is no MODULE information
832      produced in the debug info. 
833      Returning false from this function will make the caller
834      (build_psymbols) scan the table from the beginning and 
835      not use the quick lookup tables.
836      F90 has modules so this poses no problem. */
837   if (!strcmp (&vt_bits[(long) qMD[0].sbMod], "end.c"))
838     return 0;
839 #endif
840
841   /* First skip over pseudo-entries with address 0.  These represent inlined
842      routines and abstract (uninstantiated) template routines.
843      FIXME: These should be read in and available -- even if we can't set
844      breakpoints, etc., there's some information that can be presented
845      to the user. pai/1997-10-08  */
846
847   while (VALID_CURR_PROC && (CURR_PROC_START == 0))
848     curr_pd++;
849
850   /* Loop over files, modules, and procedures in code address order. Each
851      time we enter an iteration of this loop, curr_pd points to the first
852      unprocessed procedure, curr_fd points to the first unprocessed file, and
853      curr_md to the first unprocessed module.  Each iteration of this loop
854      updates these as required -- any or all of them may be bumpd up
855      each time around.  When we exit this loop, we are done with all files
856      and modules in the tables -- there may still be some procedures, however.
857
858      Note: This code used to loop only over module entries, under the assumption
859      that files can occur via inclusions and are thus unreliable, while a
860      compiled object always corresponds to a module.  With CTTI in the HP aCC
861      compiler, it turns out that compiled objects may have only files and no
862      modules; so we have to loop over files and modules, creating psymtabs for
863      either as appropriate.  Unfortunately there are some problems (notably:
864      1. the lack of "SRC_FILE_END" entries in the LNTT, 2. the lack of pointers
865      to the ending symbol indices of a module or a file) which make it quite hard
866      to do this correctly.  Currently it uses a bunch of heuristics to start and
867      end psymtabs; they seem to work well with most objects generated by aCC, but
868      who knows when that will change...   */
869
870   while (VALID_CURR_FILE || VALID_CURR_MODULE)
871     {
872
873       char *mod_name_string;
874       char *full_name_string;
875
876       /* First check for modules like "version.c", which have no code
877          in them but still have qMD entries.  They also have no qFD or
878          qPD entries.  Their start address is -1 and their end address
879          is 0.  */
880       if (VALID_CURR_MODULE && (CURR_MODULE_START == -1) && (CURR_MODULE_END == NULL))
881         {
882
883           mod_name_string = &vt_bits[(long) qMD[curr_md].sbMod];
884
885 #ifdef DUMPING
886           if (dumping)
887             printf ("Module with data only %s\n", mod_name_string);
888 #endif
889
890           /* We'll skip the rest (it makes error-checking easier), and
891              just make an empty pst.  Right now empty psts are not put
892              in the pst chain, so all this is for naught, but later it
893              might help.  */
894
895           pst = hpread_start_psymtab (objfile,
896                                       section_offsets,          /* ?? */
897                                       mod_name_string,
898                                       CURR_MODULE_START,        /* Low text address: bogus! */
899                                       (CURR_MODULE_ISYM * sizeof (struct dntt_type_block)),
900                                                                 /* ldsymoff */
901                                       global_syms,
902                                       static_syms);
903
904           pst = hpread_end_psymtab (pst,
905                                     NULL,       /* psymtab_include_list */
906                                     0,          /* includes_used        */
907                                     end_sym * sizeof (struct dntt_type_block),
908                                                 /* byte index in LNTT of end 
909                                                    = capping symbol offset  
910                                                    = LDSYMOFF of nextfile */
911                                      NULL,      /* text high            */
912                                      NULL,      /* dependency_list      */
913                                      0);        /* dependencies_used    */
914
915           global_syms = objfile->global_psymbols.next;
916           static_syms = objfile->static_psymbols.next;
917
918           curr_md++;
919         }
920       else if (VALID_CURR_MODULE &&
921                ((CURR_MODULE_START == 0) || (CURR_MODULE_START == -1) ||
922                 (CURR_MODULE_END == 0) || (CURR_MODULE_END == -1)))
923         {
924           TELL_OBJFILE;
925           warning ("Module \"%s\" [0x%x] has non-standard addresses.  It starts at 0x%x, ends at 0x%x, and will be skipped.",
926                    mod_name_string, curr_md, start_adr, end_adr);
927           /* On to next module */
928           curr_md++;
929         }
930       else
931         {
932           /* First check if we are looking at a file with code in it
933              that does not overlap the current module's code range */
934
935           if (VALID_CURR_FILE ? (VALID_CURR_MODULE ? (CURR_FILE_END < CURR_MODULE_START) : 1) : 0)
936             {
937
938               /* Looking at file not corresponding to any module,
939                  create a psymtab for it */
940               full_name_string = &vt_bits[(long) qFD[curr_fd].sbFile];
941               start_adr = CURR_FILE_START;
942               end_adr = CURR_FILE_END;
943               start_sym = CURR_FILE_ISYM;
944
945               /* Check if there are any procedures not handled until now, that
946                  begin before the start address of this file, and if so, adjust
947                  this module's start address to include them.  This handles routines that
948                  are in between file or module ranges for some reason (probably
949                  indicates a compiler bug */
950
951               if (CURR_PROC_START < start_adr)
952                 {
953                   TELL_OBJFILE;
954                   warning ("Found procedure \"%s\" [0x%x] that is not in any file or module.",
955                            &vt_bits[(long) qPD[curr_pd].sbProc], curr_pd);
956                   start_adr = CURR_PROC_START;
957                   if (CURR_PROC_ISYM < start_sym)
958                     start_sym = CURR_PROC_ISYM;
959                 }
960
961               /* Sometimes (compiler bug -- COBOL) the module end address is higher
962                  than the start address of the next module, so check for that and
963                  adjust accordingly */
964
965               if (VALID_FILE (curr_fd + 1) && (FILE_START (curr_fd + 1) <= end_adr))
966                 {
967                   TELL_OBJFILE;
968                   warning ("File \"%s\" [0x%x] has ending address after starting address of next file; adjusting ending address down.",
969                            full_name_string, curr_fd);
970                   end_adr = FILE_START (curr_fd + 1) - 1;       /* Is -4 (or -8 for 64-bit) better? */
971                 }
972               if (VALID_MODULE (curr_md) && (CURR_MODULE_START <= end_adr))
973                 {
974                   TELL_OBJFILE;
975                   warning ("File \"%s\" [0x%x] has ending address after starting address of next module; adjusting ending address down.",
976                            full_name_string, curr_fd);
977                   end_adr = CURR_MODULE_START - 1;      /* Is -4 (or -8 for 64-bit) better? */
978                 }
979
980
981 #ifdef DUMPING
982               if (dumping)
983                 {
984                   printf ("Make new psymtab for file %s (%x to %x).\n",
985                           full_name_string, start_adr, end_adr);
986                 }
987 #endif
988               /* Create the basic psymtab, connecting it in the list
989                  for this objfile and pointing its symbol entries
990                  to the current end of the symbol areas in the objfile.
991
992                  The "ldsymoff" parameter is the byte offset in the LNTT
993                  of the first symbol in this file.  Some day we should
994                  turn this into an index (fix in hp-symtab-read.c as well).
995                  And it's not even the right byte offset, as we're using
996                  the size of a union! FIXME!  */
997               pst = hpread_start_psymtab (objfile,
998                                           section_offsets,      /* ?? */
999                                           full_name_string,
1000                                           start_adr,            /* Low text address */
1001                                           (start_sym * sizeof (struct dntt_type_block)),
1002                                                                 /* ldsymoff */
1003                                           global_syms,
1004                                           static_syms);
1005
1006               /* Set up to only enter each class referenced in this module once.  */
1007               class_entered = malloc (B_BYTES (pxdb_header_p->cd_entries));
1008               B_CLRALL (class_entered, pxdb_header_p->cd_entries);
1009
1010               /* Scan the procedure descriptors for procedures in the current
1011                  file, based on the starting addresses. */
1012
1013               syms_in_pst = scan_procs (&curr_pd, qPD, pxdb_header_p->pd_entries,
1014                                         start_adr, end_adr,
1015                                         pst, vt_bits, objfile, section_offsets);
1016
1017               /* Get ending symbol offset */
1018
1019               end_sym = 0;
1020               /* First check for starting index before previous psymtab */
1021               if (pst_syms_count && start_sym < pst_syms_array[pst_syms_count - 1].end)
1022                 {
1023                   end_sym = find_next_pst_start (start_sym);
1024                 }
1025               /* Look for next start index of a file or module, or procedure */
1026               if (!end_sym)
1027                 {
1028                   int next_file_isym = find_next_file_isym (start_sym, qFD, curr_fd + 1, pxdb_header_p);
1029                   int next_module_isym = find_next_module_isym (start_sym, qMD, curr_md, pxdb_header_p);
1030                   int next_proc_isym = find_next_proc_isym (start_sym, qPD, curr_pd, pxdb_header_p);
1031
1032                   if (next_file_isym && next_module_isym)
1033                     {
1034                       /* pick lower of next file or module start index */
1035                       end_sym = min (next_file_isym, next_module_isym);
1036                     }
1037                   else
1038                     {
1039                       /* one of them is zero, pick the other */
1040                       end_sym = max (next_file_isym, next_module_isym);
1041                     }
1042
1043                   /* As a precaution, check next procedure index too */
1044                   if (!end_sym)
1045                     end_sym = next_proc_isym;
1046                   else
1047                     end_sym = min (end_sym, next_proc_isym);
1048                 }
1049
1050               /* Couldn't find procedure, file, or module, use globals as default */
1051               if (!end_sym)
1052                 end_sym = pxdb_header_p->globals;
1053
1054 #ifdef DUMPING
1055               if (dumping)
1056                 {
1057                   printf ("File psymtab indices: %x to %x\n", start_sym, end_sym);
1058                 }
1059 #endif
1060
1061               pst = hpread_end_psymtab (pst,
1062                                         NULL,   /* psymtab_include_list */
1063                                         0,      /* includes_used        */
1064                                         end_sym * sizeof (struct dntt_type_block),
1065                                                 /* byte index in LNTT of end 
1066                                                    = capping symbol offset   
1067                                                    = LDSYMOFF of nextfile */
1068                                         end_adr,        /* text high */
1069                                         NULL,   /* dependency_list */
1070                                         0);     /* dependencies_used */
1071
1072               record_pst_syms (start_sym, end_sym);
1073
1074               if (NULL == pst)
1075                 warning ("No symbols in psymtab for file \"%s\" [0x%x].", full_name_string, curr_fd);
1076
1077 #ifdef DUMPING
1078               if (dumping)
1079                 {
1080                   printf ("Made new psymtab for file %s (%x to %x), sym %x to %x.\n",
1081                           full_name_string, start_adr, end_adr, CURR_FILE_ISYM, end_sym);
1082                 }
1083 #endif
1084               /* Prepare for the next psymtab. */
1085               global_syms = objfile->global_psymbols.next;
1086               static_syms = objfile->static_psymbols.next;
1087               free (class_entered);
1088
1089               curr_fd++;
1090             }                   /* Psymtab for file */
1091           else
1092             {
1093               /* We have a module for which we create a psymtab */
1094
1095               mod_name_string = &vt_bits[(long) qMD[curr_md].sbMod];
1096
1097               /* We will include the code ranges of any files that happen to
1098                  overlap with this module */
1099
1100               /* So, first pick the lower of the file's and module's start addresses */
1101               start_adr = CURR_MODULE_START;
1102               if (VALID_CURR_FILE)
1103                 {
1104                   if (CURR_FILE_START < CURR_MODULE_START)
1105                     {
1106                       TELL_OBJFILE;
1107                       warning ("File \"%s\" [0x%x] crosses beginning of module \"%s\".",
1108                                &vt_bits[(long) qFD[curr_fd].sbFile],
1109                                curr_fd, mod_name_string);
1110
1111                       start_adr = CURR_FILE_START;
1112                     }
1113                 }
1114
1115               /* Also pick the lower of the file's and the module's start symbol indices */
1116               start_sym = CURR_MODULE_ISYM;
1117               if (VALID_CURR_FILE && (CURR_FILE_ISYM < CURR_MODULE_ISYM))
1118                 start_sym = CURR_FILE_ISYM;
1119
1120               /* For the end address, we scan through the files till we find one
1121                  that overlaps the current module but ends beyond it; if no such file exists we
1122                  simply use the module's start address.  
1123                  (Note, if file entries themselves overlap
1124                  we take the longest overlapping extension beyond the end of the module...)
1125                  We assume that modules never overlap. */
1126
1127               end_adr = CURR_MODULE_END;
1128
1129               if (VALID_CURR_FILE)
1130                 {
1131                   while (VALID_CURR_FILE && (CURR_FILE_START < end_adr))
1132                     {
1133
1134 #ifdef DUMPING
1135                       if (dumping)
1136                         printf ("Maybe skipping file %s which overlaps with module %s\n",
1137                                 &vt_bits[(long) qFD[curr_fd].sbFile], mod_name_string);
1138 #endif
1139                       if (CURR_FILE_END > end_adr)
1140                         {
1141                           TELL_OBJFILE;
1142                           warning ("File \"%s\" [0x%x] crosses end of module \"%s\".",
1143                                    &vt_bits[(long) qFD[curr_fd].sbFile],
1144                                    curr_fd, mod_name_string);
1145                           end_adr = CURR_FILE_END;
1146                         }
1147                       curr_fd++;
1148                     }
1149                   curr_fd--;    /* back up after going too far */
1150                 }
1151
1152               /* Sometimes (compiler bug -- COBOL) the module end address is higher
1153                  than the start address of the next module, so check for that and
1154                  adjust accordingly */
1155
1156               if (VALID_MODULE (curr_md + 1) && (MODULE_START (curr_md + 1) <= end_adr))
1157                 {
1158                   TELL_OBJFILE;
1159                   warning ("Module \"%s\" [0x%x] has ending address after starting address of next module; adjusting ending address down.",
1160                            mod_name_string, curr_md);
1161                   end_adr = MODULE_START (curr_md + 1) - 1;     /* Is -4 (or -8 for 64-bit) better? */
1162                 }
1163               if (VALID_FILE (curr_fd + 1) && (FILE_START (curr_fd + 1) <= end_adr))
1164                 {
1165                   TELL_OBJFILE;
1166                   warning ("Module \"%s\" [0x%x] has ending address after starting address of next file; adjusting ending address down.",
1167                            mod_name_string, curr_md);
1168                   end_adr = FILE_START (curr_fd + 1) - 1;       /* Is -4 (or -8 for 64-bit) better? */
1169                 }
1170
1171               /* Use one file to get the full name for the module.  This
1172                  situation can arise if there is executable code in a #include
1173                  file.  Each file with code in it gets a qFD.  Files which don't
1174                  contribute code don't get a qFD, even if they include files
1175                  which do, e.g.: 
1176
1177                  body.c:                    rtn.h:
1178                  int x;                     int main() {
1179                  #include "rtn.h"               return x;
1180                  }
1181
1182                  There will a qFD for "rtn.h",and a qMD for "body.c",
1183                  but no qMD for "rtn.h" or qFD for "body.c"!
1184
1185                  We pick the name of the last file to overlap with this
1186                  module.  C convention is to put include files first.  In a
1187                  perfect world, we could check names and use the file whose full
1188                  path name ends with the module name. */
1189
1190               if (VALID_CURR_FILE)
1191                 full_name_string = &vt_bits[(long) qFD[curr_fd].sbFile];
1192               else
1193                 full_name_string = mod_name_string;
1194
1195               /* Check if there are any procedures not handled until now, that
1196                  begin before the start address we have now, and if so, adjust
1197                  this psymtab's start address to include them.  This handles routines that
1198                  are in between file or module ranges for some reason (probably
1199                  indicates a compiler bug */
1200
1201               if (CURR_PROC_START < start_adr)
1202                 {
1203                   TELL_OBJFILE;
1204                   warning ("Found procedure \"%s\" [0x%x] that is not in any file or module.",
1205                            &vt_bits[(long) qPD[curr_pd].sbProc], curr_pd);
1206                   start_adr = CURR_PROC_START;
1207                   if (CURR_PROC_ISYM < start_sym)
1208                     start_sym = CURR_PROC_ISYM;
1209                 }
1210
1211 #ifdef DUMPING
1212               if (dumping)
1213                 {
1214                   printf ("Make new psymtab for module %s (%x to %x), using file %s\n",
1215                      mod_name_string, start_adr, end_adr, full_name_string);
1216                 }
1217 #endif
1218               /* Create the basic psymtab, connecting it in the list
1219                  for this objfile and pointing its symbol entries
1220                  to the current end of the symbol areas in the objfile.
1221
1222                  The "ldsymoff" parameter is the byte offset in the LNTT
1223                  of the first symbol in this file.  Some day we should
1224                  turn this into an index (fix in hp-symtab-read.c as well).
1225                  And it's not even the right byte offset, as we're using
1226                  the size of a union! FIXME!  */
1227               pst = hpread_start_psymtab (objfile,
1228                                           section_offsets,      /* ?? */
1229                                           full_name_string,
1230                                           start_adr,    /* Low text address */
1231                                           (start_sym * sizeof (struct dntt_type_block)),
1232                                                         /* ldsymoff */
1233                                           global_syms,
1234                                           static_syms);
1235
1236               /* Set up to only enter each class referenced in this module once.  */
1237               class_entered = malloc (B_BYTES (pxdb_header_p->cd_entries));
1238               B_CLRALL (class_entered, pxdb_header_p->cd_entries);
1239
1240               /* Scan the procedure descriptors for procedures in the current
1241                  module, based on the starting addresses. */
1242
1243               syms_in_pst = scan_procs (&curr_pd, qPD, pxdb_header_p->pd_entries,
1244                                         start_adr, end_adr,
1245                                         pst, vt_bits, objfile, section_offsets);
1246
1247               /* Get ending symbol offset */
1248
1249               end_sym = 0;
1250               /* First check for starting index before previous psymtab */
1251               if (pst_syms_count && start_sym < pst_syms_array[pst_syms_count - 1].end)
1252                 {
1253                   end_sym = find_next_pst_start (start_sym);
1254                 }
1255               /* Look for next start index of a file or module, or procedure */
1256               if (!end_sym)
1257                 {
1258                   int next_file_isym = find_next_file_isym (start_sym, qFD, curr_fd + 1, pxdb_header_p);
1259                   int next_module_isym = find_next_module_isym (start_sym, qMD, curr_md + 1, pxdb_header_p);
1260                   int next_proc_isym = find_next_proc_isym (start_sym, qPD, curr_pd, pxdb_header_p);
1261
1262                   if (next_file_isym && next_module_isym)
1263                     {
1264                       /* pick lower of next file or module start index */
1265                       end_sym = min (next_file_isym, next_module_isym);
1266                     }
1267                   else
1268                     {
1269                       /* one of them is zero, pick the other */
1270                       end_sym = max (next_file_isym, next_module_isym);
1271                     }
1272
1273                   /* As a precaution, check next procedure index too */
1274                   if (!end_sym)
1275                     end_sym = next_proc_isym;
1276                   else
1277                     end_sym = min (end_sym, next_proc_isym);
1278                 }
1279
1280               /* Couldn't find procedure, file, or module, use globals as default */
1281               if (!end_sym)
1282                 end_sym = pxdb_header_p->globals;
1283
1284 #ifdef DUMPING
1285               if (dumping)
1286                 {
1287                   printf ("Module psymtab indices: %x to %x\n", start_sym, end_sym);
1288                 }
1289 #endif
1290
1291               pst = hpread_end_psymtab (pst,
1292                                         NULL,   /* psymtab_include_list */
1293                                         0,      /* includes_used        */
1294                                         end_sym * sizeof (struct dntt_type_block),
1295                                                 /* byte index in LNTT of end 
1296                                                    = capping symbol offset   
1297                                                    = LDSYMOFF of nextfile */
1298                                         end_adr,        /* text high */
1299                                         NULL,   /* dependency_list      */
1300                                         0);     /* dependencies_used    */
1301
1302               record_pst_syms (start_sym, end_sym);
1303
1304               if (NULL == pst)
1305                 warning ("No symbols in psymtab for module \"%s\" [0x%x].", mod_name_string, curr_md);
1306
1307 #ifdef DUMPING
1308               if (dumping)
1309                 {
1310                   printf ("Made new psymtab for module %s (%x to %x), sym %x to %x.\n",
1311                           mod_name_string, start_adr, end_adr, CURR_MODULE_ISYM, end_sym);
1312                 }
1313 #endif
1314
1315               /* Prepare for the next psymtab. */
1316               global_syms = objfile->global_psymbols.next;
1317               static_syms = objfile->static_psymbols.next;
1318               free (class_entered);
1319
1320               curr_md++;
1321               curr_fd++;
1322             }                   /* psymtab for module */
1323         }                       /* psymtab for non-bogus file or module */
1324     }                           /* End of while loop over all files & modules */
1325
1326   /* There may be some routines after all files and modules -- these will get
1327      inserted in a separate new module of their own */
1328   if (VALID_CURR_PROC)
1329     {
1330       start_adr = CURR_PROC_START;
1331       end_adr = qPD[pxdb_header_p->pd_entries - 1].adrEnd;
1332       TELL_OBJFILE;
1333       warning ("Found functions beyond end of all files and modules [0x%x].", curr_pd);
1334 #ifdef DUMPING
1335       if (dumping)
1336         {
1337           printf ("Orphan functions at end, PD %d and beyond (%x to %x)\n",
1338                   curr_pd, start_adr, end_adr);
1339         }
1340 #endif
1341       pst = hpread_start_psymtab (objfile,
1342                                   section_offsets,      /* ?? */
1343                                   "orphans",
1344                                   start_adr,    /* Low text address */
1345                                   (CURR_PROC_ISYM * sizeof (struct dntt_type_block)),
1346                                                 /* ldsymoff */
1347                                   global_syms,
1348                                   static_syms);
1349
1350       scan_procs (&curr_pd, qPD, pxdb_header_p->pd_entries,
1351                   start_adr, end_adr,
1352                   pst, vt_bits, objfile, section_offsets);
1353
1354       pst = hpread_end_psymtab (pst,
1355                                 NULL,   /* psymtab_include_list */
1356                                 0,      /* includes_used */
1357                                 pxdb_header_p->globals * sizeof (struct dntt_type_block),
1358                                         /* byte index in LNTT of end 
1359                                            = capping symbol offset   
1360                                            = LDSYMOFF of nextfile */
1361                                 end_adr,        /* text high  */
1362                                 NULL,   /* dependency_list */
1363                                 0);     /* dependencies_used */
1364     }
1365
1366
1367 #ifdef NEVER_NEVER
1368   /* Now build psts for non-module things (in the tail of
1369      the LNTT, after the last END MODULE entry).
1370
1371      If null psts were kept on the chain, this would be
1372      a solution.  FIXME */
1373   pst = hpread_start_psymtab (objfile,
1374                               section_offsets,
1375                               "globals",
1376                               0,
1377                               (pxdb_header_p->globals
1378                                * sizeof (struct dntt_type_block)),
1379                               objfile->global_psymbols.next,
1380                               objfile->static_psymbols.next);
1381   hpread_end_psymtab (pst,
1382                       NULL, 0,
1383                       (max_LNTT_sym_index * sizeof (struct dntt_type_block)),
1384                       0,
1385                       NULL, 0);
1386 #endif
1387
1388   clear_pst_syms ();
1389
1390   return 1;
1391
1392 }                               /* End of hpread_quick_traverse. */
1393 \f
1394
1395 /* Get appropriate header, based on pxdb type. 
1396    Return value: 1 if ok, 0 if not */
1397 int
1398 hpread_get_header (objfile, pxdb_header_p)
1399      struct objfile *objfile;
1400      PXDB_header_ptr pxdb_header_p;
1401 {
1402   asection *pinfo_section, *debug_section, *header_section;
1403
1404 #ifdef DUMPING
1405   /* Turn on for debugging information */
1406   static int dumping = 0;
1407 #endif
1408
1409   header_section = bfd_get_section_by_name (objfile->obfd, "$HEADER$");
1410   if (!header_section)
1411     {
1412       /* We don't have either PINFO or DEBUG sections.  But
1413          stuff like "libc.sl" has no debug info.  There's no
1414          need to warn the user of this, as it may be ok. The
1415          caller will figure it out and issue any needed
1416          messages. */
1417 #ifdef DUMPING
1418       if (dumping)
1419         printf ("==No debug info at all for %s.\n", objfile->name);
1420 #endif
1421
1422       return 0;
1423     }
1424
1425   /* We would like either a $DEBUG$ or $PINFO$ section.
1426      Once we know which, we can understand the header
1427      data (which we have defined to suit the more common
1428      $DEBUG$ case). */
1429   debug_section = bfd_get_section_by_name (objfile->obfd, "$DEBUG$");
1430   pinfo_section = bfd_get_section_by_name (objfile->obfd, "$PINFO$");
1431   if (debug_section)
1432     {
1433       /* The expected case: normal pxdb header. */
1434       bfd_get_section_contents (objfile->obfd, header_section,
1435                                 pxdb_header_p, 0, sizeof (PXDB_header));
1436
1437       if (!pxdb_header_p->pxdbed)
1438         {
1439           /* This shouldn't happen if we check in "symfile.c". */
1440           return 0;
1441         }                       /* DEBUG section */
1442     }
1443
1444   else if (pinfo_section)
1445     {
1446       /* The DOC case; we need to translate this into a
1447          regular header. */
1448       DOC_info_PXDB_header doc_header;
1449
1450 #ifdef DUMPING
1451       if (dumping)
1452         {
1453           printf ("==OOps, PINFO, let's try to handle this, %s.\n", objfile->name);
1454         }
1455 #endif
1456
1457       bfd_get_section_contents (objfile->obfd,
1458                                 header_section,
1459                                 &doc_header, 0,
1460                                 sizeof (DOC_info_PXDB_header));
1461
1462       if (!doc_header.pxdbed)
1463         {
1464           /* This shouldn't happen if we check in "symfile.c". */
1465           warning ("File \"%s\" not processed by pxdb!", objfile->name);
1466           return 0;
1467         }
1468
1469       /* Copy relevent fields to standard header passed in. */
1470       pxdb_header_p->pd_entries = doc_header.pd_entries;
1471       pxdb_header_p->fd_entries = doc_header.fd_entries;
1472       pxdb_header_p->md_entries = doc_header.md_entries;
1473       pxdb_header_p->pxdbed = doc_header.pxdbed;
1474       pxdb_header_p->bighdr = doc_header.bighdr;
1475       pxdb_header_p->sa_header = doc_header.sa_header;
1476       pxdb_header_p->inlined = doc_header.inlined;
1477       pxdb_header_p->globals = doc_header.globals;
1478       pxdb_header_p->time = doc_header.time;
1479       pxdb_header_p->pg_entries = doc_header.pg_entries;
1480       pxdb_header_p->functions = doc_header.functions;
1481       pxdb_header_p->files = doc_header.files;
1482       pxdb_header_p->cd_entries = doc_header.cd_entries;
1483       pxdb_header_p->aa_entries = doc_header.aa_entries;
1484       pxdb_header_p->oi_entries = doc_header.oi_entries;
1485       pxdb_header_p->version = doc_header.version;
1486     }                           /* PINFO section */
1487
1488   else
1489     {
1490 #ifdef DUMPING
1491       if (dumping)
1492         printf ("==No debug info at all for %s.\n", objfile->name);
1493 #endif
1494
1495       return 0;
1496
1497     }
1498
1499   return 1;
1500 }                               /* End of hpread_get_header */
1501 #endif /* QUICK_LOOK_UP */
1502 \f
1503
1504 /* Initialization for reading native HP C debug symbols from OBJFILE.
1505
1506    Its only purpose in life is to set up the symbol reader's private
1507    per-objfile data structures, and read in the raw contents of the debug
1508    sections (attaching pointers to the debug info into the private data
1509    structures).
1510
1511    Since BFD doesn't know how to read debug symbols in a format-independent
1512    way (and may never do so...), we have to do it ourselves.  Note we may
1513    be called on a file without native HP C debugging symbols.
1514
1515    FIXME, there should be a cleaner peephole into the BFD environment
1516    here. */
1517 void
1518 hpread_symfile_init (objfile)
1519      struct objfile *objfile;
1520 {
1521   asection *vt_section, *slt_section, *lntt_section, *gntt_section;
1522
1523   /* Allocate struct to keep track of the symfile */
1524   objfile->sym_private = (PTR)
1525     xmmalloc (objfile->md, sizeof (struct hpread_symfile_info));
1526   memset (objfile->sym_private, 0, sizeof (struct hpread_symfile_info));
1527
1528   /* We haven't read in any types yet.  */
1529   TYPE_VECTOR (objfile) = 0;
1530
1531   /* Read in data from the $GNTT$ subspace.  */
1532   gntt_section = bfd_get_section_by_name (objfile->obfd, "$GNTT$");
1533   if (!gntt_section)
1534     return;
1535
1536   GNTT (objfile)
1537     = obstack_alloc (&objfile->symbol_obstack,
1538                      bfd_section_size (objfile->obfd, gntt_section));
1539
1540   bfd_get_section_contents (objfile->obfd, gntt_section, GNTT (objfile),
1541                             0, bfd_section_size (objfile->obfd, gntt_section));
1542
1543   GNTT_SYMCOUNT (objfile)
1544     = bfd_section_size (objfile->obfd, gntt_section)
1545     / sizeof (struct dntt_type_block);
1546
1547   /* Read in data from the $LNTT$ subspace.   Also keep track of the number
1548      of LNTT symbols.
1549
1550      FIXME: this could be moved into the psymtab-to-symtab expansion
1551      code, and save startup time.  At the moment this data is
1552      still used, though.  We'd need a way to tell hp-symtab-read.c
1553      whether or not to load the LNTT. */
1554   lntt_section = bfd_get_section_by_name (objfile->obfd, "$LNTT$");
1555   if (!lntt_section)
1556     return;
1557
1558   LNTT (objfile)
1559     = obstack_alloc (&objfile->symbol_obstack,
1560                      bfd_section_size (objfile->obfd, lntt_section));
1561
1562   bfd_get_section_contents (objfile->obfd, lntt_section, LNTT (objfile),
1563                             0, bfd_section_size (objfile->obfd, lntt_section));
1564
1565   LNTT_SYMCOUNT (objfile)
1566     = bfd_section_size (objfile->obfd, lntt_section)
1567     / sizeof (struct dntt_type_block);
1568
1569   /* Read in data from the $SLT$ subspace.  $SLT$ contains information
1570      on source line numbers.  */
1571   slt_section = bfd_get_section_by_name (objfile->obfd, "$SLT$");
1572   if (!slt_section)
1573     return;
1574
1575   SLT (objfile) =
1576     obstack_alloc (&objfile->symbol_obstack,
1577                    bfd_section_size (objfile->obfd, slt_section));
1578
1579   bfd_get_section_contents (objfile->obfd, slt_section, SLT (objfile),
1580                             0, bfd_section_size (objfile->obfd, slt_section));
1581
1582   /* Read in data from the $VT$ subspace.  $VT$ contains things like
1583      names and constants.  Keep track of the number of symbols in the VT.  */
1584   vt_section = bfd_get_section_by_name (objfile->obfd, "$VT$");
1585   if (!vt_section)
1586     return;
1587
1588   VT_SIZE (objfile) = bfd_section_size (objfile->obfd, vt_section);
1589
1590   VT (objfile) =
1591     (char *) obstack_alloc (&objfile->symbol_obstack,
1592                             VT_SIZE (objfile));
1593
1594   bfd_get_section_contents (objfile->obfd, vt_section, VT (objfile),
1595                             0, VT_SIZE (objfile));
1596 }
1597
1598 /* Scan and build partial symbols for a symbol file.
1599
1600    The minimal symbol table (either SOM or HP a.out) has already been
1601    read in; all we need to do is setup partial symbols based on the
1602    native debugging information.
1603
1604    Note that the minimal table is produced by the linker, and has
1605    only global routines in it; the psymtab is based on compiler-
1606    generated debug information and has non-global
1607    routines in it as well as files and class information.
1608
1609    We assume hpread_symfile_init has been called to initialize the
1610    symbol reader's private data structures.
1611
1612    SECTION_OFFSETS contains offsets relative to which the symbols in the
1613    various sections are (depending where the sections were actually loaded).
1614    MAINLINE is true if we are reading the main symbol table (as
1615    opposed to a shared lib or dynamically loaded file). */
1616 void
1617 hpread_build_psymtabs (objfile, section_offsets, mainline)
1618      struct objfile *objfile;
1619      struct section_offsets *section_offsets;
1620      int mainline;
1621 {
1622
1623 #ifdef DUMPING
1624   /* Turn this on to get debugging output. */
1625   static int dumping = 0;
1626 #endif
1627
1628   char *namestring;
1629   int past_first_source_file = 0;
1630   struct cleanup *old_chain;
1631
1632   int hp_symnum, symcount, i;
1633   int scan_start;
1634
1635   union dnttentry *dn_bufp;
1636   unsigned long valu;
1637   char *p;
1638   int texthigh = 0;
1639   int have_name = 0;
1640
1641   /* Current partial symtab */
1642   struct partial_symtab *pst;
1643
1644   /* List of current psymtab's include files */
1645   char **psymtab_include_list;
1646   int includes_allocated;
1647   int includes_used;
1648
1649   /* Index within current psymtab dependency list */
1650   struct partial_symtab **dependency_list;
1651   int dependencies_used, dependencies_allocated;
1652
1653   /* Just in case the stabs reader left turds lying around.  */
1654   free_pending_blocks ();
1655   make_cleanup (really_free_pendings, 0);
1656
1657   pst = (struct partial_symtab *) 0;
1658
1659   /* We shouldn't use alloca, instead use malloc/free.  Doing so avoids
1660      a number of problems with cross compilation and creating useless holes
1661      in the stack when we have to allocate new entries.  FIXME.  */
1662
1663   includes_allocated = 30;
1664   includes_used = 0;
1665   psymtab_include_list = (char **) alloca (includes_allocated *
1666                                            sizeof (char *));
1667
1668   dependencies_allocated = 30;
1669   dependencies_used = 0;
1670   dependency_list =
1671     (struct partial_symtab **) alloca (dependencies_allocated *
1672                                        sizeof (struct partial_symtab *));
1673
1674   old_chain = make_cleanup (free_objfile, objfile);
1675
1676   last_source_file = 0;
1677
1678 #ifdef QUICK_LOOK_UP
1679   {
1680     /* Begin code for new-style loading of quick look-up tables. */
1681
1682     /* elz: this checks whether the file has beeen processed by pxdb.
1683        If not we would like to try to read the psymbols in
1684        anyway, but it turns out to be not so easy. So this could 
1685        actually be commented out, but I leave it in, just in case
1686        we decide to add support for non-pxdb-ed stuff in the future. */
1687     bfd *abfd;
1688     abfd = symfile_bfd_open (objfile->name);
1689     if (!hpread_pxdb_needed (abfd))
1690       {
1691         if (psym_new_style)
1692           {
1693             PXDB_header pxdb_header;
1694             int found_modules_in_program;
1695
1696             if (hpread_get_header (objfile, &pxdb_header))
1697               {
1698                 /* Build a minimal table.  No types, no global variables,
1699                    no include files.... */
1700 #ifdef DUMPING
1701                 if (dumping)
1702                   printf ("\nNew method for %s\n", objfile->name);
1703 #endif
1704
1705                 /* elz: quick_traverse returns true if it found
1706                    some modules in the main source file, other
1707                    than those in end.c
1708                    In C and C++, all the files have MODULES entries
1709                    in the LNTT, and the quick table traverse is all 
1710                    based on finding these MODULES entries. Without 
1711                    those it cannot work. 
1712                    It happens that F77 programs don't have MODULES
1713                    so the quick traverse gets confused. F90 programs
1714                    have modules, and the quick method still works.
1715                    So, if modules (other than those in end.c) are
1716                    not found we give up on the quick table stuff, 
1717                    and fall back on the slower method  */
1718                 found_modules_in_program = hpread_quick_traverse (objfile,
1719                                                                   section_offsets,
1720                                                                   GNTT (objfile),
1721                                                                   VT (objfile),
1722                                                                   &pxdb_header);
1723
1724                 discard_cleanups (old_chain);
1725
1726                 /* Set up to scan the global section of the LNTT.
1727
1728                    This field is not always correct: if there are
1729                    no globals, it will point to the last record in
1730                    the regular LNTT, which is usually an END MODULE.
1731
1732                    Since it might happen that there could be a file
1733                    with just one global record, there's no way to
1734                    tell other than by looking at the record, so that's
1735                    done below. */
1736                 if (found_modules_in_program)
1737                   scan_start = pxdb_header.globals;
1738                 else
1739                   scan_start = 0;
1740               }
1741
1742 #ifdef DUMPING
1743             else
1744               {
1745                 if (dumping)
1746                   printf ("\nGoing on to old method for %s\n", objfile->name);
1747               }
1748 #endif
1749
1750           }                     /* End of new method code */
1751       }                         /* end of if pxdb exists */
1752     /* elz: if pxdb does not exists on the system, then scan the whole debug info
1753        Actually this will never be reached because we error out in case there 
1754        is no pxdb on the system. It turns out that the debug info cannot be
1755        handled the same way as after bxdb has been run, and gdb gets very 
1756        very confused. Ileave this in anyway, in case one day we want to 
1757        support non pxdb-ed files. */
1758     else
1759       scan_start = 0;
1760
1761     bfd_close (abfd);           /* close the bfd we opened to check for pxdb */
1762
1763   }                             /* end of ifdef QUICK_LOOK_UP */
1764 #else
1765   scan_start = 0;               /* if we don't want quick lookup tables start
1766                                    from the beginning */
1767 #endif
1768
1769   /* Make two passes, one over the GNTT symbols, the other for the
1770      LNTT symbols.
1771
1772      JB comment: above isn't true--they only make one pass, over
1773      the LNTT.  */
1774   for (i = 0; i < 1; i++)
1775     {
1776       int within_function = 0;
1777
1778       if (i)
1779         symcount = GNTT_SYMCOUNT (objfile);
1780       else
1781         symcount = LNTT_SYMCOUNT (objfile);
1782
1783
1784       for (hp_symnum = scan_start; hp_symnum < symcount; hp_symnum++)
1785         {
1786           QUIT;
1787           if (i)
1788             dn_bufp = hpread_get_gntt (hp_symnum, objfile);
1789           else
1790             dn_bufp = hpread_get_lntt (hp_symnum, objfile);
1791
1792           if (dn_bufp->dblock.extension)
1793             continue;
1794
1795           /* Only handle things which are necessary for minimal symbols.
1796              everything else is ignored.  */
1797           switch (dn_bufp->dblock.kind)
1798             {
1799             case DNTT_TYPE_SRCFILE:
1800               {
1801 #ifdef QUICK_LOOK_UP
1802                 if (scan_start == hp_symnum
1803                     && symcount == hp_symnum + 1)
1804                   {
1805                     /* If there are NO globals in an executable,
1806                        PXDB's index to the globals will point to
1807                        the last record in the file, which 
1808                        could be this record. (this happened for F77 libraries)
1809                        ignore it and be done! */
1810                     continue;
1811                   }
1812 #endif
1813
1814                 /* A source file of some kind.  Note this may simply
1815                    be an included file.  */
1816                 SET_NAMESTRING (dn_bufp, &namestring, objfile);
1817
1818                 /* Check if this is the source file we are already working
1819                    with.  */
1820                 if (pst && !strcmp (namestring, pst->filename))
1821                   continue;
1822
1823                 /* Check if this is an include file, if so check if we have
1824                    already seen it.  Add it to the include list */
1825                 p = strrchr (namestring, '.');
1826                 if (!strcmp (p, ".h"))
1827                   {
1828                     int j, found;
1829
1830                     found = 0;
1831                     for (j = 0; j < includes_used; j++)
1832                       if (!strcmp (namestring, psymtab_include_list[j]))
1833                         {
1834                           found = 1;
1835                           break;
1836                         }
1837                     if (found)
1838                       continue;
1839
1840                     /* Add it to the list of includes seen so far and
1841                        allocate more include space if necessary.  */
1842                     psymtab_include_list[includes_used++] = namestring;
1843                     if (includes_used >= includes_allocated)
1844                       {
1845                         char **orig = psymtab_include_list;
1846
1847                         psymtab_include_list = (char **)
1848                           alloca ((includes_allocated *= 2) *
1849                                   sizeof (char *));
1850                         memcpy ((PTR) psymtab_include_list, (PTR) orig,
1851                                 includes_used * sizeof (char *));
1852                       }
1853                     continue;
1854                   }
1855
1856                 if (pst)
1857                   {
1858                     if (!have_name)
1859                       {
1860                         pst->filename = (char *)
1861                           obstack_alloc (&pst->objfile->psymbol_obstack,
1862                                          strlen (namestring) + 1);
1863                         strcpy (pst->filename, namestring);
1864                         have_name = 1;
1865                         continue;
1866                       }
1867                     continue;
1868                   }
1869
1870                 /* This is a bonafide new source file.
1871                    End the current partial symtab and start a new one.  */
1872
1873                 if (pst && past_first_source_file)
1874                   {
1875                     hpread_end_psymtab (pst, psymtab_include_list,
1876                                         includes_used,
1877                                         (hp_symnum
1878                                          * sizeof (struct dntt_type_block)),
1879                                         texthigh,
1880                                         dependency_list, dependencies_used);
1881                     pst = (struct partial_symtab *) 0;
1882                     includes_used = 0;
1883                     dependencies_used = 0;
1884                   }
1885                 else
1886                   past_first_source_file = 1;
1887
1888                 valu = hpread_get_textlow (i, hp_symnum, objfile, symcount);
1889                 valu += ANOFFSET (section_offsets, SECT_OFF_TEXT);
1890                 pst = hpread_start_psymtab (objfile, section_offsets,
1891                                             namestring, valu,
1892                                             (hp_symnum
1893                                              * sizeof (struct dntt_type_block)),
1894                                             objfile->global_psymbols.next,
1895                                             objfile->static_psymbols.next);
1896                 texthigh = valu;
1897                 have_name = 1;
1898                 continue;
1899               }
1900
1901             case DNTT_TYPE_MODULE:
1902               /* A source file.  It's still unclear to me what the
1903                  real difference between a DNTT_TYPE_SRCFILE and DNTT_TYPE_MODULE
1904                  is supposed to be.  */
1905
1906               /* First end the previous psymtab */
1907               if (pst)
1908                 {
1909                   hpread_end_psymtab (pst, psymtab_include_list, includes_used,
1910                                       ((hp_symnum - 1)
1911                                        * sizeof (struct dntt_type_block)),
1912                                       texthigh,
1913                                       dependency_list, dependencies_used);
1914                   pst = (struct partial_symtab *) 0;
1915                   includes_used = 0;
1916                   dependencies_used = 0;
1917                   have_name = 0;
1918                 }
1919
1920               /* Now begin a new module and a new psymtab for it */
1921               SET_NAMESTRING (dn_bufp, &namestring, objfile);
1922               valu = hpread_get_textlow (i, hp_symnum, objfile, symcount);
1923               valu += ANOFFSET (section_offsets, SECT_OFF_TEXT);
1924               if (!pst)
1925                 {
1926                   pst = hpread_start_psymtab (objfile, section_offsets,
1927                                               namestring, valu,
1928                                               (hp_symnum
1929                                                * sizeof (struct dntt_type_block)),
1930                                               objfile->global_psymbols.next,
1931                                               objfile->static_psymbols.next);
1932                   texthigh = valu;
1933                   have_name = 0;
1934                 }
1935               continue;
1936
1937             case DNTT_TYPE_FUNCTION:
1938             case DNTT_TYPE_ENTRY:
1939               /* The beginning of a function.  DNTT_TYPE_ENTRY may also denote
1940                  a secondary entry point.  */
1941               valu = dn_bufp->dfunc.hiaddr + ANOFFSET (section_offsets,
1942                                                        SECT_OFF_TEXT);
1943               if (valu > texthigh)
1944                 texthigh = valu;
1945               valu = dn_bufp->dfunc.lowaddr +
1946                 ANOFFSET (section_offsets, SECT_OFF_TEXT);
1947               SET_NAMESTRING (dn_bufp, &namestring, objfile);
1948               if (dn_bufp->dfunc.global)
1949                 add_psymbol_to_list (namestring, strlen (namestring),
1950                                      VAR_NAMESPACE, LOC_BLOCK,
1951                                      &objfile->global_psymbols, valu,
1952                                      0, language_unknown, objfile);
1953               else
1954                 add_psymbol_to_list (namestring, strlen (namestring),
1955                                      VAR_NAMESPACE, LOC_BLOCK,
1956                                      &objfile->static_psymbols, valu,
1957                                      0, language_unknown, objfile);
1958               within_function = 1;
1959               continue;
1960
1961             case DNTT_TYPE_DOC_FUNCTION:
1962               valu = dn_bufp->ddocfunc.hiaddr + ANOFFSET (section_offsets,
1963                                                           SECT_OFF_TEXT);
1964               if (valu > texthigh)
1965                 texthigh = valu;
1966               valu = dn_bufp->ddocfunc.lowaddr +
1967                 ANOFFSET (section_offsets, SECT_OFF_TEXT);
1968               SET_NAMESTRING (dn_bufp, &namestring, objfile);
1969               if (dn_bufp->ddocfunc.global)
1970                 add_psymbol_to_list (namestring, strlen (namestring),
1971                                      VAR_NAMESPACE, LOC_BLOCK,
1972                                      &objfile->global_psymbols, valu,
1973                                      0, language_unknown, objfile);
1974               else
1975                 add_psymbol_to_list (namestring, strlen (namestring),
1976                                      VAR_NAMESPACE, LOC_BLOCK,
1977                                      &objfile->static_psymbols, valu,
1978                                      0, language_unknown, objfile);
1979               within_function = 1;
1980               continue;
1981
1982             case DNTT_TYPE_BEGIN:
1983             case DNTT_TYPE_END:
1984               /* We don't check MODULE end here, because there can be
1985                  symbols beyond the module end which properly belong to the
1986                  current psymtab -- so we wait till the next MODULE start */
1987
1988
1989 #ifdef QUICK_LOOK_UP
1990               if (scan_start == hp_symnum
1991                   && symcount == hp_symnum + 1)
1992                 {
1993                   /* If there are NO globals in an executable,
1994                      PXDB's index to the globals will point to
1995                      the last record in the file, which is
1996                      probably an END MODULE, i.e. this record.
1997                      ignore it and be done! */
1998                   continue;
1999                 }
2000 #endif
2001               /* Scope block begin/end.  We only care about function
2002                  and file blocks right now.  */
2003
2004               if ((dn_bufp->dend.endkind == DNTT_TYPE_FUNCTION) ||
2005                   (dn_bufp->dend.endkind == DNTT_TYPE_DOC_FUNCTION))
2006                 within_function = 0;
2007               continue;
2008
2009             case DNTT_TYPE_SVAR:
2010             case DNTT_TYPE_DVAR:
2011             case DNTT_TYPE_TYPEDEF:
2012             case DNTT_TYPE_TAGDEF:
2013               {
2014                 /* Variables, typedefs an the like.  */
2015                 enum address_class storage;
2016                 namespace_enum namespace;
2017
2018                 /* Don't add locals to the partial symbol table.  */
2019                 if (within_function
2020                     && (dn_bufp->dblock.kind == DNTT_TYPE_SVAR
2021                         || dn_bufp->dblock.kind == DNTT_TYPE_DVAR))
2022                   continue;
2023
2024                 /* TAGDEFs go into the structure namespace.  */
2025                 if (dn_bufp->dblock.kind == DNTT_TYPE_TAGDEF)
2026                   namespace = STRUCT_NAMESPACE;
2027                 else
2028                   namespace = VAR_NAMESPACE;
2029
2030                 /* What kind of "storage" does this use?  */
2031                 if (dn_bufp->dblock.kind == DNTT_TYPE_SVAR)
2032                   storage = LOC_STATIC;
2033                 else if (dn_bufp->dblock.kind == DNTT_TYPE_DVAR
2034                          && dn_bufp->ddvar.regvar)
2035                   storage = LOC_REGISTER;
2036                 else if (dn_bufp->dblock.kind == DNTT_TYPE_DVAR)
2037                   storage = LOC_LOCAL;
2038                 else
2039                   storage = LOC_UNDEF;
2040
2041                 SET_NAMESTRING (dn_bufp, &namestring, objfile);
2042                 if (!pst)
2043                   {
2044                     pst = hpread_start_psymtab (objfile, section_offsets,
2045                                                 "globals", 0,
2046                                                 (hp_symnum
2047                                                  * sizeof (struct dntt_type_block)),
2048                                                 objfile->global_psymbols.next,
2049                                                 objfile->static_psymbols.next);
2050                   }
2051
2052                 /* Compute address of the data symbol */
2053                 valu = dn_bufp->dsvar.location;
2054                 /* Relocate in case it's in a shared library */
2055                 if (storage == LOC_STATIC)
2056                   valu += ANOFFSET (section_offsets, SECT_OFF_DATA);
2057
2058                 /* Luckily, dvar, svar, typedef, and tagdef all
2059                    have their "global" bit in the same place, so it works
2060                    (though it's bad programming practice) to reference
2061                    "dsvar.global" even though we may be looking at
2062                    any of the above four types. */
2063                 if (dn_bufp->dsvar.global)
2064                   {
2065                     add_psymbol_to_list (namestring, strlen (namestring),
2066                                          namespace, storage,
2067                                          &objfile->global_psymbols,
2068                                          valu,
2069                                          0, language_unknown, objfile);
2070                   }
2071                 else
2072                   {
2073                     add_psymbol_to_list (namestring, strlen (namestring),
2074                                          namespace, storage,
2075                                          &objfile->static_psymbols,
2076                                          valu,
2077                                          0, language_unknown, objfile);
2078                   }
2079
2080                 /* For TAGDEF's, the above code added the tagname to the
2081                    struct namespace. This will cause tag "t" to be found
2082                    on a reference of the form "(struct t) x". But for
2083                    C++ classes, "t" will also be a typename, which we
2084                    want to find on a reference of the form "ptype t".
2085                    Therefore, we also add "t" to the var namespace.
2086                    Do the same for enum's due to the way aCC generates
2087                    debug info for these (see more extended comment
2088                    in hp-symtab-read.c).
2089                    We do the same for templates, so that "ptype t"
2090                    where "t" is a template also works. */
2091                 if (dn_bufp->dblock.kind == DNTT_TYPE_TAGDEF &&
2092                   dn_bufp->dtype.type.dnttp.index < LNTT_SYMCOUNT (objfile))
2093                   {
2094                     int global = dn_bufp->dtag.global;
2095                     /* Look ahead to see if it's a C++ class */
2096                     dn_bufp = hpread_get_lntt (dn_bufp->dtype.type.dnttp.index, objfile);
2097                     if (dn_bufp->dblock.kind == DNTT_TYPE_CLASS ||
2098                         dn_bufp->dblock.kind == DNTT_TYPE_ENUM ||
2099                         dn_bufp->dblock.kind == DNTT_TYPE_TEMPLATE)
2100                       {
2101                         if (global)
2102                           {
2103                             add_psymbol_to_list (namestring, strlen (namestring),
2104                                                  VAR_NAMESPACE, storage,
2105                                                  &objfile->global_psymbols,
2106                                                  dn_bufp->dsvar.location,
2107                                                  0, language_unknown, objfile);
2108                           }
2109                         else
2110                           {
2111                             add_psymbol_to_list (namestring, strlen (namestring),
2112                                                  VAR_NAMESPACE, storage,
2113                                                  &objfile->static_psymbols,
2114                                                  dn_bufp->dsvar.location,
2115                                                  0, language_unknown, objfile);
2116                           }
2117                       }
2118                   }
2119               }
2120               continue;
2121
2122             case DNTT_TYPE_MEMENUM:
2123             case DNTT_TYPE_CONST:
2124               /* Constants and members of enumerated types.  */
2125               SET_NAMESTRING (dn_bufp, &namestring, objfile);
2126               if (!pst)
2127                 {
2128                   pst = hpread_start_psymtab (objfile, section_offsets,
2129                                               "globals", 0,
2130                                               (hp_symnum
2131                                                * sizeof (struct dntt_type_block)),
2132                                               objfile->global_psymbols.next,
2133                                               objfile->static_psymbols.next);
2134                 }
2135               if (dn_bufp->dconst.global)
2136                 add_psymbol_to_list (namestring, strlen (namestring),
2137                                      VAR_NAMESPACE, LOC_CONST,
2138                                      &objfile->global_psymbols, 0,
2139                                      0, language_unknown, objfile);
2140               else
2141                 add_psymbol_to_list (namestring, strlen (namestring),
2142                                      VAR_NAMESPACE, LOC_CONST,
2143                                      &objfile->static_psymbols, 0,
2144                                      0, language_unknown, objfile);
2145               continue;
2146             default:
2147               continue;
2148             }
2149         }
2150     }
2151
2152   /* End any pending partial symbol table. */
2153   if (pst)
2154     {
2155       hpread_end_psymtab (pst, psymtab_include_list, includes_used,
2156                           hp_symnum * sizeof (struct dntt_type_block),
2157                           0, dependency_list, dependencies_used);
2158     }
2159
2160   discard_cleanups (old_chain);
2161 }
2162
2163 /* Perform any local cleanups required when we are done with a particular
2164    objfile.  I.E, we are in the process of discarding all symbol information
2165    for an objfile, freeing up all memory held for it, and unlinking the
2166    objfile struct from the global list of known objfiles. */
2167
2168 void
2169 hpread_symfile_finish (objfile)
2170      struct objfile *objfile;
2171 {
2172   if (objfile->sym_private != NULL)
2173     {
2174       mfree (objfile->md, objfile->sym_private);
2175     }
2176 }
2177 \f
2178
2179 /* The remaining functions are all for internal use only.  */
2180
2181 /* Various small functions to get entries in the debug symbol sections.  */
2182
2183 union dnttentry *
2184 hpread_get_lntt (index, objfile)
2185      int index;
2186      struct objfile *objfile;
2187 {
2188   return (union dnttentry *)
2189     &(LNTT (objfile)[(index * sizeof (struct dntt_type_block))]);
2190 }
2191
2192 static union dnttentry *
2193 hpread_get_gntt (index, objfile)
2194      int index;
2195      struct objfile *objfile;
2196 {
2197   return (union dnttentry *)
2198     &(GNTT (objfile)[(index * sizeof (struct dntt_type_block))]);
2199 }
2200
2201 union sltentry *
2202 hpread_get_slt (index, objfile)
2203      int index;
2204      struct objfile *objfile;
2205 {
2206   return (union sltentry *) &(SLT (objfile)[index * sizeof (union sltentry)]);
2207 }
2208
2209 /* Get the low address associated with some symbol (typically the start
2210    of a particular source file or module).  Since that information is not
2211    stored as part of the DNTT_TYPE_MODULE or DNTT_TYPE_SRCFILE symbol we must infer it from
2212    the existance of DNTT_TYPE_FUNCTION symbols.  */
2213
2214 static unsigned long
2215 hpread_get_textlow (global, index, objfile, symcount)
2216      int global;
2217      int index;
2218      struct objfile *objfile;
2219      int symcount;
2220 {
2221   union dnttentry *dn_bufp;
2222   struct minimal_symbol *msymbol;
2223
2224   /* Look for a DNTT_TYPE_FUNCTION symbol.  */
2225   if (index < symcount)         /* symcount is the number of symbols in */
2226     {                           /*   the dbinfo, LNTT table */
2227       do
2228         {
2229           if (global)
2230             dn_bufp = hpread_get_gntt (index++, objfile);
2231           else
2232             dn_bufp = hpread_get_lntt (index++, objfile);
2233         }
2234       while (dn_bufp->dblock.kind != DNTT_TYPE_FUNCTION
2235              && dn_bufp->dblock.kind != DNTT_TYPE_DOC_FUNCTION
2236              && dn_bufp->dblock.kind != DNTT_TYPE_END
2237              && index < symcount);
2238     }
2239
2240   /* Avoid going past a DNTT_TYPE_END when looking for a DNTT_TYPE_FUNCTION.  This
2241      might happen when a sourcefile has no functions.  */
2242   if (dn_bufp->dblock.kind == DNTT_TYPE_END)
2243     return 0;
2244
2245   /* Avoid going past the end of the LNTT file */
2246   if (index == symcount)
2247     return 0;
2248
2249   /* The minimal symbols are typically more accurate for some reason.  */
2250   if (dn_bufp->dblock.kind == DNTT_TYPE_FUNCTION)
2251     msymbol = lookup_minimal_symbol (dn_bufp->dfunc.name + VT (objfile), NULL,
2252                                      objfile);
2253   else                          /* must be a DNTT_TYPE_DOC_FUNCTION */
2254     msymbol = lookup_minimal_symbol (dn_bufp->ddocfunc.name + VT (objfile), NULL,
2255                                      objfile);
2256
2257   if (msymbol)
2258     return SYMBOL_VALUE_ADDRESS (msymbol);
2259   else
2260     return dn_bufp->dfunc.lowaddr;
2261 }
2262
2263 /* Allocate and partially fill a partial symtab.  It will be
2264    completely filled at the end of the symbol list.
2265
2266    SYMFILE_NAME is the name of the symbol-file we are reading from, and ADDR
2267    is the address relative to which its symbols are (incremental) or 0
2268    (normal). */
2269
2270 static struct partial_symtab *
2271 hpread_start_psymtab (objfile, section_offsets,
2272                       filename, textlow, ldsymoff, global_syms, static_syms)
2273      struct objfile *objfile;
2274      struct section_offsets *section_offsets;
2275      char *filename;
2276      CORE_ADDR textlow;
2277      int ldsymoff;
2278      struct partial_symbol **global_syms;
2279      struct partial_symbol **static_syms;
2280 {
2281   int offset = ANOFFSET (section_offsets, SECT_OFF_TEXT);
2282   extern void hpread_psymtab_to_symtab ();
2283   struct partial_symtab *result =
2284   start_psymtab_common (objfile, section_offsets,
2285                         filename, textlow, global_syms, static_syms);
2286
2287   result->textlow += offset;
2288   result->read_symtab_private = (char *)
2289     obstack_alloc (&objfile->psymbol_obstack, sizeof (struct symloc));
2290   LDSYMOFF (result) = ldsymoff;
2291   result->read_symtab = hpread_psymtab_to_symtab;
2292
2293   return result;
2294 }
2295 \f
2296
2297 /* Close off the current usage of PST.  
2298    Returns PST or NULL if the partial symtab was empty and thrown away.
2299
2300    capping_symbol_offset  --Byte index in LNTT or GNTT of the
2301    last symbol processed during the build
2302    of the previous pst.
2303
2304    FIXME:  List variables and peculiarities of same.  */
2305
2306 static struct partial_symtab *
2307 hpread_end_psymtab (pst, include_list, num_includes, capping_symbol_offset,
2308                     capping_text, dependency_list, number_dependencies)
2309      struct partial_symtab *pst;
2310      char **include_list;
2311      int num_includes;
2312      int capping_symbol_offset;
2313      CORE_ADDR capping_text;
2314      struct partial_symtab **dependency_list;
2315      int number_dependencies;
2316 {
2317   int i;
2318   struct objfile *objfile = pst->objfile;
2319   int offset = ANOFFSET (pst->section_offsets, SECT_OFF_TEXT);
2320
2321 #ifdef DUMPING
2322   /* Turn on to see what kind of a psymtab we've built. */
2323   static int dumping = 0;
2324 #endif
2325
2326   if (capping_symbol_offset != -1)
2327     LDSYMLEN (pst) = capping_symbol_offset - LDSYMOFF (pst);
2328   else
2329     LDSYMLEN (pst) = 0;
2330   pst->texthigh = capping_text + offset;
2331
2332   pst->n_global_syms =
2333     objfile->global_psymbols.next - (objfile->global_psymbols.list + pst->globals_offset);
2334   pst->n_static_syms =
2335     objfile->static_psymbols.next - (objfile->static_psymbols.list + pst->statics_offset);
2336
2337 #ifdef DUMPING
2338   if (dumping)
2339     {
2340       printf ("\nPst %s, LDSYMOFF %x (%x), LDSYMLEN %x (%x), globals %d, statics %d\n",
2341               pst->filename,
2342               LDSYMOFF (pst),
2343               LDSYMOFF (pst) / sizeof (struct dntt_type_block),
2344               LDSYMLEN (pst),
2345               LDSYMLEN (pst) / sizeof (struct dntt_type_block),
2346               pst->n_global_syms, pst->n_static_syms);
2347     }
2348 #endif
2349
2350   pst->number_of_dependencies = number_dependencies;
2351   if (number_dependencies)
2352     {
2353       pst->dependencies = (struct partial_symtab **)
2354         obstack_alloc (&objfile->psymbol_obstack,
2355                        number_dependencies * sizeof (struct partial_symtab *));
2356       memcpy (pst->dependencies, dependency_list,
2357               number_dependencies * sizeof (struct partial_symtab *));
2358     }
2359   else
2360     pst->dependencies = 0;
2361
2362   for (i = 0; i < num_includes; i++)
2363     {
2364       struct partial_symtab *subpst =
2365       allocate_psymtab (include_list[i], objfile);
2366
2367       subpst->section_offsets = pst->section_offsets;
2368       subpst->read_symtab_private =
2369         (char *) obstack_alloc (&objfile->psymbol_obstack,
2370                                 sizeof (struct symloc));
2371       LDSYMOFF (subpst) =
2372         LDSYMLEN (subpst) =
2373         subpst->textlow =
2374         subpst->texthigh = 0;
2375
2376       /* We could save slight bits of space by only making one of these,
2377          shared by the entire set of include files.  FIXME-someday.  */
2378       subpst->dependencies = (struct partial_symtab **)
2379         obstack_alloc (&objfile->psymbol_obstack,
2380                        sizeof (struct partial_symtab *));
2381       subpst->dependencies[0] = pst;
2382       subpst->number_of_dependencies = 1;
2383
2384       subpst->globals_offset =
2385         subpst->n_global_syms =
2386         subpst->statics_offset =
2387         subpst->n_static_syms = 0;
2388
2389       subpst->readin = 0;
2390       subpst->symtab = 0;
2391       subpst->read_symtab = pst->read_symtab;
2392     }
2393
2394   sort_pst_symbols (pst);
2395
2396   /* If there is already a psymtab or symtab for a file of this name, remove it.
2397      (If there is a symtab, more drastic things also happen.)
2398      This happens in VxWorks.  */
2399   free_named_symtabs (pst->filename);
2400
2401   if (num_includes == 0
2402       && number_dependencies == 0
2403       && pst->n_global_syms == 0
2404       && pst->n_static_syms == 0)
2405     {
2406       /* Throw away this psymtab, it's empty.  We can't deallocate it, since
2407          it is on the obstack, but we can forget to chain it on the list. 
2408          Empty psymtabs happen as a result of header files which don't have
2409          any symbols in them.  There can be a lot of them.  But this check
2410          is wrong, in that a psymtab with N_SLINE entries but nothing else
2411          is not empty, but we don't realize that.  Fixing that without slowing
2412          things down might be tricky.
2413          It's also wrong if we're using the quick look-up tables, as
2414          we can get empty psymtabs from modules with no routines in
2415          them. */
2416
2417       discard_psymtab (pst);
2418
2419       /* Indicate that psymtab was thrown away.  */
2420       pst = (struct partial_symtab *) NULL;
2421
2422     }
2423   return pst;
2424 }
2425
2426
2427 /* End of hp-psymtab-read.c */
2428
2429 /* Set indentation to 4 spaces for Emacs; this file is
2430    mostly non-GNU-ish in its style :-( */
2431 #if 0
2432 ***Local Variables:
2433 ***c - basic - offset:4
2434 *** End:
2435 #endif
2436
2437
This page took 0.163391 seconds and 4 git commands to generate.