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