From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from NAM11-BN8-obe.outbound.protection.outlook.com (mail-bn8nam11on2087.outbound.protection.outlook.com [40.107.236.87]) by sourceware.org (Postfix) with ESMTPS id A56C03857032 for ; Mon, 10 Aug 2020 15:06:47 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org A56C03857032 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=Zmd8br1oClhDEsVDhFu25Oe8oqy1eTajUOpOcvlS1BXSJ8AAWzX4z+NEsrpGOF+BKF/modVtvUt/0dWXxItzormWyBrK+5gIsedrpMWNBUOwompgwPuSXdgQp0+iuSkVh6jqo2jzVu9xS3JDQ9+sk10+kWGfd801sur6jLCbXMHUILN9UnDS0/9oTEePc6cY6nMENz1VMpdUyiwmvHmJot/zIIXmV21hAf7NIdn1gF6BuvACgGA6V5WA3vxlxSZrprvwBLxWrEfFPxNDbi+JzmEBleHr9eb2zywcfOH0MQWIRjzD85wz9mkuoJYmZRfBh3a59CLznGnb8ZxMYlpaZA== 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=fQWnYQUS3QnAKwkf8IiaPo8zQmHWWdo5Qbc4GlJr530=; b=GULW4ZMat91vcH+rCBzzeIUbUVDkaWnD0WMfX3Py9vyOCztkA9zVeG27rB7xm0Siz1FqDpBVkM/Hskc/zl7Q9JEPgqFTOMvq5QU6rxepnAzUuzpG3wyRbrS3KqyzZzNaygQMeB2lQWSAbGmXqRQOCkJOEmQHJgxS0MGvWm/7D8eskAdBypDSSA9jF5ogA90xeF56joD/cYeUFC0SbRdXgEXmZ3lVWJe0TOPxzpdURJvh5M4sJSHwRdrh6Yhi0Wd1ArxUCk1DlsHzBTDgZbNAFZGOYE1TocT91XZ9tc1uOx1bSE8KoAiEMrT1WkUDoWwv1/TaMGhoQS3nqu7rvF67GA== 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=fQWnYQUS3QnAKwkf8IiaPo8zQmHWWdo5Qbc4GlJr530=; b=DJhIxjGd852pbP1/Ph1oNc319TPTC6x+KhTnoZEAsD2JIpBlm2GbLgFTOje2DdWv+U36tGrvqgBcZbsKROd3XnBsoakH4e/P4Ik/7mLOZjiRNN8Z1KmF7Nd61jPxWfbbC4Ir975R/sybVETPxR7E21dgzQMv4LhK1xl/YZDMgzA= 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 DM5PR12MB1273.namprd12.prod.outlook.com (2603:10b6:3:76::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3261.22; Mon, 10 Aug 2020 15:06:46 +0000 Received: from DM5PR12MB1929.namprd12.prod.outlook.com ([fe80::75ae:b862:547f:8ce7]) by DM5PR12MB1929.namprd12.prod.outlook.com ([fe80::75ae:b862:547f:8ce7%12]) with mapi id 15.20.3261.024; Mon, 10 Aug 2020 15:06:46 +0000 From: nitachra To: gdb-patches@sourceware.org, simark@simark.ca, tom@tromey.com Cc: JiniSusan.George@amd.com, nitachra Subject: [PATCH v2 1/2] DWARFv5: Handle DW_MACRO_define_strx and DW_MACRO_undef_strx macro entries. Date: Mon, 10 Aug 2020 20:36:27 +0530 Message-Id: <20200810150628.1587-1-Nitika.Achra@amd.com> X-Mailer: git-send-email 2.17.1 Content-Type: text/plain X-ClientProxiedBy: MA1PR0101CA0013.INDPRD01.PROD.OUTLOOK.COM (2603:1096:a00:21::23) 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 MA1PR0101CA0013.INDPRD01.PROD.OUTLOOK.COM (2603:1096:a00:21::23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3261.19 via Frontend Transport; Mon, 10 Aug 2020 15:06:44 +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: 3af6de88-82bd-4e84-100f-08d83d3effa3 X-MS-TrafficTypeDiagnostic: DM5PR12MB1273: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:6430; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 7OmQqA43uUtynimjlTwGHb0A18HvO8dttUPwwUgjnH/yBiP7ngnxhpiBCp3TeXe5UWJA718uXDEJirzrOHbjlMw4crvnO8EeZCaZHu+HYLgJBrm7gLH0MLem3Ki/jNX4/Vw7nRjNoiYUwbqU1aHshlj1iXNS/r9sbkvQrBU9iQVigP4WNG2qkMzQC0PD8XEN9Nf4ubcShZcUilXyXsb/xZ/BEdzf3J5sxOwMfLv3kBNbjW0hEthV7Yn1HH72japl5HbjccOglrA3Q8/Z0ZPFzOXkUk0fOGiZqx1+3zzG/GcbCQxpnBOtqAllyvR3nQOrIAsXkrWqgJN80P00++yL0A0ffZrcYP0cGtODkacU7ADCiScjGIiEXfDQ5Ezdpx5Z 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)(366004)(376002)(396003)(136003)(346002)(6486002)(1076003)(66556008)(66476007)(66946007)(316002)(2616005)(16526019)(26005)(186003)(2906002)(956004)(478600001)(8936002)(36756003)(5660300002)(83380400001)(6666004)(86362001)(8676002)(4326008)(52116002)(7696005)(43062003); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData: Bnsekj2pDZ3qbduyIzKxz6QCZVe9NaWsnvSzl4kC3kemYQn8W7IPAldGe/p+JxGnlNfMBa6SNnnqKuvB5JRBL+xxrtGM3xC7ckRC1rTraADRD/0NjnrtexaPh4//W1O+fRWGPryB7lnbct3Br+OFqpUpKL7mzW39Ca0wwqHW2uJ8rrw95oDtAJ+19q4W4AWFdK1KJq9o7d2tj7pndFEJ70u5CVCQIbo1Pre5vQ2pu/EMOn/0RQ9sdryvhTMmzB8r9Tw+r3mQeR+4JCDZf9RLxY/UScLbvVoVjlR6+jBvaqW41ZhVFcUG8haKk9ks+fxnh9HcYRIgc4l7OejtC7gSaejxrxp94Cxngxx+hD+6T2kOrShgJMgsrFbyi2vrSyXrCm9c1TVq9t0lZ6QUpI1T+CvENs1pByOXgj2j/hZSinZEMImGrl3ZuJjuRzN/Hth2oONlAhU7ahyFg88O7BDaovExMPPiwlrHcQ1JZqA1LruDjAFGjIVMZUM8NurWBcsFYU909LInz5oyf6rvecTVamlwyBnFyxMZiBB4EiykdS7y28RibT/ClXV6y3XQsV0stxb9khKnZvJ9wjHQ0dUlexCZBc6sCON25dSKnzdCUiVBcaO1C7HNT0GeTRpPoGfi51D8aU47ozmPsirBVfZ19w== X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: 3af6de88-82bd-4e84-100f-08d83d3effa3 X-MS-Exchange-CrossTenant-AuthSource: DM5PR12MB1929.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 10 Aug 2020 15:06:46.1387 (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: 6cCcyM4PO60zg34l05ON2JqgCw3mhV4eZ501d42uvVuKkuqWBqsDUCN4rNTrmFPft+1UlrYvOg95ZavR0vtVTg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR12MB1273 X-Spam-Status: No, score=-18.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: Mon, 10 Aug 2020 15:06:50 -0000 Hi Tom, Thanks for the review. >>> + const gdb_byte *info_ptr = (str_offsets_section->buffer >>> + + str_offsets_base >>> + + offset_index * offset_size); >>> + >>> + const char *macinfo_str = (macinfo_type == DW_MACRO_define_strx ? >>> + "DW_MACRO_define_strx" : >>> + "DW_MACRO_undef_strx"); >>> + >>> + if (str_offsets_base + offset_index * offset_size >>> + >= str_offsets_section->size) >>> + complaint (_("%s pointing outside of .debug_str_offsets section " >>> + "[in module %s]"), macinfo_str, objfile_name >>> + (objfile)); >>I think that, in addition to issuing a complaint, this code should probably not try to read the string. This is going to be an out-of-bounds read. Done >>> + ULONGEST str_offset; >>> + if (offset_size == 4) >>> + str_offset = bfd_get_32 (abfd, info_ptr); >>> + else >>> + str_offset = bfd_get_64 (abfd, info_ptr); >>I think this can use read_offset. Done >>> /* Return the .debug_loc section to use for CU. >>> diff --git a/gdb/macrotab.c b/gdb/macrotab.c index >>> 9ada436eaf..4ffb2d67cb 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; >>This seems to be an unrelated change. I have divided the patch in two. Please have a look. Regards, Nitika --- GDB complaints "During symbol reading: unrecognized DW_MACFINO opcode 0xb" with the testcase given below. 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/new_gdb/binutils-gdb/build/bin/gdb -q macro.out -ex "set complaints 1" -ex "start" Reading symbols from macro.out... During symbol reading: unrecognized DW_MACFINO opcode 0xb 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; (gdb) 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/ChangeLog: * dwarf2/macro.c (dwarf_decode_macro_bytes): Handle DW_MACRO_define_strx and DW_MACRO_undef_strx. (dwarf_decode_macros): Likewise * dwarf2/read.c (dwarf_decode_macros): Pass str_offsets_base in the parameters which is the value of DW_AT_str_offsets_base. * dwarf2/macro.h (dwarf_decode_macros): Modify the definition to include str_offsets_base. --- gdb/dwarf2/macro.c | 71 ++++++++++++++++++++++++++++++++++++++++++++-- gdb/dwarf2/macro.h | 3 ++ gdb/dwarf2/read.c | 21 +++++++++++++- 3 files changed, 91 insertions(+), 4 deletions(-) diff --git a/gdb/dwarf2/macro.c b/gdb/dwarf2/macro.c index d047d806f8..9208614564 100644 --- a/gdb/dwarf2/macro.c +++ b/gdb/dwarf2/macro.c @@ -427,6 +427,9 @@ 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, + struct dwarf2_section_info *str_section, + struct dwarf2_section_info *str_offsets_section, + ULONGEST str_offsets_base, htab_t include_hash) { struct objfile *objfile = per_objfile->objfile; @@ -561,6 +564,53 @@ 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 = read_unsigned_leb128 (abfd, mac_ptr, &bytes_read); + mac_ptr += bytes_read; + int offset_index = read_unsigned_leb128 (abfd, mac_ptr, &bytes_read); + mac_ptr += bytes_read; + + str_offsets_section->read (objfile); + const gdb_byte *info_ptr = (str_offsets_section->buffer + + str_offsets_base + + offset_index * offset_size); + + const char *macinfo_str = (macinfo_type == DW_MACRO_define_strx ? + "DW_MACRO_define_strx" : "DW_MACRO_undef_strx"); + + if (str_offsets_base + offset_index * offset_size + >= str_offsets_section->size) + { + complaint (_("%s pointing outside of .debug_str_offsets section " + "[in module %s]"), macinfo_str, objfile_name (objfile)); + break; + } + + ULONGEST str_offset = read_offset (abfd, info_ptr, offset_size); + + const char *body = str_section->read_string (objfile, str_offset, + macinfo_str); + if (current_file == nullptr) + { + /* 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 +721,8 @@ 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_section, str_offsets_section, + str_offsets_base, include_hash); htab_remove_elt (include_hash, (void *) new_mac_ptr); } @@ -712,7 +763,9 @@ 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, struct dwarf2_section_info *str_section, + struct dwarf2_section_info *str_offsets_section, + ULONGEST str_offsets_base, int section_is_gnu) { bfd *abfd; const gdb_byte *mac_ptr, *mac_end; @@ -814,6 +867,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 +925,6 @@ 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_section, str_offsets_section, + str_offsets_base, include_hash.get ()); } diff --git a/gdb/dwarf2/macro.h b/gdb/dwarf2/macro.h index d874068947..0a7ac55fc0 100644 --- a/gdb/dwarf2/macro.h +++ b/gdb/dwarf2/macro.h @@ -28,6 +28,9 @@ extern void dwarf_decode_macros (dwarf2_per_objfile *per_objfile, const struct line_header *lh, unsigned int offset_size, unsigned int offset, + dwarf2_section_info *str_section, + dwarf2_section_info *str_offsets_section, + 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 558fad74f8..845adb0325 100644 --- a/gdb/dwarf2/read.c +++ b/gdb/dwarf2/read.c @@ -23350,8 +23350,27 @@ dwarf_decode_macros (struct dwarf2_cu *cu, unsigned int offset, buildsym_compunit *builder = cu->get_builder (); + struct dwarf2_section_info *str_offsets_section; + struct dwarf2_section_info *str_section; + ULONGEST str_offsets_base; + + if (cu->dwo_unit != nullptr) + { + str_offsets_section = &cu->dwo_unit->dwo_file + ->sections.str_offsets; + str_section = &cu->dwo_unit->dwo_file->sections.str; + str_offsets_base = cu->header.addr_size; + } + else + { + str_offsets_section = &per_objfile->per_bfd->str_offsets; + str_section = &per_objfile->per_bfd->str; + 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_section, str_offsets_section, + str_offsets_base, section_is_gnu); } /* Return the .debug_loc section to use for CU. -- 2.17.1