1130803Smarcel/* Read hp debug symbols and convert to internal format, for GDB. 2130803Smarcel Copyright 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 3130803Smarcel 2002, 2003, 2004 Free Software Foundation, Inc. 4130803Smarcel 5130803Smarcel This file is part of GDB. 6130803Smarcel 7130803Smarcel This program is free software; you can redistribute it and/or modify 8130803Smarcel it under the terms of the GNU General Public License as published by 9130803Smarcel the Free Software Foundation; either version 2 of the License, or 10130803Smarcel (at your option) any later version. 11130803Smarcel 12130803Smarcel This program is distributed in the hope that it will be useful, 13130803Smarcel but WITHOUT ANY WARRANTY; without even the implied warranty of 14130803Smarcel MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15130803Smarcel GNU General Public License for more details. 16130803Smarcel 17130803Smarcel You should have received a copy of the GNU General Public License 18130803Smarcel along with this program; if not, write to the Free Software 19130803Smarcel Foundation, Inc., 59 Temple Place - Suite 330, 20130803Smarcel Boston, MA 02111-1307, USA. 21130803Smarcel 22130803Smarcel Written by the Center for Software Science at the University of Utah 23130803Smarcel and by Cygnus Support. */ 24130803Smarcel 25130803Smarcel#include "defs.h" 26130803Smarcel#include "bfd.h" 27130803Smarcel#include "gdb_string.h" 28130803Smarcel#include "hp-symtab.h" 29130803Smarcel#include "syms.h" 30130803Smarcel#include "symtab.h" 31130803Smarcel#include "symfile.h" 32130803Smarcel#include "objfiles.h" 33130803Smarcel#include "buildsym.h" 34130803Smarcel#include "complaints.h" 35130803Smarcel#include "gdb-stabs.h" 36130803Smarcel#include "gdbtypes.h" 37130803Smarcel#include "demangle.h" 38130803Smarcel#include "somsolib.h" 39130803Smarcel#include "gdb_assert.h" 40130803Smarcel 41130803Smarcel/* Private information attached to an objfile which we use to find 42130803Smarcel and internalize the HP C debug symbols within that objfile. */ 43130803Smarcel 44130803Smarcelstruct hpread_symfile_info 45130803Smarcel { 46130803Smarcel /* The contents of each of the debug sections (there are 4 of them). */ 47130803Smarcel char *gntt; 48130803Smarcel char *lntt; 49130803Smarcel char *slt; 50130803Smarcel char *vt; 51130803Smarcel 52130803Smarcel /* We keep the size of the $VT$ section for range checking. */ 53130803Smarcel unsigned int vt_size; 54130803Smarcel 55130803Smarcel /* Some routines still need to know the number of symbols in the 56130803Smarcel main debug sections ($LNTT$ and $GNTT$). */ 57130803Smarcel unsigned int lntt_symcount; 58130803Smarcel unsigned int gntt_symcount; 59130803Smarcel 60130803Smarcel /* To keep track of all the types we've processed. */ 61130803Smarcel struct type **dntt_type_vector; 62130803Smarcel int dntt_type_vector_length; 63130803Smarcel 64130803Smarcel /* Keeps track of the beginning of a range of source lines. */ 65130803Smarcel sltpointer sl_index; 66130803Smarcel 67130803Smarcel /* Some state variables we'll need. */ 68130803Smarcel int within_function; 69130803Smarcel 70130803Smarcel /* Keep track of the current function's address. We may need to look 71130803Smarcel up something based on this address. */ 72130803Smarcel unsigned int current_function_value; 73130803Smarcel }; 74130803Smarcel 75130803Smarcel/* Accessor macros to get at the fields. */ 76130803Smarcel#define HPUX_SYMFILE_INFO(o) \ 77130803Smarcel ((struct hpread_symfile_info *)((o)->sym_private)) 78130803Smarcel#define GNTT(o) (HPUX_SYMFILE_INFO(o)->gntt) 79130803Smarcel#define LNTT(o) (HPUX_SYMFILE_INFO(o)->lntt) 80130803Smarcel#define SLT(o) (HPUX_SYMFILE_INFO(o)->slt) 81130803Smarcel#define VT(o) (HPUX_SYMFILE_INFO(o)->vt) 82130803Smarcel#define VT_SIZE(o) (HPUX_SYMFILE_INFO(o)->vt_size) 83130803Smarcel#define LNTT_SYMCOUNT(o) (HPUX_SYMFILE_INFO(o)->lntt_symcount) 84130803Smarcel#define GNTT_SYMCOUNT(o) (HPUX_SYMFILE_INFO(o)->gntt_symcount) 85130803Smarcel#define DNTT_TYPE_VECTOR(o) (HPUX_SYMFILE_INFO(o)->dntt_type_vector) 86130803Smarcel#define DNTT_TYPE_VECTOR_LENGTH(o) \ 87130803Smarcel (HPUX_SYMFILE_INFO(o)->dntt_type_vector_length) 88130803Smarcel#define SL_INDEX(o) (HPUX_SYMFILE_INFO(o)->sl_index) 89130803Smarcel#define WITHIN_FUNCTION(o) (HPUX_SYMFILE_INFO(o)->within_function) 90130803Smarcel#define CURRENT_FUNCTION_VALUE(o) (HPUX_SYMFILE_INFO(o)->current_function_value) 91130803Smarcel 92130803Smarcel 93130803Smarcel/* We put a pointer to this structure in the read_symtab_private field 94130803Smarcel of the psymtab. */ 95130803Smarcel 96130803Smarcelstruct symloc 97130803Smarcel { 98130803Smarcel /* The offset within the file symbol table of first local symbol for 99130803Smarcel this file. */ 100130803Smarcel 101130803Smarcel int ldsymoff; 102130803Smarcel 103130803Smarcel /* Length (in bytes) of the section of the symbol table devoted to 104130803Smarcel this file's symbols (actually, the section bracketed may contain 105130803Smarcel more than just this file's symbols). If ldsymlen is 0, the only 106130803Smarcel reason for this thing's existence is the dependency list. 107130803Smarcel Nothing else will happen when it is read in. */ 108130803Smarcel 109130803Smarcel int ldsymlen; 110130803Smarcel }; 111130803Smarcel 112130803Smarcel#define LDSYMOFF(p) (((struct symloc *)((p)->read_symtab_private))->ldsymoff) 113130803Smarcel#define LDSYMLEN(p) (((struct symloc *)((p)->read_symtab_private))->ldsymlen) 114130803Smarcel#define SYMLOC(p) ((struct symloc *)((p)->read_symtab_private)) 115130803Smarcel 116130803Smarcel/* Complaints about the symbols we have encountered. */ 117130803Smarcelstatic void 118130803Smarcellbrac_unmatched_complaint (int arg1) 119130803Smarcel{ 120130803Smarcel complaint (&symfile_complaints, "unmatched N_LBRAC before symtab pos %d", 121130803Smarcel arg1); 122130803Smarcel} 123130803Smarcel 124130803Smarcelstatic void 125130803Smarcellbrac_mismatch_complaint (int arg1) 126130803Smarcel{ 127130803Smarcel complaint (&symfile_complaints, 128130803Smarcel "N_LBRAC/N_RBRAC symbol mismatch at symtab pos %d", arg1); 129130803Smarcel} 130130803Smarcel 131130803Smarcel/* To generate dumping code, uncomment this define. The dumping 132130803Smarcel itself is controlled by routine-local statics called "dumping". */ 133130803Smarcel/* #define DUMPING 1 */ 134130803Smarcel 135130803Smarcel/* To use the quick look-up tables, uncomment this define. */ 136130803Smarcel#define QUICK_LOOK_UP 1 137130803Smarcel 138130803Smarcel/* To call PXDB to process un-processed files, uncomment this define. */ 139130803Smarcel#define USE_PXDB 1 140130803Smarcel 141130803Smarcel/* Forward procedure declarations */ 142130803Smarcel 143130803Smarcel/* Used in somread.c. */ 144130803Smarcelvoid hpread_symfile_init (struct objfile *); 145130803Smarcel 146130803Smarcelvoid do_pxdb (bfd *); 147130803Smarcel 148130803Smarcelvoid hpread_build_psymtabs (struct objfile *, int); 149130803Smarcel 150130803Smarcelvoid hpread_symfile_finish (struct objfile *); 151130803Smarcel 152130803Smarcelstatic void set_namestring (union dnttentry *sym, char **namep, 153130803Smarcel struct objfile *objfile); 154130803Smarcel 155130803Smarcelstatic union dnttentry *hpread_get_gntt (int, struct objfile *); 156130803Smarcel 157130803Smarcelstatic union dnttentry *hpread_get_lntt (int index, struct objfile *objfile); 158130803Smarcel 159130803Smarcel 160130803Smarcelstatic unsigned long hpread_get_textlow (int, int, struct objfile *, int); 161130803Smarcel 162130803Smarcelstatic struct partial_symtab *hpread_start_psymtab 163130803Smarcel (struct objfile *, char *, CORE_ADDR, int, 164130803Smarcel struct partial_symbol **, struct partial_symbol **); 165130803Smarcel 166130803Smarcelstatic struct partial_symtab *hpread_end_psymtab 167130803Smarcel (struct partial_symtab *, char **, int, int, CORE_ADDR, 168130803Smarcel struct partial_symtab **, int); 169130803Smarcel 170130803Smarcelstatic unsigned long hpread_get_scope_start (sltpointer, struct objfile *); 171130803Smarcel 172130803Smarcelstatic unsigned long hpread_get_line (sltpointer, struct objfile *); 173130803Smarcel 174130803Smarcelstatic CORE_ADDR hpread_get_location (sltpointer, struct objfile *); 175130803Smarcel 176130803Smarcelstatic int hpread_has_name (enum dntt_entry_type kind); 177130803Smarcel 178130803Smarcelstatic void hpread_psymtab_to_symtab_1 (struct partial_symtab *); 179130803Smarcel 180130803Smarcelstatic void hpread_psymtab_to_symtab (struct partial_symtab *); 181130803Smarcel 182130803Smarcelstatic struct symtab *hpread_expand_symtab 183130803Smarcel (struct objfile *, int, int, CORE_ADDR, int, 184130803Smarcel struct section_offsets *, char *); 185130803Smarcel 186130803Smarcelstatic int hpread_type_translate (dnttpointer); 187130803Smarcel 188130803Smarcelstatic struct type **hpread_lookup_type (dnttpointer, struct objfile *); 189130803Smarcel 190130803Smarcelstatic struct type *hpread_alloc_type (dnttpointer, struct objfile *); 191130803Smarcel 192130803Smarcelstatic struct type *hpread_read_enum_type 193130803Smarcel (dnttpointer, union dnttentry *, struct objfile *); 194130803Smarcel 195130803Smarcelstatic struct type *hpread_read_function_type 196130803Smarcel (dnttpointer, union dnttentry *, struct objfile *, int); 197130803Smarcel 198130803Smarcelstatic struct type *hpread_read_doc_function_type 199130803Smarcel (dnttpointer, union dnttentry *, struct objfile *, int); 200130803Smarcel 201130803Smarcelstatic struct type *hpread_read_struct_type 202130803Smarcel (dnttpointer, union dnttentry *, struct objfile *); 203130803Smarcel 204130803Smarcelstatic struct type *hpread_get_nth_template_arg (struct objfile *, int); 205130803Smarcel 206130803Smarcelstatic struct type *hpread_read_templ_arg_type 207130803Smarcel (dnttpointer, union dnttentry *, struct objfile *, char *); 208130803Smarcel 209130803Smarcelstatic struct type *hpread_read_set_type 210130803Smarcel (dnttpointer, union dnttentry *, struct objfile *); 211130803Smarcel 212130803Smarcelstatic struct type *hpread_read_array_type 213130803Smarcel (dnttpointer, union dnttentry *dn_bufp, struct objfile *objfile); 214130803Smarcel 215130803Smarcelstatic struct type *hpread_read_subrange_type 216130803Smarcel (dnttpointer, union dnttentry *, struct objfile *); 217130803Smarcel 218130803Smarcelstatic struct type *hpread_type_lookup (dnttpointer, struct objfile *); 219130803Smarcel 220130803Smarcelstatic sltpointer hpread_record_lines 221130803Smarcel (struct subfile *, sltpointer, sltpointer, struct objfile *, CORE_ADDR); 222130803Smarcel 223130803Smarcelstatic void hpread_process_one_debug_symbol 224130803Smarcel (union dnttentry *, char *, struct section_offsets *, 225130803Smarcel struct objfile *, CORE_ADDR, int, char *, int, int *); 226130803Smarcel 227130803Smarcelstatic int hpread_get_scope_depth (union dnttentry *, struct objfile *, int); 228130803Smarcel 229130803Smarcelstatic void fix_static_member_physnames 230130803Smarcel (struct type *, char *, struct objfile *); 231130803Smarcel 232130803Smarcelstatic void fixup_class_method_type 233130803Smarcel (struct type *, struct type *, struct objfile *); 234130803Smarcel 235130803Smarcelstatic void hpread_adjust_bitoffsets (struct type *, int); 236130803Smarcel 237130803Smarcelstatic dnttpointer hpread_get_next_skip_over_anon_unions 238130803Smarcel (int, dnttpointer, union dnttentry **, struct objfile *); 239130803Smarcel 240130803Smarcel 241130803Smarcel/* Global to indicate presence of HP-compiled objects, 242130803Smarcel in particular, SOM executable file with SOM debug info 243130803Smarcel Defined in symtab.c, used in hppa-tdep.c. */ 244130803Smarcelextern int hp_som_som_object_present; 245130803Smarcel 246130803Smarcel/* Static used to indicate a class type that requires a 247130803Smarcel fix-up of one of its method types */ 248130803Smarcelstatic struct type *fixup_class = NULL; 249130803Smarcel 250130803Smarcel/* Static used to indicate the method type that is to be 251130803Smarcel used to fix-up the type for fixup_class */ 252130803Smarcelstatic struct type *fixup_method = NULL; 253130803Smarcel 254130803Smarcel#ifdef USE_PXDB 255130803Smarcel 256130803Smarcel/* NOTE use of system files! May not be portable. */ 257130803Smarcel 258130803Smarcel#define PXDB_SVR4 "/opt/langtools/bin/pxdb" 259130803Smarcel#define PXDB_BSD "/usr/bin/pxdb" 260130803Smarcel 261130803Smarcel#include <stdlib.h> 262130803Smarcel#include "gdb_string.h" 263130803Smarcel 264130803Smarcel/* check for the existence of a file, given its full pathname */ 265130803Smarcelstatic int 266130803Smarcelfile_exists (char *filename) 267130803Smarcel{ 268130803Smarcel if (filename) 269130803Smarcel return (access (filename, F_OK) == 0); 270130803Smarcel return 0; 271130803Smarcel} 272130803Smarcel 273130803Smarcel 274130803Smarcel/* Translate from the "hp_language" enumeration in hp-symtab.h 275130803Smarcel used in the debug info to gdb's generic enumeration in defs.h. */ 276130803Smarcelstatic enum language 277130803Smarceltrans_lang (enum hp_language in_lang) 278130803Smarcel{ 279130803Smarcel if (in_lang == HP_LANGUAGE_C) 280130803Smarcel return language_c; 281130803Smarcel 282130803Smarcel else if (in_lang == HP_LANGUAGE_CPLUSPLUS) 283130803Smarcel return language_cplus; 284130803Smarcel 285130803Smarcel else if (in_lang == HP_LANGUAGE_FORTRAN) 286130803Smarcel return language_fortran; 287130803Smarcel 288130803Smarcel else 289130803Smarcel return language_unknown; 290130803Smarcel} 291130803Smarcel 292130803Smarcelstatic char main_string[] = "main"; 293130803Smarcel 294130803Smarcel 295130803Smarcel/* Given the native debug symbol SYM, set NAMEP to the name associated 296130803Smarcel with the debug symbol. Note we may be called with a debug symbol which 297130803Smarcel has no associated name, in that case we return an empty string. */ 298130803Smarcel 299130803Smarcelstatic void 300130803Smarcelset_namestring (union dnttentry *sym, char **namep, struct objfile *objfile) 301130803Smarcel{ 302130803Smarcel /* Note that we "know" that the name for any symbol is always in the same 303130803Smarcel place. Hence we don't have to conditionalize on the symbol type. */ 304130803Smarcel if (! hpread_has_name (sym->dblock.kind)) 305130803Smarcel *namep = ""; 306130803Smarcel else if ((unsigned) sym->dsfile.name >= VT_SIZE (objfile)) 307130803Smarcel { 308130803Smarcel complaint (&symfile_complaints, "bad string table offset in symbol %d", 309130803Smarcel symnum); 310130803Smarcel *namep = ""; 311130803Smarcel } 312130803Smarcel else 313130803Smarcel *namep = sym->dsfile.name + VT (objfile); 314130803Smarcel} 315130803Smarcel 316130803Smarcel/* Call PXDB to process our file. 317130803Smarcel 318130803Smarcel Approach copied from DDE's "dbgk_run_pxdb". Note: we 319130803Smarcel don't check for BSD location of pxdb, nor for existence 320130803Smarcel of pxdb itself, etc. 321130803Smarcel 322130803Smarcel NOTE: uses system function and string functions directly. 323130803Smarcel 324130803Smarcel Return value: 1 if ok, 0 if not */ 325130803Smarcelstatic int 326130803Smarcelhpread_call_pxdb (const char *file_name) 327130803Smarcel{ 328130803Smarcel char *p; 329130803Smarcel int status; 330130803Smarcel int retval; 331130803Smarcel 332130803Smarcel if (file_exists (PXDB_SVR4)) 333130803Smarcel { 334130803Smarcel p = xmalloc (strlen (PXDB_SVR4) + strlen (file_name) + 2); 335130803Smarcel strcpy (p, PXDB_SVR4); 336130803Smarcel strcat (p, " "); 337130803Smarcel strcat (p, file_name); 338130803Smarcel 339130803Smarcel warning ("File not processed by pxdb--about to process now.\n"); 340130803Smarcel status = system (p); 341130803Smarcel 342130803Smarcel retval = (status == 0); 343130803Smarcel } 344130803Smarcel else 345130803Smarcel { 346130803Smarcel 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); 347130803Smarcel 348130803Smarcel retval = 0; 349130803Smarcel } 350130803Smarcel return retval; 351130803Smarcel} /* hpread_call_pxdb */ 352130803Smarcel 353130803Smarcel 354130803Smarcel/* Return 1 if the file turns out to need pre-processing 355130803Smarcel by PXDB, and we have thus called PXDB to do this processing 356130803Smarcel and the file therefore needs to be re-loaded. Otherwise 357130803Smarcel return 0. */ 358130803Smarcelstatic int 359130803Smarcelhpread_pxdb_needed (bfd *sym_bfd) 360130803Smarcel{ 361130803Smarcel asection *pinfo_section, *debug_section, *header_section; 362130803Smarcel unsigned int do_pxdb; 363130803Smarcel char *buf; 364130803Smarcel bfd_size_type header_section_size; 365130803Smarcel 366130803Smarcel unsigned long tmp; 367130803Smarcel unsigned int pxdbed; 368130803Smarcel 369130803Smarcel header_section = bfd_get_section_by_name (sym_bfd, "$HEADER$"); 370130803Smarcel if (!header_section) 371130803Smarcel { 372130803Smarcel return 0; /* No header at all, can't recover... */ 373130803Smarcel } 374130803Smarcel 375130803Smarcel debug_section = bfd_get_section_by_name (sym_bfd, "$DEBUG$"); 376130803Smarcel pinfo_section = bfd_get_section_by_name (sym_bfd, "$PINFO$"); 377130803Smarcel 378130803Smarcel if (pinfo_section && !debug_section) 379130803Smarcel { 380130803Smarcel /* Debug info with DOC, has different header format. 381130803Smarcel this only happens if the file was pxdbed and compiled optimized 382130803Smarcel otherwise the PINFO section is not there. */ 383130803Smarcel header_section_size = bfd_section_size (objfile->obfd, header_section); 384130803Smarcel 385130803Smarcel if (header_section_size == (bfd_size_type) sizeof (DOC_info_PXDB_header)) 386130803Smarcel { 387130803Smarcel buf = alloca (sizeof (DOC_info_PXDB_header)); 388130803Smarcel memset (buf, 0, sizeof (DOC_info_PXDB_header)); 389130803Smarcel 390130803Smarcel if (!bfd_get_section_contents (sym_bfd, 391130803Smarcel header_section, 392130803Smarcel buf, 0, 393130803Smarcel header_section_size)) 394130803Smarcel error ("bfd_get_section_contents\n"); 395130803Smarcel 396130803Smarcel tmp = bfd_get_32 (sym_bfd, (bfd_byte *) (buf + sizeof (int) * 4)); 397130803Smarcel pxdbed = (tmp >> 31) & 0x1; 398130803Smarcel 399130803Smarcel if (!pxdbed) 400130803Smarcel error ("file debug header info invalid\n"); 401130803Smarcel do_pxdb = 0; 402130803Smarcel } 403130803Smarcel 404130803Smarcel else 405130803Smarcel error ("invalid $HEADER$ size in executable \n"); 406130803Smarcel } 407130803Smarcel 408130803Smarcel else 409130803Smarcel { 410130803Smarcel 411130803Smarcel /* this can be three different cases: 412130803Smarcel 1. pxdbed and not doc 413130803Smarcel - DEBUG and HEADER sections are there 414130803Smarcel - header is PXDB_header type 415130803Smarcel - pxdbed flag is set to 1 416130803Smarcel 417130803Smarcel 2. not pxdbed and doc 418130803Smarcel - DEBUG and HEADER sections are there 419130803Smarcel - header is DOC_info_header type 420130803Smarcel - pxdbed flag is set to 0 421130803Smarcel 422130803Smarcel 3. not pxdbed and not doc 423130803Smarcel - DEBUG and HEADER sections are there 424130803Smarcel - header is XDB_header type 425130803Smarcel - pxdbed flag is set to 0 426130803Smarcel 427130803Smarcel NOTE: the pxdbed flag is meaningful also in the not 428130803Smarcel already pxdb processed version of the header, 429130803Smarcel because in case on non-already processed by pxdb files 430130803Smarcel that same bit in the header would be always zero. 431130803Smarcel Why? Because the bit is the leftmost bit of a word 432130803Smarcel which contains a 'length' which is always a positive value 433130803Smarcel so that bit is never set to 1 (otherwise it would be negative) 434130803Smarcel 435130803Smarcel Given the above, we have two choices : either we ignore the 436130803Smarcel size of the header itself and just look at the pxdbed field, 437130803Smarcel or we check the size and then we (for safety and paranoia related 438130803Smarcel issues) check the bit. 439130803Smarcel The first solution is used by DDE, the second by PXDB itself. 440130803Smarcel I am using the second one here, because I already wrote it, 441130803Smarcel and it is the end of a long day. 442130803Smarcel Also, using the first approach would still involve size issues 443130803Smarcel because we need to read in the contents of the header section, and 444130803Smarcel give the correct amount of stuff we want to read to the 445130803Smarcel get_bfd_section_contents function. */ 446130803Smarcel 447130803Smarcel /* decide which case depending on the size of the header section. 448130803Smarcel The size is as defined in hp-symtab.h */ 449130803Smarcel 450130803Smarcel header_section_size = bfd_section_size (objfile->obfd, header_section); 451130803Smarcel 452130803Smarcel if (header_section_size == (bfd_size_type) sizeof (PXDB_header)) /* pxdb and not doc */ 453130803Smarcel { 454130803Smarcel 455130803Smarcel buf = alloca (sizeof (PXDB_header)); 456130803Smarcel memset (buf, 0, sizeof (PXDB_header)); 457130803Smarcel if (!bfd_get_section_contents (sym_bfd, 458130803Smarcel header_section, 459130803Smarcel buf, 0, 460130803Smarcel header_section_size)) 461130803Smarcel error ("bfd_get_section_contents\n"); 462130803Smarcel 463130803Smarcel tmp = bfd_get_32 (sym_bfd, (bfd_byte *) (buf + sizeof (int) * 3)); 464130803Smarcel pxdbed = (tmp >> 31) & 0x1; 465130803Smarcel 466130803Smarcel if (pxdbed) 467130803Smarcel do_pxdb = 0; 468130803Smarcel else 469130803Smarcel error ("file debug header invalid\n"); 470130803Smarcel } 471130803Smarcel else /*not pxdbed and doc OR not pxdbed and non doc */ 472130803Smarcel do_pxdb = 1; 473130803Smarcel } 474130803Smarcel 475130803Smarcel if (do_pxdb) 476130803Smarcel { 477130803Smarcel return 1; 478130803Smarcel } 479130803Smarcel else 480130803Smarcel { 481130803Smarcel return 0; 482130803Smarcel } 483130803Smarcel} /* hpread_pxdb_needed */ 484130803Smarcel 485130803Smarcel#endif 486130803Smarcel 487130803Smarcel/* Check whether the file needs to be preprocessed by pxdb. 488130803Smarcel If so, call pxdb. */ 489130803Smarcel 490130803Smarcelvoid 491130803Smarceldo_pxdb (bfd *sym_bfd) 492130803Smarcel{ 493130803Smarcel /* The following code is HP-specific. The "right" way of 494130803Smarcel doing this is unknown, but we bet would involve a target- 495130803Smarcel specific pre-file-load check using a generic mechanism. */ 496130803Smarcel 497130803Smarcel /* This code will not be executed if the file is not in SOM 498130803Smarcel format (i.e. if compiled with gcc) */ 499130803Smarcel if (hpread_pxdb_needed (sym_bfd)) 500130803Smarcel { 501130803Smarcel /*This file has not been pre-processed. Preprocess now */ 502130803Smarcel 503130803Smarcel if (hpread_call_pxdb (sym_bfd->filename)) 504130803Smarcel { 505130803Smarcel /* The call above has changed the on-disk file, 506130803Smarcel we can close the file anyway, because the 507130803Smarcel symbols will be reread in when the target is run */ 508130803Smarcel bfd_close (sym_bfd); 509130803Smarcel } 510130803Smarcel } 511130803Smarcel} 512130803Smarcel 513130803Smarcel 514130803Smarcel 515130803Smarcel#ifdef QUICK_LOOK_UP 516130803Smarcel 517130803Smarcel/* Code to handle quick lookup-tables follows. */ 518130803Smarcel 519130803Smarcel 520130803Smarcel/* Some useful macros */ 521130803Smarcel#define VALID_FILE(i) ((i) < pxdb_header_p->fd_entries) 522130803Smarcel#define VALID_MODULE(i) ((i) < pxdb_header_p->md_entries) 523130803Smarcel#define VALID_PROC(i) ((i) < pxdb_header_p->pd_entries) 524130803Smarcel#define VALID_CLASS(i) ((i) < pxdb_header_p->cd_entries) 525130803Smarcel 526130803Smarcel#define FILE_START(i) (qFD[i].adrStart) 527130803Smarcel#define MODULE_START(i) (qMD[i].adrStart) 528130803Smarcel#define PROC_START(i) (qPD[i].adrStart) 529130803Smarcel 530130803Smarcel#define FILE_END(i) (qFD[i].adrEnd) 531130803Smarcel#define MODULE_END(i) (qMD[i].adrEnd) 532130803Smarcel#define PROC_END(i) (qPD[i].adrEnd) 533130803Smarcel 534130803Smarcel#define FILE_ISYM(i) (qFD[i].isym) 535130803Smarcel#define MODULE_ISYM(i) (qMD[i].isym) 536130803Smarcel#define PROC_ISYM(i) (qPD[i].isym) 537130803Smarcel 538130803Smarcel#define VALID_CURR_FILE (curr_fd < pxdb_header_p->fd_entries) 539130803Smarcel#define VALID_CURR_MODULE (curr_md < pxdb_header_p->md_entries) 540130803Smarcel#define VALID_CURR_PROC (curr_pd < pxdb_header_p->pd_entries) 541130803Smarcel#define VALID_CURR_CLASS (curr_cd < pxdb_header_p->cd_entries) 542130803Smarcel 543130803Smarcel#define CURR_FILE_START (qFD[curr_fd].adrStart) 544130803Smarcel#define CURR_MODULE_START (qMD[curr_md].adrStart) 545130803Smarcel#define CURR_PROC_START (qPD[curr_pd].adrStart) 546130803Smarcel 547130803Smarcel#define CURR_FILE_END (qFD[curr_fd].adrEnd) 548130803Smarcel#define CURR_MODULE_END (qMD[curr_md].adrEnd) 549130803Smarcel#define CURR_PROC_END (qPD[curr_pd].adrEnd) 550130803Smarcel 551130803Smarcel#define CURR_FILE_ISYM (qFD[curr_fd].isym) 552130803Smarcel#define CURR_MODULE_ISYM (qMD[curr_md].isym) 553130803Smarcel#define CURR_PROC_ISYM (qPD[curr_pd].isym) 554130803Smarcel 555130803Smarcel#define TELL_OBJFILE \ 556130803Smarcel do { \ 557130803Smarcel if( !told_objfile ) { \ 558130803Smarcel told_objfile = 1; \ 559130803Smarcel warning ("\nIn object file \"%s\":\n", \ 560130803Smarcel objfile->name); \ 561130803Smarcel } \ 562130803Smarcel } while (0) 563130803Smarcel 564130803Smarcel 565130803Smarcel 566130803Smarcel/* Keeping track of the start/end symbol table (LNTT) indices of 567130803Smarcel psymtabs created so far */ 568130803Smarcel 569130803Smarceltypedef struct 570130803Smarcel{ 571130803Smarcel int start; 572130803Smarcel int end; 573130803Smarcel} 574130803Smarcelpst_syms_struct; 575130803Smarcel 576130803Smarcelstatic pst_syms_struct *pst_syms_array = 0; 577130803Smarcel 578130803Smarcelstatic int pst_syms_count = 0; 579130803Smarcelstatic int pst_syms_size = 0; 580130803Smarcel 581130803Smarcel/* used by the TELL_OBJFILE macro */ 582130803Smarcelstatic int told_objfile = 0; 583130803Smarcel 584130803Smarcel/* Set up psymtab symbol index stuff */ 585130803Smarcelstatic void 586130803Smarcelinit_pst_syms (void) 587130803Smarcel{ 588130803Smarcel pst_syms_count = 0; 589130803Smarcel pst_syms_size = 20; 590130803Smarcel pst_syms_array = (pst_syms_struct *) xmalloc (20 * sizeof (pst_syms_struct)); 591130803Smarcel} 592130803Smarcel 593130803Smarcel/* Clean up psymtab symbol index stuff */ 594130803Smarcelstatic void 595130803Smarcelclear_pst_syms (void) 596130803Smarcel{ 597130803Smarcel pst_syms_count = 0; 598130803Smarcel pst_syms_size = 0; 599130803Smarcel xfree (pst_syms_array); 600130803Smarcel pst_syms_array = 0; 601130803Smarcel} 602130803Smarcel 603130803Smarcel/* Add information about latest psymtab to symbol index table */ 604130803Smarcelstatic void 605130803Smarcelrecord_pst_syms (int start_sym, int end_sym) 606130803Smarcel{ 607130803Smarcel if (++pst_syms_count > pst_syms_size) 608130803Smarcel { 609130803Smarcel pst_syms_array = (pst_syms_struct *) xrealloc (pst_syms_array, 610130803Smarcel 2 * pst_syms_size * sizeof (pst_syms_struct)); 611130803Smarcel pst_syms_size *= 2; 612130803Smarcel } 613130803Smarcel pst_syms_array[pst_syms_count - 1].start = start_sym; 614130803Smarcel pst_syms_array[pst_syms_count - 1].end = end_sym; 615130803Smarcel} 616130803Smarcel 617130803Smarcel/* Find a suitable symbol table index which can serve as the upper 618130803Smarcel bound of a psymtab that starts at INDEX 619130803Smarcel 620130803Smarcel This scans backwards in the psymtab symbol index table to find a 621130803Smarcel "hole" in which the given index can fit. This is a heuristic!! 622130803Smarcel We don't search the entire table to check for multiple holes, 623130803Smarcel we don't care about overlaps, etc. 624130803Smarcel 625130803Smarcel Return 0 => not found */ 626130803Smarcelstatic int 627130803Smarcelfind_next_pst_start (int index) 628130803Smarcel{ 629130803Smarcel int i; 630130803Smarcel 631130803Smarcel for (i = pst_syms_count - 1; i >= 0; i--) 632130803Smarcel if (pst_syms_array[i].end <= index) 633130803Smarcel return (i == pst_syms_count - 1) ? 0 : pst_syms_array[i + 1].start - 1; 634130803Smarcel 635130803Smarcel if (pst_syms_array[0].start > index) 636130803Smarcel return pst_syms_array[0].start - 1; 637130803Smarcel 638130803Smarcel return 0; 639130803Smarcel} 640130803Smarcel 641130803Smarcel 642130803Smarcel 643130803Smarcel/* Utility functions to find the ending symbol index for a psymtab */ 644130803Smarcel 645130803Smarcel/* Find the next file entry that begins beyond INDEX, and return 646130803Smarcel its starting symbol index - 1. 647130803Smarcel QFD is the file table, CURR_FD is the file entry from where to start, 648130803Smarcel PXDB_HEADER_P as in hpread_quick_traverse (to allow macros to work). 649130803Smarcel 650130803Smarcel Return 0 => not found */ 651130803Smarcelstatic int 652130803Smarcelfind_next_file_isym (int index, quick_file_entry *qFD, int curr_fd, 653130803Smarcel PXDB_header_ptr pxdb_header_p) 654130803Smarcel{ 655130803Smarcel while (VALID_CURR_FILE) 656130803Smarcel { 657130803Smarcel if (CURR_FILE_ISYM >= index) 658130803Smarcel return CURR_FILE_ISYM - 1; 659130803Smarcel curr_fd++; 660130803Smarcel } 661130803Smarcel return 0; 662130803Smarcel} 663130803Smarcel 664130803Smarcel/* Find the next procedure entry that begins beyond INDEX, and return 665130803Smarcel its starting symbol index - 1. 666130803Smarcel QPD is the procedure table, CURR_PD is the proc entry from where to start, 667130803Smarcel PXDB_HEADER_P as in hpread_quick_traverse (to allow macros to work). 668130803Smarcel 669130803Smarcel Return 0 => not found */ 670130803Smarcelstatic int 671130803Smarcelfind_next_proc_isym (int index, quick_procedure_entry *qPD, int curr_pd, 672130803Smarcel PXDB_header_ptr pxdb_header_p) 673130803Smarcel{ 674130803Smarcel while (VALID_CURR_PROC) 675130803Smarcel { 676130803Smarcel if (CURR_PROC_ISYM >= index) 677130803Smarcel return CURR_PROC_ISYM - 1; 678130803Smarcel curr_pd++; 679130803Smarcel } 680130803Smarcel return 0; 681130803Smarcel} 682130803Smarcel 683130803Smarcel/* Find the next module entry that begins beyond INDEX, and return 684130803Smarcel its starting symbol index - 1. 685130803Smarcel QMD is the module table, CURR_MD is the modue entry from where to start, 686130803Smarcel PXDB_HEADER_P as in hpread_quick_traverse (to allow macros to work). 687130803Smarcel 688130803Smarcel Return 0 => not found */ 689130803Smarcelstatic int 690130803Smarcelfind_next_module_isym (int index, quick_module_entry *qMD, int curr_md, 691130803Smarcel PXDB_header_ptr pxdb_header_p) 692130803Smarcel{ 693130803Smarcel while (VALID_CURR_MODULE) 694130803Smarcel { 695130803Smarcel if (CURR_MODULE_ISYM >= index) 696130803Smarcel return CURR_MODULE_ISYM - 1; 697130803Smarcel curr_md++; 698130803Smarcel } 699130803Smarcel return 0; 700130803Smarcel} 701130803Smarcel 702130803Smarcel/* Scan and record partial symbols for all functions starting from index 703130803Smarcel pointed to by CURR_PD_P, and between code addresses START_ADR and END_ADR. 704130803Smarcel Other parameters are explained in comments below. */ 705130803Smarcel 706130803Smarcel/* This used to be inline in hpread_quick_traverse, but now that we do 707130803Smarcel essentially the same thing for two different cases (modules and 708130803Smarcel module-less files), it's better organized in a separate routine, 709130803Smarcel although it does take lots of arguments. pai/1997-10-08 710130803Smarcel 711130803Smarcel CURR_PD_P is the pointer to the current proc index. QPD is the 712130803Smarcel procedure quick lookup table. MAX_PROCS is the number of entries 713130803Smarcel in the proc. table. START_ADR is the beginning of the code range 714130803Smarcel for the current psymtab. end_adr is the end of the code range for 715130803Smarcel the current psymtab. PST is the current psymtab. VT_bits is 716130803Smarcel a pointer to the strings table of SOM debug space. OBJFILE is 717130803Smarcel the current object file. */ 718130803Smarcel 719130803Smarcelstatic int 720130803Smarcelscan_procs (int *curr_pd_p, quick_procedure_entry *qPD, int max_procs, 721130803Smarcel CORE_ADDR start_adr, CORE_ADDR end_adr, struct partial_symtab *pst, 722130803Smarcel char *vt_bits, struct objfile *objfile) 723130803Smarcel{ 724130803Smarcel union dnttentry *dn_bufp; 725130803Smarcel int symbol_count = 0; /* Total number of symbols in this psymtab */ 726130803Smarcel int curr_pd = *curr_pd_p; /* Convenience variable -- avoid dereferencing pointer all the time */ 727130803Smarcel 728130803Smarcel#ifdef DUMPING 729130803Smarcel /* Turn this on for lots of debugging information in this routine */ 730130803Smarcel static int dumping = 0; 731130803Smarcel#endif 732130803Smarcel 733130803Smarcel#ifdef DUMPING 734130803Smarcel if (dumping) 735130803Smarcel { 736130803Smarcel printf ("Scan_procs called, addresses %x to %x, proc %x\n", start_adr, end_adr, curr_pd); 737130803Smarcel } 738130803Smarcel#endif 739130803Smarcel 740130803Smarcel while ((CURR_PROC_START <= end_adr) && (curr_pd < max_procs)) 741130803Smarcel { 742130803Smarcel 743130803Smarcel char *rtn_name; /* mangled name */ 744130803Smarcel char *rtn_dem_name; /* qualified demangled name */ 745130803Smarcel char *class_name; 746130803Smarcel int class; 747130803Smarcel 748130803Smarcel if ((trans_lang ((enum hp_language) qPD[curr_pd].language) == language_cplus) && 749130803Smarcel vt_bits[(long) qPD[curr_pd].sbAlias]) /* not a null string */ 750130803Smarcel { 751130803Smarcel /* Get mangled name for the procedure, and demangle it */ 752130803Smarcel rtn_name = &vt_bits[(long) qPD[curr_pd].sbAlias]; 753130803Smarcel rtn_dem_name = cplus_demangle (rtn_name, DMGL_ANSI | DMGL_PARAMS); 754130803Smarcel } 755130803Smarcel else 756130803Smarcel { 757130803Smarcel rtn_name = &vt_bits[(long) qPD[curr_pd].sbProc]; 758130803Smarcel rtn_dem_name = NULL; 759130803Smarcel } 760130803Smarcel 761130803Smarcel /* Hack to get around HP C/C++ compilers' insistence on providing 762130803Smarcel "_MAIN_" as an alternate name for "main" */ 763130803Smarcel if ((strcmp (rtn_name, "_MAIN_") == 0) && 764130803Smarcel (strcmp (&vt_bits[(long) qPD[curr_pd].sbProc], "main") == 0)) 765130803Smarcel rtn_dem_name = rtn_name = main_string; 766130803Smarcel 767130803Smarcel#ifdef DUMPING 768130803Smarcel if (dumping) 769130803Smarcel { 770130803Smarcel printf ("..add %s (demangled %s), index %x to this psymtab\n", rtn_name, rtn_dem_name, curr_pd); 771130803Smarcel } 772130803Smarcel#endif 773130803Smarcel 774130803Smarcel /* Check for module-spanning routines. */ 775130803Smarcel if (CURR_PROC_END > end_adr) 776130803Smarcel { 777130803Smarcel TELL_OBJFILE; 778130803Smarcel warning ("Procedure \"%s\" [0x%x] spans file or module boundaries.", rtn_name, curr_pd); 779130803Smarcel } 780130803Smarcel 781130803Smarcel /* Add this routine symbol to the list in the objfile. 782130803Smarcel Unfortunately we have to go to the LNTT to determine the 783130803Smarcel correct list to put it on. An alternative (which the 784130803Smarcel code used to do) would be to not check and always throw 785130803Smarcel it on the "static" list. But if we go that route, then 786130803Smarcel symbol_lookup() needs to be tweaked a bit to account 787130803Smarcel for the fact that the function might not be found on 788130803Smarcel the correct list in the psymtab. - RT */ 789130803Smarcel dn_bufp = hpread_get_lntt (qPD[curr_pd].isym, objfile); 790130803Smarcel if (dn_bufp->dfunc.global) 791130803Smarcel add_psymbol_with_dem_name_to_list (rtn_name, 792130803Smarcel strlen (rtn_name), 793130803Smarcel rtn_dem_name, 794130803Smarcel strlen (rtn_dem_name), 795130803Smarcel VAR_DOMAIN, 796130803Smarcel LOC_BLOCK, /* "I am a routine" */ 797130803Smarcel &objfile->global_psymbols, 798130803Smarcel (qPD[curr_pd].adrStart + /* Starting address of rtn */ 799130803Smarcel ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile))), 800130803Smarcel 0, /* core addr?? */ 801130803Smarcel trans_lang ((enum hp_language) qPD[curr_pd].language), 802130803Smarcel objfile); 803130803Smarcel else 804130803Smarcel add_psymbol_with_dem_name_to_list (rtn_name, 805130803Smarcel strlen (rtn_name), 806130803Smarcel rtn_dem_name, 807130803Smarcel strlen (rtn_dem_name), 808130803Smarcel VAR_DOMAIN, 809130803Smarcel LOC_BLOCK, /* "I am a routine" */ 810130803Smarcel &objfile->static_psymbols, 811130803Smarcel (qPD[curr_pd].adrStart + /* Starting address of rtn */ 812130803Smarcel ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile))), 813130803Smarcel 0, /* core addr?? */ 814130803Smarcel trans_lang ((enum hp_language) qPD[curr_pd].language), 815130803Smarcel objfile); 816130803Smarcel 817130803Smarcel symbol_count++; 818130803Smarcel *curr_pd_p = ++curr_pd; /* bump up count & reflect in caller */ 819130803Smarcel } /* loop over procedures */ 820130803Smarcel 821130803Smarcel#ifdef DUMPING 822130803Smarcel if (dumping) 823130803Smarcel { 824130803Smarcel if (symbol_count == 0) 825130803Smarcel printf ("Scan_procs: no symbols found!\n"); 826130803Smarcel } 827130803Smarcel#endif 828130803Smarcel 829130803Smarcel return symbol_count; 830130803Smarcel} 831130803Smarcel 832130803Smarcel 833130803Smarcel/* Traverse the quick look-up tables, building a set of psymtabs. 834130803Smarcel 835130803Smarcel This constructs a psymtab for modules and files in the quick lookup 836130803Smarcel tables. 837130803Smarcel 838130803Smarcel Mostly, modules correspond to compilation units, so we try to 839130803Smarcel create psymtabs that correspond to modules; however, in some cases 840130803Smarcel a file can result in a compiled object which does not have a module 841130803Smarcel entry for it, so in such cases we create a psymtab for the file. */ 842130803Smarcel 843130803Smarcelstatic int 844130803Smarcelhpread_quick_traverse (struct objfile *objfile, char *gntt_bits, 845130803Smarcel char *vt_bits, PXDB_header_ptr pxdb_header_p) 846130803Smarcel{ 847130803Smarcel struct partial_symtab *pst; 848130803Smarcel 849130803Smarcel char *addr; 850130803Smarcel 851130803Smarcel quick_procedure_entry *qPD; 852130803Smarcel quick_file_entry *qFD; 853130803Smarcel quick_module_entry *qMD; 854130803Smarcel quick_class_entry *qCD; 855130803Smarcel 856130803Smarcel int idx; 857130803Smarcel int i; 858130803Smarcel CORE_ADDR start_adr; /* current psymtab's starting code addr */ 859130803Smarcel CORE_ADDR end_adr; /* current psymtab's ending code addr */ 860130803Smarcel CORE_ADDR next_mod_adr; /* next module's starting code addr */ 861130803Smarcel int curr_pd; /* current procedure */ 862130803Smarcel int curr_fd; /* current file */ 863130803Smarcel int curr_md; /* current module */ 864130803Smarcel int start_sym; /* current psymtab's starting symbol index */ 865130803Smarcel int end_sym; /* current psymtab's ending symbol index */ 866130803Smarcel int max_LNTT_sym_index; 867130803Smarcel int syms_in_pst; 868130803Smarcel B_TYPE *class_entered; 869130803Smarcel 870130803Smarcel struct partial_symbol **global_syms; /* We'll be filling in the "global" */ 871130803Smarcel struct partial_symbol **static_syms; /* and "static" tables in the objfile 872130803Smarcel as we go, so we need a pair of 873130803Smarcel current pointers. */ 874130803Smarcel 875130803Smarcel#ifdef DUMPING 876130803Smarcel /* Turn this on for lots of debugging information in this routine. 877130803Smarcel You get a blow-by-blow account of quick lookup table reading */ 878130803Smarcel static int dumping = 0; 879130803Smarcel#endif 880130803Smarcel 881130803Smarcel pst = (struct partial_symtab *) 0; 882130803Smarcel 883130803Smarcel /* Clear out some globals */ 884130803Smarcel init_pst_syms (); 885130803Smarcel told_objfile = 0; 886130803Smarcel 887130803Smarcel /* Demangling style -- if EDG style already set, don't change it, 888130803Smarcel as HP style causes some problems with the KAI EDG compiler */ 889130803Smarcel if (current_demangling_style != edg_demangling) 890130803Smarcel { 891130803Smarcel /* Otherwise, ensure that we are using HP style demangling */ 892130803Smarcel set_demangling_style (HP_DEMANGLING_STYLE_STRING); 893130803Smarcel } 894130803Smarcel 895130803Smarcel /* First we need to find the starting points of the quick 896130803Smarcel look-up tables in the GNTT. */ 897130803Smarcel 898130803Smarcel addr = gntt_bits; 899130803Smarcel 900130803Smarcel qPD = (quick_procedure_entry_ptr) addr; 901130803Smarcel addr += pxdb_header_p->pd_entries * sizeof (quick_procedure_entry); 902130803Smarcel 903130803Smarcel#ifdef DUMPING 904130803Smarcel if (dumping) 905130803Smarcel { 906130803Smarcel printf ("\n Printing routines as we see them\n"); 907130803Smarcel for (i = 0; VALID_PROC (i); i++) 908130803Smarcel { 909130803Smarcel idx = (long) qPD[i].sbProc; 910130803Smarcel printf ("%s %x..%x\n", &vt_bits[idx], 911130803Smarcel (int) PROC_START (i), 912130803Smarcel (int) PROC_END (i)); 913130803Smarcel } 914130803Smarcel } 915130803Smarcel#endif 916130803Smarcel 917130803Smarcel qFD = (quick_file_entry_ptr) addr; 918130803Smarcel addr += pxdb_header_p->fd_entries * sizeof (quick_file_entry); 919130803Smarcel 920130803Smarcel#ifdef DUMPING 921130803Smarcel if (dumping) 922130803Smarcel { 923130803Smarcel printf ("\n Printing files as we see them\n"); 924130803Smarcel for (i = 0; VALID_FILE (i); i++) 925130803Smarcel { 926130803Smarcel idx = (long) qFD[i].sbFile; 927130803Smarcel printf ("%s %x..%x\n", &vt_bits[idx], 928130803Smarcel (int) FILE_START (i), 929130803Smarcel (int) FILE_END (i)); 930130803Smarcel } 931130803Smarcel } 932130803Smarcel#endif 933130803Smarcel 934130803Smarcel qMD = (quick_module_entry_ptr) addr; 935130803Smarcel addr += pxdb_header_p->md_entries * sizeof (quick_module_entry); 936130803Smarcel 937130803Smarcel#ifdef DUMPING 938130803Smarcel if (dumping) 939130803Smarcel { 940130803Smarcel printf ("\n Printing modules as we see them\n"); 941130803Smarcel for (i = 0; i < pxdb_header_p->md_entries; i++) 942130803Smarcel { 943130803Smarcel idx = (long) qMD[i].sbMod; 944130803Smarcel printf ("%s\n", &vt_bits[idx]); 945130803Smarcel } 946130803Smarcel } 947130803Smarcel#endif 948130803Smarcel 949130803Smarcel qCD = (quick_class_entry_ptr) addr; 950130803Smarcel addr += pxdb_header_p->cd_entries * sizeof (quick_class_entry); 951130803Smarcel 952130803Smarcel#ifdef DUMPING 953130803Smarcel if (dumping) 954130803Smarcel { 955130803Smarcel printf ("\n Printing classes as we see them\n"); 956130803Smarcel for (i = 0; VALID_CLASS (i); i++) 957130803Smarcel { 958130803Smarcel idx = (long) qCD[i].sbClass; 959130803Smarcel printf ("%s\n", &vt_bits[idx]); 960130803Smarcel } 961130803Smarcel 962130803Smarcel printf ("\n Done with dump, on to build!\n"); 963130803Smarcel } 964130803Smarcel#endif 965130803Smarcel 966130803Smarcel /* We need this index only while hp-symtab-read.c expects 967130803Smarcel a byte offset to the end of the LNTT entries for a given 968130803Smarcel psymtab. Thus the need for it should go away someday. 969130803Smarcel 970130803Smarcel When it goes away, then we won't have any need to load the 971130803Smarcel LNTT from the objfile at psymtab-time, and start-up will be 972130803Smarcel faster. To make that work, we'll need some way to create 973130803Smarcel a null pst for the "globals" pseudo-module. */ 974130803Smarcel max_LNTT_sym_index = LNTT_SYMCOUNT (objfile); 975130803Smarcel 976130803Smarcel /* Scan the module descriptors and make a psymtab for each. 977130803Smarcel 978130803Smarcel We know the MDs, FDs and the PDs are in order by starting 979130803Smarcel address. We use that fact to traverse all three arrays in 980130803Smarcel parallel, knowing when the next PD is in a new file 981130803Smarcel and we need to create a new psymtab. */ 982130803Smarcel curr_pd = 0; /* Current procedure entry */ 983130803Smarcel curr_fd = 0; /* Current file entry */ 984130803Smarcel curr_md = 0; /* Current module entry */ 985130803Smarcel 986130803Smarcel start_adr = 0; /* Current psymtab code range */ 987130803Smarcel end_adr = 0; 988130803Smarcel 989130803Smarcel start_sym = 0; /* Current psymtab symbol range */ 990130803Smarcel end_sym = 0; 991130803Smarcel 992130803Smarcel syms_in_pst = 0; /* Symbol count for psymtab */ 993130803Smarcel 994130803Smarcel /* Psts actually just have pointers into the objfile's 995130803Smarcel symbol table, not their own symbol tables. */ 996130803Smarcel global_syms = objfile->global_psymbols.list; 997130803Smarcel static_syms = objfile->static_psymbols.list; 998130803Smarcel 999130803Smarcel 1000130803Smarcel /* First skip over pseudo-entries with address 0. These represent inlined 1001130803Smarcel routines and abstract (uninstantiated) template routines. 1002130803Smarcel FIXME: These should be read in and available -- even if we can't set 1003130803Smarcel breakpoints, etc., there's some information that can be presented 1004130803Smarcel to the user. pai/1997-10-08 */ 1005130803Smarcel 1006130803Smarcel while (VALID_CURR_PROC && (CURR_PROC_START == 0)) 1007130803Smarcel curr_pd++; 1008130803Smarcel 1009130803Smarcel /* Loop over files, modules, and procedures in code address order. Each 1010130803Smarcel time we enter an iteration of this loop, curr_pd points to the first 1011130803Smarcel unprocessed procedure, curr_fd points to the first unprocessed file, and 1012130803Smarcel curr_md to the first unprocessed module. Each iteration of this loop 1013130803Smarcel updates these as required -- any or all of them may be bumpd up 1014130803Smarcel each time around. When we exit this loop, we are done with all files 1015130803Smarcel and modules in the tables -- there may still be some procedures, however. 1016130803Smarcel 1017130803Smarcel Note: This code used to loop only over module entries, under the assumption 1018130803Smarcel that files can occur via inclusions and are thus unreliable, while a 1019130803Smarcel compiled object always corresponds to a module. With CTTI in the HP aCC 1020130803Smarcel compiler, it turns out that compiled objects may have only files and no 1021130803Smarcel modules; so we have to loop over files and modules, creating psymtabs for 1022130803Smarcel either as appropriate. Unfortunately there are some problems (notably: 1023130803Smarcel 1. the lack of "SRC_FILE_END" entries in the LNTT, 2. the lack of pointers 1024130803Smarcel to the ending symbol indices of a module or a file) which make it quite hard 1025130803Smarcel to do this correctly. Currently it uses a bunch of heuristics to start and 1026130803Smarcel end psymtabs; they seem to work well with most objects generated by aCC, but 1027130803Smarcel who knows when that will change... */ 1028130803Smarcel 1029130803Smarcel while (VALID_CURR_FILE || VALID_CURR_MODULE) 1030130803Smarcel { 1031130803Smarcel 1032130803Smarcel char *mod_name_string = NULL; 1033130803Smarcel char *full_name_string; 1034130803Smarcel 1035130803Smarcel /* First check for modules like "version.c", which have no code 1036130803Smarcel in them but still have qMD entries. They also have no qFD or 1037130803Smarcel qPD entries. Their start address is -1 and their end address 1038130803Smarcel is 0. */ 1039130803Smarcel if (VALID_CURR_MODULE && (CURR_MODULE_START == -1) && (CURR_MODULE_END == 0)) 1040130803Smarcel { 1041130803Smarcel 1042130803Smarcel mod_name_string = &vt_bits[(long) qMD[curr_md].sbMod]; 1043130803Smarcel 1044130803Smarcel#ifdef DUMPING 1045130803Smarcel if (dumping) 1046130803Smarcel printf ("Module with data only %s\n", mod_name_string); 1047130803Smarcel#endif 1048130803Smarcel 1049130803Smarcel /* We'll skip the rest (it makes error-checking easier), and 1050130803Smarcel just make an empty pst. Right now empty psts are not put 1051130803Smarcel in the pst chain, so all this is for naught, but later it 1052130803Smarcel might help. */ 1053130803Smarcel 1054130803Smarcel pst = hpread_start_psymtab (objfile, 1055130803Smarcel mod_name_string, 1056130803Smarcel CURR_MODULE_START, /* Low text address: bogus! */ 1057130803Smarcel (CURR_MODULE_ISYM * sizeof (struct dntt_type_block)), 1058130803Smarcel /* ldsymoff */ 1059130803Smarcel global_syms, 1060130803Smarcel static_syms); 1061130803Smarcel 1062130803Smarcel pst = hpread_end_psymtab (pst, 1063130803Smarcel NULL, /* psymtab_include_list */ 1064130803Smarcel 0, /* includes_used */ 1065130803Smarcel end_sym * sizeof (struct dntt_type_block), 1066130803Smarcel /* byte index in LNTT of end 1067130803Smarcel = capping symbol offset 1068130803Smarcel = LDSYMOFF of nextfile */ 1069130803Smarcel 0, /* text high */ 1070130803Smarcel NULL, /* dependency_list */ 1071130803Smarcel 0); /* dependencies_used */ 1072130803Smarcel 1073130803Smarcel global_syms = objfile->global_psymbols.next; 1074130803Smarcel static_syms = objfile->static_psymbols.next; 1075130803Smarcel 1076130803Smarcel curr_md++; 1077130803Smarcel } 1078130803Smarcel else if (VALID_CURR_MODULE && 1079130803Smarcel ((CURR_MODULE_START == 0) || (CURR_MODULE_START == -1) || 1080130803Smarcel (CURR_MODULE_END == 0) || (CURR_MODULE_END == -1))) 1081130803Smarcel { 1082130803Smarcel TELL_OBJFILE; 1083130803Smarcel warning ("Module \"%s\" [0x%s] has non-standard addresses. It starts at 0x%s, ends at 0x%s, and will be skipped.", 1084130803Smarcel mod_name_string, paddr_nz (curr_md), paddr_nz (start_adr), paddr_nz (end_adr)); 1085130803Smarcel /* On to next module */ 1086130803Smarcel curr_md++; 1087130803Smarcel } 1088130803Smarcel else 1089130803Smarcel { 1090130803Smarcel /* First check if we are looking at a file with code in it 1091130803Smarcel that does not overlap the current module's code range */ 1092130803Smarcel 1093130803Smarcel if (VALID_CURR_FILE ? (VALID_CURR_MODULE ? (CURR_FILE_END < CURR_MODULE_START) : 1) : 0) 1094130803Smarcel { 1095130803Smarcel 1096130803Smarcel /* Looking at file not corresponding to any module, 1097130803Smarcel create a psymtab for it */ 1098130803Smarcel full_name_string = &vt_bits[(long) qFD[curr_fd].sbFile]; 1099130803Smarcel start_adr = CURR_FILE_START; 1100130803Smarcel end_adr = CURR_FILE_END; 1101130803Smarcel start_sym = CURR_FILE_ISYM; 1102130803Smarcel 1103130803Smarcel /* Check if there are any procedures not handled until now, that 1104130803Smarcel begin before the start address of this file, and if so, adjust 1105130803Smarcel this module's start address to include them. This handles routines that 1106130803Smarcel are in between file or module ranges for some reason (probably 1107130803Smarcel indicates a compiler bug */ 1108130803Smarcel 1109130803Smarcel if (CURR_PROC_START < start_adr) 1110130803Smarcel { 1111130803Smarcel TELL_OBJFILE; 1112130803Smarcel warning ("Found procedure \"%s\" [0x%x] that is not in any file or module.", 1113130803Smarcel &vt_bits[(long) qPD[curr_pd].sbProc], curr_pd); 1114130803Smarcel start_adr = CURR_PROC_START; 1115130803Smarcel if (CURR_PROC_ISYM < start_sym) 1116130803Smarcel start_sym = CURR_PROC_ISYM; 1117130803Smarcel } 1118130803Smarcel 1119130803Smarcel /* Sometimes (compiler bug -- COBOL) the module end address is higher 1120130803Smarcel than the start address of the next module, so check for that and 1121130803Smarcel adjust accordingly */ 1122130803Smarcel 1123130803Smarcel if (VALID_FILE (curr_fd + 1) && (FILE_START (curr_fd + 1) <= end_adr)) 1124130803Smarcel { 1125130803Smarcel TELL_OBJFILE; 1126130803Smarcel warning ("File \"%s\" [0x%x] has ending address after starting address of next file; adjusting ending address down.", 1127130803Smarcel full_name_string, curr_fd); 1128130803Smarcel end_adr = FILE_START (curr_fd + 1) - 1; /* Is -4 (or -8 for 64-bit) better? */ 1129130803Smarcel } 1130130803Smarcel if (VALID_MODULE (curr_md) && (CURR_MODULE_START <= end_adr)) 1131130803Smarcel { 1132130803Smarcel TELL_OBJFILE; 1133130803Smarcel warning ("File \"%s\" [0x%x] has ending address after starting address of next module; adjusting ending address down.", 1134130803Smarcel full_name_string, curr_fd); 1135130803Smarcel end_adr = CURR_MODULE_START - 1; /* Is -4 (or -8 for 64-bit) better? */ 1136130803Smarcel } 1137130803Smarcel 1138130803Smarcel 1139130803Smarcel#ifdef DUMPING 1140130803Smarcel if (dumping) 1141130803Smarcel { 1142130803Smarcel printf ("Make new psymtab for file %s (%x to %x).\n", 1143130803Smarcel full_name_string, start_adr, end_adr); 1144130803Smarcel } 1145130803Smarcel#endif 1146130803Smarcel /* Create the basic psymtab, connecting it in the list 1147130803Smarcel for this objfile and pointing its symbol entries 1148130803Smarcel to the current end of the symbol areas in the objfile. 1149130803Smarcel 1150130803Smarcel The "ldsymoff" parameter is the byte offset in the LNTT 1151130803Smarcel of the first symbol in this file. Some day we should 1152130803Smarcel turn this into an index (fix in hp-symtab-read.c as well). 1153130803Smarcel And it's not even the right byte offset, as we're using 1154130803Smarcel the size of a union! FIXME! */ 1155130803Smarcel pst = hpread_start_psymtab (objfile, 1156130803Smarcel full_name_string, 1157130803Smarcel start_adr, /* Low text address */ 1158130803Smarcel (start_sym * sizeof (struct dntt_type_block)), 1159130803Smarcel /* ldsymoff */ 1160130803Smarcel global_syms, 1161130803Smarcel static_syms); 1162130803Smarcel 1163130803Smarcel /* Set up to only enter each class referenced in this module once. */ 1164130803Smarcel class_entered = xmalloc (B_BYTES (pxdb_header_p->cd_entries)); 1165130803Smarcel B_CLRALL (class_entered, pxdb_header_p->cd_entries); 1166130803Smarcel 1167130803Smarcel /* Scan the procedure descriptors for procedures in the current 1168130803Smarcel file, based on the starting addresses. */ 1169130803Smarcel 1170130803Smarcel syms_in_pst = scan_procs (&curr_pd, qPD, pxdb_header_p->pd_entries, 1171130803Smarcel start_adr, end_adr, pst, vt_bits, objfile); 1172130803Smarcel 1173130803Smarcel /* Get ending symbol offset */ 1174130803Smarcel 1175130803Smarcel end_sym = 0; 1176130803Smarcel /* First check for starting index before previous psymtab */ 1177130803Smarcel if (pst_syms_count && start_sym < pst_syms_array[pst_syms_count - 1].end) 1178130803Smarcel { 1179130803Smarcel end_sym = find_next_pst_start (start_sym); 1180130803Smarcel } 1181130803Smarcel /* Look for next start index of a file or module, or procedure */ 1182130803Smarcel if (!end_sym) 1183130803Smarcel { 1184130803Smarcel int next_file_isym = find_next_file_isym (start_sym, qFD, curr_fd + 1, pxdb_header_p); 1185130803Smarcel int next_module_isym = find_next_module_isym (start_sym, qMD, curr_md, pxdb_header_p); 1186130803Smarcel int next_proc_isym = find_next_proc_isym (start_sym, qPD, curr_pd, pxdb_header_p); 1187130803Smarcel 1188130803Smarcel if (next_file_isym && next_module_isym) 1189130803Smarcel { 1190130803Smarcel /* pick lower of next file or module start index */ 1191130803Smarcel end_sym = min (next_file_isym, next_module_isym); 1192130803Smarcel } 1193130803Smarcel else 1194130803Smarcel { 1195130803Smarcel /* one of them is zero, pick the other */ 1196130803Smarcel end_sym = max (next_file_isym, next_module_isym); 1197130803Smarcel } 1198130803Smarcel 1199130803Smarcel /* As a precaution, check next procedure index too */ 1200130803Smarcel if (!end_sym) 1201130803Smarcel end_sym = next_proc_isym; 1202130803Smarcel else 1203130803Smarcel end_sym = min (end_sym, next_proc_isym); 1204130803Smarcel } 1205130803Smarcel 1206130803Smarcel /* Couldn't find procedure, file, or module, use globals as default */ 1207130803Smarcel if (!end_sym) 1208130803Smarcel end_sym = pxdb_header_p->globals; 1209130803Smarcel 1210130803Smarcel#ifdef DUMPING 1211130803Smarcel if (dumping) 1212130803Smarcel { 1213130803Smarcel printf ("File psymtab indices: %x to %x\n", start_sym, end_sym); 1214130803Smarcel } 1215130803Smarcel#endif 1216130803Smarcel 1217130803Smarcel pst = hpread_end_psymtab (pst, 1218130803Smarcel NULL, /* psymtab_include_list */ 1219130803Smarcel 0, /* includes_used */ 1220130803Smarcel end_sym * sizeof (struct dntt_type_block), 1221130803Smarcel /* byte index in LNTT of end 1222130803Smarcel = capping symbol offset 1223130803Smarcel = LDSYMOFF of nextfile */ 1224130803Smarcel end_adr, /* text high */ 1225130803Smarcel NULL, /* dependency_list */ 1226130803Smarcel 0); /* dependencies_used */ 1227130803Smarcel 1228130803Smarcel record_pst_syms (start_sym, end_sym); 1229130803Smarcel 1230130803Smarcel if (NULL == pst) 1231130803Smarcel warning ("No symbols in psymtab for file \"%s\" [0x%x].", full_name_string, curr_fd); 1232130803Smarcel 1233130803Smarcel#ifdef DUMPING 1234130803Smarcel if (dumping) 1235130803Smarcel { 1236130803Smarcel printf ("Made new psymtab for file %s (%x to %x), sym %x to %x.\n", 1237130803Smarcel full_name_string, start_adr, end_adr, CURR_FILE_ISYM, end_sym); 1238130803Smarcel } 1239130803Smarcel#endif 1240130803Smarcel /* Prepare for the next psymtab. */ 1241130803Smarcel global_syms = objfile->global_psymbols.next; 1242130803Smarcel static_syms = objfile->static_psymbols.next; 1243130803Smarcel xfree (class_entered); 1244130803Smarcel 1245130803Smarcel curr_fd++; 1246130803Smarcel } /* Psymtab for file */ 1247130803Smarcel else 1248130803Smarcel { 1249130803Smarcel /* We have a module for which we create a psymtab */ 1250130803Smarcel 1251130803Smarcel mod_name_string = &vt_bits[(long) qMD[curr_md].sbMod]; 1252130803Smarcel 1253130803Smarcel /* We will include the code ranges of any files that happen to 1254130803Smarcel overlap with this module */ 1255130803Smarcel 1256130803Smarcel /* So, first pick the lower of the file's and module's start addresses */ 1257130803Smarcel start_adr = CURR_MODULE_START; 1258130803Smarcel if (VALID_CURR_FILE) 1259130803Smarcel { 1260130803Smarcel if (CURR_FILE_START < CURR_MODULE_START) 1261130803Smarcel { 1262130803Smarcel TELL_OBJFILE; 1263130803Smarcel warning ("File \"%s\" [0x%x] crosses beginning of module \"%s\".", 1264130803Smarcel &vt_bits[(long) qFD[curr_fd].sbFile], 1265130803Smarcel curr_fd, mod_name_string); 1266130803Smarcel 1267130803Smarcel start_adr = CURR_FILE_START; 1268130803Smarcel } 1269130803Smarcel } 1270130803Smarcel 1271130803Smarcel /* Also pick the lower of the file's and the module's start symbol indices */ 1272130803Smarcel start_sym = CURR_MODULE_ISYM; 1273130803Smarcel if (VALID_CURR_FILE && (CURR_FILE_ISYM < CURR_MODULE_ISYM)) 1274130803Smarcel start_sym = CURR_FILE_ISYM; 1275130803Smarcel 1276130803Smarcel /* For the end address, we scan through the files till we find one 1277130803Smarcel that overlaps the current module but ends beyond it; if no such file exists we 1278130803Smarcel simply use the module's start address. 1279130803Smarcel (Note, if file entries themselves overlap 1280130803Smarcel we take the longest overlapping extension beyond the end of the module...) 1281130803Smarcel We assume that modules never overlap. */ 1282130803Smarcel 1283130803Smarcel end_adr = CURR_MODULE_END; 1284130803Smarcel 1285130803Smarcel if (VALID_CURR_FILE) 1286130803Smarcel { 1287130803Smarcel while (VALID_CURR_FILE && (CURR_FILE_START < end_adr)) 1288130803Smarcel { 1289130803Smarcel 1290130803Smarcel#ifdef DUMPING 1291130803Smarcel if (dumping) 1292130803Smarcel printf ("Maybe skipping file %s which overlaps with module %s\n", 1293130803Smarcel &vt_bits[(long) qFD[curr_fd].sbFile], mod_name_string); 1294130803Smarcel#endif 1295130803Smarcel if (CURR_FILE_END > end_adr) 1296130803Smarcel { 1297130803Smarcel TELL_OBJFILE; 1298130803Smarcel warning ("File \"%s\" [0x%x] crosses end of module \"%s\".", 1299130803Smarcel &vt_bits[(long) qFD[curr_fd].sbFile], 1300130803Smarcel curr_fd, mod_name_string); 1301130803Smarcel end_adr = CURR_FILE_END; 1302130803Smarcel } 1303130803Smarcel curr_fd++; 1304130803Smarcel } 1305130803Smarcel curr_fd--; /* back up after going too far */ 1306130803Smarcel } 1307130803Smarcel 1308130803Smarcel /* Sometimes (compiler bug -- COBOL) the module end address is higher 1309130803Smarcel than the start address of the next module, so check for that and 1310130803Smarcel adjust accordingly */ 1311130803Smarcel 1312130803Smarcel if (VALID_MODULE (curr_md + 1) && (MODULE_START (curr_md + 1) <= end_adr)) 1313130803Smarcel { 1314130803Smarcel TELL_OBJFILE; 1315130803Smarcel warning ("Module \"%s\" [0x%x] has ending address after starting address of next module; adjusting ending address down.", 1316130803Smarcel mod_name_string, curr_md); 1317130803Smarcel end_adr = MODULE_START (curr_md + 1) - 1; /* Is -4 (or -8 for 64-bit) better? */ 1318130803Smarcel } 1319130803Smarcel if (VALID_FILE (curr_fd + 1) && (FILE_START (curr_fd + 1) <= end_adr)) 1320130803Smarcel { 1321130803Smarcel TELL_OBJFILE; 1322130803Smarcel warning ("Module \"%s\" [0x%x] has ending address after starting address of next file; adjusting ending address down.", 1323130803Smarcel mod_name_string, curr_md); 1324130803Smarcel end_adr = FILE_START (curr_fd + 1) - 1; /* Is -4 (or -8 for 64-bit) better? */ 1325130803Smarcel } 1326130803Smarcel 1327130803Smarcel /* Use one file to get the full name for the module. This 1328130803Smarcel situation can arise if there is executable code in a #include 1329130803Smarcel file. Each file with code in it gets a qFD. Files which don't 1330130803Smarcel contribute code don't get a qFD, even if they include files 1331130803Smarcel which do, e.g.: 1332130803Smarcel 1333130803Smarcel body.c: rtn.h: 1334130803Smarcel int x; int main() { 1335130803Smarcel #include "rtn.h" return x; 1336130803Smarcel } 1337130803Smarcel 1338130803Smarcel There will a qFD for "rtn.h",and a qMD for "body.c", 1339130803Smarcel but no qMD for "rtn.h" or qFD for "body.c"! 1340130803Smarcel 1341130803Smarcel We pick the name of the last file to overlap with this 1342130803Smarcel module. C convention is to put include files first. In a 1343130803Smarcel perfect world, we could check names and use the file whose full 1344130803Smarcel path name ends with the module name. */ 1345130803Smarcel 1346130803Smarcel if (VALID_CURR_FILE) 1347130803Smarcel full_name_string = &vt_bits[(long) qFD[curr_fd].sbFile]; 1348130803Smarcel else 1349130803Smarcel full_name_string = mod_name_string; 1350130803Smarcel 1351130803Smarcel /* Check if there are any procedures not handled until now, that 1352130803Smarcel begin before the start address we have now, and if so, adjust 1353130803Smarcel this psymtab's start address to include them. This handles routines that 1354130803Smarcel are in between file or module ranges for some reason (probably 1355130803Smarcel indicates a compiler bug */ 1356130803Smarcel 1357130803Smarcel if (CURR_PROC_START < start_adr) 1358130803Smarcel { 1359130803Smarcel TELL_OBJFILE; 1360130803Smarcel warning ("Found procedure \"%s\" [0x%x] that is not in any file or module.", 1361130803Smarcel &vt_bits[(long) qPD[curr_pd].sbProc], curr_pd); 1362130803Smarcel start_adr = CURR_PROC_START; 1363130803Smarcel if (CURR_PROC_ISYM < start_sym) 1364130803Smarcel start_sym = CURR_PROC_ISYM; 1365130803Smarcel } 1366130803Smarcel 1367130803Smarcel#ifdef DUMPING 1368130803Smarcel if (dumping) 1369130803Smarcel { 1370130803Smarcel printf ("Make new psymtab for module %s (%x to %x), using file %s\n", 1371130803Smarcel mod_name_string, start_adr, end_adr, full_name_string); 1372130803Smarcel } 1373130803Smarcel#endif 1374130803Smarcel /* Create the basic psymtab, connecting it in the list 1375130803Smarcel for this objfile and pointing its symbol entries 1376130803Smarcel to the current end of the symbol areas in the objfile. 1377130803Smarcel 1378130803Smarcel The "ldsymoff" parameter is the byte offset in the LNTT 1379130803Smarcel of the first symbol in this file. Some day we should 1380130803Smarcel turn this into an index (fix in hp-symtab-read.c as well). 1381130803Smarcel And it's not even the right byte offset, as we're using 1382130803Smarcel the size of a union! FIXME! */ 1383130803Smarcel pst = hpread_start_psymtab (objfile, 1384130803Smarcel full_name_string, 1385130803Smarcel start_adr, /* Low text address */ 1386130803Smarcel (start_sym * sizeof (struct dntt_type_block)), 1387130803Smarcel /* ldsymoff */ 1388130803Smarcel global_syms, 1389130803Smarcel static_syms); 1390130803Smarcel 1391130803Smarcel /* Set up to only enter each class referenced in this module once. */ 1392130803Smarcel class_entered = xmalloc (B_BYTES (pxdb_header_p->cd_entries)); 1393130803Smarcel B_CLRALL (class_entered, pxdb_header_p->cd_entries); 1394130803Smarcel 1395130803Smarcel /* Scan the procedure descriptors for procedures in the current 1396130803Smarcel module, based on the starting addresses. */ 1397130803Smarcel 1398130803Smarcel syms_in_pst = scan_procs (&curr_pd, qPD, pxdb_header_p->pd_entries, 1399130803Smarcel start_adr, end_adr, pst, vt_bits, objfile); 1400130803Smarcel 1401130803Smarcel /* Get ending symbol offset */ 1402130803Smarcel 1403130803Smarcel end_sym = 0; 1404130803Smarcel /* First check for starting index before previous psymtab */ 1405130803Smarcel if (pst_syms_count && start_sym < pst_syms_array[pst_syms_count - 1].end) 1406130803Smarcel { 1407130803Smarcel end_sym = find_next_pst_start (start_sym); 1408130803Smarcel } 1409130803Smarcel /* Look for next start index of a file or module, or procedure */ 1410130803Smarcel if (!end_sym) 1411130803Smarcel { 1412130803Smarcel int next_file_isym = find_next_file_isym (start_sym, qFD, curr_fd + 1, pxdb_header_p); 1413130803Smarcel int next_module_isym = find_next_module_isym (start_sym, qMD, curr_md + 1, pxdb_header_p); 1414130803Smarcel int next_proc_isym = find_next_proc_isym (start_sym, qPD, curr_pd, pxdb_header_p); 1415130803Smarcel 1416130803Smarcel if (next_file_isym && next_module_isym) 1417130803Smarcel { 1418130803Smarcel /* pick lower of next file or module start index */ 1419130803Smarcel end_sym = min (next_file_isym, next_module_isym); 1420130803Smarcel } 1421130803Smarcel else 1422130803Smarcel { 1423130803Smarcel /* one of them is zero, pick the other */ 1424130803Smarcel end_sym = max (next_file_isym, next_module_isym); 1425130803Smarcel } 1426130803Smarcel 1427130803Smarcel /* As a precaution, check next procedure index too */ 1428130803Smarcel if (!end_sym) 1429130803Smarcel end_sym = next_proc_isym; 1430130803Smarcel else 1431130803Smarcel end_sym = min (end_sym, next_proc_isym); 1432130803Smarcel } 1433130803Smarcel 1434130803Smarcel /* Couldn't find procedure, file, or module, use globals as default */ 1435130803Smarcel if (!end_sym) 1436130803Smarcel end_sym = pxdb_header_p->globals; 1437130803Smarcel 1438130803Smarcel#ifdef DUMPING 1439130803Smarcel if (dumping) 1440130803Smarcel { 1441130803Smarcel printf ("Module psymtab indices: %x to %x\n", start_sym, end_sym); 1442130803Smarcel } 1443130803Smarcel#endif 1444130803Smarcel 1445130803Smarcel pst = hpread_end_psymtab (pst, 1446130803Smarcel NULL, /* psymtab_include_list */ 1447130803Smarcel 0, /* includes_used */ 1448130803Smarcel end_sym * sizeof (struct dntt_type_block), 1449130803Smarcel /* byte index in LNTT of end 1450130803Smarcel = capping symbol offset 1451130803Smarcel = LDSYMOFF of nextfile */ 1452130803Smarcel end_adr, /* text high */ 1453130803Smarcel NULL, /* dependency_list */ 1454130803Smarcel 0); /* dependencies_used */ 1455130803Smarcel 1456130803Smarcel record_pst_syms (start_sym, end_sym); 1457130803Smarcel 1458130803Smarcel if (NULL == pst) 1459130803Smarcel warning ("No symbols in psymtab for module \"%s\" [0x%x].", mod_name_string, curr_md); 1460130803Smarcel 1461130803Smarcel#ifdef DUMPING 1462130803Smarcel if (dumping) 1463130803Smarcel { 1464130803Smarcel printf ("Made new psymtab for module %s (%x to %x), sym %x to %x.\n", 1465130803Smarcel mod_name_string, start_adr, end_adr, CURR_MODULE_ISYM, end_sym); 1466130803Smarcel } 1467130803Smarcel#endif 1468130803Smarcel 1469130803Smarcel /* Prepare for the next psymtab. */ 1470130803Smarcel global_syms = objfile->global_psymbols.next; 1471130803Smarcel static_syms = objfile->static_psymbols.next; 1472130803Smarcel xfree (class_entered); 1473130803Smarcel 1474130803Smarcel curr_md++; 1475130803Smarcel curr_fd++; 1476130803Smarcel } /* psymtab for module */ 1477130803Smarcel } /* psymtab for non-bogus file or module */ 1478130803Smarcel } /* End of while loop over all files & modules */ 1479130803Smarcel 1480130803Smarcel /* There may be some routines after all files and modules -- these will get 1481130803Smarcel inserted in a separate new module of their own */ 1482130803Smarcel if (VALID_CURR_PROC) 1483130803Smarcel { 1484130803Smarcel start_adr = CURR_PROC_START; 1485130803Smarcel end_adr = qPD[pxdb_header_p->pd_entries - 1].adrEnd; 1486130803Smarcel TELL_OBJFILE; 1487130803Smarcel warning ("Found functions beyond end of all files and modules [0x%x].", curr_pd); 1488130803Smarcel#ifdef DUMPING 1489130803Smarcel if (dumping) 1490130803Smarcel { 1491130803Smarcel printf ("Orphan functions at end, PD %d and beyond (%x to %x)\n", 1492130803Smarcel curr_pd, start_adr, end_adr); 1493130803Smarcel } 1494130803Smarcel#endif 1495130803Smarcel pst = hpread_start_psymtab (objfile, 1496130803Smarcel "orphans", 1497130803Smarcel start_adr, /* Low text address */ 1498130803Smarcel (CURR_PROC_ISYM * sizeof (struct dntt_type_block)), 1499130803Smarcel /* ldsymoff */ 1500130803Smarcel global_syms, 1501130803Smarcel static_syms); 1502130803Smarcel 1503130803Smarcel scan_procs (&curr_pd, qPD, pxdb_header_p->pd_entries, 1504130803Smarcel start_adr, end_adr, pst, vt_bits, objfile); 1505130803Smarcel 1506130803Smarcel pst = hpread_end_psymtab (pst, 1507130803Smarcel NULL, /* psymtab_include_list */ 1508130803Smarcel 0, /* includes_used */ 1509130803Smarcel pxdb_header_p->globals * sizeof (struct dntt_type_block), 1510130803Smarcel /* byte index in LNTT of end 1511130803Smarcel = capping symbol offset 1512130803Smarcel = LDSYMOFF of nextfile */ 1513130803Smarcel end_adr, /* text high */ 1514130803Smarcel NULL, /* dependency_list */ 1515130803Smarcel 0); /* dependencies_used */ 1516130803Smarcel } 1517130803Smarcel 1518130803Smarcel 1519130803Smarcel#ifdef NEVER_NEVER 1520130803Smarcel /* Now build psts for non-module things (in the tail of 1521130803Smarcel the LNTT, after the last END MODULE entry). 1522130803Smarcel 1523130803Smarcel If null psts were kept on the chain, this would be 1524130803Smarcel a solution. FIXME */ 1525130803Smarcel pst = hpread_start_psymtab (objfile, 1526130803Smarcel "globals", 1527130803Smarcel 0, 1528130803Smarcel (pxdb_header_p->globals 1529130803Smarcel * sizeof (struct dntt_type_block)), 1530130803Smarcel objfile->global_psymbols.next, 1531130803Smarcel objfile->static_psymbols.next); 1532130803Smarcel hpread_end_psymtab (pst, 1533130803Smarcel NULL, 0, 1534130803Smarcel (max_LNTT_sym_index * sizeof (struct dntt_type_block)), 1535130803Smarcel 0, 1536130803Smarcel NULL, 0); 1537130803Smarcel#endif 1538130803Smarcel 1539130803Smarcel clear_pst_syms (); 1540130803Smarcel 1541130803Smarcel return 1; 1542130803Smarcel 1543130803Smarcel} /* End of hpread_quick_traverse. */ 1544130803Smarcel 1545130803Smarcel 1546130803Smarcel/* Get appropriate header, based on pxdb type. 1547130803Smarcel Return value: 1 if ok, 0 if not */ 1548130803Smarcelstatic int 1549130803Smarcelhpread_get_header (struct objfile *objfile, PXDB_header_ptr pxdb_header_p) 1550130803Smarcel{ 1551130803Smarcel asection *pinfo_section, *debug_section, *header_section; 1552130803Smarcel 1553130803Smarcel#ifdef DUMPING 1554130803Smarcel /* Turn on for debugging information */ 1555130803Smarcel static int dumping = 0; 1556130803Smarcel#endif 1557130803Smarcel 1558130803Smarcel header_section = bfd_get_section_by_name (objfile->obfd, "$HEADER$"); 1559130803Smarcel if (!header_section) 1560130803Smarcel { 1561130803Smarcel /* We don't have either PINFO or DEBUG sections. But 1562130803Smarcel stuff like "libc.sl" has no debug info. There's no 1563130803Smarcel need to warn the user of this, as it may be ok. The 1564130803Smarcel caller will figure it out and issue any needed 1565130803Smarcel messages. */ 1566130803Smarcel#ifdef DUMPING 1567130803Smarcel if (dumping) 1568130803Smarcel printf ("==No debug info at all for %s.\n", objfile->name); 1569130803Smarcel#endif 1570130803Smarcel 1571130803Smarcel return 0; 1572130803Smarcel } 1573130803Smarcel 1574130803Smarcel /* We would like either a $DEBUG$ or $PINFO$ section. 1575130803Smarcel Once we know which, we can understand the header 1576130803Smarcel data (which we have defined to suit the more common 1577130803Smarcel $DEBUG$ case). */ 1578130803Smarcel debug_section = bfd_get_section_by_name (objfile->obfd, "$DEBUG$"); 1579130803Smarcel pinfo_section = bfd_get_section_by_name (objfile->obfd, "$PINFO$"); 1580130803Smarcel if (debug_section) 1581130803Smarcel { 1582130803Smarcel /* The expected case: normal pxdb header. */ 1583130803Smarcel bfd_get_section_contents (objfile->obfd, header_section, 1584130803Smarcel pxdb_header_p, 0, sizeof (PXDB_header)); 1585130803Smarcel 1586130803Smarcel if (!pxdb_header_p->pxdbed) 1587130803Smarcel { 1588130803Smarcel /* This shouldn't happen if we check in "symfile.c". */ 1589130803Smarcel return 0; 1590130803Smarcel } /* DEBUG section */ 1591130803Smarcel } 1592130803Smarcel 1593130803Smarcel else if (pinfo_section) 1594130803Smarcel { 1595130803Smarcel /* The DOC case; we need to translate this into a 1596130803Smarcel regular header. */ 1597130803Smarcel DOC_info_PXDB_header doc_header; 1598130803Smarcel 1599130803Smarcel#ifdef DUMPING 1600130803Smarcel if (dumping) 1601130803Smarcel { 1602130803Smarcel printf ("==OOps, PINFO, let's try to handle this, %s.\n", objfile->name); 1603130803Smarcel } 1604130803Smarcel#endif 1605130803Smarcel 1606130803Smarcel bfd_get_section_contents (objfile->obfd, 1607130803Smarcel header_section, 1608130803Smarcel &doc_header, 0, 1609130803Smarcel sizeof (DOC_info_PXDB_header)); 1610130803Smarcel 1611130803Smarcel if (!doc_header.pxdbed) 1612130803Smarcel { 1613130803Smarcel /* This shouldn't happen if we check in "symfile.c". */ 1614130803Smarcel warning ("File \"%s\" not processed by pxdb!", objfile->name); 1615130803Smarcel return 0; 1616130803Smarcel } 1617130803Smarcel 1618130803Smarcel /* Copy relevent fields to standard header passed in. */ 1619130803Smarcel pxdb_header_p->pd_entries = doc_header.pd_entries; 1620130803Smarcel pxdb_header_p->fd_entries = doc_header.fd_entries; 1621130803Smarcel pxdb_header_p->md_entries = doc_header.md_entries; 1622130803Smarcel pxdb_header_p->pxdbed = doc_header.pxdbed; 1623130803Smarcel pxdb_header_p->bighdr = doc_header.bighdr; 1624130803Smarcel pxdb_header_p->sa_header = doc_header.sa_header; 1625130803Smarcel pxdb_header_p->inlined = doc_header.inlined; 1626130803Smarcel pxdb_header_p->globals = doc_header.globals; 1627130803Smarcel pxdb_header_p->time = doc_header.time; 1628130803Smarcel pxdb_header_p->pg_entries = doc_header.pg_entries; 1629130803Smarcel pxdb_header_p->functions = doc_header.functions; 1630130803Smarcel pxdb_header_p->files = doc_header.files; 1631130803Smarcel pxdb_header_p->cd_entries = doc_header.cd_entries; 1632130803Smarcel pxdb_header_p->aa_entries = doc_header.aa_entries; 1633130803Smarcel pxdb_header_p->oi_entries = doc_header.oi_entries; 1634130803Smarcel pxdb_header_p->version = doc_header.version; 1635130803Smarcel } /* PINFO section */ 1636130803Smarcel 1637130803Smarcel else 1638130803Smarcel { 1639130803Smarcel#ifdef DUMPING 1640130803Smarcel if (dumping) 1641130803Smarcel printf ("==No debug info at all for %s.\n", objfile->name); 1642130803Smarcel#endif 1643130803Smarcel 1644130803Smarcel return 0; 1645130803Smarcel 1646130803Smarcel } 1647130803Smarcel 1648130803Smarcel return 1; 1649130803Smarcel} /* End of hpread_get_header */ 1650130803Smarcel#endif /* QUICK_LOOK_UP */ 1651130803Smarcel 1652130803Smarcel 1653130803Smarcel/* Initialization for reading native HP C debug symbols from OBJFILE. 1654130803Smarcel 1655130803Smarcel Its only purpose in life is to set up the symbol reader's private 1656130803Smarcel per-objfile data structures, and read in the raw contents of the debug 1657130803Smarcel sections (attaching pointers to the debug info into the private data 1658130803Smarcel structures). 1659130803Smarcel 1660130803Smarcel Since BFD doesn't know how to read debug symbols in a format-independent 1661130803Smarcel way (and may never do so...), we have to do it ourselves. Note we may 1662130803Smarcel be called on a file without native HP C debugging symbols. 1663130803Smarcel 1664130803Smarcel FIXME, there should be a cleaner peephole into the BFD environment 1665130803Smarcel here. */ 1666130803Smarcelvoid 1667130803Smarcelhpread_symfile_init (struct objfile *objfile) 1668130803Smarcel{ 1669130803Smarcel asection *vt_section, *slt_section, *lntt_section, *gntt_section; 1670130803Smarcel 1671130803Smarcel /* Allocate struct to keep track of the symfile */ 1672130803Smarcel objfile->sym_private = 1673130803Smarcel xmmalloc (objfile->md, sizeof (struct hpread_symfile_info)); 1674130803Smarcel memset (objfile->sym_private, 0, sizeof (struct hpread_symfile_info)); 1675130803Smarcel 1676130803Smarcel /* We haven't read in any types yet. */ 1677130803Smarcel DNTT_TYPE_VECTOR (objfile) = 0; 1678130803Smarcel 1679130803Smarcel /* Read in data from the $GNTT$ subspace. */ 1680130803Smarcel gntt_section = bfd_get_section_by_name (objfile->obfd, "$GNTT$"); 1681130803Smarcel if (!gntt_section) 1682130803Smarcel return; 1683130803Smarcel 1684130803Smarcel GNTT (objfile) 1685130803Smarcel = obstack_alloc (&objfile->objfile_obstack, 1686130803Smarcel bfd_section_size (objfile->obfd, gntt_section)); 1687130803Smarcel 1688130803Smarcel bfd_get_section_contents (objfile->obfd, gntt_section, GNTT (objfile), 1689130803Smarcel 0, bfd_section_size (objfile->obfd, gntt_section)); 1690130803Smarcel 1691130803Smarcel GNTT_SYMCOUNT (objfile) 1692130803Smarcel = bfd_section_size (objfile->obfd, gntt_section) 1693130803Smarcel / sizeof (struct dntt_type_block); 1694130803Smarcel 1695130803Smarcel /* Read in data from the $LNTT$ subspace. Also keep track of the number 1696130803Smarcel of LNTT symbols. 1697130803Smarcel 1698130803Smarcel FIXME: this could be moved into the psymtab-to-symtab expansion 1699130803Smarcel code, and save startup time. At the moment this data is 1700130803Smarcel still used, though. We'd need a way to tell hp-symtab-read.c 1701130803Smarcel whether or not to load the LNTT. */ 1702130803Smarcel lntt_section = bfd_get_section_by_name (objfile->obfd, "$LNTT$"); 1703130803Smarcel if (!lntt_section) 1704130803Smarcel return; 1705130803Smarcel 1706130803Smarcel LNTT (objfile) 1707130803Smarcel = obstack_alloc (&objfile->objfile_obstack, 1708130803Smarcel bfd_section_size (objfile->obfd, lntt_section)); 1709130803Smarcel 1710130803Smarcel bfd_get_section_contents (objfile->obfd, lntt_section, LNTT (objfile), 1711130803Smarcel 0, bfd_section_size (objfile->obfd, lntt_section)); 1712130803Smarcel 1713130803Smarcel LNTT_SYMCOUNT (objfile) 1714130803Smarcel = bfd_section_size (objfile->obfd, lntt_section) 1715130803Smarcel / sizeof (struct dntt_type_block); 1716130803Smarcel 1717130803Smarcel /* Read in data from the $SLT$ subspace. $SLT$ contains information 1718130803Smarcel on source line numbers. */ 1719130803Smarcel slt_section = bfd_get_section_by_name (objfile->obfd, "$SLT$"); 1720130803Smarcel if (!slt_section) 1721130803Smarcel return; 1722130803Smarcel 1723130803Smarcel SLT (objfile) = 1724130803Smarcel obstack_alloc (&objfile->objfile_obstack, 1725130803Smarcel bfd_section_size (objfile->obfd, slt_section)); 1726130803Smarcel 1727130803Smarcel bfd_get_section_contents (objfile->obfd, slt_section, SLT (objfile), 1728130803Smarcel 0, bfd_section_size (objfile->obfd, slt_section)); 1729130803Smarcel 1730130803Smarcel /* Read in data from the $VT$ subspace. $VT$ contains things like 1731130803Smarcel names and constants. Keep track of the number of symbols in the VT. */ 1732130803Smarcel vt_section = bfd_get_section_by_name (objfile->obfd, "$VT$"); 1733130803Smarcel if (!vt_section) 1734130803Smarcel return; 1735130803Smarcel 1736130803Smarcel VT_SIZE (objfile) = bfd_section_size (objfile->obfd, vt_section); 1737130803Smarcel 1738130803Smarcel VT (objfile) = 1739130803Smarcel (char *) obstack_alloc (&objfile->objfile_obstack, 1740130803Smarcel VT_SIZE (objfile)); 1741130803Smarcel 1742130803Smarcel bfd_get_section_contents (objfile->obfd, vt_section, VT (objfile), 1743130803Smarcel 0, VT_SIZE (objfile)); 1744130803Smarcel} 1745130803Smarcel 1746130803Smarcel/* Scan and build partial symbols for a symbol file. 1747130803Smarcel 1748130803Smarcel The minimal symbol table (either SOM or HP a.out) has already been 1749130803Smarcel read in; all we need to do is setup partial symbols based on the 1750130803Smarcel native debugging information. 1751130803Smarcel 1752130803Smarcel Note that the minimal table is produced by the linker, and has 1753130803Smarcel only global routines in it; the psymtab is based on compiler- 1754130803Smarcel generated debug information and has non-global 1755130803Smarcel routines in it as well as files and class information. 1756130803Smarcel 1757130803Smarcel We assume hpread_symfile_init has been called to initialize the 1758130803Smarcel symbol reader's private data structures. 1759130803Smarcel 1760130803Smarcel MAINLINE is true if we are reading the main symbol table (as 1761130803Smarcel opposed to a shared lib or dynamically loaded file). */ 1762130803Smarcel 1763130803Smarcelvoid 1764130803Smarcelhpread_build_psymtabs (struct objfile *objfile, int mainline) 1765130803Smarcel{ 1766130803Smarcel 1767130803Smarcel#ifdef DUMPING 1768130803Smarcel /* Turn this on to get debugging output. */ 1769130803Smarcel static int dumping = 0; 1770130803Smarcel#endif 1771130803Smarcel 1772130803Smarcel char *namestring; 1773130803Smarcel int past_first_source_file = 0; 1774130803Smarcel struct cleanup *old_chain; 1775130803Smarcel 1776130803Smarcel int hp_symnum, symcount, i; 1777130803Smarcel int scan_start = 0; 1778130803Smarcel 1779130803Smarcel union dnttentry *dn_bufp; 1780130803Smarcel unsigned long valu; 1781130803Smarcel char *p; 1782130803Smarcel int texthigh = 0; 1783130803Smarcel int have_name = 0; 1784130803Smarcel 1785130803Smarcel /* Current partial symtab */ 1786130803Smarcel struct partial_symtab *pst; 1787130803Smarcel 1788130803Smarcel /* List of current psymtab's include files */ 1789130803Smarcel char **psymtab_include_list; 1790130803Smarcel int includes_allocated; 1791130803Smarcel int includes_used; 1792130803Smarcel 1793130803Smarcel /* Index within current psymtab dependency list */ 1794130803Smarcel struct partial_symtab **dependency_list; 1795130803Smarcel int dependencies_used, dependencies_allocated; 1796130803Smarcel 1797130803Smarcel /* Just in case the stabs reader left turds lying around. */ 1798130803Smarcel free_pending_blocks (); 1799130803Smarcel make_cleanup (really_free_pendings, 0); 1800130803Smarcel 1801130803Smarcel pst = (struct partial_symtab *) 0; 1802130803Smarcel 1803130803Smarcel /* We shouldn't use alloca, instead use malloc/free. Doing so avoids 1804130803Smarcel a number of problems with cross compilation and creating useless holes 1805130803Smarcel in the stack when we have to allocate new entries. FIXME. */ 1806130803Smarcel 1807130803Smarcel includes_allocated = 30; 1808130803Smarcel includes_used = 0; 1809130803Smarcel psymtab_include_list = (char **) alloca (includes_allocated * 1810130803Smarcel sizeof (char *)); 1811130803Smarcel 1812130803Smarcel dependencies_allocated = 30; 1813130803Smarcel dependencies_used = 0; 1814130803Smarcel dependency_list = 1815130803Smarcel (struct partial_symtab **) alloca (dependencies_allocated * 1816130803Smarcel sizeof (struct partial_symtab *)); 1817130803Smarcel 1818130803Smarcel old_chain = make_cleanup_free_objfile (objfile); 1819130803Smarcel 1820130803Smarcel last_source_file = 0; 1821130803Smarcel 1822130803Smarcel#ifdef QUICK_LOOK_UP 1823130803Smarcel { 1824130803Smarcel /* Begin code for new-style loading of quick look-up tables. */ 1825130803Smarcel 1826130803Smarcel /* elz: this checks whether the file has beeen processed by pxdb. 1827130803Smarcel If not we would like to try to read the psymbols in 1828130803Smarcel anyway, but it turns out to be not so easy. So this could 1829130803Smarcel actually be commented out, but I leave it in, just in case 1830130803Smarcel we decide to add support for non-pxdb-ed stuff in the future. */ 1831130803Smarcel PXDB_header pxdb_header; 1832130803Smarcel int found_modules_in_program; 1833130803Smarcel 1834130803Smarcel if (hpread_get_header (objfile, &pxdb_header)) 1835130803Smarcel { 1836130803Smarcel /* Build a minimal table. No types, no global variables, 1837130803Smarcel no include files.... */ 1838130803Smarcel#ifdef DUMPING 1839130803Smarcel if (dumping) 1840130803Smarcel printf ("\nNew method for %s\n", objfile->name); 1841130803Smarcel#endif 1842130803Smarcel 1843130803Smarcel /* elz: quick_traverse returns true if it found 1844130803Smarcel some modules in the main source file, other 1845130803Smarcel than those in end.c 1846130803Smarcel In C and C++, all the files have MODULES entries 1847130803Smarcel in the LNTT, and the quick table traverse is all 1848130803Smarcel based on finding these MODULES entries. Without 1849130803Smarcel those it cannot work. 1850130803Smarcel It happens that F77 programs don't have MODULES 1851130803Smarcel so the quick traverse gets confused. F90 programs 1852130803Smarcel have modules, and the quick method still works. 1853130803Smarcel So, if modules (other than those in end.c) are 1854130803Smarcel not found we give up on the quick table stuff, 1855130803Smarcel and fall back on the slower method */ 1856130803Smarcel found_modules_in_program = hpread_quick_traverse (objfile, 1857130803Smarcel GNTT (objfile), 1858130803Smarcel VT (objfile), 1859130803Smarcel &pxdb_header); 1860130803Smarcel 1861130803Smarcel discard_cleanups (old_chain); 1862130803Smarcel 1863130803Smarcel /* Set up to scan the global section of the LNTT. 1864130803Smarcel 1865130803Smarcel This field is not always correct: if there are 1866130803Smarcel no globals, it will point to the last record in 1867130803Smarcel the regular LNTT, which is usually an END MODULE. 1868130803Smarcel 1869130803Smarcel Since it might happen that there could be a file 1870130803Smarcel with just one global record, there's no way to 1871130803Smarcel tell other than by looking at the record, so that's 1872130803Smarcel done below. */ 1873130803Smarcel if (found_modules_in_program) 1874130803Smarcel scan_start = pxdb_header.globals; 1875130803Smarcel } 1876130803Smarcel#ifdef DUMPING 1877130803Smarcel else 1878130803Smarcel { 1879130803Smarcel if (dumping) 1880130803Smarcel printf ("\nGoing on to old method for %s\n", objfile->name); 1881130803Smarcel } 1882130803Smarcel#endif 1883130803Smarcel } 1884130803Smarcel#endif /* QUICK_LOOK_UP */ 1885130803Smarcel 1886130803Smarcel /* Make two passes, one over the GNTT symbols, the other for the 1887130803Smarcel LNTT symbols. 1888130803Smarcel 1889130803Smarcel JB comment: above isn't true--they only make one pass, over 1890130803Smarcel the LNTT. */ 1891130803Smarcel for (i = 0; i < 1; i++) 1892130803Smarcel { 1893130803Smarcel int within_function = 0; 1894130803Smarcel 1895130803Smarcel if (i) 1896130803Smarcel symcount = GNTT_SYMCOUNT (objfile); 1897130803Smarcel else 1898130803Smarcel symcount = LNTT_SYMCOUNT (objfile); 1899130803Smarcel 1900130803Smarcel 1901130803Smarcel for (hp_symnum = scan_start; hp_symnum < symcount; hp_symnum++) 1902130803Smarcel { 1903130803Smarcel QUIT; 1904130803Smarcel if (i) 1905130803Smarcel dn_bufp = hpread_get_gntt (hp_symnum, objfile); 1906130803Smarcel else 1907130803Smarcel dn_bufp = hpread_get_lntt (hp_symnum, objfile); 1908130803Smarcel 1909130803Smarcel if (dn_bufp->dblock.extension) 1910130803Smarcel continue; 1911130803Smarcel 1912130803Smarcel /* Only handle things which are necessary for minimal symbols. 1913130803Smarcel everything else is ignored. */ 1914130803Smarcel switch (dn_bufp->dblock.kind) 1915130803Smarcel { 1916130803Smarcel case DNTT_TYPE_SRCFILE: 1917130803Smarcel { 1918130803Smarcel#ifdef QUICK_LOOK_UP 1919130803Smarcel if (scan_start == hp_symnum 1920130803Smarcel && symcount == hp_symnum + 1) 1921130803Smarcel { 1922130803Smarcel /* If there are NO globals in an executable, 1923130803Smarcel PXDB's index to the globals will point to 1924130803Smarcel the last record in the file, which 1925130803Smarcel could be this record. (this happened for F77 libraries) 1926130803Smarcel ignore it and be done! */ 1927130803Smarcel continue; 1928130803Smarcel } 1929130803Smarcel#endif /* QUICK_LOOK_UP */ 1930130803Smarcel 1931130803Smarcel /* A source file of some kind. Note this may simply 1932130803Smarcel be an included file. */ 1933130803Smarcel set_namestring (dn_bufp, &namestring, objfile); 1934130803Smarcel 1935130803Smarcel /* Check if this is the source file we are already working 1936130803Smarcel with. */ 1937130803Smarcel if (pst && !strcmp (namestring, pst->filename)) 1938130803Smarcel continue; 1939130803Smarcel 1940130803Smarcel /* Check if this is an include file, if so check if we have 1941130803Smarcel already seen it. Add it to the include list */ 1942130803Smarcel p = strrchr (namestring, '.'); 1943130803Smarcel if (!strcmp (p, ".h")) 1944130803Smarcel { 1945130803Smarcel int j, found; 1946130803Smarcel 1947130803Smarcel found = 0; 1948130803Smarcel for (j = 0; j < includes_used; j++) 1949130803Smarcel if (!strcmp (namestring, psymtab_include_list[j])) 1950130803Smarcel { 1951130803Smarcel found = 1; 1952130803Smarcel break; 1953130803Smarcel } 1954130803Smarcel if (found) 1955130803Smarcel continue; 1956130803Smarcel 1957130803Smarcel /* Add it to the list of includes seen so far and 1958130803Smarcel allocate more include space if necessary. */ 1959130803Smarcel psymtab_include_list[includes_used++] = namestring; 1960130803Smarcel if (includes_used >= includes_allocated) 1961130803Smarcel { 1962130803Smarcel char **orig = psymtab_include_list; 1963130803Smarcel 1964130803Smarcel psymtab_include_list = (char **) 1965130803Smarcel alloca ((includes_allocated *= 2) * 1966130803Smarcel sizeof (char *)); 1967130803Smarcel memcpy (psymtab_include_list, orig, 1968130803Smarcel includes_used * sizeof (char *)); 1969130803Smarcel } 1970130803Smarcel continue; 1971130803Smarcel } 1972130803Smarcel 1973130803Smarcel if (pst) 1974130803Smarcel { 1975130803Smarcel if (!have_name) 1976130803Smarcel { 1977130803Smarcel pst->filename = (char *) 1978130803Smarcel obstack_alloc (&pst->objfile->objfile_obstack, 1979130803Smarcel strlen (namestring) + 1); 1980130803Smarcel strcpy (pst->filename, namestring); 1981130803Smarcel have_name = 1; 1982130803Smarcel continue; 1983130803Smarcel } 1984130803Smarcel continue; 1985130803Smarcel } 1986130803Smarcel 1987130803Smarcel /* This is a bonafide new source file. 1988130803Smarcel End the current partial symtab and start a new one. */ 1989130803Smarcel 1990130803Smarcel if (pst && past_first_source_file) 1991130803Smarcel { 1992130803Smarcel hpread_end_psymtab (pst, psymtab_include_list, 1993130803Smarcel includes_used, 1994130803Smarcel (hp_symnum 1995130803Smarcel * sizeof (struct dntt_type_block)), 1996130803Smarcel texthigh, 1997130803Smarcel dependency_list, dependencies_used); 1998130803Smarcel pst = (struct partial_symtab *) 0; 1999130803Smarcel includes_used = 0; 2000130803Smarcel dependencies_used = 0; 2001130803Smarcel } 2002130803Smarcel else 2003130803Smarcel past_first_source_file = 1; 2004130803Smarcel 2005130803Smarcel valu = hpread_get_textlow (i, hp_symnum, objfile, symcount); 2006130803Smarcel valu += ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile)); 2007130803Smarcel pst = hpread_start_psymtab (objfile, 2008130803Smarcel namestring, valu, 2009130803Smarcel (hp_symnum 2010130803Smarcel * sizeof (struct dntt_type_block)), 2011130803Smarcel objfile->global_psymbols.next, 2012130803Smarcel objfile->static_psymbols.next); 2013130803Smarcel texthigh = valu; 2014130803Smarcel have_name = 1; 2015130803Smarcel continue; 2016130803Smarcel } 2017130803Smarcel 2018130803Smarcel case DNTT_TYPE_MODULE: 2019130803Smarcel /* A source file. It's still unclear to me what the 2020130803Smarcel real difference between a DNTT_TYPE_SRCFILE and DNTT_TYPE_MODULE 2021130803Smarcel is supposed to be. */ 2022130803Smarcel 2023130803Smarcel /* First end the previous psymtab */ 2024130803Smarcel if (pst) 2025130803Smarcel { 2026130803Smarcel hpread_end_psymtab (pst, psymtab_include_list, includes_used, 2027130803Smarcel ((hp_symnum - 1) 2028130803Smarcel * sizeof (struct dntt_type_block)), 2029130803Smarcel texthigh, 2030130803Smarcel dependency_list, dependencies_used); 2031130803Smarcel pst = (struct partial_symtab *) 0; 2032130803Smarcel includes_used = 0; 2033130803Smarcel dependencies_used = 0; 2034130803Smarcel have_name = 0; 2035130803Smarcel } 2036130803Smarcel 2037130803Smarcel /* Now begin a new module and a new psymtab for it */ 2038130803Smarcel set_namestring (dn_bufp, &namestring, objfile); 2039130803Smarcel valu = hpread_get_textlow (i, hp_symnum, objfile, symcount); 2040130803Smarcel valu += ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile)); 2041130803Smarcel if (!pst) 2042130803Smarcel { 2043130803Smarcel pst = hpread_start_psymtab (objfile, 2044130803Smarcel namestring, valu, 2045130803Smarcel (hp_symnum 2046130803Smarcel * sizeof (struct dntt_type_block)), 2047130803Smarcel objfile->global_psymbols.next, 2048130803Smarcel objfile->static_psymbols.next); 2049130803Smarcel texthigh = valu; 2050130803Smarcel have_name = 0; 2051130803Smarcel } 2052130803Smarcel continue; 2053130803Smarcel 2054130803Smarcel case DNTT_TYPE_FUNCTION: 2055130803Smarcel case DNTT_TYPE_ENTRY: 2056130803Smarcel /* The beginning of a function. DNTT_TYPE_ENTRY may also denote 2057130803Smarcel a secondary entry point. */ 2058130803Smarcel valu = dn_bufp->dfunc.hiaddr + ANOFFSET (objfile->section_offsets, 2059130803Smarcel SECT_OFF_TEXT (objfile)); 2060130803Smarcel if (valu > texthigh) 2061130803Smarcel texthigh = valu; 2062130803Smarcel valu = dn_bufp->dfunc.lowaddr + 2063130803Smarcel ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile)); 2064130803Smarcel set_namestring (dn_bufp, &namestring, objfile); 2065130803Smarcel if (dn_bufp->dfunc.global) 2066130803Smarcel add_psymbol_to_list (namestring, strlen (namestring), 2067130803Smarcel VAR_DOMAIN, LOC_BLOCK, 2068130803Smarcel &objfile->global_psymbols, valu, 2069130803Smarcel 0, language_unknown, objfile); 2070130803Smarcel else 2071130803Smarcel add_psymbol_to_list (namestring, strlen (namestring), 2072130803Smarcel VAR_DOMAIN, LOC_BLOCK, 2073130803Smarcel &objfile->static_psymbols, valu, 2074130803Smarcel 0, language_unknown, objfile); 2075130803Smarcel within_function = 1; 2076130803Smarcel continue; 2077130803Smarcel 2078130803Smarcel case DNTT_TYPE_DOC_FUNCTION: 2079130803Smarcel valu = dn_bufp->ddocfunc.hiaddr + ANOFFSET (objfile->section_offsets, 2080130803Smarcel SECT_OFF_TEXT (objfile)); 2081130803Smarcel if (valu > texthigh) 2082130803Smarcel texthigh = valu; 2083130803Smarcel valu = dn_bufp->ddocfunc.lowaddr + 2084130803Smarcel ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile)); 2085130803Smarcel set_namestring (dn_bufp, &namestring, objfile); 2086130803Smarcel if (dn_bufp->ddocfunc.global) 2087130803Smarcel add_psymbol_to_list (namestring, strlen (namestring), 2088130803Smarcel VAR_DOMAIN, LOC_BLOCK, 2089130803Smarcel &objfile->global_psymbols, valu, 2090130803Smarcel 0, language_unknown, objfile); 2091130803Smarcel else 2092130803Smarcel add_psymbol_to_list (namestring, strlen (namestring), 2093130803Smarcel VAR_DOMAIN, LOC_BLOCK, 2094130803Smarcel &objfile->static_psymbols, valu, 2095130803Smarcel 0, language_unknown, objfile); 2096130803Smarcel within_function = 1; 2097130803Smarcel continue; 2098130803Smarcel 2099130803Smarcel case DNTT_TYPE_BEGIN: 2100130803Smarcel case DNTT_TYPE_END: 2101130803Smarcel /* We don't check MODULE end here, because there can be 2102130803Smarcel symbols beyond the module end which properly belong to the 2103130803Smarcel current psymtab -- so we wait till the next MODULE start */ 2104130803Smarcel 2105130803Smarcel 2106130803Smarcel#ifdef QUICK_LOOK_UP 2107130803Smarcel if (scan_start == hp_symnum 2108130803Smarcel && symcount == hp_symnum + 1) 2109130803Smarcel { 2110130803Smarcel /* If there are NO globals in an executable, 2111130803Smarcel PXDB's index to the globals will point to 2112130803Smarcel the last record in the file, which is 2113130803Smarcel probably an END MODULE, i.e. this record. 2114130803Smarcel ignore it and be done! */ 2115130803Smarcel continue; 2116130803Smarcel } 2117130803Smarcel#endif /* QUICK_LOOK_UP */ 2118130803Smarcel 2119130803Smarcel /* Scope block begin/end. We only care about function 2120130803Smarcel and file blocks right now. */ 2121130803Smarcel 2122130803Smarcel if ((dn_bufp->dend.endkind == DNTT_TYPE_FUNCTION) || 2123130803Smarcel (dn_bufp->dend.endkind == DNTT_TYPE_DOC_FUNCTION)) 2124130803Smarcel within_function = 0; 2125130803Smarcel continue; 2126130803Smarcel 2127130803Smarcel case DNTT_TYPE_SVAR: 2128130803Smarcel case DNTT_TYPE_DVAR: 2129130803Smarcel case DNTT_TYPE_TYPEDEF: 2130130803Smarcel case DNTT_TYPE_TAGDEF: 2131130803Smarcel { 2132130803Smarcel /* Variables, typedefs an the like. */ 2133130803Smarcel enum address_class storage; 2134130803Smarcel domain_enum domain; 2135130803Smarcel 2136130803Smarcel /* Don't add locals to the partial symbol table. */ 2137130803Smarcel if (within_function 2138130803Smarcel && (dn_bufp->dblock.kind == DNTT_TYPE_SVAR 2139130803Smarcel || dn_bufp->dblock.kind == DNTT_TYPE_DVAR)) 2140130803Smarcel continue; 2141130803Smarcel 2142130803Smarcel /* TAGDEFs go into the structure domain. */ 2143130803Smarcel if (dn_bufp->dblock.kind == DNTT_TYPE_TAGDEF) 2144130803Smarcel domain = STRUCT_DOMAIN; 2145130803Smarcel else 2146130803Smarcel domain = VAR_DOMAIN; 2147130803Smarcel 2148130803Smarcel /* What kind of "storage" does this use? */ 2149130803Smarcel if (dn_bufp->dblock.kind == DNTT_TYPE_SVAR) 2150130803Smarcel storage = LOC_STATIC; 2151130803Smarcel else if (dn_bufp->dblock.kind == DNTT_TYPE_DVAR 2152130803Smarcel && dn_bufp->ddvar.regvar) 2153130803Smarcel storage = LOC_REGISTER; 2154130803Smarcel else if (dn_bufp->dblock.kind == DNTT_TYPE_DVAR) 2155130803Smarcel storage = LOC_LOCAL; 2156130803Smarcel else 2157130803Smarcel storage = LOC_UNDEF; 2158130803Smarcel 2159130803Smarcel set_namestring (dn_bufp, &namestring, objfile); 2160130803Smarcel if (!pst) 2161130803Smarcel { 2162130803Smarcel pst = hpread_start_psymtab (objfile, 2163130803Smarcel "globals", 0, 2164130803Smarcel (hp_symnum 2165130803Smarcel * sizeof (struct dntt_type_block)), 2166130803Smarcel objfile->global_psymbols.next, 2167130803Smarcel objfile->static_psymbols.next); 2168130803Smarcel } 2169130803Smarcel 2170130803Smarcel /* Compute address of the data symbol */ 2171130803Smarcel valu = dn_bufp->dsvar.location; 2172130803Smarcel /* Relocate in case it's in a shared library */ 2173130803Smarcel if (storage == LOC_STATIC) 2174130803Smarcel valu += ANOFFSET (objfile->section_offsets, SECT_OFF_DATA (objfile)); 2175130803Smarcel 2176130803Smarcel /* Luckily, dvar, svar, typedef, and tagdef all 2177130803Smarcel have their "global" bit in the same place, so it works 2178130803Smarcel (though it's bad programming practice) to reference 2179130803Smarcel "dsvar.global" even though we may be looking at 2180130803Smarcel any of the above four types. */ 2181130803Smarcel if (dn_bufp->dsvar.global) 2182130803Smarcel { 2183130803Smarcel add_psymbol_to_list (namestring, strlen (namestring), 2184130803Smarcel domain, storage, 2185130803Smarcel &objfile->global_psymbols, 2186130803Smarcel valu, 2187130803Smarcel 0, language_unknown, objfile); 2188130803Smarcel } 2189130803Smarcel else 2190130803Smarcel { 2191130803Smarcel add_psymbol_to_list (namestring, strlen (namestring), 2192130803Smarcel domain, storage, 2193130803Smarcel &objfile->static_psymbols, 2194130803Smarcel valu, 2195130803Smarcel 0, language_unknown, objfile); 2196130803Smarcel } 2197130803Smarcel 2198130803Smarcel /* For TAGDEF's, the above code added the tagname to the 2199130803Smarcel struct domain. This will cause tag "t" to be found 2200130803Smarcel on a reference of the form "(struct t) x". But for 2201130803Smarcel C++ classes, "t" will also be a typename, which we 2202130803Smarcel want to find on a reference of the form "ptype t". 2203130803Smarcel Therefore, we also add "t" to the var domain. 2204130803Smarcel Do the same for enum's due to the way aCC generates 2205130803Smarcel debug info for these (see more extended comment 2206130803Smarcel in hp-symtab-read.c). 2207130803Smarcel We do the same for templates, so that "ptype t" 2208130803Smarcel where "t" is a template also works. */ 2209130803Smarcel if (dn_bufp->dblock.kind == DNTT_TYPE_TAGDEF && 2210130803Smarcel dn_bufp->dtype.type.dnttp.index < LNTT_SYMCOUNT (objfile)) 2211130803Smarcel { 2212130803Smarcel int global = dn_bufp->dtag.global; 2213130803Smarcel /* Look ahead to see if it's a C++ class */ 2214130803Smarcel dn_bufp = hpread_get_lntt (dn_bufp->dtype.type.dnttp.index, objfile); 2215130803Smarcel if (dn_bufp->dblock.kind == DNTT_TYPE_CLASS || 2216130803Smarcel dn_bufp->dblock.kind == DNTT_TYPE_ENUM || 2217130803Smarcel dn_bufp->dblock.kind == DNTT_TYPE_TEMPLATE) 2218130803Smarcel { 2219130803Smarcel if (global) 2220130803Smarcel { 2221130803Smarcel add_psymbol_to_list (namestring, strlen (namestring), 2222130803Smarcel VAR_DOMAIN, storage, 2223130803Smarcel &objfile->global_psymbols, 2224130803Smarcel dn_bufp->dsvar.location, 2225130803Smarcel 0, language_unknown, objfile); 2226130803Smarcel } 2227130803Smarcel else 2228130803Smarcel { 2229130803Smarcel add_psymbol_to_list (namestring, strlen (namestring), 2230130803Smarcel VAR_DOMAIN, storage, 2231130803Smarcel &objfile->static_psymbols, 2232130803Smarcel dn_bufp->dsvar.location, 2233130803Smarcel 0, language_unknown, objfile); 2234130803Smarcel } 2235130803Smarcel } 2236130803Smarcel } 2237130803Smarcel } 2238130803Smarcel continue; 2239130803Smarcel 2240130803Smarcel case DNTT_TYPE_MEMENUM: 2241130803Smarcel case DNTT_TYPE_CONST: 2242130803Smarcel /* Constants and members of enumerated types. */ 2243130803Smarcel set_namestring (dn_bufp, &namestring, objfile); 2244130803Smarcel if (!pst) 2245130803Smarcel { 2246130803Smarcel pst = hpread_start_psymtab (objfile, 2247130803Smarcel "globals", 0, 2248130803Smarcel (hp_symnum 2249130803Smarcel * sizeof (struct dntt_type_block)), 2250130803Smarcel objfile->global_psymbols.next, 2251130803Smarcel objfile->static_psymbols.next); 2252130803Smarcel } 2253130803Smarcel if (dn_bufp->dconst.global) 2254130803Smarcel add_psymbol_to_list (namestring, strlen (namestring), 2255130803Smarcel VAR_DOMAIN, LOC_CONST, 2256130803Smarcel &objfile->global_psymbols, 0, 2257130803Smarcel 0, language_unknown, objfile); 2258130803Smarcel else 2259130803Smarcel add_psymbol_to_list (namestring, strlen (namestring), 2260130803Smarcel VAR_DOMAIN, LOC_CONST, 2261130803Smarcel &objfile->static_psymbols, 0, 2262130803Smarcel 0, language_unknown, objfile); 2263130803Smarcel continue; 2264130803Smarcel default: 2265130803Smarcel continue; 2266130803Smarcel } 2267130803Smarcel } 2268130803Smarcel } 2269130803Smarcel 2270130803Smarcel /* End any pending partial symbol table. */ 2271130803Smarcel if (pst) 2272130803Smarcel { 2273130803Smarcel hpread_end_psymtab (pst, psymtab_include_list, includes_used, 2274130803Smarcel hp_symnum * sizeof (struct dntt_type_block), 2275130803Smarcel 0, dependency_list, dependencies_used); 2276130803Smarcel } 2277130803Smarcel 2278130803Smarcel discard_cleanups (old_chain); 2279130803Smarcel} 2280130803Smarcel 2281130803Smarcel/* Perform any local cleanups required when we are done with a particular 2282130803Smarcel objfile. I.E, we are in the process of discarding all symbol information 2283130803Smarcel for an objfile, freeing up all memory held for it, and unlinking the 2284130803Smarcel objfile struct from the global list of known objfiles. */ 2285130803Smarcel 2286130803Smarcelvoid 2287130803Smarcelhpread_symfile_finish (struct objfile *objfile) 2288130803Smarcel{ 2289130803Smarcel if (objfile->sym_private != NULL) 2290130803Smarcel { 2291130803Smarcel xmfree (objfile->md, objfile->sym_private); 2292130803Smarcel } 2293130803Smarcel} 2294130803Smarcel 2295130803Smarcel 2296130803Smarcel/* The remaining functions are all for internal use only. */ 2297130803Smarcel 2298130803Smarcel/* Various small functions to get entries in the debug symbol sections. */ 2299130803Smarcel 2300130803Smarcelstatic union dnttentry * 2301130803Smarcelhpread_get_lntt (int index, struct objfile *objfile) 2302130803Smarcel{ 2303130803Smarcel return (union dnttentry *) 2304130803Smarcel &(LNTT (objfile)[(index * sizeof (struct dntt_type_block))]); 2305130803Smarcel} 2306130803Smarcel 2307130803Smarcelstatic union dnttentry * 2308130803Smarcelhpread_get_gntt (int index, struct objfile *objfile) 2309130803Smarcel{ 2310130803Smarcel return (union dnttentry *) 2311130803Smarcel &(GNTT (objfile)[(index * sizeof (struct dntt_type_block))]); 2312130803Smarcel} 2313130803Smarcel 2314130803Smarcelstatic union sltentry * 2315130803Smarcelhpread_get_slt (int index, struct objfile *objfile) 2316130803Smarcel{ 2317130803Smarcel return (union sltentry *) &(SLT (objfile)[index * sizeof (union sltentry)]); 2318130803Smarcel} 2319130803Smarcel 2320130803Smarcel/* Get the low address associated with some symbol (typically the start 2321130803Smarcel of a particular source file or module). Since that information is not 2322130803Smarcel stored as part of the DNTT_TYPE_MODULE or DNTT_TYPE_SRCFILE symbol we 2323130803Smarcel must infer it from the existence of DNTT_TYPE_FUNCTION symbols. */ 2324130803Smarcel 2325130803Smarcelstatic unsigned long 2326130803Smarcelhpread_get_textlow (int global, int index, struct objfile *objfile, 2327130803Smarcel int symcount) 2328130803Smarcel{ 2329130803Smarcel union dnttentry *dn_bufp = NULL; 2330130803Smarcel struct minimal_symbol *msymbol; 2331130803Smarcel 2332130803Smarcel /* Look for a DNTT_TYPE_FUNCTION symbol. */ 2333130803Smarcel if (index < symcount) /* symcount is the number of symbols in */ 2334130803Smarcel { /* the dbinfo, LNTT table */ 2335130803Smarcel do 2336130803Smarcel { 2337130803Smarcel if (global) 2338130803Smarcel dn_bufp = hpread_get_gntt (index++, objfile); 2339130803Smarcel else 2340130803Smarcel dn_bufp = hpread_get_lntt (index++, objfile); 2341130803Smarcel } 2342130803Smarcel while (dn_bufp->dblock.kind != DNTT_TYPE_FUNCTION 2343130803Smarcel && dn_bufp->dblock.kind != DNTT_TYPE_DOC_FUNCTION 2344130803Smarcel && dn_bufp->dblock.kind != DNTT_TYPE_END 2345130803Smarcel && index < symcount); 2346130803Smarcel } 2347130803Smarcel 2348130803Smarcel /* NOTE: cagney/2003-03-29: If !(index < symcount), dn_bufp is left 2349130803Smarcel undefined and that means that the test below is using a garbage 2350130803Smarcel pointer from the stack. */ 2351130803Smarcel gdb_assert (dn_bufp != NULL); 2352130803Smarcel 2353130803Smarcel /* Avoid going past a DNTT_TYPE_END when looking for a DNTT_TYPE_FUNCTION. This 2354130803Smarcel might happen when a sourcefile has no functions. */ 2355130803Smarcel if (dn_bufp->dblock.kind == DNTT_TYPE_END) 2356130803Smarcel return 0; 2357130803Smarcel 2358130803Smarcel /* Avoid going past the end of the LNTT file */ 2359130803Smarcel if (index == symcount) 2360130803Smarcel return 0; 2361130803Smarcel 2362130803Smarcel /* The minimal symbols are typically more accurate for some reason. */ 2363130803Smarcel if (dn_bufp->dblock.kind == DNTT_TYPE_FUNCTION) 2364130803Smarcel msymbol = lookup_minimal_symbol (dn_bufp->dfunc.name + VT (objfile), NULL, 2365130803Smarcel objfile); 2366130803Smarcel else /* must be a DNTT_TYPE_DOC_FUNCTION */ 2367130803Smarcel msymbol = lookup_minimal_symbol (dn_bufp->ddocfunc.name + VT (objfile), NULL, 2368130803Smarcel objfile); 2369130803Smarcel 2370130803Smarcel if (msymbol) 2371130803Smarcel return SYMBOL_VALUE_ADDRESS (msymbol); 2372130803Smarcel else 2373130803Smarcel return dn_bufp->dfunc.lowaddr; 2374130803Smarcel} 2375130803Smarcel 2376130803Smarcel/* Allocate and partially fill a partial symtab. It will be 2377130803Smarcel completely filled at the end of the symbol list. 2378130803Smarcel 2379130803Smarcel SYMFILE_NAME is the name of the symbol-file we are reading from, and ADDR 2380130803Smarcel is the address relative to which its symbols are (incremental) or 0 2381130803Smarcel (normal). */ 2382130803Smarcel 2383130803Smarcelstatic struct partial_symtab * 2384130803Smarcelhpread_start_psymtab (struct objfile *objfile, char *filename, 2385130803Smarcel CORE_ADDR textlow, int ldsymoff, 2386130803Smarcel struct partial_symbol **global_syms, 2387130803Smarcel struct partial_symbol **static_syms) 2388130803Smarcel{ 2389130803Smarcel int offset = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile)); 2390130803Smarcel extern void hpread_psymtab_to_symtab (); 2391130803Smarcel struct partial_symtab *result = 2392130803Smarcel start_psymtab_common (objfile, objfile->section_offsets, 2393130803Smarcel filename, textlow, global_syms, static_syms); 2394130803Smarcel 2395130803Smarcel result->textlow += offset; 2396130803Smarcel result->read_symtab_private = (char *) 2397130803Smarcel obstack_alloc (&objfile->objfile_obstack, sizeof (struct symloc)); 2398130803Smarcel LDSYMOFF (result) = ldsymoff; 2399130803Smarcel result->read_symtab = hpread_psymtab_to_symtab; 2400130803Smarcel 2401130803Smarcel return result; 2402130803Smarcel} 2403130803Smarcel 2404130803Smarcel 2405130803Smarcel/* Close off the current usage of PST. 2406130803Smarcel Returns PST or NULL if the partial symtab was empty and thrown away. 2407130803Smarcel 2408130803Smarcel capping_symbol_offset --Byte index in LNTT or GNTT of the 2409130803Smarcel last symbol processed during the build 2410130803Smarcel of the previous pst. 2411130803Smarcel 2412130803Smarcel FIXME: List variables and peculiarities of same. */ 2413130803Smarcel 2414130803Smarcelstatic struct partial_symtab * 2415130803Smarcelhpread_end_psymtab (struct partial_symtab *pst, char **include_list, 2416130803Smarcel int num_includes, int capping_symbol_offset, 2417130803Smarcel CORE_ADDR capping_text, 2418130803Smarcel struct partial_symtab **dependency_list, 2419130803Smarcel int number_dependencies) 2420130803Smarcel{ 2421130803Smarcel int i; 2422130803Smarcel struct objfile *objfile = pst->objfile; 2423130803Smarcel int offset = ANOFFSET (pst->section_offsets, SECT_OFF_TEXT (objfile)); 2424130803Smarcel 2425130803Smarcel#ifdef DUMPING 2426130803Smarcel /* Turn on to see what kind of a psymtab we've built. */ 2427130803Smarcel static int dumping = 0; 2428130803Smarcel#endif 2429130803Smarcel 2430130803Smarcel if (capping_symbol_offset != -1) 2431130803Smarcel LDSYMLEN (pst) = capping_symbol_offset - LDSYMOFF (pst); 2432130803Smarcel else 2433130803Smarcel LDSYMLEN (pst) = 0; 2434130803Smarcel pst->texthigh = capping_text + offset; 2435130803Smarcel 2436130803Smarcel pst->n_global_syms = 2437130803Smarcel objfile->global_psymbols.next - (objfile->global_psymbols.list + pst->globals_offset); 2438130803Smarcel pst->n_static_syms = 2439130803Smarcel objfile->static_psymbols.next - (objfile->static_psymbols.list + pst->statics_offset); 2440130803Smarcel 2441130803Smarcel#ifdef DUMPING 2442130803Smarcel if (dumping) 2443130803Smarcel { 2444130803Smarcel printf ("\nPst %s, LDSYMOFF %x (%x), LDSYMLEN %x (%x), globals %d, statics %d\n", 2445130803Smarcel pst->filename, 2446130803Smarcel LDSYMOFF (pst), 2447130803Smarcel LDSYMOFF (pst) / sizeof (struct dntt_type_block), 2448130803Smarcel LDSYMLEN (pst), 2449130803Smarcel LDSYMLEN (pst) / sizeof (struct dntt_type_block), 2450130803Smarcel pst->n_global_syms, pst->n_static_syms); 2451130803Smarcel } 2452130803Smarcel#endif 2453130803Smarcel 2454130803Smarcel pst->number_of_dependencies = number_dependencies; 2455130803Smarcel if (number_dependencies) 2456130803Smarcel { 2457130803Smarcel pst->dependencies = (struct partial_symtab **) 2458130803Smarcel obstack_alloc (&objfile->objfile_obstack, 2459130803Smarcel number_dependencies * sizeof (struct partial_symtab *)); 2460130803Smarcel memcpy (pst->dependencies, dependency_list, 2461130803Smarcel number_dependencies * sizeof (struct partial_symtab *)); 2462130803Smarcel } 2463130803Smarcel else 2464130803Smarcel pst->dependencies = 0; 2465130803Smarcel 2466130803Smarcel for (i = 0; i < num_includes; i++) 2467130803Smarcel { 2468130803Smarcel struct partial_symtab *subpst = 2469130803Smarcel allocate_psymtab (include_list[i], objfile); 2470130803Smarcel 2471130803Smarcel subpst->section_offsets = pst->section_offsets; 2472130803Smarcel subpst->read_symtab_private = 2473130803Smarcel (char *) obstack_alloc (&objfile->objfile_obstack, 2474130803Smarcel sizeof (struct symloc)); 2475130803Smarcel LDSYMOFF (subpst) = 2476130803Smarcel LDSYMLEN (subpst) = 2477130803Smarcel subpst->textlow = 2478130803Smarcel subpst->texthigh = 0; 2479130803Smarcel 2480130803Smarcel /* We could save slight bits of space by only making one of these, 2481130803Smarcel shared by the entire set of include files. FIXME-someday. */ 2482130803Smarcel subpst->dependencies = (struct partial_symtab **) 2483130803Smarcel obstack_alloc (&objfile->objfile_obstack, 2484130803Smarcel sizeof (struct partial_symtab *)); 2485130803Smarcel subpst->dependencies[0] = pst; 2486130803Smarcel subpst->number_of_dependencies = 1; 2487130803Smarcel 2488130803Smarcel subpst->globals_offset = 2489130803Smarcel subpst->n_global_syms = 2490130803Smarcel subpst->statics_offset = 2491130803Smarcel subpst->n_static_syms = 0; 2492130803Smarcel 2493130803Smarcel subpst->readin = 0; 2494130803Smarcel subpst->symtab = 0; 2495130803Smarcel subpst->read_symtab = pst->read_symtab; 2496130803Smarcel } 2497130803Smarcel 2498130803Smarcel sort_pst_symbols (pst); 2499130803Smarcel 2500130803Smarcel /* If there is already a psymtab or symtab for a file of this name, remove it. 2501130803Smarcel (If there is a symtab, more drastic things also happen.) 2502130803Smarcel This happens in VxWorks. */ 2503130803Smarcel free_named_symtabs (pst->filename); 2504130803Smarcel 2505130803Smarcel if (num_includes == 0 2506130803Smarcel && number_dependencies == 0 2507130803Smarcel && pst->n_global_syms == 0 2508130803Smarcel && pst->n_static_syms == 0) 2509130803Smarcel { 2510130803Smarcel /* Throw away this psymtab, it's empty. We can't deallocate it, since 2511130803Smarcel it is on the obstack, but we can forget to chain it on the list. 2512130803Smarcel Empty psymtabs happen as a result of header files which don't have 2513130803Smarcel any symbols in them. There can be a lot of them. But this check 2514130803Smarcel is wrong, in that a psymtab with N_SLINE entries but nothing else 2515130803Smarcel is not empty, but we don't realize that. Fixing that without slowing 2516130803Smarcel things down might be tricky. 2517130803Smarcel It's also wrong if we're using the quick look-up tables, as 2518130803Smarcel we can get empty psymtabs from modules with no routines in 2519130803Smarcel them. */ 2520130803Smarcel 2521130803Smarcel discard_psymtab (pst); 2522130803Smarcel 2523130803Smarcel /* Indicate that psymtab was thrown away. */ 2524130803Smarcel pst = (struct partial_symtab *) NULL; 2525130803Smarcel 2526130803Smarcel } 2527130803Smarcel return pst; 2528130803Smarcel} 2529130803Smarcel 2530130803Smarcel 2531130803Smarcel/* Get the nesting depth for the source line identified by INDEX. */ 2532130803Smarcel 2533130803Smarcelstatic unsigned long 2534130803Smarcelhpread_get_scope_start (sltpointer index, struct objfile *objfile) 2535130803Smarcel{ 2536130803Smarcel union sltentry *sl_bufp; 2537130803Smarcel 2538130803Smarcel sl_bufp = hpread_get_slt (index, objfile); 2539130803Smarcel return sl_bufp->sspec.backptr.dnttp.index; 2540130803Smarcel} 2541130803Smarcel 2542130803Smarcel/* Get the source line number the the line identified by INDEX. */ 2543130803Smarcel 2544130803Smarcelstatic unsigned long 2545130803Smarcelhpread_get_line (sltpointer index, struct objfile *objfile) 2546130803Smarcel{ 2547130803Smarcel union sltentry *sl_bufp; 2548130803Smarcel 2549130803Smarcel sl_bufp = hpread_get_slt (index, objfile); 2550130803Smarcel return sl_bufp->snorm.line; 2551130803Smarcel} 2552130803Smarcel 2553130803Smarcel/* Find the code address associated with a given sltpointer */ 2554130803Smarcel 2555130803Smarcelstatic CORE_ADDR 2556130803Smarcelhpread_get_location (sltpointer index, struct objfile *objfile) 2557130803Smarcel{ 2558130803Smarcel union sltentry *sl_bufp; 2559130803Smarcel int i; 2560130803Smarcel 2561130803Smarcel /* code location of special sltentrys is determined from context */ 2562130803Smarcel sl_bufp = hpread_get_slt (index, objfile); 2563130803Smarcel 2564130803Smarcel if (sl_bufp->snorm.sltdesc == SLT_END) 2565130803Smarcel { 2566130803Smarcel /* find previous normal sltentry and get address */ 2567130803Smarcel for (i = 0; ((sl_bufp->snorm.sltdesc != SLT_NORMAL) && 2568130803Smarcel (sl_bufp->snorm.sltdesc != SLT_NORMAL_OFFSET) && 2569130803Smarcel (sl_bufp->snorm.sltdesc != SLT_EXIT)); i++) 2570130803Smarcel sl_bufp = hpread_get_slt (index - i, objfile); 2571130803Smarcel if (sl_bufp->snorm.sltdesc == SLT_NORMAL_OFFSET) 2572130803Smarcel return sl_bufp->snormoff.address; 2573130803Smarcel else 2574130803Smarcel return sl_bufp->snorm.address; 2575130803Smarcel } 2576130803Smarcel 2577130803Smarcel /* find next normal sltentry and get address */ 2578130803Smarcel for (i = 0; ((sl_bufp->snorm.sltdesc != SLT_NORMAL) && 2579130803Smarcel (sl_bufp->snorm.sltdesc != SLT_NORMAL_OFFSET) && 2580130803Smarcel (sl_bufp->snorm.sltdesc != SLT_EXIT)); i++) 2581130803Smarcel sl_bufp = hpread_get_slt (index + i, objfile); 2582130803Smarcel if (sl_bufp->snorm.sltdesc == SLT_NORMAL_OFFSET) 2583130803Smarcel return sl_bufp->snormoff.address; 2584130803Smarcel else 2585130803Smarcel return sl_bufp->snorm.address; 2586130803Smarcel} 2587130803Smarcel 2588130803Smarcel 2589130803Smarcel/* Return 1 if an HP debug symbol of type KIND has a name associated with 2590130803Smarcel * it, else return 0. (This function is not currently used, but I'll 2591130803Smarcel * leave it here in case it proves useful later on. - RT). 2592130803Smarcel */ 2593130803Smarcel 2594130803Smarcelstatic int 2595130803Smarcelhpread_has_name (enum dntt_entry_type kind) 2596130803Smarcel{ 2597130803Smarcel switch (kind) 2598130803Smarcel { 2599130803Smarcel case DNTT_TYPE_SRCFILE: 2600130803Smarcel case DNTT_TYPE_MODULE: 2601130803Smarcel case DNTT_TYPE_FUNCTION: 2602130803Smarcel case DNTT_TYPE_DOC_FUNCTION: 2603130803Smarcel case DNTT_TYPE_ENTRY: 2604130803Smarcel case DNTT_TYPE_IMPORT: 2605130803Smarcel case DNTT_TYPE_LABEL: 2606130803Smarcel case DNTT_TYPE_FPARAM: 2607130803Smarcel case DNTT_TYPE_SVAR: 2608130803Smarcel case DNTT_TYPE_DVAR: 2609130803Smarcel case DNTT_TYPE_CONST: 2610130803Smarcel case DNTT_TYPE_TYPEDEF: 2611130803Smarcel case DNTT_TYPE_TAGDEF: 2612130803Smarcel case DNTT_TYPE_MEMENUM: 2613130803Smarcel case DNTT_TYPE_FIELD: 2614130803Smarcel case DNTT_TYPE_SA: 2615130803Smarcel case DNTT_TYPE_BLOCKDATA: 2616130803Smarcel case DNTT_TYPE_MEMFUNC: 2617130803Smarcel case DNTT_TYPE_DOC_MEMFUNC: 2618130803Smarcel return 1; 2619130803Smarcel 2620130803Smarcel case DNTT_TYPE_BEGIN: 2621130803Smarcel case DNTT_TYPE_END: 2622130803Smarcel case DNTT_TYPE_POINTER: 2623130803Smarcel case DNTT_TYPE_ENUM: 2624130803Smarcel case DNTT_TYPE_SET: 2625130803Smarcel case DNTT_TYPE_ARRAY: 2626130803Smarcel case DNTT_TYPE_STRUCT: 2627130803Smarcel case DNTT_TYPE_UNION: 2628130803Smarcel case DNTT_TYPE_VARIANT: 2629130803Smarcel case DNTT_TYPE_FILE: 2630130803Smarcel case DNTT_TYPE_FUNCTYPE: 2631130803Smarcel case DNTT_TYPE_SUBRANGE: 2632130803Smarcel case DNTT_TYPE_WITH: 2633130803Smarcel case DNTT_TYPE_COMMON: 2634130803Smarcel case DNTT_TYPE_COBSTRUCT: 2635130803Smarcel case DNTT_TYPE_XREF: 2636130803Smarcel case DNTT_TYPE_MACRO: 2637130803Smarcel case DNTT_TYPE_CLASS_SCOPE: 2638130803Smarcel case DNTT_TYPE_REFERENCE: 2639130803Smarcel case DNTT_TYPE_PTRMEM: 2640130803Smarcel case DNTT_TYPE_PTRMEMFUNC: 2641130803Smarcel case DNTT_TYPE_CLASS: 2642130803Smarcel case DNTT_TYPE_GENFIELD: 2643130803Smarcel case DNTT_TYPE_VFUNC: 2644130803Smarcel case DNTT_TYPE_MEMACCESS: 2645130803Smarcel case DNTT_TYPE_INHERITANCE: 2646130803Smarcel case DNTT_TYPE_FRIEND_CLASS: 2647130803Smarcel case DNTT_TYPE_FRIEND_FUNC: 2648130803Smarcel case DNTT_TYPE_MODIFIER: 2649130803Smarcel case DNTT_TYPE_OBJECT_ID: 2650130803Smarcel case DNTT_TYPE_TEMPLATE: 2651130803Smarcel case DNTT_TYPE_TEMPLATE_ARG: 2652130803Smarcel case DNTT_TYPE_FUNC_TEMPLATE: 2653130803Smarcel case DNTT_TYPE_LINK: 2654130803Smarcel /* DNTT_TYPE_DYN_ARRAY_DESC ? */ 2655130803Smarcel /* DNTT_TYPE_DESC_SUBRANGE ? */ 2656130803Smarcel /* DNTT_TYPE_BEGIN_EXT ? */ 2657130803Smarcel /* DNTT_TYPE_INLN ? */ 2658130803Smarcel /* DNTT_TYPE_INLN_LIST ? */ 2659130803Smarcel /* DNTT_TYPE_ALIAS ? */ 2660130803Smarcel default: 2661130803Smarcel return 0; 2662130803Smarcel } 2663130803Smarcel} 2664130803Smarcel 2665130803Smarcel/* Do the dirty work of reading in the full symbol from a partial symbol 2666130803Smarcel table. */ 2667130803Smarcel 2668130803Smarcelstatic void 2669130803Smarcelhpread_psymtab_to_symtab_1 (struct partial_symtab *pst) 2670130803Smarcel{ 2671130803Smarcel struct cleanup *old_chain; 2672130803Smarcel int i; 2673130803Smarcel 2674130803Smarcel /* Get out quick if passed junk. */ 2675130803Smarcel if (!pst) 2676130803Smarcel return; 2677130803Smarcel 2678130803Smarcel /* Complain if we've already read in this symbol table. */ 2679130803Smarcel if (pst->readin) 2680130803Smarcel { 2681130803Smarcel fprintf_unfiltered (gdb_stderr, "Psymtab for %s already read in." 2682130803Smarcel " Shouldn't happen.\n", 2683130803Smarcel pst->filename); 2684130803Smarcel return; 2685130803Smarcel } 2686130803Smarcel 2687130803Smarcel /* Read in all partial symtabs on which this one is dependent */ 2688130803Smarcel for (i = 0; i < pst->number_of_dependencies; i++) 2689130803Smarcel if (!pst->dependencies[i]->readin) 2690130803Smarcel { 2691130803Smarcel /* Inform about additional files that need to be read in. */ 2692130803Smarcel if (info_verbose) 2693130803Smarcel { 2694130803Smarcel fputs_filtered (" ", gdb_stdout); 2695130803Smarcel wrap_here (""); 2696130803Smarcel fputs_filtered ("and ", gdb_stdout); 2697130803Smarcel wrap_here (""); 2698130803Smarcel printf_filtered ("%s...", pst->dependencies[i]->filename); 2699130803Smarcel wrap_here (""); /* Flush output */ 2700130803Smarcel gdb_flush (gdb_stdout); 2701130803Smarcel } 2702130803Smarcel hpread_psymtab_to_symtab_1 (pst->dependencies[i]); 2703130803Smarcel } 2704130803Smarcel 2705130803Smarcel /* If it's real... */ 2706130803Smarcel if (LDSYMLEN (pst)) 2707130803Smarcel { 2708130803Smarcel /* Init stuff necessary for reading in symbols */ 2709130803Smarcel buildsym_init (); 2710130803Smarcel old_chain = make_cleanup (really_free_pendings, 0); 2711130803Smarcel 2712130803Smarcel pst->symtab = 2713130803Smarcel hpread_expand_symtab (pst->objfile, LDSYMOFF (pst), LDSYMLEN (pst), 2714130803Smarcel pst->textlow, pst->texthigh - pst->textlow, 2715130803Smarcel pst->section_offsets, pst->filename); 2716130803Smarcel 2717130803Smarcel do_cleanups (old_chain); 2718130803Smarcel } 2719130803Smarcel 2720130803Smarcel pst->readin = 1; 2721130803Smarcel} 2722130803Smarcel 2723130803Smarcel/* Read in all of the symbols for a given psymtab for real. 2724130803Smarcel Be verbose about it if the user wants that. */ 2725130803Smarcel 2726130803Smarcelstatic void 2727130803Smarcelhpread_psymtab_to_symtab (struct partial_symtab *pst) 2728130803Smarcel{ 2729130803Smarcel /* Get out quick if given junk. */ 2730130803Smarcel if (!pst) 2731130803Smarcel return; 2732130803Smarcel 2733130803Smarcel /* Sanity check. */ 2734130803Smarcel if (pst->readin) 2735130803Smarcel { 2736130803Smarcel fprintf_unfiltered (gdb_stderr, "Psymtab for %s already read in." 2737130803Smarcel " Shouldn't happen.\n", 2738130803Smarcel pst->filename); 2739130803Smarcel return; 2740130803Smarcel } 2741130803Smarcel 2742130803Smarcel /* elz: setting the flag to indicate that the code of the target 2743130803Smarcel was compiled using an HP compiler (aCC, cc) 2744130803Smarcel the processing_acc_compilation variable is declared in the 2745130803Smarcel file buildsym.h, the HP_COMPILED_TARGET is defined to be equal 2746130803Smarcel to 3 in the file tm_hppa.h */ 2747130803Smarcel 2748130803Smarcel processing_gcc_compilation = 0; 2749130803Smarcel 2750130803Smarcel if (LDSYMLEN (pst) || pst->number_of_dependencies) 2751130803Smarcel { 2752130803Smarcel /* Print the message now, before reading the string table, 2753130803Smarcel to avoid disconcerting pauses. */ 2754130803Smarcel if (info_verbose) 2755130803Smarcel { 2756130803Smarcel printf_filtered ("Reading in symbols for %s...", pst->filename); 2757130803Smarcel gdb_flush (gdb_stdout); 2758130803Smarcel } 2759130803Smarcel 2760130803Smarcel hpread_psymtab_to_symtab_1 (pst); 2761130803Smarcel 2762130803Smarcel /* Match with global symbols. This only needs to be done once, 2763130803Smarcel after all of the symtabs and dependencies have been read in. */ 2764130803Smarcel scan_file_globals (pst->objfile); 2765130803Smarcel 2766130803Smarcel /* Finish up the debug error message. */ 2767130803Smarcel if (info_verbose) 2768130803Smarcel printf_filtered ("done.\n"); 2769130803Smarcel } 2770130803Smarcel} 2771130803Smarcel 2772130803Smarcel/* Read in a defined section of a specific object file's symbols. 2773130803Smarcel 2774130803Smarcel DESC is the file descriptor for the file, positioned at the 2775130803Smarcel beginning of the symtab 2776130803Smarcel SYM_OFFSET is the offset within the file of 2777130803Smarcel the beginning of the symbols we want to read 2778130803Smarcel SYM_SIZE is the size of the symbol info to read in. 2779130803Smarcel TEXT_OFFSET is the beginning of the text segment we are reading symbols for 2780130803Smarcel TEXT_SIZE is the size of the text segment read in. 2781130803Smarcel SECTION_OFFSETS are the relocation offsets which get added to each symbol. */ 2782130803Smarcel 2783130803Smarcelstatic struct symtab * 2784130803Smarcelhpread_expand_symtab (struct objfile *objfile, int sym_offset, int sym_size, 2785130803Smarcel CORE_ADDR text_offset, int text_size, 2786130803Smarcel struct section_offsets *section_offsets, char *filename) 2787130803Smarcel{ 2788130803Smarcel char *namestring; 2789130803Smarcel union dnttentry *dn_bufp; 2790130803Smarcel unsigned max_symnum; 2791130803Smarcel int at_module_boundary = 0; 2792130803Smarcel /* 1 => at end, -1 => at beginning */ 2793130803Smarcel 2794130803Smarcel int sym_index = sym_offset / sizeof (struct dntt_type_block); 2795130803Smarcel 2796130803Smarcel current_objfile = objfile; 2797130803Smarcel subfile_stack = 0; 2798130803Smarcel 2799130803Smarcel last_source_file = 0; 2800130803Smarcel 2801130803Smarcel /* Demangling style -- if EDG style already set, don't change it, 2802130803Smarcel as HP style causes some problems with the KAI EDG compiler */ 2803130803Smarcel if (current_demangling_style != edg_demangling) 2804130803Smarcel { 2805130803Smarcel /* Otherwise, ensure that we are using HP style demangling */ 2806130803Smarcel set_demangling_style (HP_DEMANGLING_STYLE_STRING); 2807130803Smarcel } 2808130803Smarcel 2809130803Smarcel dn_bufp = hpread_get_lntt (sym_index, objfile); 2810130803Smarcel if (!((dn_bufp->dblock.kind == (unsigned char) DNTT_TYPE_SRCFILE) || 2811130803Smarcel (dn_bufp->dblock.kind == (unsigned char) DNTT_TYPE_MODULE))) 2812130803Smarcel { 2813130803Smarcel start_symtab ("globals", NULL, 0); 2814130803Smarcel record_debugformat ("HP"); 2815130803Smarcel } 2816130803Smarcel 2817130803Smarcel /* The psymtab builder (hp-psymtab-read.c) is the one that 2818130803Smarcel * determined the "sym_size" argument (i.e. how many DNTT symbols 2819130803Smarcel * are in this symtab), which we use to compute "max_symnum" 2820130803Smarcel * (point in DNTT to which we read). 2821130803Smarcel * 2822130803Smarcel * Perhaps this should be changed so that 2823130803Smarcel * process_one_debug_symbol() "knows" when 2824130803Smarcel * to stop reading (based on reading from the MODULE to the matching 2825130803Smarcel * END), and take out this reliance on a #-syms being passed in... 2826130803Smarcel * (I'm worried about the reliability of this number). But I'll 2827130803Smarcel * leave it as-is, for now. - RT 2828130803Smarcel * 2829130803Smarcel * The change above has been made. I've left the "for" loop control 2830130803Smarcel * in to prepare for backing this out again. -JB 2831130803Smarcel */ 2832130803Smarcel max_symnum = sym_size / sizeof (struct dntt_type_block); 2833130803Smarcel /* No reason to multiply on pst side and divide on sym side... FIXME */ 2834130803Smarcel 2835130803Smarcel /* Read in and process each debug symbol within the specified range. 2836130803Smarcel */ 2837130803Smarcel for (symnum = 0; 2838130803Smarcel symnum < max_symnum; 2839130803Smarcel symnum++) 2840130803Smarcel { 2841130803Smarcel QUIT; /* Allow this to be interruptable */ 2842130803Smarcel dn_bufp = hpread_get_lntt (sym_index + symnum, objfile); 2843130803Smarcel 2844130803Smarcel if (dn_bufp->dblock.extension) 2845130803Smarcel continue; 2846130803Smarcel 2847130803Smarcel /* Yow! We call set_namestring on things without names! */ 2848130803Smarcel set_namestring (dn_bufp, &namestring, objfile); 2849130803Smarcel 2850130803Smarcel hpread_process_one_debug_symbol (dn_bufp, namestring, section_offsets, 2851130803Smarcel objfile, text_offset, text_size, 2852130803Smarcel filename, symnum + sym_index, 2853130803Smarcel &at_module_boundary 2854130803Smarcel ); 2855130803Smarcel 2856130803Smarcel /* OLD COMMENTS: This routine is only called for psts. All psts 2857130803Smarcel * correspond to MODULES. If we ever do lazy-reading of globals 2858130803Smarcel * from the LNTT, then there will be a pst which ends when the 2859130803Smarcel * LNTT ends, and not at an END MODULE entry. Then we'll have 2860130803Smarcel * to re-visit this break. 2861130803Smarcel 2862130803Smarcel if( at_end_of_module ) 2863130803Smarcel break; 2864130803Smarcel 2865130803Smarcel */ 2866130803Smarcel 2867130803Smarcel /* We no longer break out of the loop when we reach the end of a 2868130803Smarcel module. The reason is that with CTTI, the compiler can generate 2869130803Smarcel function symbols (for template function instantiations) which are not 2870130803Smarcel in any module; typically they show up beyond a module's end, and 2871130803Smarcel before the next module's start. We include them in the current 2872130803Smarcel module. However, we still don't trust the MAX_SYMNUM value from 2873130803Smarcel the psymtab, so we break out if we enter a new module. */ 2874130803Smarcel 2875130803Smarcel if (at_module_boundary == -1) 2876130803Smarcel break; 2877130803Smarcel } 2878130803Smarcel 2879130803Smarcel current_objfile = NULL; 2880130803Smarcel hp_som_som_object_present = 1; /* Indicate we've processed an HP SOM SOM file */ 2881130803Smarcel 2882130803Smarcel return end_symtab (text_offset + text_size, objfile, SECT_OFF_TEXT (objfile)); 2883130803Smarcel} 2884130803Smarcel 2885130803Smarcel 2886130803Smarcel 2887130803Smarcel 2888130803Smarcel/* Convert basic types from HP debug format into GDB internal format. */ 2889130803Smarcel 2890130803Smarcelstatic int 2891130803Smarcelhpread_type_translate (dnttpointer typep) 2892130803Smarcel{ 2893130803Smarcel if (!typep.dntti.immediate) 2894130803Smarcel { 2895130803Smarcel error ("error in hpread_type_translate\n."); 2896130803Smarcel return FT_VOID; 2897130803Smarcel } 2898130803Smarcel 2899130803Smarcel switch (typep.dntti.type) 2900130803Smarcel { 2901130803Smarcel case HP_TYPE_BOOLEAN: 2902130803Smarcel case HP_TYPE_BOOLEAN_S300_COMPAT: 2903130803Smarcel case HP_TYPE_BOOLEAN_VAX_COMPAT: 2904130803Smarcel return FT_BOOLEAN; 2905130803Smarcel case HP_TYPE_CHAR: /* C signed char, C++ plain char */ 2906130803Smarcel 2907130803Smarcel case HP_TYPE_WIDE_CHAR: 2908130803Smarcel return FT_CHAR; 2909130803Smarcel case HP_TYPE_INT: 2910130803Smarcel if (typep.dntti.bitlength <= 8) 2911130803Smarcel return FT_SIGNED_CHAR; /* C++ signed char */ 2912130803Smarcel if (typep.dntti.bitlength <= 16) 2913130803Smarcel return FT_SHORT; 2914130803Smarcel if (typep.dntti.bitlength <= 32) 2915130803Smarcel return FT_INTEGER; 2916130803Smarcel return FT_LONG_LONG; 2917130803Smarcel case HP_TYPE_LONG: 2918130803Smarcel if (typep.dntti.bitlength <= 8) 2919130803Smarcel return FT_SIGNED_CHAR; /* C++ signed char. */ 2920130803Smarcel return FT_LONG; 2921130803Smarcel case HP_TYPE_UNSIGNED_LONG: 2922130803Smarcel if (typep.dntti.bitlength <= 8) 2923130803Smarcel return FT_UNSIGNED_CHAR; /* C/C++ unsigned char */ 2924130803Smarcel if (typep.dntti.bitlength <= 16) 2925130803Smarcel return FT_UNSIGNED_SHORT; 2926130803Smarcel if (typep.dntti.bitlength <= 32) 2927130803Smarcel return FT_UNSIGNED_LONG; 2928130803Smarcel return FT_UNSIGNED_LONG_LONG; 2929130803Smarcel case HP_TYPE_UNSIGNED_INT: 2930130803Smarcel if (typep.dntti.bitlength <= 8) 2931130803Smarcel return FT_UNSIGNED_CHAR; 2932130803Smarcel if (typep.dntti.bitlength <= 16) 2933130803Smarcel return FT_UNSIGNED_SHORT; 2934130803Smarcel if (typep.dntti.bitlength <= 32) 2935130803Smarcel return FT_UNSIGNED_INTEGER; 2936130803Smarcel return FT_UNSIGNED_LONG_LONG; 2937130803Smarcel case HP_TYPE_REAL: 2938130803Smarcel case HP_TYPE_REAL_3000: 2939130803Smarcel case HP_TYPE_DOUBLE: 2940130803Smarcel if (typep.dntti.bitlength == 64) 2941130803Smarcel return FT_DBL_PREC_FLOAT; 2942130803Smarcel if (typep.dntti.bitlength == 128) 2943130803Smarcel return FT_EXT_PREC_FLOAT; 2944130803Smarcel return FT_FLOAT; 2945130803Smarcel case HP_TYPE_COMPLEX: 2946130803Smarcel case HP_TYPE_COMPLEXS3000: 2947130803Smarcel if (typep.dntti.bitlength == 128) 2948130803Smarcel return FT_DBL_PREC_COMPLEX; 2949130803Smarcel if (typep.dntti.bitlength == 192) 2950130803Smarcel return FT_EXT_PREC_COMPLEX; 2951130803Smarcel return FT_COMPLEX; 2952130803Smarcel case HP_TYPE_VOID: 2953130803Smarcel return FT_VOID; 2954130803Smarcel case HP_TYPE_STRING200: 2955130803Smarcel case HP_TYPE_LONGSTRING200: 2956130803Smarcel case HP_TYPE_FTN_STRING_SPEC: 2957130803Smarcel case HP_TYPE_MOD_STRING_SPEC: 2958130803Smarcel case HP_TYPE_MOD_STRING_3000: 2959130803Smarcel case HP_TYPE_FTN_STRING_S300_COMPAT: 2960130803Smarcel case HP_TYPE_FTN_STRING_VAX_COMPAT: 2961130803Smarcel return FT_STRING; 2962130803Smarcel case HP_TYPE_TEMPLATE_ARG: 2963130803Smarcel return FT_TEMPLATE_ARG; 2964130803Smarcel case HP_TYPE_TEXT: 2965130803Smarcel case HP_TYPE_FLABEL: 2966130803Smarcel case HP_TYPE_PACKED_DECIMAL: 2967130803Smarcel case HP_TYPE_ANYPOINTER: 2968130803Smarcel case HP_TYPE_GLOBAL_ANYPOINTER: 2969130803Smarcel case HP_TYPE_LOCAL_ANYPOINTER: 2970130803Smarcel default: 2971130803Smarcel warning ("hpread_type_translate: unhandled type code.\n"); 2972130803Smarcel return FT_VOID; 2973130803Smarcel } 2974130803Smarcel} 2975130803Smarcel 2976130803Smarcel/* Given a position in the DNTT, return a pointer to the 2977130803Smarcel * already-built "struct type" (if any), for the type defined 2978130803Smarcel * at that position. 2979130803Smarcel */ 2980130803Smarcel 2981130803Smarcelstatic struct type ** 2982130803Smarcelhpread_lookup_type (dnttpointer hp_type, struct objfile *objfile) 2983130803Smarcel{ 2984130803Smarcel unsigned old_len; 2985130803Smarcel int index = hp_type.dnttp.index; 2986130803Smarcel int size_changed = 0; 2987130803Smarcel 2988130803Smarcel /* The immediate flag indicates this doesn't actually point to 2989130803Smarcel * a type DNTT. 2990130803Smarcel */ 2991130803Smarcel if (hp_type.dntti.immediate) 2992130803Smarcel return NULL; 2993130803Smarcel 2994130803Smarcel /* For each objfile, we maintain a "type vector". 2995130803Smarcel * This an array of "struct type *"'s with one pointer per DNTT index. 2996130803Smarcel * Given a DNTT index, we look in this array to see if we have 2997130803Smarcel * already processed this DNTT and if it is a type definition. 2998130803Smarcel * If so, then we can locate a pointer to the already-built 2999130803Smarcel * "struct type", and not build it again. 3000130803Smarcel * 3001130803Smarcel * The need for this arises because our DNTT-walking code wanders 3002130803Smarcel * around. In particular, it will encounter the same type multiple 3003130803Smarcel * times (once for each object of that type). We don't want to 3004130803Smarcel * built multiple "struct type"'s for the same thing. 3005130803Smarcel * 3006130803Smarcel * Having said this, I should point out that this type-vector is 3007130803Smarcel * an expensive way to keep track of this. If most DNTT entries are 3008130803Smarcel * 3 words, the type-vector will be 1/3 the size of the DNTT itself. 3009130803Smarcel * Alternative solutions: 3010130803Smarcel * - Keep a compressed or hashed table. Less memory, but more expensive 3011130803Smarcel * to search and update. 3012130803Smarcel * - (Suggested by JB): Overwrite the DNTT entry itself 3013130803Smarcel * with the info. Create a new type code "ALREADY_BUILT", and modify 3014130803Smarcel * the DNTT to have that type code and point to the already-built entry. 3015130803Smarcel * -RT 3016130803Smarcel */ 3017130803Smarcel 3018130803Smarcel if (index < LNTT_SYMCOUNT (objfile)) 3019130803Smarcel { 3020130803Smarcel if (index >= DNTT_TYPE_VECTOR_LENGTH (objfile)) 3021130803Smarcel { 3022130803Smarcel old_len = DNTT_TYPE_VECTOR_LENGTH (objfile); 3023130803Smarcel 3024130803Smarcel /* See if we need to allocate a type-vector. */ 3025130803Smarcel if (old_len == 0) 3026130803Smarcel { 3027130803Smarcel DNTT_TYPE_VECTOR_LENGTH (objfile) = LNTT_SYMCOUNT (objfile) + GNTT_SYMCOUNT (objfile); 3028130803Smarcel DNTT_TYPE_VECTOR (objfile) = (struct type **) 3029130803Smarcel xmmalloc (objfile->md, DNTT_TYPE_VECTOR_LENGTH (objfile) * sizeof (struct type *)); 3030130803Smarcel memset (&DNTT_TYPE_VECTOR (objfile)[old_len], 0, 3031130803Smarcel (DNTT_TYPE_VECTOR_LENGTH (objfile) - old_len) * 3032130803Smarcel sizeof (struct type *)); 3033130803Smarcel } 3034130803Smarcel 3035130803Smarcel /* See if we need to resize type-vector. With my change to 3036130803Smarcel * initially allocate a correct-size type-vector, this code 3037130803Smarcel * should no longer trigger. 3038130803Smarcel */ 3039130803Smarcel while (index >= DNTT_TYPE_VECTOR_LENGTH (objfile)) 3040130803Smarcel { 3041130803Smarcel DNTT_TYPE_VECTOR_LENGTH (objfile) *= 2; 3042130803Smarcel size_changed = 1; 3043130803Smarcel } 3044130803Smarcel if (size_changed) 3045130803Smarcel { 3046130803Smarcel DNTT_TYPE_VECTOR (objfile) = (struct type **) 3047130803Smarcel xmrealloc (objfile->md, 3048130803Smarcel (char *) DNTT_TYPE_VECTOR (objfile), 3049130803Smarcel (DNTT_TYPE_VECTOR_LENGTH (objfile) * sizeof (struct type *))); 3050130803Smarcel 3051130803Smarcel memset (&DNTT_TYPE_VECTOR (objfile)[old_len], 0, 3052130803Smarcel (DNTT_TYPE_VECTOR_LENGTH (objfile) - old_len) * 3053130803Smarcel sizeof (struct type *)); 3054130803Smarcel } 3055130803Smarcel 3056130803Smarcel } 3057130803Smarcel return &DNTT_TYPE_VECTOR (objfile)[index]; 3058130803Smarcel } 3059130803Smarcel else 3060130803Smarcel return NULL; 3061130803Smarcel} 3062130803Smarcel 3063130803Smarcel/* Possibly allocate a GDB internal type so we can internalize HP_TYPE. 3064130803Smarcel Note we'll just return the address of a GDB internal type if we already 3065130803Smarcel have it lying around. */ 3066130803Smarcel 3067130803Smarcelstatic struct type * 3068130803Smarcelhpread_alloc_type (dnttpointer hp_type, struct objfile *objfile) 3069130803Smarcel{ 3070130803Smarcel struct type **type_addr; 3071130803Smarcel 3072130803Smarcel type_addr = hpread_lookup_type (hp_type, objfile); 3073130803Smarcel if (*type_addr == 0) 3074130803Smarcel { 3075130803Smarcel *type_addr = alloc_type (objfile); 3076130803Smarcel 3077130803Smarcel /* A hack - if we really are a C++ class symbol, then this default 3078130803Smarcel * will get overriden later on. 3079130803Smarcel */ 3080130803Smarcel TYPE_CPLUS_SPECIFIC (*type_addr) 3081130803Smarcel = (struct cplus_struct_type *) &cplus_struct_default; 3082130803Smarcel } 3083130803Smarcel 3084130803Smarcel return *type_addr; 3085130803Smarcel} 3086130803Smarcel 3087130803Smarcel/* Read a native enumerated type and return it in GDB internal form. */ 3088130803Smarcel 3089130803Smarcelstatic struct type * 3090130803Smarcelhpread_read_enum_type (dnttpointer hp_type, union dnttentry *dn_bufp, 3091130803Smarcel struct objfile *objfile) 3092130803Smarcel{ 3093130803Smarcel struct type *type; 3094130803Smarcel struct pending **symlist, *osyms, *syms; 3095130803Smarcel struct pending *local_list = NULL; 3096130803Smarcel int o_nsyms, nsyms = 0; 3097130803Smarcel dnttpointer mem; 3098130803Smarcel union dnttentry *memp; 3099130803Smarcel char *name; 3100130803Smarcel long n; 3101130803Smarcel struct symbol *sym; 3102130803Smarcel 3103130803Smarcel /* Allocate a GDB type. If we've already read in this enum type, 3104130803Smarcel * it'll return the already built GDB type, so stop here. 3105130803Smarcel * (Note: I added this check, to conform with what's done for 3106130803Smarcel * struct, union, class. 3107130803Smarcel * I assume this is OK. - RT) 3108130803Smarcel */ 3109130803Smarcel type = hpread_alloc_type (hp_type, objfile); 3110130803Smarcel if (TYPE_CODE (type) == TYPE_CODE_ENUM) 3111130803Smarcel return type; 3112130803Smarcel 3113130803Smarcel /* HP C supports "sized enums", where a specifier such as "short" or 3114130803Smarcel "char" can be used to get enums of different sizes. So don't assume 3115130803Smarcel an enum is always 4 bytes long. pai/1997-08-21 */ 3116130803Smarcel TYPE_LENGTH (type) = dn_bufp->denum.bitlength / 8; 3117130803Smarcel 3118130803Smarcel symlist = &file_symbols; 3119130803Smarcel osyms = *symlist; 3120130803Smarcel o_nsyms = osyms ? osyms->nsyms : 0; 3121130803Smarcel 3122130803Smarcel /* Get a name for each member and add it to our list of members. 3123130803Smarcel * The list of "mem" SOM records we are walking should all be 3124130803Smarcel * SOM type DNTT_TYPE_MEMENUM (not checked). 3125130803Smarcel */ 3126130803Smarcel mem = dn_bufp->denum.firstmem; 3127130803Smarcel while (mem.word && mem.word != DNTTNIL) 3128130803Smarcel { 3129130803Smarcel memp = hpread_get_lntt (mem.dnttp.index, objfile); 3130130803Smarcel 3131130803Smarcel name = VT (objfile) + memp->dmember.name; 3132130803Smarcel sym = (struct symbol *) obstack_alloc (&objfile->objfile_obstack, 3133130803Smarcel sizeof (struct symbol)); 3134130803Smarcel memset (sym, 0, sizeof (struct symbol)); 3135130803Smarcel DEPRECATED_SYMBOL_NAME (sym) = obsavestring (name, strlen (name), 3136130803Smarcel &objfile->objfile_obstack); 3137130803Smarcel SYMBOL_CLASS (sym) = LOC_CONST; 3138130803Smarcel SYMBOL_DOMAIN (sym) = VAR_DOMAIN; 3139130803Smarcel SYMBOL_VALUE (sym) = memp->dmember.value; 3140130803Smarcel add_symbol_to_list (sym, symlist); 3141130803Smarcel nsyms++; 3142130803Smarcel mem = memp->dmember.nextmem; 3143130803Smarcel } 3144130803Smarcel 3145130803Smarcel /* Now that we know more about the enum, fill in more info. */ 3146130803Smarcel TYPE_CODE (type) = TYPE_CODE_ENUM; 3147130803Smarcel TYPE_FLAGS (type) &= ~TYPE_FLAG_STUB; 3148130803Smarcel TYPE_NFIELDS (type) = nsyms; 3149130803Smarcel TYPE_FIELDS (type) = (struct field *) 3150130803Smarcel obstack_alloc (&objfile->objfile_obstack, sizeof (struct field) * nsyms); 3151130803Smarcel 3152130803Smarcel /* Find the symbols for the members and put them into the type. 3153130803Smarcel The symbols can be found in the symlist that we put them on 3154130803Smarcel to cause them to be defined. osyms contains the old value 3155130803Smarcel of that symlist; everything up to there was defined by us. 3156130803Smarcel 3157130803Smarcel Note that we preserve the order of the enum constants, so 3158130803Smarcel that in something like "enum {FOO, LAST_THING=FOO}" we print 3159130803Smarcel FOO, not LAST_THING. */ 3160130803Smarcel for (syms = *symlist, n = 0; syms; syms = syms->next) 3161130803Smarcel { 3162130803Smarcel int j = 0; 3163130803Smarcel if (syms == osyms) 3164130803Smarcel j = o_nsyms; 3165130803Smarcel for (; j < syms->nsyms; j++, n++) 3166130803Smarcel { 3167130803Smarcel struct symbol *xsym = syms->symbol[j]; 3168130803Smarcel SYMBOL_TYPE (xsym) = type; 3169130803Smarcel TYPE_FIELD_NAME (type, n) = DEPRECATED_SYMBOL_NAME (xsym); 3170130803Smarcel TYPE_FIELD_BITPOS (type, n) = SYMBOL_VALUE (xsym); 3171130803Smarcel TYPE_FIELD_BITSIZE (type, n) = 0; 3172130803Smarcel TYPE_FIELD_STATIC_KIND (type, n) = 0; 3173130803Smarcel } 3174130803Smarcel if (syms == osyms) 3175130803Smarcel break; 3176130803Smarcel } 3177130803Smarcel 3178130803Smarcel return type; 3179130803Smarcel} 3180130803Smarcel 3181130803Smarcel/* Read and internalize a native function debug symbol. */ 3182130803Smarcel 3183130803Smarcelstatic struct type * 3184130803Smarcelhpread_read_function_type (dnttpointer hp_type, union dnttentry *dn_bufp, 3185130803Smarcel struct objfile *objfile, int newblock) 3186130803Smarcel{ 3187130803Smarcel struct type *type, *type1; 3188130803Smarcel struct pending *syms; 3189130803Smarcel struct pending *local_list = NULL; 3190130803Smarcel int nsyms = 0; 3191130803Smarcel dnttpointer param; 3192130803Smarcel union dnttentry *paramp; 3193130803Smarcel char *name; 3194130803Smarcel long n; 3195130803Smarcel struct symbol *sym; 3196130803Smarcel int record_args = 1; 3197130803Smarcel 3198130803Smarcel /* See if we've already read in this type. */ 3199130803Smarcel type = hpread_alloc_type (hp_type, objfile); 3200130803Smarcel if (TYPE_CODE (type) == TYPE_CODE_FUNC) 3201130803Smarcel { 3202130803Smarcel record_args = 0; /* already read in, don't modify type */ 3203130803Smarcel } 3204130803Smarcel else 3205130803Smarcel { 3206130803Smarcel /* Nope, so read it in and store it away. */ 3207130803Smarcel if (dn_bufp->dblock.kind == DNTT_TYPE_FUNCTION || 3208130803Smarcel dn_bufp->dblock.kind == DNTT_TYPE_MEMFUNC) 3209130803Smarcel type1 = lookup_function_type (hpread_type_lookup (dn_bufp->dfunc.retval, 3210130803Smarcel objfile)); 3211130803Smarcel else if (dn_bufp->dblock.kind == DNTT_TYPE_FUNCTYPE) 3212130803Smarcel type1 = lookup_function_type (hpread_type_lookup (dn_bufp->dfunctype.retval, 3213130803Smarcel objfile)); 3214130803Smarcel else /* expect DNTT_TYPE_FUNC_TEMPLATE */ 3215130803Smarcel type1 = lookup_function_type (hpread_type_lookup (dn_bufp->dfunc_template.retval, 3216130803Smarcel objfile)); 3217130803Smarcel replace_type (type, type1); 3218130803Smarcel 3219130803Smarcel /* Mark it -- in the middle of processing */ 3220130803Smarcel TYPE_FLAGS (type) |= TYPE_FLAG_INCOMPLETE; 3221130803Smarcel } 3222130803Smarcel 3223130803Smarcel /* Now examine each parameter noting its type, location, and a 3224130803Smarcel wealth of other information. */ 3225130803Smarcel if (dn_bufp->dblock.kind == DNTT_TYPE_FUNCTION || 3226130803Smarcel dn_bufp->dblock.kind == DNTT_TYPE_MEMFUNC) 3227130803Smarcel param = dn_bufp->dfunc.firstparam; 3228130803Smarcel else if (dn_bufp->dblock.kind == DNTT_TYPE_FUNCTYPE) 3229130803Smarcel param = dn_bufp->dfunctype.firstparam; 3230130803Smarcel else /* expect DNTT_TYPE_FUNC_TEMPLATE */ 3231130803Smarcel param = dn_bufp->dfunc_template.firstparam; 3232130803Smarcel while (param.word && param.word != DNTTNIL) 3233130803Smarcel { 3234130803Smarcel paramp = hpread_get_lntt (param.dnttp.index, objfile); 3235130803Smarcel nsyms++; 3236130803Smarcel param = paramp->dfparam.nextparam; 3237130803Smarcel 3238130803Smarcel /* Get the name. */ 3239130803Smarcel name = VT (objfile) + paramp->dfparam.name; 3240130803Smarcel sym = (struct symbol *) obstack_alloc (&objfile->objfile_obstack, 3241130803Smarcel sizeof (struct symbol)); 3242130803Smarcel (void) memset (sym, 0, sizeof (struct symbol)); 3243130803Smarcel DEPRECATED_SYMBOL_NAME (sym) = obsavestring (name, strlen (name), 3244130803Smarcel &objfile->objfile_obstack); 3245130803Smarcel 3246130803Smarcel /* Figure out where it lives. */ 3247130803Smarcel if (paramp->dfparam.regparam) 3248130803Smarcel SYMBOL_CLASS (sym) = LOC_REGPARM; 3249130803Smarcel else if (paramp->dfparam.indirect) 3250130803Smarcel SYMBOL_CLASS (sym) = LOC_REF_ARG; 3251130803Smarcel else 3252130803Smarcel SYMBOL_CLASS (sym) = LOC_ARG; 3253130803Smarcel SYMBOL_DOMAIN (sym) = VAR_DOMAIN; 3254130803Smarcel if (paramp->dfparam.copyparam) 3255130803Smarcel { 3256130803Smarcel SYMBOL_VALUE (sym) = paramp->dfparam.location; 3257130803Smarcel#ifdef HPREAD_ADJUST_STACK_ADDRESS 3258130803Smarcel SYMBOL_VALUE (sym) 3259130803Smarcel += HPREAD_ADJUST_STACK_ADDRESS (CURRENT_FUNCTION_VALUE (objfile)); 3260130803Smarcel#endif 3261130803Smarcel /* This is likely a pass-by-invisible reference parameter, 3262130803Smarcel Hack on the symbol class to make GDB happy. */ 3263130803Smarcel /* ??rehrauer: This appears to be broken w/r/t to passing 3264130803Smarcel C values of type float and struct. Perhaps this ought 3265130803Smarcel to be highighted as a special case, but for now, just 3266130803Smarcel allowing these to be LOC_ARGs seems to work fine. 3267130803Smarcel */ 3268130803Smarcel#if 0 3269130803Smarcel SYMBOL_CLASS (sym) = LOC_REGPARM_ADDR; 3270130803Smarcel#endif 3271130803Smarcel } 3272130803Smarcel else 3273130803Smarcel SYMBOL_VALUE (sym) = paramp->dfparam.location; 3274130803Smarcel 3275130803Smarcel /* Get its type. */ 3276130803Smarcel SYMBOL_TYPE (sym) = hpread_type_lookup (paramp->dfparam.type, objfile); 3277130803Smarcel /* Add it to the symbol list. */ 3278130803Smarcel /* Note 1 (RT) At the moment, add_symbol_to_list() is also being 3279130803Smarcel * called on FPARAM symbols from the process_one_debug_symbol() 3280130803Smarcel * level... so parameters are getting added twice! (this shows 3281130803Smarcel * up in the symbol dump you get from "maint print symbols ..."). 3282130803Smarcel * Note 2 (RT) I took out the processing of FPARAM from the 3283130803Smarcel * process_one_debug_symbol() level, so at the moment parameters are only 3284130803Smarcel * being processed here. This seems to have no ill effect. 3285130803Smarcel */ 3286130803Smarcel /* Note 3 (pai/1997-08-11) I removed the add_symbol_to_list() which put 3287130803Smarcel each fparam on the local_symbols list from here. Now we use the 3288130803Smarcel local_list to which fparams are added below, and set the param_symbols 3289130803Smarcel global to point to that at the end of this routine. */ 3290130803Smarcel /* elz: I added this new list of symbols which is local to the function. 3291130803Smarcel this list is the one which is actually used to build the type for the 3292130803Smarcel function rather than the gloabal list pointed to by symlist. 3293130803Smarcel Using a global list to keep track of the parameters is wrong, because 3294130803Smarcel this function is called recursively if one parameter happend to be 3295130803Smarcel a function itself with more parameters in it. Adding parameters to the 3296130803Smarcel same global symbol list would not work! 3297130803Smarcel Actually it did work in case of cc compiled programs where you do 3298130803Smarcel not check the parameter lists of the arguments. */ 3299130803Smarcel add_symbol_to_list (sym, &local_list); 3300130803Smarcel 3301130803Smarcel } 3302130803Smarcel 3303130803Smarcel /* If type was read in earlier, don't bother with modifying 3304130803Smarcel the type struct */ 3305130803Smarcel if (!record_args) 3306130803Smarcel goto finish; 3307130803Smarcel 3308130803Smarcel /* Note how many parameters we found. */ 3309130803Smarcel TYPE_NFIELDS (type) = nsyms; 3310130803Smarcel TYPE_FIELDS (type) = (struct field *) 3311130803Smarcel obstack_alloc (&objfile->objfile_obstack, 3312130803Smarcel sizeof (struct field) * nsyms); 3313130803Smarcel 3314130803Smarcel /* Find the symbols for the parameters and 3315130803Smarcel use them to fill parameter-type information into the function-type. 3316130803Smarcel The parameter symbols can be found in the local_list that we just put them on. */ 3317130803Smarcel /* Note that we preserve the order of the parameters, so 3318130803Smarcel that in something like "enum {FOO, LAST_THING=FOO}" we print 3319130803Smarcel FOO, not LAST_THING. */ 3320130803Smarcel 3321130803Smarcel /* get the parameters types from the local list not the global list 3322130803Smarcel so that the type can be correctly constructed for functions which 3323130803Smarcel have function as parameters */ 3324130803Smarcel for (syms = local_list, n = 0; syms; syms = syms->next) 3325130803Smarcel { 3326130803Smarcel int j = 0; 3327130803Smarcel for (j = 0; j < syms->nsyms; j++, n++) 3328130803Smarcel { 3329130803Smarcel struct symbol *xsym = syms->symbol[j]; 3330130803Smarcel TYPE_FIELD_NAME (type, n) = DEPRECATED_SYMBOL_NAME (xsym); 3331130803Smarcel TYPE_FIELD_TYPE (type, n) = SYMBOL_TYPE (xsym); 3332130803Smarcel TYPE_FIELD_ARTIFICIAL (type, n) = 0; 3333130803Smarcel TYPE_FIELD_BITSIZE (type, n) = 0; 3334130803Smarcel TYPE_FIELD_STATIC_KIND (type, n) = 0; 3335130803Smarcel } 3336130803Smarcel } 3337130803Smarcel /* Mark it as having been processed */ 3338130803Smarcel TYPE_FLAGS (type) &= ~(TYPE_FLAG_INCOMPLETE); 3339130803Smarcel 3340130803Smarcel /* Check whether we need to fix-up a class type with this function's type */ 3341130803Smarcel if (fixup_class && (fixup_method == type)) 3342130803Smarcel { 3343130803Smarcel fixup_class_method_type (fixup_class, fixup_method, objfile); 3344130803Smarcel fixup_class = NULL; 3345130803Smarcel fixup_method = NULL; 3346130803Smarcel } 3347130803Smarcel 3348130803Smarcel /* Set the param list of this level of the context stack 3349130803Smarcel to our local list. Do this only if this function was 3350130803Smarcel called for creating a new block, and not if it was called 3351130803Smarcel simply to get the function type. This prevents recursive 3352130803Smarcel invocations from trashing param_symbols. */ 3353130803Smarcelfinish: 3354130803Smarcel if (newblock) 3355130803Smarcel param_symbols = local_list; 3356130803Smarcel 3357130803Smarcel return type; 3358130803Smarcel} 3359130803Smarcel 3360130803Smarcel 3361130803Smarcel/* Read and internalize a native DOC function debug symbol. */ 3362130803Smarcel/* This is almost identical to hpread_read_function_type(), except 3363130803Smarcel * for references to dn_bufp->ddocfunc instead of db_bufp->dfunc. 3364130803Smarcel * Since debug information for DOC functions is more likely to be 3365130803Smarcel * volatile, please leave it this way. 3366130803Smarcel */ 3367130803Smarcelstatic struct type * 3368130803Smarcelhpread_read_doc_function_type (dnttpointer hp_type, union dnttentry *dn_bufp, 3369130803Smarcel struct objfile *objfile, int newblock) 3370130803Smarcel{ 3371130803Smarcel struct pending *syms; 3372130803Smarcel struct pending *local_list = NULL; 3373130803Smarcel int nsyms = 0; 3374130803Smarcel struct type *type; 3375130803Smarcel dnttpointer param; 3376130803Smarcel union dnttentry *paramp; 3377130803Smarcel char *name; 3378130803Smarcel long n; 3379130803Smarcel struct symbol *sym; 3380130803Smarcel int record_args = 1; 3381130803Smarcel 3382130803Smarcel /* See if we've already read in this type. */ 3383130803Smarcel type = hpread_alloc_type (hp_type, objfile); 3384130803Smarcel if (TYPE_CODE (type) == TYPE_CODE_FUNC) 3385130803Smarcel { 3386130803Smarcel record_args = 0; /* already read in, don't modify type */ 3387130803Smarcel } 3388130803Smarcel else 3389130803Smarcel { 3390130803Smarcel struct type *type1 = NULL; 3391130803Smarcel /* Nope, so read it in and store it away. */ 3392130803Smarcel if (dn_bufp->dblock.kind == DNTT_TYPE_DOC_FUNCTION || 3393130803Smarcel dn_bufp->dblock.kind == DNTT_TYPE_DOC_MEMFUNC) 3394130803Smarcel type1 = lookup_function_type (hpread_type_lookup (dn_bufp->ddocfunc.retval, 3395130803Smarcel objfile)); 3396130803Smarcel /* NOTE: cagney/2003-03-29: Oh, no not again. TYPE1 is 3397130803Smarcel potentially left undefined here. Assert it isn't and hope 3398130803Smarcel the assert never fails ... */ 3399130803Smarcel gdb_assert (type1 != NULL); 3400130803Smarcel 3401130803Smarcel replace_type (type, type1); 3402130803Smarcel 3403130803Smarcel /* Mark it -- in the middle of processing */ 3404130803Smarcel TYPE_FLAGS (type) |= TYPE_FLAG_INCOMPLETE; 3405130803Smarcel } 3406130803Smarcel 3407130803Smarcel /* Now examine each parameter noting its type, location, and a 3408130803Smarcel wealth of other information. */ 3409130803Smarcel if (dn_bufp->dblock.kind == DNTT_TYPE_DOC_FUNCTION || 3410130803Smarcel dn_bufp->dblock.kind == DNTT_TYPE_DOC_MEMFUNC) 3411130803Smarcel param = dn_bufp->ddocfunc.firstparam; 3412130803Smarcel while (param.word && param.word != DNTTNIL) 3413130803Smarcel { 3414130803Smarcel paramp = hpread_get_lntt (param.dnttp.index, objfile); 3415130803Smarcel nsyms++; 3416130803Smarcel param = paramp->dfparam.nextparam; 3417130803Smarcel 3418130803Smarcel /* Get the name. */ 3419130803Smarcel name = VT (objfile) + paramp->dfparam.name; 3420130803Smarcel sym = (struct symbol *) obstack_alloc (&objfile->objfile_obstack, 3421130803Smarcel sizeof (struct symbol)); 3422130803Smarcel (void) memset (sym, 0, sizeof (struct symbol)); 3423130803Smarcel DEPRECATED_SYMBOL_NAME (sym) = name; 3424130803Smarcel 3425130803Smarcel /* Figure out where it lives. */ 3426130803Smarcel if (paramp->dfparam.regparam) 3427130803Smarcel SYMBOL_CLASS (sym) = LOC_REGPARM; 3428130803Smarcel else if (paramp->dfparam.indirect) 3429130803Smarcel SYMBOL_CLASS (sym) = LOC_REF_ARG; 3430130803Smarcel else 3431130803Smarcel SYMBOL_CLASS (sym) = LOC_ARG; 3432130803Smarcel SYMBOL_DOMAIN (sym) = VAR_DOMAIN; 3433130803Smarcel if (paramp->dfparam.copyparam) 3434130803Smarcel { 3435130803Smarcel SYMBOL_VALUE (sym) = paramp->dfparam.location; 3436130803Smarcel#ifdef HPREAD_ADJUST_STACK_ADDRESS 3437130803Smarcel SYMBOL_VALUE (sym) 3438130803Smarcel += HPREAD_ADJUST_STACK_ADDRESS (CURRENT_FUNCTION_VALUE (objfile)); 3439130803Smarcel#endif 3440130803Smarcel /* This is likely a pass-by-invisible reference parameter, 3441130803Smarcel Hack on the symbol class to make GDB happy. */ 3442130803Smarcel /* ??rehrauer: This appears to be broken w/r/t to passing 3443130803Smarcel C values of type float and struct. Perhaps this ought 3444130803Smarcel to be highighted as a special case, but for now, just 3445130803Smarcel allowing these to be LOC_ARGs seems to work fine. 3446130803Smarcel */ 3447130803Smarcel#if 0 3448130803Smarcel SYMBOL_CLASS (sym) = LOC_REGPARM_ADDR; 3449130803Smarcel#endif 3450130803Smarcel } 3451130803Smarcel else 3452130803Smarcel SYMBOL_VALUE (sym) = paramp->dfparam.location; 3453130803Smarcel 3454130803Smarcel /* Get its type. */ 3455130803Smarcel SYMBOL_TYPE (sym) = hpread_type_lookup (paramp->dfparam.type, objfile); 3456130803Smarcel /* Add it to the symbol list. */ 3457130803Smarcel /* Note 1 (RT) At the moment, add_symbol_to_list() is also being 3458130803Smarcel * called on FPARAM symbols from the process_one_debug_symbol() 3459130803Smarcel * level... so parameters are getting added twice! (this shows 3460130803Smarcel * up in the symbol dump you get from "maint print symbols ..."). 3461130803Smarcel * Note 2 (RT) I took out the processing of FPARAM from the 3462130803Smarcel * process_one_debug_symbol() level, so at the moment parameters are only 3463130803Smarcel * being processed here. This seems to have no ill effect. 3464130803Smarcel */ 3465130803Smarcel /* Note 3 (pai/1997-08-11) I removed the add_symbol_to_list() which put 3466130803Smarcel each fparam on the local_symbols list from here. Now we use the 3467130803Smarcel local_list to which fparams are added below, and set the param_symbols 3468130803Smarcel global to point to that at the end of this routine. */ 3469130803Smarcel 3470130803Smarcel /* elz: I added this new list of symbols which is local to the function. 3471130803Smarcel this list is the one which is actually used to build the type for the 3472130803Smarcel function rather than the gloabal list pointed to by symlist. 3473130803Smarcel Using a global list to keep track of the parameters is wrong, because 3474130803Smarcel this function is called recursively if one parameter happend to be 3475130803Smarcel a function itself with more parameters in it. Adding parameters to the 3476130803Smarcel same global symbol list would not work! 3477130803Smarcel Actually it did work in case of cc compiled programs where you do not check the 3478130803Smarcel parameter lists of the arguments. */ 3479130803Smarcel add_symbol_to_list (sym, &local_list); 3480130803Smarcel } 3481130803Smarcel 3482130803Smarcel /* If type was read in earlier, don't bother with modifying 3483130803Smarcel the type struct */ 3484130803Smarcel if (!record_args) 3485130803Smarcel goto finish; 3486130803Smarcel 3487130803Smarcel /* Note how many parameters we found. */ 3488130803Smarcel TYPE_NFIELDS (type) = nsyms; 3489130803Smarcel TYPE_FIELDS (type) = (struct field *) 3490130803Smarcel obstack_alloc (&objfile->objfile_obstack, 3491130803Smarcel sizeof (struct field) * nsyms); 3492130803Smarcel 3493130803Smarcel /* Find the symbols for the parameters and 3494130803Smarcel use them to fill parameter-type information into the function-type. 3495130803Smarcel The parameter symbols can be found in the local_list that we just put them on. */ 3496130803Smarcel /* Note that we preserve the order of the parameters, so 3497130803Smarcel that in something like "enum {FOO, LAST_THING=FOO}" we print 3498130803Smarcel FOO, not LAST_THING. */ 3499130803Smarcel 3500130803Smarcel /* get the parameters types from the local list not the global list 3501130803Smarcel so that the type can be correctly constructed for functions which 3502130803Smarcel have function as parameters 3503130803Smarcel */ 3504130803Smarcel for (syms = local_list, n = 0; syms; syms = syms->next) 3505130803Smarcel { 3506130803Smarcel int j = 0; 3507130803Smarcel for (j = 0; j < syms->nsyms; j++, n++) 3508130803Smarcel { 3509130803Smarcel struct symbol *xsym = syms->symbol[j]; 3510130803Smarcel TYPE_FIELD_NAME (type, n) = DEPRECATED_SYMBOL_NAME (xsym); 3511130803Smarcel TYPE_FIELD_TYPE (type, n) = SYMBOL_TYPE (xsym); 3512130803Smarcel TYPE_FIELD_ARTIFICIAL (type, n) = 0; 3513130803Smarcel TYPE_FIELD_BITSIZE (type, n) = 0; 3514130803Smarcel TYPE_FIELD_STATIC_KIND (type, n) = 0; 3515130803Smarcel } 3516130803Smarcel } 3517130803Smarcel 3518130803Smarcel /* Mark it as having been processed */ 3519130803Smarcel TYPE_FLAGS (type) &= ~(TYPE_FLAG_INCOMPLETE); 3520130803Smarcel 3521130803Smarcel /* Check whether we need to fix-up a class type with this function's type */ 3522130803Smarcel if (fixup_class && (fixup_method == type)) 3523130803Smarcel { 3524130803Smarcel fixup_class_method_type (fixup_class, fixup_method, objfile); 3525130803Smarcel fixup_class = NULL; 3526130803Smarcel fixup_method = NULL; 3527130803Smarcel } 3528130803Smarcel 3529130803Smarcel /* Set the param list of this level of the context stack 3530130803Smarcel to our local list. Do this only if this function was 3531130803Smarcel called for creating a new block, and not if it was called 3532130803Smarcel simply to get the function type. This prevents recursive 3533130803Smarcel invocations from trashing param_symbols. */ 3534130803Smarcelfinish: 3535130803Smarcel if (newblock) 3536130803Smarcel param_symbols = local_list; 3537130803Smarcel 3538130803Smarcel return type; 3539130803Smarcel} 3540130803Smarcel 3541130803Smarcel 3542130803Smarcel 3543130803Smarcel/* A file-level variable which keeps track of the current-template 3544130803Smarcel * being processed. Set in hpread_read_struct_type() while processing 3545130803Smarcel * a template type. Referred to in hpread_get_nth_templ_arg(). 3546130803Smarcel * Yes, this is a kludge, but it arises from the kludge that already 3547130803Smarcel * exists in symtab.h, namely the fact that they encode 3548130803Smarcel * "template argument n" with fundamental type FT_TEMPLATE_ARG and 3549130803Smarcel * bitlength n. This means that deep in processing fundamental types 3550130803Smarcel * I need to ask the question "what template am I in the middle of?". 3551130803Smarcel * The alternative to stuffing a global would be to pass an argument 3552130803Smarcel * down the chain of calls just for this purpose. 3553130803Smarcel * 3554130803Smarcel * There may be problems handling nested templates... tough. 3555130803Smarcel */ 3556130803Smarcelstatic struct type *current_template = NULL; 3557130803Smarcel 3558130803Smarcel/* Read in and internalize a structure definition. 3559130803Smarcel * This same routine is called for struct, union, and class types. 3560130803Smarcel * Also called for templates, since they build a very similar 3561130803Smarcel * type entry as for class types. 3562130803Smarcel */ 3563130803Smarcel 3564130803Smarcelstatic struct type * 3565130803Smarcelhpread_read_struct_type (dnttpointer hp_type, union dnttentry *dn_bufp, 3566130803Smarcel struct objfile *objfile) 3567130803Smarcel{ 3568130803Smarcel /* The data members get linked together into a list of struct nextfield's */ 3569130803Smarcel struct nextfield 3570130803Smarcel { 3571130803Smarcel struct nextfield *next; 3572130803Smarcel struct field field; 3573130803Smarcel unsigned char attributes; /* store visibility and virtuality info */ 3574130803Smarcel#define ATTR_VIRTUAL 1 3575130803Smarcel#define ATTR_PRIVATE 2 3576130803Smarcel#define ATTR_PROTECT 3 3577130803Smarcel }; 3578130803Smarcel 3579130803Smarcel 3580130803Smarcel /* The methods get linked together into a list of struct next_fn_field's */ 3581130803Smarcel struct next_fn_field 3582130803Smarcel { 3583130803Smarcel struct next_fn_field *next; 3584130803Smarcel struct fn_fieldlist field; 3585130803Smarcel struct fn_field fn_field; 3586130803Smarcel int num_fn_fields; 3587130803Smarcel }; 3588130803Smarcel 3589130803Smarcel /* The template args get linked together into a list of struct next_template's */ 3590130803Smarcel struct next_template 3591130803Smarcel { 3592130803Smarcel struct next_template *next; 3593130803Smarcel struct template_arg arg; 3594130803Smarcel }; 3595130803Smarcel 3596130803Smarcel /* The template instantiations get linked together into a list of these... */ 3597130803Smarcel struct next_instantiation 3598130803Smarcel { 3599130803Smarcel struct next_instantiation *next; 3600130803Smarcel struct type *t; 3601130803Smarcel }; 3602130803Smarcel 3603130803Smarcel struct type *type; 3604130803Smarcel struct type *baseclass; 3605130803Smarcel struct type *memtype; 3606130803Smarcel struct nextfield *list = 0, *tmp_list = 0; 3607130803Smarcel struct next_fn_field *fn_list = 0; 3608130803Smarcel struct next_fn_field *fn_p; 3609130803Smarcel struct next_template *t_new, *t_list = 0; 3610130803Smarcel struct nextfield *new; 3611130803Smarcel struct next_fn_field *fn_new; 3612130803Smarcel struct next_instantiation *i_new, *i_list = 0; 3613130803Smarcel int n, nfields = 0, n_fn_fields = 0, n_fn_fields_total = 0; 3614130803Smarcel int n_base_classes = 0, n_templ_args = 0; 3615130803Smarcel int ninstantiations = 0; 3616130803Smarcel dnttpointer field, fn_field, parent; 3617130803Smarcel union dnttentry *fieldp, *fn_fieldp, *parentp; 3618130803Smarcel int i; 3619130803Smarcel int static_member = 0; 3620130803Smarcel int const_member = 0; 3621130803Smarcel int volatile_member = 0; 3622130803Smarcel unsigned long vtbl_offset; 3623130803Smarcel int need_bitvectors = 0; 3624130803Smarcel char *method_name = NULL; 3625130803Smarcel char *method_alias = NULL; 3626130803Smarcel 3627130803Smarcel 3628130803Smarcel /* Is it something we've already dealt with? */ 3629130803Smarcel type = hpread_alloc_type (hp_type, objfile); 3630130803Smarcel if ((TYPE_CODE (type) == TYPE_CODE_STRUCT) || 3631130803Smarcel (TYPE_CODE (type) == TYPE_CODE_UNION) || 3632130803Smarcel (TYPE_CODE (type) == TYPE_CODE_CLASS) || 3633130803Smarcel (TYPE_CODE (type) == TYPE_CODE_TEMPLATE)) 3634130803Smarcel return type; 3635130803Smarcel 3636130803Smarcel /* Get the basic type correct. */ 3637130803Smarcel if (dn_bufp->dblock.kind == DNTT_TYPE_STRUCT) 3638130803Smarcel { 3639130803Smarcel TYPE_CODE (type) = TYPE_CODE_STRUCT; 3640130803Smarcel TYPE_LENGTH (type) = dn_bufp->dstruct.bitlength / 8; 3641130803Smarcel } 3642130803Smarcel else if (dn_bufp->dblock.kind == DNTT_TYPE_UNION) 3643130803Smarcel { 3644130803Smarcel TYPE_CODE (type) = TYPE_CODE_UNION; 3645130803Smarcel TYPE_LENGTH (type) = dn_bufp->dunion.bitlength / 8; 3646130803Smarcel } 3647130803Smarcel else if (dn_bufp->dblock.kind == DNTT_TYPE_CLASS) 3648130803Smarcel { 3649130803Smarcel TYPE_CODE (type) = TYPE_CODE_CLASS; 3650130803Smarcel TYPE_LENGTH (type) = dn_bufp->dclass.bitlength / 8; 3651130803Smarcel 3652130803Smarcel /* Overrides the TYPE_CPLUS_SPECIFIC(type) with allocated memory 3653130803Smarcel * rather than &cplus_struct_default. 3654130803Smarcel */ 3655130803Smarcel allocate_cplus_struct_type (type); 3656130803Smarcel 3657130803Smarcel /* Fill in declared-type. 3658130803Smarcel * (The C++ compiler will emit TYPE_CODE_CLASS 3659130803Smarcel * for all 3 of "class", "struct" 3660130803Smarcel * "union", and we have to look at the "class_decl" field if we 3661130803Smarcel * want to know how it was really declared) 3662130803Smarcel */ 3663130803Smarcel /* (0==class, 1==union, 2==struct) */ 3664130803Smarcel TYPE_DECLARED_TYPE (type) = dn_bufp->dclass.class_decl; 3665130803Smarcel } 3666130803Smarcel else if (dn_bufp->dblock.kind == DNTT_TYPE_TEMPLATE) 3667130803Smarcel { 3668130803Smarcel /* Get the basic type correct. */ 3669130803Smarcel TYPE_CODE (type) = TYPE_CODE_TEMPLATE; 3670130803Smarcel allocate_cplus_struct_type (type); 3671130803Smarcel TYPE_DECLARED_TYPE (type) = DECLARED_TYPE_TEMPLATE; 3672130803Smarcel } 3673130803Smarcel else 3674130803Smarcel return type; 3675130803Smarcel 3676130803Smarcel 3677130803Smarcel TYPE_FLAGS (type) &= ~TYPE_FLAG_STUB; 3678130803Smarcel 3679130803Smarcel /* For classes, read the parent list. 3680130803Smarcel * Question (RT): Do we need to do this for templates also? 3681130803Smarcel */ 3682130803Smarcel if (dn_bufp->dblock.kind == DNTT_TYPE_CLASS) 3683130803Smarcel { 3684130803Smarcel 3685130803Smarcel /* First read the parent-list (classes from which we derive fields) */ 3686130803Smarcel parent = dn_bufp->dclass.parentlist; 3687130803Smarcel while (parent.word && parent.word != DNTTNIL) 3688130803Smarcel { 3689130803Smarcel parentp = hpread_get_lntt (parent.dnttp.index, objfile); 3690130803Smarcel 3691130803Smarcel /* "parentp" should point to a DNTT_TYPE_INHERITANCE record */ 3692130803Smarcel 3693130803Smarcel /* Get space to record the next field/data-member. */ 3694130803Smarcel new = (struct nextfield *) alloca (sizeof (struct nextfield)); 3695130803Smarcel memset (new, 0, sizeof (struct nextfield)); 3696130803Smarcel new->next = list; 3697130803Smarcel list = new; 3698130803Smarcel 3699130803Smarcel FIELD_BITSIZE (list->field) = 0; 3700130803Smarcel FIELD_STATIC_KIND (list->field) = 0; 3701130803Smarcel 3702130803Smarcel /* The "classname" field is actually a DNTT pointer to the base class */ 3703130803Smarcel baseclass = hpread_type_lookup (parentp->dinheritance.classname, 3704130803Smarcel objfile); 3705130803Smarcel FIELD_TYPE (list->field) = baseclass; 3706130803Smarcel 3707130803Smarcel list->field.name = type_name_no_tag (FIELD_TYPE (list->field)); 3708130803Smarcel 3709130803Smarcel list->attributes = 0; 3710130803Smarcel 3711130803Smarcel /* Check for virtuality of base, and set the 3712130803Smarcel * offset of the base subobject within the object. 3713130803Smarcel * (Offset set to -1 for virtual bases (for now).) 3714130803Smarcel */ 3715130803Smarcel if (parentp->dinheritance.Virtual) 3716130803Smarcel { 3717130803Smarcel B_SET (&(list->attributes), ATTR_VIRTUAL); 3718130803Smarcel parentp->dinheritance.offset = -1; 3719130803Smarcel } 3720130803Smarcel else 3721130803Smarcel FIELD_BITPOS (list->field) = parentp->dinheritance.offset; 3722130803Smarcel 3723130803Smarcel /* Check visibility */ 3724130803Smarcel switch (parentp->dinheritance.visibility) 3725130803Smarcel { 3726130803Smarcel case 1: 3727130803Smarcel B_SET (&(list->attributes), ATTR_PROTECT); 3728130803Smarcel break; 3729130803Smarcel case 2: 3730130803Smarcel B_SET (&(list->attributes), ATTR_PRIVATE); 3731130803Smarcel break; 3732130803Smarcel } 3733130803Smarcel 3734130803Smarcel n_base_classes++; 3735130803Smarcel nfields++; 3736130803Smarcel 3737130803Smarcel parent = parentp->dinheritance.next; 3738130803Smarcel } 3739130803Smarcel } 3740130803Smarcel 3741130803Smarcel /* For templates, read the template argument list. 3742130803Smarcel * This must be done before processing the member list, because 3743130803Smarcel * the member list may refer back to this. E.g.: 3744130803Smarcel * template <class T1, class T2> class q2 { 3745130803Smarcel * public: 3746130803Smarcel * T1 a; 3747130803Smarcel * T2 b; 3748130803Smarcel * }; 3749130803Smarcel * We need to read the argument list "T1", "T2" first. 3750130803Smarcel */ 3751130803Smarcel if (dn_bufp->dblock.kind == DNTT_TYPE_TEMPLATE) 3752130803Smarcel { 3753130803Smarcel /* Kludge alert: This stuffs a global "current_template" which 3754130803Smarcel * is referred to by hpread_get_nth_templ_arg(). The global 3755130803Smarcel * is cleared at the end of this routine. 3756130803Smarcel */ 3757130803Smarcel current_template = type; 3758130803Smarcel 3759130803Smarcel /* Read in the argument list */ 3760130803Smarcel field = dn_bufp->dtemplate.arglist; 3761130803Smarcel while (field.word && field.word != DNTTNIL) 3762130803Smarcel { 3763130803Smarcel /* Get this template argument */ 3764130803Smarcel fieldp = hpread_get_lntt (field.dnttp.index, objfile); 3765130803Smarcel if (fieldp->dblock.kind != DNTT_TYPE_TEMPLATE_ARG) 3766130803Smarcel { 3767130803Smarcel warning ("Invalid debug info: Template argument entry is of wrong kind"); 3768130803Smarcel break; 3769130803Smarcel } 3770130803Smarcel /* Bump the count */ 3771130803Smarcel n_templ_args++; 3772130803Smarcel /* Allocate and fill in a struct next_template */ 3773130803Smarcel t_new = (struct next_template *) alloca (sizeof (struct next_template)); 3774130803Smarcel memset (t_new, 0, sizeof (struct next_template)); 3775130803Smarcel t_new->next = t_list; 3776130803Smarcel t_list = t_new; 3777130803Smarcel t_list->arg.name = VT (objfile) + fieldp->dtempl_arg.name; 3778130803Smarcel t_list->arg.type = hpread_read_templ_arg_type (field, fieldp, 3779130803Smarcel objfile, t_list->arg.name); 3780130803Smarcel /* Walk to the next template argument */ 3781130803Smarcel field = fieldp->dtempl_arg.nextarg; 3782130803Smarcel } 3783130803Smarcel } 3784130803Smarcel 3785130803Smarcel TYPE_NTEMPLATE_ARGS (type) = n_templ_args; 3786130803Smarcel 3787130803Smarcel if (n_templ_args > 0) 3788130803Smarcel TYPE_TEMPLATE_ARGS (type) = (struct template_arg *) 3789130803Smarcel obstack_alloc (&objfile->objfile_obstack, sizeof (struct template_arg) * n_templ_args); 3790130803Smarcel for (n = n_templ_args; t_list; t_list = t_list->next) 3791130803Smarcel { 3792130803Smarcel n -= 1; 3793130803Smarcel TYPE_TEMPLATE_ARG (type, n) = t_list->arg; 3794130803Smarcel } 3795130803Smarcel 3796130803Smarcel /* Next read in and internalize all the fields/members. */ 3797130803Smarcel if (dn_bufp->dblock.kind == DNTT_TYPE_STRUCT) 3798130803Smarcel field = dn_bufp->dstruct.firstfield; 3799130803Smarcel else if (dn_bufp->dblock.kind == DNTT_TYPE_UNION) 3800130803Smarcel field = dn_bufp->dunion.firstfield; 3801130803Smarcel else if (dn_bufp->dblock.kind == DNTT_TYPE_CLASS) 3802130803Smarcel field = dn_bufp->dclass.memberlist; 3803130803Smarcel else if (dn_bufp->dblock.kind == DNTT_TYPE_TEMPLATE) 3804130803Smarcel field = dn_bufp->dtemplate.memberlist; 3805130803Smarcel else 3806130803Smarcel field.word = DNTTNIL; 3807130803Smarcel 3808130803Smarcel while (field.word && field.word != DNTTNIL) 3809130803Smarcel { 3810130803Smarcel fieldp = hpread_get_lntt (field.dnttp.index, objfile); 3811130803Smarcel 3812130803Smarcel /* At this point "fieldp" may point to either a DNTT_TYPE_FIELD 3813130803Smarcel * or a DNTT_TYPE_GENFIELD record. 3814130803Smarcel */ 3815130803Smarcel vtbl_offset = 0; 3816130803Smarcel static_member = 0; 3817130803Smarcel const_member = 0; 3818130803Smarcel volatile_member = 0; 3819130803Smarcel 3820130803Smarcel if (fieldp->dblock.kind == DNTT_TYPE_GENFIELD) 3821130803Smarcel { 3822130803Smarcel 3823130803Smarcel /* The type will be GENFIELD if the field is a method or 3824130803Smarcel * a static member (or some other cases -- see below) 3825130803Smarcel */ 3826130803Smarcel 3827130803Smarcel /* Follow a link to get to the record for the field. */ 3828130803Smarcel fn_field = fieldp->dgenfield.field; 3829130803Smarcel fn_fieldp = hpread_get_lntt (fn_field.dnttp.index, objfile); 3830130803Smarcel 3831130803Smarcel /* Virtual funcs are indicated by a VFUNC which points to the 3832130803Smarcel * real entry 3833130803Smarcel */ 3834130803Smarcel if (fn_fieldp->dblock.kind == DNTT_TYPE_VFUNC) 3835130803Smarcel { 3836130803Smarcel vtbl_offset = fn_fieldp->dvfunc.vtbl_offset; 3837130803Smarcel fn_field = fn_fieldp->dvfunc.funcptr; 3838130803Smarcel fn_fieldp = hpread_get_lntt (fn_field.dnttp.index, objfile); 3839130803Smarcel } 3840130803Smarcel 3841130803Smarcel /* A function's entry may be preceded by a modifier which 3842130803Smarcel * labels it static/constant/volatile. 3843130803Smarcel */ 3844130803Smarcel if (fn_fieldp->dblock.kind == DNTT_TYPE_MODIFIER) 3845130803Smarcel { 3846130803Smarcel static_member = fn_fieldp->dmodifier.m_static; 3847130803Smarcel const_member = fn_fieldp->dmodifier.m_const; 3848130803Smarcel volatile_member = fn_fieldp->dmodifier.m_volatile; 3849130803Smarcel fn_field = fn_fieldp->dmodifier.type; 3850130803Smarcel fn_fieldp = hpread_get_lntt (fn_field.dnttp.index, objfile); 3851130803Smarcel } 3852130803Smarcel 3853130803Smarcel /* Check whether we have a method */ 3854130803Smarcel if ((fn_fieldp->dblock.kind == DNTT_TYPE_MEMFUNC) || 3855130803Smarcel (fn_fieldp->dblock.kind == DNTT_TYPE_FUNCTION) || 3856130803Smarcel (fn_fieldp->dblock.kind == DNTT_TYPE_DOC_MEMFUNC) || 3857130803Smarcel (fn_fieldp->dblock.kind == DNTT_TYPE_DOC_FUNCTION)) 3858130803Smarcel { 3859130803Smarcel /* Method found */ 3860130803Smarcel 3861130803Smarcel short ix = 0; 3862130803Smarcel 3863130803Smarcel /* Look up function type of method */ 3864130803Smarcel memtype = hpread_type_lookup (fn_field, objfile); 3865130803Smarcel 3866130803Smarcel /* Methods can be seen before classes in the SOM records. 3867130803Smarcel If we are processing this class because it's a parameter of a 3868130803Smarcel method, at this point the method's type is actually incomplete; 3869130803Smarcel we'll have to fix it up later; mark the class for this. */ 3870130803Smarcel 3871130803Smarcel if (TYPE_INCOMPLETE (memtype)) 3872130803Smarcel { 3873130803Smarcel TYPE_FLAGS (type) |= TYPE_FLAG_INCOMPLETE; 3874130803Smarcel if (fixup_class) 3875130803Smarcel warning ("Two classes to fix up for method?? Type information may be incorrect for some classes."); 3876130803Smarcel if (fixup_method) 3877130803Smarcel warning ("Two methods to be fixed up at once?? Type information may be incorrect for some classes."); 3878130803Smarcel fixup_class = type; /* remember this class has to be fixed up */ 3879130803Smarcel fixup_method = memtype; /* remember the method type to be used in fixup */ 3880130803Smarcel } 3881130803Smarcel 3882130803Smarcel /* HP aCC generates operator names without the "operator" keyword, and 3883130803Smarcel generates null strings as names for operators that are 3884130803Smarcel user-defined type conversions to basic types (e.g. operator int ()). 3885130803Smarcel So try to reconstruct name as best as possible. */ 3886130803Smarcel 3887130803Smarcel method_name = (char *) (VT (objfile) + fn_fieldp->dfunc.name); 3888130803Smarcel method_alias = (char *) (VT (objfile) + fn_fieldp->dfunc.alias); 3889130803Smarcel 3890130803Smarcel if (!method_name || /* no name */ 3891130803Smarcel !*method_name || /* or null name */ 3892130803Smarcel cplus_mangle_opname (method_name, DMGL_ANSI)) /* or name is an operator like "<" */ 3893130803Smarcel { 3894130803Smarcel char *tmp_name = cplus_demangle (method_alias, DMGL_ANSI); 3895130803Smarcel char *op_string = strstr (tmp_name, "operator"); 3896130803Smarcel method_name = xmalloc (strlen (op_string) + 1); /* don't overwrite VT! */ 3897130803Smarcel strcpy (method_name, op_string); 3898130803Smarcel } 3899130803Smarcel 3900130803Smarcel /* First check if a method of the same name has already been seen. */ 3901130803Smarcel fn_p = fn_list; 3902130803Smarcel while (fn_p) 3903130803Smarcel { 3904130803Smarcel if (DEPRECATED_STREQ (fn_p->field.name, method_name)) 3905130803Smarcel break; 3906130803Smarcel fn_p = fn_p->next; 3907130803Smarcel } 3908130803Smarcel 3909130803Smarcel /* If no such method was found, allocate a new entry in the list */ 3910130803Smarcel if (!fn_p) 3911130803Smarcel { 3912130803Smarcel /* Get space to record this member function */ 3913130803Smarcel /* Note: alloca used; this will disappear on routine exit */ 3914130803Smarcel fn_new = (struct next_fn_field *) alloca (sizeof (struct next_fn_field)); 3915130803Smarcel memset (fn_new, 0, sizeof (struct next_fn_field)); 3916130803Smarcel fn_new->next = fn_list; 3917130803Smarcel fn_list = fn_new; 3918130803Smarcel 3919130803Smarcel /* Fill in the fields of the struct nextfield */ 3920130803Smarcel 3921130803Smarcel /* Record the (unmangled) method name */ 3922130803Smarcel fn_list->field.name = method_name; 3923130803Smarcel /* Initial space for overloaded methods */ 3924130803Smarcel /* Note: xmalloc is used; this will persist after this routine exits */ 3925130803Smarcel fn_list->field.fn_fields = (struct fn_field *) xmalloc (5 * (sizeof (struct fn_field))); 3926130803Smarcel fn_list->field.length = 1; /* Init # of overloaded instances */ 3927130803Smarcel fn_list->num_fn_fields = 5; /* # of entries for which space allocated */ 3928130803Smarcel fn_p = fn_list; 3929130803Smarcel ix = 0; /* array index for fn_field */ 3930130803Smarcel /* Bump the total count of the distinctly named methods */ 3931130803Smarcel n_fn_fields++; 3932130803Smarcel } 3933130803Smarcel else 3934130803Smarcel /* Another overloaded instance of an already seen method name */ 3935130803Smarcel { 3936130803Smarcel if (++(fn_p->field.length) > fn_p->num_fn_fields) 3937130803Smarcel { 3938130803Smarcel /* Increase space allocated for overloaded instances */ 3939130803Smarcel fn_p->field.fn_fields 3940130803Smarcel = (struct fn_field *) xrealloc (fn_p->field.fn_fields, 3941130803Smarcel (fn_p->num_fn_fields + 5) * sizeof (struct fn_field)); 3942130803Smarcel fn_p->num_fn_fields += 5; 3943130803Smarcel } 3944130803Smarcel ix = fn_p->field.length - 1; /* array index for fn_field */ 3945130803Smarcel } 3946130803Smarcel 3947130803Smarcel /* "physname" is intended to be the name of this overloaded instance. */ 3948130803Smarcel if ((fn_fieldp->dfunc.language == HP_LANGUAGE_CPLUSPLUS) && 3949130803Smarcel method_alias && 3950130803Smarcel *method_alias) /* not a null string */ 3951130803Smarcel fn_p->field.fn_fields[ix].physname = method_alias; 3952130803Smarcel else 3953130803Smarcel fn_p->field.fn_fields[ix].physname = method_name; 3954130803Smarcel /* What's expected here is the function type */ 3955130803Smarcel /* But mark it as NULL if the method was incompletely processed 3956130803Smarcel We'll fix this up later when the method is fully processed */ 3957130803Smarcel if (TYPE_INCOMPLETE (memtype)) 3958130803Smarcel fn_p->field.fn_fields[ix].type = NULL; 3959130803Smarcel else 3960130803Smarcel fn_p->field.fn_fields[ix].type = memtype; 3961130803Smarcel 3962130803Smarcel /* For virtual functions, fill in the voffset field with the 3963130803Smarcel * virtual table offset. (This is just copied over from the 3964130803Smarcel * SOM record; not sure if it is what GDB expects here...). 3965130803Smarcel * But if the function is a static method, set it to 1. 3966130803Smarcel * 3967130803Smarcel * Note that we have to add 1 because 1 indicates a static 3968130803Smarcel * method, and 0 indicates a non-static, non-virtual method */ 3969130803Smarcel 3970130803Smarcel if (static_member) 3971130803Smarcel fn_p->field.fn_fields[ix].voffset = VOFFSET_STATIC; 3972130803Smarcel else 3973130803Smarcel fn_p->field.fn_fields[ix].voffset = vtbl_offset ? vtbl_offset + 1 : 0; 3974130803Smarcel 3975130803Smarcel /* Also fill in the fcontext field with the current 3976130803Smarcel * class. (The latter isn't quite right: should be the baseclass 3977130803Smarcel * that defines the virtual function... Note we do have 3978130803Smarcel * a variable "baseclass" that we could stuff into the fcontext 3979130803Smarcel * field, but "baseclass" isn't necessarily right either, 3980130803Smarcel * since the virtual function could have been defined more 3981130803Smarcel * than one level up). 3982130803Smarcel */ 3983130803Smarcel 3984130803Smarcel if (vtbl_offset != 0) 3985130803Smarcel fn_p->field.fn_fields[ix].fcontext = type; 3986130803Smarcel else 3987130803Smarcel fn_p->field.fn_fields[ix].fcontext = NULL; 3988130803Smarcel 3989130803Smarcel /* Other random fields pertaining to this method */ 3990130803Smarcel fn_p->field.fn_fields[ix].is_const = const_member; 3991130803Smarcel fn_p->field.fn_fields[ix].is_volatile = volatile_member; /* ?? */ 3992130803Smarcel switch (fieldp->dgenfield.visibility) 3993130803Smarcel { 3994130803Smarcel case 1: 3995130803Smarcel fn_p->field.fn_fields[ix].is_protected = 1; 3996130803Smarcel fn_p->field.fn_fields[ix].is_private = 0; 3997130803Smarcel break; 3998130803Smarcel case 2: 3999130803Smarcel fn_p->field.fn_fields[ix].is_protected = 0; 4000130803Smarcel fn_p->field.fn_fields[ix].is_private = 1; 4001130803Smarcel break; 4002130803Smarcel default: /* public */ 4003130803Smarcel fn_p->field.fn_fields[ix].is_protected = 0; 4004130803Smarcel fn_p->field.fn_fields[ix].is_private = 0; 4005130803Smarcel } 4006130803Smarcel fn_p->field.fn_fields[ix].is_stub = 0; 4007130803Smarcel 4008130803Smarcel /* HP aCC emits both MEMFUNC and FUNCTION entries for a method; 4009130803Smarcel if the class points to the FUNCTION, there is usually separate 4010130803Smarcel code for the method; but if we have a MEMFUNC, the method has 4011130803Smarcel been inlined (and there is usually no FUNCTION entry) 4012130803Smarcel FIXME Not sure if this test is accurate. pai/1997-08-22 */ 4013130803Smarcel if ((fn_fieldp->dblock.kind == DNTT_TYPE_MEMFUNC) || 4014130803Smarcel (fn_fieldp->dblock.kind == DNTT_TYPE_DOC_MEMFUNC)) 4015130803Smarcel fn_p->field.fn_fields[ix].is_inlined = 1; 4016130803Smarcel else 4017130803Smarcel fn_p->field.fn_fields[ix].is_inlined = 0; 4018130803Smarcel 4019130803Smarcel fn_p->field.fn_fields[ix].dummy = 0; 4020130803Smarcel 4021130803Smarcel /* Bump the total count of the member functions */ 4022130803Smarcel n_fn_fields_total++; 4023130803Smarcel 4024130803Smarcel } 4025130803Smarcel else if (fn_fieldp->dblock.kind == DNTT_TYPE_SVAR) 4026130803Smarcel { 4027130803Smarcel /* This case is for static data members of classes */ 4028130803Smarcel 4029130803Smarcel /* pai:: FIXME -- check that "staticmem" bit is set */ 4030130803Smarcel 4031130803Smarcel /* Get space to record this static member */ 4032130803Smarcel new = (struct nextfield *) alloca (sizeof (struct nextfield)); 4033130803Smarcel memset (new, 0, sizeof (struct nextfield)); 4034130803Smarcel new->next = list; 4035130803Smarcel list = new; 4036130803Smarcel 4037130803Smarcel list->field.name = VT (objfile) + fn_fieldp->dsvar.name; 4038130803Smarcel SET_FIELD_PHYSNAME (list->field, 0); /* initialize to empty */ 4039130803Smarcel memtype = hpread_type_lookup (fn_fieldp->dsvar.type, objfile); 4040130803Smarcel 4041130803Smarcel FIELD_TYPE (list->field) = memtype; 4042130803Smarcel list->attributes = 0; 4043130803Smarcel switch (fieldp->dgenfield.visibility) 4044130803Smarcel { 4045130803Smarcel case 1: 4046130803Smarcel B_SET (&(list->attributes), ATTR_PROTECT); 4047130803Smarcel break; 4048130803Smarcel case 2: 4049130803Smarcel B_SET (&(list->attributes), ATTR_PRIVATE); 4050130803Smarcel break; 4051130803Smarcel } 4052130803Smarcel nfields++; 4053130803Smarcel } 4054130803Smarcel 4055130803Smarcel else if (fn_fieldp->dblock.kind == DNTT_TYPE_FIELD) 4056130803Smarcel { 4057130803Smarcel /* FIELDs follow GENFIELDs for fields of anonymous unions. 4058130803Smarcel Code below is replicated from the case for FIELDs further 4059130803Smarcel below, except that fieldp is replaced by fn_fieldp */ 4060130803Smarcel if (!fn_fieldp->dfield.a_union) 4061130803Smarcel warning ("Debug info inconsistent: FIELD of anonymous union doesn't have a_union bit set"); 4062130803Smarcel /* Get space to record the next field/data-member. */ 4063130803Smarcel new = (struct nextfield *) alloca (sizeof (struct nextfield)); 4064130803Smarcel memset (new, 0, sizeof (struct nextfield)); 4065130803Smarcel new->next = list; 4066130803Smarcel list = new; 4067130803Smarcel 4068130803Smarcel list->field.name = VT (objfile) + fn_fieldp->dfield.name; 4069130803Smarcel FIELD_BITPOS (list->field) = fn_fieldp->dfield.bitoffset; 4070130803Smarcel if (fn_fieldp->dfield.bitlength % 8) 4071130803Smarcel list->field.bitsize = fn_fieldp->dfield.bitlength; 4072130803Smarcel else 4073130803Smarcel list->field.bitsize = 0; 4074130803Smarcel 4075130803Smarcel memtype = hpread_type_lookup (fn_fieldp->dfield.type, objfile); 4076130803Smarcel list->field.type = memtype; 4077130803Smarcel list->attributes = 0; 4078130803Smarcel switch (fn_fieldp->dfield.visibility) 4079130803Smarcel { 4080130803Smarcel case 1: 4081130803Smarcel B_SET (&(list->attributes), ATTR_PROTECT); 4082130803Smarcel break; 4083130803Smarcel case 2: 4084130803Smarcel B_SET (&(list->attributes), ATTR_PRIVATE); 4085130803Smarcel break; 4086130803Smarcel } 4087130803Smarcel nfields++; 4088130803Smarcel } 4089130803Smarcel else if (fn_fieldp->dblock.kind == DNTT_TYPE_SVAR) 4090130803Smarcel { 4091130803Smarcel /* Field of anonymous union; union is not inside a class */ 4092130803Smarcel if (!fn_fieldp->dsvar.a_union) 4093130803Smarcel warning ("Debug info inconsistent: SVAR field in anonymous union doesn't have a_union bit set"); 4094130803Smarcel /* Get space to record the next field/data-member. */ 4095130803Smarcel new = (struct nextfield *) alloca (sizeof (struct nextfield)); 4096130803Smarcel memset (new, 0, sizeof (struct nextfield)); 4097130803Smarcel new->next = list; 4098130803Smarcel list = new; 4099130803Smarcel 4100130803Smarcel list->field.name = VT (objfile) + fn_fieldp->dsvar.name; 4101130803Smarcel FIELD_BITPOS (list->field) = 0; /* FIXME is this always true? */ 4102130803Smarcel FIELD_BITSIZE (list->field) = 0; /* use length from type */ 4103130803Smarcel FIELD_STATIC_KIND (list->field) = 0; 4104130803Smarcel memtype = hpread_type_lookup (fn_fieldp->dsvar.type, objfile); 4105130803Smarcel list->field.type = memtype; 4106130803Smarcel list->attributes = 0; 4107130803Smarcel /* No info to set visibility -- always public */ 4108130803Smarcel nfields++; 4109130803Smarcel } 4110130803Smarcel else if (fn_fieldp->dblock.kind == DNTT_TYPE_DVAR) 4111130803Smarcel { 4112130803Smarcel /* Field of anonymous union; union is not inside a class */ 4113130803Smarcel if (!fn_fieldp->ddvar.a_union) 4114130803Smarcel warning ("Debug info inconsistent: DVAR field in anonymous union doesn't have a_union bit set"); 4115130803Smarcel /* Get space to record the next field/data-member. */ 4116130803Smarcel new = (struct nextfield *) alloca (sizeof (struct nextfield)); 4117130803Smarcel memset (new, 0, sizeof (struct nextfield)); 4118130803Smarcel new->next = list; 4119130803Smarcel list = new; 4120130803Smarcel 4121130803Smarcel list->field.name = VT (objfile) + fn_fieldp->ddvar.name; 4122130803Smarcel FIELD_BITPOS (list->field) = 0; /* FIXME is this always true? */ 4123130803Smarcel FIELD_BITSIZE (list->field) = 0; /* use length from type */ 4124130803Smarcel FIELD_STATIC_KIND (list->field) = 0; 4125130803Smarcel memtype = hpread_type_lookup (fn_fieldp->ddvar.type, objfile); 4126130803Smarcel list->field.type = memtype; 4127130803Smarcel list->attributes = 0; 4128130803Smarcel /* No info to set visibility -- always public */ 4129130803Smarcel nfields++; 4130130803Smarcel } 4131130803Smarcel else 4132130803Smarcel { /* Not a method, nor a static data member, nor an anon union field */ 4133130803Smarcel 4134130803Smarcel /* This case is for miscellaneous type entries (local enums, 4135130803Smarcel local function templates, etc.) that can be present 4136130803Smarcel inside a class. */ 4137130803Smarcel 4138130803Smarcel /* Enums -- will be handled by other code that takes care 4139130803Smarcel of DNTT_TYPE_ENUM; here we see only DNTT_TYPE_MEMENUM so 4140130803Smarcel it's not clear we could have handled them here at all. */ 4141130803Smarcel /* FUNC_TEMPLATE: is handled by other code (?). */ 4142130803Smarcel /* MEMACCESS: modified access for inherited member. Not 4143130803Smarcel sure what to do with this, ignoriing it at present. */ 4144130803Smarcel 4145130803Smarcel /* What other entries can appear following a GENFIELD which 4146130803Smarcel we do not handle above? (MODIFIER, VFUNC handled above.) */ 4147130803Smarcel 4148130803Smarcel if ((fn_fieldp->dblock.kind != DNTT_TYPE_MEMACCESS) && 4149130803Smarcel (fn_fieldp->dblock.kind != DNTT_TYPE_MEMENUM) && 4150130803Smarcel (fn_fieldp->dblock.kind != DNTT_TYPE_FUNC_TEMPLATE)) 4151130803Smarcel warning ("Internal error: Unexpected debug record kind %d found following DNTT_GENFIELD", 4152130803Smarcel fn_fieldp->dblock.kind); 4153130803Smarcel } 4154130803Smarcel /* walk to the next FIELD or GENFIELD */ 4155130803Smarcel field = fieldp->dgenfield.nextfield; 4156130803Smarcel 4157130803Smarcel } 4158130803Smarcel else if (fieldp->dblock.kind == DNTT_TYPE_FIELD) 4159130803Smarcel { 4160130803Smarcel 4161130803Smarcel /* Ordinary structure/union/class field */ 4162130803Smarcel struct type *anon_union_type; 4163130803Smarcel 4164130803Smarcel /* Get space to record the next field/data-member. */ 4165130803Smarcel new = (struct nextfield *) alloca (sizeof (struct nextfield)); 4166130803Smarcel memset (new, 0, sizeof (struct nextfield)); 4167130803Smarcel new->next = list; 4168130803Smarcel list = new; 4169130803Smarcel 4170130803Smarcel list->field.name = VT (objfile) + fieldp->dfield.name; 4171130803Smarcel 4172130803Smarcel 4173130803Smarcel /* A FIELD by itself (without a GENFIELD) can also be a static 4174130803Smarcel member. Mark it as static with a physname of NULL. 4175130803Smarcel fix_static_member_physnames will assign the physname later. */ 4176130803Smarcel if (fieldp->dfield.staticmem) 4177130803Smarcel { 4178130803Smarcel SET_FIELD_PHYSNAME (list->field, NULL); 4179130803Smarcel FIELD_BITPOS (list->field) = 0; 4180130803Smarcel FIELD_BITSIZE (list->field) = 0; 4181130803Smarcel } 4182130803Smarcel else 4183130803Smarcel /* Non-static data member */ 4184130803Smarcel { 4185130803Smarcel FIELD_STATIC_KIND (list->field) = 0; 4186130803Smarcel FIELD_BITPOS (list->field) = fieldp->dfield.bitoffset; 4187130803Smarcel if (fieldp->dfield.bitlength % 8) 4188130803Smarcel FIELD_BITSIZE (list->field) = fieldp->dfield.bitlength; 4189130803Smarcel else 4190130803Smarcel FIELD_BITSIZE (list->field) = 0; 4191130803Smarcel } 4192130803Smarcel 4193130803Smarcel memtype = hpread_type_lookup (fieldp->dfield.type, objfile); 4194130803Smarcel FIELD_TYPE (list->field) = memtype; 4195130803Smarcel list->attributes = 0; 4196130803Smarcel switch (fieldp->dfield.visibility) 4197130803Smarcel { 4198130803Smarcel case 1: 4199130803Smarcel B_SET (&(list->attributes), ATTR_PROTECT); 4200130803Smarcel break; 4201130803Smarcel case 2: 4202130803Smarcel B_SET (&(list->attributes), ATTR_PRIVATE); 4203130803Smarcel break; 4204130803Smarcel } 4205130803Smarcel nfields++; 4206130803Smarcel 4207130803Smarcel 4208130803Smarcel /* Note 1: First, we have to check if the current field is an anonymous 4209130803Smarcel union. If it is, then *its* fields are threaded along in the 4210130803Smarcel nextfield chain. :-( This was supposed to help debuggers, but is 4211130803Smarcel really just a nuisance since we deal with anonymous unions anyway by 4212130803Smarcel checking that the name is null. So anyway, we skip over the fields 4213130803Smarcel of the anonymous union. pai/1997-08-22 */ 4214130803Smarcel /* Note 2: In addition, the bitoffsets for the fields of the anon union 4215130803Smarcel are relative to the enclosing struct, *NOT* relative to the anon 4216130803Smarcel union! This is an even bigger nuisance -- we have to go in and munge 4217130803Smarcel the anon union's type information appropriately. pai/1997-08-22 */ 4218130803Smarcel 4219130803Smarcel /* Both tasks noted above are done by a separate function. This takes us 4220130803Smarcel to the next FIELD or GENFIELD, skipping anon unions, and recursively 4221130803Smarcel processing intermediate types. */ 4222130803Smarcel field = hpread_get_next_skip_over_anon_unions (1, field, &fieldp, objfile); 4223130803Smarcel 4224130803Smarcel } 4225130803Smarcel else 4226130803Smarcel { 4227130803Smarcel /* neither field nor genfield ?? is this possible?? */ 4228130803Smarcel /* pai:: FIXME walk to the next -- how? */ 4229130803Smarcel warning ("Internal error: unexpected DNTT kind %d encountered as field of struct", 4230130803Smarcel fieldp->dblock.kind); 4231130803Smarcel warning ("Skipping remaining fields of struct"); 4232130803Smarcel break; /* get out of loop of fields */ 4233130803Smarcel } 4234130803Smarcel } 4235130803Smarcel 4236130803Smarcel /* If it's a template, read in the instantiation list */ 4237130803Smarcel if (dn_bufp->dblock.kind == DNTT_TYPE_TEMPLATE) 4238130803Smarcel { 4239130803Smarcel ninstantiations = 0; 4240130803Smarcel field = dn_bufp->dtemplate.expansions; 4241130803Smarcel while (field.word && field.word != DNTTNIL) 4242130803Smarcel { 4243130803Smarcel fieldp = hpread_get_lntt (field.dnttp.index, objfile); 4244130803Smarcel 4245130803Smarcel /* The expansions or nextexp should point to a tagdef */ 4246130803Smarcel if (fieldp->dblock.kind != DNTT_TYPE_TAGDEF) 4247130803Smarcel break; 4248130803Smarcel 4249130803Smarcel i_new = (struct next_instantiation *) alloca (sizeof (struct next_instantiation)); 4250130803Smarcel memset (i_new, 0, sizeof (struct next_instantiation)); 4251130803Smarcel i_new->next = i_list; 4252130803Smarcel i_list = i_new; 4253130803Smarcel i_list->t = hpread_type_lookup (field, objfile); 4254130803Smarcel ninstantiations++; 4255130803Smarcel 4256130803Smarcel /* And the "type" field of that should point to a class */ 4257130803Smarcel field = fieldp->dtag.type; 4258130803Smarcel fieldp = hpread_get_lntt (field.dnttp.index, objfile); 4259130803Smarcel if (fieldp->dblock.kind != DNTT_TYPE_CLASS) 4260130803Smarcel break; 4261130803Smarcel 4262130803Smarcel /* Get the next expansion */ 4263130803Smarcel field = fieldp->dclass.nextexp; 4264130803Smarcel } 4265130803Smarcel } 4266130803Smarcel TYPE_NINSTANTIATIONS (type) = ninstantiations; 4267130803Smarcel if (ninstantiations > 0) 4268130803Smarcel TYPE_INSTANTIATIONS (type) = (struct type **) 4269130803Smarcel obstack_alloc (&objfile->objfile_obstack, sizeof (struct type *) * ninstantiations); 4270130803Smarcel for (n = ninstantiations; i_list; i_list = i_list->next) 4271130803Smarcel { 4272130803Smarcel n -= 1; 4273130803Smarcel TYPE_INSTANTIATION (type, n) = i_list->t; 4274130803Smarcel } 4275130803Smarcel 4276130803Smarcel 4277130803Smarcel /* Copy the field-list to GDB's symbol table */ 4278130803Smarcel TYPE_NFIELDS (type) = nfields; 4279130803Smarcel TYPE_N_BASECLASSES (type) = n_base_classes; 4280130803Smarcel TYPE_FIELDS (type) = (struct field *) 4281130803Smarcel obstack_alloc (&objfile->objfile_obstack, sizeof (struct field) * nfields); 4282130803Smarcel /* Copy the saved-up fields into the field vector. */ 4283130803Smarcel for (n = nfields, tmp_list = list; tmp_list; tmp_list = tmp_list->next) 4284130803Smarcel { 4285130803Smarcel n -= 1; 4286130803Smarcel TYPE_FIELD (type, n) = tmp_list->field; 4287130803Smarcel } 4288130803Smarcel 4289130803Smarcel /* Copy the "function-field-list" (i.e., the list of member 4290130803Smarcel * functions in the class) to GDB's symbol table 4291130803Smarcel */ 4292130803Smarcel TYPE_NFN_FIELDS (type) = n_fn_fields; 4293130803Smarcel TYPE_NFN_FIELDS_TOTAL (type) = n_fn_fields_total; 4294130803Smarcel TYPE_FN_FIELDLISTS (type) = (struct fn_fieldlist *) 4295130803Smarcel obstack_alloc (&objfile->objfile_obstack, sizeof (struct fn_fieldlist) * n_fn_fields); 4296130803Smarcel for (n = n_fn_fields; fn_list; fn_list = fn_list->next) 4297130803Smarcel { 4298130803Smarcel n -= 1; 4299130803Smarcel TYPE_FN_FIELDLIST (type, n) = fn_list->field; 4300130803Smarcel } 4301130803Smarcel 4302130803Smarcel /* pai:: FIXME -- perhaps each bitvector should be created individually */ 4303130803Smarcel for (n = nfields, tmp_list = list; tmp_list; tmp_list = tmp_list->next) 4304130803Smarcel { 4305130803Smarcel n -= 1; 4306130803Smarcel if (tmp_list->attributes) 4307130803Smarcel { 4308130803Smarcel need_bitvectors = 1; 4309130803Smarcel break; 4310130803Smarcel } 4311130803Smarcel } 4312130803Smarcel 4313130803Smarcel if (need_bitvectors) 4314130803Smarcel { 4315130803Smarcel /* pai:: this step probably redundant */ 4316130803Smarcel ALLOCATE_CPLUS_STRUCT_TYPE (type); 4317130803Smarcel 4318130803Smarcel TYPE_FIELD_VIRTUAL_BITS (type) = 4319130803Smarcel (B_TYPE *) TYPE_ALLOC (type, B_BYTES (nfields)); 4320130803Smarcel B_CLRALL (TYPE_FIELD_VIRTUAL_BITS (type), nfields); 4321130803Smarcel 4322130803Smarcel TYPE_FIELD_PRIVATE_BITS (type) = 4323130803Smarcel (B_TYPE *) TYPE_ALLOC (type, B_BYTES (nfields)); 4324130803Smarcel B_CLRALL (TYPE_FIELD_PRIVATE_BITS (type), nfields); 4325130803Smarcel 4326130803Smarcel TYPE_FIELD_PROTECTED_BITS (type) = 4327130803Smarcel (B_TYPE *) TYPE_ALLOC (type, B_BYTES (nfields)); 4328130803Smarcel B_CLRALL (TYPE_FIELD_PROTECTED_BITS (type), nfields); 4329130803Smarcel 4330130803Smarcel /* this field vector isn't actually used with HP aCC */ 4331130803Smarcel TYPE_FIELD_IGNORE_BITS (type) = 4332130803Smarcel (B_TYPE *) TYPE_ALLOC (type, B_BYTES (nfields)); 4333130803Smarcel B_CLRALL (TYPE_FIELD_IGNORE_BITS (type), nfields); 4334130803Smarcel 4335130803Smarcel while (nfields-- > 0) 4336130803Smarcel { 4337130803Smarcel if (B_TST (&(list->attributes), ATTR_VIRTUAL)) 4338130803Smarcel SET_TYPE_FIELD_VIRTUAL (type, nfields); 4339130803Smarcel if (B_TST (&(list->attributes), ATTR_PRIVATE)) 4340130803Smarcel SET_TYPE_FIELD_PRIVATE (type, nfields); 4341130803Smarcel if (B_TST (&(list->attributes), ATTR_PROTECT)) 4342130803Smarcel SET_TYPE_FIELD_PROTECTED (type, nfields); 4343130803Smarcel 4344130803Smarcel list = list->next; 4345130803Smarcel } 4346130803Smarcel } 4347130803Smarcel else 4348130803Smarcel { 4349130803Smarcel TYPE_FIELD_VIRTUAL_BITS (type) = NULL; 4350130803Smarcel TYPE_FIELD_PROTECTED_BITS (type) = NULL; 4351130803Smarcel TYPE_FIELD_PRIVATE_BITS (type) = NULL; 4352130803Smarcel } 4353130803Smarcel 4354130803Smarcel if (has_vtable (type)) 4355130803Smarcel { 4356130803Smarcel /* Allocate space for class runtime information */ 4357130803Smarcel TYPE_RUNTIME_PTR (type) = (struct runtime_info *) xmalloc (sizeof (struct runtime_info)); 4358130803Smarcel /* Set flag for vtable */ 4359130803Smarcel TYPE_VTABLE (type) = 1; 4360130803Smarcel /* The first non-virtual base class with a vtable. */ 4361130803Smarcel TYPE_PRIMARY_BASE (type) = primary_base_class (type); 4362130803Smarcel /* The virtual base list. */ 4363130803Smarcel TYPE_VIRTUAL_BASE_LIST (type) = virtual_base_list (type); 4364130803Smarcel } 4365130803Smarcel else 4366130803Smarcel TYPE_RUNTIME_PTR (type) = NULL; 4367130803Smarcel 4368130803Smarcel /* If this is a local type (C++ - declared inside a function), record file name & line # */ 4369130803Smarcel if (hpread_get_scope_depth (dn_bufp, objfile, 1 /* no need for real depth */ )) 4370130803Smarcel { 4371130803Smarcel TYPE_LOCALTYPE_PTR (type) = (struct local_type_info *) xmalloc (sizeof (struct local_type_info)); 4372130803Smarcel TYPE_LOCALTYPE_FILE (type) = (char *) xmalloc (strlen (current_subfile->name) + 1); 4373130803Smarcel strcpy (TYPE_LOCALTYPE_FILE (type), current_subfile->name); 4374130803Smarcel if (current_subfile->line_vector && (current_subfile->line_vector->nitems > 0)) 4375130803Smarcel TYPE_LOCALTYPE_LINE (type) = current_subfile->line_vector->item[current_subfile->line_vector->nitems - 1].line; 4376130803Smarcel else 4377130803Smarcel TYPE_LOCALTYPE_LINE (type) = 0; 4378130803Smarcel } 4379130803Smarcel else 4380130803Smarcel TYPE_LOCALTYPE_PTR (type) = NULL; 4381130803Smarcel 4382130803Smarcel /* Clear the global saying what template we are in the middle of processing */ 4383130803Smarcel current_template = NULL; 4384130803Smarcel 4385130803Smarcel return type; 4386130803Smarcel} 4387130803Smarcel 4388130803Smarcel/* Adjust the physnames for each static member of a struct 4389130803Smarcel or class type to be something like "A::x"; then various 4390130803Smarcel other pieces of code that do a lookup_symbol on the phyname 4391130803Smarcel work correctly. 4392130803Smarcel TYPE is a pointer to the struct/class type 4393130803Smarcel NAME is a char * (string) which is the class/struct name 4394130803Smarcel Void return */ 4395130803Smarcel 4396130803Smarcelstatic void 4397130803Smarcelfix_static_member_physnames (struct type *type, char *class_name, 4398130803Smarcel struct objfile *objfile) 4399130803Smarcel{ 4400130803Smarcel int i; 4401130803Smarcel 4402130803Smarcel /* We fix the member names only for classes or structs */ 4403130803Smarcel if (TYPE_CODE (type) != TYPE_CODE_STRUCT) 4404130803Smarcel return; 4405130803Smarcel 4406130803Smarcel for (i = 0; i < TYPE_NFIELDS (type); i++) 4407130803Smarcel if (TYPE_FIELD_STATIC (type, i)) 4408130803Smarcel { 4409130803Smarcel if (TYPE_FIELD_STATIC_PHYSNAME (type, i)) 4410130803Smarcel return; /* physnames are already set */ 4411130803Smarcel 4412130803Smarcel SET_FIELD_PHYSNAME (TYPE_FIELDS (type)[i], 4413130803Smarcel obstack_alloc (&objfile->objfile_obstack, 4414130803Smarcel strlen (class_name) + strlen (TYPE_FIELD_NAME (type, i)) + 3)); 4415130803Smarcel strcpy (TYPE_FIELD_STATIC_PHYSNAME (type, i), class_name); 4416130803Smarcel strcat (TYPE_FIELD_STATIC_PHYSNAME (type, i), "::"); 4417130803Smarcel strcat (TYPE_FIELD_STATIC_PHYSNAME (type, i), TYPE_FIELD_NAME (type, i)); 4418130803Smarcel } 4419130803Smarcel} 4420130803Smarcel 4421130803Smarcel/* Fix-up the type structure for a CLASS so that the type entry 4422130803Smarcel * for a method (previously marked with a null type in hpread_read_struct_type() 4423130803Smarcel * is set correctly to METHOD. 4424130803Smarcel * OBJFILE is as for other such functions. 4425130803Smarcel * Void return. */ 4426130803Smarcel 4427130803Smarcelstatic void 4428130803Smarcelfixup_class_method_type (struct type *class, struct type *method, 4429130803Smarcel struct objfile *objfile) 4430130803Smarcel{ 4431130803Smarcel int i, j, k; 4432130803Smarcel 4433130803Smarcel if (!class || !method || !objfile) 4434130803Smarcel return; 4435130803Smarcel 4436130803Smarcel /* Only for types that have methods */ 4437130803Smarcel if ((TYPE_CODE (class) != TYPE_CODE_CLASS) && 4438130803Smarcel (TYPE_CODE (class) != TYPE_CODE_UNION)) 4439130803Smarcel return; 4440130803Smarcel 4441130803Smarcel /* Loop over all methods and find the one marked with a NULL type */ 4442130803Smarcel for (i = 0; i < TYPE_NFN_FIELDS (class); i++) 4443130803Smarcel for (j = 0; j < TYPE_FN_FIELDLIST_LENGTH (class, i); j++) 4444130803Smarcel if (TYPE_FN_FIELD_TYPE (TYPE_FN_FIELDLIST1 (class, i), j) == NULL) 4445130803Smarcel { 4446130803Smarcel /* Set the method type */ 4447130803Smarcel TYPE_FN_FIELD_TYPE (TYPE_FN_FIELDLIST1 (class, i), j) = method; 4448130803Smarcel 4449130803Smarcel /* Break out of both loops -- only one method to fix up in a class */ 4450130803Smarcel goto finish; 4451130803Smarcel } 4452130803Smarcel 4453130803Smarcelfinish: 4454130803Smarcel TYPE_FLAGS (class) &= ~TYPE_FLAG_INCOMPLETE; 4455130803Smarcel} 4456130803Smarcel 4457130803Smarcel 4458130803Smarcel/* If we're in the middle of processing a template, get a pointer 4459130803Smarcel * to the Nth template argument. 4460130803Smarcel * An example may make this clearer: 4461130803Smarcel * template <class T1, class T2> class q2 { 4462130803Smarcel * public: 4463130803Smarcel * T1 a; 4464130803Smarcel * T2 b; 4465130803Smarcel * }; 4466130803Smarcel * The type for "a" will be "first template arg" and 4467130803Smarcel * the type for "b" will be "second template arg". 4468130803Smarcel * We need to look these up in order to fill in "a" and "b"'s type. 4469130803Smarcel * This is called from hpread_type_lookup(). 4470130803Smarcel */ 4471130803Smarcelstatic struct type * 4472130803Smarcelhpread_get_nth_template_arg (struct objfile *objfile, int n) 4473130803Smarcel{ 4474130803Smarcel if (current_template != NULL) 4475130803Smarcel return TYPE_TEMPLATE_ARG (current_template, n).type; 4476130803Smarcel else 4477130803Smarcel return lookup_fundamental_type (objfile, FT_TEMPLATE_ARG); 4478130803Smarcel} 4479130803Smarcel 4480130803Smarcel/* Read in and internalize a TEMPL_ARG (template arg) symbol. */ 4481130803Smarcel 4482130803Smarcelstatic struct type * 4483130803Smarcelhpread_read_templ_arg_type (dnttpointer hp_type, union dnttentry *dn_bufp, 4484130803Smarcel struct objfile *objfile, char *name) 4485130803Smarcel{ 4486130803Smarcel struct type *type; 4487130803Smarcel 4488130803Smarcel /* See if it's something we've already deal with. */ 4489130803Smarcel type = hpread_alloc_type (hp_type, objfile); 4490130803Smarcel if (TYPE_CODE (type) == TYPE_CODE_TEMPLATE_ARG) 4491130803Smarcel return type; 4492130803Smarcel 4493130803Smarcel /* Nope. Fill in the appropriate fields. */ 4494130803Smarcel TYPE_CODE (type) = TYPE_CODE_TEMPLATE_ARG; 4495130803Smarcel TYPE_LENGTH (type) = 0; 4496130803Smarcel TYPE_NFIELDS (type) = 0; 4497130803Smarcel TYPE_NAME (type) = name; 4498130803Smarcel return type; 4499130803Smarcel} 4500130803Smarcel 4501130803Smarcel/* Read in and internalize a set debug symbol. */ 4502130803Smarcel 4503130803Smarcelstatic struct type * 4504130803Smarcelhpread_read_set_type (dnttpointer hp_type, union dnttentry *dn_bufp, 4505130803Smarcel struct objfile *objfile) 4506130803Smarcel{ 4507130803Smarcel struct type *type; 4508130803Smarcel 4509130803Smarcel /* See if it's something we've already deal with. */ 4510130803Smarcel type = hpread_alloc_type (hp_type, objfile); 4511130803Smarcel if (TYPE_CODE (type) == TYPE_CODE_SET) 4512130803Smarcel return type; 4513130803Smarcel 4514130803Smarcel /* Nope. Fill in the appropriate fields. */ 4515130803Smarcel TYPE_CODE (type) = TYPE_CODE_SET; 4516130803Smarcel TYPE_LENGTH (type) = dn_bufp->dset.bitlength / 8; 4517130803Smarcel TYPE_NFIELDS (type) = 0; 4518130803Smarcel TYPE_TARGET_TYPE (type) = hpread_type_lookup (dn_bufp->dset.subtype, 4519130803Smarcel objfile); 4520130803Smarcel return type; 4521130803Smarcel} 4522130803Smarcel 4523130803Smarcel/* Read in and internalize an array debug symbol. */ 4524130803Smarcel 4525130803Smarcelstatic struct type * 4526130803Smarcelhpread_read_array_type (dnttpointer hp_type, union dnttentry *dn_bufp, 4527130803Smarcel struct objfile *objfile) 4528130803Smarcel{ 4529130803Smarcel struct type *type; 4530130803Smarcel 4531130803Smarcel /* Allocate an array type symbol. 4532130803Smarcel * Why no check for already-read here, like in the other 4533130803Smarcel * hpread_read_xxx_type routines? Because it kept us 4534130803Smarcel * from properly determining the size of the array! 4535130803Smarcel */ 4536130803Smarcel type = hpread_alloc_type (hp_type, objfile); 4537130803Smarcel 4538130803Smarcel TYPE_CODE (type) = TYPE_CODE_ARRAY; 4539130803Smarcel 4540130803Smarcel /* Although the hp-symtab.h does not *require* this to be the case, 4541130803Smarcel * GDB is assuming that "arrayisbytes" and "elemisbytes" be consistent. 4542130803Smarcel * I.e., express both array-length and element-length in bits, 4543130803Smarcel * or express both array-length and element-length in bytes. 4544130803Smarcel */ 4545130803Smarcel if (!((dn_bufp->darray.arrayisbytes && dn_bufp->darray.elemisbytes) || 4546130803Smarcel (!dn_bufp->darray.arrayisbytes && !dn_bufp->darray.elemisbytes))) 4547130803Smarcel { 4548130803Smarcel warning ("error in hpread_array_type.\n"); 4549130803Smarcel return NULL; 4550130803Smarcel } 4551130803Smarcel else if (dn_bufp->darray.arraylength == 0x7fffffff) 4552130803Smarcel { 4553130803Smarcel /* The HP debug format represents char foo[]; as an array with 4554130803Smarcel * length 0x7fffffff. Internally GDB wants to represent this 4555130803Smarcel * as an array of length zero. 4556130803Smarcel */ 4557130803Smarcel TYPE_LENGTH (type) = 0; 4558130803Smarcel } 4559130803Smarcel else if (dn_bufp->darray.arrayisbytes) 4560130803Smarcel TYPE_LENGTH (type) = dn_bufp->darray.arraylength; 4561130803Smarcel else /* arraylength is in bits */ 4562130803Smarcel TYPE_LENGTH (type) = dn_bufp->darray.arraylength / 8; 4563130803Smarcel 4564130803Smarcel TYPE_TARGET_TYPE (type) = hpread_type_lookup (dn_bufp->darray.elemtype, 4565130803Smarcel objfile); 4566130803Smarcel 4567130803Smarcel /* The one "field" is used to store the subscript type */ 4568130803Smarcel /* Since C and C++ multi-dimensional arrays are simply represented 4569130803Smarcel * as: array of array of ..., we only need one subscript-type 4570130803Smarcel * per array. This subscript type is typically a subrange of integer. 4571130803Smarcel * If this gets extended to support languages like Pascal, then 4572130803Smarcel * we need to fix this to represent multi-dimensional arrays properly. 4573130803Smarcel */ 4574130803Smarcel TYPE_NFIELDS (type) = 1; 4575130803Smarcel TYPE_FIELDS (type) = (struct field *) 4576130803Smarcel obstack_alloc (&objfile->objfile_obstack, sizeof (struct field)); 4577130803Smarcel TYPE_FIELD_TYPE (type, 0) = hpread_type_lookup (dn_bufp->darray.indextype, 4578130803Smarcel objfile); 4579130803Smarcel return type; 4580130803Smarcel} 4581130803Smarcel 4582130803Smarcel/* Read in and internalize a subrange debug symbol. */ 4583130803Smarcelstatic struct type * 4584130803Smarcelhpread_read_subrange_type (dnttpointer hp_type, union dnttentry *dn_bufp, 4585130803Smarcel struct objfile *objfile) 4586130803Smarcel{ 4587130803Smarcel struct type *type; 4588130803Smarcel 4589130803Smarcel /* Is it something we've already dealt with. */ 4590130803Smarcel type = hpread_alloc_type (hp_type, objfile); 4591130803Smarcel if (TYPE_CODE (type) == TYPE_CODE_RANGE) 4592130803Smarcel return type; 4593130803Smarcel 4594130803Smarcel /* Nope, internalize it. */ 4595130803Smarcel TYPE_CODE (type) = TYPE_CODE_RANGE; 4596130803Smarcel TYPE_LENGTH (type) = dn_bufp->dsubr.bitlength / 8; 4597130803Smarcel TYPE_NFIELDS (type) = 2; 4598130803Smarcel TYPE_FIELDS (type) 4599130803Smarcel = (struct field *) obstack_alloc (&objfile->objfile_obstack, 4600130803Smarcel 2 * sizeof (struct field)); 4601130803Smarcel 4602130803Smarcel if (dn_bufp->dsubr.dyn_low) 4603130803Smarcel TYPE_FIELD_BITPOS (type, 0) = 0; 4604130803Smarcel else 4605130803Smarcel TYPE_FIELD_BITPOS (type, 0) = dn_bufp->dsubr.lowbound; 4606130803Smarcel 4607130803Smarcel if (dn_bufp->dsubr.dyn_high) 4608130803Smarcel TYPE_FIELD_BITPOS (type, 1) = -1; 4609130803Smarcel else 4610130803Smarcel TYPE_FIELD_BITPOS (type, 1) = dn_bufp->dsubr.highbound; 4611130803Smarcel TYPE_TARGET_TYPE (type) = hpread_type_lookup (dn_bufp->dsubr.subtype, 4612130803Smarcel objfile); 4613130803Smarcel return type; 4614130803Smarcel} 4615130803Smarcel 4616130803Smarcel/* struct type * hpread_type_lookup(hp_type, objfile) 4617130803Smarcel * Arguments: 4618130803Smarcel * hp_type: A pointer into the DNTT specifying what type we 4619130803Smarcel * are about to "look up"., or else [for fundamental types 4620130803Smarcel * like int, float, ...] an "immediate" structure describing 4621130803Smarcel * the type. 4622130803Smarcel * objfile: ? 4623130803Smarcel * Return value: A pointer to a "struct type" (representation of a 4624130803Smarcel * type in GDB's internal symbol table - see gdbtypes.h) 4625130803Smarcel * Routine description: 4626130803Smarcel * There are a variety of places when scanning the DNTT when we 4627130803Smarcel * need to interpret a "type" field. The simplest and most basic 4628130803Smarcel * example is when we're processing the symbol table record 4629130803Smarcel * for a data symbol (a SVAR or DVAR record). That has 4630130803Smarcel * a "type" field specifying the type of the data symbol. That 4631130803Smarcel * "type" field is either an "immediate" type specification (for the 4632130803Smarcel * fundamental types) or a DNTT pointer (for more complicated types). 4633130803Smarcel * For the more complicated types, we may or may not have already 4634130803Smarcel * processed the pointed-to type. (Multiple data symbols can of course 4635130803Smarcel * share the same type). 4636130803Smarcel * The job of hpread_type_lookup() is to process this "type" field. 4637130803Smarcel * Most of the real work is done in subroutines. Here we interpret 4638130803Smarcel * the immediate flag. If not immediate, chase the DNTT pointer to 4639130803Smarcel * find our way to the SOM record describing the type, switch on 4640130803Smarcel * the SOM kind, and then call an appropriate subroutine depending 4641130803Smarcel * on what kind of type we are constructing. (e.g., an array type, 4642130803Smarcel * a struct/class type, etc). 4643130803Smarcel */ 4644130803Smarcelstatic struct type * 4645130803Smarcelhpread_type_lookup (dnttpointer hp_type, struct objfile *objfile) 4646130803Smarcel{ 4647130803Smarcel union dnttentry *dn_bufp; 4648130803Smarcel struct type *tmp_type; 4649130803Smarcel 4650130803Smarcel /* First see if it's a simple builtin type. */ 4651130803Smarcel if (hp_type.dntti.immediate) 4652130803Smarcel { 4653130803Smarcel /* If this is a template argument, the argument number is 4654130803Smarcel * encoded in the bitlength. All other cases, just return 4655130803Smarcel * GDB's representation of this fundamental type. 4656130803Smarcel */ 4657130803Smarcel if (hp_type.dntti.type == HP_TYPE_TEMPLATE_ARG) 4658130803Smarcel return hpread_get_nth_template_arg (objfile, hp_type.dntti.bitlength); 4659130803Smarcel else 4660130803Smarcel return lookup_fundamental_type (objfile, 4661130803Smarcel hpread_type_translate (hp_type)); 4662130803Smarcel } 4663130803Smarcel 4664130803Smarcel /* Not a builtin type. We'll have to read it in. */ 4665130803Smarcel if (hp_type.dnttp.index < LNTT_SYMCOUNT (objfile)) 4666130803Smarcel dn_bufp = hpread_get_lntt (hp_type.dnttp.index, objfile); 4667130803Smarcel else 4668130803Smarcel /* This is a fancy way of returning NULL */ 4669130803Smarcel return lookup_fundamental_type (objfile, FT_VOID); 4670130803Smarcel 4671130803Smarcel switch (dn_bufp->dblock.kind) 4672130803Smarcel { 4673130803Smarcel case DNTT_TYPE_SRCFILE: 4674130803Smarcel case DNTT_TYPE_MODULE: 4675130803Smarcel case DNTT_TYPE_ENTRY: 4676130803Smarcel case DNTT_TYPE_BEGIN: 4677130803Smarcel case DNTT_TYPE_END: 4678130803Smarcel case DNTT_TYPE_IMPORT: 4679130803Smarcel case DNTT_TYPE_LABEL: 4680130803Smarcel case DNTT_TYPE_FPARAM: 4681130803Smarcel case DNTT_TYPE_SVAR: 4682130803Smarcel case DNTT_TYPE_DVAR: 4683130803Smarcel case DNTT_TYPE_CONST: 4684130803Smarcel case DNTT_TYPE_MEMENUM: 4685130803Smarcel case DNTT_TYPE_VARIANT: 4686130803Smarcel case DNTT_TYPE_FILE: 4687130803Smarcel case DNTT_TYPE_WITH: 4688130803Smarcel case DNTT_TYPE_COMMON: 4689130803Smarcel case DNTT_TYPE_COBSTRUCT: 4690130803Smarcel case DNTT_TYPE_XREF: 4691130803Smarcel case DNTT_TYPE_SA: 4692130803Smarcel case DNTT_TYPE_MACRO: 4693130803Smarcel case DNTT_TYPE_BLOCKDATA: 4694130803Smarcel case DNTT_TYPE_CLASS_SCOPE: 4695130803Smarcel case DNTT_TYPE_MEMACCESS: 4696130803Smarcel case DNTT_TYPE_INHERITANCE: 4697130803Smarcel case DNTT_TYPE_OBJECT_ID: 4698130803Smarcel case DNTT_TYPE_FRIEND_CLASS: 4699130803Smarcel case DNTT_TYPE_FRIEND_FUNC: 4700130803Smarcel /* These are not types - something went wrong. */ 4701130803Smarcel /* This is a fancy way of returning NULL */ 4702130803Smarcel return lookup_fundamental_type (objfile, FT_VOID); 4703130803Smarcel 4704130803Smarcel case DNTT_TYPE_FUNCTION: 4705130803Smarcel /* We wind up here when dealing with class member functions 4706130803Smarcel * (called from hpread_read_struct_type(), i.e. when processing 4707130803Smarcel * the class definition itself). 4708130803Smarcel */ 4709130803Smarcel return hpread_read_function_type (hp_type, dn_bufp, objfile, 0); 4710130803Smarcel 4711130803Smarcel case DNTT_TYPE_DOC_FUNCTION: 4712130803Smarcel return hpread_read_doc_function_type (hp_type, dn_bufp, objfile, 0); 4713130803Smarcel 4714130803Smarcel case DNTT_TYPE_TYPEDEF: 4715130803Smarcel { 4716130803Smarcel /* A typedef - chase it down by making a recursive call */ 4717130803Smarcel struct type *structtype = hpread_type_lookup (dn_bufp->dtype.type, 4718130803Smarcel objfile); 4719130803Smarcel 4720130803Smarcel /* The following came from the base hpread.c that we inherited. 4721130803Smarcel * It is WRONG so I have commented it out. - RT 4722130803Smarcel *... 4723130803Smarcel 4724130803Smarcel char *suffix; 4725130803Smarcel suffix = VT (objfile) + dn_bufp->dtype.name; 4726130803Smarcel TYPE_NAME (structtype) = suffix; 4727130803Smarcel 4728130803Smarcel * ... further explanation .... 4729130803Smarcel * 4730130803Smarcel * What we have here is a typedef pointing to a typedef. 4731130803Smarcel * E.g., 4732130803Smarcel * typedef int foo; 4733130803Smarcel * typedef foo fum; 4734130803Smarcel * 4735130803Smarcel * What we desire to build is (these are pictures 4736130803Smarcel * of "struct type"'s): 4737130803Smarcel * 4738130803Smarcel * +---------+ +----------+ +------------+ 4739130803Smarcel * | typedef | | typedef | | fund. type | 4740130803Smarcel * | type| -> | type| -> | | 4741130803Smarcel * | "fum" | | "foo" | | "int" | 4742130803Smarcel * +---------+ +----------+ +------------+ 4743130803Smarcel * 4744130803Smarcel * What this commented-out code is doing is smashing the 4745130803Smarcel * name of pointed-to-type to be the same as the pointed-from 4746130803Smarcel * type. So we wind up with something like: 4747130803Smarcel * 4748130803Smarcel * +---------+ +----------+ +------------+ 4749130803Smarcel * | typedef | | typedef | | fund. type | 4750130803Smarcel * | type| -> | type| -> | | 4751130803Smarcel * | "fum" | | "fum" | | "fum" | 4752130803Smarcel * +---------+ +----------+ +------------+ 4753130803Smarcel * 4754130803Smarcel */ 4755130803Smarcel 4756130803Smarcel return structtype; 4757130803Smarcel } 4758130803Smarcel 4759130803Smarcel case DNTT_TYPE_TAGDEF: 4760130803Smarcel { 4761130803Smarcel /* Just a little different from above. We have to tack on 4762130803Smarcel * an identifier of some kind (struct, union, enum, class, etc). 4763130803Smarcel */ 4764130803Smarcel struct type *structtype = hpread_type_lookup (dn_bufp->dtype.type, 4765130803Smarcel objfile); 4766130803Smarcel char *prefix, *suffix; 4767130803Smarcel suffix = VT (objfile) + dn_bufp->dtype.name; 4768130803Smarcel 4769130803Smarcel /* Lookup the next type in the list. It should be a structure, 4770130803Smarcel * union, class, enum, or template type. 4771130803Smarcel * We will need to attach that to our name. 4772130803Smarcel */ 4773130803Smarcel if (dn_bufp->dtype.type.dnttp.index < LNTT_SYMCOUNT (objfile)) 4774130803Smarcel dn_bufp = hpread_get_lntt (dn_bufp->dtype.type.dnttp.index, objfile); 4775130803Smarcel else 4776130803Smarcel { 4777130803Smarcel complaint (&symfile_complaints, "error in hpread_type_lookup()."); 4778130803Smarcel return NULL; 4779130803Smarcel } 4780130803Smarcel 4781130803Smarcel if (dn_bufp->dblock.kind == DNTT_TYPE_STRUCT) 4782130803Smarcel { 4783130803Smarcel prefix = "struct "; 4784130803Smarcel } 4785130803Smarcel else if (dn_bufp->dblock.kind == DNTT_TYPE_UNION) 4786130803Smarcel { 4787130803Smarcel prefix = "union "; 4788130803Smarcel } 4789130803Smarcel else if (dn_bufp->dblock.kind == DNTT_TYPE_CLASS) 4790130803Smarcel { 4791130803Smarcel /* Further field for CLASS saying how it was really declared */ 4792130803Smarcel /* 0==class, 1==union, 2==struct */ 4793130803Smarcel if (dn_bufp->dclass.class_decl == 0) 4794130803Smarcel prefix = "class "; 4795130803Smarcel else if (dn_bufp->dclass.class_decl == 1) 4796130803Smarcel prefix = "union "; 4797130803Smarcel else if (dn_bufp->dclass.class_decl == 2) 4798130803Smarcel prefix = "struct "; 4799130803Smarcel else 4800130803Smarcel prefix = ""; 4801130803Smarcel } 4802130803Smarcel else if (dn_bufp->dblock.kind == DNTT_TYPE_ENUM) 4803130803Smarcel { 4804130803Smarcel prefix = "enum "; 4805130803Smarcel } 4806130803Smarcel else if (dn_bufp->dblock.kind == DNTT_TYPE_TEMPLATE) 4807130803Smarcel { 4808130803Smarcel prefix = "template "; 4809130803Smarcel } 4810130803Smarcel else 4811130803Smarcel { 4812130803Smarcel prefix = ""; 4813130803Smarcel } 4814130803Smarcel 4815130803Smarcel /* Build the correct name. */ 4816130803Smarcel TYPE_NAME (structtype) 4817130803Smarcel = (char *) obstack_alloc (&objfile->objfile_obstack, 4818130803Smarcel strlen (prefix) + strlen (suffix) + 1); 4819130803Smarcel TYPE_NAME (structtype) = strcpy (TYPE_NAME (structtype), prefix); 4820130803Smarcel TYPE_NAME (structtype) = strcat (TYPE_NAME (structtype), suffix); 4821130803Smarcel TYPE_TAG_NAME (structtype) = suffix; 4822130803Smarcel 4823130803Smarcel /* For classes/structs, we have to set the static member "physnames" 4824130803Smarcel to point to strings like "Class::Member" */ 4825130803Smarcel if (TYPE_CODE (structtype) == TYPE_CODE_STRUCT) 4826130803Smarcel fix_static_member_physnames (structtype, suffix, objfile); 4827130803Smarcel 4828130803Smarcel return structtype; 4829130803Smarcel } 4830130803Smarcel 4831130803Smarcel case DNTT_TYPE_POINTER: 4832130803Smarcel /* Pointer type - call a routine in gdbtypes.c that constructs 4833130803Smarcel * the appropriate GDB type. 4834130803Smarcel */ 4835130803Smarcel return make_pointer_type ( 4836130803Smarcel hpread_type_lookup (dn_bufp->dptr.pointsto, 4837130803Smarcel objfile), 4838130803Smarcel NULL); 4839130803Smarcel 4840130803Smarcel case DNTT_TYPE_REFERENCE: 4841130803Smarcel /* C++ reference type - call a routine in gdbtypes.c that constructs 4842130803Smarcel * the appropriate GDB type. 4843130803Smarcel */ 4844130803Smarcel return make_reference_type ( 4845130803Smarcel hpread_type_lookup (dn_bufp->dreference.pointsto, 4846130803Smarcel objfile), 4847130803Smarcel NULL); 4848130803Smarcel 4849130803Smarcel case DNTT_TYPE_ENUM: 4850130803Smarcel return hpread_read_enum_type (hp_type, dn_bufp, objfile); 4851130803Smarcel case DNTT_TYPE_SET: 4852130803Smarcel return hpread_read_set_type (hp_type, dn_bufp, objfile); 4853130803Smarcel case DNTT_TYPE_SUBRANGE: 4854130803Smarcel return hpread_read_subrange_type (hp_type, dn_bufp, objfile); 4855130803Smarcel case DNTT_TYPE_ARRAY: 4856130803Smarcel return hpread_read_array_type (hp_type, dn_bufp, objfile); 4857130803Smarcel case DNTT_TYPE_STRUCT: 4858130803Smarcel case DNTT_TYPE_UNION: 4859130803Smarcel return hpread_read_struct_type (hp_type, dn_bufp, objfile); 4860130803Smarcel case DNTT_TYPE_FIELD: 4861130803Smarcel return hpread_type_lookup (dn_bufp->dfield.type, objfile); 4862130803Smarcel 4863130803Smarcel case DNTT_TYPE_FUNCTYPE: 4864130803Smarcel /* Here we want to read the function SOMs and return a 4865130803Smarcel * type for it. We get here, for instance, when processing 4866130803Smarcel * pointer-to-function type. 4867130803Smarcel */ 4868130803Smarcel return hpread_read_function_type (hp_type, dn_bufp, objfile, 0); 4869130803Smarcel 4870130803Smarcel case DNTT_TYPE_PTRMEM: 4871130803Smarcel /* Declares a C++ pointer-to-data-member type. 4872130803Smarcel * The "pointsto" field defines the class, 4873130803Smarcel * while the "memtype" field defines the pointed-to-type. 4874130803Smarcel */ 4875130803Smarcel { 4876130803Smarcel struct type *ptrmemtype; 4877130803Smarcel struct type *class_type; 4878130803Smarcel struct type *memtype; 4879130803Smarcel memtype = hpread_type_lookup (dn_bufp->dptrmem.memtype, 4880130803Smarcel objfile), 4881130803Smarcel class_type = hpread_type_lookup (dn_bufp->dptrmem.pointsto, 4882130803Smarcel objfile), 4883130803Smarcel ptrmemtype = alloc_type (objfile); 4884130803Smarcel smash_to_member_type (ptrmemtype, class_type, memtype); 4885130803Smarcel return make_pointer_type (ptrmemtype, NULL); 4886130803Smarcel } 4887130803Smarcel break; 4888130803Smarcel 4889130803Smarcel case DNTT_TYPE_PTRMEMFUNC: 4890130803Smarcel /* Defines a C++ pointer-to-function-member type. 4891130803Smarcel * The "pointsto" field defines the class, 4892130803Smarcel * while the "memtype" field defines the pointed-to-type. 4893130803Smarcel */ 4894130803Smarcel { 4895130803Smarcel struct type *ptrmemtype; 4896130803Smarcel struct type *class_type; 4897130803Smarcel struct type *functype; 4898130803Smarcel struct type *retvaltype; 4899130803Smarcel int nargs; 4900130803Smarcel int i; 4901130803Smarcel class_type = hpread_type_lookup (dn_bufp->dptrmem.pointsto, 4902130803Smarcel objfile); 4903130803Smarcel functype = hpread_type_lookup (dn_bufp->dptrmem.memtype, 4904130803Smarcel objfile); 4905130803Smarcel retvaltype = TYPE_TARGET_TYPE (functype); 4906130803Smarcel nargs = TYPE_NFIELDS (functype); 4907130803Smarcel ptrmemtype = alloc_type (objfile); 4908130803Smarcel 4909130803Smarcel smash_to_method_type (ptrmemtype, class_type, retvaltype, 4910130803Smarcel TYPE_FIELDS (functype), 4911130803Smarcel TYPE_NFIELDS (functype), 4912130803Smarcel 0); 4913130803Smarcel return make_pointer_type (ptrmemtype, NULL); 4914130803Smarcel } 4915130803Smarcel break; 4916130803Smarcel 4917130803Smarcel case DNTT_TYPE_CLASS: 4918130803Smarcel return hpread_read_struct_type (hp_type, dn_bufp, objfile); 4919130803Smarcel 4920130803Smarcel case DNTT_TYPE_GENFIELD: 4921130803Smarcel /* Chase pointer from GENFIELD to FIELD, and make recursive 4922130803Smarcel * call on that. 4923130803Smarcel */ 4924130803Smarcel return hpread_type_lookup (dn_bufp->dgenfield.field, objfile); 4925130803Smarcel 4926130803Smarcel case DNTT_TYPE_VFUNC: 4927130803Smarcel /* C++ virtual function. 4928130803Smarcel * We get here in the course of processing a class type which 4929130803Smarcel * contains virtual functions. Just go through another level 4930130803Smarcel * of indirection to get to the pointed-to function SOM. 4931130803Smarcel */ 4932130803Smarcel return hpread_type_lookup (dn_bufp->dvfunc.funcptr, objfile); 4933130803Smarcel 4934130803Smarcel case DNTT_TYPE_MODIFIER: 4935130803Smarcel /* Check the modifiers and then just make a recursive call on 4936130803Smarcel * the "type" pointed to by the modifier DNTT. 4937130803Smarcel * 4938130803Smarcel * pai:: FIXME -- do we ever want to handle "m_duplicate" and 4939130803Smarcel * "m_void" modifiers? Is static_flag really needed here? 4940130803Smarcel * (m_static used for methods of classes, elsewhere). 4941130803Smarcel */ 4942244437Semaste tmp_type = make_cvr_type (dn_bufp->dmodifier.m_const, 4943130803Smarcel dn_bufp->dmodifier.m_volatile, 4944244437Semaste 0, 4945130803Smarcel hpread_type_lookup (dn_bufp->dmodifier.type, objfile), 4946130803Smarcel 0); 4947130803Smarcel return tmp_type; 4948130803Smarcel 4949130803Smarcel 4950130803Smarcel case DNTT_TYPE_MEMFUNC: 4951130803Smarcel /* Member function. Treat like a function. 4952130803Smarcel * I think we get here in the course of processing a 4953130803Smarcel * pointer-to-member-function type... 4954130803Smarcel */ 4955130803Smarcel return hpread_read_function_type (hp_type, dn_bufp, objfile, 0); 4956130803Smarcel 4957130803Smarcel case DNTT_TYPE_DOC_MEMFUNC: 4958130803Smarcel return hpread_read_doc_function_type (hp_type, dn_bufp, objfile, 0); 4959130803Smarcel 4960130803Smarcel case DNTT_TYPE_TEMPLATE: 4961130803Smarcel /* Template - sort of the header for a template definition, 4962130803Smarcel * which like a class, points to a member list and also points 4963130803Smarcel * to a TEMPLATE_ARG list of type-arguments. 4964130803Smarcel */ 4965130803Smarcel return hpread_read_struct_type (hp_type, dn_bufp, objfile); 4966130803Smarcel 4967130803Smarcel case DNTT_TYPE_TEMPLATE_ARG: 4968130803Smarcel { 4969130803Smarcel char *name; 4970130803Smarcel /* The TEMPLATE record points to an argument list of 4971130803Smarcel * TEMPLATE_ARG records, each of which describes one 4972130803Smarcel * of the type-arguments. 4973130803Smarcel */ 4974130803Smarcel name = VT (objfile) + dn_bufp->dtempl_arg.name; 4975130803Smarcel return hpread_read_templ_arg_type (hp_type, dn_bufp, objfile, name); 4976130803Smarcel } 4977130803Smarcel 4978130803Smarcel case DNTT_TYPE_FUNC_TEMPLATE: 4979130803Smarcel /* We wind up here when processing a TEMPLATE type, 4980130803Smarcel * if the template has member function(s). 4981130803Smarcel * Treat it like a FUNCTION. 4982130803Smarcel */ 4983130803Smarcel return hpread_read_function_type (hp_type, dn_bufp, objfile, 0); 4984130803Smarcel 4985130803Smarcel case DNTT_TYPE_LINK: 4986130803Smarcel /* The LINK record is used to link up templates with instantiations. 4987130803Smarcel * There is no type associated with the LINK record per se. 4988130803Smarcel */ 4989130803Smarcel return lookup_fundamental_type (objfile, FT_VOID); 4990130803Smarcel 4991130803Smarcel /* Also not yet handled... */ 4992130803Smarcel /* case DNTT_TYPE_DYN_ARRAY_DESC: */ 4993130803Smarcel /* case DNTT_TYPE_DESC_SUBRANGE: */ 4994130803Smarcel /* case DNTT_TYPE_BEGIN_EXT: */ 4995130803Smarcel /* case DNTT_TYPE_INLN: */ 4996130803Smarcel /* case DNTT_TYPE_INLN_LIST: */ 4997130803Smarcel /* case DNTT_TYPE_ALIAS: */ 4998130803Smarcel default: 4999130803Smarcel /* A fancy way of returning NULL */ 5000130803Smarcel return lookup_fundamental_type (objfile, FT_VOID); 5001130803Smarcel } 5002130803Smarcel} 5003130803Smarcel 5004130803Smarcelstatic sltpointer 5005130803Smarcelhpread_record_lines (struct subfile *subfile, sltpointer s_idx, 5006130803Smarcel sltpointer e_idx, struct objfile *objfile, 5007130803Smarcel CORE_ADDR offset) 5008130803Smarcel{ 5009130803Smarcel union sltentry *sl_bufp; 5010130803Smarcel 5011130803Smarcel while (s_idx <= e_idx) 5012130803Smarcel { 5013130803Smarcel sl_bufp = hpread_get_slt (s_idx, objfile); 5014130803Smarcel /* Only record "normal" entries in the SLT. */ 5015130803Smarcel if (sl_bufp->snorm.sltdesc == SLT_NORMAL 5016130803Smarcel || sl_bufp->snorm.sltdesc == SLT_EXIT) 5017130803Smarcel record_line (subfile, sl_bufp->snorm.line, 5018130803Smarcel sl_bufp->snorm.address + offset); 5019130803Smarcel else if (sl_bufp->snorm.sltdesc == SLT_NORMAL_OFFSET) 5020130803Smarcel record_line (subfile, sl_bufp->snormoff.line, 5021130803Smarcel sl_bufp->snormoff.address + offset); 5022130803Smarcel s_idx++; 5023130803Smarcel } 5024130803Smarcel return e_idx; 5025130803Smarcel} 5026130803Smarcel 5027130803Smarcel/* Given a function "f" which is a member of a class, find 5028130803Smarcel * the classname that it is a member of. Used to construct 5029130803Smarcel * the name (e.g., "c::f") which GDB will put in the 5030130803Smarcel * "demangled name" field of the function's symbol. 5031130803Smarcel * Called from hpread_process_one_debug_symbol() 5032130803Smarcel * If "f" is not a member function, return NULL. 5033130803Smarcel */ 5034130803Smarcelstatic char * 5035130803Smarcelclass_of (struct type *functype) 5036130803Smarcel{ 5037130803Smarcel struct type *first_param_type; 5038130803Smarcel char *first_param_name; 5039130803Smarcel struct type *pointed_to_type; 5040130803Smarcel char *class_name; 5041130803Smarcel 5042130803Smarcel /* Check that the function has a first argument "this", 5043130803Smarcel * and that "this" is a pointer to a class. If not, 5044130803Smarcel * functype is not a member function, so return NULL. 5045130803Smarcel */ 5046130803Smarcel if (TYPE_NFIELDS (functype) == 0) 5047130803Smarcel return NULL; 5048130803Smarcel first_param_name = TYPE_FIELD_NAME (functype, 0); 5049130803Smarcel if (first_param_name == NULL) 5050130803Smarcel return NULL; /* paranoia */ 5051130803Smarcel if (strcmp (first_param_name, "this")) 5052130803Smarcel return NULL; 5053130803Smarcel first_param_type = TYPE_FIELD_TYPE (functype, 0); 5054130803Smarcel if (first_param_type == NULL) 5055130803Smarcel return NULL; /* paranoia */ 5056130803Smarcel if (TYPE_CODE (first_param_type) != TYPE_CODE_PTR) 5057130803Smarcel return NULL; 5058130803Smarcel 5059130803Smarcel /* Get the thing that "this" points to, check that 5060130803Smarcel * it's a class, and get its class name. 5061130803Smarcel */ 5062130803Smarcel pointed_to_type = TYPE_TARGET_TYPE (first_param_type); 5063130803Smarcel if (pointed_to_type == NULL) 5064130803Smarcel return NULL; /* paranoia */ 5065130803Smarcel if (TYPE_CODE (pointed_to_type) != TYPE_CODE_CLASS) 5066130803Smarcel return NULL; 5067130803Smarcel class_name = TYPE_NAME (pointed_to_type); 5068130803Smarcel if (class_name == NULL) 5069130803Smarcel return NULL; /* paranoia */ 5070130803Smarcel 5071130803Smarcel /* The class name may be of the form "class c", in which case 5072130803Smarcel * we want to strip off the leading "class ". 5073130803Smarcel */ 5074130803Smarcel if (strncmp (class_name, "class ", 6) == 0) 5075130803Smarcel class_name += 6; 5076130803Smarcel 5077130803Smarcel return class_name; 5078130803Smarcel} 5079130803Smarcel 5080130803Smarcel/* Internalize one native debug symbol. 5081130803Smarcel * Called in a loop from hpread_expand_symtab(). 5082130803Smarcel * Arguments: 5083130803Smarcel * dn_bufp: 5084130803Smarcel * name: 5085130803Smarcel * section_offsets: 5086130803Smarcel * objfile: 5087130803Smarcel * text_offset: 5088130803Smarcel * text_size: 5089130803Smarcel * filename: 5090130803Smarcel * index: Index of this symbol 5091130803Smarcel * at_module_boundary_p Pointer to boolean flag to control caller's loop. 5092130803Smarcel */ 5093130803Smarcel 5094130803Smarcelstatic void 5095130803Smarcelhpread_process_one_debug_symbol (union dnttentry *dn_bufp, char *name, 5096130803Smarcel struct section_offsets *section_offsets, 5097130803Smarcel struct objfile *objfile, CORE_ADDR text_offset, 5098130803Smarcel int text_size, char *filename, int index, 5099130803Smarcel int *at_module_boundary_p) 5100130803Smarcel{ 5101130803Smarcel unsigned long desc; 5102130803Smarcel int type; 5103130803Smarcel CORE_ADDR valu; 5104130803Smarcel int offset = ANOFFSET (section_offsets, SECT_OFF_TEXT (objfile)); 5105130803Smarcel int data_offset = ANOFFSET (section_offsets, SECT_OFF_DATA (objfile)); 5106130803Smarcel union dnttentry *dn_temp; 5107130803Smarcel dnttpointer hp_type; 5108130803Smarcel struct symbol *sym; 5109130803Smarcel struct context_stack *new; 5110130803Smarcel char *class_scope_name; 5111130803Smarcel 5112130803Smarcel /* Allocate one GDB debug symbol and fill in some default values. */ 5113130803Smarcel sym = (struct symbol *) obstack_alloc (&objfile->objfile_obstack, 5114130803Smarcel sizeof (struct symbol)); 5115130803Smarcel memset (sym, 0, sizeof (struct symbol)); 5116130803Smarcel DEPRECATED_SYMBOL_NAME (sym) = obsavestring (name, strlen (name), &objfile->objfile_obstack); 5117130803Smarcel SYMBOL_LANGUAGE (sym) = language_auto; 5118130803Smarcel SYMBOL_DOMAIN (sym) = VAR_DOMAIN; 5119130803Smarcel SYMBOL_LINE (sym) = 0; 5120130803Smarcel SYMBOL_VALUE (sym) = 0; 5121130803Smarcel SYMBOL_CLASS (sym) = LOC_TYPEDEF; 5122130803Smarcel 5123130803Smarcel /* Just a trick in case the SOM debug symbol is a type definition. 5124130803Smarcel * There are routines that are set up to build a GDB type symbol, given 5125130803Smarcel * a SOM dnttpointer. So we set up a dummy SOM dnttpointer "hp_type". 5126130803Smarcel * This allows us to call those same routines. 5127130803Smarcel */ 5128130803Smarcel hp_type.dnttp.extension = 1; 5129130803Smarcel hp_type.dnttp.immediate = 0; 5130130803Smarcel hp_type.dnttp.global = 0; 5131130803Smarcel hp_type.dnttp.index = index; 5132130803Smarcel 5133130803Smarcel /* This "type" is the type of SOM record. 5134130803Smarcel * Switch on SOM type. 5135130803Smarcel */ 5136130803Smarcel type = dn_bufp->dblock.kind; 5137130803Smarcel switch (type) 5138130803Smarcel { 5139130803Smarcel case DNTT_TYPE_SRCFILE: 5140130803Smarcel /* This type of symbol indicates from which source file or 5141130803Smarcel * include file any following data comes. It may indicate: 5142130803Smarcel * 5143130803Smarcel * o The start of an entirely new source file (and thus 5144130803Smarcel * a new module) 5145130803Smarcel * 5146130803Smarcel * o The start of a different source file due to #include 5147130803Smarcel * 5148130803Smarcel * o The end of an include file and the return to the original 5149130803Smarcel * file. Thus if "foo.c" includes "bar.h", we see first 5150130803Smarcel * a SRCFILE for foo.c, then one for bar.h, and then one for 5151130803Smarcel * foo.c again. 5152130803Smarcel * 5153130803Smarcel * If it indicates the start of a new module then we must 5154130803Smarcel * finish the symbol table of the previous module 5155130803Smarcel * (if any) and start accumulating a new symbol table. 5156130803Smarcel */ 5157130803Smarcel 5158130803Smarcel valu = text_offset; 5159130803Smarcel if (!last_source_file) 5160130803Smarcel { 5161130803Smarcel /* 5162130803Smarcel * A note on "last_source_file": this is a char* pointing 5163130803Smarcel * to the actual file name. "start_symtab" sets it, 5164130803Smarcel * "end_symtab" clears it. 5165130803Smarcel * 5166130803Smarcel * So if "last_source_file" is NULL, then either this is 5167130803Smarcel * the first record we are looking at, or a previous call 5168130803Smarcel * to "end_symtab()" was made to close out the previous 5169130803Smarcel * module. Since we're now quitting the scan loop when we 5170130803Smarcel * see a MODULE END record, we should never get here, except 5171130803Smarcel * in the case that we're not using the quick look-up tables 5172130803Smarcel * and have to use the old system as a fall-back. 5173130803Smarcel */ 5174130803Smarcel start_symtab (name, NULL, valu); 5175130803Smarcel record_debugformat ("HP"); 5176130803Smarcel SL_INDEX (objfile) = dn_bufp->dsfile.address; 5177130803Smarcel } 5178130803Smarcel 5179130803Smarcel else 5180130803Smarcel { 5181130803Smarcel /* Either a new include file, or a SRCFILE record 5182130803Smarcel * saying we are back in the main source (or out of 5183130803Smarcel * a nested include file) again. 5184130803Smarcel */ 5185130803Smarcel SL_INDEX (objfile) = hpread_record_lines (current_subfile, 5186130803Smarcel SL_INDEX (objfile), 5187130803Smarcel dn_bufp->dsfile.address, 5188130803Smarcel objfile, offset); 5189130803Smarcel } 5190130803Smarcel 5191130803Smarcel /* A note on "start_subfile". This routine will check 5192130803Smarcel * the name we pass it and look for an existing subfile 5193130803Smarcel * of that name. There's thus only one sub-file for the 5194130803Smarcel * actual source (e.g. for "foo.c" in foo.c), despite the 5195130803Smarcel * fact that we'll see lots of SRCFILE entries for foo.c 5196130803Smarcel * inside foo.c. 5197130803Smarcel */ 5198130803Smarcel start_subfile (name, NULL); 5199130803Smarcel break; 5200130803Smarcel 5201130803Smarcel case DNTT_TYPE_MODULE: 5202130803Smarcel /* 5203130803Smarcel * We no longer ignore DNTT_TYPE_MODULE symbols. The module 5204130803Smarcel * represents the meaningful semantic structure of a compilation 5205130803Smarcel * unit. We expect to start the psymtab-to-symtab expansion 5206130803Smarcel * looking at a MODULE entry, and to end it at the corresponding 5207130803Smarcel * END MODULE entry. 5208130803Smarcel * 5209130803Smarcel *--Begin outdated comments 5210130803Smarcel * 5211130803Smarcel * This record signifies the start of a new source module 5212130803Smarcel * In C/C++ there is no explicit "module" construct in the language, 5213130803Smarcel * but each compilation unit is implicitly a module and they 5214130803Smarcel * do emit the DNTT_TYPE_MODULE records. 5215130803Smarcel * The end of the module is marked by a matching DNTT_TYPE_END record. 5216130803Smarcel * 5217130803Smarcel * The reason GDB gets away with ignoring the DNTT_TYPE_MODULE record 5218130803Smarcel * is it notices the DNTT_TYPE_END record for the previous 5219130803Smarcel * module (see comments under DNTT_TYPE_END case), and then treats 5220130803Smarcel * the next DNTT_TYPE_SRCFILE record as if it were the module-start record. 5221130803Smarcel * (i.e., it makes a start_symtab() call). 5222130803Smarcel * This scheme seems a little convoluted, but I'll leave it 5223130803Smarcel * alone on the principle "if it ain't broke don't fix 5224130803Smarcel * it". (RT). 5225130803Smarcel * 5226130803Smarcel *-- End outdated comments 5227130803Smarcel */ 5228130803Smarcel 5229130803Smarcel valu = text_offset; 5230130803Smarcel if (!last_source_file) 5231130803Smarcel { 5232130803Smarcel /* Start of a new module. We know this because "last_source_file" 5233130803Smarcel * is NULL, which can only happen the first time or if we just 5234130803Smarcel * made a call to end_symtab() to close out the previous module. 5235130803Smarcel */ 5236130803Smarcel start_symtab (name, NULL, valu); 5237130803Smarcel SL_INDEX (objfile) = dn_bufp->dmodule.address; 5238130803Smarcel } 5239130803Smarcel else 5240130803Smarcel { 5241130803Smarcel /* This really shouldn't happen if we're using the quick 5242130803Smarcel * look-up tables, as it would mean we'd scanned past an 5243130803Smarcel * END MODULE entry. But if we're not using the tables, 5244130803Smarcel * we started the module on the SRCFILE entry, so it's ok. 5245130803Smarcel * For now, accept this. 5246130803Smarcel */ 5247130803Smarcel /* warning( "Error expanding psymtab, missed module end, found entry for %s", 5248130803Smarcel * name ); 5249130803Smarcel */ 5250130803Smarcel *at_module_boundary_p = -1; 5251130803Smarcel } 5252130803Smarcel 5253130803Smarcel start_subfile (name, NULL); 5254130803Smarcel break; 5255130803Smarcel 5256130803Smarcel case DNTT_TYPE_FUNCTION: 5257130803Smarcel case DNTT_TYPE_ENTRY: 5258130803Smarcel /* A function or secondary entry point. */ 5259130803Smarcel valu = dn_bufp->dfunc.lowaddr + offset; 5260130803Smarcel 5261130803Smarcel /* Record lines up to this point. */ 5262130803Smarcel SL_INDEX (objfile) = hpread_record_lines (current_subfile, 5263130803Smarcel SL_INDEX (objfile), 5264130803Smarcel dn_bufp->dfunc.address, 5265130803Smarcel objfile, offset); 5266130803Smarcel 5267130803Smarcel WITHIN_FUNCTION (objfile) = 1; 5268130803Smarcel CURRENT_FUNCTION_VALUE (objfile) = valu; 5269130803Smarcel 5270130803Smarcel /* Stack must be empty now. */ 5271130803Smarcel if (context_stack_depth != 0) 5272130803Smarcel lbrac_unmatched_complaint (symnum); 5273130803Smarcel new = push_context (0, valu); 5274130803Smarcel 5275130803Smarcel /* Built a type for the function. This includes processing 5276130803Smarcel * the symbol records for the function parameters. 5277130803Smarcel */ 5278130803Smarcel SYMBOL_CLASS (sym) = LOC_BLOCK; 5279130803Smarcel SYMBOL_TYPE (sym) = hpread_read_function_type (hp_type, dn_bufp, objfile, 1); 5280130803Smarcel 5281130803Smarcel /* All functions in C++ have prototypes. For C we don't have enough 5282130803Smarcel information in the debug info. */ 5283130803Smarcel if (SYMBOL_LANGUAGE (sym) == language_cplus) 5284130803Smarcel TYPE_FLAGS (SYMBOL_TYPE (sym)) |= TYPE_FLAG_PROTOTYPED; 5285130803Smarcel 5286130803Smarcel /* The "DEPRECATED_SYMBOL_NAME" field is expected to be the mangled name 5287130803Smarcel * (if any), which we get from the "alias" field of the SOM record 5288130803Smarcel * if that exists. 5289130803Smarcel */ 5290130803Smarcel if ((dn_bufp->dfunc.language == HP_LANGUAGE_CPLUSPLUS) && 5291130803Smarcel dn_bufp->dfunc.alias && /* has an alias */ 5292130803Smarcel *(char *) (VT (objfile) + dn_bufp->dfunc.alias)) /* not a null string */ 5293130803Smarcel DEPRECATED_SYMBOL_NAME (sym) = VT (objfile) + dn_bufp->dfunc.alias; 5294130803Smarcel else 5295130803Smarcel DEPRECATED_SYMBOL_NAME (sym) = VT (objfile) + dn_bufp->dfunc.name; 5296130803Smarcel 5297130803Smarcel /* Special hack to get around HP compilers' insistence on 5298130803Smarcel * reporting "main" as "_MAIN_" for C/C++ */ 5299130803Smarcel if ((strcmp (DEPRECATED_SYMBOL_NAME (sym), "_MAIN_") == 0) && 5300130803Smarcel (strcmp (VT (objfile) + dn_bufp->dfunc.name, "main") == 0)) 5301130803Smarcel DEPRECATED_SYMBOL_NAME (sym) = VT (objfile) + dn_bufp->dfunc.name; 5302130803Smarcel 5303130803Smarcel /* The SYMBOL_CPLUS_DEMANGLED_NAME field is expected to 5304130803Smarcel * be the demangled name. 5305130803Smarcel */ 5306130803Smarcel if (dn_bufp->dfunc.language == HP_LANGUAGE_CPLUSPLUS) 5307130803Smarcel { 5308130803Smarcel /* SYMBOL_INIT_DEMANGLED_NAME is a macro which winds up 5309130803Smarcel * calling the demangler in libiberty (cplus_demangle()) to 5310130803Smarcel * do the job. This generally does the job, even though 5311130803Smarcel * it's intended for the GNU compiler and not the aCC compiler 5312130803Smarcel * Note that SYMBOL_INIT_DEMANGLED_NAME calls the 5313130803Smarcel * demangler with arguments DMGL_PARAMS | DMGL_ANSI. 5314130803Smarcel * Generally, we don't want params when we display 5315130803Smarcel * a demangled name, but when I took out the DMGL_PARAMS, 5316130803Smarcel * some things broke, so I'm leaving it in here, and 5317130803Smarcel * working around the issue in stack.c. - RT 5318130803Smarcel */ 5319130803Smarcel SYMBOL_INIT_DEMANGLED_NAME (sym, &objfile->objfile_obstack); 5320130803Smarcel if ((DEPRECATED_SYMBOL_NAME (sym) == VT (objfile) + dn_bufp->dfunc.alias) && 5321130803Smarcel (!SYMBOL_CPLUS_DEMANGLED_NAME (sym))) 5322130803Smarcel { 5323130803Smarcel 5324130803Smarcel /* Well, the symbol name is mangled, but the 5325130803Smarcel * demangler in libiberty failed so the demangled 5326130803Smarcel * field is still NULL. Try to 5327130803Smarcel * do the job ourselves based on the "name" field 5328130803Smarcel * in the SOM record. A complication here is that 5329130803Smarcel * the name field contains only the function name 5330130803Smarcel * (like "f"), whereas we want the class qualification 5331130803Smarcel * (as in "c::f"). Try to reconstruct that. 5332130803Smarcel */ 5333130803Smarcel char *basename; 5334130803Smarcel char *classname; 5335130803Smarcel char *dem_name; 5336130803Smarcel basename = VT (objfile) + dn_bufp->dfunc.name; 5337130803Smarcel classname = class_of (SYMBOL_TYPE (sym)); 5338130803Smarcel if (classname) 5339130803Smarcel { 5340130803Smarcel dem_name = xmalloc (strlen (basename) + strlen (classname) + 3); 5341130803Smarcel strcpy (dem_name, classname); 5342130803Smarcel strcat (dem_name, "::"); 5343130803Smarcel strcat (dem_name, basename); 5344130803Smarcel SYMBOL_CPLUS_DEMANGLED_NAME (sym) = dem_name; 5345130803Smarcel SYMBOL_LANGUAGE (sym) = language_cplus; 5346130803Smarcel } 5347130803Smarcel } 5348130803Smarcel } 5349130803Smarcel 5350130803Smarcel /* Add the function symbol to the list of symbols in this blockvector */ 5351130803Smarcel if (dn_bufp->dfunc.global) 5352130803Smarcel add_symbol_to_list (sym, &global_symbols); 5353130803Smarcel else 5354130803Smarcel add_symbol_to_list (sym, &file_symbols); 5355130803Smarcel new->name = sym; 5356130803Smarcel 5357130803Smarcel /* Search forward to the next BEGIN and also read 5358130803Smarcel * in the line info up to that point. 5359130803Smarcel * Not sure why this is needed. 5360130803Smarcel * In HP FORTRAN this code is harmful since there 5361130803Smarcel * may not be a BEGIN after the FUNCTION. 5362130803Smarcel * So I made it C/C++ specific. - RT 5363130803Smarcel */ 5364130803Smarcel if (dn_bufp->dfunc.language == HP_LANGUAGE_C || 5365130803Smarcel dn_bufp->dfunc.language == HP_LANGUAGE_CPLUSPLUS) 5366130803Smarcel { 5367130803Smarcel while (dn_bufp->dblock.kind != DNTT_TYPE_BEGIN) 5368130803Smarcel { 5369130803Smarcel dn_bufp = hpread_get_lntt (++index, objfile); 5370130803Smarcel if (dn_bufp->dblock.extension) 5371130803Smarcel continue; 5372130803Smarcel } 5373130803Smarcel SL_INDEX (objfile) = hpread_record_lines (current_subfile, 5374130803Smarcel SL_INDEX (objfile), 5375130803Smarcel dn_bufp->dbegin.address, 5376130803Smarcel objfile, offset); 5377130803Smarcel SYMBOL_LINE (sym) = hpread_get_line (dn_bufp->dbegin.address, objfile); 5378130803Smarcel } 5379130803Smarcel record_line (current_subfile, SYMBOL_LINE (sym), valu); 5380130803Smarcel break; 5381130803Smarcel 5382130803Smarcel case DNTT_TYPE_DOC_FUNCTION: 5383130803Smarcel valu = dn_bufp->ddocfunc.lowaddr + offset; 5384130803Smarcel 5385130803Smarcel /* Record lines up to this point. */ 5386130803Smarcel SL_INDEX (objfile) = hpread_record_lines (current_subfile, 5387130803Smarcel SL_INDEX (objfile), 5388130803Smarcel dn_bufp->ddocfunc.address, 5389130803Smarcel objfile, offset); 5390130803Smarcel 5391130803Smarcel WITHIN_FUNCTION (objfile) = 1; 5392130803Smarcel CURRENT_FUNCTION_VALUE (objfile) = valu; 5393130803Smarcel /* Stack must be empty now. */ 5394130803Smarcel if (context_stack_depth != 0) 5395130803Smarcel lbrac_unmatched_complaint (symnum); 5396130803Smarcel new = push_context (0, valu); 5397130803Smarcel 5398130803Smarcel /* Built a type for the function. This includes processing 5399130803Smarcel * the symbol records for the function parameters. 5400130803Smarcel */ 5401130803Smarcel SYMBOL_CLASS (sym) = LOC_BLOCK; 5402130803Smarcel SYMBOL_TYPE (sym) = hpread_read_doc_function_type (hp_type, dn_bufp, objfile, 1); 5403130803Smarcel 5404130803Smarcel /* The "DEPRECATED_SYMBOL_NAME" field is expected to be the mangled name 5405130803Smarcel * (if any), which we get from the "alias" field of the SOM record 5406130803Smarcel * if that exists. 5407130803Smarcel */ 5408130803Smarcel if ((dn_bufp->ddocfunc.language == HP_LANGUAGE_CPLUSPLUS) && 5409130803Smarcel dn_bufp->ddocfunc.alias && /* has an alias */ 5410130803Smarcel *(char *) (VT (objfile) + dn_bufp->ddocfunc.alias)) /* not a null string */ 5411130803Smarcel DEPRECATED_SYMBOL_NAME (sym) = VT (objfile) + dn_bufp->ddocfunc.alias; 5412130803Smarcel else 5413130803Smarcel DEPRECATED_SYMBOL_NAME (sym) = VT (objfile) + dn_bufp->ddocfunc.name; 5414130803Smarcel 5415130803Smarcel /* Special hack to get around HP compilers' insistence on 5416130803Smarcel * reporting "main" as "_MAIN_" for C/C++ */ 5417130803Smarcel if ((strcmp (DEPRECATED_SYMBOL_NAME (sym), "_MAIN_") == 0) && 5418130803Smarcel (strcmp (VT (objfile) + dn_bufp->ddocfunc.name, "main") == 0)) 5419130803Smarcel DEPRECATED_SYMBOL_NAME (sym) = VT (objfile) + dn_bufp->ddocfunc.name; 5420130803Smarcel 5421130803Smarcel if (dn_bufp->ddocfunc.language == HP_LANGUAGE_CPLUSPLUS) 5422130803Smarcel { 5423130803Smarcel 5424130803Smarcel /* SYMBOL_INIT_DEMANGLED_NAME is a macro which winds up 5425130803Smarcel * calling the demangler in libiberty (cplus_demangle()) to 5426130803Smarcel * do the job. This generally does the job, even though 5427130803Smarcel * it's intended for the GNU compiler and not the aCC compiler 5428130803Smarcel * Note that SYMBOL_INIT_DEMANGLED_NAME calls the 5429130803Smarcel * demangler with arguments DMGL_PARAMS | DMGL_ANSI. 5430130803Smarcel * Generally, we don't want params when we display 5431130803Smarcel * a demangled name, but when I took out the DMGL_PARAMS, 5432130803Smarcel * some things broke, so I'm leaving it in here, and 5433130803Smarcel * working around the issue in stack.c. - RT 5434130803Smarcel */ 5435130803Smarcel SYMBOL_INIT_DEMANGLED_NAME (sym, &objfile->objfile_obstack); 5436130803Smarcel 5437130803Smarcel if ((DEPRECATED_SYMBOL_NAME (sym) == VT (objfile) + dn_bufp->ddocfunc.alias) && 5438130803Smarcel (!SYMBOL_CPLUS_DEMANGLED_NAME (sym))) 5439130803Smarcel { 5440130803Smarcel 5441130803Smarcel /* Well, the symbol name is mangled, but the 5442130803Smarcel * demangler in libiberty failed so the demangled 5443130803Smarcel * field is still NULL. Try to 5444130803Smarcel * do the job ourselves based on the "name" field 5445130803Smarcel * in the SOM record. A complication here is that 5446130803Smarcel * the name field contains only the function name 5447130803Smarcel * (like "f"), whereas we want the class qualification 5448130803Smarcel * (as in "c::f"). Try to reconstruct that. 5449130803Smarcel */ 5450130803Smarcel char *basename; 5451130803Smarcel char *classname; 5452130803Smarcel char *dem_name; 5453130803Smarcel basename = VT (objfile) + dn_bufp->ddocfunc.name; 5454130803Smarcel classname = class_of (SYMBOL_TYPE (sym)); 5455130803Smarcel if (classname) 5456130803Smarcel { 5457130803Smarcel dem_name = xmalloc (strlen (basename) + strlen (classname) + 3); 5458130803Smarcel strcpy (dem_name, classname); 5459130803Smarcel strcat (dem_name, "::"); 5460130803Smarcel strcat (dem_name, basename); 5461130803Smarcel SYMBOL_CPLUS_DEMANGLED_NAME (sym) = dem_name; 5462130803Smarcel SYMBOL_LANGUAGE (sym) = language_cplus; 5463130803Smarcel } 5464130803Smarcel } 5465130803Smarcel } 5466130803Smarcel 5467130803Smarcel /* Add the function symbol to the list of symbols in this blockvector */ 5468130803Smarcel if (dn_bufp->ddocfunc.global) 5469130803Smarcel add_symbol_to_list (sym, &global_symbols); 5470130803Smarcel else 5471130803Smarcel add_symbol_to_list (sym, &file_symbols); 5472130803Smarcel new->name = sym; 5473130803Smarcel 5474130803Smarcel /* Search forward to the next BEGIN and also read 5475130803Smarcel * in the line info up to that point. 5476130803Smarcel * Not sure why this is needed. 5477130803Smarcel * In HP FORTRAN this code is harmful since there 5478130803Smarcel * may not be a BEGIN after the FUNCTION. 5479130803Smarcel * So I made it C/C++ specific. - RT 5480130803Smarcel */ 5481130803Smarcel if (dn_bufp->ddocfunc.language == HP_LANGUAGE_C || 5482130803Smarcel dn_bufp->ddocfunc.language == HP_LANGUAGE_CPLUSPLUS) 5483130803Smarcel { 5484130803Smarcel while (dn_bufp->dblock.kind != DNTT_TYPE_BEGIN) 5485130803Smarcel { 5486130803Smarcel dn_bufp = hpread_get_lntt (++index, objfile); 5487130803Smarcel if (dn_bufp->dblock.extension) 5488130803Smarcel continue; 5489130803Smarcel } 5490130803Smarcel SL_INDEX (objfile) = hpread_record_lines (current_subfile, 5491130803Smarcel SL_INDEX (objfile), 5492130803Smarcel dn_bufp->dbegin.address, 5493130803Smarcel objfile, offset); 5494130803Smarcel SYMBOL_LINE (sym) = hpread_get_line (dn_bufp->dbegin.address, objfile); 5495130803Smarcel } 5496130803Smarcel record_line (current_subfile, SYMBOL_LINE (sym), valu); 5497130803Smarcel break; 5498130803Smarcel 5499130803Smarcel case DNTT_TYPE_BEGIN: 5500130803Smarcel /* Begin a new scope. */ 5501130803Smarcel if (context_stack_depth == 1 /* this means we're at function level */ && 5502130803Smarcel context_stack[0].name != NULL /* this means it's a function */ && 5503130803Smarcel context_stack[0].depth == 0 /* this means it's the first BEGIN 5504130803Smarcel we've seen after the FUNCTION */ 5505130803Smarcel ) 5506130803Smarcel { 5507130803Smarcel /* This is the first BEGIN after a FUNCTION. 5508130803Smarcel * We ignore this one, since HP compilers always insert 5509130803Smarcel * at least one BEGIN, i.e. it's: 5510130803Smarcel * 5511130803Smarcel * FUNCTION 5512130803Smarcel * argument symbols 5513130803Smarcel * BEGIN 5514130803Smarcel * local symbols 5515130803Smarcel * (possibly nested BEGIN ... END's if there are inner { } blocks) 5516130803Smarcel * END 5517130803Smarcel * END 5518130803Smarcel * 5519130803Smarcel * By ignoring this first BEGIN, the local symbols get treated 5520130803Smarcel * as belonging to the function scope, and "print func::local_sym" 5521130803Smarcel * works (which is what we want). 5522130803Smarcel */ 5523130803Smarcel 5524130803Smarcel /* All we do here is increase the depth count associated with 5525130803Smarcel * the FUNCTION entry in the context stack. This ensures that 5526130803Smarcel * the next BEGIN we see (if any), representing a real nested { } 5527130803Smarcel * block, will get processed. 5528130803Smarcel */ 5529130803Smarcel 5530130803Smarcel context_stack[0].depth++; 5531130803Smarcel 5532130803Smarcel } 5533130803Smarcel else 5534130803Smarcel { 5535130803Smarcel 5536130803Smarcel /* Record lines up to this SLT pointer. */ 5537130803Smarcel SL_INDEX (objfile) = hpread_record_lines (current_subfile, 5538130803Smarcel SL_INDEX (objfile), 5539130803Smarcel dn_bufp->dbegin.address, 5540130803Smarcel objfile, offset); 5541130803Smarcel /* Calculate start address of new scope */ 5542130803Smarcel valu = hpread_get_location (dn_bufp->dbegin.address, objfile); 5543130803Smarcel valu += offset; /* Relocate for dynamic loading */ 5544130803Smarcel /* We use the scope start DNTT index as nesting depth identifier! */ 5545130803Smarcel desc = hpread_get_scope_start (dn_bufp->dbegin.address, objfile); 5546130803Smarcel new = push_context (desc, valu); 5547130803Smarcel } 5548130803Smarcel break; 5549130803Smarcel 5550130803Smarcel case DNTT_TYPE_END: 5551130803Smarcel /* End a scope. */ 5552130803Smarcel 5553130803Smarcel /* Valid end kinds are: 5554130803Smarcel * MODULE 5555130803Smarcel * FUNCTION 5556130803Smarcel * WITH 5557130803Smarcel * COMMON 5558130803Smarcel * BEGIN 5559130803Smarcel * CLASS_SCOPE 5560130803Smarcel */ 5561130803Smarcel 5562130803Smarcel SL_INDEX (objfile) = hpread_record_lines (current_subfile, 5563130803Smarcel SL_INDEX (objfile), 5564130803Smarcel dn_bufp->dend.address, 5565130803Smarcel objfile, offset); 5566130803Smarcel switch (dn_bufp->dend.endkind) 5567130803Smarcel { 5568130803Smarcel case DNTT_TYPE_MODULE: 5569130803Smarcel /* Ending a module ends the symbol table for that module. 5570130803Smarcel * Calling end_symtab() has the side effect of clearing the 5571130803Smarcel * last_source_file pointer, which in turn signals 5572130803Smarcel * process_one_debug_symbol() to treat the next DNTT_TYPE_SRCFILE 5573130803Smarcel * record as a module-begin. 5574130803Smarcel */ 5575130803Smarcel valu = text_offset + text_size + offset; 5576130803Smarcel 5577130803Smarcel /* Tell our caller that we're done with expanding the 5578130803Smarcel * debug information for a module. 5579130803Smarcel */ 5580130803Smarcel *at_module_boundary_p = 1; 5581130803Smarcel 5582130803Smarcel /* Don't do this, as our caller will do it! 5583130803Smarcel 5584130803Smarcel * (void) end_symtab (valu, objfile, 0); 5585130803Smarcel */ 5586130803Smarcel break; 5587130803Smarcel 5588130803Smarcel case DNTT_TYPE_FUNCTION: 5589130803Smarcel /* Ending a function, well, ends the function's scope. */ 5590130803Smarcel dn_temp = hpread_get_lntt (dn_bufp->dend.beginscope.dnttp.index, 5591130803Smarcel objfile); 5592130803Smarcel valu = dn_temp->dfunc.hiaddr + offset; 5593130803Smarcel /* Insert func params into local list */ 5594130803Smarcel merge_symbol_lists (¶m_symbols, &local_symbols); 5595130803Smarcel new = pop_context (); 5596130803Smarcel /* Make a block for the local symbols within. */ 5597130803Smarcel finish_block (new->name, &local_symbols, new->old_blocks, 5598130803Smarcel new->start_addr, valu, objfile); 5599130803Smarcel WITHIN_FUNCTION (objfile) = 0; /* This may have to change for Pascal */ 5600130803Smarcel local_symbols = new->locals; 5601130803Smarcel param_symbols = new->params; 5602130803Smarcel break; 5603130803Smarcel 5604130803Smarcel case DNTT_TYPE_BEGIN: 5605130803Smarcel if (context_stack_depth == 1 && 5606130803Smarcel context_stack[0].name != NULL && 5607130803Smarcel context_stack[0].depth == 1) 5608130803Smarcel { 5609130803Smarcel /* This is the END corresponding to the 5610130803Smarcel * BEGIN which we ignored - see DNTT_TYPE_BEGIN case above. 5611130803Smarcel */ 5612130803Smarcel context_stack[0].depth--; 5613130803Smarcel } 5614130803Smarcel else 5615130803Smarcel { 5616130803Smarcel /* Ending a local scope. */ 5617130803Smarcel valu = hpread_get_location (dn_bufp->dend.address, objfile); 5618130803Smarcel /* Why in the hell is this needed? */ 5619130803Smarcel valu += offset + 9; /* Relocate for dynamic loading */ 5620130803Smarcel new = pop_context (); 5621130803Smarcel desc = dn_bufp->dend.beginscope.dnttp.index; 5622130803Smarcel if (desc != new->depth) 5623130803Smarcel lbrac_mismatch_complaint (symnum); 5624130803Smarcel 5625130803Smarcel /* Make a block for the local symbols within. */ 5626130803Smarcel finish_block (new->name, &local_symbols, new->old_blocks, 5627130803Smarcel new->start_addr, valu, objfile); 5628130803Smarcel local_symbols = new->locals; 5629130803Smarcel param_symbols = new->params; 5630130803Smarcel } 5631130803Smarcel break; 5632130803Smarcel 5633130803Smarcel case DNTT_TYPE_WITH: 5634130803Smarcel /* Since we ignore the DNTT_TYPE_WITH that starts the scope, 5635130803Smarcel * we can ignore the DNTT_TYPE_END that ends it. 5636130803Smarcel */ 5637130803Smarcel break; 5638130803Smarcel 5639130803Smarcel case DNTT_TYPE_COMMON: 5640130803Smarcel /* End a FORTRAN common block. We don't currently handle these */ 5641130803Smarcel complaint (&symfile_complaints, 5642130803Smarcel "unhandled symbol in hp-symtab-read.c: DNTT_TYPE_COMMON/DNTT_TYPE_END.\n"); 5643130803Smarcel break; 5644130803Smarcel 5645130803Smarcel case DNTT_TYPE_CLASS_SCOPE: 5646130803Smarcel 5647130803Smarcel /* pai: FIXME Not handling nested classes for now -- must 5648130803Smarcel * maintain a stack */ 5649130803Smarcel class_scope_name = NULL; 5650130803Smarcel 5651130803Smarcel#if 0 5652130803Smarcel /* End a class scope */ 5653130803Smarcel valu = hpread_get_location (dn_bufp->dend.address, objfile); 5654130803Smarcel /* Why in the hell is this needed? */ 5655130803Smarcel valu += offset + 9; /* Relocate for dynamic loading */ 5656130803Smarcel new = pop_context (); 5657130803Smarcel desc = dn_bufp->dend.beginscope.dnttp.index; 5658130803Smarcel if (desc != new->depth) 5659130803Smarcel lbrac_mismatch_complaint ((char *) symnum); 5660130803Smarcel /* Make a block for the local symbols within. */ 5661130803Smarcel finish_block (new->name, &local_symbols, new->old_blocks, 5662130803Smarcel new->start_addr, valu, objfile); 5663130803Smarcel local_symbols = new->locals; 5664130803Smarcel param_symbols = new->params; 5665130803Smarcel#endif 5666130803Smarcel break; 5667130803Smarcel 5668130803Smarcel default: 5669130803Smarcel complaint (&symfile_complaints, 5670130803Smarcel "internal error in hp-symtab-read.c: Unexpected DNTT_TYPE_END kind."); 5671130803Smarcel break; 5672130803Smarcel } 5673130803Smarcel break; 5674130803Smarcel 5675130803Smarcel /* DNTT_TYPE_IMPORT is not handled */ 5676130803Smarcel 5677130803Smarcel case DNTT_TYPE_LABEL: 5678130803Smarcel SYMBOL_DOMAIN (sym) = LABEL_DOMAIN; 5679130803Smarcel break; 5680130803Smarcel 5681130803Smarcel case DNTT_TYPE_FPARAM: 5682130803Smarcel /* Function parameters. */ 5683130803Smarcel /* Note 1: This code was present in the 4.16 sources, and then 5684130803Smarcel removed, because fparams are handled in 5685130803Smarcel hpread_read_function_type(). However, while fparam symbols 5686130803Smarcel are indeed handled twice, this code here cannot be removed 5687130803Smarcel because then they don't get added to the local symbol list of 5688130803Smarcel the function's code block, which leads to a failure to look 5689130803Smarcel up locals, "this"-relative member names, etc. So I've put 5690130803Smarcel this code back in. pai/1997-07-21 */ 5691130803Smarcel /* Note 2: To fix a defect, we stopped adding FPARAMS to local_symbols 5692130803Smarcel in hpread_read_function_type(), so FPARAMS had to be handled 5693130803Smarcel here. I changed the location to be the appropriate argument 5694130803Smarcel kinds rather than LOC_LOCAL. pai/1997-08-08 */ 5695130803Smarcel /* Note 3: Well, the fix in Note 2 above broke argument printing 5696130803Smarcel in traceback frames, and further it makes assumptions about the 5697130803Smarcel order of the FPARAM entries from HP compilers (cc and aCC in particular 5698130803Smarcel generate them in reverse orders -- fixing one breaks for the other). 5699130803Smarcel So I've added code in hpread_read_function_type() to add fparams 5700130803Smarcel to a param_symbols list for the current context level. These are 5701130803Smarcel then merged into local_symbols when a function end is reached. 5702130803Smarcel pai/1997-08-11 */ 5703130803Smarcel 5704130803Smarcel break; /* do nothing; handled in hpread_read_function_type() */ 5705130803Smarcel 5706130803Smarcel#if 0 /* Old code */ 5707130803Smarcel if (dn_bufp->dfparam.regparam) 5708130803Smarcel SYMBOL_CLASS (sym) = LOC_REGISTER; 5709130803Smarcel else if (dn_bufp->dfparam.indirect) 5710130803Smarcel SYMBOL_CLASS (sym) = LOC_REF_ARG; 5711130803Smarcel else 5712130803Smarcel SYMBOL_CLASS (sym) = LOC_ARG; 5713130803Smarcel SYMBOL_DOMAIN (sym) = VAR_DOMAIN; 5714130803Smarcel if (dn_bufp->dfparam.copyparam) 5715130803Smarcel { 5716130803Smarcel SYMBOL_VALUE (sym) = dn_bufp->dfparam.location; 5717130803Smarcel#ifdef HPREAD_ADJUST_STACK_ADDRESS 5718130803Smarcel SYMBOL_VALUE (sym) 5719130803Smarcel += HPREAD_ADJUST_STACK_ADDRESS (CURRENT_FUNCTION_VALUE (objfile)); 5720130803Smarcel#endif 5721130803Smarcel } 5722130803Smarcel else 5723130803Smarcel SYMBOL_VALUE (sym) = dn_bufp->dfparam.location; 5724130803Smarcel SYMBOL_TYPE (sym) = hpread_type_lookup (dn_bufp->dfparam.type, objfile); 5725130803Smarcel add_symbol_to_list (sym, &fparam_symbols); 5726130803Smarcel break; 5727130803Smarcel#endif 5728130803Smarcel 5729130803Smarcel case DNTT_TYPE_SVAR: 5730130803Smarcel /* Static variables. */ 5731130803Smarcel SYMBOL_CLASS (sym) = LOC_STATIC; 5732130803Smarcel 5733130803Smarcel /* Note: There is a case that arises with globals in shared 5734130803Smarcel * libraries where we need to set the address to LOC_INDIRECT. 5735130803Smarcel * This case is if you have a global "g" in one library, and 5736130803Smarcel * it is referenced "extern <type> g;" in another library. 5737130803Smarcel * If we're processing the symbols for the referencing library, 5738130803Smarcel * we'll see a global "g", but in this case the address given 5739130803Smarcel * in the symbol table contains a pointer to the real "g". 5740130803Smarcel * We use the storage class LOC_INDIRECT to indicate this. RT 5741130803Smarcel */ 5742130803Smarcel if (is_in_import_list (DEPRECATED_SYMBOL_NAME (sym), objfile)) 5743130803Smarcel SYMBOL_CLASS (sym) = LOC_INDIRECT; 5744130803Smarcel 5745130803Smarcel SYMBOL_VALUE_ADDRESS (sym) = dn_bufp->dsvar.location + data_offset; 5746130803Smarcel SYMBOL_TYPE (sym) = hpread_type_lookup (dn_bufp->dsvar.type, objfile); 5747130803Smarcel 5748130803Smarcel if (dn_bufp->dsvar.global) 5749130803Smarcel add_symbol_to_list (sym, &global_symbols); 5750130803Smarcel 5751130803Smarcel else if (WITHIN_FUNCTION (objfile)) 5752130803Smarcel add_symbol_to_list (sym, &local_symbols); 5753130803Smarcel 5754130803Smarcel else 5755130803Smarcel add_symbol_to_list (sym, &file_symbols); 5756130803Smarcel 5757130803Smarcel if (dn_bufp->dsvar.thread_specific) 5758130803Smarcel { 5759130803Smarcel /* Thread-local variable. 5760130803Smarcel */ 5761130803Smarcel SYMBOL_CLASS (sym) = LOC_HP_THREAD_LOCAL_STATIC; 5762130803Smarcel SYMBOL_BASEREG (sym) = CR27_REGNUM; 5763130803Smarcel 5764130803Smarcel if (objfile->flags & OBJF_SHARED) 5765130803Smarcel { 5766130803Smarcel /* 5767130803Smarcel * This variable is not only thread local but 5768130803Smarcel * in a shared library. 5769130803Smarcel * 5770130803Smarcel * Alas, the shared lib structures are private 5771130803Smarcel * to "somsolib.c". But C lets us point to one. 5772130803Smarcel */ 5773130803Smarcel struct so_list *so; 5774130803Smarcel 5775130803Smarcel if (objfile->obj_private == NULL) 5776130803Smarcel error ("Internal error in reading shared library information."); 5777130803Smarcel 5778130803Smarcel so = ((obj_private_data_t *) (objfile->obj_private))->so_info; 5779130803Smarcel if (so == NULL) 5780130803Smarcel error ("Internal error in reading shared library information."); 5781130803Smarcel 5782130803Smarcel /* Thread-locals in shared libraries do NOT have the 5783130803Smarcel * standard offset ("data_offset"), so we re-calculate 5784130803Smarcel * where to look for this variable, using a call-back 5785130803Smarcel * to interpret the private shared-library data. 5786130803Smarcel */ 5787130803Smarcel SYMBOL_VALUE_ADDRESS (sym) = dn_bufp->dsvar.location + 5788130803Smarcel so_lib_thread_start_addr (so); 5789130803Smarcel } 5790130803Smarcel } 5791130803Smarcel break; 5792130803Smarcel 5793130803Smarcel case DNTT_TYPE_DVAR: 5794130803Smarcel /* Dynamic variables. */ 5795130803Smarcel if (dn_bufp->ddvar.regvar) 5796130803Smarcel SYMBOL_CLASS (sym) = LOC_REGISTER; 5797130803Smarcel else 5798130803Smarcel SYMBOL_CLASS (sym) = LOC_LOCAL; 5799130803Smarcel 5800130803Smarcel SYMBOL_VALUE (sym) = dn_bufp->ddvar.location; 5801130803Smarcel#ifdef HPREAD_ADJUST_STACK_ADDRESS 5802130803Smarcel SYMBOL_VALUE (sym) 5803130803Smarcel += HPREAD_ADJUST_STACK_ADDRESS (CURRENT_FUNCTION_VALUE (objfile)); 5804130803Smarcel#endif 5805130803Smarcel SYMBOL_TYPE (sym) = hpread_type_lookup (dn_bufp->ddvar.type, objfile); 5806130803Smarcel if (dn_bufp->ddvar.global) 5807130803Smarcel add_symbol_to_list (sym, &global_symbols); 5808130803Smarcel else if (WITHIN_FUNCTION (objfile)) 5809130803Smarcel add_symbol_to_list (sym, &local_symbols); 5810130803Smarcel else 5811130803Smarcel add_symbol_to_list (sym, &file_symbols); 5812130803Smarcel break; 5813130803Smarcel 5814130803Smarcel case DNTT_TYPE_CONST: 5815130803Smarcel /* A constant (pascal?). */ 5816130803Smarcel SYMBOL_CLASS (sym) = LOC_CONST; 5817130803Smarcel SYMBOL_VALUE (sym) = dn_bufp->dconst.location; 5818130803Smarcel SYMBOL_TYPE (sym) = hpread_type_lookup (dn_bufp->dconst.type, objfile); 5819130803Smarcel if (dn_bufp->dconst.global) 5820130803Smarcel add_symbol_to_list (sym, &global_symbols); 5821130803Smarcel else if (WITHIN_FUNCTION (objfile)) 5822130803Smarcel add_symbol_to_list (sym, &local_symbols); 5823130803Smarcel else 5824130803Smarcel add_symbol_to_list (sym, &file_symbols); 5825130803Smarcel break; 5826130803Smarcel 5827130803Smarcel case DNTT_TYPE_TYPEDEF: 5828130803Smarcel /* A typedef. We do want to process these, since a name is 5829130803Smarcel * added to the domain for the typedef'ed name. 5830130803Smarcel */ 5831130803Smarcel SYMBOL_DOMAIN (sym) = VAR_DOMAIN; 5832130803Smarcel SYMBOL_TYPE (sym) = hpread_type_lookup (dn_bufp->dtype.type, objfile); 5833130803Smarcel if (dn_bufp->dtype.global) 5834130803Smarcel add_symbol_to_list (sym, &global_symbols); 5835130803Smarcel else if (WITHIN_FUNCTION (objfile)) 5836130803Smarcel add_symbol_to_list (sym, &local_symbols); 5837130803Smarcel else 5838130803Smarcel add_symbol_to_list (sym, &file_symbols); 5839130803Smarcel break; 5840130803Smarcel 5841130803Smarcel case DNTT_TYPE_TAGDEF: 5842130803Smarcel { 5843130803Smarcel int global = dn_bufp->dtag.global; 5844130803Smarcel /* Structure, union, enum, template, or class tag definition */ 5845130803Smarcel /* We do want to process these, since a name is 5846130803Smarcel * added to the domain for the tag name (and if C++ class, 5847130803Smarcel * for the typename also). 5848130803Smarcel */ 5849130803Smarcel SYMBOL_DOMAIN (sym) = STRUCT_DOMAIN; 5850130803Smarcel 5851130803Smarcel /* The tag contains in its "type" field a pointer to the 5852130803Smarcel * DNTT_TYPE_STRUCT, DNTT_TYPE_UNION, DNTT_TYPE_ENUM, 5853130803Smarcel * DNTT_TYPE_CLASS or DNTT_TYPE_TEMPLATE 5854130803Smarcel * record that actually defines the type. 5855130803Smarcel */ 5856130803Smarcel SYMBOL_TYPE (sym) = hpread_type_lookup (dn_bufp->dtype.type, objfile); 5857130803Smarcel TYPE_NAME (sym->type) = DEPRECATED_SYMBOL_NAME (sym); 5858130803Smarcel TYPE_TAG_NAME (sym->type) = DEPRECATED_SYMBOL_NAME (sym); 5859130803Smarcel if (dn_bufp->dtag.global) 5860130803Smarcel add_symbol_to_list (sym, &global_symbols); 5861130803Smarcel else if (WITHIN_FUNCTION (objfile)) 5862130803Smarcel add_symbol_to_list (sym, &local_symbols); 5863130803Smarcel else 5864130803Smarcel add_symbol_to_list (sym, &file_symbols); 5865130803Smarcel 5866130803Smarcel /* If this is a C++ class, then we additionally 5867130803Smarcel * need to define a typedef for the 5868130803Smarcel * class type. E.g., so that the name "c" becomes visible as 5869130803Smarcel * a type name when the user says "class c { ... }". 5870130803Smarcel * In order to figure this out, we need to chase down the "type" 5871130803Smarcel * field to get to the DNTT_TYPE_CLASS record. 5872130803Smarcel * 5873130803Smarcel * We also add the typename for ENUM. Though this isn't 5874130803Smarcel * strictly correct, it is necessary because of the debug info 5875130803Smarcel * generated by the aCC compiler, in which we cannot 5876130803Smarcel * distinguish between: 5877130803Smarcel * enum e { ... }; 5878130803Smarcel * and 5879130803Smarcel * typedef enum { ... } e; 5880130803Smarcel * I.e., the compiler emits the same debug info for the above 5881130803Smarcel * two cases, in both cases "e" appearing as a tagdef. 5882130803Smarcel * Therefore go ahead and generate the typename so that 5883130803Smarcel * "ptype e" will work in the above cases. 5884130803Smarcel * 5885130803Smarcel * We also add the typename for TEMPLATE, so as to allow "ptype t" 5886130803Smarcel * when "t" is a template name. 5887130803Smarcel */ 5888130803Smarcel if (dn_bufp->dtype.type.dnttp.index < LNTT_SYMCOUNT (objfile)) 5889130803Smarcel dn_bufp = hpread_get_lntt (dn_bufp->dtag.type.dnttp.index, objfile); 5890130803Smarcel else 5891130803Smarcel { 5892130803Smarcel complaint (&symfile_complaints, "error processing class tagdef"); 5893130803Smarcel return; 5894130803Smarcel } 5895130803Smarcel if (dn_bufp->dblock.kind == DNTT_TYPE_CLASS || 5896130803Smarcel dn_bufp->dblock.kind == DNTT_TYPE_ENUM || 5897130803Smarcel dn_bufp->dblock.kind == DNTT_TYPE_TEMPLATE) 5898130803Smarcel { 5899130803Smarcel struct symbol *newsym; 5900130803Smarcel 5901130803Smarcel newsym = (struct symbol *) obstack_alloc (&objfile->objfile_obstack, 5902130803Smarcel sizeof (struct symbol)); 5903130803Smarcel memset (newsym, 0, sizeof (struct symbol)); 5904130803Smarcel DEPRECATED_SYMBOL_NAME (newsym) = name; 5905130803Smarcel SYMBOL_LANGUAGE (newsym) = language_auto; 5906130803Smarcel SYMBOL_DOMAIN (newsym) = VAR_DOMAIN; 5907130803Smarcel SYMBOL_LINE (newsym) = 0; 5908130803Smarcel SYMBOL_VALUE (newsym) = 0; 5909130803Smarcel SYMBOL_CLASS (newsym) = LOC_TYPEDEF; 5910130803Smarcel SYMBOL_TYPE (newsym) = sym->type; 5911130803Smarcel if (global) 5912130803Smarcel add_symbol_to_list (newsym, &global_symbols); 5913130803Smarcel else if (WITHIN_FUNCTION (objfile)) 5914130803Smarcel add_symbol_to_list (newsym, &local_symbols); 5915130803Smarcel else 5916130803Smarcel add_symbol_to_list (newsym, &file_symbols); 5917130803Smarcel } 5918130803Smarcel } 5919130803Smarcel break; 5920130803Smarcel 5921130803Smarcel case DNTT_TYPE_POINTER: 5922130803Smarcel /* Declares a pointer type. Should not be necessary to do anything 5923130803Smarcel * with the type at this level; these are processed 5924130803Smarcel * at the hpread_type_lookup() level. 5925130803Smarcel */ 5926130803Smarcel break; 5927130803Smarcel 5928130803Smarcel case DNTT_TYPE_ENUM: 5929130803Smarcel /* Declares an enum type. Should not be necessary to do anything 5930130803Smarcel * with the type at this level; these are processed 5931130803Smarcel * at the hpread_type_lookup() level. 5932130803Smarcel */ 5933130803Smarcel break; 5934130803Smarcel 5935130803Smarcel case DNTT_TYPE_MEMENUM: 5936130803Smarcel /* Member of enum */ 5937130803Smarcel /* Ignored at this level, but hpread_read_enum_type() will take 5938130803Smarcel * care of walking the list of enumeration members. 5939130803Smarcel */ 5940130803Smarcel break; 5941130803Smarcel 5942130803Smarcel case DNTT_TYPE_SET: 5943130803Smarcel /* Declares a set type. Should not be necessary to do anything 5944130803Smarcel * with the type at this level; these are processed 5945130803Smarcel * at the hpread_type_lookup() level. 5946130803Smarcel */ 5947130803Smarcel break; 5948130803Smarcel 5949130803Smarcel case DNTT_TYPE_SUBRANGE: 5950130803Smarcel /* Declares a subrange type. Should not be necessary to do anything 5951130803Smarcel * with the type at this level; these are processed 5952130803Smarcel * at the hpread_type_lookup() level. 5953130803Smarcel */ 5954130803Smarcel break; 5955130803Smarcel 5956130803Smarcel case DNTT_TYPE_ARRAY: 5957130803Smarcel /* Declares an array type. Should not be necessary to do anything 5958130803Smarcel * with the type at this level; these are processed 5959130803Smarcel * at the hpread_type_lookup() level. 5960130803Smarcel */ 5961130803Smarcel break; 5962130803Smarcel 5963130803Smarcel case DNTT_TYPE_STRUCT: 5964130803Smarcel case DNTT_TYPE_UNION: 5965130803Smarcel /* Declares an struct/union type. 5966130803Smarcel * Should not be necessary to do anything 5967130803Smarcel * with the type at this level; these are processed 5968130803Smarcel * at the hpread_type_lookup() level. 5969130803Smarcel */ 5970130803Smarcel break; 5971130803Smarcel 5972130803Smarcel case DNTT_TYPE_FIELD: 5973130803Smarcel /* Structure/union/class field */ 5974130803Smarcel /* Ignored at this level, but hpread_read_struct_type() will take 5975130803Smarcel * care of walking the list of structure/union/class members. 5976130803Smarcel */ 5977130803Smarcel break; 5978130803Smarcel 5979130803Smarcel /* DNTT_TYPE_VARIANT is not handled by GDB */ 5980130803Smarcel 5981130803Smarcel /* DNTT_TYPE_FILE is not handled by GDB */ 5982130803Smarcel 5983130803Smarcel case DNTT_TYPE_FUNCTYPE: 5984130803Smarcel /* Function type */ 5985130803Smarcel /* Ignored at this level, handled within hpread_type_lookup() */ 5986130803Smarcel break; 5987130803Smarcel 5988130803Smarcel case DNTT_TYPE_WITH: 5989130803Smarcel /* This is emitted within methods to indicate "with <class>" 5990130803Smarcel * scoping rules (i.e., indicate that the class data members 5991130803Smarcel * are directly visible). 5992130803Smarcel * However, since GDB already infers this by looking at the 5993130803Smarcel * "this" argument, interpreting the DNTT_TYPE_WITH 5994130803Smarcel * symbol record is unnecessary. 5995130803Smarcel */ 5996130803Smarcel break; 5997130803Smarcel 5998130803Smarcel case DNTT_TYPE_COMMON: 5999130803Smarcel /* FORTRAN common. Not yet handled. */ 6000130803Smarcel complaint (&symfile_complaints, 6001130803Smarcel "unhandled symbol in hp-symtab-read.c: DNTT_TYPE_COMMON."); 6002130803Smarcel break; 6003130803Smarcel 6004130803Smarcel /* DNTT_TYPE_COBSTRUCT is not handled by GDB. */ 6005130803Smarcel /* DNTT_TYPE_XREF is not handled by GDB. */ 6006130803Smarcel /* DNTT_TYPE_SA is not handled by GDB. */ 6007130803Smarcel /* DNTT_TYPE_MACRO is not handled by GDB */ 6008130803Smarcel 6009130803Smarcel case DNTT_TYPE_BLOCKDATA: 6010130803Smarcel /* Not sure what this is - part of FORTRAN support maybe? 6011130803Smarcel * Anyway, not yet handled. 6012130803Smarcel */ 6013130803Smarcel complaint (&symfile_complaints, 6014130803Smarcel "unhandled symbol in hp-symtab-read.c: DNTT_TYPE_BLOCKDATA."); 6015130803Smarcel break; 6016130803Smarcel 6017130803Smarcel case DNTT_TYPE_CLASS_SCOPE: 6018130803Smarcel 6019130803Smarcel 6020130803Smarcel 6021130803Smarcel /* The compiler brackets member functions with a CLASS_SCOPE/END 6022130803Smarcel * pair of records, presumably to put them in a different scope 6023130803Smarcel * from the module scope where they are normally defined. 6024130803Smarcel * E.g., in the situation: 6025130803Smarcel * void f() { ... } 6026130803Smarcel * void c::f() { ...} 6027130803Smarcel * The member function "c::f" will be bracketed by a CLASS_SCOPE/END. 6028130803Smarcel * This causes "break f" at the module level to pick the 6029130803Smarcel * the file-level function f(), not the member function 6030130803Smarcel * (which needs to be referenced via "break c::f"). 6031130803Smarcel * 6032130803Smarcel * Here we record the class name to generate the demangled names of 6033130803Smarcel * member functions later. 6034130803Smarcel * 6035130803Smarcel * FIXME Not being used now for anything -- cplus_demangle seems 6036130803Smarcel * enough for getting the class-qualified names of functions. We 6037130803Smarcel * may need this for handling nested classes and types. */ 6038130803Smarcel 6039130803Smarcel /* pai: FIXME Not handling nested classes for now -- need to 6040130803Smarcel * maintain a stack */ 6041130803Smarcel 6042130803Smarcel dn_temp = hpread_get_lntt (dn_bufp->dclass_scope.type.dnttp.index, objfile); 6043130803Smarcel if (dn_temp->dblock.kind == DNTT_TYPE_TAGDEF) 6044130803Smarcel class_scope_name = VT (objfile) + dn_temp->dtag.name; 6045130803Smarcel else 6046130803Smarcel class_scope_name = NULL; 6047130803Smarcel 6048130803Smarcel#if 0 6049130803Smarcel 6050130803Smarcel /* Begin a new scope. */ 6051130803Smarcel SL_INDEX (objfile) = hpread_record_lines (current_subfile, 6052130803Smarcel SL_INDEX (objfile), 6053130803Smarcel dn_bufp->dclass_scope.address, 6054130803Smarcel objfile, offset); 6055130803Smarcel valu = hpread_get_location (dn_bufp->dclass_scope.address, objfile); 6056130803Smarcel valu += offset; /* Relocate for dynamic loading */ 6057130803Smarcel desc = hpread_get_scope_start (dn_bufp->dclass_scope.address, objfile); 6058130803Smarcel /* We use the scope start DNTT index as the nesting depth identifier! */ 6059130803Smarcel new = push_context (desc, valu); 6060130803Smarcel#endif 6061130803Smarcel break; 6062130803Smarcel 6063130803Smarcel case DNTT_TYPE_REFERENCE: 6064130803Smarcel /* Declares a C++ reference type. Should not be necessary to do anything 6065130803Smarcel * with the type at this level; these are processed 6066130803Smarcel * at the hpread_type_lookup() level. 6067130803Smarcel */ 6068130803Smarcel break; 6069130803Smarcel 6070130803Smarcel case DNTT_TYPE_PTRMEM: 6071130803Smarcel /* Declares a C++ pointer-to-data-member type. This does not 6072130803Smarcel * need to be handled at this level; being a type description it 6073130803Smarcel * is instead handled at the hpread_type_lookup() level. 6074130803Smarcel */ 6075130803Smarcel break; 6076130803Smarcel 6077130803Smarcel case DNTT_TYPE_PTRMEMFUNC: 6078130803Smarcel /* Declares a C++ pointer-to-function-member type. This does not 6079130803Smarcel * need to be handled at this level; being a type description it 6080130803Smarcel * is instead handled at the hpread_type_lookup() level. 6081130803Smarcel */ 6082130803Smarcel break; 6083130803Smarcel 6084130803Smarcel case DNTT_TYPE_CLASS: 6085130803Smarcel /* Declares a class type. 6086130803Smarcel * Should not be necessary to do anything 6087130803Smarcel * with the type at this level; these are processed 6088130803Smarcel * at the hpread_type_lookup() level. 6089130803Smarcel */ 6090130803Smarcel break; 6091130803Smarcel 6092130803Smarcel case DNTT_TYPE_GENFIELD: 6093130803Smarcel /* I believe this is used for class member functions */ 6094130803Smarcel /* Ignored at this level, but hpread_read_struct_type() will take 6095130803Smarcel * care of walking the list of class members. 6096130803Smarcel */ 6097130803Smarcel break; 6098130803Smarcel 6099130803Smarcel case DNTT_TYPE_VFUNC: 6100130803Smarcel /* Virtual function */ 6101130803Smarcel /* This does not have to be handled at this level; handled in 6102130803Smarcel * the course of processing class symbols. 6103130803Smarcel */ 6104130803Smarcel break; 6105130803Smarcel 6106130803Smarcel case DNTT_TYPE_MEMACCESS: 6107130803Smarcel /* DDE ignores this symbol table record. 6108130803Smarcel * It has something to do with "modified access" to class members. 6109130803Smarcel * I'll assume we can safely ignore it too. 6110130803Smarcel */ 6111130803Smarcel break; 6112130803Smarcel 6113130803Smarcel case DNTT_TYPE_INHERITANCE: 6114130803Smarcel /* These don't have to be handled here, since they are handled 6115130803Smarcel * within hpread_read_struct_type() in the process of constructing 6116130803Smarcel * a class type. 6117130803Smarcel */ 6118130803Smarcel break; 6119130803Smarcel 6120130803Smarcel case DNTT_TYPE_FRIEND_CLASS: 6121130803Smarcel case DNTT_TYPE_FRIEND_FUNC: 6122130803Smarcel /* These can safely be ignored, as GDB doesn't need this 6123130803Smarcel * info. DDE only uses it in "describe". We may later want 6124130803Smarcel * to extend GDB's "ptype" to give this info, but for now 6125130803Smarcel * it seems safe enough to ignore it. 6126130803Smarcel */ 6127130803Smarcel break; 6128130803Smarcel 6129130803Smarcel case DNTT_TYPE_MODIFIER: 6130130803Smarcel /* Intended to supply "modified access" to a type */ 6131130803Smarcel /* From the way DDE handles this, it looks like it always 6132130803Smarcel * modifies a type. Therefore it is safe to ignore it at this 6133130803Smarcel * level, and handle it in hpread_type_lookup(). 6134130803Smarcel */ 6135130803Smarcel break; 6136130803Smarcel 6137130803Smarcel case DNTT_TYPE_OBJECT_ID: 6138130803Smarcel /* Just ignore this - that's all DDE does */ 6139130803Smarcel break; 6140130803Smarcel 6141130803Smarcel case DNTT_TYPE_MEMFUNC: 6142130803Smarcel /* Member function */ 6143130803Smarcel /* This does not have to be handled at this level; handled in 6144130803Smarcel * the course of processing class symbols. 6145130803Smarcel */ 6146130803Smarcel break; 6147130803Smarcel 6148130803Smarcel case DNTT_TYPE_DOC_MEMFUNC: 6149130803Smarcel /* Member function */ 6150130803Smarcel /* This does not have to be handled at this level; handled in 6151130803Smarcel * the course of processing class symbols. 6152130803Smarcel */ 6153130803Smarcel break; 6154130803Smarcel 6155130803Smarcel case DNTT_TYPE_TEMPLATE: 6156130803Smarcel /* Template - sort of the header for a template definition, 6157130803Smarcel * which like a class, points to a member list and also points 6158130803Smarcel * to a TEMPLATE_ARG list of type-arguments. 6159130803Smarcel * We do not need to process TEMPLATE records at this level though. 6160130803Smarcel */ 6161130803Smarcel break; 6162130803Smarcel 6163130803Smarcel case DNTT_TYPE_TEMPLATE_ARG: 6164130803Smarcel /* The TEMPLATE record points to an argument list of 6165130803Smarcel * TEMPLATE_ARG records, each of which describes one 6166130803Smarcel * of the type-arguments. 6167130803Smarcel * We do not need to process TEMPLATE_ARG records at this level though. 6168130803Smarcel */ 6169130803Smarcel break; 6170130803Smarcel 6171130803Smarcel case DNTT_TYPE_FUNC_TEMPLATE: 6172130803Smarcel /* This will get emitted for member functions of templates. 6173130803Smarcel * But we don't need to process this record at this level though, 6174130803Smarcel * we will process it in the course of processing a TEMPLATE 6175130803Smarcel * record. 6176130803Smarcel */ 6177130803Smarcel break; 6178130803Smarcel 6179130803Smarcel case DNTT_TYPE_LINK: 6180130803Smarcel /* The LINK record is used to link up templates with instantiations. */ 6181130803Smarcel /* It is not clear why this is needed, and furthermore aCC does 6182130803Smarcel * not appear to generate this, so I think we can safely ignore it. - RT 6183130803Smarcel */ 6184130803Smarcel break; 6185130803Smarcel 6186130803Smarcel /* DNTT_TYPE_DYN_ARRAY_DESC is not handled by GDB */ 6187130803Smarcel /* DNTT_TYPE_DESC_SUBRANGE is not handled by GDB */ 6188130803Smarcel /* DNTT_TYPE_BEGIN_EXT is not handled by GDB */ 6189130803Smarcel /* DNTT_TYPE_INLN is not handled by GDB */ 6190130803Smarcel /* DNTT_TYPE_INLN_LIST is not handled by GDB */ 6191130803Smarcel /* DNTT_TYPE_ALIAS is not handled by GDB */ 6192130803Smarcel 6193130803Smarcel default: 6194130803Smarcel break; 6195130803Smarcel } 6196130803Smarcel} 6197130803Smarcel 6198130803Smarcel/* Get nesting depth for a DNTT entry. 6199130803Smarcel * DN_BUFP points to a DNTT entry. 6200130803Smarcel * OBJFILE is the object file. 6201130803Smarcel * REPORT_NESTED is a flag; if 0, real nesting depth is 6202130803Smarcel * reported, if it is 1, the function simply returns a 6203130803Smarcel * non-zero value if the nesting depth is anything > 0. 6204130803Smarcel * 6205130803Smarcel * Return value is an integer. 0 => not a local type / name 6206130803Smarcel * positive return => type or name is local to some 6207130803Smarcel * block or function. 6208130803Smarcel */ 6209130803Smarcel 6210130803Smarcel 6211130803Smarcel/* elz: ATTENTION: FIXME: NOTE: WARNING!!!! 6212130803Smarcel this function now returns 0 right away. It was taking too much time 6213130803Smarcel at start up. Now, though, the local types are not handled correctly. 6214130803Smarcel */ 6215130803Smarcel 6216130803Smarcel 6217130803Smarcelstatic int 6218130803Smarcelhpread_get_scope_depth (union dnttentry *dn_bufp, struct objfile *objfile, 6219130803Smarcel int report_nested) 6220130803Smarcel{ 6221130803Smarcel int index; 6222130803Smarcel union dnttentry *dn_tmp; 6223130803Smarcel short depth = 0; 6224130803Smarcel/****************************/ 6225130803Smarcel return 0; 6226130803Smarcel/****************************/ 6227130803Smarcel 6228130803Smarcel index = (((char *) dn_bufp) - LNTT (objfile)) / (sizeof (struct dntt_type_block)); 6229130803Smarcel 6230130803Smarcel while (--index >= 0) 6231130803Smarcel { 6232130803Smarcel dn_tmp = hpread_get_lntt (index, objfile); 6233130803Smarcel switch (dn_tmp->dblock.kind) 6234130803Smarcel { 6235130803Smarcel case DNTT_TYPE_MODULE: 6236130803Smarcel return depth; 6237130803Smarcel case DNTT_TYPE_END: 6238130803Smarcel /* index is signed int; dnttp.index is 29-bit unsigned int! */ 6239130803Smarcel index = (int) dn_tmp->dend.beginscope.dnttp.index; 6240130803Smarcel break; 6241130803Smarcel case DNTT_TYPE_BEGIN: 6242130803Smarcel case DNTT_TYPE_FUNCTION: 6243130803Smarcel case DNTT_TYPE_DOC_FUNCTION: 6244130803Smarcel case DNTT_TYPE_WITH: 6245130803Smarcel case DNTT_TYPE_COMMON: 6246130803Smarcel case DNTT_TYPE_CLASS_SCOPE: 6247130803Smarcel depth++; 6248130803Smarcel if (report_nested) 6249130803Smarcel return 1; 6250130803Smarcel break; 6251130803Smarcel default: 6252130803Smarcel break; 6253130803Smarcel } 6254130803Smarcel } 6255130803Smarcel return depth; 6256130803Smarcel} 6257130803Smarcel 6258130803Smarcel/* Adjust the bitoffsets for all fields of an anonymous union of 6259130803Smarcel type TYPE by negative BITS. This handles HP aCC's hideous habit 6260130803Smarcel of giving members of anonymous unions bit offsets relative to the 6261130803Smarcel enclosing structure instead of relative to the union itself. */ 6262130803Smarcel 6263130803Smarcelstatic void 6264130803Smarcelhpread_adjust_bitoffsets (struct type *type, int bits) 6265130803Smarcel{ 6266130803Smarcel int i; 6267130803Smarcel 6268130803Smarcel /* This is done only for unions; caller had better check that 6269130803Smarcel it is an anonymous one. */ 6270130803Smarcel if (TYPE_CODE (type) != TYPE_CODE_UNION) 6271130803Smarcel return; 6272130803Smarcel 6273130803Smarcel /* Adjust each field; since this is a union, there are no base 6274130803Smarcel classes. Also no static membes. Also, no need for recursion as 6275130803Smarcel the members of this union if themeselves structs or unions, have 6276130803Smarcel the correct bitoffsets; if an anonymous union is a member of this 6277130803Smarcel anonymous union, the code in hpread_read_struct_type() will 6278130803Smarcel adjust for that. */ 6279130803Smarcel 6280130803Smarcel for (i = 0; i < TYPE_NFIELDS (type); i++) 6281130803Smarcel TYPE_FIELD_BITPOS (type, i) -= bits; 6282130803Smarcel} 6283130803Smarcel 6284130803Smarcel/* Because of quirks in HP compilers' treatment of anonymous unions inside 6285130803Smarcel classes, we have to chase through a chain of threaded FIELD entries. 6286130803Smarcel If we encounter an anonymous union in the chain, we must recursively skip over 6287130803Smarcel that too. 6288130803Smarcel 6289130803Smarcel This function does a "next" in the chain of FIELD entries, but transparently 6290130803Smarcel skips over anonymous unions' fields (recursively). 6291130803Smarcel 6292130803Smarcel Inputs are the number of times to do "next" at the top level, the dnttpointer 6293130803Smarcel (FIELD) and entry pointer (FIELDP) for the dntt record corresponding to it, 6294130803Smarcel and the ubiquitous objfile parameter. (Note: FIELDP is a **.) Return value 6295130803Smarcel is a dnttpointer for the new field after all the skipped ones */ 6296130803Smarcel 6297130803Smarcelstatic dnttpointer 6298130803Smarcelhpread_get_next_skip_over_anon_unions (int skip_fields, dnttpointer field, 6299130803Smarcel union dnttentry **fieldp, 6300130803Smarcel struct objfile *objfile) 6301130803Smarcel{ 6302130803Smarcel struct type *anon_type; 6303130803Smarcel int i; 6304130803Smarcel int bitoffset; 6305130803Smarcel char *name; 6306130803Smarcel 6307130803Smarcel for (i = 0; i < skip_fields; i++) 6308130803Smarcel { 6309130803Smarcel /* Get type of item we're looking at now; recursively processes the types 6310130803Smarcel of these intermediate items we skip over, so they aren't lost. */ 6311130803Smarcel anon_type = hpread_type_lookup ((*fieldp)->dfield.type, objfile); 6312130803Smarcel anon_type = CHECK_TYPEDEF (anon_type); 6313130803Smarcel bitoffset = (*fieldp)->dfield.bitoffset; 6314130803Smarcel name = VT (objfile) + (*fieldp)->dfield.name; 6315130803Smarcel /* First skip over one item to avoid stack death on recursion */ 6316130803Smarcel field = (*fieldp)->dfield.nextfield; 6317130803Smarcel *fieldp = hpread_get_lntt (field.dnttp.index, objfile); 6318130803Smarcel /* Do we have another anonymous union? If so, adjust the bitoffsets 6319130803Smarcel of its members and skip over its members. */ 6320130803Smarcel if ((TYPE_CODE (anon_type) == TYPE_CODE_UNION) && 6321130803Smarcel (!name || DEPRECATED_STREQ (name, ""))) 6322130803Smarcel { 6323130803Smarcel hpread_adjust_bitoffsets (anon_type, bitoffset); 6324130803Smarcel field = hpread_get_next_skip_over_anon_unions (TYPE_NFIELDS (anon_type), field, fieldp, objfile); 6325130803Smarcel } 6326130803Smarcel } 6327130803Smarcel return field; 6328130803Smarcel} 6329