Mirror of the gdb mailing list
 help / color / mirror / Atom feed
From: "Chu, Josh" <josh.chu@retek.com>
To: "'gdb@sources.redhat.com'" <gdb@sources.redhat.com>
Subject: 64bit gdb for KAI/KCC compiler
Date: Thu, 27 Jun 2002 15:37:00 -0000	[thread overview]
Message-ID: <E6C33530C94CD311ABB20008C791D6C313E103F1@mspmail1.retek.int> (raw)


[-- Attachment #1.1: Type: text/plain, Size: 1469 bytes --]

Ok, so here's the deal : KAI released a patch for gdb 5.0 that will allow
gdb to read the EDG-style mangled names.  I've attached the patch files that
were to be applied to 5.0 (gdb.patch-5.0 and libiberty.patch-5.0).  I tried
manually applying these modifications to the 5.2 source, and it builds.
However, there are some definite problems because gdb will now core dump
occasionally, not to mention the names are still mangled.
I've included the patch files to 5.0 and my modifications to the files in
5.2 :
 
gdb/libiberty:
    cplus-dem.c
 
gdb/gdb:
    dwarf2read.c
    hpread.c
    stabsread.c
    symfile.c
 
 
to patch a 5.0 gdb base :
----
cd gdb/gdb
patch < gdb.patch-5.0
----
and
---
cd- gdb/libiberty
patch < libiberty.patch-5.0
----
 
To patch a 5.2 gdb base with the same modifications :
----
cd gdb/gdb
patch < gdb.patch-5.2
----
and
---
cd- gdb/libiberty
patch < libiberty.patch-5.2
----
 
 
After this is done, you can try to build and run.  (export CC='gcc -m64' and
./configure first)
 
I suppose this is a fairly vague question : but does anyone have a clue why
the patches aren't working with 5.2?
This would be a huge help for anyone who has a KAI compiler on a 64-bit
system, as it would allow people to debug 64bit programs compiled with KCC.
Or if someone who's familiar with the above-mentioned files could comment on
the patched files and what could potentially be wrong with them, I would
very much appreciate it.
Thanks so much
--JC
    
 

[-- Attachment #1.2: Type: text/html, Size: 5649 bytes --]

[-- Attachment #2: libiberty.patch-5.0 --]
[-- Type: application/octet-stream, Size: 2199 bytes --]

*** cplus-dem.c.orig	Fri May 11 08:51:51 2001
--- cplus-dem.c	Tue Apr 24 09:09:53 2001
***************
*** 2220,2229 ****
--- 2220,2234 ----
  	      if (gnu_special (work, mangled, declp))
  		return success;
  	    }
  	}
      }
