*** symfile.c.orig Mon Jun 18 09:55:22 2001 --- symfile.c Fri May 11 08:58:39 2001 *************** *** 2058,2070 **** int i; char *cp; if (filename != NULL) if ((cp = strrchr (filename, '.')) != NULL) ! for (i = 0; i < fl_table_next; i++) ! if (strcmp (cp, filename_language_table[i].ext) == 0) ! return filename_language_table[i].lang; return language_unknown; } /* allocate_symtab: --- 2058,2074 ---- int i; char *cp; if (filename != NULL) if ((cp = strrchr (filename, '.')) != NULL) ! { ! if (strlen(filename)>6 && strcmp(cp-4,".int.c")==0) ! return language_cplus; ! for (i = 0; i < fl_table_next; i++) ! if (strcmp (cp, filename_language_table[i].ext) == 0) ! return filename_language_table[i].lang; ! } return language_unknown; } /* allocate_symtab: *** stabsread.c.orig Mon Jun 18 09:55:39 2001 --- stabsread.c Fri Jun 8 14:45:23 2001 *************** *** 1305,1314 **** --- 1305,1329 ---- or this is a forward reference to it. */ *string = p; return -1; } } + + /* recogize an EDG compiler-generated temporary, like __T136266940 */ + int + is_edg_temporary_var( sym ) + struct symbol *sym; + { + char * pname = sym->ginfo.name; + if ( pname[0]=='_' && pname[1]=='_' && pname[2]=='T' ) { + pname+=3; + while ( isdigit(*pname) ) pname++; + if ( *pname=='\0' ) + return 1; + } + return 0; + } /* ARGSUSED */ struct symbol * define_symbol (valu, string, desc, type, objfile) CORE_ADDR valu; *************** *** 1723,1733 **** case 'l': SYMBOL_TYPE (sym) = read_type (&p, objfile); SYMBOL_CLASS (sym) = LOC_LOCAL; SYMBOL_VALUE (sym) = valu; SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE; ! add_symbol_to_list (sym, &local_symbols); break; case 'p': if (*p == 'F') /* pF is a two-letter code that means a function parameter in Fortran. --- 1738,1749 ---- case 'l': SYMBOL_TYPE (sym) = read_type (&p, objfile); SYMBOL_CLASS (sym) = LOC_LOCAL; SYMBOL_VALUE (sym) = valu; SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE; ! if ( !EDG_DEMANGLING || !is_edg_temporary_var(sym) ) ! add_symbol_to_list (sym, &local_symbols); break; case 'p': if (*p == 'F') /* pF is a two-letter code that means a function parameter in Fortran. *************** *** 2050,2062 **** obstack_alloc (&objfile->symbol_obstack, sizeof (struct symbol)); *typedef_sym = *sym; SYMBOL_CLASS (typedef_sym) = LOC_TYPEDEF; SYMBOL_VALUE (typedef_sym) = valu; SYMBOL_NAMESPACE (typedef_sym) = VAR_NAMESPACE; ! if (TYPE_NAME (SYMBOL_TYPE (sym)) == 0) ! TYPE_NAME (SYMBOL_TYPE (sym)) ! = obconcat (&objfile->type_obstack, "", "", SYMBOL_NAME (sym)); add_symbol_to_list (typedef_sym, &file_symbols); } break; case 'V': --- 2066,2087 ---- obstack_alloc (&objfile->symbol_obstack, sizeof (struct symbol)); *typedef_sym = *sym; SYMBOL_CLASS (typedef_sym) = LOC_TYPEDEF; SYMBOL_VALUE (typedef_sym) = valu; SYMBOL_NAMESPACE (typedef_sym) = VAR_NAMESPACE; ! /* SYMBOL_TYPE (sym) and SYMBOL_TYPE (typedef_sym) are identical at this point */ ! if (TYPE_NAME (SYMBOL_TYPE (sym)) == 0) { ! if ( SYMBOL_LANGUAGE (sym)==language_cplus && SYMBOL_CPLUS_DEMANGLED_NAME (sym) ) { ! /* name of type should be demangled C++ name, if there is one */ ! TYPE_NAME (SYMBOL_TYPE (typedef_sym)) ! = obconcat (&objfile->type_obstack, "", "", SYMBOL_CPLUS_DEMANGLED_NAME (sym)); ! TYPE_TAG_NAME (SYMBOL_TYPE (typedef_sym)) ! = obconcat (&objfile->type_obstack, "", "", SYMBOL_CPLUS_DEMANGLED_NAME (sym)); ! } else ! TYPE_NAME (SYMBOL_TYPE (sym)) ! = obconcat (&objfile->type_obstack, "", "", SYMBOL_NAME (sym)); ! } add_symbol_to_list (typedef_sym, &file_symbols); } break; case 'V': *************** *** 2078,2088 **** #endif SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE; if (os9k_stabs) add_symbol_to_list (sym, &global_symbols); else ! add_symbol_to_list (sym, &local_symbols); break; case 'v': /* Reference parameter */ SYMBOL_TYPE (sym) = read_type (&p, objfile); --- 2103,2114 ---- #endif SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE; if (os9k_stabs) add_symbol_to_list (sym, &global_symbols); else ! if ( !EDG_DEMANGLING && !is_edg_temporary_var(sym) ) ! add_symbol_to_list (sym, &local_symbols); break; case 'v': /* Reference parameter */ SYMBOL_TYPE (sym) = read_type (&p, objfile); *************** *** 3514,3523 **** --- 3540,3589 ---- FIELD_BITSIZE (fip->list->field) = 0; } } } + /* fix the baseclasses for stabs created by edg front ends */ + static void + edg_baseclass_fixup( type ) + struct type *type; + { + int i; + int edg_n_baseclasses = 0; + if ( type==NULL || TYPE_CPLUS_SPECIFIC(type)==NULL ) { + /* no c++ info, better not touch it. */ + return; + } + if ( TYPE_N_BASECLASSES(type) > 0 ) { + /* already have base classes for some reason, better not touch it */ + return; + } + for ( i=0; infields; i++ ) { + if ( strncmp( type->fields[i].name, "__b_", 4 )!=0 ) { + /* we're done. */ + break; + } + edg_n_baseclasses++; + } + if ( edg_n_baseclasses==0 ) { + return; + } + ALLOCATE_CPLUS_STRUCT_TYPE (type); + TYPE_N_BASECLASSES(type) = edg_n_baseclasses; + + /* allocate space for virtual flag bits */ + { + int num_bytes = B_BYTES (TYPE_N_BASECLASSES (type)); + char *pointer; + + pointer = (char *) TYPE_ALLOC (type, num_bytes); + TYPE_FIELD_VIRTUAL_BITS (type) = (B_TYPE *) pointer; + } + B_CLRALL (TYPE_FIELD_VIRTUAL_BITS (type), TYPE_N_BASECLASSES (type)); + + } + /* Read struct or class data fields. They have the form: NAME : [VISIBILITY] TYPENUM , BITPOS , BITSIZE ; *************** *** 4149,4158 **** --- 4215,4226 ---- || !attach_fn_fields_to_type (&fi, type) || !read_tilde_fields (&fi, pp, type, objfile)) { type = error_type (pp, objfile); } + + edg_baseclass_fixup(type); do_cleanups (back_to); return (type); } *** hp-symtab-read.c.orig Mon Jun 18 09:56:01 2001 --- hp-symtab-read.c Fri May 18 08:38:53 2001 *************** *** 1204,1213 **** --- 1204,1250 ---- param_symbols = local_list; return type; } + /* KAI EDG-style compiler ends up with lowered base classes, fix those + up here. */ + static void + edg_baseclass_fixup( ptype ) + struct type * ptype; + { + int i; + int edg_n_baseclasses = 0; + if ( TYPE_N_BASECLASSES(ptype) > 0 ) { + /* already have base classes for some reason, better not touch it */ + return; + } + for ( i=0; infields; i++ ) { + if ( strncmp( ptype->fields[i].name, "__b_", 4 )!=0 ) { + /* we're done. */ + break; + } + edg_n_baseclasses++; + } + if ( edg_n_baseclasses==0 ) { + return; + } + ALLOCATE_CPLUS_STRUCT_TYPE (ptype); + TYPE_N_BASECLASSES(ptype) = edg_n_baseclasses; + + /* allocate space for virtual flag bits */ + { + int num_bytes = B_BYTES (TYPE_N_BASECLASSES (ptype)); + char *pointer; + + pointer = (char *) TYPE_ALLOC (ptype, num_bytes); + TYPE_FIELD_VIRTUAL_BITS (ptype) = (B_TYPE *) pointer; + } + B_CLRALL (TYPE_FIELD_VIRTUAL_BITS (ptype), TYPE_N_BASECLASSES (ptype)); + if (TYPE_DECLARED_TYPE (ptype)==DECLARED_TYPE_STRUCT) + TYPE_DECLARED_TYPE (ptype)==DECLARED_TYPE_CLASS; + } /* A file-level variable which keeps track of the current-template * being processed. Set in hpread_read_struct_type() while processing * a template type. Referred to in hpread_get_nth_templ_arg(). *************** *** 1961,1970 **** --- 1998,2011 ---- { n -= 1; TYPE_FIELD (type, n) = tmp_list->field; } + /* if C++ class comes through lowered C code, need to fix it up here */ + if (EDG_DEMANGLING) + edg_baseclass_fixup( type ); + /* Copy the "function-field-list" (i.e., the list of member * functions in the class) to GDB's symbol table */ TYPE_NFN_FIELDS (type) = n_fn_fields; TYPE_NFN_FIELDS_TOTAL (type) = n_fn_fields_total; *************** *** 2520,2535 **** { prefix = ""; } /* Build the correct name. */ ! structtype->name ! = (char *) obstack_alloc (&objfile->type_obstack, ! strlen (prefix) + strlen (suffix) + 1); ! TYPE_NAME (structtype) = strcpy (TYPE_NAME (structtype), prefix); ! TYPE_NAME (structtype) = strcat (TYPE_NAME (structtype), suffix); ! TYPE_TAG_NAME (structtype) = suffix; /* For classes/structs, we have to set the static member "physnames" to point to strings like "Class::Member" */ if (TYPE_CODE (structtype) == TYPE_CODE_STRUCT) fix_static_member_physnames (structtype, suffix, objfile); --- 2561,2592 ---- { prefix = ""; } /* Build the correct name. */ ! structtype->name = NULL; ! if ( EDG_DEMANGLING ) { ! char *demangled = NULL; ! demangled = cplus_demangle (suffix, DMGL_PARAMS | DMGL_ANSI); ! if (demangled != NULL) ! { ! structtype->name ! = (char *) obstack_alloc (&objfile->type_obstack, ! strlen (demangled) + 1 ); ! TYPE_NAME (structtype) = strcpy (TYPE_NAME (structtype), demangled); ! TYPE_TAG_NAME (structtype) = TYPE_NAME (structtype); ! free (demangled); ! } ! } ! if ( structtype->name==NULL ) { ! structtype->name ! = (char *) obstack_alloc (&objfile->type_obstack, ! strlen (prefix) + strlen (suffix) + 1); ! TYPE_NAME (structtype) = strcpy (TYPE_NAME (structtype), prefix); ! TYPE_NAME (structtype) = strcat (TYPE_NAME (structtype), suffix); ! TYPE_TAG_NAME (structtype) = suffix; ! } /* For classes/structs, we have to set the static member "physnames" to point to strings like "Class::Member" */ if (TYPE_CODE (structtype) == TYPE_CODE_STRUCT) fix_static_member_physnames (structtype, suffix, objfile); *************** *** 2789,2798 **** --- 2846,2883 ---- class_name += 6; return class_name; } + /* KAI EDG-style compiler mangles local vars differently. Need to make + sure C++ demangler is called if the right name patterns appear. */ + static void + edg_local_var_demangling( struct pending * local_symbols, struct obstack * ostack ) + { + struct pending *next; + struct symbol *sym; + int j; + char *pn; + for (next = local_symbols; next; next = next->next) + { + for (j = next->nsyms - 1; j >= 0; j--) + { + sym = next->symbol[j]; + pn = SYMBOL_NAME (sym); + if ( pn && pn[0]=='_' && pn[1]=='_' && pn[2]>='0' && pn[2]<='9' + && SYMBOL_CPLUS_DEMANGLED_NAME(sym)==NULL ) + { + if (SYMBOL_LANGUAGE (sym) == language_c || + SYMBOL_LANGUAGE (sym) == language_unknown) { + SYMBOL_LANGUAGE (sym) = language_auto; + } + SYMBOL_INIT_DEMANGLED_NAME(sym,ostack); + } + } + } + } + /* Internalize one native debug symbol. * Called in a loop from hpread_expand_symtab(). * Arguments: * dn_bufp: * name: *************** *** 3009,3018 **** --- 3094,3107 ---- *(char *) (VT (objfile) + dn_bufp->dfunc.alias)) /* not a null string */ SYMBOL_NAME (sym) = VT (objfile) + dn_bufp->dfunc.alias; else SYMBOL_NAME (sym) = VT (objfile) + dn_bufp->dfunc.name; + /* See if this is really a mangled C++ name */ + if ( (EDG_DEMANGLING) && (dn_bufp->dfunc.language == HP_LANGUAGE_C) ) + SYMBOL_INIT_DEMANGLED_NAME (sym, &objfile->symbol_obstack); + /* Special hack to get around HP compilers' insistence on * reporting "main" as "_MAIN_" for C/C++ */ if ((strcmp (SYMBOL_NAME (sym), "_MAIN_") == 0) && (strcmp (VT (objfile) + dn_bufp->dfunc.name, "main") == 0)) SYMBOL_NAME (sym) = VT (objfile) + dn_bufp->dfunc.name; *************** *** 3308,3317 **** --- 3397,3408 ---- objfile); valu = dn_temp->dfunc.hiaddr + offset; /* Insert func params into local list */ merge_symbol_lists (¶m_symbols, &local_symbols); new = pop_context (); + if (EDG_DEMANGLING) + edg_local_var_demangling( local_symbols, &objfile->symbol_obstack ); /* Make a block for the local symbols within. */ finish_block (new->name, &local_symbols, new->old_blocks, new->start_addr, valu, objfile); WITHIN_FUNCTION (objfile) = 0; /* This may have to change for Pascal */ local_symbols = new->locals; *************** *** 3336,3345 **** --- 3427,3438 ---- valu += offset + 9; /* Relocate for dynamic loading */ new = pop_context (); desc = dn_bufp->dend.beginscope.dnttp.index; if (desc != new->depth) complain (&lbrac_mismatch_complaint, (char *) symnum); + if (EDG_DEMANGLING) + edg_local_var_demangling( local_symbols, &objfile->symbol_obstack ); /* Make a block for the local symbols within. */ finish_block (new->name, &local_symbols, new->old_blocks, new->start_addr, valu, objfile); local_symbols = new->locals; *** dwarf2read.c.orig Mon Jun 18 09:56:22 2001 --- dwarf2read.c Fri May 11 08:58:42 2001 *************** *** 1550,1559 **** --- 1550,1587 ---- child_die = sibling_die (child_die); } } } + /* KAI EDG-style compiler can have different local variable name + mangling for C++. Run through the demaingler to see if this is the case */ + static void /*mab*/ + edg_local_var_demangling( struct pending * local_symbols, struct obstack * ostack ) + { + struct pending *next; + struct symbol *sym; + int j; + char *pn; + for (next = local_symbols; next; next = next->next) + { + for (j = next->nsyms - 1; j >= 0; j--) + { + sym = next->symbol[j]; + pn = SYMBOL_NAME (sym); + if ( pn && pn[0]=='_' && pn[1]=='_' && pn[2]>='0' && pn[2]<='9' + && SYMBOL_CPLUS_DEMANGLED_NAME(sym)==NULL ) + { + if (SYMBOL_LANGUAGE (sym) == language_c || + SYMBOL_LANGUAGE (sym) == language_unknown) { + SYMBOL_LANGUAGE (sym) = language_auto; + } + SYMBOL_INIT_DEMANGLED_NAME(sym,ostack); + } + } + } + } + static void read_func_scope (die, objfile) struct die_info *die; struct objfile *objfile; { *************** *** 1615,1624 **** --- 1643,1654 ---- child_die = sibling_die (child_die); } } new = pop_context (); + if (EDG_DEMANGLING) + edg_local_var_demangling( local_symbols, &objfile->symbol_obstack ); /* Make a block for the local symbols within. */ finish_block (new->name, &local_symbols, new->old_blocks, lowpc, highpc, objfile); list_in_scope = &file_symbols; } *************** *** 1653,1662 **** --- 1683,1694 ---- } new = pop_context (); if (local_symbols != NULL) { + if (EDG_DEMANGLING) + edg_local_var_demangling( local_symbols, &objfile->symbol_obstack ); finish_block (0, &local_symbols, new->old_blocks, new->start_addr, highpc, objfile); } local_symbols = new->locals; } *************** *** 2117,2126 **** --- 2149,2193 ---- TYPE_NFN_FIELDS (type) = fip->nfnfields; TYPE_NFN_FIELDS_TOTAL (type) = total_length; } + /* reconstruct baseclass information out of DIE field info */ + /* EDG baseclasses are encoded as the first fields of the + struct, and they all have a __b_ prefix name */ + static void + dwarf2_edg_baseclass_fixup( struct field_info * pfi ) + { + int i; + int edg_n_baseclasses = 0; + int field_ct; + struct nextfield *pfield; + if ( pfi->nbaseclasses > 0 ) { + /* already have base classes for some reason, better not touch it */ + return; + } + pfield = pfi->fields; + field_ct = 0; + /* fields in this list are in reverse order */ + /* first skip non-baseclass members */ + while ( field_ct < pfi->nfields ) { + if ( strncmp( pfield->field.name, "__b_", 4 )==0 ) break; + field_ct++; + pfield = pfield->next; + } + /* count baseclass members, if any */ + while ( field_ct < pfi->nfields && strncmp( pfield->field.name, "__b_", 4 )==0 ) { + edg_n_baseclasses++; + field_ct++; + pfield = pfield->next; + } + if ( field_ct == pfi->nfields + && edg_n_baseclasses > 0 ) { + pfi->nbaseclasses = edg_n_baseclasses; + } + } + /* Called when we find the DIE that starts a structure or union scope (definition) to process all dies that define the members of the structure or union. NOTE: we need to call struct_type regardless of whether or not the *************** *** 2220,2229 **** --- 2287,2301 ---- { process_die (child_die, objfile); } child_die = sibling_die (child_die); } + + /* If the file was compiled by KAI C++ or some other + EDG front ends, the struct fields may need to be un-lowered. */ + if ( EDG_DEMANGLING ) + dwarf2_edg_baseclass_fixup( &fi ); /* Attach fields and member functions to the type. */ if (fi.nfields) dwarf2_attach_fields_to_type (&fi, type, objfile); if (fi.nfnfields)