Skip to content
This repository has been archived by the owner on Jun 20, 2019. It is now read-only.

Commit

Permalink
Generate correct debug information for D modules.
Browse files Browse the repository at this point in the history
  • Loading branch information
ibuclaw committed Feb 16, 2014
1 parent 942298f commit 91a1863
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 19 deletions.
8 changes: 8 additions & 0 deletions gcc/d/ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
2014-02-16 Iain Buclaw <ibuclaw@gdcproject.org>

* d-decls.cc(Module::toSymbol): Build a NAMESPACE_DECL to populate the
DECL_CONTEXT of toplevel functions.
* d-codegen.cc(d_decl_context): Return the enclosing module
NAMESPACE_DECL as the decl context only when the symbol is extern(D)
and not D main.

2014-02-15 Iain Buclaw <ibuclaw@gdcproject.org>

* d-decls.cc(VarDeclaration::toSymbol): Don't call
Expand Down
33 changes: 22 additions & 11 deletions gcc/d/d-codegen.cc
Original file line number Diff line number Diff line change
Expand Up @@ -34,32 +34,43 @@ IRState *current_irstate;
tree
d_decl_context (Dsymbol *dsym)
{
Dsymbol *orig_sym = dsym;
Dsymbol *parent = dsym;
AggregateDeclaration *ad;

while ((dsym = dsym->toParent2()))
while ((parent = parent->toParent2()))
{
if (dsym->isFuncDeclaration())
if (parent->isFuncDeclaration())
{
// dwarf2out chokes without this check... (output_pubnames)
FuncDeclaration *f = orig_sym->isFuncDeclaration();
if (f && !needs_static_chain (f))
FuncDeclaration *fd = dsym->isFuncDeclaration();
if (fd && !needs_static_chain (fd))
return NULL_TREE;

return dsym->toSymbol()->Stree;
return parent->toSymbol()->Stree;
}
else if ((ad = dsym->isAggregateDeclaration()))
else if ((ad = parent->isAggregateDeclaration()))
{
tree context = ad->type->toCtype();
if (ad->isClassDeclaration())
{
// RECORD_TYPE instead of REFERENCE_TYPE
// Want the underlying RECORD_TYPE.
context = TREE_TYPE (context);
}
return context;
}
else if (dsym->isModule())
return dsym->toSymbol()->ScontextDecl;
else if (parent->isModule())
{
// We've reached the top-level module namespace.
// Set DECL_CONTEXT as the NAMESPACE_DECL of the enclosing
// module, but only for extern(D) symbols that aren't D main.
Declaration *decl = dsym->isDeclaration();
FuncDeclaration *fd = dsym->isFuncDeclaration();
if (decl != NULL)
{
if (decl->linkage != LINKd || fd->isMain())
return NULL_TREE;
}
return parent->toSymbol()->ScontextDecl;
}
}

return NULL_TREE;
Expand Down
11 changes: 10 additions & 1 deletion gcc/d/d-decls.cc
Original file line number Diff line number Diff line change
Expand Up @@ -569,7 +569,7 @@ InterfaceDeclaration::toSymbol (void)
return csym;
}

// Create the "ModuleInfo" symbol for given module.
// Create the "ModuleInfo" symbol and namespace for given module.

Symbol *
Module::toSymbol (void)
Expand All @@ -589,6 +589,15 @@ Module::toSymbol (void)
// Not readonly, moduleinit depends on this.
TREE_CONSTANT (decl) = 0;
TREE_READONLY (decl) = 0;

// Build the module namespace, any enclosing members will have
// this set as their DECL_CONTEXT, see d_decl_context.
const char *name = this->toPrettyChars();
tree mod = build_decl (UNKNOWN_LOCATION, NAMESPACE_DECL,
get_identifier (name), void_type_node);
set_decl_location (mod, this);
csym->ScontextDecl = mod;
d_keep (mod);
}

return csym;
Expand Down
39 changes: 32 additions & 7 deletions gcc/d/patches/patch-gcc-4.9.x
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ relevant documentation about the GDC front end.

