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