From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id QWQODMMNnGC0YQAAWB0awg (envelope-from ) for ; Wed, 12 May 2021 13:17:55 -0400 Received: by simark.ca (Postfix, from userid 112) id 24A901F11C; Wed, 12 May 2021 13:17:55 -0400 (EDT) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on simark.ca X-Spam-Level: X-Spam-Status: No, score=-1.1 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,MAILING_LIST_MULTI,MSGID_FROM_MTA_HEADER,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.2 Received: from sourceware.org (server2.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by simark.ca (Postfix) with ESMTPS id 567C21E783 for ; Wed, 12 May 2021 13:17:52 -0400 (EDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id C5C043853832; Wed, 12 May 2021 17:17:51 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org C5C043853832 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1620839871; bh=lHnPJE7leTxl2v7foKvvkJC4DETAx7PqW1y/7Gr6GxU=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:Cc:From; b=HQwXayQ+KfhCpQ4kAPDhA8UOKhF2HdcYnvuSEKk0AVytXe9wtL7Z7SdcfDzQ3TcJr 9fUBgphuhIU4rsjD6MpOTNTMdH9w4f7nz+CBiOsQVvu7Yb403BI/bvla4WpAc40hav 8pcINvOVphj7if/gGvU0DTvODaRoWbjWd6c+pWfo= Received: from NAM10-MW2-obe.outbound.protection.outlook.com (mail-mw2nam10on2061.outbound.protection.outlook.com [40.107.94.61]) by sourceware.org (Postfix) with ESMTPS id 3DF33385382A for ; Wed, 12 May 2021 17:17:47 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 3DF33385382A ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=E8+RQ4qweO6efggGbF2SJBb9HaDbU3D76465W/p1bmBnT3J1aaoxlHqdNyY6iJuSj9/E3KXQLVlk1M8rOdS5A8UqVyQDpeZ6ZztG4gfJj8zvpk6VJpFAksbuKWams51ycMDF93X4FM0t3aFKDipooi9fXQ+SrL00zMHsrqn9R+vVuPixR8ylLejSByL11LyP/vh51PUZDf4CnENcm99Mc9GO5S+KusO70B61fWnBaDmvHpLwRY33wmge5jMYVV8aeY2nMWhrQTr/LaKKjCwnuTznA6kXHUmMEGFBBrcJrIGv0aKI/J6wIq/LqFZpuQlbQ3e8G+cmhC4DKnY2ZaMJ7g== 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=lHnPJE7leTxl2v7foKvvkJC4DETAx7PqW1y/7Gr6GxU=; b=grEN6iKj9+/+sraofjt96QCkoaakivb0iSJsxjFZWK5AvbWyqNpwfXLbDBKvucHCmM0IiiDZSqlTdaW89uvhijgB3o/eVQ5UkWT3zWeD9sFGjqYC8GwhGZVY4JzQVcciL/WkiWOxdJZNceudIBWGhpNwzMhkQjv+SOxn5CE8oBvCVFNA5h7oFBWGlNO7oQ6cQ/e3KqA6HxVGM4BJfZj7U+p7264znzbAKNhd16DP0S1rB4fsKYU17Bu7nP/GOG87JzowoKQ+nBGHcoH+T+9bHuyE6wcAsaBnZ6VYmYGR9RZwSP1A3jf5r0d5n1KieCqUXrPHaBblEOuYpD+R5SqBiA== 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 DM4PR12MB5327.namprd12.prod.outlook.com (2603:10b6:5:39e::21) 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:17:44 +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:17:43 +0000 To: gdb-patches@sourceware.org Subject: [PATCH] Fix macro info lookup for binaries containing DWARFv5 line table Date: Wed, 12 May 2021 22:46:55 +0530 Message-Id: <20210512171655.9463-1-SourabhSingh.Tomar@amd.com> X-Mailer: git-send-email 2.17.1 Content-Type: text/plain X-Originating-IP: [165.204.156.251] X-ClientProxiedBy: BM1PR01CA0106.INDPRD01.PROD.OUTLOOK.COM (2603:1096:b00::22) To DM4PR12MB5295.namprd12.prod.outlook.com (2603:10b6:5:39f::23) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from llvm-slrz2.amd.com (165.204.156.251) by BM1PR01CA0106.INDPRD01.PROD.OUTLOOK.COM (2603:1096:b00::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4108.25 via Frontend Transport; Wed, 12 May 2021 17:17:42 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: a3af7558-0adc-4021-0150-08d91569dace X-MS-TrafficTypeDiagnostic: DM4PR12MB5327: X-MS-Exchange-Transport-Forked: True 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: 7uuDv/JYJjwqhhzDiFNZTpTFsg/+ZM9rV3OphbL/nCd7E4GLVdqVAaiaVGWNn5AuO1xzhxhI63sSFmUUHwDP5kgykNZjtmjhRJIXPYX/KxRUoJ8lin/WgPWLupAlS03dDVuSRf/QdiZ1quRRQtRWe9PBlF6lmbEP95iuMT2Jse7Y/F40QM9dt4z2hESuqCaiEl31M+/2ZU4GsW1VOT+zkbxAO/6cfeQscsatu5KElou18bBmFv6prdjwvj492lt5zfYL8yYERk9xgnAeP7RSgm53/7jfeZ91W1bpV4EjrH/KmXVJCbCX706XbUQ0I/u0t6ZWI9mjMWKfPbOrVampwIKmNRTCpFVdJmPNtBAVxwtLjfR0vmdH95JtPaw/EebPsxQ97Y1PTwugujJ3QPaT3XraV/oCfQpzPEYCw/RmLR1mrZ86UQMzIuuOUpC3tbQlQxkIZZQQqIKO+0GF/9MaxlhwoA9XXeYTvOv9KoL6IfI3wspEbo8Zcagw0FAarVrLLEaYSY7YcMZcjnEemqwckt+PaW27Ip3OW32Y1+SJoSC7v6J46MpXdMIMg+0iC9Qu+4xpPWLvuFOewNYGCEDc5Og84qyEGM41pK5IEuMgMq8xwfCMZRAtppGaPTNUIYJawbCe4hnXhyX9nWMYfdRcmLdoOguJrkdOeh16e/mK5UZd6mMtG8+xS10tB6BfeVfFPVwrOHEWVVziX155ddBI4qyn2M/gXFV6LC4VgeKwe8aVdvUftFoNbzq41nj6419u 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)(376002)(136003)(39860400002)(396003)(366004)(346002)(36756003)(2616005)(86362001)(38350700002)(38100700002)(83380400001)(52116002)(66476007)(66946007)(6666004)(66556008)(956004)(4326008)(2906002)(316002)(8676002)(6486002)(6916009)(186003)(478600001)(1076003)(16526019)(26005)(8936002)(7696005)(5660300002)(2004002); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData: =?us-ascii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ytEu5sZOjXAujozsfFA/HWDd3Nn?= =?us-ascii?Q?YlWQR1UEEDP0Ejk+yDZmG/ZrQmI2eue/TKRnFQmogr7CI43I2/8Xx48zHaBV?= =?us-ascii?Q?DokMxEGwwpxaVB+lihAS5BHcETr0CfMcjPbG0Tmy6fehjgu5K4mPZJPHOurX?= =?us-ascii?Q?QgpLsetbpM7Y7ocUXi/1tycXVAfQ2HvDWqxksdBN4FirAkYmMlTCmEMVUN1m?= =?us-ascii?Q?C1/4htVcvbRXxqI7lADQRRuDAgIVF4E5gzwce9QBo0vKwauq15r6SJEbwqIQ?= =?us-ascii?Q?EpC6Qek5SBBCBHXhTa/ph6dPdfDfZXpvuKpdl2IIiPk238cbyaHwYNrPdbZp?= =?us-ascii?Q?C7DcXMV+BXClol2xg2yUweMjsDLg5BpEXm7kTvo1hf+v6bScwuLgU1OQcXjd?= =?us-ascii?Q?cKet9ZgFCNJEJRSlDab0RJFn5VyOueNnEcw1SB/C9J88x2AGN3a2pWAlp9//?= =?us-ascii?Q?NQtuxy0CRoBKTFTPVoRrfNvB?= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: a3af7558-0adc-4021-0150-08d91569dace X-MS-Exchange-CrossTenant-AuthSource: DM4PR12MB5295.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 12 May 2021 17:17:43.7653 (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: Vl4tYO/CLIjmW1CBkkfZhT4qCDbciShLYyry8Gauhtv2VQg2TNBkHvqg8Uu4rvD9NbueOZiR0B/lLL+NSTOtVQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM4PR12MB5327 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: , From: Sourabh Singh Tomar via Gdb-patches Reply-To: Sourabh Singh Tomar Cc: Sourabh Singh Tomar Errors-To: gdb-patches-bounces@sourceware.org Sender: "Gdb-patches" Consider following C test case: ``` cat test.c int main() { int a = 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/test.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 the macro filename which will cause macro info lookup failure due to mismatch in `main_file->filename` and `sal.symtab->filename`. This problem does not pops up with GCC compiled binaries, since GCC does not 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 100644 --- 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 * 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 7575297f966..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_name (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 = file_name_at (file); @@ -72,7 +73,10 @@ line_header::file_file_name (int file) const if (!IS_ABSOLUTE_PATH (fe->name)) { const char *dir = fe->include_dir (this); - if (dir != NULL) + /* The file at index 0 (valid starting with DWARF 5) is already + relative to the compilation directory. */ + + if (file != 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_name (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 = file_file_name (file); diff --git a/gdb/testsuite/ChangeLog b/gdb/testsuite/ChangeLog index e0f64965d94..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 * gdb.guile/scm-value.exp (test_value_in_inferior): Add test for diff --git 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.base/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 +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +standard_testfile +set additional_flags {debug} +file copy -force $srcdir/$subdir/$srcfile [standard_output_file $srcfile] +gdb_compile outputs/gdb.base/dwarf5-macro/dwarf5-macro.c $binfile executable {debug} + +get_compiler_info +if { [test_compiler_info "gcc-*"] } { + set options "additional_flags=-g3" +} elseif { [test_compiler_info "clang-*"] } { + set options "additional_flags=-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