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