From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from NAM11-BN8-obe.outbound.protection.outlook.com (mail-bn8nam11on2064.outbound.protection.outlook.com [40.107.236.64]) by sourceware.org (Postfix) with ESMTPS id 085113857C52 for ; Wed, 12 May 2021 17:31:11 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 085113857C52 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=NmzbJcZYvn8mKmwleWHYh34YJ0rmaMVqxp90/5Urk/7sONnXFCFDi9PNel+oQzBxn597ClyDFF5B5s0zJTQ70ddQtGQvZw4DVOxvl6LWTBF0nKo8SEIie2gSnRHrqL0cC2hqHPGcYjBSw39qZ040DSGj7YqJPhaUgokhNLdtPbZnw6zjF9y1qNOZKgvr9xX4khqgNuAdTXuGrBenTFeQdVR5Ffvm6B7uU+KVC/uyA8qZ1lFDxYmQc02jrfFdo9Ky0WjcfRvCm9fAjqpcgILG2ODe2H6cItuFKwrexysFA73YIAYRfGxQid+uF2+oS63y2hJd8/15aZTJYiTXhk1JZA== 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=TyJTGxcg9NivT9q+8ZiwWKIc6D/TzlgLV5JC1RHXwxo=; b=L7J1ggLlwNnAE7kVbJFQ2duiTfQN+Q8bpbQ09JJWVeHV0As0tibT6S25z8EFjojufQDAhHEGw/XFEkR9Vf5xFg/WeBuYbbW2tVXyRzJjCm/HtNlR8nZXoYDi9iKjh3bSUreXq6C1uPVudMg8qx0hUH4D1yT/D+Dwn+Vb+4STmG/2C1vDgHYcnJf9LrAOPb9qHFuHU0nIh83wTVJoxhOCQydK1Cr3qbo5beT1KN7EM6SEdSWHRYQL28jNDl8ORx8SfsbD3H/25recNUWYYJyx1lM7fmiDFrqIHzLAv1LQ64r/4QNhZvzSyAs03ft4Nh6e5dZStmUUjHVryKqAIvKT7w== 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 Received: from DM4PR12MB5295.namprd12.prod.outlook.com (2603:10b6:5:39f::23) by DM6PR12MB5517.namprd12.prod.outlook.com (2603:10b6:5:1be::8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4129.25; Wed, 12 May 2021 17:31:08 +0000 Received: from DM4PR12MB5295.namprd12.prod.outlook.com ([fe80::54b5:5330:471e:a5be]) by DM4PR12MB5295.namprd12.prod.outlook.com ([fe80::54b5:5330:471e:a5be%7]) with mapi id 15.20.4108.031; Wed, 12 May 2021 17:31:08 +0000 From: "Tomar, Sourabh Singh" To: "gdb-patches@sourceware.org" , "simon.marchi@polymtl.ca" Subject: RE: [PATCH] Fix macro info lookup for binaries containing DWARFv5 line table Thread-Topic: [PATCH] Fix macro info lookup for binaries containing DWARFv5 line table Thread-Index: AQHXR1K4Ez/SOOIC+Um9kNVPM6yW/6rgFzQA Date: Wed, 12 May 2021 17:31:07 +0000 Message-ID: References: <20210512171655.9463-1-SourabhSingh.Tomar@amd.com> In-Reply-To: <20210512171655.9463-1-SourabhSingh.Tomar@amd.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: msip_labels: MSIP_Label_0d814d60-469d-470c-8cb0-58434e2bf457_Enabled=true; MSIP_Label_0d814d60-469d-470c-8cb0-58434e2bf457_SetDate=2021-05-12T17:31:03Z; MSIP_Label_0d814d60-469d-470c-8cb0-58434e2bf457_Method=Privileged; MSIP_Label_0d814d60-469d-470c-8cb0-58434e2bf457_Name=Public_0; MSIP_Label_0d814d60-469d-470c-8cb0-58434e2bf457_SiteId=3dd8961f-e488-4e60-8e11-a82d994e183d; MSIP_Label_0d814d60-469d-470c-8cb0-58434e2bf457_ActionId=710219f4-4fa3-4b66-b05f-f31c3581b580; MSIP_Label_0d814d60-469d-470c-8cb0-58434e2bf457_ContentBits=1 x-originating-ip: [203.81.243.131] x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: 5b6614bb-82fd-46f6-c8f9-08d9156bba47 x-ms-traffictypediagnostic: DM6PR12MB5517: x-microsoft-antispam-prvs: x-ms-oob-tlc-oobclassifiers: OLM:9508; x-ms-exchange-senderadcheck: 1 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: AfbCZ33+FxqwQ4J4M0jzOk1Z9Ji+T4SyYlIZ0GEmMpo92t64ywQMntGM79ZoRywCGc2sRFqeTXAqyuhz+Ytd7Ut47h2FqyS7tzi5ufWF69pOD288188sdE51UwvIBzHadnzaeB/hnI6cTNHnJ5/5sbP5ktKqOG9KPW98MXuYJG0h2btgB26xRf/PDz1/aYzqjasdetxC+wLLyJs3dmqE415jy6QI4QfIG66LzCpxBkDDIHbGtSOpOnoDHRxvOv3KdVC4NEOTNpjW/eCqvqoUM4R2LR51jVPeaZXtHTLZgW4Ll3tcTCgc4rffZGEXIWSEM44sSo4vhzZGMrlOQtgzvpA8pvOP3N0ioRa8okUT/20LIzURlLjCCaHhvJaOF/esX6AyJFpgwn4CbEHJxUCsyPP6+Oiys3EikI5bg37visCBf2c68yKXWVflZa+4ODuygB0uczcvdiOP3Je2Wm5QfVgQJO0tNUOwxQy99Pr/6J0mmqDt/Z+V/5wc83R4pLZ5MrDrT/9ja5nT7XCKH2rqXF8MJz5OhBnsmRBNzYJR/zdmpcCa1mJGzJ+exHvdAAWCjilsVnMr65KU6rpN7qI+cg25r0Dn+wgaG+IXgpuVL36hcv5XVH8UpBnWgg27y3cDb2lcI/cJw73vLmvC2g66nAhWwyiIPQhsYoGx+TAWTzJTxerjlGEKX2FAlkpGv1FuXmWkBfWE+nsEhq0aRh/rcfSN7m35iyo/FMVJ3wlIsSg= x-forefront-antispam-report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:DM4PR12MB5295.namprd12.prod.outlook.com; PTR:; CAT:NONE; SFS:(4636009)(366004)(86362001)(33656002)(38100700002)(122000001)(66946007)(83380400001)(66446008)(66476007)(64756008)(71200400001)(66556008)(76116006)(7696005)(186003)(2906002)(55016002)(110136005)(8676002)(9686003)(8936002)(26005)(6506007)(53546011)(5660300002)(498600001)(52536014)(2004002); DIR:OUT; SFP:1101; x-ms-exchange-antispam-messagedata: =?us-ascii?Q?Z08UVK+PeLj335gxGAMH0FlLNHCZCg2aeHK4rRqKXgXQnKJDaznHz4vYgxWK?= =?us-ascii?Q?VpEiyjf9c9lGac/bJbi7hmp87Xb3Sgb+gUSpXva2Bxw1jyBmGZCJO9dJdyPB?= =?us-ascii?Q?JMlA6Y0h/3QUHsl8moTWhdp3WveHMTcp6G9GiR03sXHsl2hiLq4ZZqNw2EIq?= =?us-ascii?Q?eWjKOoALPM2it9CSIyIjpC6rRUekOH98snQ1zPNYLu2mmtb8MLDPcwSSLIK3?= =?us-ascii?Q?beyJDyZWtquqm9SI0fFS5HcudIELa7DXZqxTrd+aaVM4CLYNaMyfllBPGazO?= =?us-ascii?Q?01ZqJcyeP3w+jTOpXqleVF9tqbnq+UhpNZd6nGV1x9qBXwDSk/LK0icl7h/h?= =?us-ascii?Q?5q1WzWaTMQJwwZBpG1g7pgacXKjac20HBv+Z+4FA9KN5zGMYkglU1U+eZZCk?= =?us-ascii?Q?bSXRGZYENgH3c5oy6vpVo9TOTBi1j3iydsCZKcgBEIT4GDcZn2SaS2dQ8yQm?= =?us-ascii?Q?pC/o7t8Q8d6K6MvNKXegtYBx/6jVVqx5ZJ9FHxHGTo2c6S1NTFc5qCFqRFv/?= =?us-ascii?Q?wqq4egY+p+BDktJO0XuauXcKFjH3W43MeHwRmknfiTOY3AzET1uUPEtSQ9OE?= =?us-ascii?Q?JKOmQrXxyWpB73aNbpuzp2aGqFZCpg1hWReH+YWEMgBcpSnexrWtIfFx/WoT?= =?us-ascii?Q?aBF0buUF4fBlZTrnN5KcrmFiat9pgCwBfXW0eiiRIUyTb6EFMowM3Si2YBsN?= =?us-ascii?Q?sU0m5fGo355DJzz+dkENq2xEIGmOdaN2aKcVpF8Qz9Oe9JDHk5UWoc9dJ8dz?= =?us-ascii?Q?GxJX1UoZOCONAiPSmcmJD0gzmNuJgpo2B9aBQVl/WJugjkxKkbxwUKdBuAJ/?= =?us-ascii?Q?UvsWg2vudTFfy2V2kXkjdk5cBWUHuxihwF9CWpOmLdnBfcuUU0hRZPX1sGvC?= =?us-ascii?Q?4WY+SwQCITqN2JK+E63MB0PvGOWG3UP9oqEc/11oy5pb2nuDz7t2Q0PHASNc?= =?us-ascii?Q?Gqui0wMEJnHRoxt1QICMsbm8TXVWqY23xqQt5RoZQLTjavSKTbYX2M6L5qYT?= =?us-ascii?Q?eW7uxL+DnoiihnJcNfqrtufuhj814m+iZpXxJ8IN5CtZlP3WhqyBlfsK3rnz?= =?us-ascii?Q?/x3LVMENWQK0t0a/0wF2abkhgCcXw35zXbjPBuxIoqvSF1Uz7bKUS71ylhXF?= =?us-ascii?Q?Z9dkJDOQLGIo9OB1JM28e5fAu9X5VROFFx+yDwArzWI9AAj/2wy20w0WOOpY?= =?us-ascii?Q?qi6W5fSqEcZsyvWpbRiRjw/BLK4DcvzdfhHmMzlgEIPqI21aUC1mPN6vijTL?= =?us-ascii?Q?bEEhQ16PaC/aAFZfivyRD3jRZvuGWADxiHXLvSPBR6tCjSdVhvQZr+an9BpC?= =?us-ascii?Q?eYE=3D?= x-ms-exchange-transport-forked: True Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-AuthSource: DM4PR12MB5295.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: 5b6614bb-82fd-46f6-c8f9-08d9156bba47 X-MS-Exchange-CrossTenant-originalarrivaltime: 12 May 2021 17:31:07.9551 (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: RoSqbvGyV5gK2n1LHg01NpkdY78foQgDnLzYGroE85H96/7xBrTF3hygIP1srHYdo5FsTW5vgcXgCGS4NikpdQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR12MB5517 X-Spam-Status: No, score=-9.3 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, 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: 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: Wed, 12 May 2021 17:31:13 -0000 [AMD Public Use] Hello Simon, Thanks for the review comments. There was some configuration issue with my git send-mail thing*, apparently= the patch arrived but missed the reply to your review comments. I'll try to address them here: Comments: > Sorry for the delay, there are just so many patches to look at. No Problem, thanks for taking out time for reviewing this! >Ok, I think you're right. We want line_header::file_file_name to return t= he path to the file, relative to the compilation directory. In DWARF5, at = least with clang, the file at index 0 appears to always be >relative to the= compilation directory (directory at index 0). If I do: $ clang-11 test.c -o test -gdwarf-5 -fdebug-macro && llvm-dwarfdump -F = -color -debug-line test I get: .... If I move up a directory: $ clang-11 gdb/test.c -o test -gdwarf-5 -fdebug-macro && llvm-dwarfdump= -F -color -debug-line test ... > So it looks like by returning the filename as-is, we'll indeed return a p= ath to the file relative to the compilation directory. Yes, thanks for acknowledging the issue. > I made a test (took gdb.base/template.exp and modified it) with: > standard_testfile > file copy -force $srcdir/$subdir/$srcfile [standard_output_file $srcfi= le] > gdb_compile outputs/gdb.base/template/template.c $binfile executable {= debug} > This copies the source file in the "output" directory of the test, and co= mpiles it from there using a relative path. You can run it with clang & DW= ARF5 with: > $ make check TESTS=3D"gdb.base/template.exp" RUNTESTFLAGS=3D"--target_= board=3Dunix/gdb:debug_flags=3D-gdwarf-5 CC_FOR_TARGET=3Dclang" > So I think you could make a test based on this. Note that the test shoul= d work with gcc too, where you need to use -g3 in order to get macro inform= ation. A few tests (gdb.base/info-macros.exp, >gdb.base/macscp.exp, gdb.ba= se/style.exp, >gdb.linespec/macro-relative.exp) already deal with this, you can take a lo= ok. Speaking of gdb.linespec/macro-relative.exp, it would be worth looking= into it, it kind of looks related, but I am not sure. Thanks for the pointers, I've added a minimal test case that passes after t= his patch. > For next time, could you please try to send your patch using git-send-ema= il? It makes it easier to comment inline. Sure, patch is sent through git-send-email Review comment addressed in this patch: > Use present tense (e.g. Update, not Updated). > Watch the indentation. > You can shorten this comment to: > /* The file at index 0 (valid starting with DWARF 5) is already relative > to the compilation directory. */ > Use `file !=3D 0`. gdb/ChangeLog 2021-05-12 Sourabh Singh Tomar * dwarf2/line-header.c: Updated the comment and extended check in function `line_header::file_file_name` for DWARFv5 line tables. gdb/testsuite/ChangeLog 2021-05-12 Sourabh Singh Tomar * gdb.base/dwarf5-macro.exp: Add new tests. * gdb.base/dwarf5-macro.c: Likewise. Thanks, Sourabh Singh tomar -----Original Message----- From: Tomar, Sourabh Singh =20 Sent: Wednesday, May 12, 2021 10:47 PM To: gdb-patches@sourceware.org Cc: Tomar, Sourabh Singh Subject: [PATCH] Fix macro info lookup for binaries containing DWARFv5 line= table Consider following C test case: ``` cat test.c int main() { int a =3D OUT; } ``` Compiled as: `clang -gdwarf-5 -fdebug-macro test.c` Loading this bin into GDB and trying to access macro info, GDB is unable to= extract and display macro info correctly. ``` $gdb a.out (gdb) start (gdb) info macro OUT Temporary breakpoint 1 at 0x2016a8: file test.c, line 3. Starting program: /home/a.out (gdb) info macro OUT The symbol `OUT' has no definition as a C/C++ preprocessor macro at /home/t= est.c:-1 ``` The problems starts when processing file and dir indexes from DWARFv5 line = table. DWARFv5 specifies: - The current directory is explicitly present in the directories field. - The current compilation filename is explicitly present and has index 0. dir entry 0 contains the absoute path(Not including source filename). file entry 0 contains the source file name and refers dir 0. As one may notice that dir index `0` will always contain absoulte path(Not = including the file name as), this causes GDB to append the path + filename = to construt macro info `main_file->filename`. This leads to overriding of t= he macro filename which will cause macro info lookup failure due to mismatc= h in `main_file->filename` and `sal.symtab->filename`. This problem does not pops up with GCC compiled binaries, since GCC does no= t emits DWARFv5 compliant line tables. Testing: - NO regressing observed in `gdb.base` and associated macro based tests. gdb/ChangeLog 2021-05-12 Sourabh Singh Tomar * dwarf2/line-header.c: Updated the comment and extended check in function `line_header::file_file_name` for DWARFv5 line tables. gdb/testsuite/ChangeLog 2021-05-12 Sourabh Singh Tomar * gdb.base/dwarf5-macro.exp: Add new tests. * gdb.base/dwarf5-macro.c: Likewise. Change-Id: I09f39c8680fca382523f4ac72bcbd1018851b480 --- gdb/ChangeLog | 5 +++ gdb/dwarf2/line-header.c | 11 +++++-- gdb/testsuite/ChangeLog | 5 +++ gdb/testsuite/gdb.base/dwarf5-macro.c | 3 ++ gdb/testsuite/gdb.base/dwarf5-macro.exp | 43 +++++++++++++++++++++++++ 5 files changed, 64 insertions(+), 3 deletions(-) create mode 100644 gdb/= testsuite/gdb.base/dwarf5-macro.c create mode 100644 gdb/testsuite/gdb.base/dwarf5-macro.exp diff --git a/gdb/ChangeLog b/gdb/ChangeLog index d564621f4c6..98650ff8a60 1= 00644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,3 +1,8 @@ +2021-05-12 Sourabh Singh Tomar + + * dwarf2/line-header.c: Update the comment and extended + check in function `line_header::file_file_name` for + DWARFv5 line tables. 2021-05-12 George Barrett =20 * NEWS (Guile API): Note the addition of the new procedure. diff --git a/gdb/dwarf2/line-header.c b/gdb/dwarf2/line-header.c index 7575= 297f966..d79051d326e 100644 --- a/gdb/dwarf2/line-header.c +++ b/gdb/dwarf2/line-header.c @@ -64,7 +64,8 @@ gdb::unique_xmalloc_ptr line_header::file_file_nam= e (int file) const { /* Is the file number a valid index into the line header's file name - table? Remember that file numbers start with one, not zero. */ + table? Remember that file numbers start with zero for DWARFv5 and one + for DWARFv4 . */ if (is_valid_file_index (file)) { const file_entry *fe =3D file_name_at (file); @@ -72,7 +73,10 @@ lin= e_header::file_file_name (int file) const if (!IS_ABSOLUTE_PATH (fe->name)) { const char *dir =3D fe->include_dir (this); - if (dir !=3D NULL) + /* The file at index 0 (valid starting with DWARF 5) is already + relative to the compilation directory. */ + + if (file !=3D 0) return gdb::unique_xmalloc_ptr (concat (dir, SLASH_STRING, fe->name, (char *) NULL)); @@ -100,7 +104,8 @@ gdb::unique_xmalloc_ptr line_header::file_full_n= ame (int file, const char *comp_dir) const { /* Is the file number a valid index into the line header's file name - table? Remember that file numbers start with one, not zero. */ + table? Remember that file numbers start with zero for DWARFv5 and one + for DWARFv4 . */ if (is_valid_file_index (file)) { gdb::unique_xmalloc_ptr relative =3D file_file_name (file); di= ff --git a/gdb/testsuite/ChangeLog b/gdb/testsuite/ChangeLog index e0f64965= d94..66b395b1e4c 100644 --- a/gdb/testsuite/ChangeLog +++ b/gdb/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2021-05-12 Sourabh Singh Tomar + + * gdb.base/dwarf5-macro.exp: Add new tests. + * gdb.base/dwarf5-macro.c: Likewise. + 2021-05-12 George Barrett =20 * gdb.guile/scm-value.exp (test_value_in_inferior): Add test for diff --g= it a/gdb/testsuite/gdb.base/dwarf5-macro.c b/gdb/testsuite/gdb.base/dwarf5-= macro.c new file mode 100644 index 00000000000..0a7dc98c620 --- /dev/null +++ b/gdb/testsuite/gdb.base/dwarf5-macro.c @@ -0,0 +1,3 @@ +#define HELLO_GDB 1 +int main() { +} diff --git a/gdb/testsuite/gdb.base/dwarf5-macro.exp b/gdb/testsuite/gdb.ba= se/dwarf5-macro.exp new file mode 100644 index 00000000000..cf622cebe32 --- /dev/null +++ b/gdb/testsuite/gdb.base/dwarf5-macro.exp @@ -0,0 +1,43 @@ +# Copyright 2020-2021 Free Software Foundation, Inc. + +# This program is free software; you can redistribute it and/or modify=20 +# it under the terms of the GNU General Public License as published by=20 +# the Free Software Foundation; either version 3 of the License, or #=20 +(at your option) any later version. +# +# This program is distributed in the hope that it will be useful, # but=20 +WITHOUT ANY WARRANTY; without even the implied warranty of #=20 +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU=20 +General Public License for more details. +# +# You should have received a copy of the GNU General Public License #=20 +along with this program. If not, see . + +standard_testfile +set additional_flags {debug} +file copy -force $srcdir/$subdir/$srcfile [standard_output_file=20 +$srcfile] gdb_compile outputs/gdb.base/dwarf5-macro/dwarf5-macro.c=20 +$binfile executable {debug} + +get_compiler_info +if { [test_compiler_info "gcc-*"] } { + set options "additional_flags=3D-g3" +} elseif { [test_compiler_info "clang-*"] } { + set options "additional_flags=3D-gdwarf-5 -fdebug-macro" +} + +if { [prepare_for_testing "failed to prepare" \ + ${testfile} ${srcfile}] } { + return +} + +if { ![runto_main] } { + untested "could not run to main" + return +} + +set filepat {dwarf5-macro.[ch]} +set definition {} +set location {} +set nonzero {[1-9][0-9]*} +gdb_test "info macro HELLO_GDB" \ + ".*define HELLO_GDB 1" -- 2.17.1