www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1994/09/13/03:59:22

Date: Mon, 12 Sep 1994 23:40:49 -0700 (PDT)
From: Gordon Hogenson <ghogenso AT u DOT washington DOT edu>
Sender: Gordon Hogenson <ghogenso AT u DOT washington DOT edu>
Reply-To: Gordon Hogenson <ghogenso AT u DOT washington DOT edu>
Subject: Demangling symify's output
To: djgpp AT sun DOT soe DOT clarkson DOT edu

Hi, I finally got sick of trying to figure out the mangled
names in my 'symify' output, so I combined DJ's symify.c with
routines from libiberty/c++filt to make a demangling version
of symify.

The following is a README style file for the new version.
Included at the end of this message are the diffs, although
in addition to the diffs you must build libiberty.a (see below).

If there is sufficient interest, this may become part of the
standard distribution. 
------------------------------------------------------------

What is symify?  Symify is a program which, when run after
go32 dumps a stack trace to your screen (or to a file
specified with the "CORE corefile" option of the go32
environment variable), replaces the stack trace execution
instruction pointers (EIPs) with function names, files,
and line numbers.  The old version of symify did not
demangle the C++ function names, so you would often be left
trying to demangle them yourself.  This gets tiresome after a 
while.

What's new in this version?  The new version uses the routine,
"cplus_demangle" from the GNU "liberty" library.  Symify will
attempt to demangle the function names.  If it succeeds, the
demangled names will be displayed instead of the mangled ones.
If it fails, what you see will be unchanged.  Thus, you can use
symify on with your C programs and C functions without fear that
they will themselves be mangled by the demangler.

How to use it?
The old usage was 

"symify [-o <output file>] [-i <core file>] <program name>".

In the old usage (which carries over to the new version), you
specify -o to write the information to a specified file rather
than just writing to the screen memory (note: it is NOT stdout).
The -i option applies if you use the CORE option of the go32
environment variable.  See the readme.doc for more information.

The new usage is

"symify [-o <output file>] [-i <core file>] [-d [n]] <program name>".

The "-d" option can be used to specify the desired "demangling level".
There are four demangling levels:

-d0 : do not demangle
-d1 : function names only
-d2 : function names AND parameters
-d3 : function names, parameters, and storage class ('const', 'volatile'...)

The default condition depends on how symify was configured when it
was built.  For the executable included in this package, I have set
the default demangling level (what happens if you don't specify
-d at all) to 3, since that's what g++ error messages report. 
Thus, specifying -d alone is the same as not specifying -d at all. 

Installation:

For the lazy, I have included an executable, which
is available at ftp.u.washington.edu:public/ghogenso/djgpp/symify.zip.

-----------------------------------------------------------------
Building it:

You need libiberty.a, ansidecls.h and demangle.h, all
from the DJGPP 1.12 binutils distribution: bnu24sr*.zip. 
You also need the go32 sources from djsrc112.zip. 

Apply the diffs in go32/ed.  Edit the source symify.c
to specify the default demangling behavior that you want.
Run 'make symify.exe' there.
  
The following assumes you have demangle.h in your INCLUDE
PATH, and libiberty.a in the LIBRARY_PATH.

------------cut here-------------------------------------

*** cxxify.c	Sun Sep 11 23:39:46 1994
--- symify.c	Mon Sep 12 20:23:40 1994
***************
*** 2,8 ****
--- 2,24 ----
  #include "ed.h"
  #include "syms.h"
+ #include <demangle.h>
  
  #define SC(r,c) (*(char *)(sc + (r)*ScreenCols() + (c)))
  #define SW(r,c) (*(sc + (r)*ScreenCols() + (c)))
+ #define NO_DEMANGLING (-1)
+ 
+ /* what demangling level to select if -d alone is specified */
+ #ifndef DEFAULT_DEMANGLING_LEVEL
+ #define DEFAULT_DEMANGLING_LEVEL 3 
+ #endif
+ 
+ /* what demangling options to select if invoked without -d:
+    set to "NO_DEMANGLING" if you want to disable automatic demangling */
+ #ifndef DEFAULT_DEMANGLING_BEHAVIOR
+ #define DEFAULT_DEMANGLING_BEHAVIOR (DMGL_PARAMS | DMGL_ANSI) 
+ #endif
+ 
+ void attempt_to_demangle(char**, int demangle_options); 
+ void usage();
  
  TSS a_tss;
