* D Symbol Demangling
@ 2005-04-04 2:37 John Demme
2005-04-04 18:21 ` Michael Snyder
0 siblings, 1 reply; 20+ messages in thread
From: John Demme @ 2005-04-04 2:37 UTC (permalink / raw)
To: gdb-patches
[-- Attachment #1: Type: text/plain, Size: 1130 bytes --]
Greetings GDB hackers!
I'm new to GDB programming, so please excuse any stupid questions.
There is a language called D which, like C++, uses symbol mangling since
it supports things such as method overloading. I've been attempting to
add support to GDB to demangle the names.
Thus far, I've had partial success. In fairly simple D programs, my
demangling works, but in more complex programs with mixed C and D code
(D is link-compatible with C) it only calls the D demangler for some of
the functions.
Unfortunately, I'm not very familiar with GDB's architecture, so I've
been basically wandering around in the dark on this one. Any help you
could provide would be appreciated.
Attached is my patch against GDB 6.3. It is not the cleanest code right
now, and certainly not anywhere near ready for a release... I'm just
trying to get it to work, and feeling out the GDB code. Once it's
working, I'll refactor it into something decent.
Thanks
John Demme
BTW- more information about D can be found at
http://www.digitalmars.com/d and there is a forum for D GDB patches at
http://www.dsource.org/forums/viewforum.php?f=58
[-- Attachment #2: d.patch --]
[-- Type: text/x-patch, Size: 12642 bytes --]
Index: gdb/symtab.c
===================================================================
--- gdb/symtab.c (revision 7)
+++ gdb/symtab.c (working copy)
@@ -42,6 +42,7 @@
#include "filenames.h" /* for FILENAME_CMP */
#include "objc-lang.h"
#include "ada-lang.h"
+#include "c-lang.h"
#include "hashtab.h"
@@ -395,7 +396,7 @@
return (mangled_name);
}
-\f
+
/* Initialize the language dependent portion of a symbol
depending upon the language for the symbol. */
void
@@ -404,6 +405,7 @@
{
gsymbol->language = language;
if (gsymbol->language == language_cplus
+ || gsymbol->language == language_d
|| gsymbol->language == language_java
|| gsymbol->language == language_objc)
{
@@ -450,6 +452,15 @@
if (gsymbol->language == language_unknown)
gsymbol->language = language_auto;
+ if (gsymbol->language == language_d
+ || gsymbol->language == language_auto) {
+ demangled = d_demangle(mangled, 0);
+ if (demangled != NULL) {
+ gsymbol->language = language_d;
+ return demangled;
+ }
+ }
+
if (gsymbol->language == language_objc
|| gsymbol->language == language_auto)
{
@@ -609,6 +620,7 @@
demangled = symbol_find_demangled_name (gsymbol, mangled);
if (gsymbol->language == language_cplus
+ || gsymbol->language == language_d
|| gsymbol->language == language_java
|| gsymbol->language == language_objc)
{
@@ -638,6 +650,7 @@
switch (gsymbol->language)
{
case language_cplus:
+ case language_d:
case language_java:
case language_objc:
if (gsymbol->language_specific.cplus_specific.demangled_name != NULL)
@@ -663,6 +676,7 @@
switch (gsymbol->language)
{
case language_cplus:
+ case language_d:
case language_java:
case language_objc:
if (gsymbol->language_specific.cplus_specific.demangled_name != NULL)
@@ -1020,7 +1034,7 @@
modified_name = name;
- /* If we are using C++ or Java, demangle the name before doing a lookup, so
+ /* If we are using C++, D, or Java, demangle the name before doing a lookup, so
we can always binary search. */
if (current_language->la_language == language_cplus)
{
@@ -1032,6 +1046,16 @@
needtofreename = 1;
}
}
+ else if (current_language->la_language == language_d)
+ {
+ demangled_name = d_demangle (name, 0);
+ if (demangled_name)
+ {
+ mangled_name = name;
+ modified_name = demangled_name;
+ needtofreename = 1;
+ }
+ }
else if (current_language->la_language == language_java)
{
demangled_name = cplus_demangle (name,
Index: gdb/c-lang.c
===================================================================
--- gdb/c-lang.c (revision 7)
+++ gdb/c-lang.c (working copy)
@@ -696,9 +696,214 @@
a language currently not supported by GDB. */
const struct language_defn minimal_language_defn =
+ {
+ "minimal", /* Language name */
+ language_minimal,
+ NULL,
+ range_check_off,
+ type_check_off,
+ case_sensitive_on,
+ array_row_major,
+ &exp_descriptor_standard,
+ c_preprocess_and_parse,
+ c_error,
+ null_post_parser,
+ c_printchar, /* Print a character constant */
+ c_printstr, /* Function to print string constant */
+ c_emit_char, /* Print a single char */
+ c_create_fundamental_type, /* Create fundamental type in this language */
+ c_print_type, /* Print a type using appropriate syntax */
+ c_val_print, /* Print a value using appropriate syntax */
+ c_value_print, /* Print a top-level value */
+ NULL, /* Language specific skip_trampoline */
+ NULL, /* value_of_this */
+ basic_lookup_symbol_nonlocal, /* lookup_symbol_nonlocal */
+ basic_lookup_transparent_type,/* lookup_transparent_type */
+ NULL, /* Language specific symbol demangler */
+ NULL, /* Language specific class_name_from_physname */
+ c_op_print_tab, /* expression operators for printing */
+ 1, /* c-style arrays */
+ 0, /* String lower bound */
+ NULL,
+ default_word_break_characters,
+ c_language_arch_info,
+ LANG_MAGIC
+};
+
+
+/*****************************
+ D Language stuff
+******************************/
+#include <string.h>
+#include <ctype.h>
+
+static int extractidentifiers(char** output, char** mangled) {
+ int i = -1;
+ while (isdigit(**mangled)) {
+ i = strtol(*mangled, mangled, 10);
+ if (strlen(*mangled) < i)
+ return -1;
+ memcpy(*output, *mangled, i);
+ *mangled += i;
+ *output += i + 1;
+ (*output)[-1] = '.';
+ }
+ if (**mangled == '\0' || i == -1)
+ return -1;
+ (*output)--;
+ return 1;
+}
+
+static void append(char** dest, char* src) {
+ int i = strlen(src);
+ for(;i>0; i--) {
+ *(*dest)++ = *src++;
+ }
+}
+
+static int extracttypeinfo(char** dest, char** id) {
+ if (**id == '\0')
+ return -1;
+ // Extract the type info:
+ switch (*(*id)++) {
+ // array, static array, dynamic array:
+ case 'A': case 'G': case 'H':
+ if (extracttypeinfo(dest, id) == -1)
+ return -1;
+ append(dest, "[]");
+ return 1;
+ // pointer:
+ case 'P':
+ if (extracttypeinfo(dest, id) == -1)
+ return -1;
+ append(dest, "*");
+ return 1;
+ // reference:
+ case 'R':
+ if (extracttypeinfo(dest, id) == -1)
+ return -1;
+ append(dest, "&");
+ return 1;
+ // return value:
+ case 'Z':
+ return extracttypeinfo(dest, id);
+ // out:
+ case 'J':
+ append(dest, "out ");
+ return extracttypeinfo(dest, id);
+ // inout:
+ case 'K':
+ append(dest, "inout ");
+ return extracttypeinfo(dest, id);
+
+ // enum:
+ case 'E': case 'T': case 'D': case 'C': case 'S': case 'I':
+ return extractidentifiers(dest, id);
+
+ // basic types:
+ case 'n': append(dest, "none"); return 1; // ever used?
+ case 'v': append(dest, "void"); return 1;
+ case 'g': append(dest, "byte"); return 1;
+ case 'h': append(dest, "ubyte"); return 1;
+ case 's': append(dest, "short"); return 1;
+ case 't': append(dest, "ushort"); return 1;
+ case 'i': append(dest, "int"); return 1;
+ case 'k': append(dest, "uint"); return 1;
+ case 'l': append(dest, "long"); return 1;
+ case 'm': append(dest, "ulong"); return 1;
+ case 'f': append(dest, "float"); return 1;
+ case 'd': append(dest, "double"); return 1;
+ case 'e': append(dest, "real"); return 1;
+
+ // imaginary and complex:
+ case 'o': append(dest, "ifloat"); return 1;
+ case 'p': append(dest, "idouble"); return 1;
+ case 'j': append(dest, "ireal"); return 1;
+ case 'q': append(dest, "cfloat"); return 1;
+ case 'r': append(dest, "cdouble"); return 1;
+ case 'c': append(dest, "creal"); return 1;
+
+ // other types:
+ case 'b': append(dest, "bit"); return 1;
+ case 'a': append(dest, "char"); return 1;
+ case 'u': append(dest, "wchar"); return 1;
+ case 'w': append(dest, "dchar"); return 1;
+
+ // typeinfo, error, instance:
+ case '@': return extractidentifiers(dest, id); // BUG: is this right?
+
+ default: append(dest, "unknown"); return 1;
+ }
+}
+
+char* d_demangle(const char* mangled, int options) {
+ char *symbol = mangled;
+ char *output = malloc(strlen(mangled)+20), *orig = output;
+ unsigned char isFunc = 0;
+ if (mangled == NULL) {
+ free(output);
+ return NULL;
+ } else if (strcmp(mangled, "_Dmain") == 0) {
+ free(output);
+ return strdup("D main");
+ }
+ if (symbol == strstr(symbol, "_D")) {
+ symbol += 2;
+ isFunc = 1;
+ } else if (symbol == strstr(symbol, "__Class_")) {
+ symbol += 8;
+ } else if (symbol == strstr(symbol, "__init_")) {
+ symbol += 7;
+ } else if (symbol == strstr(symbol, "__vtbl_")) {
+ symbol += 7;
+ } else if (symbol == strstr(symbol, "__modctor_")) {
+ symbol += 10;
+ } else if (symbol == strstr(symbol, "__moddtor_")) {
+ symbol += 10;
+ } else if (symbol == strstr(symbol, "__ModuleInfo_")) {
+ symbol += 13;
+ } else {
+ free(orig);
+ return NULL;
+ }
+
+ if (extractidentifiers(&output, &symbol) < 0) {
+ free(orig);
+ return NULL;
+ }
+ append(&output, "(");
+ if (isFunc == 1 && *symbol == 'F') {
+ symbol++;
+ while (*symbol != '\0' && *symbol != 'Z') {
+ if (isFunc == 1) {
+ isFunc++;
+ } else {
+ append(&output, ", ");
+ }
+ if (extracttypeinfo(&output, &symbol) < 0) {
+ free(orig);
+ return NULL;
+ }
+ }
+ }
+ append(&output, ")");
+
+ //Doesn't display the return type, but wouldn't be too hard to do.
+
+ *output = '\0';
+ output = strdup(orig);
+ free(orig);
+ return output;
+}
+
+char* d_sym_demangle(const struct general_symbol_info *gsymbol) {
+ return d_demangle(gsymbol->name, 0);
+}
+
+const struct language_defn d_language_defn =
{
- "minimal", /* Language name */
- language_minimal,
+ "d", /* Language name */
+ language_d,
NULL,
range_check_off,
type_check_off,
@@ -719,7 +924,7 @@
NULL, /* value_of_this */
basic_lookup_symbol_nonlocal, /* lookup_symbol_nonlocal */
basic_lookup_transparent_type,/* lookup_transparent_type */
- NULL, /* Language specific symbol demangler */
+ d_demangle, /* Language specific symbol demangler */
NULL, /* Language specific class_name_from_physname */
c_op_print_tab, /* expression operators for printing */
1, /* c-style arrays */
@@ -733,7 +938,8 @@
void
_initialize_c_language (void)
{
- add_language (&c_language_defn);
+ add_language (&c_language_defn);
+ add_language (&d_language_defn);
add_language (&cplus_language_defn);
add_language (&asm_language_defn);
add_language (&minimal_language_defn);
Index: gdb/language.c
===================================================================
--- gdb/language.c (revision 7)
+++ gdb/language.c (working copy)
@@ -553,6 +553,7 @@
{
case language_c:
case language_cplus:
+ case language_d:
case language_objc:
if (TYPE_CODE (t1) == TYPE_CODE_FLT)
return TYPE_CODE (t2) == TYPE_CODE_FLT && l2 > l1 ?
@@ -664,6 +665,7 @@
{
case language_c:
case language_cplus:
+ case language_d:
case language_objc:
return (TYPE_CODE (type) != TYPE_CODE_INT) &&
(TYPE_CODE (type) != TYPE_CODE_ENUM) ? 0 : 1;
@@ -704,6 +706,7 @@
case language_c:
case language_cplus:
+ case language_d:
case language_objc:
return (TYPE_CODE (type) == TYPE_CODE_INT) &&
TYPE_LENGTH (type) == sizeof (char)
@@ -726,6 +729,7 @@
case language_c:
case language_cplus:
+ case language_d:
case language_objc:
/* C does not have distinct string type. */
return (0);
@@ -745,6 +749,7 @@
{
case language_c:
case language_cplus:
+ case language_d:
case language_objc:
/* Might be more cleanly handled by having a
TYPE_CODE_INT_NOT_BOOL for (the deleted) CHILL and such
@@ -818,6 +823,7 @@
}
return builtin_type_f_logical_s2;
case language_cplus:
+ case language_d:
case language_pascal:
if (current_language->la_language==language_cplus)
{sym = lookup_symbol ("bool", NULL, VAR_DOMAIN, NULL, NULL);}
Index: gdb/c-lang.h
===================================================================
--- gdb/c-lang.h (revision 7)
+++ gdb/c-lang.h (working copy)
@@ -28,6 +28,7 @@
#include "value.h"
#include "macroexp.h"
+#include "symtab.h"
extern int c_parse (void); /* Defined in c-exp.y */
@@ -90,4 +91,13 @@
extern int cp_is_vtbl_member (struct type *);
+/*****************************
+ D Language stuff
+******************************/
+
+char* d_demangle(const char* mangled, int options);
+
+char* d_sym_demangle(const struct general_symbol_info *gsymbol);
+
+
#endif /* !defined (C_LANG_H) */
Index: gdb/defs.h
===================================================================
--- gdb/defs.h (revision 7)
+++ gdb/defs.h (working copy)
@@ -190,6 +190,7 @@
language_auto, /* Placeholder for automatic setting */
language_c, /* C */
language_cplus, /* C++ */
+ language_d, /* D */
language_objc, /* Objective-C */
language_java, /* Java */
language_fortran, /* Fortran */
Index: gdb/symfile.c
===================================================================
--- gdb/symfile.c (revision 7)
+++ gdb/symfile.c (working copy)
@@ -2169,6 +2169,7 @@
filename_language_table =
xmalloc (fl_table_size * sizeof (*filename_language_table));
add_filename_language (".c", language_c);
+ add_filename_language (".d", language_d);
add_filename_language (".C", language_cplus);
add_filename_language (".cc", language_cplus);
add_filename_language (".cp", language_cplus);
^ permalink raw reply [flat|nested] 20+ messages in thread* Re: D Symbol Demangling 2005-04-04 2:37 D Symbol Demangling John Demme @ 2005-04-04 18:21 ` Michael Snyder 2005-04-04 20:44 ` John Demme 0 siblings, 1 reply; 20+ messages in thread From: Michael Snyder @ 2005-04-04 18:21 UTC (permalink / raw) To: John Demme; +Cc: gdb-patches John Demme wrote: > Thus far, I've had partial success. In fairly simple D programs, my > demangling works, but in more complex programs with mixed C and D code > (D is link-compatible with C) it only calls the D demangler for some of > the functions. What's the granularity of mixed code? Is it mixed within a source file, or just between source files? If a source file contains only one language, I think gdb ought to be able to discern it reliably. When you say "for some of the functions", what differentiates the ones where it successfully discerns the D language from those where it doesn't? ^ permalink raw reply [flat|nested] 20+ messages in thread
* Re: D Symbol Demangling 2005-04-04 18:21 ` Michael Snyder @ 2005-04-04 20:44 ` John Demme 2005-04-04 20:47 ` Daniel Jacobowitz 2005-04-04 21:49 ` Michael Snyder 0 siblings, 2 replies; 20+ messages in thread From: John Demme @ 2005-04-04 20:44 UTC (permalink / raw) To: Michael Snyder; +Cc: gdb-patches By link compatible, I mean that I'll compile a D file with a D compiler to a .o file, then I can link it with another .o file compiled with, say, gcc. So a source file can be either C or D, but not both (barring some sort of bizarre scripting situations.) An important note here, however, is that because D can call C functions, some of the symbols in a D object file won't be mangled. I've been having trouble figuring out what differentiates the functions. On the surface, the more complex ones don't work, but in my test, there's only simple one. Do I appear to be interfacing with GDB correctly? If so, I'll triple check my code. Thanks John Demme On Mon, 2005-04-04 at 11:21 -0700, Michael Snyder wrote: > John Demme wrote: > > Thus far, I've had partial success. In fairly simple D programs, my > > demangling works, but in more complex programs with mixed C and D code > > (D is link-compatible with C) it only calls the D demangler for some of > > the functions. > > What's the granularity of mixed code? Is it mixed within a source > file, or just between source files? If a source file contains only > one language, I think gdb ought to be able to discern it reliably. > > When you say "for some of the functions", what differentiates > the ones where it successfully discerns the D language from those > where it doesn't? > ^ permalink raw reply [flat|nested] 20+ messages in thread
* Re: D Symbol Demangling 2005-04-04 20:44 ` John Demme @ 2005-04-04 20:47 ` Daniel Jacobowitz 2005-04-04 21:49 ` Michael Snyder 1 sibling, 0 replies; 20+ messages in thread From: Daniel Jacobowitz @ 2005-04-04 20:47 UTC (permalink / raw) To: John Demme; +Cc: Michael Snyder, gdb-patches On Mon, Apr 04, 2005 at 04:45:05PM -0400, John Demme wrote: > By link compatible, I mean that I'll compile a D file with a D compiler > to a .o file, then I can link it with another .o file compiled with, > say, gcc. So a source file can be either C or D, but not both (barring > some sort of bizarre scripting situations.) An important note here, > however, is that because D can call C functions, some of the symbols in > a D object file won't be mangled. > > I've been having trouble figuring out what differentiates the functions. > On the surface, the more complex ones don't work, but in my test, > there's only simple one. > > Do I appear to be interfacing with GDB correctly? If so, I'll triple > check my code. Nothing is obviously wrong. I'd need to look at a sample file to say anything else. -- Daniel Jacobowitz CodeSourcery, LLC ^ permalink raw reply [flat|nested] 20+ messages in thread
* Re: D Symbol Demangling 2005-04-04 20:44 ` John Demme 2005-04-04 20:47 ` Daniel Jacobowitz @ 2005-04-04 21:49 ` Michael Snyder 2005-04-04 22:39 ` John Demme [not found] ` <1112654359.14153.50.camel@localhost.localdomain> 1 sibling, 2 replies; 20+ messages in thread From: Michael Snyder @ 2005-04-04 21:49 UTC (permalink / raw) To: John Demme; +Cc: gdb-patches John Demme wrote: > By link compatible, I mean that I'll compile a D file with a D compiler > to a .o file, then I can link it with another .o file compiled with, > say, gcc. So a source file can be either C or D, but not both (barring > some sort of bizarre scripting situations.) An important note here, > however, is that because D can call C functions, some of the symbols in > a D object file won't be mangled. > > I've been having trouble figuring out what differentiates the functions. > On the surface, the more complex ones don't work, but in my test, > there's only simple one. > > Do I appear to be interfacing with GDB correctly? If so, I'll triple > check my code. Looks ok at first glance. Do I understand that the D compiler is not gcc or gcc-derived? That raises the question of whether the debug info in the D-compiled .o file is "correct" as far as gdb is concerned. Something unexpected about that info might cause gdb to "lose its place", eg. in determining which functions belong to the D-compiled module. ^ permalink raw reply [flat|nested] 20+ messages in thread
* Re: D Symbol Demangling 2005-04-04 21:49 ` Michael Snyder @ 2005-04-04 22:39 ` John Demme [not found] ` <1112654359.14153.50.camel@localhost.localdomain> 1 sibling, 0 replies; 20+ messages in thread From: John Demme @ 2005-04-04 22:39 UTC (permalink / raw) Cc: gdb-patches On Mon, 2005-04-04 at 14:48 -0700, Michael Snyder wrote: > John Demme wrote: > > By link compatible, I mean that I'll compile a D file with a D compiler > > to a .o file, then I can link it with another .o file compiled with, > > say, gcc. So a source file can be either C or D, but not both (barring > > some sort of bizarre scripting situations.) An important note here, > > however, is that because D can call C functions, some of the symbols in > > a D object file won't be mangled. > > > > I've been having trouble figuring out what differentiates the functions. > > On the surface, the more complex ones don't work, but in my test, > > there's only simple one. > > > > Do I appear to be interfacing with GDB correctly? If so, I'll triple > > check my code. > > Looks ok at first glance. Do I understand that the D compiler > is not gcc or gcc-derived? That raises the question of whether > the debug info in the D-compiled .o file is "correct" as far as > gdb is concerned. Something unexpected about that info might > cause gdb to "lose its place", eg. in determining which functions > belong to the D-compiled module. > > That's correct. It uses Walter Bright's C backend. In fact, the DWARF2 information that it generates it total crap, as in just plain wrong in some/most cases. There is a gcc-derived version of it. I'll give that a try. Thanks John ^ permalink raw reply [flat|nested] 20+ messages in thread
[parent not found: <1112654359.14153.50.camel@localhost.localdomain>]
[parent not found: <4251CF00.5080002@redhat.com>]
* Re: D Symbol Demangling [not found] ` <4251CF00.5080002@redhat.com> @ 2005-04-08 16:47 ` John Demme 2005-04-08 16:52 ` Daniel Jacobowitz 0 siblings, 1 reply; 20+ messages in thread From: John Demme @ 2005-04-08 16:47 UTC (permalink / raw) To: gdb-patches I finally had time to play firefighter, and I found the fire as well. If you compile a D application without DWARF2 information, my gdb patches work just fine... how do ya like that? Now I REALLY have an excuse to yell at the compiler programmer. I don't really understand why bad DWARF2 information would screw up GDB like that, considering that I call my function at the point where GDB tries to demangle a symbol, but I don't really understand how GDB works. Thanks for your help... Expect to hear more from me in the future concerning this. BTW... assuming I can get a decent patch together to bring D support to GDB, would it stand a good chance of being put in the main GDB tree? Thanks again, John Demme On Mon, 2005-04-04 at 16:34 -0700, Michael Snyder wrote: > John Demme wrote: > > In fact, the DWARF2 > > information that it generates it total crap, as in just plain wrong in > > some/most cases. > > Well, there's your smoke... > > ^ permalink raw reply [flat|nested] 20+ messages in thread
* Re: D Symbol Demangling 2005-04-08 16:47 ` John Demme @ 2005-04-08 16:52 ` Daniel Jacobowitz 2005-04-08 20:50 ` John Demme 0 siblings, 1 reply; 20+ messages in thread From: Daniel Jacobowitz @ 2005-04-08 16:52 UTC (permalink / raw) To: John Demme; +Cc: gdb-patches On Fri, Apr 08, 2005 at 12:47:51PM -0400, John Demme wrote: > I finally had time to play firefighter, and I found the fire as well. > If you compile a D application without DWARF2 information, my gdb > patches work just fine... how do ya like that? > > Now I REALLY have an excuse to yell at the compiler programmer. > > I don't really understand why bad DWARF2 information would screw up GDB > like that, considering that I call my function at the point where GDB > tries to demangle a symbol, but I don't really understand how GDB works. > > Thanks for your help... Expect to hear more from me in the future > concerning this. Presumably because you don't have a DWARF language code for D. What's it labelling the language as in the DW_TAG_compile_unit DIE? You can define one temporarily for now, but you'll need to request from the DWARF working group eventually. > BTW... assuming I can get a decent patch together to bring D support to > GDB, would it stand a good chance of being put in the main GDB tree? Perhaps. Are there multiple implementations of D? How inconsistent are they in ways that would affect GDB? If you want to do this, you will eventually need a GDB copyright assignment with the FSF. -- Daniel Jacobowitz CodeSourcery, LLC ^ permalink raw reply [flat|nested] 20+ messages in thread
* Re: D Symbol Demangling 2005-04-08 16:52 ` Daniel Jacobowitz @ 2005-04-08 20:50 ` John Demme 2005-04-08 21:11 ` Daniel Jacobowitz 0 siblings, 1 reply; 20+ messages in thread From: John Demme @ 2005-04-08 20:50 UTC (permalink / raw) To: Daniel Jacobowitz; +Cc: gdb-patches On Fri, 2005-04-08 at 12:52 -0400, Daniel Jacobowitz wrote: > On Fri, Apr 08, 2005 at 12:47:51PM -0400, John Demme wrote: > > I finally had time to play firefighter, and I found the fire as well. > > If you compile a D application without DWARF2 information, my gdb > > patches work just fine... how do ya like that? > > > > Now I REALLY have an excuse to yell at the compiler programmer. > > > > I don't really understand why bad DWARF2 information would screw up GDB > > like that, considering that I call my function at the point where GDB > > tries to demangle a symbol, but I don't really understand how GDB works. > > > > Thanks for your help... Expect to hear more from me in the future > > concerning this. > > Presumably because you don't have a DWARF language code for D. What's > it labelling the language as in the DW_TAG_compile_unit DIE? > According to the compiler programmer, "The DW_TAG_compile_unit is not the right thing. What it does do is write into the prolog DW_LANG_C89, masquerading as C. When GDB gets a DW_LANG_D, I'll switch to that." I assume this is correct... so does anyone know what is involved in getting DW_LANG_D? Where might one find contact information for the DWARF working group? > You can define one temporarily for now, but you'll need to request from > the DWARF working group eventually. > > > BTW... assuming I can get a decent patch together to bring D support to > > GDB, would it stand a good chance of being put in the main GDB tree? > > Perhaps. Are there multiple implementations of D? How inconsistent > are they in ways that would affect GDB? There are currently two. DMD, the reference implementation, has an open source front-end, and a closed-source backend. GDC, the other compiler, uses the front-end from DMD, and GCC's backend. I'm not sure what this means for operation with GDB. It would be nice to have possible inconsistencies in the D language spec, so as to avoid them. Since I'm currently working on it, I'm going to suggest the DMD's method of symbol mangling become part of the spec. Keeping in mind that D is very similar to C, is there anything else I should suggest? > > If you want to do this, you will eventually need a GDB copyright > assignment with the FSF. > I assume this is to assign copyrights to the FSF... I have no problem with that. Where do I sign up? Thanks John Demme ^ permalink raw reply [flat|nested] 20+ messages in thread
* Re: D Symbol Demangling 2005-04-08 20:50 ` John Demme @ 2005-04-08 21:11 ` Daniel Jacobowitz 0 siblings, 0 replies; 20+ messages in thread From: Daniel Jacobowitz @ 2005-04-08 21:11 UTC (permalink / raw) To: John Demme; +Cc: gdb-patches On Fri, Apr 08, 2005 at 04:51:03PM -0400, John Demme wrote: > On Fri, 2005-04-08 at 12:52 -0400, Daniel Jacobowitz wrote: > > On Fri, Apr 08, 2005 at 12:47:51PM -0400, John Demme wrote: > > > I finally had time to play firefighter, and I found the fire as well. > > > If you compile a D application without DWARF2 information, my gdb > > > patches work just fine... how do ya like that? > > > > > > Now I REALLY have an excuse to yell at the compiler programmer. > > > > > > I don't really understand why bad DWARF2 information would screw up GDB > > > like that, considering that I call my function at the point where GDB > > > tries to demangle a symbol, but I don't really understand how GDB works. > > > > > > Thanks for your help... Expect to hear more from me in the future > > > concerning this. > > > > Presumably because you don't have a DWARF language code for D. What's > > it labelling the language as in the DW_TAG_compile_unit DIE? > > > > According to the compiler programmer, > "The DW_TAG_compile_unit is not the right thing. What it does do is > write > into the prolog DW_LANG_C89, masquerading as C. When GDB gets a > DW_LANG_D, > I'll switch to that." > > I assume this is correct... so does anyone know what is involved in > getting DW_LANG_D? Where might one find contact information for the > DWARF working group? See: http://dwarf.freestandards.org/ > There are currently two. DMD, the reference implementation, has an open > source front-end, and a closed-source backend. GDC, the other compiler, > uses the front-end from DMD, and GCC's backend. I'm not sure what this > means for operation with GDB. It would be nice to have possible > inconsistencies in the D language spec, so as to avoid them. Since I'm > currently working on it, I'm going to suggest the DMD's method of symbol > mangling become part of the spec. Keeping in mind that D is very > similar to C, is there anything else I should suggest? I have no idea. > > If you want to do this, you will eventually need a GDB copyright > > assignment with the FSF. > > > I assume this is to assign copyrights to the FSF... I have no problem > with that. Where do I sign up? I'll send it to you. -- Daniel Jacobowitz CodeSourcery, LLC ^ permalink raw reply [flat|nested] 20+ messages in thread
* D Symbol Demangling
@ 2006-04-19 11:18 Thomas Kuehne
2006-04-20 13:20 ` Daniel Jacobowitz
0 siblings, 1 reply; 20+ messages in thread
From: Thomas Kuehne @ 2006-04-19 11:18 UTC (permalink / raw)
To: gdb-patches
[-- Attachment #1: Type: text/plain, Size: 664 bytes --]
Attached is a patch against GDB-6.4 that enables demangling of symbols
generated by DMD[1] and GDC[2].
The infrastructure part (c-lang.c, defs.h, d-lang.h, dwarf2read.c,
language.c, Makefile.in, symfile, syntab.c, dwarf2.h) is based on John
Demme's work[3][4].
The pluggable demangler (gdb/demangle_d/*) was written completely form
scratch and isn't based on John's work and supports templates and - to a
certain extend - nested functions and types.
Thomas
[1] http://digitalmars.com/d/dcompiler.html
[2] http://home.earthlink.net/~dvdfrdmn/d/
[3] http://www.dsource.org/forums/viewforum.php?f=58
[4] http://sourceware.org/ml/gdb-patches/2005-04/msg00039.html
[-- Attachment #2: gdb-6.4-demangle_d.diff --]
[-- Type: text/plain, Size: 40717 bytes --]
diff -urN gdb-6.4/gdb/c-lang.c gdb-6.4-demangle_d/gdb/c-lang.c
--- gdb-6.4/gdb/c-lang.c 2005-10-03 23:21:20.000000000 +0200
+++ gdb-6.4-demangle_d/gdb/c-lang.c 2006-04-17 21:29:25.000000000 +0200
@@ -27,6 +27,7 @@
#include "parser-defs.h"
#include "language.h"
#include "c-lang.h"
+#include "d-lang.h"
#include "valprint.h"
#include "macroscope.h"
#include "gdb_assert.h"
@@ -735,10 +736,48 @@
LANG_MAGIC
};
+const struct language_defn d_language_defn =
+{
+ "d", /* Language name */
+ language_d,
+ NULL,
+ range_check_off,
+ type_check_off,
+ case_sensitive_on,
+ array_row_major,
+ &exp_descriptor_standard,
+ c_preprocess_and_parse,
+ c_error,
+ null_post_parser,
+ c_printchar, /* Print a character constant */
+ c_printstr, /* Function to print string constant */
+ c_emit_char, /* Print a single char */
+ c_create_fundamental_type, /* Create fundamental type in this language */
+ c_print_type, /* Print a type using appropriate syntax */
+ c_val_print, /* Print a value using appropriate syntax */
+ c_value_print, /* Print a top-level value */
+ NULL, /* Language specific skip_trampoline */
+ NULL, /* value_of_this */
+ basic_lookup_symbol_nonlocal, /* lookup_symbol_nonlocal */
+ basic_lookup_transparent_type,/* lookup_transparent_type */
+ d_demangle, /* Language specific symbol demangler */
+ NULL, /* Language specific class_name_from_physname */
+ c_op_print_tab, /* expression operators for printing */
+ 1, /* c-style arrays */
+ 0, /* String lower bound */
+ NULL,
+ default_word_break_characters,
+ c_language_arch_info,
+ default_print_array_index,
+ LANG_MAGIC
+};
+
+
void
_initialize_c_language (void)
{
add_language (&c_language_defn);
+ add_language (&d_language_defn);
add_language (&cplus_language_defn);
add_language (&asm_language_defn);
add_language (&minimal_language_defn);
diff -urN gdb-6.4/gdb/defs.h gdb-6.4-demangle_d/gdb/defs.h
--- gdb-6.4/gdb/defs.h 2005-08-05 23:08:54.000000000 +0200
+++ gdb-6.4-demangle_d/gdb/defs.h 2006-04-17 21:27:21.000000000 +0200
@@ -190,6 +190,7 @@
language_auto, /* Placeholder for automatic setting */
language_c, /* C */
language_cplus, /* C++ */
+ language_d, /* D */
language_objc, /* Objective-C */
language_java, /* Java */
language_fortran, /* Fortran */
diff -urN gdb-6.4/gdb/demangle_d/demangle_d.c gdb-6.4-demangle_d/gdb/demangle_d/demangle_d.c
--- gdb-6.4/gdb/demangle_d/demangle_d.c 1970-01-01 01:00:00.000000000 +0100
+++ gdb-6.4-demangle_d/gdb/demangle_d/demangle_d.c 2006-04-19 14:08:46.000000000 +0200
@@ -0,0 +1,844 @@
+/*
+ * demangle_d.c - pluggable D de-mangler
+ *
+ * Copyright 2006 Thomas Kuehne <thomas@kuehne.cn>
+ *
+ *
+ * Eiffel Forum License, version 1
+ *
+ * Permission is hereby granted to use, copy, modify and/or distribute this
+ * package, provided that:
+ *
+ * - copyright notices are retained unchanged
+ *
+ * - any distribution of this package, whether modified or not, includes
+ * this file
+ *
+ * Permission is hereby also granted to distribute binary programs which
+ * depend on this package, provided that:
+ *
+ * - if the binary program depends on a modified version of this package,
+ * you must publicly release the modified version of this package
+ *
+ * THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT WARRANTY. ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
+ * EVENT SHALL THE AUTHORS BE LIABLE TO ANY PARTY FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS PACKAGE.
+ *
+ * 2006-04-19
+ * added GDB support
+ *
+ * 2006-04-17
+ * added Valgrind support
+ *
+ * 2006-04-16
+ * inital public release
+ *
+ */
+
+#include "demangle_d_conf.h"
+#include "demangle_d_internal.h"
+
+/* copy len first bytes into a newly allocated buffer */
+char*
+DD_(strndup)(const char* source, size_t len)
+{
+ char* dest;
+ dest = xmalloc(len+1);
+ xmemcpy(dest, source, len);
+ dest[len] = '\x00';
+ return dest;
+}
+
+#if (DEMANGLE_D_REQUIRE_strtol_10)
+/* convert a string to a long integer using base 10 */
+long int
+xstrtol_10(char* src, char** endptr)
+{
+ long int value;
+ int sign;
+
+ if(src[0] == '-'){
+ sign = -1;
+ src++;
+ }else if(src[0] == '+'){
+ sign = 1;
+ src++;
+ }else{
+ sign = 1;
+ }
+
+ value = 0;
+
+ while(xisdigit(src[0])){
+ value = (value * 10) + (src[0] - '0');
+ src++;
+ }
+
+ if(endptr){
+ *endptr = src;
+ }
+
+ return sign * value;
+}
+#endif
+
+#if (DEMANGLE_D_REQUIRE_malloc)
+void*
+DD_(malloc)(size_t len)
+{
+ void* ptr;
+ ptr = malloc(len);
+ if(!ptr){
+ perror("DD_(malloc)");
+ xabort();
+ }
+ return ptr;
+}
+#endif
+
+#if (DEMANGLE_D_REQUIRE_realloc)
+void*
+DD_(realloc)(void* ptr, size_t len)
+{
+ ptr = realloc(ptr, len);
+ if(!ptr){
+ perror("DD_(realloc)");
+ xabort();
+ }
+ return ptr;
+}
+#endif
+
+DD_(string_t)*
+DD_(new_string)(void)
+{
+ DD_(string_t)* str = xmalloc(sizeof(DD_(string_t)));
+ str->used = 0;
+ str->len = 128;
+ str->str = xmalloc(str->len);
+ str->str[0] = '\x00';
+ return str;
+}
+
+void
+DD_(append_n)(DD_(string_t)* dest, const char* source, size_t len)
+{
+ size_t new_len = dest->used + len + 1;
+ if(new_len > dest->len){
+ dest->len = (size_t)(new_len * 1.5);
+ dest->str = xrealloc(dest->str, dest->len);
+ }
+ xmemcpy(dest->str + dest->used, source, len);
+ dest->used += len;
+ dest->str[dest->used] = '\x00';
+}
+
+void
+DD_(append_c)(DD_(string_t)* dest, char source)
+{
+ size_t new_len = dest->used + 2;
+ if(new_len > dest->len){
+ dest->len = (size_t)(new_len * 1.5);
+ dest->str = xrealloc(dest->str, dest->len);
+ }
+ dest->str[dest->used++] = source;
+ dest->str[dest->used] = '\x00';
+}
+
+void
+DD_(append)(DD_(string_t)* dest, const char* source)
+{
+ DD_(append_n)(dest, source, xstrlen(source));
+}
+
+void
+DD_(prepend_n)(DD_(string_t)* dest, const char* source, size_t len)
+{
+ size_t new_len = dest->used + len + 1;
+ if(new_len > dest->len){
+ dest->len = (size_t)(new_len * 1.5);
+ dest->str = xrealloc(dest->str, dest->len);
+ }
+ if(dest->used){
+ xmemmove(dest->str + len, dest->str, dest->used);
+ }
+ xmemcpy(dest->str, source, len);
+ dest->used += len;
+ dest->str[dest->used] = '\x00';
+}
+
+void
+DD_(prepend)(DD_(string_t)* dest, const char* source)
+{
+ DD_(prepend_n)(dest, source, xstrlen(source));
+}
+
+void
+DD_(nestpend_n)(DD_(string_t)* dest, const char* source, size_t len,
+ int is_nested)
+{
+ if(is_nested){
+ DD_(append_n)(dest, source, len);
+ }else{
+ DD_(prepend)(dest, " ");
+ DD_(prepend_n)(dest, source, len);
+ }
+}
+
+void
+DD_(nestpend)(DD_(string_t)* dest, const char* source, int is_nested)
+{
+ DD_(nestpend_n)(dest, source, xstrlen(source), is_nested);
+}
+
+/* parse until the end of the next type */
+char*
+DD_(nextType)(DD_(string_t)* dest, char* source, int is_nested)
+{
+ if(!source || !source[0]){
+ return NULL;
+ }
+
+ if((source[0] == '_') && (source[1] == 'D')
+ && xisdigit(source[2])
+ && (source[2] != '0'))
+ {
+ DD_(string_t)* tmp;
+ tmp = DD_(new_string)();
+ source = DD_(nextType)(tmp, source + 2, 0);
+ if(dest->used && (dest->str[dest->used] != '.')){
+ DD_(append_c)(dest, '.');
+ }
+ DD_(append_n)(dest, tmp->str, tmp->used);
+ xfree(tmp->str);
+ xfree(tmp);
+ return source;
+ }
+
+ switch(source[0]){
+ case 'v':
+ DD_(nestpend)(dest, "void", is_nested);
+ source += 1;
+ break;
+ case 'b': /* deprecated since DMD-0.148 (2006-02-25) */
+ DD_(nestpend)(dest, "bit", is_nested);
+ source += 1;
+ break;
+ case 'x':
+ DD_(nestpend)(dest, "bool", is_nested);
+ source += 1;
+ break;
+ case 'g':
+ DD_(nestpend)(dest, "byte", is_nested);
+ source += 1;
+ break;
+ case 'h':
+ DD_(nestpend)(dest, "ubyte", is_nested);
+ source += 1;
+ break;
+ case 's':
+ DD_(nestpend)(dest, "short", is_nested);
+ source += 1;
+ break;
+ case 't':
+ DD_(nestpend)(dest, "ushort", is_nested);
+ source += 1;
+ break;
+ case 'i':
+ DD_(nestpend)(dest, "int", is_nested);
+ source += 1;
+ break;
+ case 'k':
+ DD_(nestpend)(dest, "uint", is_nested);
+ source += 1;
+ break;
+ case 'l':
+ DD_(nestpend)(dest, "long", is_nested);
+ source += 1;
+ break;
+ case 'm':
+ DD_(nestpend)(dest, "ulong", is_nested);
+ source += 1;
+ break;
+ case 'f':
+ DD_(nestpend)(dest, "float", is_nested);
+ source += 1;
+ break;
+ case 'd':
+ DD_(nestpend)(dest, "double", is_nested);
+ source += 1;
+ break;
+ case 'e':
+ DD_(nestpend)(dest, "real", is_nested);
+ source += 1;
+ break;
+ case 'o':
+ DD_(nestpend)(dest, "ifloat", is_nested);
+ source += 1;
+ break;
+ case 'p':
+ DD_(nestpend)(dest, "idouble", is_nested);
+ source += 1;
+ break;
+ case 'j':
+ DD_(nestpend)(dest, "ireal", is_nested);
+ source += 1;
+ break;
+ case 'q':
+ DD_(nestpend)(dest, "cfloat", is_nested);
+ source += 1;
+ break;
+ case 'r':
+ DD_(nestpend)(dest, "cdouble", is_nested);
+ source += 1;
+ break;
+ case 'c':
+ DD_(nestpend)(dest, "creal", is_nested);
+ source += 1;
+ break;
+ case 'a':
+ DD_(nestpend)(dest, "char", is_nested);
+ source += 1;
+ break;
+ case 'u':
+ DD_(nestpend)(dest, "wchar", is_nested);
+ source += 1;
+ break;
+ case 'w':
+ DD_(nestpend)(dest, "dchar", is_nested);
+ source += 1;
+ break;
+
+ case 'A': /* dynamic array */
+ if(!is_nested){
+ DD_(prepend)(dest, "[] ");
+ }
+ source = DD_(nextType)(dest, source+1, is_nested);
+ if(is_nested){
+ DD_(append)(dest, "[]");
+ }
+ break;
+
+ case 'G': { /* static array */
+ char* start = ++source;
+ char* end = start;
+ while(xisdigit(*end)){
+ end++;
+ }
+ if(!is_nested){
+ DD_(prepend)(dest, "] ");
+ DD_(prepend_n)(dest, start, end-start);
+ DD_(prepend)(dest, "[");
+ }
+ source = DD_(nextType)(dest, end, is_nested);
+ if(is_nested){
+ DD_(append)(dest, "[");
+ DD_(append_n)(dest, start, end-start);
+ DD_(append)(dest, "]");
+ }
+ break;
+ }
+
+ case 'H': { /* associative array */
+ DD_(string_t)* aa;
+ aa = DD_(new_string)();
+ source = DD_(nextType)(aa, source+1, 1);
+ DD_(prepend)(aa, "[");
+ DD_(append)(aa, "]");
+ source = DD_(nextType)(aa, source, 0);
+
+ DD_(nestpend)(dest, aa->str, is_nested);
+ xfree(aa->str);
+ xfree(aa);
+ break;
+ }
+
+ case 'D': { /* delegate */
+ DD_(string_t)* sig;
+ sig = DD_(new_string)();
+ source = DD_(parseFunction)(sig, source+1, NULL, 0);
+ DD_(nestpend_n)(dest, sig->str, sig->used, is_nested);
+ xfree(sig->str);
+ xfree(sig);
+ break;
+ }
+
+ case 'P': /* pointer */
+ if((source[1] == 'F') || (source[1]=='U')
+ || (source[1]=='W') || (source[1]=='V')
+ || (source[1]=='R'))
+ {
+ /* function */
+ DD_(string_t)* sig;
+ sig = DD_(new_string)();
+ source = DD_(parseFunction)(sig, source+1,
+ "", 0);
+ DD_(nestpend_n)(dest, sig->str, sig->used,
+ is_nested);
+ xfree(sig->str);
+ xfree(sig);
+ }else{
+ /* 'normal' type */
+ if(!is_nested){
+ DD_(prepend)(dest, "* ");
+ }
+ source = DD_(nextType)(dest, source+1,
+ is_nested);
+ if(is_nested){
+ DD_(append)(dest, " *");
+ }
+ }
+ break;
+
+ case 'J': /* out */
+ DD_(append)(dest, "out ");
+ source = DD_(nextType)(dest, source+1, 1);
+ break;
+
+ case 'K': /* inout */
+ DD_(append)(dest, "inout ");
+ source = DD_(nextType)(dest, source+1, 1);
+ break;
+
+ case 'C': /* class */
+ case 'S': /* struct */
+ case 'E': /* enum */
+ case 'T': /* typedef */
+ {
+#if (DEMANGLE_D_VERBOSE)
+ char tmp = source[0];
+#endif /* DEMANGLE_D_VERBOSE */
+ if(!is_nested){
+ DD_(string_t)* sig;
+ sig = DD_(new_string)();
+ source = DD_(nextType)(sig, source+1, 0);
+ DD_(append)(sig, " ");
+#if (DEMANGLE_D_VERBOSE)
+ switch(tmp){
+ case 'C':
+ DD_(prepend)(sig, "class ");
+ break;
+ case 'S':
+ DD_(prepend)(sig, "struct ");
+ break;
+ case 'E':
+ DD_(prepend)(sig, "enum ");
+ break;
+ case 'T':
+ DD_(prepend)(sig, "typedef ");
+ break;
+ }
+#endif /* DEMANGLE_D_VERBOSE */
+ DD_(prepend_n)(dest, sig->str, sig->used);
+ xfree(sig->str);
+ xfree(sig);
+ }else{
+#if (DEMANGLE_D_VERBOSE)
+ switch(tmp){
+ case 'C':
+ DD_(append)(dest, "class ");
+ break;
+ case 'S':
+ DD_(append)(dest, "struct ");
+ break;
+ case 'E':
+ DD_(append)(dest, "enum ");
+ break;
+ case 'T':
+ DD_(append)(dest, "typedef ");
+ break;
+ }
+#endif /* DEMANGLE_D_VERBOSE */
+ source = DD_(nextType)(dest, source+1, 1);
+ }
+ break;
+ }
+
+ case '1': /* qualified name */
+ case '2':
+ case '3':
+ case '4':
+ case '5':
+ case '6':
+ case '7':
+ case '8':
+ case '9':
+ {
+ long int len;
+ len = xstrtol_10(source, &source);
+ if(len >= 5 && (source[0] == '_') && (source[1] == '_')
+ && (source[2] == 'T')
+ && xisdigit(source[3])
+ && (source[3] != '0'))
+ {
+ /* template */
+ char* template = DD_(strndup)(source + 3, len-3);
+ DD_(interpreteTemplate)(dest, template);
+ xfree(template);
+ }else{
+ DD_(append_n)(dest, source, len);
+ }
+ source += len;
+ while(source && xisdigit(source[0])
+ && (source[0] != '0'))
+ {
+ len = xstrtol_10(source, &source);
+ DD_(append_c)(dest, '.');
+ if(len >= 5 && (source[0] == '_')
+ && (source[1] == '_')
+ && (source[2] == 'T')
+ && xisdigit(source[3])
+ && (source[3] != '0'))
+ {
+ /* template */
+ char* template = DD_(strndup)(source + 3, len-3);
+ DD_(interpreteTemplate)(dest, template);
+ xfree(template);
+ }else if((len == 5) && (xstrncmp(source, "_ctor", len) == 0)){
+ DD_(append)(dest, "this");
+ }else if((len == 5) && (xstrncmp(source, "_dtor", len) == 0)){
+ DD_(append)(dest, "~this");
+ }else if((len == 11) && (xstrncmp(source, "_staticCtorFZv", len + 3) == 0)){
+ DD_(prepend)(dest, "static void ");
+ DD_(append)(dest, "this()");
+ source = source + 11 + 3;
+ break;
+ }else if((len == 11) && (xstrncmp(source, "_staticDtorFZv", len + 3) == 0)){
+ DD_(prepend)(dest, "static void ");
+ DD_(append)(dest, "~this()");
+ source = source + 11 + 3;
+ break;
+ }else{
+ DD_(append_n)(dest, source, len);
+ }
+ source += len;
+ }
+ if(!is_nested){
+ source = DD_(nextType)(dest, source, 0);
+ }
+ break;
+ }
+
+ case 'F': /* D function */
+ case 'U': /* C function */
+ case 'W': /* Windows function */
+ case 'V': /* Pascal function */
+ case 'R': /* C++ function */
+ if(!is_nested){
+ DD_(string_t)* id;
+ id = DD_(new_string)();
+ DD_(append_n)(id, dest->str, dest->used);
+ dest->used = 0;
+ dest->str[0] = '\x00';
+ source = DD_(parseFunction)(dest, source, id->str, 0);
+ xfree(id->str);
+ xfree(id);
+ }else{
+ source = DD_(parseFunction)(dest, source, "", 1);
+ }
+ break;
+
+ default:
+ DD_(append)(dest, " @bug@[2]{");
+ DD_(append)(dest, source);
+ DD_(append)(dest, "}");
+ source = NULL;
+ break;
+ }
+
+ return source;
+}
+
+/* parse a "real" template parameter */
+char*
+DD_(parseReal)(DD_(string_t)* dest, char* source)
+{
+ /* @BUG@ architecture dependent */
+ long double f;
+ size_t i;
+ int tmp;
+ unsigned char* c = (unsigned char*) &f;
+ char* buffer;
+
+ for(i = 0; i < 10; i++){
+ if(!xisxdigit(source[i * 2]) || !xisxdigit(source[i * 2 + 1])){
+format_error:
+ DD_(append)(dest, "0x");
+ DD_(append_n)(dest, source, 20);
+ return source + 20;
+ }
+ c[i] = (xasci2hex(source[i * 2]) << 4);
+ c[i] |= xasci2hex(source[i * 2 + 1]);
+ }
+
+ buffer = xmalloc(64);
+ tmp = xsnprintf(buffer, 64, "%Lf", f);
+ if(tmp < 1){
+ xfree(buffer);
+ goto format_error;
+ }
+ DD_(append_n)(dest, buffer, tmp);
+ xfree(buffer);
+ return source + 20;
+}
+
+/* parse a function (including arguments and return type) */
+char*
+DD_(parseFunction)(DD_(string_t)* dest, char* source, char* name,
+ int is_nested)
+{
+ DD_(string_t)* fn_return;
+ DD_(string_t)* fn_param;
+
+ fn_return = DD_(new_string)();
+ fn_param = DD_(new_string)();
+
+ source++;
+
+ /* params */
+ if(source[0] != 'Z'){
+ if(source[0] == 'Y'){
+ DD_(append)(fn_param, "...");
+ goto var_arg_param;
+ }
+ source = DD_(nextType)(fn_param, source, 1);
+ while(source && source[0] && source[0]!='Z'){
+ if(source[0] == 'Y'){
+ DD_(append)(fn_param, ", ...");
+ goto var_arg_param;
+ }else if(source[0] == 'X'){
+ DD_(append)(fn_param, " ...");
+ goto var_arg_param;
+ }
+ DD_(append)(fn_param, ", ");
+ source = DD_(nextType)(fn_param, source, 1);
+ }
+ }
+
+ /* return type */
+ if(source && source[0] == 'Z'){
+var_arg_param:
+ source = DD_(nextType)(fn_return, source + 1, 1);
+ }
+
+ /* output */
+ if(name && name[0]){
+ if(! is_nested){
+ DD_(prepend)(dest, " ");
+ DD_(prepend_n)(dest, fn_return->str, fn_return->used);
+ DD_(append)(dest, name);
+ }else{
+ DD_(append_n)(dest, fn_return->str, fn_return->used);
+ DD_(append)(dest, " ");
+ DD_(append)(dest, name);
+ }
+ }else if(name){
+ DD_(append_n)(dest, fn_return->str, fn_return->used);
+ DD_(append)(dest, " function");
+ }else{
+ DD_(append_n)(dest, fn_return->str, fn_return->used);
+ DD_(append)(dest, " delegate");
+ }
+
+ if(fn_param->used){
+ DD_(append)(dest, "(");
+ DD_(append_n)(dest, fn_param->str, fn_param->used);
+ DD_(append)(dest, ")");
+ }else{
+ DD_(append)(dest, "()");
+ }
+
+ xfree(fn_return->str);
+ xfree(fn_return);
+ xfree(fn_param->str);
+ xfree(fn_param);
+
+ return source;
+}
+
+/* interprete a NULL terminated template symbol */
+void
+DD_(interpreteTemplate)(DD_(string_t)* dest, char* raw)
+{
+ char* tmp;
+ int first_arg = 1;
+ long int dataLen;
+
+ /* id */
+ while(xisdigit(raw[0]) && (raw[0] != '0')){
+ long int len;
+ len = xstrtol_10(raw, &raw);
+ DD_(append_n)(dest, raw, len);
+ raw += len;
+ }
+ DD_(append)(dest, "!(");
+
+ /* arguments */
+ while(raw && raw[0]){
+ if(raw[0] == 'T'){
+ /* type parameter */
+ raw++;
+ if(!first_arg){
+ DD_(append)(dest, ", ");
+ }else{
+ first_arg = 0;
+ }
+ raw = DD_(nextType)(dest, raw, 1);
+ }else if(raw[0] == 'V'){
+ /* value parameter */
+ if(!first_arg){
+ DD_(append)(dest, ", ");
+ }else{
+ first_arg = 0;
+ }
+ raw = DD_(nextType)(dest, raw + 1, 1);
+ DD_(append)(dest, " ");
+ if(xisdigit(raw[0])){
+ /* integer */
+integer_arg:
+ tmp = raw;
+ while(xisdigit(raw[0])){
+ raw++;
+ }
+ DD_(append_n)(dest, tmp, raw-tmp);
+ }else if(raw[0] == 'N'){
+ /* negative integer */
+ raw++;
+ DD_(append)(dest, "-");
+ goto integer_arg;
+ }else if(raw[0] == 'e'){
+ /* float */
+ raw = DD_(parseReal)(dest, raw+1);
+ }else if(raw[0] == 'c'){
+ /* complex float */
+ raw = DD_(parseReal)(dest, raw+1);
+ DD_(append)(dest, " + ");
+ raw = DD_(parseReal)(dest, raw);
+ DD_(append)(dest, "i");
+ }else if(raw[0] == 'n'){
+ DD_(append)(dest, "null");
+ raw++;
+ }else if((raw[0] == 'a') || (raw[0] == 'w') || (raw[0] == 'd')){
+ /* character literal */
+ raw++;
+ if(!xisdigit(raw[0])){
+ goto bug;
+ }
+ dataLen = xstrtol_10(raw, &raw);
+ if(raw[0] != '_'){
+ goto bug;
+ }
+ raw++;
+ DD_(append)(dest, "\"");
+ while(dataLen--){
+ if(xisxdigit(raw[0]) && xisxdigit(raw[1])){
+ DD_(append_c)(dest, (xasci2hex(raw[0]) << 4)
+ + xasci2hex(raw[1]));
+ }else{
+ DD_(append_c)(dest, '?');
+ }
+ raw += 2;
+ }
+ DD_(append)(dest, "\"");
+ }else{
+ goto bug;
+ }
+ }else if(raw[0] == 'Z'){
+ /* end of parameter list */
+ break;
+ }else{
+bug:
+ DD_(append)(dest, " @bug@[1]{");
+ DD_(append)(dest, raw);
+ DD_(append)(dest, "}");
+ break;
+ }
+ }
+ DD_(append)(dest, ")");
+}
+
+/* demangle a D symbol
+ *
+ * input:
+ * a NULL terminated mangled symbol
+ *
+ * output:
+ * UTF-8 encoded demangled symbol
+ * or NULL if unable to demangle
+ *
+ * memory:
+ * the caller is responsible to
+ * free input and output
+ */
+static char*
+DD_(demangle_d)(char* source)
+{
+ DD_(string_t)* dest;
+ DD_(string_t)* nested;
+ char* back;
+
+ if((source[0] != '_') || (source[1] != 'D') || (!xisdigit(source[2]))
+ || (source[2] == '0'))
+ {
+ /* %% @BUG@ might be mangled with 'D' but hasn't 'D' linkage
+ * samples:
+ * _aaApply10treewalkerFPS3aaA3aaAZi
+ * _aaKeys9_aaKeys_xFPS3aaA3aaAZv
+ */
+ return NULL;
+ }else{
+ source += 2;
+ }
+
+ dest = DD_(new_string)();
+
+ source = DD_(nextType)(dest, source, 0);
+
+ while(source && source[0]){
+ /* nested symbols */
+ nested = DD_(new_string)();
+ DD_(append)(dest, ".");
+ source = DD_(nextType)(nested, source, 0);
+ DD_(append_n)(dest, nested->str, nested->used);
+ xfree(nested->str);
+ xfree(nested);
+ }
+
+ back = DD_(strndup)(dest->str, dest->used+1);
+ xfree(dest->str);
+ xfree(dest);
+
+ return back;
+}
+
+#if (DEMANGLE_D_STANDALONE)
+int
+main(int argc, char** argv)
+{
+ int i;
+ if(argc < 2){
+ xfprintf(stderr,
+ "pluggable D d-demangler by Thomas Kuehne <thomas@kuehne.cn> "
+ "($Date: 2006-04-19T11:09:00.287803Z $)\n");
+ if(argc > 0){
+ xfprintf(stderr, "%s <mangledSymbol_1> [<mangledSymbol_2> ...]\n", argv[0]);
+ }else{
+ xfprintf(stderr, "dmangle_d <mangledSymbol_1> [<mangledSymbol_2> ...]\n");
+ }
+ return (EXIT_FAILURE);
+ }
+ for(i = 1; i < argc; i++){
+ char* demangled = DD_(demangle_d)(argv[i]);
+ if(4 > xprintf("%s\t%s\n", argv[i], demangled)){
+ xperror("main");
+ }
+ if(demangled){
+ xfree(demangled);
+ }
+ }
+ return (EXIT_SUCCESS);
+}
+#endif
diff -urN gdb-6.4/gdb/demangle_d/demangle_d_conf.h gdb-6.4-demangle_d/gdb/demangle_d/demangle_d_conf.h
--- gdb-6.4/gdb/demangle_d/demangle_d_conf.h 1970-01-01 01:00:00.000000000 +0100
+++ gdb-6.4-demangle_d/gdb/demangle_d/demangle_d_conf.h 2006-04-19 13:47:54.000000000 +0200
@@ -0,0 +1,115 @@
+#if !(DEMANGLE_D_CONF_H)
+#define DEMANGLE_D_CONF_H 1
+
+#include "demangle_d.h"
+
+#if (DEMANGLE_D_IN_VALGRIND)
+
+/* valgrind - http://www.valgrind.org */
+
+#include <stddef.h> /* size_t */
+
+#define xmemcpy VG_(memcpy)
+#define xmemmove MEMMOVE
+#define xstrlen VG_(strlen)
+#define xstrncmp VG_(strncmp)
+#define xmalloc VG_(malloc)
+#define DEMANGLE_D_REQUIRE_malloc 0
+#define xrealloc VG_(realloc)
+#define DEMANGLE_D_REQUIRE_realloc 0
+#define xfree VG_(free)
+#define xsnprintf VG_(snprintf)
+#define xisdigit ISDIGIT
+#define xisxdigit ISXDIGIT
+#define xasci2hex ASCI2HEX
+
+#define DEMANGLE_D_REQUIRE_strtol_10 1
+#define xstrtol_10 DD_(strtol_10)
+
+#else
+
+/* "normal" libc */
+#define DEMANGLE_D_IN_VALGRIND 0
+
+#include <string.h>
+#define xmemcpy memcpy
+#define xmemmove memmove
+#define xstrlen strlen
+#define xstrncmp strncmp
+
+#include <stdlib.h>
+#define xmalloc DD_(malloc)
+#define DEMANGLE_D_REQUIRE_malloc 1
+#define xrealloc DD_(realloc)
+#define DEMANGLE_D_REQUIRE_realloc 1
+#define xfree free
+#define xabort abort
+#define xstrtol_10(n,p) strtol((n), (p), 10)
+#define DEMANGLE_D_REQUIRE_strtol_10 0
+
+#include <stdio.h>
+#define xsnprintf snprintf
+
+#include <ctype.h>
+#define xisdigit isdigit
+#define xisxdigit isxdigit
+
+#define xasci2hex ASCI2HEX
+
+#if (DEMANGLE_D_STANDALONE)
+#define xprintf printf
+#define xperror perror
+#define xfprintf fprintf
+#else
+#define DEMANGLE_D_STANDALONE 0
+#endif
+
+#endif
+
+/* helper macros */
+
+#define MEMMOVE(dest, src, len) \
+{ \
+ if(((dest < src) && (dest + len < src)) \
+ || (((src < dest) && (src + len < dest)))) \
+ { \
+ xmemcpy(dest, src, len); \
+ }else{ \
+ void* tmp; \
+ tmp = xmalloc(len); \
+ xmemcpy(tmp, src, len); \
+ xmemcpy(dest, tmp, len); \
+ xfree(tmp); \
+ } \
+}
+
+#define ISDIGIT(c) (('0' <= (c)) && ((c) <= '9'))
+
+#define ISXDIGIT(c) ( \
+ (('0' <= (c)) && ((c) <= '9')) \
+ || (('a' <= (c)) && ((c) <= 'f')) \
+ || (('A' <= (c)) && ((c) <= 'F')) \
+ )
+
+#define ASCI2HEX(c) \
+ ( \
+ ('a' <= (c) && (c) <= 'f') \
+ ? \
+ ((c) - 'a' + 10) \
+ : \
+ ( \
+ ('A' <= (c) && (c) <= 'F') \
+ ? \
+ ((c) - 'A' + 10) \
+ : \
+ ( \
+ ('0' <= (c) && (c) <= '9') \
+ ? \
+ ((c) - '0') \
+ : \
+ 0 \
+ ) \
+ ) \
+ )
+
+#endif /* DEMANGLE_D_CONF_H */
diff -urN gdb-6.4/gdb/demangle_d/demangle_d.h gdb-6.4-demangle_d/gdb/demangle_d/demangle_d.h
--- gdb-6.4/gdb/demangle_d/demangle_d.h 1970-01-01 01:00:00.000000000 +0100
+++ gdb-6.4-demangle_d/gdb/demangle_d/demangle_d.h 2006-04-19 13:22:13.000000000 +0200
@@ -0,0 +1,21 @@
+#if !(DEMANGLE_D_H)
+#define DEMANGEL_D_H 1
+
+#define DD_(str) demangle_d_##str
+
+/* demangle a D symbol
+ *
+ * input:
+ * a NULL terminated mangled symbol
+ *
+ * output:
+ * UTF-8 encoded demangled symbol
+ * or NULL if unable to demangle
+ *
+ * memory:
+ * the caller is responsible to
+ * free input and output
+ */
+static char* DD_(demangle_d)(char* source);
+
+#endif /* DEMANGEL_D_H */
diff -urN gdb-6.4/gdb/demangle_d/demangle_d_internal.h gdb-6.4-demangle_d/gdb/demangle_d/demangle_d_internal.h
--- gdb-6.4/gdb/demangle_d/demangle_d_internal.h 1970-01-01 01:00:00.000000000 +0100
+++ gdb-6.4-demangle_d/gdb/demangle_d/demangle_d_internal.h 2006-04-19 13:47:14.000000000 +0200
@@ -0,0 +1,45 @@
+#if !(DEMANGLE_D_INTERNAL_H)
+#define DEMANGLE_D_INTERNAL_H 1
+
+#include "demangle_d.h"
+
+typedef struct{
+ size_t used;
+ char* str;
+ size_t len;
+} DD_(string_t);
+
+DD_(string_t)* DD_(new_string)(void);
+
+void DD_(append_n)(DD_(string_t)* dest, const char* source, size_t len);
+void DD_(append_c)(DD_(string_t)* dest, char source);
+void DD_(append)(DD_(string_t)* dest, const char* source);
+
+void DD_(prepend_n)(DD_(string_t)* dest, const char* source, size_t len);
+void DD_(prepend)(DD_(string_t)* dest, const char* source);
+
+void DD_(nestpend_n)(DD_(string_t)* dest, const char* source, size_t len, int is_nested);
+void DD_(nestpend)(DD_(string_t)* dest, const char* source, int is_nested);
+
+char* DD_(nextType)(DD_(string_t)* dest, char* raw, int is_nested);
+
+void DD_(interpreteTemplate)(DD_(string_t)* dest, char* raw);
+
+char* DD_(parseReal)(DD_(string_t)* dest, char* raw);
+char* DD_(parseFunction)(DD_(string_t)* dest, char* raw, char* name, int is_nested);
+
+char* DD_(strndup)(const char* source, size_t len);
+
+#if (DEMANGLE_D_REQUIRE_strtol_10)
+long int DD_(strtol_10)(char* src, char** endptr);
+#endif
+
+#if (DEMANGLE_D_REQUIRE_malloc)
+void* DD_(malloc)(size_t len);
+#endif
+
+#if (DEMANGLE_D_REQUIRE_realloc)
+void* DD_(realloc)(void* ptr, size_t len);
+#endif
+
+#endif /* DEMANGLE_D_INTERNAL_H */
diff -urN gdb-6.4/gdb/demangle_d/license.txt gdb-6.4-demangle_d/gdb/demangle_d/license.txt
--- gdb-6.4/gdb/demangle_d/license.txt 1970-01-01 01:00:00.000000000 +0100
+++ gdb-6.4-demangle_d/gdb/demangle_d/license.txt 2006-04-18 10:07:40.000000000 +0200
@@ -0,0 +1,22 @@
+Eiffel Forum License, version 1
+
+Permission is hereby granted to use, copy, modify and/or distribute this
+package, provided that:
+
+ - copyright notices are retained unchanged
+
+ - any distribution of this package, whether modified or not, includes this
+ file
+
+Permission is hereby also granted to distribute binary programs which depend
+on this package, provided that:
+
+ - if the binary program depends on a modified version of this package, you
+ must publicly release the modified version of this package
+
+THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT WARRANTY. ANY EXPRESS OR IMPLIED
+WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
+EVENT SHALL THE AUTHORS BE LIABLE TO ANY PARTY FOR ANY DIRECT, INDIRECT,
+INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES ARISING IN ANY WAY OUT
+OF THE USE OF THIS PACKAGE.
diff -urN gdb-6.4/gdb/demangle_d/readme.txt gdb-6.4-demangle_d/gdb/demangle_d/readme.txt
--- gdb-6.4/gdb/demangle_d/readme.txt 1970-01-01 01:00:00.000000000 +0100
+++ gdb-6.4-demangle_d/gdb/demangle_d/readme.txt 2006-04-19 12:02:13.000000000 +0200
@@ -0,0 +1,62 @@
+ pluggable D de-mangler
+=======================
+
+Author:
+ Thomas Kuehne <thomas@kuehne.cn>
+
+License:
+ Eiffel Forum License, version 1 (see license.txt)
+
+
+Usage: stand alone
+---------------------
+
+1) compile:
+ cc -DDEMANGLE_D_STANDALONE -o demangle_d demangle_d.c
+
+2) run:
+ ./demangle_d _D3std3utf6toUTF8FG4awZAa _D3std6string7sformatFAaYAa
+ > _D3std3utf6toUTF8FG4awZAa char[] std.utf.toUTF8(char[4], dchar)
+ > _D3std6string7sformatFAaYAa char[] std.string.sformat(char[], ...)
+
+
+Usage: plugin
+---------------------
+
+1) adapt demangle_d_conf.h to your system
+
+2) include demangle_d.c in your build system
+
+3) demangle:
+ #include "demangle_d.h"
+
+ char* mangled;
+ char* demangled;
+
+ mangled = "_D1b5outerFeZf";
+ demangled = DD_(demangle_d)(mangled);
+
+ // ... process demangled ...
+
+ if(demangled){
+ free(demangled);
+ }
+
+optional:
+ adapt the DD_(str) macro in "demangle_d.h" to resolve potential
+ name clashes in your object code
+
+
+TODO
+---------------------
+
+ * better output for symbols in nested types:
+ _staticCtorFZv3Ali5_ctorFiZC_D1b11_staticCtorFZv3Ali5innerFiZi
+
+ * handle "special" names:
+ _init__D1b11_staticCtorFZv3Al
+ _Class__D1b11_staticCtorFZv3Ali
+ _vtbl__D1b11_staticCtorFZv3Ali
+ _modctor_1b
+ _assert_1b
+
diff -urN gdb-6.4/gdb/d-lang.c gdb-6.4-demangle_d/gdb/d-lang.c
--- gdb-6.4/gdb/d-lang.c 1970-01-01 01:00:00.000000000 +0100
+++ gdb-6.4-demangle_d/gdb/d-lang.c 2006-04-17 22:06:33.000000000 +0200
@@ -0,0 +1,32 @@
+/* C language support routines for GDB, the GNU debugger.
+ Copyright 2006
+ Free Software Foundation, Inc.
+
+ This file is part of GDB.
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA. */
+
+#include "defs.h"
+#include "symtab.h"
+#include "demangle_d/demangle_d.c"
+
+char* d_demangle(char* symbol, int options) {
+ return DD_(demangle_d)(symbol);
+}
+
+char* d_sym_demangle(const struct general_symbol_info *gsymbol) {
+ return DD_(demangle_d)(gsymbol->name);
+}
diff -urN gdb-6.4/gdb/d-lang.h gdb-6.4-demangle_d/gdb/d-lang.h
--- gdb-6.4/gdb/d-lang.h 1970-01-01 01:00:00.000000000 +0100
+++ gdb-6.4-demangle_d/gdb/d-lang.h 2006-04-17 21:34:12.000000000 +0200
@@ -0,0 +1,37 @@
+/* C language support definitions for GDB, the GNU debugger.
+ Copyright 1992, 1994, 1995, 1996, 1997, 1998, 2000, 2002
+ Free Software Foundation, Inc.
+
+ This file is part of GDB.
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA. */
+
+
+#if !defined (D_LANG_H)
+#define D_LANG_H 1
+
+#include "symtab.h"
+
+/*****************************
+ D Language stuff
+******************************/
+
+char* d_demangle(const char* mangled, int options);
+
+char* d_sym_demangle(const struct general_symbol_info *gsymbol);
+
+
+#endif /* !defined (D_LANG_H) */
diff -urN gdb-6.4/gdb/dwarf2read.c gdb-6.4-demangle_d/gdb/dwarf2read.c
--- gdb-6.4/gdb/dwarf2read.c 2005-11-04 03:58:31.000000000 +0100
+++ gdb-6.4-demangle_d/gdb/dwarf2read.c 2006-04-17 21:30:07.000000000 +0200
@@ -6098,6 +6098,9 @@
case DW_LANG_C_plus_plus:
cu->language = language_cplus;
break;
+ case DW_LANG_D:
+ cu->language = language_d;
+ break;
case DW_LANG_Fortran77:
case DW_LANG_Fortran90:
case DW_LANG_Fortran95:
@@ -6577,7 +6580,7 @@
file = read_unsigned_leb128 (abfd, line_ptr, &bytes_read);
line_ptr += bytes_read;
fe = &lh->file_names[file - 1];
- if (fe->dir_index)
+ if (fe->dir_index && lh->include_dirs != NULL)
dir = lh->include_dirs[fe->dir_index - 1];
else
dir = comp_dir;
diff -urN gdb-6.4/gdb/language.c gdb-6.4-demangle_d/gdb/language.c
--- gdb-6.4/gdb/language.c 2005-10-03 23:21:20.000000000 +0200
+++ gdb-6.4-demangle_d/gdb/language.c 2006-04-17 21:30:46.000000000 +0200
@@ -539,6 +539,7 @@
{
case language_c:
case language_cplus:
+ case language_d:
case language_objc:
if (TYPE_CODE (t1) == TYPE_CODE_FLT)
return TYPE_CODE (t2) == TYPE_CODE_FLT && l2 > l1 ?
@@ -650,6 +651,7 @@
{
case language_c:
case language_cplus:
+ case language_d:
case language_objc:
return (TYPE_CODE (type) != TYPE_CODE_INT) &&
(TYPE_CODE (type) != TYPE_CODE_ENUM) ? 0 : 1;
@@ -690,6 +692,7 @@
case language_c:
case language_cplus:
+ case language_d:
case language_objc:
return (TYPE_CODE (type) == TYPE_CODE_INT) &&
TYPE_LENGTH (type) == sizeof (char)
@@ -712,6 +715,7 @@
case language_c:
case language_cplus:
+ case language_d:
case language_objc:
/* C does not have distinct string type. */
return (0);
@@ -731,6 +735,7 @@
{
case language_c:
case language_cplus:
+ case language_d:
case language_objc:
/* Might be more cleanly handled by having a
TYPE_CODE_INT_NOT_BOOL for (the deleted) CHILL and such
@@ -804,6 +809,7 @@
}
return builtin_type_f_logical_s2;
case language_cplus:
+ case language_d:
case language_pascal:
if (current_language->la_language==language_cplus)
{sym = lookup_symbol ("bool", NULL, VAR_DOMAIN, NULL, NULL);}
diff -urN gdb-6.4/gdb/Makefile.in gdb-6.4-demangle_d/gdb/Makefile.in
--- gdb-6.4/gdb/Makefile.in 2005-11-16 13:44:10.000000000 +0100
+++ gdb-6.4-demangle_d/gdb/Makefile.in 2006-04-17 21:32:59.000000000 +0200
@@ -515,7 +515,7 @@
c-exp.y c-lang.c c-typeprint.c c-valprint.c \
charset.c cli-out.c coffread.c coff-pe-read.c \
complaints.c completer.c corefile.c \
- cp-abi.c cp-support.c cp-namespace.c cp-valprint.c \
+ cp-abi.c cp-support.c cp-namespace.c cp-valprint.c d-lang.c \
cp-name-parser.y \
dbxread.c demangle.c dictionary.c disasm.c doublest.c dummy-frame.c \
dwarfread.c dwarf2expr.c dwarf2loc.c dwarf2read.c dwarf2-frame.c \
@@ -655,6 +655,7 @@
completer_h = completer.h
cp_abi_h = cp-abi.h
cp_support_h = cp-support.h $(symtab_h)
+d_lang_h = d-lang.h $(symtab_h)
dcache_h = dcache.h
defs_h = defs.h $(config_h) $(ansidecl_h) $(gdb_locale_h) $(gdb_signals_h) \
$(libiberty_h) $(bfd_h) $(ui_file_h) $(xm_h) $(nm_h) $(tm_h) \
@@ -918,7 +919,7 @@
dbxread.o coffread.o coff-pe-read.o elfread.o \
dwarfread.o dwarf2read.o mipsread.o stabsread.o corefile.o \
dwarf2expr.o dwarf2loc.o dwarf2-frame.o \
- ada-lang.o c-lang.o f-lang.o objc-lang.o \
+ ada-lang.o c-lang.o d-lang.o f-lang.o objc-lang.o \
ui-out.o cli-out.o \
varobj.o wrapper.o \
jv-lang.o jv-valprint.o jv-typeprint.o \
@@ -1859,6 +1860,9 @@
c-valprint.o: c-valprint.c $(defs_h) $(gdb_string_h) $(symtab_h) \
$(gdbtypes_h) $(expression_h) $(value_h) $(valprint_h) $(language_h) \
$(c_lang_h) $(cp_abi_h) $(target_h)
+d-lang.o: d-lang.c $(defs_h) $(symtab_h) $(gdbtypes_h) $(expression_h) \
+ $(parser_defs_h) $(language_h) $(c_lang_h) $(valprint_h) \
+ $(macroscope_h) $(gdb_assert_h) $(charset_h) $(gdb_string_h)
# OBSOLETE d10v-tdep.o: d10v-tdep.c
dbug-rom.o: dbug-rom.c $(defs_h) $(gdbcore_h) $(target_h) $(monitor_h) \
$(serial_h) $(regcache_h) $(m68k_tdep_h)
@@ -2668,7 +2672,7 @@
$(gdb_obstack_h) $(exceptions_h) $(language_h) $(bcache_h) \
$(block_h) $(gdb_regex_h) $(dictionary_h) $(gdb_string_h) \
$(readline_h)
-symtab.o: symtab.c $(defs_h) $(symtab_h) $(gdbtypes_h) $(gdbcore_h) \
+symtab.o: symtab.c $(defs_h) $(d_lang_h) $(symtab_h) $(gdbtypes_h) $(gdbcore_h) \
$(frame_h) $(target_h) $(value_h) $(symfile_h) $(objfiles_h) \
$(gdbcmd_h) $(call_cmds_h) $(gdb_regex_h) $(expression_h) \
$(language_h) $(demangle_h) $(inferior_h) $(linespec_h) $(source_h) \
diff -urN gdb-6.4/gdb/symfile.c gdb-6.4-demangle_d/gdb/symfile.c
--- gdb-6.4/gdb/symfile.c 2005-08-31 23:07:33.000000000 +0200
+++ gdb-6.4-demangle_d/gdb/symfile.c 2006-04-17 21:31:23.000000000 +0200
@@ -2317,6 +2317,7 @@
filename_language_table =
xmalloc (fl_table_size * sizeof (*filename_language_table));
add_filename_language (".c", language_c);
+ add_filename_language (".d", language_d);
add_filename_language (".C", language_cplus);
add_filename_language (".cc", language_cplus);
add_filename_language (".cp", language_cplus);
diff -urN gdb-6.4/gdb/symtab.c gdb-6.4-demangle_d/gdb/symtab.c
--- gdb-6.4/gdb/symtab.c 2005-03-08 05:34:44.000000000 +0100
+++ gdb-6.4-demangle_d/gdb/symtab.c 2006-04-17 21:32:33.000000000 +0200
@@ -42,6 +42,7 @@
#include "filenames.h" /* for FILENAME_CMP */
#include "objc-lang.h"
#include "ada-lang.h"
+#include "d-lang.h"
#include "hashtab.h"
@@ -405,6 +406,7 @@
{
gsymbol->language = language;
if (gsymbol->language == language_cplus
+ || gsymbol->language == language_d
|| gsymbol->language == language_java
|| gsymbol->language == language_objc)
{
@@ -451,6 +453,15 @@
if (gsymbol->language == language_unknown)
gsymbol->language = language_auto;
+ if (gsymbol->language == language_d
+ || gsymbol->language == language_auto) {
+ demangled = d_demangle(mangled, 0);
+ if (demangled != NULL) {
+ gsymbol->language = language_d;
+ return demangled;
+ }
+ }
+
if (gsymbol->language == language_objc
|| gsymbol->language == language_auto)
{
@@ -610,6 +621,7 @@
demangled = symbol_find_demangled_name (gsymbol, mangled);
if (gsymbol->language == language_cplus
+ || gsymbol->language == language_d
|| gsymbol->language == language_java
|| gsymbol->language == language_objc)
{
@@ -639,6 +651,7 @@
switch (gsymbol->language)
{
case language_cplus:
+ case language_d:
case language_java:
case language_objc:
if (gsymbol->language_specific.cplus_specific.demangled_name != NULL)
@@ -664,6 +677,7 @@
switch (gsymbol->language)
{
case language_cplus:
+ case language_d:
case language_java:
case language_objc:
if (gsymbol->language_specific.cplus_specific.demangled_name != NULL)
@@ -1023,7 +1037,7 @@
modified_name = name;
- /* If we are using C++ or Java, demangle the name before doing a lookup, so
+ /* If we are using C++, D, or Java, demangle the name before doing a lookup, so
we can always binary search. */
if (current_language->la_language == language_cplus)
{
@@ -1035,6 +1049,16 @@
needtofreename = 1;
}
}
+ else if (current_language->la_language == language_d)
+ {
+ demangled_name = d_demangle (name, 0);
+ if (demangled_name)
+ {
+ mangled_name = name;
+ modified_name = demangled_name;
+ needtofreename = 1;
+ }
+ }
else if (current_language->la_language == language_java)
{
demangled_name = cplus_demangle (name,
diff -urN gdb-6.4/include/elf/dwarf2.h gdb-6.4-demangle_d/include/elf/dwarf2.h
--- gdb-6.4/include/elf/dwarf2.h 2005-07-18 06:13:05.000000000 +0200
+++ gdb-6.4-demangle_d/include/elf/dwarf2.h 2006-04-17 21:47:19.000000000 +0200
@@ -732,6 +732,7 @@
DW_LANG_C99 = 0x000c,
DW_LANG_Ada95 = 0x000d,
DW_LANG_Fortran95 = 0x000e,
+ DW_LANG_D = 0x0013,
/* MIPS. */
DW_LANG_Mips_Assembler = 0x8001,
/* UPC. */
^ permalink raw reply [flat|nested] 20+ messages in thread* Re: D Symbol Demangling 2006-04-19 11:18 Thomas Kuehne @ 2006-04-20 13:20 ` Daniel Jacobowitz 2006-04-21 21:25 ` Thomas Kühne 0 siblings, 1 reply; 20+ messages in thread From: Daniel Jacobowitz @ 2006-04-20 13:20 UTC (permalink / raw) To: Thomas Kuehne; +Cc: gdb-patches On Wed, Apr 19, 2006 at 02:17:04PM +0200, Thomas Kuehne wrote: > Attached is a patch against GDB-6.4 that enables demangling of symbols > generated by DMD[1] and GDC[2]. > > The infrastructure part (c-lang.c, defs.h, d-lang.h, dwarf2read.c, > language.c, Makefile.in, symfile, syntab.c, dwarf2.h) is based on John > Demme's work[3][4]. > > The pluggable demangler (gdb/demangle_d/*) was written completely form > scratch and isn't based on John's work and supports templates and - to a > certain extend - nested functions and types. Unfortunately, there are several major problems with accepting this code. 1. Neither you nor John has an FSF copyright assignment in place. If you're interested in one, let me know and I can send you the forms. 2. The demangler would need to be contributed to the FSF and licensed under the GPL before we could include it with GDB. That doesn't prevent another copy of it from being used under a different license elsewhere; but you wouldn't be able to import fixes from one to the other, in either direction. 3. The code would need to match the GNU Coding Standards. 4. A patch would need to be generated against HEAD, not against an old release. And, no offense, but the DD_() thing is horribly ugly and doesn't seem to serve any purpose here. Is that for reusing the demangler elsewhere? -- Daniel Jacobowitz CodeSourcery ^ permalink raw reply [flat|nested] 20+ messages in thread
* Re: D Symbol Demangling 2006-04-20 13:20 ` Daniel Jacobowitz @ 2006-04-21 21:25 ` Thomas Kühne 2006-04-22 22:52 ` Thomas Kühne 0 siblings, 1 reply; 20+ messages in thread From: Thomas Kühne @ 2006-04-21 21:25 UTC (permalink / raw) To: gdb-patches Daniel Jacobowitz wrote: > Unfortunately, there are several major problems with accepting this > code. > > 1. Neither you nor John has an FSF copyright assignment in place. If > you're interested in one, let me know and I can send you the forms. > > 2. The demangler would need to be contributed to the FSF and licensed > under the GPL before we could include it with GDB. That doesn't > prevent another copy of it from being used under a different license > elsewhere; but you wouldn't be able to import fixes from one to the > other, in either direction. I've no problem with assigning the copyright of the demangler to the FSF if the license issue - as you noted, using more than one license might cause problems - can be solved. The GPL with linking exception would seem to be the best solution for all. (taken from /usr/portage/licenses/GPL-2-with-linking-exception) | As a special exception, the copyright holders of this library give you | permission to link this library with independent modules to produce an | executable, regardless of the license terms of these independent modules, | and to copy and distribute the resulting executable under terms of your | choice, provided that you also meet, for each linked independent module, | the terms and conditions of the license of that module. An independent | module is a module which is not derived from or based on this library. If | you modify this library, you may extend this exception to your version of | the library, but you are not obligated to do so. If you do not wish to do | so, delete this exception statement from your version. <followed by the GPL text> > 3. The code would need to match the GNU Coding Standards. > > 4. A patch would need to be generated against HEAD, not against an old > release. working on that > And, no offense, but the DD_() thing is horribly ugly and doesn't seem > to serve any purpose here. Is that for reusing the demangler > elsewhere? Yes it's ugly and not the kind of code I normally write. The problem: the demangler is currently used with GDB, Valgrind and 3 in-house tools - thus name and symbol clashes are a real problem. Thomas ^ permalink raw reply [flat|nested] 20+ messages in thread
* Re: D Symbol Demangling 2006-04-21 21:25 ` Thomas Kühne @ 2006-04-22 22:52 ` Thomas Kühne 2006-04-24 17:21 ` Jim Blandy 0 siblings, 1 reply; 20+ messages in thread From: Thomas Kühne @ 2006-04-22 22:52 UTC (permalink / raw) To: gdb-patches [-- Attachment #1: Type: text/plain, Size: 173 bytes --] >>3. The code would need to match the GNU Coding Standards. >> >>4. A patch would need to be generated against HEAD, not against an old >>release. see attachment Thomas [-- Attachment #2: gdb-20060422-demangle_d.diff --] [-- Type: text/plain, Size: 74091 bytes --] diff --exclude=CVS -urN current/gdb/c-lang.c current-demangle_d/gdb/c-lang.c --- current/gdb/c-lang.c 2005-12-17 23:33:59.000000000 +0100 +++ current-demangle_d/gdb/c-lang.c 2006-04-22 18:22:35.000000000 +0200 @@ -27,6 +27,7 @@ #include "parser-defs.h" #include "language.h" #include "c-lang.h" +#include "d-lang.h" #include "valprint.h" #include "macroscope.h" #include "gdb_assert.h" @@ -735,10 +736,48 @@ LANG_MAGIC }; +const struct language_defn d_language_defn = +{ + "d", /* Language name */ + language_d, + NULL, + range_check_off, + type_check_off, + case_sensitive_on, + array_row_major, + &exp_descriptor_standard, + c_preprocess_and_parse, + c_error, + null_post_parser, + c_printchar, /* Print a character constant */ + c_printstr, /* Function to print string constant */ + c_emit_char, /* Print a single char */ + c_create_fundamental_type, /* Create fundamental type in this language */ + c_print_type, /* Print a type using appropriate syntax */ + c_val_print, /* Print a value using appropriate syntax */ + c_value_print, /* Print a top-level value */ + NULL, /* Language specific skip_trampoline */ + NULL, /* value_of_this */ + basic_lookup_symbol_nonlocal, /* lookup_symbol_nonlocal */ + basic_lookup_transparent_type,/* lookup_transparent_type */ + d_demangle, /* Language specific symbol demangler */ + NULL, /* Language specific class_name_from_physname */ + c_op_print_tab, /* expression operators for printing */ + 1, /* c-style arrays */ + 0, /* String lower bound */ + NULL, + default_word_break_characters, + c_language_arch_info, + default_print_array_index, + LANG_MAGIC +}; + + void _initialize_c_language (void) { add_language (&c_language_defn); + add_language (&d_language_defn); add_language (&cplus_language_defn); add_language (&asm_language_defn); add_language (&minimal_language_defn); diff --exclude=CVS -urN current/gdb/defs.h current-demangle_d/gdb/defs.h --- current/gdb/defs.h 2006-02-25 05:36:39.000000000 +0100 +++ current-demangle_d/gdb/defs.h 2006-04-22 18:22:35.000000000 +0200 @@ -202,6 +202,7 @@ language_auto, /* Placeholder for automatic setting */ language_c, /* C */ language_cplus, /* C++ */ + language_d, /* D */ language_objc, /* Objective-C */ language_java, /* Java */ language_fortran, /* Fortran */ diff --exclude=CVS -urN current/gdb/demangle_d/config.h current-demangle_d/gdb/demangle_d/config.h --- current/gdb/demangle_d/config.h 1970-01-01 01:00:00.000000000 +0100 +++ current-demangle_d/gdb/demangle_d/config.h 2006-04-23 01:01:44.000000000 +0200 @@ -0,0 +1,119 @@ +#ifndef DEMANGLE_D_CONFIG_H +#define DEMANGLE_D_CONFIG_H 1 + +#include "demangle.h" + +#undef DEMANGLE_D_REQUIRE_ISDIGIT +#undef DEMANGLE_D_REQUIRE_ISXDIGIT +#undef DEMANGLE_D_REQUIRE_ASCI2HEX + +#ifdef DEMANGLE_D_IN_VALGRIND + +/* valgrind - http://www.valgrind.org */ + +#include <stddef.h> /* size_t */ + +#define xstrlen VG_(strlen) +#define xstrncmp VG_(strncmp) +#define xsnprintf VG_(snprintf) +#define xisdigit ISDIGIT +#define DEMANGLE_D_REQUIRE_ISDIGIT 1 +#define xisxdigit ISXDIGIT +#define DEMANGLE_D_REQUIRE_ISXDIGIT 1 +#define xasci2hex ASCI2HEX +#define DEMANGLE_D_REQUIRE_ASCI2HEX 1 + + +#elif defined(DEMANGLE_D_IN_GDB) /* not DEMANGLE_D_IN_VALGRIND */ + +/* gdb - http://www.gnu.org/software/gdb/ */ + +#include <stddef.h> /* size_t */ + +#include <string.h> +#define xstrlen strlen +#define xstrncmp strncmp + + +#include "../defs.h" +/* xsnprintf */ + +#include "../../include/safe-ctype.h" +#define xisdigit ISDIGIT +#define xisxdigit ISXDIGIT + +#define xasci2hex ASCI2HEX +#define DEMANGLE_D_REQUIRE_ASCI2HEX 1 + + +#else /* not DEMANGLE_D_IN_GDB */ + +/* "normal" libc */ + +#include <stddef.h> /* size_t */ + +#include <string.h> +#define xstrlen strlen +#define xstrncmp strncmp + +#include <stdlib.h> +#define xabort abort + +#include <stdio.h> +#define xsnprintf snprintf + +#include <ctype.h> +#define xisdigit isdigit +#define xisxdigit isxdigit + +#define xasci2hex ASCI2HEX +#define DEMANGLE_D_REQUIRE_ASCI2HEX 1 + + +#endif /* not DEMANGLE_D_IN_VALGRIND && not DEMANGLE_D_IN_GDB */ + +#include <libintl.h> +#ifdef _LIBINTL_H +#define _(str) gettext(str) +#else +#define _(str) str +#endif + +/* helper macros */ + +#ifdef DEMANGLE_D_REQUIRE_ISDIGIT +#define ISDIGIT(c) (('0' <= (c)) && ((c) <= '9')) +#endif + +#ifdef DEMANGLE_D_REQUIRE_ISXDIGIT +#define ISXDIGIT(c) ( \ + (('0' <= (c)) && ((c) <= '9')) \ + || (('a' <= (c)) && ((c) <= 'f')) \ + || (('A' <= (c)) && ((c) <= 'F')) \ + ) +#endif + +#ifdef DEMANGLE_D_REQUIRE_ASCI2HEX +#define ASCI2HEX(c) \ + ( \ + ('a' <= (c) && (c) <= 'f') \ + ? \ + ((c) - 'a' + 10) \ + : \ + ( \ + ('A' <= (c) && (c) <= 'F') \ + ? \ + ((c) - 'A' + 10) \ + : \ + ( \ + ('0' <= (c) && (c) <= '9') \ + ? \ + ((c) - '0') \ + : \ + 0 \ + ) \ + ) \ + ) +#endif + +#endif /* DEMANGLE_D_CONFIG_H */ diff --exclude=CVS -urN current/gdb/demangle_d/COPYING current-demangle_d/gdb/demangle_d/COPYING --- current/gdb/demangle_d/COPYING 1970-01-01 01:00:00.000000000 +0100 +++ current-demangle_d/gdb/demangle_d/COPYING 2006-04-23 00:37:13.000000000 +0200 @@ -0,0 +1,352 @@ +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent modules, +and to copy and distribute the resulting executable under terms of your choice, +provided that you also meet, for each linked independent module, the terms and +conditions of the license of that module. An independent module is a module +which is not derived from or based on this library. If you modify this library, +you may extend this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this exception +statement from your version. + + + GNU GENERAL PUBLIC LICENSE + Version 2, June 1991 + + Copyright (C) 1989, 1991 Free Software Foundation, Inc. + 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + + Preamble + + The licenses for most software are designed to take away your +freedom to share and change it. By contrast, the GNU General Public +License is intended to guarantee your freedom to share and change free +software--to make sure the software is free for all its users. This +General Public License applies to most of the Free Software +Foundation's software and to any other program whose authors commit to +using it. (Some other Free Software Foundation software is covered by +the GNU Library General Public License instead.) You can apply it to +your programs, too. + + When we speak of free software, we are referring to freedom, not +price. Our General Public Licenses are designed to make sure that you +have the freedom to distribute copies of free software (and charge for +this service if you wish), that you receive source code or can get it +if you want it, that you can change the software or use pieces of it +in new free programs; and that you know you can do these things. + + To protect your rights, we need to make restrictions that forbid +anyone to deny you these rights or to ask you to surrender the rights. +These restrictions translate to certain responsibilities for you if you +distribute copies of the software, or if you modify it. + + For example, if you distribute copies of such a program, whether +gratis or for a fee, you must give the recipients all the rights that +you have. You must make sure that they, too, receive or can get the +source code. And you must show them these terms so they know their +rights. + + We protect your rights with two steps: (1) copyright the software, and +(2) offer you this license which gives you legal permission to copy, +distribute and/or modify the software. + + Also, for each author's protection and ours, we want to make certain +that everyone understands that there is no warranty for this free +software. If the software is modified by someone else and passed on, we +want its recipients to know that what they have is not the original, so +that any problems introduced by others will not reflect on the original +authors' reputations. + + Finally, any free program is threatened constantly by software +patents. We wish to avoid the danger that redistributors of a free +program will individually obtain patent licenses, in effect making the +program proprietary. To prevent this, we have made it clear that any +patent must be licensed for everyone's free use or not licensed at all. + + The precise terms and conditions for copying, distribution and +modification follow. +\f + GNU GENERAL PUBLIC LICENSE + TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION + + 0. This License applies to any program or other work which contains +a notice placed by the copyright holder saying it may be distributed +under the terms of this General Public License. The "Program", below, +refers to any such program or work, and a "work based on the Program" +means either the Program or any derivative work under copyright law: +that is to say, a work containing the Program or a portion of it, +either verbatim or with modifications and/or translated into another +language. (Hereinafter, translation is included without limitation in +the term "modification".) Each licensee is addressed as "you". + +Activities other than copying, distribution and modification are not +covered by this License; they are outside its scope. The act of +running the Program is not restricted, and the output from the Program +is covered only if its contents constitute a work based on the +Program (independent of having been made by running the Program). +Whether that is true depends on what the Program does. + + 1. You may copy and distribute verbatim copies of the Program's +source code as you receive it, in any medium, provided that you +conspicuously and appropriately publish on each copy an appropriate +copyright notice and disclaimer of warranty; keep intact all the +notices that refer to this License and to the absence of any warranty; +and give any other recipients of the Program a copy of this License +along with the Program. + +You may charge a fee for the physical act of transferring a copy, and +you may at your option offer warranty protection in exchange for a fee. + + 2. You may modify your copy or copies of the Program or any portion +of it, thus forming a work based on the Program, and copy and +distribute such modifications or work under the terms of Section 1 +above, provided that you also meet all of these conditions: + + a) You must cause the modified files to carry prominent notices + stating that you changed the files and the date of any change. + + b) You must cause any work that you distribute or publish, that in + whole or in part contains or is derived from the Program or any + part thereof, to be licensed as a whole at no charge to all third + parties under the terms of this License. + + c) If the modified program normally reads commands interactively + when run, you must cause it, when started running for such + interactive use in the most ordinary way, to print or display an + announcement including an appropriate copyright notice and a + notice that there is no warranty (or else, saying that you provide + a warranty) and that users may redistribute the program under + these conditions, and telling the user how to view a copy of this + License. (Exception: if the Program itself is interactive but + does not normally print such an announcement, your work based on + the Program is not required to print an announcement.) +\f +These requirements apply to the modified work as a whole. If +identifiable sections of that work are not derived from the Program, +and can be reasonably considered independent and separate works in +themselves, then this License, and its terms, do not apply to those +sections when you distribute them as separate works. But when you +distribute the same sections as part of a whole which is a work based +on the Program, the distribution of the whole must be on the terms of +this License, whose permissions for other licensees extend to the +entire whole, and thus to each and every part regardless of who wrote it. + +Thus, it is not the intent of this section to claim rights or contest +your rights to work written entirely by you; rather, the intent is to +exercise the right to control the distribution of derivative or +collective works based on the Program. + +In addition, mere aggregation of another work not based on the Program +with the Program (or with a work based on the Program) on a volume of +a storage or distribution medium does not bring the other work under +the scope of this License. + + 3. You may copy and distribute the Program (or a work based on it, +under Section 2) in object code or executable form under the terms of +Sections 1 and 2 above provided that you also do one of the following: + + a) Accompany it with the complete corresponding machine-readable + source code, which must be distributed under the terms of Sections + 1 and 2 above on a medium customarily used for software interchange; or, + + b) Accompany it with a written offer, valid for at least three + years, to give any third party, for a charge no more than your + cost of physically performing source distribution, a complete + machine-readable copy of the corresponding source code, to be + distributed under the terms of Sections 1 and 2 above on a medium + customarily used for software interchange; or, + + c) Accompany it with the information you received as to the offer + to distribute corresponding source code. (This alternative is + allowed only for noncommercial distribution and only if you + received the program in object code or executable form with such + an offer, in accord with Subsection b above.) + +The source code for a work means the preferred form of the work for +making modifications to it. For an executable work, complete source +code means all the source code for all modules it contains, plus any +associated interface definition files, plus the scripts used to +control compilation and installation of the executable. However, as a +special exception, the source code distributed need not include +anything that is normally distributed (in either source or binary +form) with the major components (compiler, kernel, and so on) of the +operating system on which the executable runs, unless that component +itself accompanies the executable. + +If distribution of executable or object code is made by offering +access to copy from a designated place, then offering equivalent +access to copy the source code from the same place counts as +distribution of the source code, even though third parties are not +compelled to copy the source along with the object code. +\f + 4. You may not copy, modify, sublicense, or distribute the Program +except as expressly provided under this License. Any attempt +otherwise to copy, modify, sublicense or distribute the Program is +void, and will automatically terminate your rights under this License. +However, parties who have received copies, or rights, from you under +this License will not have their licenses terminated so long as such +parties remain in full compliance. + + 5. You are not required to accept this License, since you have not +signed it. However, nothing else grants you permission to modify or +distribute the Program or its derivative works. These actions are +prohibited by law if you do not accept this License. Therefore, by +modifying or distributing the Program (or any work based on the +Program), you indicate your acceptance of this License to do so, and +all its terms and conditions for copying, distributing or modifying +the Program or works based on it. + + 6. Each time you redistribute the Program (or any work based on the +Program), the recipient automatically receives a license from the +original licensor to copy, distribute or modify the Program subject to +these terms and conditions. You may not impose any further +restrictions on the recipients' exercise of the rights granted herein. +You are not responsible for enforcing compliance by third parties to +this License. + + 7. If, as a consequence of a court judgment or allegation of patent +infringement or for any other reason (not limited to patent issues), +conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot +distribute so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you +may not distribute the Program at all. For example, if a patent +license would not permit royalty-free redistribution of the Program by +all those who receive copies directly or indirectly through you, then +the only way you could satisfy both it and this License would be to +refrain entirely from distribution of the Program. + +If any portion of this section is held invalid or unenforceable under +any particular circumstance, the balance of the section is intended to +apply and the section as a whole is intended to apply in other +circumstances. + +It is not the purpose of this section to induce you to infringe any +patents or other property right claims or to contest validity of any +such claims; this section has the sole purpose of protecting the +integrity of the free software distribution system, which is +implemented by public license practices. Many people have made +generous contributions to the wide range of software distributed +through that system in reliance on consistent application of that +system; it is up to the author/donor to decide if he or she is willing +to distribute software through any other system and a licensee cannot +impose that choice. + +This section is intended to make thoroughly clear what is believed to +be a consequence of the rest of this License. +\f + 8. If the distribution and/or use of the Program is restricted in +certain countries either by patents or by copyrighted interfaces, the +original copyright holder who places the Program under this License +may add an explicit geographical distribution limitation excluding +those countries, so that distribution is permitted only in or among +countries not thus excluded. In such case, this License incorporates +the limitation as if written in the body of this License. + + 9. The Free Software Foundation may publish revised and/or new versions +of the General Public License from time to time. Such new versions will +be similar in spirit to the present version, but may differ in detail to +address new problems or concerns. + +Each version is given a distinguishing version number. If the Program +specifies a version number of this License which applies to it and "any +later version", you have the option of following the terms and conditions +either of that version or of any later version published by the Free +Software Foundation. If the Program does not specify a version number of +this License, you may choose any version ever published by the Free Software +Foundation. + + 10. If you wish to incorporate parts of the Program into other free +programs whose distribution conditions are different, write to the author +to ask for permission. For software which is copyrighted by the Free +Software Foundation, write to the Free Software Foundation; we sometimes +make exceptions for this. Our decision will be guided by the two goals +of preserving the free status of all derivatives of our free software and +of promoting the sharing and reuse of software generally. + + NO WARRANTY + + 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY +FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN +OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES +PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED +OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF +MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS +TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE +PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, +REPAIR OR CORRECTION. + + 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING +WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR +REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, +INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING +OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED +TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY +YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER +PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE +POSSIBILITY OF SUCH DAMAGES. + + END OF TERMS AND CONDITIONS +\f + How to Apply These Terms to Your New Programs + + If you develop a new program, and you want it to be of the greatest +possible use to the public, the best way to achieve this is to make it +free software which everyone can redistribute and change under these terms. + + To do so, attach the following notices to the program. It is safest +to attach them to the start of each source file to most effectively +convey the exclusion of warranty; and each file should have at least +the "copyright" line and a pointer to where the full notice is found. + + <one line to give the program's name and a brief idea of what it does.> + Copyright (C) <year> <name of author> + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + + +Also add information on how to contact you by electronic and paper mail. + +If the program is interactive, make it output a short notice like this +when it starts in an interactive mode: + + Gnomovision version 69, Copyright (C) year name of author + Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. + This is free software, and you are welcome to redistribute it + under certain conditions; type `show c' for details. + +The hypothetical commands `show w' and `show c' should show the appropriate +parts of the General Public License. Of course, the commands you use may +be called something other than `show w' and `show c'; they could even be +mouse-clicks or menu items--whatever suits your program. + +You should also get your employer (if you work as a programmer) or your +school, if any, to sign a "copyright disclaimer" for the program, if +necessary. Here is a sample; alter the names: + + Yoyodyne, Inc., hereby disclaims all copyright interest in the program + `Gnomovision' (which makes passes at compilers) written by James Hacker. + + <signature of Ty Coon>, 1 April 1989 + Ty Coon, President of Vice + +This General Public License does not permit incorporating your program into +proprietary programs. If your program is a subroutine library, you may +consider it more useful to permit linking proprietary applications with the +library. If this is what you want to do, use the GNU Library General +Public License instead of this License. diff --exclude=CVS -urN current/gdb/demangle_d/demangle.c current-demangle_d/gdb/demangle_d/demangle.c --- current/gdb/demangle_d/demangle.c 1970-01-01 01:00:00.000000000 +0100 +++ current-demangle_d/gdb/demangle_d/demangle.c 2006-04-23 00:34:16.000000000 +0200 @@ -0,0 +1,5 @@ +/* used as source drop for plugins without the need to adapt the build system */ +#include "main.c" +#include "parser.c" +#include "string.c" +#include "util.c" diff --exclude=CVS -urN current/gdb/demangle_d/demangle.h current-demangle_d/gdb/demangle_d/demangle.h --- current/gdb/demangle_d/demangle.h 1970-01-01 01:00:00.000000000 +0100 +++ current-demangle_d/gdb/demangle_d/demangle.h 2006-04-22 23:41:47.000000000 +0200 @@ -0,0 +1,21 @@ +#ifndef DEMANGLE_D_DEMANGLE_H +#define DEMANGEL_D_DEMANGLE_H 1 + +#define DD_(str) demangle_d_##str + +/* demangle a D symbol + * + * input: + * a NULL terminated mangled symbol + * + * output: + * UTF-8 encoded demangled symbol + * or NULL if unable to demangle + * + * memory: + * the caller is responsible to + * free input and output + */ +char* DD_(demangle_d)(char*); + +#endif /* DEMANGEL_D_DEMANGLE_H */ diff --exclude=CVS -urN current/gdb/demangle_d/main.c current-demangle_d/gdb/demangle_d/main.c --- current/gdb/demangle_d/main.c 1970-01-01 01:00:00.000000000 +0100 +++ current-demangle_d/gdb/demangle_d/main.c 2006-04-23 01:02:46.000000000 +0200 @@ -0,0 +1,59 @@ +/* + * demangle_d - pluggable D de-mangler + * Copyright (C) 2006 Thomas Kuehne <thomas@kuehne.cn> + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * As a special exception, the copyright holders of this library give you + * permission to link this library with independent modules to produce an + * executable, regardless of the license terms of these independent modules, + * and to copy and distribute the resulting executable under terms of your + * choice, provided that you also meet, for each linked independent module, + * the terms and conditions of the license of that module. An independent + * module is a module which is not derived from or based on this library. If + * you modify this library, you may extend this exception to your version of + * the library, but you are not obligated to do so. If you do not wish to do + * so, delete this exception statement from your version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + */ + +#ifdef DEMANGLE_D_STANDALONE +#include "parser.h" +#include "util.h" + +int +main(int argc, char** argv) +{ + int i; + if (argc < 2) + { + xfprintf(stderr, + _("pluggable D d-demangler by Thomas Kuehne <thomas@kuehne.cn> (%s)\n"), + "$Date: 2006-04-22T18:03:19.787625Z $"); + xfprintf(stderr, _("%s <mangledSymbol_1> [<mangledSymbol_2> ...]\n"), + argc ? argv[0] :"demangle_d"); + return (EXIT_FAILURE); + } + for (i = 1; i < argc; i++) + { + char* demangled = DD_(demangle_d)(argv[i]); + if (1 > xprintf(_("%s\t%s\n"), argv[i], demangled)) + xperror(NULL); + if (demangled) + xfree(demangled); + } + return (EXIT_SUCCESS); +} +#endif /* DEMANGLE_D_STANDALONE */ diff --exclude=CVS -urN current/gdb/demangle_d/parser.c current-demangle_d/gdb/demangle_d/parser.c --- current/gdb/demangle_d/parser.c 1970-01-01 01:00:00.000000000 +0100 +++ current-demangle_d/gdb/demangle_d/parser.c 2006-04-23 01:13:26.000000000 +0200 @@ -0,0 +1,694 @@ +/* + * demangle_d - pluggable D de-mangler + * Copyright (C) 2006 Thomas Kuehne <thomas@kuehne.cn> + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * As a special exception, the copyright holders of this library give you + * permission to link this library with independent modules to produce an + * executable, regardless of the license terms of these independent modules, + * and to copy and distribute the resulting executable under terms of your + * choice, provided that you also meet, for each linked independent module, + * the terms and conditions of the license of that module. An independent + * module is a module which is not derived from or based on this library. If + * you modify this library, you may extend this exception to your version of + * the library, but you are not obligated to do so. If you do not wish to do + * so, delete this exception statement from your version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + */ + +#include "parser.h" +#include "util.h" + +/* Parse until the end of the next type and return the pointer to the first + uninterpreted charachter or NULL. Set is_nested if a nested type + (e.g. index of AA or template/function parameter) is parsed. */ +char* +next_type(dest, source, is_nested) + string_t dest; char* source; int is_nested; +{ + if (!source || !source[0]) + return NULL; + + if ((source[0] == '_') && (source[1] == 'D') && xisdigit(source[2]) + && (source[2] != '0')) + { + string_t tmp; + tmp = new_string(); + source = next_type(tmp, source + 2, 0); + if (dest->used && (dest->str[dest->used] != '.')) + append_c(dest, '.'); + append_n(dest, tmp->str, tmp->used); + xfree(tmp->str); + xfree(tmp); + return source; + } + + switch(source[0]) + { + case 'v': + nestpend(dest, "void", is_nested); + source += 1; + break; + case 'b': /* deprecated since DMD-0.148 (2006-02-25) */ + nestpend(dest, "bit", is_nested); + source += 1; + break; + case 'x': + nestpend(dest, "bool", is_nested); + source += 1; + break; + case 'g': + nestpend(dest, "byte", is_nested); + source += 1; + break; + case 'h': + nestpend(dest, "ubyte", is_nested); + source += 1; + break; + case 's': + nestpend(dest, "short", is_nested); + source += 1; + break; + case 't': + nestpend(dest, "ushort", is_nested); + source += 1; + break; + case 'i': + nestpend(dest, "int", is_nested); + source += 1; + break; + case 'k': + nestpend(dest, "uint", is_nested); + source += 1; + break; + case 'l': + nestpend(dest, "long", is_nested); + source += 1; + break; + case 'm': + nestpend(dest, "ulong", is_nested); + source += 1; + break; + case 'f': + nestpend(dest, "float", is_nested); + source += 1; + break; + case 'd': + nestpend(dest, "double", is_nested); + source += 1; + break; + case 'e': + nestpend(dest, "real", is_nested); + source += 1; + break; + case 'o': + nestpend(dest, "ifloat", is_nested); + source += 1; + break; + case 'p': + nestpend(dest, "idouble", is_nested); + source += 1; + break; + case 'j': + nestpend(dest, "ireal", is_nested); + source += 1; + break; + case 'q': + nestpend(dest, "cfloat", is_nested); + source += 1; + break; + case 'r': + nestpend(dest, "cdouble", is_nested); + source += 1; + break; + case 'c': + nestpend(dest, "creal", is_nested); + source += 1; + break; + case 'a': + nestpend(dest, "char", is_nested); + source += 1; + break; + case 'u': + nestpend(dest, "wchar", is_nested); + source += 1; + break; + case 'w': + nestpend(dest, "dchar", is_nested); + source += 1; + break; + + case 'A': /* dynamic array */ + if (!is_nested) + prepend(dest, "[] "); + source = next_type(dest, source+1, is_nested); + if (is_nested) + append(dest, "[]"); + break; + + case 'G': /* static array */ + { + char* start; + char* end; + start = ++source; + end = start; + + while (xisdigit(*end)) + end++; + + if (!is_nested) + { + prepend(dest, "] "); + prepend_n(dest, start, end-start); + prepend(dest, "["); + } + source = next_type(dest, end, is_nested); + if (is_nested) + { + append_c(dest, '['); + append_n(dest, start, end-start); + append_c(dest, ']'); + } + break; + } + + case 'H': /* associative array */ + { + string_t aa; + aa = new_string(); + source = next_type(aa, source+1, 1); + prepend(aa, "["); + append_c(aa, ']'); + source = next_type(aa, source, 0); + nestpend(dest, aa->str, is_nested); + xfree(aa->str); + xfree(aa); + break; + } + + case 'D': /* delegate */ + { + string_t sig; + sig = new_string(); + source = parse_function(sig, source+1, NULL, 0); + nestpend_n(dest, sig->str, sig->used, is_nested); + xfree(sig->str); + xfree(sig); + break; + } + + case 'P': /* pointer */ + if ((source[1] == 'F') || (source[1]=='U') || (source[1]=='W') + || (source[1]=='V') || (source[1]=='R')) + { + /* function */ + string_t sig; + sig = new_string(); + source = parse_function(sig, source+1, "", 0); + nestpend_n(dest, sig->str, sig->used, is_nested); + xfree(sig->str); + xfree(sig); + } + else + { + /* 'normal' type */ + if (!is_nested) + prepend(dest, "* "); + source = next_type(dest, source+1, is_nested); + if (is_nested) + append(dest, " *"); + } + break; + + case 'J': /* out */ + append(dest, "out "); + source = next_type(dest, source+1, 1); + break; + + case 'K': /* inout */ + append(dest, "inout "); + source = next_type(dest, source+1, 1); + break; + + case 'C': /* class */ + case 'S': /* struct */ + case 'E': /* enum */ + case 'T': /* typedef */ + { +#ifdef DEMANGLE_D_VERBOSE + char tmp; + tmp = source[0]; +#endif /* DEMANGLE_D_VERBOSE */ + if (!is_nested) + { + string_t sig; + sig = new_string(); + source = next_type(sig, source+1, 0); + append_c(sig, ' '); +#ifdef DEMANGLE_D_VERBOSE + switch (tmp) + { + case 'C': + prepend(sig, "class "); + break; + case 'S': + prepend(sig, "struct "); + break; + case 'E': + prepend(sig, "enum "); + break; + case 'T': + prepend(sig, "typedef "); + break; + } +#endif /* DEMANGLE_D_VERBOSE */ + prepend_n(dest, sig->str, sig->used); + xfree(sig->str); + xfree(sig); + } + else + { +#ifdef DEMANGLE_D_VERBOSE + switch (tmp) + { + case 'C': + append(dest, "class "); + break; + case 'S': + append(dest, "struct "); + break; + case 'E': + append(dest, "enum "); + break; + case 'T': + append(dest, "typedef "); + break; + } +#endif /* DEMANGLE_D_VERBOSE */ + source = next_type(dest, source+1, 1); + } + break; + } + + case '1': /* qualified name */ + case '2': + case '3': + case '4': + case '5': + case '6': + case '7': + case '8': + case '9': + { + int first_round; + first_round = 1; + + while (source && xisdigit(source[0]) && (source[0] != '0')) + { + long int len; + len = xstrtol_10(source, &source); + + if (!first_round) + append_c(dest, '.'); + else + first_round = 0; + + if (len >= 5 && (source[0] == '_') && (source[1] == '_') + && (source[2] == 'T') && xisdigit(source[3]) + && (source[3] != '0')) + { + /* template */ + char* template; + template = xstrndup(source + 3, len-3); + interprete_template(dest, template); + xfree(template); + } + else if((len == 5) && (xstrncmp(source, "_ctor", len) == 0)) + append(dest, "this"); + else if((len == 5) && (xstrncmp(source, "_dtor", len) == 0)) + append(dest, "~this"); + else if((len == 11) + && (xstrncmp(source, "_staticCtorFZv", len + 3) == 0)) + { + prepend(dest, "static void "); + append(dest, "this()"); + source = source + 11 + 3; + break; + } + else if((len == 11) + && (xstrncmp(source, "_staticDtorFZv", len + 3) == 0)) + { + prepend(dest, "static void "); + append(dest, "~this()"); + source = source + 11 + 3; + break; + } + else + /* plain identifier part */ + append_n(dest, source, len); + + source += len; + } + if (!is_nested) + source = next_type(dest, source, 0); + break; + } + + case 'F': /* D function */ + case 'U': /* C function */ + case 'W': /* Windows function */ + case 'V': /* Pascal function */ + case 'R': /* C++ function */ + if (!is_nested) + { + string_t id; + id = new_string(); + append_n(id, dest->str, dest->used); + dest->used = 0; + dest->str[0] = '\x00'; + source = parse_function(dest, source, id->str, 0); + xfree(id->str); + xfree(id); + } + else + source = parse_function(dest, source, "", 1); + break; + + default: + append(dest, " @bug@[2]{"); + append(dest, source); + append_c(dest, '}'); + source = NULL; + break; + } + + return source; +} + +/* Parse a "real" template parameter and return a pointer to the first not + interpreted character. */ +char* +parse_real(dest, source) + string_t dest; char* source; +{ + /* FIXME architecture dependent */ + long double f; + size_t i; + int tmp; + char* buffer; + unsigned char* c; + + c = (unsigned char*) &f; + + for (i = 0; i < 10; i++) + { + if (!xisxdigit(source[i * 2]) || !xisxdigit(source[i * 2 + 1])) + { +format_error: + append(dest, "0x"); + append_n(dest, source, 20); + return source + 20; + } + c[i] = (xasci2hex(source[i * 2]) << 4); + c[i] |= xasci2hex(source[i * 2 + 1]); + } + + buffer = xmalloc(64); + tmp = xsnprintf(buffer, 64, "%Lf", f); + if (tmp < 1) + { + xfree(buffer); + goto format_error; + } + append_n(dest, buffer, tmp); + xfree(buffer); + return source + 20; +} + +/* Parse a function - including arguments and return type - and + return a pointer to the first not interpreted character. */ +char* +parse_function(dest, source, name, is_nested) + string_t dest; char* source; char* name; int is_nested; +{ + string_t fn_return; + string_t fn_param; + + fn_return = new_string(); + fn_param = new_string(); + + source++; + + /* params */ + if (source[0] != 'Z') + { + if (source[0] == 'Y') + { + append(fn_param, "..."); + goto var_arg_param; + } + source = next_type(fn_param, source, 1); + while (source && source[0] && source[0]!='Z') + { + if (source[0] == 'Y') + { + append(fn_param, ", ..."); + goto var_arg_param; + } + else if(source[0] == 'X') + { + append(fn_param, " ..."); + goto var_arg_param; + } + append(fn_param, ", "); + source = next_type(fn_param, source, 1); + } + } + + /* return type */ + if (source && source[0] == 'Z') +var_arg_param: + source = next_type(fn_return, source + 1, 1); + + /* output */ + if (name && name[0]) + if (! is_nested) + { + prepend(dest, " "); + prepend_n(dest, fn_return->str, fn_return->used); + append(dest, name); + } + else + { + append_n(dest, fn_return->str, fn_return->used); + append_c(dest, ' '); + append(dest, name); + } + else if(name) + { + append_n(dest, fn_return->str, fn_return->used); + append(dest, " function"); + } + else + { + append_n(dest, fn_return->str, fn_return->used); + append(dest, " delegate"); + } + + if (fn_param->used) + { + append_c(dest, '('); + append_n(dest, fn_param->str, fn_param->used); + append_c(dest, ')'); + } + else + append(dest, "()"); + + xfree(fn_return->str); + xfree(fn_return); + xfree(fn_param->str); + xfree(fn_param); + + return source; +} + +/* Interprete the NULL terminated template symbol. */ +void +interprete_template(dest, raw) + string_t dest; char* raw; +{ + char* tmp; + long int dataLen; + int first_arg; + + first_arg = 1; + + /* id */ + while (xisdigit(raw[0]) && (raw[0] != '0')) + { + long int len; + len = xstrtol_10(raw, &raw); + append_n(dest, raw, len); + raw += len; + } + append(dest, "!("); + + /* arguments */ + while (raw && raw[0]) + { + if (raw[0] == 'T') + { + /* type parameter */ + raw++; + if (!first_arg) + append(dest, ", "); + else + first_arg = 0; + raw = next_type(dest, raw, 1); + } + else if(raw[0] == 'V') + { + /* value parameter */ + if (!first_arg) + append(dest, ", "); + else + first_arg = 0; + raw = next_type(dest, raw + 1, 1); + append_c(dest, ' '); + if (xisdigit(raw[0])) + { + /* positive integer */ +integer_arg: + tmp = raw; + while (xisdigit(raw[0])) + raw++; + append_n(dest, tmp, raw-tmp); + } + else if(raw[0] == 'N') + { + /* negative integer */ + raw++; + append_c(dest, '-'); + goto integer_arg; + } + else if(raw[0] == 'e') + /* float */ + raw = parse_real(dest, raw+1); + else if(raw[0] == 'c') + { + /* complex float */ + raw = parse_real(dest, raw+1); + append(dest, " + "); + raw = parse_real(dest, raw); + append_c(dest, 'i'); + } + else if(raw[0] == 'n') + { + append(dest, "null"); + raw++; + } + else if((raw[0] == 'a') || (raw[0] == 'w') || (raw[0] == 'd')) + { + /* character literal */ + raw++; + if (!xisdigit(raw[0])) + goto bug; + dataLen = xstrtol_10(raw, &raw); + if (raw[0] != '_') + goto bug; + raw++; + append_c(dest, '"'); + while (dataLen--) + { + if (xisxdigit(raw[0]) && xisxdigit(raw[1])) + append_c(dest, (xasci2hex(raw[0]) << 4) + + xasci2hex(raw[1])); + else + append_c(dest, '?'); + raw += 2; + } + append_c(dest, '"'); + } + else + goto bug; + } + else if(raw[0] == 'Z') + /* end of parameter list */ + break; + else + { +bug: + append(dest, " @bug@[1]{"); + append(dest, raw); + append_c(dest, '}'); + break; + } + } + append_c(dest, ')'); +} + +/* Demangle the NULL-terminated D symbol and return the UTF-8 encoded + representation or NULL. The caller is responsible to free input and + output. */ +char* +demangle_d(source) + char* source; +{ + string_t dest; + string_t nested; + char* back; + + if ((source[0] != '_') || (source[1] != 'D') || (!xisdigit(source[2])) + || (source[2] == '0')) + { + /* FIXME might be mangled with 'D' but hasn't 'D' linkage + * samples: + * _aaApply10treewalkerFPS3aaA3aaAZi + * _aaKeys9_aaKeys_xFPS3aaA3aaAZv + */ + /* FIXME handle special cases: + * _init__D1b11_staticCtorFZv3Al + * _Class__D1b11_staticCtorFZv3Ali + * _vtbl__D1b11_staticCtorFZv3Ali + * _modctor_1b + * _assert_1b + */ + return NULL; + } + else + source += 2; + + dest = new_string(); + + source = next_type(dest, source, 0); + + while (source && source[0]) + { + /* nested symbols */ + nested = new_string(); + append_c(dest, '.'); + source = next_type(nested, source, 0); + append_n(dest, nested->str, nested->used); + xfree(nested->str); + xfree(nested); + } + + back = xstrndup(dest->str, dest->used+1); + xfree(dest->str); + xfree(dest); + + return back; +} diff --exclude=CVS -urN current/gdb/demangle_d/parser.h current-demangle_d/gdb/demangle_d/parser.h --- current/gdb/demangle_d/parser.h 1970-01-01 01:00:00.000000000 +0100 +++ current-demangle_d/gdb/demangle_d/parser.h 2006-04-22 23:47:12.000000000 +0200 @@ -0,0 +1,21 @@ +#ifndef DEMANGLE_D_PARSER_H +#define DEMANGLE_D_PARSER_H 1 + +#include "config.h" +#include "string.h" + +#define next_type DD_(next_type) +#define interprete_template DD_(interprete_template) +#define parse_real DD_(parse_real) +#define parse_function DD_(parse_function) +#define demangle_d DD_(demangle_d) + +char* next_type(string_t dest, char* raw, int is_nested); + +void interprete_template(string_t dest, char* raw); + +char* parse_real(string_t dest, char* raw); + +char* parse_function(string_t dest, char* raw, char* name, int is_nested); + +#endif /* DEMANGLE_D_PARSER_H */ diff --exclude=CVS -urN current/gdb/demangle_d/README current-demangle_d/gdb/demangle_d/README --- current/gdb/demangle_d/README 1970-01-01 01:00:00.000000000 +0100 +++ current-demangle_d/gdb/demangle_d/README 2006-04-23 00:36:10.000000000 +0200 @@ -0,0 +1,65 @@ + pluggable D de-mangler +======================= + +Author: + Thomas Kuehne <thomas@kuehne.cn> + +License: + GPL with linking exception (see license.txt) + + +Usage: stand alone +--------------------- + +1) compile: + cc -DDEMANGLE_D_STANDALONE -o demangle_d demangle.c + +2) run: + ./demangle_d _D3std3utf6toUTF8FG4awZAa _D3std6string7sformatFAaYAa + > _D3std3utf6toUTF8FG4awZAa char[] std.utf.toUTF8(char[4], dchar) + > _D3std6string7sformatFAaYAa char[] std.string.sformat(char[], ...) + + +Usage: plugin +--------------------- + +gdb: - ) +valgrind: - ) + +1) adapt config.h to your system + +2) include demangle.c in your build system + +3) demangle: + #include "demangle.h" + + char* mangled; + char* demangled; + + mangled = "_D1b5outerFeZf"; + demangled = DD_(demangle_d)(mangled); + + // ... process demangled ... + + if(demangled){ + free(demangled); + } + +optional: + adapt the DD_(str) macro in "demangle.h" to resolve potential + name clashes in your object code + + +TODO +--------------------- + + * better output for symbols in nested types: + _D1a11_staticCtorFZv1A11_staticCtorFZv5innerFHfeZHia + + * handle "special" names: + _init__D1b11_staticCtorFZv3Al + _Class__D1b11_staticCtorFZv3Ali + _vtbl__D1b11_staticCtorFZv3Ali + _modctor_1b + _assert_1b + diff --exclude=CVS -urN current/gdb/demangle_d/string.c current-demangle_d/gdb/demangle_d/string.c --- current/gdb/demangle_d/string.c 1970-01-01 01:00:00.000000000 +0100 +++ current-demangle_d/gdb/demangle_d/string.c 2006-04-23 01:14:44.000000000 +0200 @@ -0,0 +1,142 @@ +/* + demangle_d - pluggable D de-mangler + Copyright (C) 2006 Thomas Kuehne <thomas@kuehne.cn> + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + As a special exception, the copyright holders of this library give you + permission to link this library with independent modules to produce an + executable, regardless of the license terms of these independent modules, + and to copy and distribute the resulting executable under terms of your + choice, provided that you also meet, for each linked independent module, + the terms and conditions of the license of that module. An independent + module is a module which is not derived from or based on this library. If + you modify this library, you may extend this exception to your version of + the library, but you are not obligated to do so. If you do not wish to do + so, delete this exception statement from your version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ + +/* This file provieds functions for creating and modifing dynamic sized + strings. */ + +#include "config.h" +#include "string.h" +#include "util.h" + +/* Create and initialize a new string. */ +string_t +new_string(void) +{ + string_t str = xmalloc(sizeof(string_t)); + str->used = 0; + str->len = 128; + str->str = xmalloc(str->len); + str->str[0] = '\x00'; + return str; +} + +/* Append len bytes from source string to dest string. */ +void +append_n(dest, source, len) + string_t dest; const char* source; size_t len; +{ + size_t new_len; + new_len = dest->used + len + 1; + if (new_len > dest->len) + { + dest->len = new_len + (new_len >> 1); + dest->str = xrealloc(dest->str, dest->len); + } + xmemcpy(dest->str + dest->used, source, len); + dest->used += len; + dest->str[dest->used] = '\x00'; +} + +/* Append source char to dest string. */ +void +append_c(dest, source) + string_t dest; int source; +{ + size_t new_len; + new_len = dest->used + 2; + if (new_len > dest->len) + { + dest->len = new_len + (new_len >> 1); + dest->str = xrealloc(dest->str, dest->len); + } + dest->str[dest->used++] = (char)source; + dest->str[dest->used] = '\x00'; +} + +/* Append NULL-terminated string source to dest. */ +void +append(dest, source) + string_t dest; const char* source; +{ + append_n(dest, source, xstrlen(source)); +} + +/* Prepend len bytes from source string to dest string. */ +void +prepend_n(dest, source, len) + string_t dest; const char* source; size_t len; +{ + size_t new_len; + new_len = dest->used + len + 1; + if (new_len > dest->len) + { + dest->len = new_len + (new_len >> 1); + dest->str = xrealloc(dest->str, dest->len); + } + + if (dest->used) + xmemmove(dest->str + len, dest->str, dest->used); + + xmemcpy(dest->str, source, len); + dest->used += len; + dest->str[dest->used] = '\x00'; +} + +/* Prepend NULL-terminated string source to dest. */ +void +prepend(dest, source) + string_t dest; const char* source; +{ + prepend_n(dest, source, xstrlen(source)); +} + +/* If not nested, append len bytes from source string to dest else + prepend with space. */ +void +nestpend_n(dest, source, len, is_nested) + string_t dest; const char* source; size_t len; int is_nested; +{ + if (is_nested) + append_n(dest, source, len); + else + { + prepend(dest, " "); + prepend_n(dest, source, len); + } +} + +/* If not nested, append NULL-terminated source string to dest else + prepend with space. */ +void +nestpend(dest, source, is_nested) + string_t dest; const char* source; int is_nested; +{ + nestpend_n(dest, source, xstrlen(source), is_nested); +} + diff --exclude=CVS -urN current/gdb/demangle_d/string.h current-demangle_d/gdb/demangle_d/string.h --- current/gdb/demangle_d/string.h 1970-01-01 01:00:00.000000000 +0100 +++ current-demangle_d/gdb/demangle_d/string.h 2006-04-23 00:43:25.000000000 +0200 @@ -0,0 +1,67 @@ +#ifndef DEMANGLE_D_STRING_H +#define DEMANGLE_D_STRING_H 1 + +#include "config.h" + +#undef DEMANGLE_D_USE_LIBIBERY + +/*#ifdef DEMANGLE_D_IN_GDB + +#include "../../include/dyn-string.h" +#define DEMANGLE_D_USE_LIBIBERY 1 + +#elif defined(DEMANGLE_D_IN_VALGRIND) + +#include "../dyn-string.h" +#define DEMANGLE_D_USE_LIBIBERY 1 + +#endif*/ + +#ifdef DEMANGLE_D_USE_LIBIBERY + +#define string_t dyn_string_t +#define new_string() dyn_string(128) + +#define append_n DD_(append_n) +#define append_c dyn_string_append_char +#define append dyn_string_append_cstr + +#define prepend_n DD_(prepend_n) +#define prepend dyn_string_prepend_cstr + +#define nestpend_n DD_(nestpend_n) +#define nestpend DD_(nestpend) + +#else /* not DEMANGLE_D_USE_LIBIBERY */ + +#define string_t DD_(string_t) +#define new_string DD_(new_string) +#define append_n DD_(append_n) +#define append_c DD_(append_c) +#define append DD_(append) +#define prepend_n DD_(prepend_n) +#define prepend DD_(prepend) +#define nestpend_n DD_(nestpend_n) +#define nestpend DD_(nestpend) + +typedef struct{ + size_t used; + char* str; + size_t len; +}* string_t; + +string_t new_string(void); + +void append_c(string_t, int); +void append(string_t, const char *); +void prepend(string_t, const char *); + +#endif /* not DEMANGLE_D_USE_LIBIBERY */ + +void append_n(string_t, const char *, size_t); +void prepend_n(string_t, const char *, size_t); + +void nestpend_n(string_t, const char *, size_t, int); +void nestpend(string_t, const char*, int); + +#endif /* DEMANGLE_D_STRING_H */ diff --exclude=CVS -urN current/gdb/demangle_d/util.c current-demangle_d/gdb/demangle_d/util.c --- current/gdb/demangle_d/util.c 1970-01-01 01:00:00.000000000 +0100 +++ current-demangle_d/gdb/demangle_d/util.c 2006-04-23 00:08:43.000000000 +0200 @@ -0,0 +1,153 @@ +/* + demangle_d - pluggable D de-mangler + Copyright (C) 2006 Thomas Kuehne <thomas@kuehne.cn> + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + As a special exception, the copyright holders of this library give you + permission to link this library with independent modules to produce an + executable, regardless of the license terms of these independent modules, + and to copy and distribute the resulting executable under terms of your + choice, provided that you also meet, for each linked independent module, + the terms and conditions of the license of that module. An independent + module is a module which is not derived from or based on this library. If + you modify this library, you may extend this exception to your version of + the library, but you are not obligated to do so. If you do not wish to do + so, delete this exception statement from your version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ + +/* This file contains configuration dependent memory management helpers. */ + +#include "util.h" + +#ifdef DEMANGLE_D_REQUIRE_strndup +/* Copy n first bytes into a newly allocated buffer. */ +char* +DD_(strndup)(source, n) + const char* source; size_t n; +{ + char* dest; + dest = xmalloc(n+1); + xmemcpy(dest, source, n); + dest[n] = '\x00'; + return dest; +} +#endif + +#ifdef DEMANGLE_D_REQUIRE_memmove +/* Copy n bytes from memory area src to memory area dest. */ +void * DD_(memmove)(dest, src, n) + void *dest; const void *src; size_t n; +{ + void* tmp; + char* a; + const char* b; + + a = (char*) dest; + b = (const char*) src; + + if (((a < b) && (a + n < b)) || (((b < a) && (b + n < a)))) + return xmemcpy(dest, src, n); + else + { + tmp = xmalloc(n); + xmemcpy(tmp, src, n); + xmemcpy(dest, tmp, n); + xfree(tmp); + return dest; + } +} +#endif + + +#ifdef DEMANGLE_D_REQUIRE_strtol_10 +/* Convert the beginning of string src to an integer using base 10. + If endptr is not NULL, store the address of the first invalid character in + *endptr. */ +long int +DD_(strtol_10)(src, endptr) + char* src; char** endptr; +{ + long int value; + int sign; + + if (src[0] == '-') + { + sign = -1; + src++; + } + else if(src[0] == '+') + { + sign = 1; + src++; + } + else + sign = 1; + + value = 0; + + while (xisdigit(src[0])) + { + value = (value * 10) + (src[0] - '0'); + src++; + } + + if (endptr) + *endptr = src; + + return sign * value; +} +#endif + +#ifdef DEMANGLE_D_REQUIRE_malloc +/* Allocate n bytes and returns a pointer to the allocated memory. */ +void* +DD_(malloc)(n) + size_t n; +{ + void* ptr; + ptr = malloc(n); + if (!ptr) + DD_(error)(NULL); + return ptr; +} +#endif + +#ifdef DEMANGLE_D_REQUIRE_realloc +/* Changes the size of the memory block pointed to by ptr to len bytes. */ +void* +DD_(realloc)(ptr, len) + void* ptr; size_t len; +{ + ptr = realloc(ptr, len); + if (!ptr) + DD_(error)(NULL); + return ptr; +} +#endif + +#ifdef DEMANGLE_D_REQUIRE_error +/* Print error message and abort. If message is null, print the last + encountered system error and abort. */ +void +DD_(error)(message) + const char* message; +{ + if (message) + xfprintf(stderr, message); + else + xperror("demangle_d"); + xabort(); +} +#endif diff --exclude=CVS -urN current/gdb/demangle_d/util.h current-demangle_d/gdb/demangle_d/util.h --- current/gdb/demangle_d/util.h 1970-01-01 01:00:00.000000000 +0100 +++ current-demangle_d/gdb/demangle_d/util.h 2006-04-23 00:53:52.000000000 +0200 @@ -0,0 +1,99 @@ +#ifndef DEMANGLE_D_UTIL_H +#define DEMANGLE_D_UTIL_H 1 + +#include "config.h" + +#undef DEMANGLE_D_REQUIRE_strndup +#undef DEMANGLE_D_REQUIRE_strtol_10 +#undef DEMANGLE_D_REQUIRE_malloc +#undef DEMANGLE_D_REQUIRE_realloc +#undef DEMANGLE_D_REQUIRE_memmove +#undef DEMANGLE_D_REQUIRE_error + +#ifdef DEMANGLE_D_IN_VALGRIND +/* gdb - http://www.gnu.org/software/gdb/ */ + +#define xstrndup DD_(strndup) +#define DEMANGLE_D_REQUIRE_strndup 1 +#define xstrtol_10 DD_(strtol_10) +#define DEMANGLE_D_REQUIRE_strtol_10 1 +#define xmalloc VG_(malloc) +#define xrealloc VG_(realloc) +#define xmemmove DD_(memmove) +#define DEMANGLE_D_REQUIRE_memmove 1 +#define xfree VG_(free) +#define xmemcpy VG_(memcpy) + +#elif defined(DEMANGLE_D_IN_GDB) /* not DEMANGLE_D_IN_VALGRIND */ +/* gdb - http://www.gnu.org/software/gdb/ */ + +#include "../libiberty.h" +/* xmalloc */ +/* xrealloc */ + +#include "../defs.h" +/* xfree */ + +#include <string.h> +#define xmemcpy memcpy +#define xmemmove memmove +#define xstrndup strndup +#define xstrtol_10(n,p) strtol((n), (p), 10) + +#else /* not DEMANGLE_D_IN_VALGRIND && not DEMANGLE_D_IN_GDB */ +/* 'normal' libc */ + +#include <stdlib.h> +#include <string.h> + +#if defined(__USE_GNU) || defined(_GNU_SOURCE) +#define xstrndup strndup +#else +#define xstrndup DD_(strndup) +#define DEMANGLE_D_REQUIRE_strndup 1 +#endif + +#define xstrtol_10(n,p) strtol((n), (p), 10) + +#define xmalloc DD_(malloc) +#define DEMANGLE_D_REQUIRE_malloc 1 +#define xrealloc DD_(realloc) +#define DEMANGLE_D_REQUIRE_realloc 1 +#define xmemmove memmove +#define xfree free +#define xmemcpy memcpy + +#ifdef DEMANGLE_D_STANDALONE +#define DEMANGLE_D_REQUIRE_error 1 +#define xprintf printf +#define xperror perror +#define xfprintf fprintf +#endif + +#endif /* not DEMANGLE_D_IN_VALGRIND && not DEMANGLE_D_IN_GDB */ + +#ifdef DEMANGLE_D_REQUIRE_strndup +char* DD_(strndup)(const char*, size_t); +#endif + +#ifdef DEMANGLE_D_REQUIRE_strtol_10 +long int DD_(strtol_10)(char*, char**); +#endif + +#ifdef DEMANGLE_D_REQUIRE_malloc +void* DD_(malloc)(size_t); +#endif + +#ifdef DEMANGLE_D_REQUIRE_realloc +void* DD_(realloc)(void*, size_t); +#endif + +#ifdef DEMANGLE_D_REQUIRE_memmove +void * DD_(memmove)(void*, const void *, size_t ); +#endif + +#ifdef DEMANGLE_D_REQUIRE_error +void DD_(error)(const char*); +#endif + +#endif /* DEMANGLE_D_UTIL_H */ diff --exclude=CVS -urN current/gdb/demangle_d/version current-demangle_d/gdb/demangle_d/version --- current/gdb/demangle_d/version 1970-01-01 01:00:00.000000000 +0100 +++ current-demangle_d/gdb/demangle_d/version 2006-04-23 00:39:00.000000000 +0200 @@ -0,0 +1 @@ +$Date$ diff --exclude=CVS -urN current/gdb/d-lang.c current-demangle_d/gdb/d-lang.c --- current/gdb/d-lang.c 1970-01-01 01:00:00.000000000 +0100 +++ current-demangle_d/gdb/d-lang.c 2006-04-23 00:53:10.000000000 +0200 @@ -0,0 +1,34 @@ +/* C language support routines for GDB, the GNU debugger. + Copyright 2006 + Free Software Foundation, Inc. + + This file is part of GDB. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place - Suite 330, + Boston, MA 02111-1307, USA. */ + +#include "defs.h" +#include "symtab.h" + +#define DEMANGLE_D_IN_GDB 1 +#include "demangle_d/demangle.c" + +char* d_demangle(char* symbol, int options) { + return DD_(demangle_d)(symbol); +} + +char* d_sym_demangle(const struct general_symbol_info *gsymbol) { + return DD_(demangle_d)(gsymbol->name); +} diff --exclude=CVS -urN current/gdb/d-lang.h current-demangle_d/gdb/d-lang.h --- current/gdb/d-lang.h 1970-01-01 01:00:00.000000000 +0100 +++ current-demangle_d/gdb/d-lang.h 2006-04-22 18:22:35.000000000 +0200 @@ -0,0 +1,37 @@ +/* C language support definitions for GDB, the GNU debugger. + Copyright 1992, 1994, 1995, 1996, 1997, 1998, 2000, 2002 + Free Software Foundation, Inc. + + This file is part of GDB. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place - Suite 330, + Boston, MA 02111-1307, USA. */ + + +#if !defined (D_LANG_H) +#define D_LANG_H 1 + +#include "symtab.h" + +/***************************** + D Language stuff +******************************/ + +char* d_demangle(const char* mangled, int options); + +char* d_sym_demangle(const struct general_symbol_info *gsymbol); + + +#endif /* !defined (D_LANG_H) */ diff --exclude=CVS -urN current/gdb/dwarf2read.c current-demangle_d/gdb/dwarf2read.c --- current/gdb/dwarf2read.c 2006-04-22 19:12:36.000000000 +0200 +++ current-demangle_d/gdb/dwarf2read.c 2006-04-22 18:22:35.000000000 +0200 @@ -6153,6 +6153,9 @@ case DW_LANG_C_plus_plus: cu->language = language_cplus; break; + case DW_LANG_D: + cu->language = language_d; + break; case DW_LANG_Fortran77: case DW_LANG_Fortran90: case DW_LANG_Fortran95: @@ -6631,7 +6634,7 @@ file = read_unsigned_leb128 (abfd, line_ptr, &bytes_read); line_ptr += bytes_read; fe = &lh->file_names[file - 1]; - if (fe->dir_index) + if (fe->dir_index && lh->include_dirs != NULL) dir = lh->include_dirs[fe->dir_index - 1]; if (!decode_for_pst_p) diff --exclude=CVS -urN current/gdb/language.c current-demangle_d/gdb/language.c --- current/gdb/language.c 2005-12-17 23:34:01.000000000 +0100 +++ current-demangle_d/gdb/language.c 2006-04-22 18:22:35.000000000 +0200 @@ -539,6 +539,7 @@ { case language_c: case language_cplus: + case language_d: case language_objc: if (TYPE_CODE (t1) == TYPE_CODE_FLT) return TYPE_CODE (t2) == TYPE_CODE_FLT && l2 > l1 ? @@ -650,6 +651,7 @@ { case language_c: case language_cplus: + case language_d: case language_objc: return (TYPE_CODE (type) != TYPE_CODE_INT) && (TYPE_CODE (type) != TYPE_CODE_ENUM) ? 0 : 1; @@ -690,6 +692,7 @@ case language_c: case language_cplus: + case language_d: case language_objc: return (TYPE_CODE (type) == TYPE_CODE_INT) && TYPE_LENGTH (type) == sizeof (char) @@ -712,6 +715,7 @@ case language_c: case language_cplus: + case language_d: case language_objc: /* C does not have distinct string type. */ return (0); @@ -731,6 +735,7 @@ { case language_c: case language_cplus: + case language_d: case language_objc: /* Might be more cleanly handled by having a TYPE_CODE_INT_NOT_BOOL for (the deleted) CHILL and such @@ -804,6 +809,7 @@ } return builtin_type_f_logical_s2; case language_cplus: + case language_d: case language_pascal: if (current_language->la_language==language_cplus) {sym = lookup_symbol ("bool", NULL, VAR_DOMAIN, NULL, NULL);} diff --exclude=CVS -urN current/gdb/Makefile.in current-demangle_d/gdb/Makefile.in --- current/gdb/Makefile.in 2006-04-22 19:12:35.000000000 +0200 +++ current-demangle_d/gdb/Makefile.in 2006-04-22 18:24:03.000000000 +0200 @@ -518,7 +518,7 @@ c-exp.y c-lang.c c-typeprint.c c-valprint.c \ charset.c cli-out.c coffread.c coff-pe-read.c \ complaints.c completer.c corefile.c \ - cp-abi.c cp-support.c cp-namespace.c cp-valprint.c \ + cp-abi.c cp-support.c cp-namespace.c cp-valprint.c d-lang.c \ cp-name-parser.y \ dbxread.c demangle.c dictionary.c disasm.c doublest.c dummy-frame.c \ dwarfread.c dwarf2expr.c dwarf2loc.c dwarf2read.c dwarf2-frame.c \ @@ -662,6 +662,7 @@ completer_h = completer.h cp_abi_h = cp-abi.h cp_support_h = cp-support.h $(symtab_h) +d_lang_h = d-lang.h $(symtab_h) dcache_h = dcache.h defs_h = defs.h $(config_h) $(ansidecl_h) $(gdb_locale_h) $(gdb_signals_h) \ $(libiberty_h) $(bfd_h) $(ui_file_h) $(xm_h) $(nm_h) $(tm_h) \ @@ -934,7 +935,7 @@ dbxread.o coffread.o coff-pe-read.o elfread.o \ dwarfread.o dwarf2read.o mipsread.o stabsread.o corefile.o \ dwarf2expr.o dwarf2loc.o dwarf2-frame.o \ - ada-lang.o c-lang.o f-lang.o objc-lang.o \ + ada-lang.o c-lang.o d-lang.o f-lang.o objc-lang.o \ ui-out.o cli-out.o \ varobj.o wrapper.o \ jv-lang.o jv-valprint.o jv-typeprint.o \ @@ -1874,6 +1875,9 @@ c-valprint.o: c-valprint.c $(defs_h) $(gdb_string_h) $(symtab_h) \ $(gdbtypes_h) $(expression_h) $(value_h) $(valprint_h) $(language_h) \ $(c_lang_h) $(cp_abi_h) $(target_h) +d-lang.o: d-lang.c $(defs_h) $(symtab_h) $(gdbtypes_h) $(expression_h) \ + $(parser_defs_h) $(language_h) $(c_lang_h) $(valprint_h) \ + $(macroscope_h) $(gdb_assert_h) $(charset_h) $(gdb_string_h) # OBSOLETE d10v-tdep.o: d10v-tdep.c dbug-rom.o: dbug-rom.c $(defs_h) $(gdbcore_h) $(target_h) $(monitor_h) \ $(serial_h) $(regcache_h) $(m68k_tdep_h) @@ -2710,7 +2714,7 @@ $(gdb_obstack_h) $(exceptions_h) $(language_h) $(bcache_h) \ $(block_h) $(gdb_regex_h) $(gdb_stat_h) $(dictionary_h) \ $(gdb_string_h) $(readline_h) -symtab.o: symtab.c $(defs_h) $(symtab_h) $(gdbtypes_h) $(gdbcore_h) \ +symtab.o: symtab.c $(defs_h) $(d_lang_h) $(symtab_h) $(gdbtypes_h) $(gdbcore_h) \ $(frame_h) $(target_h) $(value_h) $(symfile_h) $(objfiles_h) \ $(gdbcmd_h) $(call_cmds_h) $(gdb_regex_h) $(expression_h) \ $(language_h) $(demangle_h) $(inferior_h) $(linespec_h) $(source_h) \ diff --exclude=CVS -urN current/gdb/symfile.c current-demangle_d/gdb/symfile.c --- current/gdb/symfile.c 2006-02-25 05:36:39.000000000 +0100 +++ current-demangle_d/gdb/symfile.c 2006-04-22 18:22:35.000000000 +0200 @@ -2358,6 +2358,7 @@ filename_language_table = xmalloc (fl_table_size * sizeof (*filename_language_table)); add_filename_language (".c", language_c); + add_filename_language (".d", language_d); add_filename_language (".C", language_cplus); add_filename_language (".cc", language_cplus); add_filename_language (".cp", language_cplus); diff --exclude=CVS -urN current/gdb/symtab.c current-demangle_d/gdb/symtab.c --- current/gdb/symtab.c 2005-12-17 23:34:03.000000000 +0100 +++ current-demangle_d/gdb/symtab.c 2006-04-22 18:22:35.000000000 +0200 @@ -42,6 +42,7 @@ #include "filenames.h" /* for FILENAME_CMP */ #include "objc-lang.h" #include "ada-lang.h" +#include "d-lang.h" #include "hashtab.h" @@ -405,6 +406,7 @@ { gsymbol->language = language; if (gsymbol->language == language_cplus + || gsymbol->language == language_d || gsymbol->language == language_java || gsymbol->language == language_objc) { @@ -451,6 +453,15 @@ if (gsymbol->language == language_unknown) gsymbol->language = language_auto; + if (gsymbol->language == language_d + || gsymbol->language == language_auto) { + demangled = d_demangle(mangled, 0); + if (demangled != NULL) { + gsymbol->language = language_d; + return demangled; + } + } + if (gsymbol->language == language_objc || gsymbol->language == language_auto) { @@ -610,6 +621,7 @@ demangled = symbol_find_demangled_name (gsymbol, mangled); if (gsymbol->language == language_cplus + || gsymbol->language == language_d || gsymbol->language == language_java || gsymbol->language == language_objc) { @@ -639,6 +651,7 @@ switch (gsymbol->language) { case language_cplus: + case language_d: case language_java: case language_objc: if (gsymbol->language_specific.cplus_specific.demangled_name != NULL) @@ -664,6 +677,7 @@ switch (gsymbol->language) { case language_cplus: + case language_d: case language_java: case language_objc: if (gsymbol->language_specific.cplus_specific.demangled_name != NULL) @@ -1023,7 +1037,7 @@ modified_name = name; - /* If we are using C++ or Java, demangle the name before doing a lookup, so + /* If we are using C++, D, or Java, demangle the name before doing a lookup, so we can always binary search. */ if (current_language->la_language == language_cplus) { @@ -1035,6 +1049,16 @@ needtofreename = 1; } } + else if (current_language->la_language == language_d) + { + demangled_name = d_demangle (name, 0); + if (demangled_name) + { + mangled_name = name; + modified_name = demangled_name; + needtofreename = 1; + } + } else if (current_language->la_language == language_java) { demangled_name = cplus_demangle (name, Dateien current/gdb/testsuite/gdb.asm/asm-source und current-demangle_d/gdb/testsuite/gdb.asm/asm-source sind verschieden. Dateien current/gdb/testsuite/gdb.base/advance und current-demangle_d/gdb/testsuite/gdb.base/advance sind verschieden. Dateien current/gdb/testsuite/gdb.base/annota3 und current-demangle_d/gdb/testsuite/gdb.base/annota3 sind verschieden. Dateien current/gdb/testsuite/gdb.base/args und current-demangle_d/gdb/testsuite/gdb.base/args sind verschieden. Dateien current/gdb/testsuite/gdb.base/arrayidx und current-demangle_d/gdb/testsuite/gdb.base/arrayidx sind verschieden. Dateien current/gdb/testsuite/gdb.base/async und current-demangle_d/gdb/testsuite/gdb.base/async sind verschieden. Dateien current/gdb/testsuite/gdb.base/attach und current-demangle_d/gdb/testsuite/gdb.base/attach sind verschieden. Dateien current/gdb/testsuite/gdb.base/attach2 und current-demangle_d/gdb/testsuite/gdb.base/attach2 sind verschieden. Dateien current/gdb/testsuite/gdb.base/auxv und current-demangle_d/gdb/testsuite/gdb.base/auxv sind verschieden. Dateien current/gdb/testsuite/gdb.base/auxv.gcore und current-demangle_d/gdb/testsuite/gdb.base/auxv.gcore sind verschieden. Dateien current/gdb/testsuite/gdb.base/bang! und current-demangle_d/gdb/testsuite/gdb.base/bang! sind verschieden. Dateien current/gdb/testsuite/gdb.base/bfp-test und current-demangle_d/gdb/testsuite/gdb.base/bfp-test sind verschieden. Dateien current/gdb/testsuite/gdb.base/bigcore und current-demangle_d/gdb/testsuite/gdb.base/bigcore sind verschieden. Dateien current/gdb/testsuite/gdb.base/bigcore.corefile und current-demangle_d/gdb/testsuite/gdb.base/bigcore.corefile sind verschieden. Dateien current/gdb/testsuite/gdb.base/bitfields2 und current-demangle_d/gdb/testsuite/gdb.base/bitfields2 sind verschieden. Dateien current/gdb/testsuite/gdb.base/breako2 und current-demangle_d/gdb/testsuite/gdb.base/breako2 sind verschieden. Dateien current/gdb/testsuite/gdb.base/call-sc-tc und current-demangle_d/gdb/testsuite/gdb.base/call-sc-tc sind verschieden. Dateien current/gdb/testsuite/gdb.base/call-sc-td und current-demangle_d/gdb/testsuite/gdb.base/call-sc-td sind verschieden. Dateien current/gdb/testsuite/gdb.base/call-sc-tf und current-demangle_d/gdb/testsuite/gdb.base/call-sc-tf sind verschieden. Dateien current/gdb/testsuite/gdb.base/call-sc-ti und current-demangle_d/gdb/testsuite/gdb.base/call-sc-ti sind verschieden. Dateien current/gdb/testsuite/gdb.base/call-sc-tl und current-demangle_d/gdb/testsuite/gdb.base/call-sc-tl sind verschieden. Dateien current/gdb/testsuite/gdb.base/call-sc-tll und current-demangle_d/gdb/testsuite/gdb.base/call-sc-tll sind verschieden. Dateien current/gdb/testsuite/gdb.base/call-sc-ts und current-demangle_d/gdb/testsuite/gdb.base/call-sc-ts sind verschieden. ^ permalink raw reply [flat|nested] 20+ messages in thread
* Re: D Symbol Demangling 2006-04-22 22:52 ` Thomas Kühne @ 2006-04-24 17:21 ` Jim Blandy 2006-04-24 20:53 ` Daniel Jacobowitz 0 siblings, 1 reply; 20+ messages in thread From: Jim Blandy @ 2006-04-24 17:21 UTC (permalink / raw) To: Thomas Kühne; +Cc: gdb-patches The other demanglers are all in libiberty; shouldn't this one go there, too? ^ permalink raw reply [flat|nested] 20+ messages in thread
* Re: D Symbol Demangling 2006-04-24 17:21 ` Jim Blandy @ 2006-04-24 20:53 ` Daniel Jacobowitz 2006-04-25 3:35 ` Eli Zaretskii 0 siblings, 1 reply; 20+ messages in thread From: Daniel Jacobowitz @ 2006-04-24 20:53 UTC (permalink / raw) To: Thomas Kühne, Jim Blandy; +Cc: gdb-patches On Mon, Apr 24, 2006 at 10:21:15AM -0700, Jim Blandy wrote: > The other demanglers are all in libiberty; shouldn't this one go there, too? Well, the old and new C++ demanglers are in libiberty, and the "Java demangler" is part of that. But there's an Ada demangler in GDB already. On Sat, Apr 22, 2006 at 12:24:24AM +0200, Thomas Kühne wrote: > I've no problem with assigning the copyright of the demangler to the FSF if > the license issue - as you noted, using more than one license might cause > problems - can be solved. > > The GPL with linking exception would seem to be the best solution for all. > (taken from /usr/portage/licenses/GPL-2-with-linking-exception) > > | As a special exception, the copyright holders of this library give you > | permission to link this library with independent modules to produce an > | executable, regardless of the license terms of these independent modules, > | and to copy and distribute the resulting executable under terms of your > | choice, provided that you also meet, for each linked independent module, > | the terms and conditions of the license of that module. An independent > | module is a module which is not derived from or based on this library. If > | you modify this library, you may extend this exception to your version of > | the library, but you are not obligated to do so. If you do not wish to do > | so, delete this exception statement from your version. > > <followed by the GPL text> I don't know what permissions we need to generate new code under this license; does anyone else know? Do we need to check it with the FSF? They're usually reasonable about such things, but obviously they prefer the stronger GPL when possible. > > And, no offense, but the DD_() thing is horribly ugly and doesn't seem > > to serve any purpose here. Is that for reusing the demangler > > elsewhere? > > Yes it's ugly and not the kind of code I normally write. > The problem: the demangler is currently used with GDB, Valgrind and 3 > in-house tools - thus name and symbol clashes are a real problem. What's the actual interface to the demangler? All I see is a single function: char* DD_(demangle_d)(char*); If that's the case, it ought to be possible to make everything else static by careful use of #include, and then presto - no name clashes. -- Daniel Jacobowitz CodeSourcery ^ permalink raw reply [flat|nested] 20+ messages in thread
* Re: D Symbol Demangling 2006-04-24 20:53 ` Daniel Jacobowitz @ 2006-04-25 3:35 ` Eli Zaretskii 2006-04-25 14:13 ` DJ Delorie 0 siblings, 1 reply; 20+ messages in thread From: Eli Zaretskii @ 2006-04-25 3:35 UTC (permalink / raw) To: Thomas Kühne, dj; +Cc: gdb-patches, Jim Blandy [-- Warning: decoded text below may be mangled, UTF-8 assumed --] [-- Attachment #1: Type: text/plain, Size: 2112 bytes --] > Date: Mon, 24 Apr 2006 16:53:28 -0400 > From: Daniel Jacobowitz <drow@false.org> > Cc: gdb-patches@sources.redhat.com > > On Sat, Apr 22, 2006 at 12:24:24AM +0200, Thomas Kühne wrote: > > I've no problem with assigning the copyright of the demangler to the FSF if > > the license issue - as you noted, using more than one license might cause > > problems - can be solved. > > > > The GPL with linking exception would seem to be the best solution for all. > > (taken from /usr/portage/licenses/GPL-2-with-linking-exception) > > > > | As a special exception, the copyright holders of this library give you > > | permission to link this library with independent modules to produce an > > | executable, regardless of the license terms of these independent modules, > > | and to copy and distribute the resulting executable under terms of your > > | choice, provided that you also meet, for each linked independent module, > > | the terms and conditions of the license of that module. An independent > > | module is a module which is not derived from or based on this library. If > > | you modify this library, you may extend this exception to your version of > > | the library, but you are not obligated to do so. If you do not wish to do > > | so, delete this exception statement from your version. > > > > <followed by the GPL text> > > I don't know what permissions we need to generate new code under this > license; does anyone else know? Do we need to check it with the FSF? > They're usually reasonable about such things, but obviously they prefer > the stronger GPL when possible. In general, I think that exceptions like that are okay as long as they don't interfere with distribution under the GPL. The copyright holder can decide to release the software under any license she chooses, and it should be okay with the FSF as long as the license doesn't prevent the freedoms required by the GPL. But it's a good idea to check with the FSF nonetheless. Perhaps DJ could help with advice: the DJGPP project's license is the GPL with an exception, so DJ probably already ``been there, done that''. ^ permalink raw reply [flat|nested] 20+ messages in thread
* Re: D Symbol Demangling 2006-04-25 3:35 ` Eli Zaretskii @ 2006-04-25 14:13 ` DJ Delorie 2006-04-29 7:23 ` Thomas Kühne 0 siblings, 1 reply; 20+ messages in thread From: DJ Delorie @ 2006-04-25 14:13 UTC (permalink / raw) To: eliz; +Cc: thomas, gdb-patches, jimb > Perhaps DJ could help with advice: the DJGPP project's license is > the GPL with an exception, so DJ probably already ``been there, done > that''. The rules are as follows: The author of the new file may choose one or more licenses when it's contributed. Ideally, the author would choose the GPL+exception, or whatever is most desirable for where they're contributing it to. To change the license *after* it's contributed, requires the FSF to agree to the change (as they're now the de facto copyright holders). The FSF prefers the GPL when possible, however, files which would be parts of libraries which implement standards (such as libstdc++-v3) really can't be just GPL because you wouldn't be able to use gcc to compile a conforming program without that program being GPL'd. Non-standard libraries are a different story, of course. Note that the exception the FSF usually permits is not the "independent module" one, but the "built with gcc" one. They are not particularly interested in promoting other vendors' compilers. The special exception noted in the "portage" snippet is really no different than the LGPL, only it's even weaker. Even *I* wouldn't recommend that one for FSF contributions, although it's very similar to DJGPP's license. Note: DJGPP's library license is: pre-built libraries I distribute are free to use for proprietary applications, sources I distribute (and thus rebuilt libraries) are strictly LGPL. We normally make exceptions for re-built libraries where the patches are submitted back to the DJGPP project; the goal is to never have a library out there that you can't rebuild *somehow*. ^ permalink raw reply [flat|nested] 20+ messages in thread
* Re: D Symbol Demangling 2006-04-25 14:13 ` DJ Delorie @ 2006-04-29 7:23 ` Thomas Kühne 2006-04-29 16:47 ` DJ Delorie 0 siblings, 1 reply; 20+ messages in thread From: Thomas Kühne @ 2006-04-29 7:23 UTC (permalink / raw) To: gdb-patches DJ Delorie wrote: >>Perhaps DJ could help with advice: the DJGPP project's license is >>the GPL with an exception, so DJ probably already ``been there, done >>that''. > Note that the exception the FSF usually permits is not the > "independent module" one, but the "built with gcc" one. They are not > particularly interested in promoting other vendors' compilers. The > special exception noted in the "portage" snippet is really no > different than the LGPL, only it's even weaker. Even *I* wouldn't > recommend that one for FSF contributions, although it's very similar > to DJGPP's license. The reason behind the "independent module" exception: There are development tools specially developed for D that don't support languages other than D. If the tool uses the demangler the complete tool would have to be licensed under the GPL. Changing the demangler's license to LGPL doesn't significantly change the situation. Thomas ^ permalink raw reply [flat|nested] 20+ messages in thread
* Re: D Symbol Demangling 2006-04-29 7:23 ` Thomas Kühne @ 2006-04-29 16:47 ` DJ Delorie 0 siblings, 0 replies; 20+ messages in thread From: DJ Delorie @ 2006-04-29 16:47 UTC (permalink / raw) To: thomas; +Cc: gdb-patches > The reason behind the "independent module" exception: > There are development tools specially developed for D that don't > support languages other than D. > > If the tool uses the demangler the complete tool would have to be > licensed under the GPL. Changing the demangler's license to LGPL > doesn't significantly change the situation. This really belongs on gnu.misc.discuss, but I'll add one last comment: The FSF is not interested in supporting other people's non-GPL software (in fact, it's very much against supporting proprietary software). So, if you want your demangler to be licensed other than GPL or the usual exceptions, you'd better license it that way before you contribute it, else the FSF will never agree to re-license it the way you want. There are modules in libiberty that use the advert-less BSD license. Thus, that would probably be an acceptable license. ^ permalink raw reply [flat|nested] 20+ messages in thread
end of thread, other threads:[~2006-04-29 15:18 UTC | newest]
Thread overview: 20+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-04-04 2:37 D Symbol Demangling John Demme
2005-04-04 18:21 ` Michael Snyder
2005-04-04 20:44 ` John Demme
2005-04-04 20:47 ` Daniel Jacobowitz
2005-04-04 21:49 ` Michael Snyder
2005-04-04 22:39 ` John Demme
[not found] ` <1112654359.14153.50.camel@localhost.localdomain>
[not found] ` <4251CF00.5080002@redhat.com>
2005-04-08 16:47 ` John Demme
2005-04-08 16:52 ` Daniel Jacobowitz
2005-04-08 20:50 ` John Demme
2005-04-08 21:11 ` Daniel Jacobowitz
2006-04-19 11:18 Thomas Kuehne
2006-04-20 13:20 ` Daniel Jacobowitz
2006-04-21 21:25 ` Thomas Kühne
2006-04-22 22:52 ` Thomas Kühne
2006-04-24 17:21 ` Jim Blandy
2006-04-24 20:53 ` Daniel Jacobowitz
2006-04-25 3:35 ` Eli Zaretskii
2006-04-25 14:13 ` DJ Delorie
2006-04-29 7:23 ` Thomas Kühne
2006-04-29 16:47 ` DJ Delorie
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox