From patchwork Mon Jul 13 17:47:30 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Iain Buclaw X-Patchwork-Id: 7662 Received: (qmail 109629 invoked by alias); 13 Jul 2015 17:47:36 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Delivered-To: mailing list gdb-patches@sourceware.org Received: (qmail 109617 invoked by uid 89); 13 Jul 2015 17:47:35 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.7 required=5.0 tests=AWL, BAYES_20, FREEMAIL_FROM, RCVD_IN_DNSWL_LOW, SPF_PASS autolearn=ham version=3.3.2 X-HELO: mail-wi0-f171.google.com Received: from mail-wi0-f171.google.com (HELO mail-wi0-f171.google.com) (209.85.212.171) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES128-GCM-SHA256 encrypted) ESMTPS; Mon, 13 Jul 2015 17:47:33 +0000 Received: by widjy10 with SMTP id jy10so76616897wid.1 for ; Mon, 13 Jul 2015 10:47:30 -0700 (PDT) MIME-Version: 1.0 X-Received: by 10.194.23.225 with SMTP id p1mr73295859wjf.155.1436809650599; Mon, 13 Jul 2015 10:47:30 -0700 (PDT) Received: by 10.27.81.138 with HTTP; Mon, 13 Jul 2015 10:47:30 -0700 (PDT) Date: Mon, 13 Jul 2015 19:47:30 +0200 Message-ID: Subject: [PATCH] D: support reading modules from DWARF From: Iain Buclaw To: gdb-patches@sourceware.org X-IsSubscribed: yes Hi, D uses modules (DW_TAG_module), but to separate the namespace of every source file. Modules can be imported into each other, either publicly or privately (DW_TAG_imported_module). Or declarations can be selectively imported or renamed (DW_TAG_imported_decl). This patch pretty much just extends the existing support for namespaces/modules in C++/Fortran/Java to include language_d too. However unlike Fortran/C++, the separator for qualified names is a single dot. This will need to be followed up with a patch to support looking up symbols in D module 'namespaces'. However I'm currently unsure whether to either extend cp-namespace.c, or to go ahead with my current fork (d-namespace.c), which copies only what's needed, adjusting for D-specific symbol import logic. Iain. 2015-07-13 Iain Buclaw * dwarf2read.c (find_slot_in_mapped_hash): Extend language support to also test for language_d. (dwarf2_compute_name): Likewise. (read_func_scope): Likewise. (read_structure_type): Likewise. (determine_prefix): Likewise. (read_import_statement): Use dot as the separator for language_d. (typename_concat): Likewise, but don't prefix the D main function. --- a/gdb/dwarf2read.c +++ b/gdb/dwarf2read.c @@ -2974,7 +2974,8 @@ find_slot_in_mapped_hash (struct mapped_index *index, const char *name, if (current_language->la_language == language_cplus || current_language->la_language == language_java - || current_language->la_language == language_fortran) + || current_language->la_language == language_fortran + || current_language->la_language == language_d) { /* NAME is already canonical. Drop any qualifiers as .gdb_index does not contain any. */ @@ -8463,7 +8464,7 @@ dwarf2_compute_name (const char *name, /* These are the only languages we know how to qualify names in. */ if (name != NULL && (cu->language == language_cplus || cu->language == language_java - || cu->language == language_fortran)) + || cu->language == language_fortran || cu->language == language_d)) { if (die_needs_namespace (die, cu)) { @@ -8941,8 +8942,9 @@ read_import_statement (struct die_info *die, struct dwarf2_cu *cu) } else if (strlen (imported_name_prefix) > 0) canonical_name = obconcat (&objfile->objfile_obstack, - imported_name_prefix, "::", imported_name, - (char *) NULL); + imported_name_prefix, + (cu->language == language_d ? "." : "::"), + imported_name, (char *) NULL); else canonical_name = imported_name; @@ -11445,7 +11447,9 @@ read_func_scope (struct die_info *die, struct dwarf2_cu *cu) lowpc, highpc); /* For C++, set the block's scope. */ - if ((cu->language == language_cplus || cu->language == language_fortran) + if ((cu->language == language_cplus + || cu->language == language_fortran + || cu->language == language_d) && cu->processing_has_namespace_info) block_set_scope (block, determine_prefix (die, cu), &objfile->objfile_obstack); @@ -13140,7 +13144,8 @@ read_structure_type (struct die_info *die, struct dwarf2_cu *cu) if (name != NULL) { if (cu->language == language_cplus - || cu->language == language_java) + || cu->language == language_java + || cu->language == language_d) { const char *full_name = dwarf2_full_name (name, die, cu); @@ -19228,7 +19233,7 @@ determine_prefix (struct die_info *die, struct dwarf2_cu *cu) char *retval; if (cu->language != language_cplus && cu->language != language_java - && cu->language != language_fortran) + && cu->language != language_fortran && cu->language != language_d) return ""; retval = anonymous_struct_prefix (die, cu); @@ -19384,6 +19389,18 @@ typename_concat (struct obstack *obs, const char *prefix, const char *suffix, sep = ""; else if (cu->language == language_java) sep = "."; + else if (cu->language == language_d) + { + /* For D, the 'main' function could be defined in any module, but it + should never be prefixed. */ + if (strcmp (suffix, "D main") == 0) + { + prefix = ""; + sep = ""; + } + else + sep = "."; + } else if (cu->language == language_fortran && physname) { /* This is gfortran specific mangling. Normally DW_AT_linkage_name or