From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from NAM11-CO1-obe.outbound.protection.outlook.com (mail-co1nam11on2042.outbound.protection.outlook.com [40.107.220.42]) by sourceware.org (Postfix) with ESMTPS id A7AE03851C09 for ; Sun, 28 Jun 2020 16:58:15 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org A7AE03851C09 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=amd.com Authentication-Results: sourceware.org; spf=none smtp.mailfrom=Nitika.Achra@amd.com ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=NgsiWE/es2oZAU1OzUNEha9u2llu/Qlbc/I+O5xgFl+g0dAL55Zc+a09IPwZdPAsgr4YAgIbU4NkVVac/NBtNesDVleVsMeGg6S7DYq+T+7UJFMJS4jbHtg97s/nDqTUxL3hz6RYx0qeQGWCsoiXzdp2ouHyu6zZj75PJliWgJxKkPajxP4J40vkBFiXqQ4vlcHXnm9G1VAoGlVUmsZ2Dj3J9eC3mCWgcSi77uZ6pfyICkcAF1yA/X0xSl4FvC9Omls1lItGO4e9XCz/PKpx4w63B+EL7xyuXKSn1oTiveZ0i80GDtjUF9yWbSrFVyLe65z6/gSom5Ho5OD4orJLqA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=0jJ2EXDEMbXh6flQbkTSOyH+M1brr/O6VCbAap+5eVk=; b=HO7v+7EX8EAS7EkR+5TYki5JlANdWSTzTXFRE7UODq8gP3lYhrLbFgyXIWI+Gipe+w809AqZ07/e3Hfog48Efy70myq14vO3o1FxhLHCOmCskB9xc6Tu8Cqx42bYz3WzfKF8egEj7F2oU6DoCzU+kW54Rz0o4ZcS5Og6cuN1bjAb0fZsKGJtGeDNodSZ3JYMS8jes0ZEzCFxyxIeqiUTMNj+/cEiYB3BA36w5YEqCdfwE58aOV4HN6HPgtoD4amgNXucqU44+29nb72+ydXsw2e3XuV3iEqNjAUcJFKuDnUEVdEXbgBPeNsk+IDOJQ9pJkiHo+DKpVQ1UlukwVDUag== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=amd.com; dmarc=pass action=none header.from=amd.com; dkim=pass header.d=amd.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amdcloud.onmicrosoft.com; s=selector2-amdcloud-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=0jJ2EXDEMbXh6flQbkTSOyH+M1brr/O6VCbAap+5eVk=; b=lGB3dfxCkaCC3MSHC/uLtLsm8w1I3s0Gk8R9sEN1DtFChClcIuh6+H+tfUVh3QLmje+QqEXU7Zej66L48LY4o5mRgalJ3PKJKFJVJubGcsc4xHmaiENza8aQ3w3SyPiguu3maXRMpbe9wKqIi4loFIeXN/d+2+4xN0YYZeA2HtU= Authentication-Results: sourceware.org; dkim=none (message not signed) header.d=none;sourceware.org; dmarc=none action=none header.from=amd.com; Received: from DM5PR12MB1929.namprd12.prod.outlook.com (2603:10b6:3:106::9) by DM5PR12MB1577.namprd12.prod.outlook.com (2603:10b6:4:f::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3131.21; Sun, 28 Jun 2020 16:58:12 +0000 Received: from DM5PR12MB1929.namprd12.prod.outlook.com ([fe80::e981:f456:4f6c:d093]) by DM5PR12MB1929.namprd12.prod.outlook.com ([fe80::e981:f456:4f6c:d093%10]) with mapi id 15.20.3131.026; Sun, 28 Jun 2020 16:58:12 +0000 From: nitachra To: gdb-patches@sourceware.org Cc: JiniSusan.George@amd.com, nitachra Subject: [PATCH] DWARFv5: Handle DW_MACRO_define_strx and DW_MACRO_undef_strx macro entries. Date: Sun, 28 Jun 2020 22:27:52 +0530 Message-Id: <20200628165752.5379-1-Nitika.Achra@amd.com> X-Mailer: git-send-email 2.17.1 Content-Type: text/plain X-ClientProxiedBy: MAXPR01CA0071.INDPRD01.PROD.OUTLOOK.COM (2603:1096:a00:49::13) To DM5PR12MB1929.namprd12.prod.outlook.com (2603:10b6:3:106::9) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from bglcomp-haswell-105.amd.com (165.204.156.251) by MAXPR01CA0071.INDPRD01.PROD.OUTLOOK.COM (2603:1096:a00:49::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3131.20 via Frontend Transport; Sun, 28 Jun 2020 16:58:11 +0000 X-Mailer: git-send-email 2.17.1 X-Originating-IP: [165.204.156.251] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: 13bfcdb0-d6f9-467c-7a32-08d81b84713d X-MS-TrafficTypeDiagnostic: DM5PR12MB1577: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:3826; X-Forefront-PRVS: 0448A97BF2 X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 0BbcApIXi3tvr6iHrXxkBTc8kLQkROgAStG6KvKJw0jjG66DR1nMKpK+M2OAM4UnBQDaHQDooKPhI+uMIZtD3ysd09wuNt6d/Z2UED+UwzFOLD0cKwl+w87lpxktysjYKYzZ7oO79g8eJRljDsJ7A2avixqrpqiWkajzjD4ze4ScFmepWnVjp+3wdR+WLippaiMWRm1BLNeBOzEKAI8amQB4B26uUS87aIWUqw1/denBy/U44w01facfKQeQjhTar192VcFmibZ5Wjijop7yBVDb80YH5BX0w59w38PWkWPIOLC+44ZCfSoS+eI97fiSF/6YvnE9D5kZktSpXG7kk7b8UidjUzE4+OwEziOPs3KuJmlrQDmwsFJbK/AvRinB X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:DM5PR12MB1929.namprd12.prod.outlook.com; PTR:; CAT:NONE; SFTY:; SFS:(4636009)(39860400002)(396003)(376002)(346002)(366004)(136003)(66946007)(8936002)(66476007)(66556008)(316002)(4326008)(8676002)(5660300002)(36756003)(1076003)(83380400001)(186003)(2616005)(956004)(16526019)(6486002)(478600001)(26005)(2906002)(86362001)(6666004)(6916009)(7696005)(52116002)(43062003); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData: Lh/2IAhB9G+K0uDu3dIT/3NglPHf1U9vOVt1pSEMHL4JRimq/9BlicLVtY7dx+WJu/b9TiMoMxS0haR1PaubDhsLtmpArh2x4oKm1hJBCfW95Qp+/0ZqfDe9d65JJ1WHIXZ+4xmNyHHtv9F1H4U9gLjdMUL7g0qrxa3aT8ZPGsoqV/ZtnK9IlnFOILZdU4bY4obOzWecXyj124qxuUnqA6/8PEeYlEfEEOjjAOFYeuYbP1bIWkoLiW6G6MG3OhKfEU3QjvjG0884e9hFdz6ryr47Q0mxie+fpjIm1/HBXLEIPl+synL50lhFLCWA2PzRKNMFHU0066Mm76nGHIMchdi+U3RPNrmFyH8wg8l10IDLGjSYmmnCymXm+FA3fSzaUyq0qdA8lQUBpebezOrPlREBmAsUWyMFJBPKbKT4OJEqGBYfdXIr0rioB6VGE8vBNNebUMlXxLNlOcHBXZlZGD8YUbIfIwTYUiog0q3uFbo= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: 13bfcdb0-d6f9-467c-7a32-08d81b84713d X-MS-Exchange-CrossTenant-AuthSource: DM5PR12MB1929.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 28 Jun 2020 16:58:12.4271 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: fKgen09MGIUArsr1Dysdvr/Sfm65hkCQE4+Wk6mL3DJpLN36kouGxFomZuRsSSTYGgEPbBuEcTKGs79p29TbEw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR12MB1577 X-Spam-Status: No, score=-20.0 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, FORGED_SPF_HELO, GIT_PATCH_0, MSGID_FROM_MTA_HEADER, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, SPF_HELO_PASS, SPF_NONE, 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: Sun, 28 Jun 2020 16:58:17 -0000 GDB is not able to print the macro values with -gdwarf-5 for clang generated binaries. Clang is emitting DW_MACRO_define_strx and DW_MACRO_undef_strx entries in .debug_macro section which are not supported in GDB. This patch handles them. DW_MACRO_define_strx and DW_MACRO_undef_strx are added in DWARFv5. They have two operands. The first operand encodes the line number of the #define or #undef macro directive. The second operand identifies a string; it is represented using an unsigned LEB128 encoded value, which is interpreted as a zero-based index into an array of offsets in the .debug_str_offsets section. This is as per the section 6.3.2.1 of Dwarf Debugging Information Format Version 5. Test case used: #define MAX_SIZE 10 int main(void) { int size = 0; size = size + MAX_SIZE; printf("\n The value of size is [%d]\n",size); return 0; } clang -gdwarf-5 -fdebug-macro macro.c -o macro.out Before the patch: gdb -q macro.out -ex "start" -ex "p MAX_SIZE" Reading symbols from macro.out... Temporary breakpoint 1 at 0x4004df: file macro.c, line 7. Starting program: /home/nitika/workspace/macro.out Temporary breakpoint 1, main () at macro.c:7 7 int size = 0; No symbol "MAX_SIZE" in current context. After the patch: gdb -q macro.out -ex "start" -ex "p MAX_SIZE" Reading symbols from macro.out... Temporary breakpoint 1 at 0x4004df: file macro.c, line 7. Starting program: /home/nitika/workspace/macro.out Temporary breakpoint 1, main () at macro.c:7 7 int size = 0; $1 = 10 Tested by running the testsuite before and after the patch with -gdwarf-5 and there is no increase in the number of test cases that fails. Used clang 11.0.0. gdb/dwarf2/ChangeLog: *macro.c (dwarf_decode_macro_bytes): Handle DW_MACRO_define_strx and DW_MACRO_undef_strx. (dwarf_decode_macros): Likewise *read.c (dwarf_decode_macros): Pass str_offsets_base in the parameters which is the value of DW_AT_str_offsets_base. *macro.h (dwarf_decode_macros): Modify the definition to include str_offsets_base. gdb/ChangeLog: *macrotab.c (macro_lookup_inclusion): In DWARF version 5 filename includes the full directory path. --- gdb/dwarf2/macro.c | 63 +++++++++++++++++++++++++++++++++++++++++++--- gdb/dwarf2/macro.h | 1 + gdb/dwarf2/read.c | 4 ++- gdb/macrotab.c | 3 ++- 4 files changed, 66 insertions(+), 5 deletions(-) diff --git a/gdb/dwarf2/macro.c b/gdb/dwarf2/macro.c index d047d806f8..2f5f3aa827 100644 --- a/gdb/dwarf2/macro.c +++ b/gdb/dwarf2/macro.c @@ -427,6 +427,7 @@ dwarf_decode_macro_bytes (dwarf2_per_objfile *per_objfile, const struct dwarf2_section_info *section, int section_is_gnu, int section_is_dwz, unsigned int offset_size, + ULONGEST str_offsets_base, htab_t include_hash) { struct objfile *objfile = per_objfile->objfile; @@ -561,6 +562,50 @@ dwarf_decode_macro_bytes (dwarf2_per_objfile *per_objfile, } break; + case DW_MACRO_define_strx: + case DW_MACRO_undef_strx: + { + unsigned int bytes_read; + int line; + int offset_index; + const char* body; + const gdb_byte* info_ptr; + ULONGEST str_offset; + + line = read_unsigned_leb128 (abfd, mac_ptr, &bytes_read); + mac_ptr += bytes_read; + offset_index = read_unsigned_leb128 (abfd, mac_ptr, &bytes_read); + mac_ptr += bytes_read; + struct dwarf2_section_info str_offsets_section = per_objfile->per_bfd->str_offsets; + str_offsets_section.read (objfile); + info_ptr = (str_offsets_section.buffer + + str_offsets_base + + offset_index * offset_size); + if (offset_size == 4) + str_offset = bfd_get_32 (abfd, info_ptr); + else + str_offset = bfd_get_64 (abfd, info_ptr); + body = per_objfile->per_bfd->str.read_string (objfile, + str_offset, + "DW_FORM_strx"); + + if (! current_file) + { + /* DWARF violation as no main source is present. */ + complaint (_("debug info with no main source gives macro %s " + "on line %d: %s"), + macinfo_type == DW_MACRO_define_strx ? _("definition") + : _("undefinition"), line, body); + break; + } + + if (macinfo_type == DW_MACRO_define_strx) + parse_macro_definition (current_file, line, body); + else + macro_undef (current_file, line, body); + } + break; + case DW_MACRO_start_file: { unsigned int bytes_read; @@ -671,7 +716,7 @@ dwarf_decode_macro_bytes (dwarf2_per_objfile *per_objfile, new_mac_ptr, include_mac_end, current_file, lh, section, section_is_gnu, is_dwz, offset_size, - include_hash); + str_offsets_base, include_hash); htab_remove_elt (include_hash, (void *) new_mac_ptr); } @@ -712,7 +757,8 @@ dwarf_decode_macros (dwarf2_per_objfile *per_objfile, buildsym_compunit *builder, const dwarf2_section_info *section, const struct line_header *lh, unsigned int offset_size, - unsigned int offset, int section_is_gnu) + unsigned int offset, ULONGEST str_offsets_base, + int section_is_gnu) { bfd *abfd; const gdb_byte *mac_ptr, *mac_end; @@ -814,6 +860,17 @@ dwarf_decode_macros (dwarf2_per_objfile *per_objfile, mac_ptr += offset_size; } break; + case DW_MACRO_define_strx: + case DW_MACRO_undef_strx: + { + unsigned int bytes_read; + + read_unsigned_leb128 (abfd, mac_ptr, &bytes_read); + mac_ptr += bytes_read; + read_unsigned_leb128 (abfd, mac_ptr, &bytes_read); + mac_ptr += bytes_read; + } + break; case DW_MACRO_import: case DW_MACRO_import_sup: @@ -861,5 +918,5 @@ dwarf_decode_macros (dwarf2_per_objfile *per_objfile, *slot = (void *) mac_ptr; dwarf_decode_macro_bytes (per_objfile, builder, abfd, mac_ptr, mac_end, current_file, lh, section, section_is_gnu, 0, - offset_size, include_hash.get ()); + offset_size, str_offsets_base, include_hash.get ()); } diff --git a/gdb/dwarf2/macro.h b/gdb/dwarf2/macro.h index d874068947..dc396e1b70 100644 --- a/gdb/dwarf2/macro.h +++ b/gdb/dwarf2/macro.h @@ -28,6 +28,7 @@ extern void dwarf_decode_macros (dwarf2_per_objfile *per_objfile, const struct line_header *lh, unsigned int offset_size, unsigned int offset, + ULONGEST str_offsets_base, int section_is_gnu); #endif /* GDB_DWARF2_MACRO_H */ diff --git a/gdb/dwarf2/read.c b/gdb/dwarf2/read.c index e3073fe43c..a0e197c748 100644 --- a/gdb/dwarf2/read.c +++ b/gdb/dwarf2/read.c @@ -23353,8 +23353,10 @@ dwarf_decode_macros (struct dwarf2_cu *cu, unsigned int offset, buildsym_compunit *builder = cu->get_builder (); + ULONGEST str_offsets_base = *cu->str_offsets_base; + dwarf_decode_macros (per_objfile, builder, section, lh, - offset_size, offset, section_is_gnu); + offset_size, offset, str_offsets_base, section_is_gnu); } /* Return the .debug_loc section to use for CU. diff --git a/gdb/macrotab.c b/gdb/macrotab.c index 63cd30148a..606f084bc9 100644 --- a/gdb/macrotab.c +++ b/gdb/macrotab.c @@ -507,7 +507,8 @@ struct macro_source_file * macro_lookup_inclusion (struct macro_source_file *source, const char *name) { /* Is SOURCE itself named NAME? */ - if (filename_cmp (name, source->filename) == 0) + if (filename_cmp (name, source->filename) == 0 || + filename_cmp (basename (name), basename (source->filename)) == 0) return source; /* It's not us. Try all our children, and return the lowest. */ -- 2.17.1