Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
* D language support
@ 2009-12-23 23:57 Mihail Zenkov
  2009-12-30 12:56 ` Joel Brobecker
  0 siblings, 1 reply; 39+ messages in thread
From: Mihail Zenkov @ 2009-12-23 23:57 UTC (permalink / raw)
  To: gdb-patches

[-- Attachment #1: Type: text/plain, Size: 100 bytes --]

Hi,
 I receive confirmation from FSF - assignment process completed. Patch
updated for current git.

[-- Attachment #2: gdb-091223-d.patch --]
[-- Type: application/octet-stream, Size: 23292 bytes --]

diff --git a/gdb/Makefile.in b/gdb/Makefile.in
index 348d853..768adfe 100644
--- a/gdb/Makefile.in
+++ b/gdb/Makefile.in
@@ -641,6 +641,7 @@ SFILES = ada-exp.y ada-lang.c ada-typeprint.c ada-valprint.c ada-tasks.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 \
+	d-lang.c d-valprint.c \
 	cp-name-parser.y \
 	dbxread.c demangle.c dictionary.c disasm.c doublest.c dummy-frame.c \
 	dwarf2expr.c dwarf2loc.c dwarf2read.c dwarf2-frame.c \
@@ -809,7 +810,7 @@ COMMON_OBS = $(DEPFILES) $(CONFIG_OBS) $(YYOBJ) \
 	dbxread.o coffread.o coff-pe-read.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 \
 	ada-tasks.o \
 	ui-out.o cli-out.o \
 	varobj.o vec.o wrapper.o \
@@ -819,7 +820,7 @@ COMMON_OBS = $(DEPFILES) $(CONFIG_OBS) $(YYOBJ) \
 	sentinel-frame.o \
 	complaints.o typeprint.o \
 	ada-typeprint.o c-typeprint.o f-typeprint.o m2-typeprint.o \
-	ada-valprint.o c-valprint.o cp-valprint.o f-valprint.o m2-valprint.o \
+	ada-valprint.o c-valprint.o cp-valprint.o d-valprint.o f-valprint.o m2-valprint.o \
 	serial.o mdebugread.o top.o utils.o \
 	ui-file.o \
 	user-regs.o \
diff --git a/gdb/c-lang.c b/gdb/c-lang.c
index 405c489..4eb1bea 100644
--- a/gdb/c-lang.c
+++ b/gdb/c-lang.c
@@ -25,6 +25,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"
@@ -1380,10 +1381,50 @@ const struct language_defn minimal_language_defn =
   LANG_MAGIC
 };
 
+const struct language_defn d_language_defn =
+{
+  "d",				/* Language name */
+  language_d,
+  range_check_off,
+  type_check_off,
+  case_sensitive_on,
+  array_row_major,
+  macro_expansion_c,
+  &exp_descriptor_c,
+  c_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_print_type,			/* Print a type using appropriate syntax */
+  c_print_typedef,              /* Print a typedef using appropriate syntax */
+  d_val_print,			/* Print a value using appropriate syntax */
+  c_value_print,		/* Print a top-level value */
+  NULL,				/* Language specific skip_trampoline */
+  "this",			/* name_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 */
+  default_word_break_characters,
+  default_make_symbol_completion_list,
+  c_language_arch_info,
+  default_print_array_index,
+  default_pass_by_reference,
+  c_get_string,
+  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 --git a/gdb/d-lang.c b/gdb/d-lang.c
new file mode 100644
index 0000000..58ddcd3
--- /dev/null
+++ b/gdb/d-lang.c
@@ -0,0 +1,241 @@
+
+/* C language support routines for GDB, the GNU debugger.
+   Copyright 1992, 1993, 1994, 1995, 1996, 1998, 1999, 2000, 2002, 2003, 2004
+   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 "language.h"
+#include "d-lang.h"
+#include "c-lang.h"
+#include "gdb_string.h"
+
+#include <ctype.h>
+
+typedef struct {
+  size_t len;
+  char* str;
+  char* pos;
+} String;
+
+static size_t str_left(String* str) {
+  return (str->len - (str->pos - str->str));
+}
+
+static void str_resize(String* str, size_t new_size) {
+  int pos = str->pos - str->str;
+  if (new_size == 0)
+    new_size = strlen(str->str) + 1;
+  str->str = xrealloc(str->str, new_size);
+  str->len = new_size;
+  str->pos = str->str + pos;
+}
+
+static void append_len(String* str, char* src, size_t i) {
+  size_t amnt = str_left(str);
+  if (i > amnt) {
+    str_resize(str, str->len + i + 20);
+  }
+  memcpy(str->pos, src, i);
+  str->pos += i;
+}
+
+static void append(String* str, char* src) {
+  append_len(str, src, strlen(src));
+}
+
+static int extractidentifiers(String* output, String* mangled) {
+  long i = 0;
+  while (isdigit(*mangled->pos)) {
+    i = strtol(mangled->pos, &mangled->pos, 10);
+    if (i == 0 || i == LONG_MAX || i == LONG_MIN) {
+      return -1;
+    }
+    if (strlen(mangled->pos) < i)
+      return -1;
+    append_len(output, mangled->pos, i);
+    mangled->pos += i;
+    append(output, ".");
+  }
+  if (*mangled->pos == '\0' || i == 0)
+    return -1;
+  output->pos--;
+  return 1;
+}
+
+static int extracttypeinfo(String* dest, String* id) {
+  if (*id->pos == '\0')
+    return -1;
+  // Extract the type info:
+  switch (*id->pos++) {
+    // 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* symbol_, int options) {
+  String output;
+  String mangled;
+  unsigned char isFunc = 0;
+  char* symbol;
+  //printf("%s: ", symbol);
+  if (symbol_ == NULL) {
+    //printf("NULL1\n");
+    return NULL;
+  } else if (strcmp(symbol_, "_Dmain") == 0) {
+    return strdup("D main");
+  }
+
+  symbol = xstrdup(symbol_);
+  mangled.len = strlen(symbol);
+  mangled.str = symbol;
+  mangled.pos = symbol;
+
+  output.len = 2;
+  output.str = xmalloc(output.len);
+  output.pos = output.str;
+
+  if (symbol == strstr(symbol, "_D")) {
+    mangled.pos += 2;
+    isFunc = 1;
+  } else if (symbol == strstr(symbol, "__Class_")) {
+    mangled.pos += 8;
+  } else if (symbol == strstr(symbol, "__init_")) {
+    mangled.pos += 7;
+  } else if (symbol == strstr(symbol, "__vtbl_")) {
+    mangled.pos += 7;
+  } else if (symbol == strstr(symbol, "__modctor_")) {
+    mangled.pos += 10;
+  } else if (symbol == strstr(symbol, "__moddtor_")) {
+    mangled.pos += 10;
+  } else if (symbol == strstr(symbol, "__ModuleInfo_")) {
+    mangled.pos += 13;
+  } else {
+    xfree(output.str);
+    xfree(symbol);
+    //printf("NULL2\n");
+    return NULL;
+  }
+  
+  
+  if (extractidentifiers(&output, &mangled) < 0) {
+    xfree(output.str);
+    xfree(symbol);
+    //printf("NULL3\n");
+    return NULL;
+  }
+
+
+
+  append(&output, "(");
+  if (isFunc == 1 && *mangled.pos == 'F') {
+    mangled.pos++;
+    while (*mangled.pos != '\0' && *mangled.pos != 'Z') {
+      if (isFunc == 1) {
+	isFunc++;
+      } else {
+	append(&output, ", ");
+      }
+      if (extracttypeinfo(&output, &mangled) < 0) {
+	xfree(output.str);
+    xfree(symbol);
+	return NULL;
+      }
+    }
+  }
+  append(&output, ")");
+
+  //Doesn't display the return type, but wouldn't be too hard to do.
+
+  append_len(&output, "", 1);
+  str_resize(&output, 0);
+  //printf("%s\n", output.str);
+  xfree(symbol);
+  return output.str;
+}
+
+char* d_sym_demangle(const struct general_symbol_info *gsymbol) {
+  return d_demangle(gsymbol->name, 0);
+}
diff --git a/gdb/d-lang.h b/gdb/d-lang.h
new file mode 100644
index 0000000..3404579
--- /dev/null
+++ b/gdb/d-lang.h
@@ -0,0 +1,39 @@
+/* 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);
+
+int d_val_print (struct type *type, const gdb_byte *valaddr, int embedded_offset,
+        	 CORE_ADDR address, struct ui_file *stream, int recurse,
+                 const struct value_print_options *options);
+#endif /* !defined (D_LANG_H) */
diff --git a/gdb/d-valprint.c b/gdb/d-valprint.c
new file mode 100644
index 0000000..388f183
--- /dev/null
+++ b/gdb/d-valprint.c
@@ -0,0 +1,100 @@
+/* Support for printing D values for GDB, the GNU debugger.
+
+   Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2007,
+   2008 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 3 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, see <http://www.gnu.org/licenses/>.  */
+
+#include "defs.h"
+#include "symtab.h"
+#include "gdbtypes.h"
+#include "gdbcore.h"
+#include "expression.h"
+#include "value.h"
+#include "demangle.h"
+#include "valprint.h"
+#include "language.h"
+#include "d-lang.h"
+#include "c-lang.h"
+#include "annotate.h"
+#include "gdb_string.h"
+
+static int
+dynamic_array_type (struct type *type, const gdb_byte *valaddr,
+		    int embedded_offset, CORE_ADDR address,
+		    struct ui_file *stream, int recurse,
+		    const struct value_print_options *options)
+{
+  if (TYPE_NFIELDS (type) == 2
+      && TYPE_CODE (TYPE_FIELD_TYPE (type, 0)) == TYPE_CODE_INT
+      && strcmp (TYPE_FIELD_NAME (type, 0), "length") == 0
+      && strcmp (TYPE_FIELD_NAME (type, 1), "ptr") == 0)
+    {
+      CORE_ADDR addr;
+      struct type *elttype;
+      struct type *true_type;
+      struct type *ptr_type;
+      struct type *range_type;
+      const gdb_byte *ptraddr;
+      struct value *val;
+      int length;
+
+      length = unpack_field_as_long (type, valaddr + embedded_offset, 0);
+
+      ptr_type = TYPE_FIELD_TYPE (type, 1);
+      elttype = check_typedef (TYPE_TARGET_TYPE (ptr_type));
+      addr = unpack_pointer (ptr_type, valaddr +TYPE_FIELD_BITPOS (type, 1) / 8 + embedded_offset);
+      true_type = check_typedef (elttype);
+
+      true_type = lookup_array_range_type (true_type, 0, length - 1);
+      val = value_at(true_type, addr);
+      ptraddr = value_contents(val);
+
+      val_print (true_type,
+		 ptraddr, 0,
+		 addr,
+		 stream, recurse + 1, options, current_language);
+      return 1;
+    }
+  return 0;
+}
+
+/* Print data of type TYPE located at VALADDR (within GDB), which came from
+   the inferior at address ADDRESS, onto stdio stream STREAM according to
+   OPTIONS.  The data at VALADDR is in target byte order.
+
+   If the data are a string pointer, returns the number of string characters
+   printed.  */
+
+int
+d_val_print (struct type *type, const gdb_byte *valaddr, int embedded_offset,
+             CORE_ADDR address, struct ui_file *stream, int recurse,
+             const struct value_print_options *options)
+{
+  CHECK_TYPEDEF (type);
+  switch (TYPE_CODE (type))
+    {
+    case TYPE_CODE_STRUCT:
+      if (dynamic_array_type (type, valaddr, embedded_offset, address, stream,
+	  recurse, options))
+	  break;
+    default:
+	return c_val_print (type, valaddr, embedded_offset, address, stream,
+			    recurse, options);
+    }
+
+  return 0;
+}
diff --git a/gdb/defs.h b/gdb/defs.h
index b944ffb..fe31926 100644
--- a/gdb/defs.h
+++ b/gdb/defs.h
@@ -188,6 +188,7 @@ enum language
     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 --git a/gdb/doc/gdb.texinfo b/gdb/doc/gdb.texinfo
index e880838..0167177 100644
--- a/gdb/doc/gdb.texinfo
+++ b/gdb/doc/gdb.texinfo
@@ -213,6 +213,10 @@ You can use @value{GDBN} to debug programs written in C and C@t{++}.
 For more information, see @ref{Supported Languages,,Supported Languages}.
 For more information, see @ref{C,,C and C++}.
 
+@cindex D
+Support for D is partial.  For information on D, see
+@ref{D,,D}.
+
 @cindex Modula-2
 Support for Modula-2 is partial.  For information on Modula-2, see
 @ref{Modula-2,,Modula-2}.
@@ -10414,6 +10418,9 @@ C source file
 @itemx .c++
 C@t{++} source file
 
+@item .d
+D source file
+
 @item .m
 Objective-C source file
 
@@ -10691,7 +10698,7 @@ being set automatically by @value{GDBN}.
 @node Supported Languages
 @section Supported Languages
 
-@value{GDBN} supports C, C@t{++}, Objective-C, Fortran, Java, Pascal,
+@value{GDBN} supports C, C@t{++}, D, Objective-C, Fortran, Java, Pascal,
 assembly, Modula-2, and Ada.
 @c This is false ...
 Some @value{GDBN} features may be used in expressions regardless of the
@@ -10710,6 +10717,7 @@ language reference or tutorial.
 
 @menu
 * C::                           C and C@t{++}
+* D::                           D
 * Objective-C::                 Objective-C
 * Fortran::                     Fortran
 * Pascal::                      Pascal
@@ -11247,6 +11255,14 @@ In the PowerPC architecture, @value{GDBN} provides a set of pseudo-registers
 to inspect @code{_Decimal128} values stored in floating point registers.
 See @ref{PowerPC,,PowerPC} for more details.
 
+@node D
+@subsection D
+
+@cindex D
+@value{GDBN} can be used to debug programs written in D and compiled with
+GDC, LDC or DMD. Currently @value{GDBN} supports only one D specific
+features - dynamic arrays.
+
 @node Objective-C
 @subsection Objective-C
 
diff --git a/gdb/dwarf2read.c b/gdb/dwarf2read.c
index ffeaaf2..93f8552 100644
--- a/gdb/dwarf2read.c
+++ b/gdb/dwarf2read.c
@@ -7515,6 +7515,9 @@ set_cu_language (unsigned int lang, struct dwarf2_cu *cu)
     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:
@@ -8083,7 +8086,7 @@ dwarf_decode_lines (struct line_header *lh, char *comp_dir, bfd *abfd,
                 else
                   {
                     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 --git a/gdb/language.c b/gdb/language.c
index 5dbe81c..bc6fdef 100644
--- a/gdb/language.c
+++ b/gdb/language.c
@@ -485,6 +485,7 @@ binop_result_type (struct value *v1, struct value *v2)
     {
     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 ?
@@ -596,6 +597,7 @@ integral_type (struct type *type)
     {
     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;
@@ -636,6 +638,7 @@ character_type (struct type *type)
 
     case language_c:
     case language_cplus:
+    case language_d:
     case language_objc:
       return (TYPE_CODE (type) == TYPE_CODE_INT) &&
 	TYPE_LENGTH (type) == sizeof (char)
@@ -658,6 +661,7 @@ string_type (struct type *type)
 
     case language_c:
     case language_cplus:
+    case language_d:
     case language_objc:
       /* C does not have distinct string type. */
       return (0);
@@ -677,6 +681,7 @@ boolean_type (struct type *type)
     {
     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
@@ -714,6 +719,7 @@ structured_type (struct type *type)
     {
     case language_c:
     case language_cplus:
+    case language_d:
     case language_objc:
       return (TYPE_CODE (type) == TYPE_CODE_STRUCT) ||
 	(TYPE_CODE (type) == TYPE_CODE_UNION) ||
diff --git a/gdb/symfile.c b/gdb/symfile.c
index 8f486e3..ae4bbc1 100644
--- a/gdb/symfile.c
+++ b/gdb/symfile.c
@@ -2513,6 +2513,7 @@ init_filename_language_table (void)
       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 --git a/gdb/symtab.c b/gdb/symtab.c
index 950be26..1149069 100644
--- a/gdb/symtab.c
+++ b/gdb/symtab.c
@@ -39,6 +39,7 @@
 #include "source.h"
 #include "filenames.h"		/* for FILENAME_CMP */
 #include "objc-lang.h"
+#include "d-lang.h"
 #include "ada-lang.h"
 #include "p-lang.h"
 #include "addrmap.h"
@@ -413,6 +414,7 @@ symbol_init_language_specific (struct general_symbol_info *gsymbol,
 {
   gsymbol->language = language;
   if (gsymbol->language == language_cplus
+      || gsymbol->language == language_d
       || gsymbol->language == language_java
       || gsymbol->language == language_objc)
     {
@@ -483,6 +485,15 @@ symbol_find_demangled_name (struct general_symbol_info *gsymbol,
   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)
     {
@@ -693,6 +704,7 @@ symbol_natural_name (const struct general_symbol_info *gsymbol)
   switch (gsymbol->language)
     {
     case language_cplus:
+    case language_d:
     case language_java:
     case language_objc:
       if (gsymbol->language_specific.cplus_specific.demangled_name != NULL)
@@ -718,6 +730,7 @@ symbol_demangled_name (const struct general_symbol_info *gsymbol)
   switch (gsymbol->language)
     {
     case language_cplus:
+    case language_d:
     case language_java:
     case language_objc:
       if (gsymbol->language_specific.cplus_specific.demangled_name != NULL)
@@ -1263,7 +1276,7 @@ lookup_symbol_in_language (const char *name, const struct block *block,
 
   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 (lang == language_cplus)
     {
@@ -1286,6 +1299,16 @@ lookup_symbol_in_language (const char *name, const struct block *block,
 	    }
 	}
     }
+  else if (current_language->la_language == language_d)
+    {
+      demangled_name = d_demangle (name, 0);
+      if (demangled_name)
+	{
+	  mangled_name = name;
+	  modified_name = demangled_name;
+	  make_cleanup (xfree, demangled_name);
+	}
+    }
   else if (lang == language_java)
     {
       demangled_name = cplus_demangle (name,
@@ -1732,6 +1755,7 @@ symbol_matches_domain (enum language symbol_language,
      A Java class declaration also defines a typedef for the class.
      Similarly, any Ada type declaration implicitly defines a typedef.  */
   if (symbol_language == language_cplus
+      || symbol_language == language_d
       || symbol_language == language_java
       || symbol_language == language_ada)
     {

^ permalink raw reply	[flat|nested] 39+ messages in thread
* D language support
@ 2009-08-17 23:02 Mihail Zenkov
  2009-08-18  4:18 ` Eli Zaretskii
  2009-08-18 16:39 ` Tom Tromey
  0 siblings, 2 replies; 39+ messages in thread
From: Mihail Zenkov @ 2009-08-17 23:02 UTC (permalink / raw)
  To: gdb-patches

[-- Attachment #1: Type: text/plain, Size: 95 bytes --]

Hi. This patch add D language support. In current state it quite
useful with GDC, LDC and DMD.

[-- Attachment #2: gdb-090818-d.patch --]
[-- Type: application/octet-stream, Size: 21461 bytes --]

diff --git a/gdb/Makefile.in b/gdb/Makefile.in
index ccc4db8..7f0b3ca 100644
--- a/gdb/Makefile.in
+++ b/gdb/Makefile.in
@@ -638,6 +638,7 @@ SFILES = ada-exp.y ada-lang.c ada-typeprint.c ada-valprint.c ada-tasks.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 \
+	d-lang.c d-valprint.c \
 	cp-name-parser.y \
 	dbxread.c demangle.c dictionary.c disasm.c doublest.c dummy-frame.c \
 	dwarf2expr.c dwarf2loc.c dwarf2read.c dwarf2-frame.c \
@@ -803,7 +804,7 @@ COMMON_OBS = $(DEPFILES) $(CONFIG_OBS) $(YYOBJ) \
 	dbxread.o coffread.o coff-pe-read.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 \
 	ada-tasks.o \
 	ui-out.o cli-out.o \
 	varobj.o vec.o wrapper.o \
@@ -813,7 +814,7 @@ COMMON_OBS = $(DEPFILES) $(CONFIG_OBS) $(YYOBJ) \
 	sentinel-frame.o \
 	complaints.o typeprint.o \
 	ada-typeprint.o c-typeprint.o f-typeprint.o m2-typeprint.o \
-	ada-valprint.o c-valprint.o cp-valprint.o f-valprint.o m2-valprint.o \
+	ada-valprint.o c-valprint.o cp-valprint.o d-valprint.o f-valprint.o m2-valprint.o \
 	serial.o mdebugread.o top.o utils.o \
 	ui-file.o \
 	user-regs.o \
diff --git a/gdb/c-lang.c b/gdb/c-lang.c
index 4ba81ba..034d70e 100644
--- a/gdb/c-lang.c
+++ b/gdb/c-lang.c
@@ -25,6 +25,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"
@@ -1381,10 +1382,50 @@ const struct language_defn minimal_language_defn =
   LANG_MAGIC
 };
 
+const struct language_defn d_language_defn =
+{
+  "d",				/* Language name */
+  language_d,
+  range_check_off,
+  type_check_off,
+  case_sensitive_on,
+  array_row_major,
+  macro_expansion_c,
+  &exp_descriptor_c,
+  c_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_print_type,			/* Print a type using appropriate syntax */
+  c_print_typedef,              /* Print a typedef using appropriate syntax */
+  d_val_print,			/* Print a value using appropriate syntax */
+  c_value_print,		/* Print a top-level value */
+  NULL,				/* Language specific skip_trampoline */
+  "this",			/* name_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 */
+  default_word_break_characters,
+  default_make_symbol_completion_list,
+  c_language_arch_info,
+  default_print_array_index,
+  default_pass_by_reference,
+  c_get_string,
+  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 --git a/gdb/d-lang.c b/gdb/d-lang.c
new file mode 100644
index 0000000..58ddcd3
--- /dev/null
+++ b/gdb/d-lang.c
@@ -0,0 +1,241 @@
+
+/* C language support routines for GDB, the GNU debugger.
+   Copyright 1992, 1993, 1994, 1995, 1996, 1998, 1999, 2000, 2002, 2003, 2004
+   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 "language.h"
+#include "d-lang.h"
+#include "c-lang.h"
+#include "gdb_string.h"
+
+#include <ctype.h>
+
+typedef struct {
+  size_t len;
+  char* str;
+  char* pos;
+} String;
+
+static size_t str_left(String* str) {
+  return (str->len - (str->pos - str->str));
+}
+
+static void str_resize(String* str, size_t new_size) {
+  int pos = str->pos - str->str;
+  if (new_size == 0)
+    new_size = strlen(str->str) + 1;
+  str->str = xrealloc(str->str, new_size);
+  str->len = new_size;
+  str->pos = str->str + pos;
+}
+
+static void append_len(String* str, char* src, size_t i) {
+  size_t amnt = str_left(str);
+  if (i > amnt) {
+    str_resize(str, str->len + i + 20);
+  }
+  memcpy(str->pos, src, i);
+  str->pos += i;
+}
+
+static void append(String* str, char* src) {
+  append_len(str, src, strlen(src));
+}
+
+static int extractidentifiers(String* output, String* mangled) {
+  long i = 0;
+  while (isdigit(*mangled->pos)) {
+    i = strtol(mangled->pos, &mangled->pos, 10);
+    if (i == 0 || i == LONG_MAX || i == LONG_MIN) {
+      return -1;
+    }
+    if (strlen(mangled->pos) < i)
+      return -1;
+    append_len(output, mangled->pos, i);
+    mangled->pos += i;
+    append(output, ".");
+  }
+  if (*mangled->pos == '\0' || i == 0)
+    return -1;
+  output->pos--;
+  return 1;
+}
+
+static int extracttypeinfo(String* dest, String* id) {
+  if (*id->pos == '\0')
+    return -1;
+  // Extract the type info:
+  switch (*id->pos++) {
+    // 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* symbol_, int options) {
+  String output;
+  String mangled;
+  unsigned char isFunc = 0;
+  char* symbol;
+  //printf("%s: ", symbol);
+  if (symbol_ == NULL) {
+    //printf("NULL1\n");
+    return NULL;
+  } else if (strcmp(symbol_, "_Dmain") == 0) {
+    return strdup("D main");
+  }
+
+  symbol = xstrdup(symbol_);
+  mangled.len = strlen(symbol);
+  mangled.str = symbol;
+  mangled.pos = symbol;
+
+  output.len = 2;
+  output.str = xmalloc(output.len);
+  output.pos = output.str;
+
+  if (symbol == strstr(symbol, "_D")) {
+    mangled.pos += 2;
+    isFunc = 1;
+  } else if (symbol == strstr(symbol, "__Class_")) {
+    mangled.pos += 8;
+  } else if (symbol == strstr(symbol, "__init_")) {
+    mangled.pos += 7;
+  } else if (symbol == strstr(symbol, "__vtbl_")) {
+    mangled.pos += 7;
+  } else if (symbol == strstr(symbol, "__modctor_")) {
+    mangled.pos += 10;
+  } else if (symbol == strstr(symbol, "__moddtor_")) {
+    mangled.pos += 10;
+  } else if (symbol == strstr(symbol, "__ModuleInfo_")) {
+    mangled.pos += 13;
+  } else {
+    xfree(output.str);
+    xfree(symbol);
+    //printf("NULL2\n");
+    return NULL;
+  }
+  
+  
+  if (extractidentifiers(&output, &mangled) < 0) {
+    xfree(output.str);
+    xfree(symbol);
+    //printf("NULL3\n");
+    return NULL;
+  }
+
+
+
+  append(&output, "(");
+  if (isFunc == 1 && *mangled.pos == 'F') {
+    mangled.pos++;
+    while (*mangled.pos != '\0' && *mangled.pos != 'Z') {
+      if (isFunc == 1) {
+	isFunc++;
+      } else {
+	append(&output, ", ");
+      }
+      if (extracttypeinfo(&output, &mangled) < 0) {
+	xfree(output.str);
+    xfree(symbol);
+	return NULL;
+      }
+    }
+  }
+  append(&output, ")");
+
+  //Doesn't display the return type, but wouldn't be too hard to do.
+
+  append_len(&output, "", 1);
+  str_resize(&output, 0);
+  //printf("%s\n", output.str);
+  xfree(symbol);
+  return output.str;
+}
+
+char* d_sym_demangle(const struct general_symbol_info *gsymbol) {
+  return d_demangle(gsymbol->name, 0);
+}
diff --git a/gdb/d-lang.h b/gdb/d-lang.h
new file mode 100644
index 0000000..3404579
--- /dev/null
+++ b/gdb/d-lang.h
@@ -0,0 +1,39 @@
+/* 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);
+
+int d_val_print (struct type *type, const gdb_byte *valaddr, int embedded_offset,
+        	 CORE_ADDR address, struct ui_file *stream, int recurse,
+                 const struct value_print_options *options);
+#endif /* !defined (D_LANG_H) */
diff --git a/gdb/d-valprint.c b/gdb/d-valprint.c
new file mode 100644
index 0000000..388f183
--- /dev/null
+++ b/gdb/d-valprint.c
@@ -0,0 +1,100 @@
+/* Support for printing D values for GDB, the GNU debugger.
+
+   Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2007,
+   2008 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 3 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, see <http://www.gnu.org/licenses/>.  */
+
+#include "defs.h"
+#include "symtab.h"
+#include "gdbtypes.h"
+#include "gdbcore.h"
+#include "expression.h"
+#include "value.h"
+#include "demangle.h"
+#include "valprint.h"
+#include "language.h"
+#include "d-lang.h"
+#include "c-lang.h"
+#include "annotate.h"
+#include "gdb_string.h"
+
+static int
+dynamic_array_type (struct type *type, const gdb_byte *valaddr,
+		    int embedded_offset, CORE_ADDR address,
+		    struct ui_file *stream, int recurse,
+		    const struct value_print_options *options)
+{
+  if (TYPE_NFIELDS (type) == 2
+      && TYPE_CODE (TYPE_FIELD_TYPE (type, 0)) == TYPE_CODE_INT
+      && strcmp (TYPE_FIELD_NAME (type, 0), "length") == 0
+      && strcmp (TYPE_FIELD_NAME (type, 1), "ptr") == 0)
+    {
+      CORE_ADDR addr;
+      struct type *elttype;
+      struct type *true_type;
+      struct type *ptr_type;
+      struct type *range_type;
+      const gdb_byte *ptraddr;
+      struct value *val;
+      int length;
+
+      length = unpack_field_as_long (type, valaddr + embedded_offset, 0);
+
+      ptr_type = TYPE_FIELD_TYPE (type, 1);
+      elttype = check_typedef (TYPE_TARGET_TYPE (ptr_type));
+      addr = unpack_pointer (ptr_type, valaddr +TYPE_FIELD_BITPOS (type, 1) / 8 + embedded_offset);
+      true_type = check_typedef (elttype);
+
+      true_type = lookup_array_range_type (true_type, 0, length - 1);
+      val = value_at(true_type, addr);
+      ptraddr = value_contents(val);
+
+      val_print (true_type,
+		 ptraddr, 0,
+		 addr,
+		 stream, recurse + 1, options, current_language);
+      return 1;
+    }
+  return 0;
+}
+
+/* Print data of type TYPE located at VALADDR (within GDB), which came from
+   the inferior at address ADDRESS, onto stdio stream STREAM according to
+   OPTIONS.  The data at VALADDR is in target byte order.
+
+   If the data are a string pointer, returns the number of string characters
+   printed.  */
+
+int
+d_val_print (struct type *type, const gdb_byte *valaddr, int embedded_offset,
+             CORE_ADDR address, struct ui_file *stream, int recurse,
+             const struct value_print_options *options)
+{
+  CHECK_TYPEDEF (type);
+  switch (TYPE_CODE (type))
+    {
+    case TYPE_CODE_STRUCT:
+      if (dynamic_array_type (type, valaddr, embedded_offset, address, stream,
+	  recurse, options))
+	  break;
+    default:
+	return c_val_print (type, valaddr, embedded_offset, address, stream,
+			    recurse, options);
+    }
+
+  return 0;
+}
diff --git a/gdb/defs.h b/gdb/defs.h
index f5127fd..c172d4d 100644
--- a/gdb/defs.h
+++ b/gdb/defs.h
@@ -188,6 +188,7 @@ enum language
     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 --git a/gdb/dwarf2read.c b/gdb/dwarf2read.c
index 445bab8..f376079 100644
--- a/gdb/dwarf2read.c
+++ b/gdb/dwarf2read.c
@@ -7451,6 +7451,9 @@ set_cu_language (unsigned int lang, struct dwarf2_cu *cu)
     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:
@@ -8019,7 +8022,7 @@ dwarf_decode_lines (struct line_header *lh, char *comp_dir, bfd *abfd,
                 else
                   {
                     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 --git a/gdb/language.c b/gdb/language.c
index d975f23..33d3d35 100644
--- a/gdb/language.c
+++ b/gdb/language.c
@@ -485,6 +485,7 @@ binop_result_type (struct value *v1, struct value *v2)
     {
     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 ?
@@ -596,6 +597,7 @@ integral_type (struct type *type)
     {
     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;
@@ -636,6 +638,7 @@ character_type (struct type *type)
 
     case language_c:
     case language_cplus:
+    case language_d:
     case language_objc:
       return (TYPE_CODE (type) == TYPE_CODE_INT) &&
 	TYPE_LENGTH (type) == sizeof (char)
@@ -658,6 +661,7 @@ string_type (struct type *type)
 
     case language_c:
     case language_cplus:
+    case language_d:
     case language_objc:
       /* C does not have distinct string type. */
       return (0);
@@ -677,6 +681,7 @@ boolean_type (struct type *type)
     {
     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
@@ -714,6 +719,7 @@ structured_type (struct type *type)
     {
     case language_c:
     case language_cplus:
+    case language_d:
     case language_objc:
       return (TYPE_CODE (type) == TYPE_CODE_STRUCT) ||
 	(TYPE_CODE (type) == TYPE_CODE_UNION) ||
diff --git a/gdb/symfile.c b/gdb/symfile.c
index 5151966..ea373cd 100644
--- a/gdb/symfile.c
+++ b/gdb/symfile.c
@@ -2662,6 +2662,7 @@ init_filename_language_table (void)
       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 --git a/gdb/symtab.c b/gdb/symtab.c
index c88156a..d437f4f 100644
--- a/gdb/symtab.c
+++ b/gdb/symtab.c
@@ -39,6 +39,7 @@
 #include "source.h"
 #include "filenames.h"		/* for FILENAME_CMP */
 #include "objc-lang.h"
+#include "d-lang.h"
 #include "ada-lang.h"
 #include "p-lang.h"
 #include "addrmap.h"
@@ -413,6 +414,7 @@ symbol_init_language_specific (struct general_symbol_info *gsymbol,
 {
   gsymbol->language = language;
   if (gsymbol->language == language_cplus
+      || gsymbol->language == language_d
       || gsymbol->language == language_java
       || gsymbol->language == language_objc)
     {
@@ -459,6 +461,15 @@ symbol_find_demangled_name (struct general_symbol_info *gsymbol,
   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)
     {
@@ -631,6 +642,7 @@ symbol_natural_name (const struct general_symbol_info *gsymbol)
   switch (gsymbol->language)
     {
     case language_cplus:
+    case language_d:
     case language_java:
     case language_objc:
       if (gsymbol->language_specific.cplus_specific.demangled_name != NULL)
@@ -656,6 +668,7 @@ symbol_demangled_name (const struct general_symbol_info *gsymbol)
   switch (gsymbol->language)
     {
     case language_cplus:
+    case language_d:
     case language_java:
     case language_objc:
       if (gsymbol->language_specific.cplus_specific.demangled_name != NULL)
@@ -1200,7 +1213,7 @@ lookup_symbol_in_language (const char *name, const struct block *block,
 
   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 (lang == language_cplus)
     {
@@ -1223,6 +1236,16 @@ lookup_symbol_in_language (const char *name, const struct block *block,
 	    }
 	}
     }
+  else if (current_language->la_language == language_d)
+    {
+      demangled_name = d_demangle (name, 0);
+      if (demangled_name)
+	{
+	  mangled_name = name;
+	  modified_name = demangled_name;
+	  make_cleanup (xfree, demangled_name);
+	}
+    }
   else if (lang == language_java)
     {
       demangled_name = cplus_demangle (name,
@@ -1669,6 +1692,7 @@ symbol_matches_domain (enum language symbol_language,
      A Java class declaration also defines a typedef for the class.
      Similarly, any Ada type declaration implicitly defines a typedef.  */
   if (symbol_language == language_cplus
+      || symbol_language == language_d
       || symbol_language == language_java
       || symbol_language == language_ada)
     {

^ permalink raw reply	[flat|nested] 39+ messages in thread

end of thread, other threads:[~2010-04-29 14:47 UTC | newest]

Thread overview: 39+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-12-23 23:57 D language support Mihail Zenkov
2009-12-30 12:56 ` Joel Brobecker
2010-01-09  6:25   ` Mihail Zenkov
2010-01-09  6:29     ` Mihail Zenkov
2010-01-09 14:23       ` Joel Brobecker
2010-01-13  4:42         ` Mihail Zenkov
2010-01-15  5:10           ` Joel Brobecker
2010-01-15 21:02             ` Tom Tromey
2010-01-15 21:05           ` Tom Tromey
2010-04-14 22:22             ` Mihail Zenkov
2010-04-20 21:39               ` Tom Tromey
2010-04-21  0:01                 ` Mihail Zenkov
2010-04-21 15:57                   ` Joel Brobecker
2010-04-22  0:11                     ` Mihail Zenkov
2010-04-22  0:44                       ` Joel Brobecker
2010-04-22  1:53                         ` Mihail Zenkov
2010-04-23 18:11                           ` Tom Tromey
2010-04-24  0:06                             ` Mihail Zenkov
2010-04-27 16:05                               ` Joel Brobecker
2010-04-27 23:55                                 ` Mihail Zenkov
2010-04-28 15:17                                   ` Joel Brobecker
2010-04-28 17:11                                     ` Eli Zaretskii
2010-04-29  2:16                                     ` Mihail Zenkov
2010-04-28 17:10                                   ` Eli Zaretskii
2010-04-29  1:59                                     ` Mihail Zenkov
2010-04-29  3:10                                       ` Eli Zaretskii
2010-04-29 14:47                                       ` Joel Brobecker
2010-04-23 18:09                         ` Tom Tromey
2010-04-23 20:15                           ` Leandro Lucarella
2010-04-23 20:37                             ` Tom Tromey
2010-04-26 23:51                               ` Stan Shebs
2010-04-27  0:29                                 ` Joel Brobecker
2010-04-23 21:35               ` Robert Clipsham
2010-04-24  0:26                 ` Mihail Zenkov
2010-04-27 20:27                   ` Robert Clipsham
  -- strict thread matches above, loose matches on Subject: below --
2009-08-17 23:02 Mihail Zenkov
2009-08-18  4:18 ` Eli Zaretskii
2009-08-18 16:39 ` Tom Tromey
     [not found]   ` <20090818225844.GA9879@homero.springfield.home>
2009-08-19 18:36     ` Tom Tromey

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox