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