From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from wmauth2.doit.wisc.edu (wmauth2.doit.wisc.edu [144.92.197.222]) by sourceware.org (Postfix) with ESMTPS id 8FC68386F434 for ; Sat, 6 Jun 2020 01:02:41 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 8FC68386F434 Received: from NAM10-BN7-obe.outbound.protection.outlook.com (mail-bn7nam10lp2105.outbound.protection.outlook.com [104.47.70.105]) by smtpauth2.wiscmail.wisc.edu (Oracle Communications Messaging Server 8.0.2.4.20190812 64bit (built Aug 12 2019)) with ESMTPS id <0QBH007BPAQZTX40@smtpauth2.wiscmail.wisc.edu> for elfutils-devel@sourceware.org; Fri, 05 Jun 2020 19:30:36 -0500 (CDT) X-Wisc-Env-From-B64: ZGFyb2NoYXBpbmhlQHdpc2MuZWR1 X-Spam-PmxInfo: Server=avs-2, Version=6.4.7.2805085, Antispam-Engine: 2.7.2.2107409, Antispam-Data: 2020.6.6.2417, AntiVirus-Engine: 5.74.0, AntiVirus-Data: 2020.5.19.5740000, SenderIP=[104.47.70.105] ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=S87djN0I1YV2GYCGV7JVbfg8TbLQRo4uKiw+dpWObSD1YqOY7h0P3ZdzlWHP4Ge6HE/gYVAD6dfjWsQ1272o4h0gPwQqxqwUhfIshpc6XOUt0Z2GfaIrp9GDboidrPJS8H+LZt+p5RZlNtMvk7zO6sfidexOHXySOlCopFLpcUQrRDyYGortWlpzIc4GydZyOklxJDOlZFdumGXI1nS1Af2ety+ThOg1sms+5fBiHWJbWRGvmWwQKcVZQbyylA5Qnj6mZ55hK4B1/9PFSk/sdvJg94Ouss8MQXFyOdNZUT5lx7VuENQjTpUOzATxYHxj56ML5kF0opets8cGUhsTmA== 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=SIQpI2tLMM4fVI+2Xk5ID4T7+Ky+4otPPEZFi8s1f4Y=; b=fDDNW2LYGwT4GYjpJNCeItmhYQyLCrsivkK58ushakNgrrUYzaOHG4JAIAWlWdYHV+raYh+bzIgO73YnMQykmIE3XUja98tD9sZD2VH9UXNCH8Zjepg5L78Yyxuq/JpkwduW3xupMeDYDO7E1m9HUy12SsQ5VN9X+/DpNg2CvnM4q8UC7W2JQUzmus49er7nEz5y+U51/o6t+taJ4WGBE+gwWC2DWZlOMG10GFmBkw5oyLdD+EaYZ0bxg1n7tFCSkPEXMx8SQtcS0IZwQrNsxLrj2MjfuYrnBIZUf1ds8OQiwNIL7yLXJ0HOqE9P4LtDhCwTBH3QLkF2CsQqeZQgZg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=wisc.edu; dmarc=pass action=none header.from=wisc.edu; dkim=pass header.d=wisc.edu; arc=none Received: from DM5PR06MB3115.namprd06.prod.outlook.com (2603:10b6:4:42::37) by DM5PR06MB3131.namprd06.prod.outlook.com (2603:10b6:4:3f::23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3066.19; Sat, 6 Jun 2020 00:30:34 +0000 Received: from DM5PR06MB3115.namprd06.prod.outlook.com ([fe80::6081:d9ec:42a5:ce54]) by DM5PR06MB3115.namprd06.prod.outlook.com ([fe80::6081:d9ec:42a5:ce54%6]) with mapi id 15.20.3066.019; Sat, 6 Jun 2020 00:30:34 +0000 From: Sasha Da Rocha Pinheiro To: Mark Wielaard , "elfutils-devel@sourceware.org" Subject: Re: location list Thread-topic: location list Thread-index: AQHWOOe462cU6I0Nz02M96DfbJ8gBKjFkjiAgAAM3+uABSA4hg== Date: Sat, 6 Jun 2020 00:30:34 +0000 Message-id: References: , , In-reply-to: Accept-Language: en-US, pt-BR Content-language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: X-Originating-IP: [71.90.118.165] x-ms-publictraffictype: Email x-ms-office365-filtering-ht: Tenant x-ms-office365-filtering-correlation-id: 47cbba24-1008-4753-8e50-08d809b0d3c1 x-ms-traffictypediagnostic: DM5PR06MB3131: x-microsoft-antispam-prvs: x-ms-oob-tlc-oobclassifiers: OLM:8882; x-forefront-prvs: 04267075BD x-ms-exchange-senderadcheck: 1 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: gTjhrGaHRqH4RBixU2MMmeV2grI762aRt+pylwbQUqe876wsVfoJ3Yz+xdA8IJj7I7PhXnLUXUFAEP4kRR8U5cTSHvwnm/sameRpMSNV76aOXnPjqmdzer9WU/iwQSN0zPURsRmNMTQ0xCPeLl3wsbXpAGj1V/9rba3J9HEkHetmA9K4ETONmDX/+rmUd1iwmwTT9gzHmoXF15YvkBHldSD4BuD5f7O/G91f0/2rQY/EF+KoAfiibUlY2UzLmg7otHIE9q2oknz4L/f5Nh0PqKAO2gGYvfUUrPgxqe2s4wIGeE52tWWodrKuipfj90uQc7RqlzHdk3m0e2osgo730Q== X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:DM5PR06MB3115.namprd06.prod.outlook.com; PTR:; CAT:NONE; SFTY:; SFS:(136003)(396003)(366004)(346002)(39860400002)(376002)(6506007)(26005)(3480700007)(7696005)(7116003)(75432002)(8676002)(186003)(2906002)(55016002)(8936002)(9686003)(786003)(86362001)(33656002)(64756008)(53546011)(71200400001)(52536014)(66946007)(5660300002)(66446008)(66556008)(76116006)(478600001)(110136005)(66476007)(83380400001)(316002); DIR:OUT; SFP:1101; x-ms-exchange-antispam-messagedata: gyvWQ12iwcKrRS70ciLlA6zTmpceUqH3bI8/NyUe4gZf2NwurZ/A9FGoTBqdYgjm0gyHU0wvBuCRg1Xt3CtcOA/PwUsz6YpdXn5cG/4+zk5zNZHAVtFOtrNr1ji4GJpnXU99kwLRKabt1rxPJhLvu7x+4mR1wDPUBgTZWwtF5jhEozPv3VDogIz8bQNOognIFYyp1fJEgV6WOhctfywwP4M1E5Oxl8hS82+0Oqq1m4CSb+7v5O4haFfQkMkjUz4VzU9bodYgQ9NEKNHflbFIljYZ2m08aI6dGfVnhXwAKWgpyZxHb4yFlhNvlqk4UbA2KLPE0tIo5ioPOc44qtyXTZTRGfH72q8Yah1gm8MmMwY2JbiM6dx57zGEhVDqw4DzYgpylVpDxEclVep5J1M27+HKYlUexAMfmx8jaG+qkPfWkzt/AXHIoz5GNCnmXvQZ/iTpjg2urliDBrGtyLRtqfMcz4gW22MOE5iUaOKyHAI= x-ms-exchange-transport-forked: True Content-type: text/plain; charset="iso-8859-1" Content-transfer-encoding: quoted-printable MIME-version: 1.0 X-OriginatorOrg: wisc.edu X-MS-Exchange-CrossTenant-Network-Message-Id: 47cbba24-1008-4753-8e50-08d809b0d3c1 X-MS-Exchange-CrossTenant-OriginalArrivalTime: 06 Jun 2020 00:30:34.3107 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 2ca68321-0eda-4908-88b2-424a8cb4b0f9 X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: ubdASVAb18oAtdKENvndxopJCzJB8TfmcERjv0lgX/vEELGtkZe0j5zDEMXfIlNBKUl5hT3BCsVs5Nu7YpS/Gw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR06MB3131 X-Spam-Status: No, score=-0.6 required=5.0 tests=BAYES_00, BODY_8BITS, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, SPF_HELO_PASS, SPF_PASS, 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: elfutils-devel@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Elfutils-devel mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 06 Jun 2020 01:02:43 -0000 As you can see the following variables have distinct locations:=0A= [ 81] variable abbrev: 5=0A= name (string) "a"=0A= decl_file (data1) sasha.c (1)=0A= decl_line (data1) 12=0A= type (ref4) [ cd]=0A= location (sec_offset) location list [ 0]=0A= [ 9f] variable abbrev: 5=0A= name (string) "g"=0A= decl_file (data1) sasha.c (1)=0A= decl_line (data1) 15=0A= type (ref4) [ cd]=0A= location (sec_offset) location list [ 4a]= =0A= [ bd] variable abbrev: 5=0A= name (string) "z"=0A= decl_file (data1) sasha.c (1)=0A= decl_line (data1) 16=0A= type (ref4) [ cd]=0A= location (sec_offset) location list [ 6e]= =0A= =0A= But when I use the code I sent before to list the three variables, I always= get:=0A= =0A= [main01.cpp:73] - Variable and location found (a), size(1).=0A= [main01.cpp:78] - interval: (0x0,0x5) =0A= [main01.cpp:78] - interval: (0x5,0xa) =0A= [main01.cpp:78] - interval: (0x16,0x24) =0A= [main01.cpp:73] - Variable and location found (g), size(1).=0A= [main01.cpp:78] - interval: (0x0,0x5) =0A= [main01.cpp:78] - interval: (0x5,0xa) =0A= [main01.cpp:78] - interval: (0x16,0x24) =0A= [main01.cpp:73] - Variable and location found (z), size(1).=0A= [main01.cpp:78] - interval: (0x0,0x5) =0A= [main01.cpp:78] - interval: (0x5,0xa) =0A= [main01.cpp:78] - interval: (0x16,0x24) =0A= =0A= =0A= No matter the locationAttribute the code always get the first location desc= riptors in .debug_loc: =0A= =0A= DWARF section [ 7] '.debug_loc' at offset 0x1c6:=0A= =0A= CU [ b] base: .text+000000000000000000
=0A= [ 0] range 0, 5=0A= .text+000000000000000000
..=0A= .text+0x0000000000000004 =0A= [ 0] lit0=0A= [ 1] stack_value=0A= range 5, a=0A= .text+0x0000000000000005 ..=0A= .text+0x0000000000000009 =0A= [ 0] reg1=0A= range 16, 24=0A= .text+0x0000000000000016 ..=0A= .text+0x0000000000000023 =0A= [ 0] reg1=0A= [ 4a] range 0, 5=0A= .text+000000000000000000
..=0A= .text+0x0000000000000004 =0A= [ 0] lit0=0A= [ 1] stack_value=0A= [ 6e] range 5, a=0A= .text+0x0000000000000005 ..=0A= .text+0x0000000000000009 =0A= [ 0] lit0=0A= [ 1] stack_value=0A= range a, e=0A= .text+0x000000000000000a ..=0A= .text+0x000000000000000d =0A= [ 0] const4u 65537=0A= [ 5] breg0 0=0A= [ 7] minus=0A= [ 8] stack_value=0A= =0A= =0A= =0A= Sasha=0A= =0A= From: Sasha Da Rocha Pinheiro =0A= Sent: Tuesday, June 2, 2020 1:12 PM=0A= To: Mark Wielaard ; elfutils-devel@sourceware.org =0A= Subject: Re: location list =0A= =A0=0A= Well, I have been trying to use the Dwarf_Attribute.=0A= If you see the snippet below, locationAttribute is acquired by doing dwarf_= attr(&e, DW_AT_location, &locationAttribute);=0A= and &e is the DW_TAG_variable DIE.=0A= =0A= =A0=A0=A0=A0=A0=A0=A0 Dwarf_Op * exprs =3D NULL;=0A= =A0=A0=A0=A0=A0=A0=A0 size_t exprlen =3D 0;=0A= =A0=A0=A0=A0=A0=A0=A0 std::vector locDescs;=0A= =A0=A0=A0=A0=A0=A0=A0 ptrdiff_t offset =3D 0;=0A= =A0=A0=A0=A0=A0=A0=A0 Dwarf_Addr basep, start, end;=0A= =A0=A0=A0=A0=A0=A0=A0 do {=0A= =A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 offset =3D dwarf_getlocations(&locationAt= tribute, offset, &basep,=0A= =A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 &start, &end, &ex= prs, &exprlen);=0A= =A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 if(offset=3D=3D-1) return false;=0A= =A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 if(offset=3D=3D0) break;=0A= =A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 LocDesc ld;=0A= =A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 ld.ld_lopc =3D start;=0A= =A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 ld.ld_hipc =3D end;=0A= =A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 ld.dwarfOp =3D exprs;=0A= =A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 ld.opLen =3D exprlen;=0A= =A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 locDescs.push_back(ld);=0A= =A0=A0=A0=A0=A0=A0=A0 }while(offset > 0);=0A= =0A= But what happens here is I always get the very first entry in .debug_loc. W= here clearly for this variable, the location list (sec_offset) is at [=A0= =A0=A0 4a] of that section.=0A= Maybe I am using the offset or the basep wrongly?=0A= =0A= =0A= Sasha=0A= =0A= =0A= =0A= =0A= From: Mark Wielaard =0A= Sent: Tuesday, June 2, 2020 12:19 PM=0A= To: Sasha Da Rocha Pinheiro ; elfutils-devel@sourcew= are.org =0A= Subject: Re: location list =0A= =A0=0A= Hi,=0A= =0A= On Tue, 2020-06-02 at 14:18 +0000, Sasha Da Rocha Pinheiro wrote:=0A= > I am trying to parse a location list given as an sec_offset. =0A= > How do I get this offset value that points to .debug_loc so I can=0A= > call dwarf_getlocations()?=0A= > Should I pass this offset as the second parameter of this call? =0A= =0A= Normally an offset isn't enough information to resolve an DIE attribute=0A= reference. So if at all possible you should try to use an=0A= Dwarf_Attribute you got from some DIE.=0A= =0A= It isn't really supported, but you could try creating a "fake"=0A= attribute that carries all information. e.g.=0A= =0A= Dwarf_Attribute loc_attr;=0A= loc_attr.code =3D DW_AT_location;=0A= loc_attr.form =3D DW_FORM_data4; /* Assuming 32bit DWARF.=A0 */=0A= loc_attr.valp =3D &offset; /* Your offset should be a 32bit type.=A0 */=0A= loc_attr.cu =3D cu;=0A= =0A= dwarf_getlocations (&loc_attr, offset, ...);=0A= =0A= Note that the CU needs to be version 3 or lower for the above to work.=0A= If the CU is > 3 then the only correct form to use is=0A= DW_FORM_sec_offset, and your valp should point to a uleb128 encoded=0A= offset value.=0A= =0A= But in general I would not recommend this approach. It isn't really=0A= supported. And some code might do sanity checks on the valp pointer and=0A= decide it looks bogus and just error out. Also you have to have a valid=0A= Dwarf_CU pointer around because you cannot create a valid fake CU=0A= easily.=0A= =0A= So try to keep a reference (or copy) around of the Dwarf_Attribute from=0A= which you got this offset and use that for your dwarf_getlocations=0A= call.=0A= =0A= Cheers,=0A= =0A= Mark=