***************
*** 19,27 ****
    FILE *ofile=0;
    FILE *ifile=0;
  
    if (argc < 2)
    {
!     fprintf(stderr, "Usage: symify [-o <outfile>] [-i <corefile>] 
<program>\n");
!     fprintf(stderr, "This program replaces the stack dumps from go32 
with debug info\n");
      return 1;
    }
--- 35,43 ----
    FILE *ofile=0;
    FILE *ifile=0;
+   int demangle_opt = DEFAULT_DEMANGLING_BEHAVIOR;
  
    if (argc < 2)
    {
!     usage();
      return 1;
    }
***************
*** 44,47 ****
--- 60,101 ----
        argv += 2;
      }
+     if (strncmp(argv[1], "-d", 2) == 0)
+     {
+       /* "-d" takes an optional demangling level as parameter. */
+ 
+       unsigned int demangling_level = 0;
+       if ( isdigit(argv[1][2]) )
+          demangling_level = atoi(&argv[1][2]);         
+       else
+         if (argc > 2)
+         {
+            /* is the next arg a digit? */
+            if (isdigit(argv[2][0]))
+            {
+              demangling_level = atoi(argv[2]);
+              argc -= 1;
+              argv += 1;
+            }
+            else
+            {
+              demangling_level = DEFAULT_DEMANGLING_LEVEL;
+            }
+         }
+     argc -= 1;
+     argv += 1;
+     if (demangling_level <= 0)
+       demangle_opt = NO_DEMANGLING; 
+     if (demangling_level == 1)
+       demangle_opt = DMGL_NO_OPTS;
+     if (demangling_level == 2)
+       demangle_opt = DMGL_PARAMS;
+     if (demangling_level > 2)
+       demangle_opt = DMGL_PARAMS | DMGL_ANSI;
+     } 
+   }
+   if (argc < 2)
+   {
+     usage();
+     return 1;
    }
    syms_init(argv[1]);
***************
*** 63,66 ****
--- 117,122 ----
          if (func)
          {
+         if (demangle_opt != NO_DEMANGLING)
+           attempt_to_demangle(&func, demangle_opt);
            fprintf(ofile, " %s", func);
            if (d)
***************
*** 98,102 ****
        if (func)
        {
! 	strcpy(buf, func);
  	if (d)
  	  sprintf(buf+strlen(buf), "%+d", d);
--- 154,160 ----
        if (func)
        {
!         if (demangle_opt != NO_DEMANGLING)
!           attempt_to_demangle(&func, demangle_opt);
! 	strcpy(buf, func); 
  	if (d)
  	  sprintf(buf+strlen(buf), "%+d", d);
***************
*** 130,132 ****
--- 188,216 ----
    else
      ScreenUpdate(sc);
+ }
+ 
+ void usage()
+ {
+     fprintf(stderr, "Usage: symify [-o <outfile>] [-i <corefile>] [-d 
[<n>] ] <program>\n");
+     fprintf(stderr, "This program replaces the stack dumps from go32 
with debug info\n");
+     fprintf(stderr, "Use -d to demangle C++ function names.  An 
optional integer\n");
+     fprintf(stderr, "specifies the demangling level:\n");
+     fprintf(stderr, "Use -d0 for no demangling; -d1 for function names 
only;\n");
+     fprintf(stderr, "-d2 to include parameters; -d3 to include const 
and volatile.\n");
+     fprintf(stderr, "The default demangling level (-d alone) is %d.\n",
+                     DEFAULT_DEMANGLING_LEVEL);
+ }
+ 
+ void attempt_to_demangle(char** func, int demangle_options)
+ {
+    /* try to demangle a function name.  If successful,
+       func is replaced by the function name.
+       If unsuccessful, func is unchanged. */
+ 
+    char* demangled;
+    demangle_options |= DMGL_GNU;
+      /* add 1 to func to skip the initial underscore: */
+    demangled = cplus_demangle(*func+1, demangle_options);
+    if (demangled) 
+       *func = demangled;
  }

*** makefile	Mon Sep 12 20:39:52 1994
--- makefile.new	Mon Sep 12 20:39:20 1994
***************
*** 26,30 ****
  
  symify.exe : symify.o $(CO)
! 	gcc -o symify symify.o $(CO) -lpc
  	strip symify
  	coff2exe symify
--- 26,30 ----
  
  symify.exe : symify.o $(CO)
! 	gcc -o symify symify.o $(CO) -lpc -liberty
  	strip symify
  	coff2exe symify

----------------------------------------------------------------------------
Gordon Hogenson
ghogenso AT u DOT washington DOT edu


- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019