+   else if ( (EDG_DEMANGLING) && strncmp(*mangled, "__SO__", 6) == 0)
+     {
+       /* it's a ARM global destructor to be executed at program exit */
+       (*mangled) += 6;
+     }
    else if ((ARM_DEMANGLING || HP_DEMANGLING || EDG_DEMANGLING) && strncmp(*mangled, "__std__", 7) == 0)
      {
        /* it's a ARM global destructor to be executed at program exit */
        (*mangled) += 7;
        work->destructor = 2;
***************
*** 2276,2286 ****
  	       || (scan[2] == 't') || (scan[2] == 'K') || (scan[2] == 'H')))
      {
        /* The ARM says nothing about the mangling of local variables.
  	 But cfront mangles local variables by prepending __<nesting_level>
  	 to them. As an extension to ARM demangling we handle this case.  */
!       if ((LUCID_DEMANGLING || ARM_DEMANGLING || HP_DEMANGLING)
  	  && isdigit ((unsigned char)scan[2]))
  	{
  	  *mangled = scan + 2;
  	  consume_count (mangled);
  	  string_append (declp, *mangled);
--- 2281,2306 ----
  	       || (scan[2] == 't') || (scan[2] == 'K') || (scan[2] == 'H')))
      {
        /* The ARM says nothing about the mangling of local variables.
  	 But cfront mangles local variables by prepending __<nesting_level>
  	 to them. As an extension to ARM demangling we handle this case.  */
!       /* MAB 6/1/00  -- hard-coded KCC local variable demangling */
!       if (EDG_DEMANGLING && isdigit((unsigned char)scan[2])) {
!         const char *scout = *mangled;
! 	scout+=2; /* skip __ */
! 	consume_count(&scout);
! 	if ( *scout=='_' ) {
! 	  scout++;
! 	  consume_count(&scout);
! 	  if ( *scout=='_' && *(scout+1)!='\0' ) {
! 	    *mangled=scout+1;
! 	    string_append (declp, *mangled);
! 	    *mangled += strlen (*mangled);
! 	    success = 1;
! 	  }
! 	}
!       } else if ((LUCID_DEMANGLING || ARM_DEMANGLING || HP_DEMANGLING)
  	  && isdigit ((unsigned char)scan[2]))
  	{
  	  *mangled = scan + 2;
  	  consume_count (mangled);
  	  string_append (declp, *mangled);

[-- Attachment #3: libiberty.patch-5.2 --]
[-- Type: application/octet-stream, Size: 1778 bytes --]

*** cplus-dem.c	Thu Jun 27 17:01:05 2002
--- cplus-dem.c.new	Thu Jun 27 17:00:53 2002
***************
*** 2711,2716 ****
--- 2711,2721 ----
  	    }
  	}
      }
+   else if ( (EDG_DEMANGLING) && strncmp(*mangled, "__SO__", 6) == 0)
+     {
+       /* it's a ARM global destructor to be executed at program exit */
+       (*mangled) += 6;
+     }
    else if ((ARM_DEMANGLING || HP_DEMANGLING || EDG_DEMANGLING) && strncmp(*mangled, "__std__", 7) == 0)
      {
        /* it's a ARM global destructor to be executed at program exit */
***************
*** 2767,2773 ****
        /* The ARM says nothing about the mangling of local variables.
  	 But cfront mangles local variables by prepending __<nesting_level>
  	 to them. As an extension to ARM demangling we handle this case.  */
!       if ((LUCID_DEMANGLING || ARM_DEMANGLING || HP_DEMANGLING)
  	  && ISDIGIT ((unsigned char)scan[2]))
  	{
  	  *mangled = scan + 2;
--- 2772,2793 ----
        /* The ARM says nothing about the mangling of local variables.
  	 But cfront mangles local variables by prepending __<nesting_level>
  	 to them. As an extension to ARM demangling we handle this case.  */
!       /* MAB 6/1/00  -- hard-coded KCC local variable demangling */
!       if (EDG_DEMANGLING && isdigit((unsigned char)scan[2])) {
!         const char *scout = *mangled;
! 	scout+=2; /* skip __ */
! 	consume_count(&scout);
! 	if ( *scout=='_' ) {
! 	  scout++;
! 	  consume_count(&scout);
! 	  if ( *scout=='_' && *(scout+1)!='\0' ) {
! 	    *mangled=scout+1;
! 	    string_append (declp, *mangled);
! 	    *mangled += strlen (*mangled);
! 	    success = 1;
! 	  }
! 	}
!       } else if ((LUCID_DEMANGLING || ARM_DEMANGLING || HP_DEMANGLING)
  	  && ISDIGIT ((unsigned char)scan[2]))
  	{
  	  *mangled = scan + 2;

[-- Attachment #4: gdb.patch-5.0 --]
[-- Type: application/octet-stream, Size: 17968 bytes --]

*** 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;
  }
  \f
  /* 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;
  }
  \f
  /* 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; i<type->nfields; 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; i<ptype->nfields; 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 (&param_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)

[-- Attachment #5: gdb.patch-5.2 --]
[-- Type: application/octet-stream, Size: 15450 bytes --]

*** dwarf2read.c	Thu Jun 27 15:41:58 2002
--- dwarf2read.c.new	Thu Jun 27 10:52:12 2002
***************
*** 1653,1658 ****
--- 1653,1686 ----
      }
  }
  
+ /* 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 (struct die_info *die, struct objfile *objfile,
  		 const struct comp_unit_head *cu_header)
***************
*** 1717,1722 ****
--- 1745,1752 ----
      }
  
    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);
***************
*** 1754,1759 ****
--- 1784,1791 ----
  
    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);
      }
***************
*** 2213,2218 ****
--- 2245,2285 ----
    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.
***************
*** 2316,2321 ****
--- 2383,2393 ----
  	  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);
*** hpread.c	Thu Jun 27 17:04:37 2002
--- hpread.c.new	Thu Jun 27 17:04:49 2002
***************
*** 3543,3550 ****
--- 3543,3587 ----
    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; i<ptype->nfields; 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().
***************
*** 4299,4304 ****
--- 4336,4345 ----
        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 
     */
***************
*** 4847,4858 ****
  	  }
  
  	/* 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" */
--- 4888,4915 ----
  	  }
  
  	/* 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" */
***************
*** 5113,5118 ****
--- 5170,5203 ----
    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:
***************
*** 5325,5330 ****
--- 5410,5419 ----
        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) &&
