From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from gateway31.websitewelcome.com (gateway31.websitewelcome.com [192.185.144.96]) by sourceware.org (Postfix) with ESMTPS id 654BE384F033 for ; Thu, 10 Jun 2021 19:02:57 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 654BE384F033 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=tromey.com Authentication-Results: sourceware.org; spf=fail smtp.mailfrom=tromey.com Received: from cm12.websitewelcome.com (cm12.websitewelcome.com [100.42.49.8]) by gateway31.websitewelcome.com (Postfix) with ESMTP id C8B6E325AB6 for ; Thu, 10 Jun 2021 14:00:56 -0500 (CDT) Received: from box5379.bluehost.com ([162.241.216.53]) by cmsmtp with SMTP id rPvDlUxDhELyOrPvDlKfmV; Thu, 10 Jun 2021 14:00:55 -0500 X-Authority-Reason: nr=8 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=tromey.com; s=default; h=Content-Transfer-Encoding:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To:Content-Type:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive; bh=9kZuNGT8RARogFl68EubrFWF+/LE5RYZ9nHNT7paWfU=; b=ntjxAdGZC30salxj8+1tmh0tK3 DX+NtviHvHVufi6ewEAABAvQDgVHSf/H8bPSR3ZF8zlQQX0QHxAPDewDBCLvjkiFL+N+tfbhb6iop z3VwQzudueZhGSuoEr26PVwZo; Received: from 97-122-81-113.hlrn.qwest.net ([97.122.81.113]:56264 helo=localhost.localdomain) by box5379.bluehost.com with esmtpsa (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1lrPvD-000G8A-1I; Thu, 10 Jun 2021 13:00:55 -0600 From: Tom Tromey To: gdb-patches@sourceware.org Cc: Tom Tromey Subject: [PATCH v2 1/2] Consolidate CU language setting Date: Thu, 10 Jun 2021 13:00:50 -0600 Message-Id: <20210610190051.902127-2-tom@tromey.com> X-Mailer: git-send-email 2.26.3 In-Reply-To: <20210610190051.902127-1-tom@tromey.com> References: <20210610190051.902127-1-tom@tromey.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - box5379.bluehost.com X-AntiAbuse: Original Domain - sourceware.org X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - tromey.com X-BWhitelist: no X-Source-IP: 97.122.81.113 X-Source-L: No X-Exim-ID: 1lrPvD-000G8A-1I X-Source: X-Source-Args: X-Source-Dir: X-Source-Sender: 97-122-81-113.hlrn.qwest.net (localhost.localdomain) [97.122.81.113]:56264 X-Source-Auth: tom+tromey.com X-Email-Count: 2 X-Source-Cap: ZWx5bnJvYmk7ZWx5bnJvYmk7Ym94NTM3OS5ibHVlaG9zdC5jb20= X-Local-Domain: yes X-Spam-Status: No, score=-3032.0 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, GIT_PATCH_0, JMQ_SPF_NEUTRAL, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, SPF_HELO_PASS, SPF_NEUTRAL, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 10 Jun 2021 19:02:59 -0000 The DWARF reader currently sets the CU's language in two different spots. It is primarily done in prepare_one_comp_unit, but read_file_scope also checks the producer and may change the language based on the result. This patch consolidates all language-setting into prepare_one_comp_unit. set_cu_language is renamed and changed not to set language_defn; instead that is done in prepare_one_comp_unit after the correct language enum value is chosen. This fixes a minor latent bug, which is that read_file_scope could set the language enum value to language_opencl, but then neglected to reset language_defn in this case. gdb/ChangeLog 2021-06-10 Tom Tromey * dwarf2/read.c (read_file_scope): Don't call set_cu_language. (dwarf_lang_to_enum_language): Rename from set_cu_language. Don't set language_defn. Handle DW_LANG_OpenCL. (prepare_one_comp_unit): Check producer and set language_defn. --- gdb/ChangeLog | 7 +++++ gdb/dwarf2/read.c | 75 ++++++++++++++++++++++++++--------------------- 2 files changed, 48 insertions(+), 34 deletions(-) diff --git a/gdb/dwarf2/read.c b/gdb/dwarf2/read.c index 96009f1418f..b441feb6ea7 100644 --- a/gdb/dwarf2/read.c +++ b/gdb/dwarf2/read.c @@ -1173,8 +1173,6 @@ static const char *read_dwo_str_index (const struct die_reader_specs *reader, static const char *read_stub_str_index (struct dwarf2_cu *cu, ULONGEST str_index); -static void set_cu_language (unsigned int, struct dwarf2_cu *); - static struct attribute *dwarf2_attr (struct die_info *, unsigned int, struct dwarf2_cu *); @@ -10509,16 +10507,6 @@ read_file_scope (struct die_info *die, struct dwarf2_cu *cu) file_and_directory fnd = find_file_and_directory (die, cu); - /* The XLCL doesn't generate DW_LANG_OpenCL because this attribute is not - standardised yet. As a workaround for the language detection we fall - back to the DW_AT_producer string. */ - if (cu->producer && strstr (cu->producer, "IBM XL C for OpenCL") != NULL) - cu->language = language_opencl; - - /* Similar hack for Go. */ - if (cu->producer && strstr (cu->producer, "GNU Go ") != NULL) - set_cu_language (DW_LANG_Go, cu); - cu->start_symtab (fnd.name, fnd.comp_dir, lowpc); /* Decode line number information if present. We do this before @@ -20350,9 +20338,11 @@ leb128_size (const gdb_byte *buf) } } -static void -set_cu_language (unsigned int lang, struct dwarf2_cu *cu) +static enum language +dwarf_lang_to_enum_language (unsigned int lang) { + enum language language; + switch (lang) { case DW_LANG_C89: @@ -20360,54 +20350,58 @@ set_cu_language (unsigned int lang, struct dwarf2_cu *cu) case DW_LANG_C11: case DW_LANG_C: case DW_LANG_UPC: - cu->language = language_c; + language = language_c; break; case DW_LANG_Java: case DW_LANG_C_plus_plus: case DW_LANG_C_plus_plus_11: case DW_LANG_C_plus_plus_14: - cu->language = language_cplus; + language = language_cplus; break; case DW_LANG_D: - cu->language = language_d; + language = language_d; break; case DW_LANG_Fortran77: case DW_LANG_Fortran90: case DW_LANG_Fortran95: case DW_LANG_Fortran03: case DW_LANG_Fortran08: - cu->language = language_fortran; + language = language_fortran; break; case DW_LANG_Go: - cu->language = language_go; + language = language_go; break; case DW_LANG_Mips_Assembler: - cu->language = language_asm; + language = language_asm; break; case DW_LANG_Ada83: case DW_LANG_Ada95: - cu->language = language_ada; + language = language_ada; break; case DW_LANG_Modula2: - cu->language = language_m2; + language = language_m2; break; case DW_LANG_Pascal83: - cu->language = language_pascal; + language = language_pascal; break; case DW_LANG_ObjC: - cu->language = language_objc; + language = language_objc; break; case DW_LANG_Rust: case DW_LANG_Rust_old: - cu->language = language_rust; + language = language_rust; + break; + case DW_LANG_OpenCL: + language = language_opencl; break; case DW_LANG_Cobol74: case DW_LANG_Cobol85: default: - cu->language = language_minimal; + language = language_minimal; break; } - cu->language_defn = language_def (cu->language); + + return language; } /* Return the named attribute or NULL if not there. */ @@ -24413,17 +24407,30 @@ prepare_one_comp_unit (struct dwarf2_cu *cu, struct die_info *comp_unit_die, { struct attribute *attr; + cu->producer = dwarf2_string_attr (comp_unit_die, DW_AT_producer, cu); + /* Set the language we're debugging. */ attr = dwarf2_attr (comp_unit_die, DW_AT_language, cu); - if (attr != nullptr) - set_cu_language (attr->constant_value (0), cu); - else + if (cu->producer != nullptr + && strstr (cu->producer, "IBM XL C for OpenCL") != NULL) { - cu->language = pretend_language; - cu->language_defn = language_def (cu->language); + /* The XLCL doesn't generate DW_LANG_OpenCL because this + attribute is not standardised yet. As a workaround for the + language detection we fall back to the DW_AT_producer + string. */ + cu->language = language_opencl; } - - cu->producer = dwarf2_string_attr (comp_unit_die, DW_AT_producer, cu); + else if (cu->producer != nullptr + && strstr (cu->producer, "GNU Go ") != NULL) + { + /* Similar hack for Go. */ + cu->language = language_go; + } + else if (attr != nullptr) + cu->language = dwarf_lang_to_enum_language (attr->constant_value (0)); + else + cu->language = pretend_language; + cu->language_defn = language_def (cu->language); } /* See read.h. */ -- 2.26.3