Index: /branches/libc-0.6/src/emx/ChangeLog.LIBC
===================================================================
--- /branches/libc-0.6/src/emx/ChangeLog.LIBC	(revision 2649)
+++ /branches/libc-0.6/src/emx/ChangeLog.LIBC	(revision 2650)
@@ -2,4 +2,8 @@
 
 TODO: open replace on RAMFS fails with error 32!
+
+2006-03-17: knut st. osmundsen <bird-gccos2-spam@anduin.net>
+    - emxomf:
+        o #70: Demangle symbol names in debug info. (thanks to Yuri)
 
 2006-03-14: knut st. osmundsen <bird-gccos2-spam@anduin.net>
Index: /branches/libc-0.6/src/emx/src/emxomf/emxomf.smak
===================================================================
--- /branches/libc-0.6/src/emx/src/emxomf/emxomf.smak	(revision 2649)
+++ /branches/libc-0.6/src/emx/src/emxomf/emxomf.smak	(revision 2650)
@@ -9,4 +9,5 @@
 .TCF	:= $(CFLAGS.DEF.VERSION)
 .TDEP	:= @O@libomflib$A
+.TLDF   := -liberty
 include mkexe.smak
 
Index: /branches/libc-0.6/src/emx/src/emxomf/stabshll.c
===================================================================
--- /branches/libc-0.6/src/emx/src/emxomf/stabshll.c	(revision 2649)
+++ /branches/libc-0.6/src/emx/src/emxomf/stabshll.c	(revision 2650)
@@ -20,4 +20,6 @@
 Boston, MA 02111-1307, USA.  */
 //#define HLL_DEBUG 1
+
+#define DEMANGLE_PROC_NAMES 1
 
 /*******************************************************************************
@@ -31,4 +33,7 @@
 #include <alloca.h>
 #include <ctype.h>
+#ifdef DEMANGLE_PROC_NAMES
+# include <demangle.h>
+#endif
 #include "defs.h"
 #include "emxomf.h"
@@ -2225,5 +2230,5 @@
                   if (!parse_mangled_args ())
                     goto syntax;
-                  tf->mnglname = strpool_addn(str_pool, pszMangled, parse_ptr - pszMangled - 1); /* ASSUMES not extra spaces! */
+                  tf->mnglname = strpool_addn(str_pool, pszMangled, parse_ptr - pszMangled - 1); /* ASSUMES no extra spaces! */
                   tf->flags = parse_visibility () | MEMBER_FUNCTION;
                   switch (*parse_ptr)
@@ -3315,8 +3320,10 @@
   struct relocation_info r;
   const char *str, *p, *p2;
-  const char *name;
-  int n,                                /* size of name. */
-      ti,
-      ticlass;
+  const char *name, *mnglname;
+#ifdef DEMANGLE_PROC_NAMES
+  char *pszFree;
+#endif
+  size_t cchName, cchMnglName;
+  int ti, ticlass;
 
   str = str_ptr + symbol->n_un.n_strx;
@@ -3324,14 +3331,29 @@
   if (p == NULL)
     abort ();
-  n = p - str;
-
-  /** @todo name demangling */
-  name = strpool_addn (str_pool, str, n);
+  cchName = cchMnglName = p - str;
+  name = mnglname = strpool_addn (str_pool, str, cchMnglName);
   proc_start_addr = symbol->n_value;
+
+#ifdef DEMANGLE_PROC_NAMES
+  /* demangle the name */
+  pszFree = cplus_demangle (mnglname, DMGL_ANSI | DMGL_PARAMS);
+  if (!pszFree && (*mnglname == '_' || *mnglname == '*'))
+    pszFree = cplus_demangle (mnglname + 1, DMGL_ANSI | DMGL_PARAMS);
+  if (pszFree)
+    {
+      cchName = strlen (pszFree);
+      name = pszFree;
+    }
+  else if (*mnglname == '*')
+    {
+      cchName--;
+      name++;
+    }
+#endif
 
   /* now let's see if there is a memfunc for this name. */
   for (t1 = type_head; t1; t1 = t1->next)
     if (    t1->tag == ty_memfunc
-        &&  t1->d.memfunc.mnglname == name)
+        &&  t1->d.memfunc.mnglname == mnglname)
       break;
 
@@ -3358,6 +3380,6 @@
                        */
                       /** @todo: the string parsing still is a bit spooky. */
-                      for (p2 = p; (p2 = strstr (p2, name)) != NULL; p2 += n)
-                        if (p2[-1] == ':' && p2[n] == ';')
+                      for (p2 = p; (p2 = strstr (p2, mnglname)) != NULL; p2 += cchMnglName)
+                        if (p2[-1] == ':' && p2[cchMnglName] == ';')
                         {
                             int stab = atoi (&p[3]);
@@ -3373,5 +3395,5 @@
           if (ticlass < 0)
             {
-              warning (" Can't figure out which class method '%s' is a member of!", name);
+              warning (" Can't figure out which class method '%s' is a member of!", mnglname);
               ticlass = 0;
             }
@@ -3411,5 +3433,5 @@
       make_type (t2, &ti);
 
-      sst_start (cplusplus_flag || n > 255 ? SST_CPPproc : SST_proc);
+      sst_start (cplusplus_flag || cchName > 255 ? SST_CPPproc : SST_proc);
       r.r_address = sst.size;
       buffer_dword (&sst, symbol->n_value); /* Segment offset */
@@ -3421,5 +3443,5 @@
       buffer_word (&sst, 0);        /* Class type (for member functions) */
       buffer_byte (&sst, 8);        /* 32-bit near */
-      if (cplusplus_flag || n > 255)
+      if (cplusplus_flag || cchName > 255)
         buffer_enc (&sst, name);    /* Proc name */
       else
@@ -3434,4 +3456,9 @@
   buffer_mem (&sst_reloc, &r, sizeof (r));
   set_hll_type (symbol - sym_ptr, ti);
+
+#ifdef DEMANGLE_PROC_NAMES
+  /* free the demangled name. */
+  free (pszFree);
+#endif
 }
 