--- gcc/config/rs6000/rs6000.c
+++ gcc/config/rs6000/rs6000.c
@@ -24314,7 +24314,8 @@ rs6000_output_function_epilogue (FILE *file,
@@ -24406,7 +24406,8 @@ rs6000_output_function_epilogue (FILE *file,
either, so for now use 0. */
if (! strcmp (language_string, "GNU C")
|| ! strcmp (language_string, "GNU GIMPLE")
Expand Down Expand Up @@ -35,7 +35,7 @@ relevant documentation about the GDC front end.
current official meaning is ``GNU Compiler Collection'', which refers
--- gcc/doc/install.texi
+++ gcc/doc/install.texi
@@ -1402,12 +1402,12 @@ their runtime libraries should be built. For a list of valid values for
@@ -1418,12 +1418,12 @@ their runtime libraries should be built. For a list of valid values for
grep language= */config-lang.in
@end smallexample
Currently, you can use any of the following:
Expand All @@ -52,7 +52,7 @@ relevant documentation about the GDC front end.
Specify that a particular subset of compilers and their runtime
--- gcc/doc/invoke.texi
+++ gcc/doc/invoke.texi
@@ -1216,6 +1216,15 @@ called @dfn{specs}.
@@ -1229,6 +1229,15 @@ called @dfn{specs}.
Ada source code file containing a library unit body (a subprogram or
package body). Such files are also called @dfn{bodies}.

Expand All @@ -68,7 +68,7 @@ relevant documentation about the GDC front end.
@c GCC also knows about some suffixes for languages not yet included:
@c Pascal:
@c @var{file}.p
@@ -1251,6 +1260,7 @@ objective-c objective-c-header objective-c-cpp-output
@@ -1264,6 +1273,7 @@ objective-c objective-c-header objective-c-cpp-output
objective-c++ objective-c++-header objective-c++-cpp-output
assembler assembler-with-cpp
ada
Expand All @@ -90,7 +90,7 @@ relevant documentation about the GDC front end.

--- gcc/doc/standards.texi
+++ gcc/doc/standards.texi
@@ -283,6 +283,16 @@ available online, see @uref{http://gcc.gnu.org/readings.html}
@@ -282,6 +282,16 @@ available online, see @uref{http://gcc.gnu.org/readings.html}
As of the GCC 4.7.1 release, GCC supports the Go 1 language standard,
described at @uref{http://golang.org/doc/go1.html}.

Expand All @@ -109,7 +109,23 @@ relevant documentation about the GDC front end.
@xref{Top, GNAT Reference Manual, About This Guide, gnat_rm,
--- gcc/dwarf2out.c
+++ gcc/dwarf2out.c
@@ -19249,6 +19249,8 @@ gen_compile_unit_die (const char *filename)
@@ -4613,6 +4613,15 @@ is_ada (void)
return lang == DW_LANG_Ada95 || lang == DW_LANG_Ada83;
}

+/* Return TRUE if the language is D. */
+static inline bool
+is_dlang (void)
+{
+ unsigned int lang = get_AT_unsigned (comp_unit_die (), DW_AT_language);
+
+ return lang == DW_LANG_D;
+}
+
/* Remove the specified attribute if present. */

static void
@@ -19277,6 +19286,8 @@ gen_compile_unit_die (const char *filename)
language = DW_LANG_C89;
if (strcmp (language_string, "GNU C++") == 0)
language = DW_LANG_C_plus_plus;
Expand All @@ -118,9 +134,18 @@ relevant documentation about the GDC front end.
else if (strcmp (language_string, "GNU F77") == 0)
language = DW_LANG_Fortran77;
else if (strcmp (language_string, "GNU Pascal") == 0)
@@ -20236,7 +20247,7 @@ gen_namespace_die (tree decl, dw_die_ref context_die)
{
/* Output a real namespace or module. */
context_die = setup_namespace_context (decl, comp_unit_die ());
- namespace_die = new_die (is_fortran ()
+ namespace_die = new_die (is_fortran () || is_dlang ()
? DW_TAG_module : DW_TAG_namespace,
context_die, decl);
/* For Fortran modules defined in different CU don't add src coords. */
--- gcc/gcc.c
+++ gcc/gcc.c
@@ -1034,6 +1034,7 @@ static const struct compiler default_compilers[] =
@@ -1021,6 +1021,7 @@ static const struct compiler default_compilers[] =
{".java", "#Java", 0, 0, 0}, {".class", "#Java", 0, 0, 0},
{".zip", "#Java", 0, 0, 0}, {".jar", "#Java", 0, 0, 0},
{".go", "#Go", 0, 1, 0},
Expand Down

0 comments on commit 91a1863

Please sign in to comment.