***************
*** 5624,5629 ****
--- 5713,5720 ----
  	  /* Insert func params into local list */
  	  merge_symbol_lists (&param_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);
***************
*** 5652,5657 ****
--- 5743,5750 ----
  	      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,
*** stabsread.c	Thu Jun 27 17:04:37 2002
--- stabsread.c.new	Thu Jun 27 17:04:53 2002
***************
*** 1260,1265 ****
--- 1260,1280 ----
      }
  }
  
+ /* 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 (CORE_ADDR valu, char *string, int desc, int type,
***************
*** 1674,1680 ****
        SYMBOL_CLASS (sym) = LOC_LOCAL;
        SYMBOL_VALUE (sym) = valu;
        SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
!       add_symbol_to_list (sym, &local_symbols);
        break;
  
      case 'p':
--- 1689,1696 ----
        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':
***************
*** 2025,2033 ****
  	  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;
--- 2041,2058 ----
  	  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;
***************
*** 2053,2059 ****
        if (os9k_stabs)
  	add_symbol_to_list (sym, &global_symbols);
        else
! 	add_symbol_to_list (sym, &local_symbols);
        break;
  
      case 'v':
--- 2078,2085 ----
        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':
***************
*** 3590,3596 ****
--- 3616,3662 ----
      }
  }
  
+ /* 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; i<type->nfields; 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 ;
***************
*** 4208,4214 ****
      }
  
    /* Fix up any cv-qualified versions of this type.  */
!   finish_cv_type (type);
    do_cleanups (back_to);
    return (type);
  }
--- 4274,4285 ----
      }
  
    /* Fix up any cv-qualified versions of this type.  */
!   /*finish_cv_type (type);*/
! 
!   /*  FIXIT : jchu - may need to comment-out above line since it 
!    *  didn't exist in the original 5.0 src
!    */
!   edg_baseclass_fixup(type);
    do_cleanups (back_to);
    return (type);
  }
*** symfile.c	Thu Jun 27 17:04:37 2002
--- symfile.c.new	Thu Jun 27 17:04:57 2002
***************
*** 1926,1934 ****
  
    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;
  }
--- 1926,1938 ----
  
    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;
  }

             reply	other threads:[~2002-06-27 22:37 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2002-06-27 15:37 Chu, Josh [this message]
2002-06-28  6:31 ` Daniel Jacobowitz
2002-06-28  6:47 Chu, Josh

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=E6C33530C94CD311ABB20008C791D6C313E103F1@mspmail1.retek.int \
    --to=josh.chu@retek.com \
    --cc=gdb@sources.redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox