From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from NAM11-CO1-obe.outbound.protection.outlook.com (mail-co1nam11on2043.outbound.protection.outlook.com [40.107.220.43]) by sourceware.org (Postfix) with ESMTPS id C4E78385DC02 for ; Mon, 30 Mar 2020 15:22:03 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org C4E78385DC02 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=V2cRrqRvTKypDmB2IT1qi6oXJaPRnz2YQn5PcLfAYHibpyNpT0Zg9urPsl/RCEtU0TdGb9igBkPKjaXdUEKwQdNKvsYVg3/KjVQU5PT5uESuJlNKDq10tXYaV1jCSdwRNfww9TwuskSIj0SB8vb5cyqDKIMf/GiLk8R82+8A05852IXcuutCEvric+0AElNkygVXkMR/Z+gjWMer2WWlfKhlO9W8NtwP3IT2gLj4jSkRWWmE1VFBLYTWtCaU+xYS8Zl97S0M4nvJgYm6hDD4SSWZXpsDpbYOEXNoHBLlva8W+tCwRLxtlMaSd2lWykfwVUtYLllepxf6ZmKVbLc6hw== 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=pcB+ufK709zyHjLaWAs2xKlGZMfuCB9M6yTR1NzaMD4=; b=a3HPxq5z98t+hC46xwV7YtTZt6ArRzikPOjQvrUuV10Kntokypl8gsigeonm4xuu6QlcQJEEhE3YN2Q2gsegKaAauPRYZ+ZvF9EV4N8pF8QcqGkow1r/WcVg/Wsdzib84HIQk+3gJm1+dOETRZ2C09LBngu4PEZlnnitQLcjo8mMbdFSzYcSFwVBitDHIQBDuIFFakO2vN2T3m32U1Gpf2Var4MTmP5vR2GJY/nz0WJrDoJV71ZaMpRipNl7/MC1kNDxX+u8vfDGMPONNgwyoOhDQD6sig83uFmInIn98pYT6STbA8AwqXBeIY+DbHOEugQ9clrUMta+EICtw95oEg== 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=pcB+ufK709zyHjLaWAs2xKlGZMfuCB9M6yTR1NzaMD4=; b=fT5nz+HevNLhgRJDUDvGcMnudO1XI7v2YkHgqTCgBx5umnCzUvGyBB0Y6FD8pJyEZKxiV96bEq/3G5oclKBSH4JwbsYhnW6vnOU4lzi52vU9VfhHczi9DHLSz5wNEFspHTDRA3HmRW3D9KHQ7ieWERAZxY5uzfpU8aoaPHz0o6k= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=Nitika.Achra@amd.com; Received: from SN6PR12MB2736.namprd12.prod.outlook.com (2603:10b6:805:75::30) by SN6PR12MB2845.namprd12.prod.outlook.com (2603:10b6:805:75::33) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2856.20; Mon, 30 Mar 2020 15:22:02 +0000 Received: from SN6PR12MB2736.namprd12.prod.outlook.com ([fe80::3cdb:5c47:4de4:9bc2]) by SN6PR12MB2736.namprd12.prod.outlook.com ([fe80::3cdb:5c47:4de4:9bc2%2]) with mapi id 15.20.2856.019; Mon, 30 Mar 2020 15:22:02 +0000 From: nitachra To: gdb-patches@sourceware.org, simark@simark.ca Cc: JiniSusan.George@amd.com, tom@tromey.com, nitachra Subject: [PATCH v2 1/3] Support for DW_AT_loclists_base and DW_FORM_loclistx. Date: Mon, 30 Mar 2020 20:51:34 +0530 Message-Id: <20200330152136.18688-1-Nitika.Achra@amd.com> X-Mailer: git-send-email 2.17.1 Content-Type: text/plain X-ClientProxiedBy: BM1PR0101CA0042.INDPRD01.PROD.OUTLOOK.COM (2603:1096:b00:1a::28) To SN6PR12MB2736.namprd12.prod.outlook.com (2603:10b6:805:75::30) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from BLR-5CG93516QQ.amd.com (165.204.158.249) by BM1PR0101CA0042.INDPRD01.PROD.OUTLOOK.COM (2603:1096:b00:1a::28) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2856.18 via Frontend Transport; Mon, 30 Mar 2020 15:21:59 +0000 X-Mailer: git-send-email 2.17.1 X-Originating-IP: [165.204.158.249] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: 41d6071e-5a1d-4a24-8b43-08d7d4be1883 X-MS-TrafficTypeDiagnostic: SN6PR12MB2845:|SN6PR12MB2845: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:4941; X-Forefront-PRVS: 0358535363 X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:SN6PR12MB2736.namprd12.prod.outlook.com; PTR:; CAT:NONE; SFTY:; SFS:(10009020)(4636009)(396003)(366004)(136003)(39860400002)(376002)(346002)(6666004)(4326008)(66476007)(66946007)(16526019)(26005)(52116002)(66556008)(7696005)(86362001)(186003)(316002)(81156014)(8676002)(81166006)(478600001)(1076003)(5660300002)(2906002)(956004)(2616005)(8936002)(36756003)(6486002)(43062003); DIR:OUT; SFP:1101; Received-SPF: None (protection.outlook.com: amd.com does not designate permitted sender hosts) X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: PYQIxSrTkKsf83PLBqPrgbP564eRjIHobKDasw0WX/CPqfOoa/yxQqILizU5YKQvji3ha3C4Lta73V9lrQicEmOcgQRDVhzGF7kfHExUEH5o3lW+RMMPgSDbYt5cHmWCh8j+0r+GmSfa5a+If/CiN1xIX7/4iyzdBpc3bN9cTVVBhTSCxKrDRL13bgNnDJxOqHinF2BGjjxCNd2D/jbM3oWbQjHQmcgAPDtqQjVyjr7ONCKQWGgmIgkXHTlkp4QwsHr0IjtvbX02OQW70lggtCNsQ9+dbu/HqkbNT2CVG9IC6poW6/e9CFFa2IsBCXePrAFlTbu931ZhicVVYtb0y0bPxP8PbtU+CzOkDmRlBS3WX53YN+1DHWjl+gEu6X1m5Y7BgdjmB8te3iQHt1PNfv4fE+BjI0OYU9vVGLU3hYtu7AXJLDgVQUQTssRqMhF78YHwKldgCimyg7mfjh2Ca0bega9tO3ZVg9LDvPRh+7/Vdr4fqQY7627Z945WH4VR X-MS-Exchange-AntiSpam-MessageData: juVx+4cxJDSqxO2WXLshD4AMBANGUkhf1dLGNA9871XHCwi6HkJdgg9rU6TP6CM6MEUZ1L4uf/t6C7ODNaNjHMPtd4s4KZSYdDTzcoApWxpxZ5Ko76LhLy6UJkXEcVvTA5SsRUjqcwbKfHOjpzkH/g== X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: 41d6071e-5a1d-4a24-8b43-08d7d4be1883 X-MS-Exchange-CrossTenant-OriginalArrivalTime: 30 Mar 2020 15:22:02.0670 (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: CAVH8SZLXXqUI84LFpXIUNLYIeXhI6tnkYrgPdXxcYmVyQ7603yfjinIJ4KiMEQOHQbKR47/ahE0gwFHIaNJgA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN6PR12MB2845 X-Spam-Status: No, score=-25.9 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, FORGED_SPF_HELO, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, MSGID_FROM_MTA_HEADER, RCVD_IN_DNSWL_NONE, 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, 30 Mar 2020 15:22:06 -0000 Thanks for the review. I have made all the style changes. Regards, Nitika --- This patch handles DW_AT_loclists_base and DW_FORM_loclistx. DW_AT_loclists_base is a new attribute added in DWARFv5 which points to the beginning of the offset table of .debug_loclists section. Reference to the location list (DW_FORM_loclistx) is interpreted relative to this base. DW_FORM_loclistx is a new form added in DWARFv5 which is used to access location list. Tested by running the testsuite before and after the patch and there is no increase in the number of test cases that fails. Tested with both -gdwarf-4 and -gdwarf-5 flags. Also tested -gsplit-dwarf along with -gdwarf-4 as well as -gdwarf5 flags. Used clang 10.0.0 for testing. gdb/dwarf2/ChangeLog: *read.c (cu_debug_loc_section): Added the declaration for the function. (read_loclist_index): New function declaration. (lookup_loclist_base): New function declaration. (read_loclist_header): New function declaration (dwarf2_cu): Added loclist_base and loclist_header field. (dwarf2_locate_dwo_sections): Handle .debug_loclists.dwo section. (read_full_die_1): Read the value of DW_AT_loclists_base. (read_attribute_reprocess): Handle DW_FORM_loclistx. (read_attribute_value): Handle DW_FORM_loclistx. (skip_one_die): Handle DW_FORM_loclistx. (loclist_header): New structure declaration. *attribute.c (form_is_section_offset): Handle DW_FORM_loclistx. gdb/testsuite/ChangeLog: *gdb.dwarf2/dw5-form-loclistx.exp: New file. *gdb.dwarf2/dw5-form-loclistx.c: New file. Signed-off-by: nitachra --- gdb/dwarf2/attribute.c | 3 +- gdb/dwarf2/read.c | 131 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 133 insertions(+), 1 deletion(-) diff --git a/gdb/dwarf2/attribute.c b/gdb/dwarf2/attribute.c index 0e5a8c8f53..9ceacf0409 100644 --- a/gdb/dwarf2/attribute.c +++ b/gdb/dwarf2/attribute.c @@ -78,7 +78,8 @@ attribute::form_is_section_offset () const { return (form == DW_FORM_data4 || form == DW_FORM_data8 - || form == DW_FORM_sec_offset); + || form == DW_FORM_sec_offset + || form == DW_FORM_loclistx); } /* See attribute.h. */ diff --git a/gdb/dwarf2/read.c b/gdb/dwarf2/read.c index 8c5046ef41..556c3ab873 100644 --- a/gdb/dwarf2/read.c +++ b/gdb/dwarf2/read.c @@ -114,6 +114,12 @@ static int dwarf2_loclist_index; static int dwarf2_locexpr_block_index; static int dwarf2_loclist_block_index; +/* Size of .debug_loclists section header for 32-bit DWARF format. */ +#define LOCLIST_HEADER_SIZE32 12 + +/* Size of .debug_loclists section header for 64-bit DWARF format. */ +#define LOCLIST_HEADER_SIZE64 20 + /* An index into a (C++) symbol name component in a symbol name as recorded in the mapped_index's symbol table. For each C++ symbol in the symbol table, we record one entry for the start of each @@ -346,6 +352,30 @@ dwop_section_names = /* local data types */ +/* The location list section (.debug_loclists) begins with a header, + which contains the following information. */ +struct loclist_header +{ + /* A 4-byte or 12-byte length containing the length of the + set of entries for this compilation unit, not including the + length field itself. */ + unsigned int length; + + /* A 2-byte version identifier. */ + short version; + + /* A 1-byte unsigned integer containing the size in bytes of an address on + the target system. */ + unsigned char addr_size; + + /* A 1-byte unsigned integer containing the size in bytes of a segment selector + on the target system. */ + unsigned char segment_collector_size; + + /* A 4-byte count of the number of offsets that follow the header. */ + unsigned int offset_entry_count; +}; + /* Type used for delaying computation of method physnames. See comments for compute_delayed_physnames. */ struct delayed_method_info @@ -493,6 +523,9 @@ struct dwarf2_cu whether the DW_AT_ranges attribute came from the skeleton or DWO. */ ULONGEST ranges_base = 0; + /* The DW_AT_loclists_base attribute if present. */ + gdb::optional loclist_base; + /* When reading debug info generated by older versions of rustc, we have to rewrite some union types to be struct types with a variant part. This rewriting must be done after the CU is fully @@ -1303,6 +1336,9 @@ static void read_variable (struct die_info *die, struct dwarf2_cu *cu); static int dwarf2_ranges_read (unsigned, CORE_ADDR *, CORE_ADDR *, struct dwarf2_cu *, dwarf2_psymtab *); +/* Return the .debug_loclists section to use for cu. */ +static struct dwarf2_section_info *cu_debug_loc_section (struct dwarf2_cu *cu); + /* How dwarf2_get_pc_bounds constructed its *LOWPC and *HIGHPC return values. Keep the items ordered with increasing constraints compliance. */ enum pc_bounds_kind @@ -8564,6 +8600,7 @@ skip_one_die (const struct die_reader_specs *reader, const gdb_byte *info_ptr, case DW_FORM_GNU_addr_index: case DW_FORM_GNU_str_index: case DW_FORM_rnglistx: + case DW_FORM_loclistx: info_ptr = safe_skip_leb128 (info_ptr, buffer_end); break; case DW_FORM_indirect: @@ -12029,6 +12066,11 @@ dwarf2_locate_dwo_sections (bfd *abfd, asection *sectp, void *dwo_sections_ptr) dwo_sections->loc.s.section = sectp; dwo_sections->loc.size = bfd_section_size (sectp); } + else if (section_is_p (sectp->name, &names->loclists_dwo)) + { + dwo_sections->loclists.s.section = sectp; + dwo_sections->loclists.size = bfd_section_size (sectp); + } else if (section_is_p (sectp->name, &names->macinfo_dwo)) { dwo_sections->macinfo.s.section = sectp; @@ -17496,6 +17538,10 @@ read_full_die_1 (const struct die_reader_specs *reader, if (attr != nullptr) cu->str_offsets_base = DW_UNSND (attr); + attr = die->attr (DW_AT_loclists_base); + if (attr != nullptr) + cu->loclist_base = DW_UNSND (attr); + auto maybe_addr_base = die->addr_base (); if (maybe_addr_base.has_value ()) cu->addr_base = *maybe_addr_base; @@ -18298,6 +18344,81 @@ partial_die_info::fixup (struct dwarf2_cu *cu) fixup_called = 1; } +/* Read the .debug_loclists header contents from the given SECTION in the HEADER. */ +static void +read_loclist_header (struct loclist_header *header, struct dwarf2_section_info *section) +{ + unsigned int bytes_read; + bfd *abfd = section->get_bfd_owner (); + const gdb_byte *info_ptr = section->buffer; + header->length = read_initial_length (abfd, info_ptr, &bytes_read); + info_ptr += bytes_read; + header->version = read_2_bytes (abfd, info_ptr); + info_ptr += 2; + header->addr_size = read_1_byte (abfd, info_ptr); + info_ptr += 1; + header->segment_collector_size = read_1_byte (abfd, info_ptr); + info_ptr += 1; + header->offset_entry_count = read_4_bytes (abfd, info_ptr); +} + +/* Return the DW_AT_loclists_base value for the CU. */ +static ULONGEST +lookup_loclist_base (struct dwarf2_cu *cu) +{ + /* For the .dwo unit, the loclist_base points to the first offset following + the header. The header consists of the following entities- + 1. Unit Length (4 bytes for 32 bit DWARF format, and 12 bytes for the 64 bit format) + 2. version (2 bytes) + 3. address size (1 byte) + 4. segment selector size (1 byte) + 5. offset entry count (4 bytes) + These sizes are derived as per the DWARFv5 standard. */ + if (cu->dwo_unit != nullptr) + { + if (cu->header.initial_length_size == 4) + return LOCLIST_HEADER_SIZE32; + return LOCLIST_HEADER_SIZE64; + } + return *cu->loclist_base; +} + +/* Given a DW_FORM_loclistx value LOCLIST_INDEX, fetch the offset from the array + of offsets in the .debug_loclists section. */ +static CORE_ADDR +read_loclist_index (struct dwarf2_cu *cu, ULONGEST loclist_index) +{ + struct dwarf2_per_objfile *dwarf2_per_objfile + = cu->per_cu->dwarf2_per_objfile; + struct objfile *objfile = dwarf2_per_objfile->objfile; + bfd *abfd = objfile->obfd; + ULONGEST loclist_base = lookup_loclist_base (cu); + struct dwarf2_section_info *section = cu_debug_loc_section (cu); + + section->read (objfile); + if (section->buffer == NULL) + complaint(_("DW_FORM_loclistx used without .debug_loclists section [in module %s]"), + objfile_name (objfile)); + struct loclist_header header; + read_loclist_header (&header, section); + if (loclist_index >= header.offset_entry_count) + complaint(_("DW_FORM_loclistx pointing outside of " + ".debug_loclists offset array [in module %s]"), + objfile_name (objfile)); + if (loclist_base + loclist_index * cu->header.offset_size + >= section->size) + complaint(_("DW_FORM_loclistx pointing outside of " + ".debug_loclists section [in module %s]"), + objfile_name (objfile)); + const gdb_byte *info_ptr + = section->buffer + loclist_base + loclist_index * cu->header.offset_size; + + if (cu->header.offset_size == 4) + return bfd_get_32 (abfd, info_ptr) + loclist_base; + else + return bfd_get_64 (abfd, info_ptr) + loclist_base; +} + /* Process the attributes that had to be skipped in the first round. These attributes are the ones that need str_offsets_base or addr_base attributes. They could not have been processed in the first round, because at the time @@ -18313,6 +18434,9 @@ read_attribute_reprocess (const struct die_reader_specs *reader, case DW_FORM_GNU_addr_index: DW_ADDR (attr) = read_addr_index (cu, DW_UNSND (attr)); break; + case DW_FORM_loclistx: + DW_UNSND (attr) = read_loclist_index (cu, DW_UNSND (attr)); + break; case DW_FORM_strx: case DW_FORM_strx1: case DW_FORM_strx2: @@ -18417,6 +18541,13 @@ read_attribute_value (const struct die_reader_specs *reader, DW_UNSND (attr) = cu->header.read_offset (abfd, info_ptr, &bytes_read); info_ptr += bytes_read; break; + case DW_FORM_loclistx: + { + *need_reprocess = true; + DW_UNSND (attr) = read_unsigned_leb128 (abfd, info_ptr, &bytes_read); + info_ptr += bytes_read; + } + break; case DW_FORM_string: DW_STRING (attr) = read_direct_string (abfd, info_ptr, &bytes_read); DW_STRING_IS_CANONICAL (attr) = 0; -- 2.17.1