From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from EUR05-DB8-obe.outbound.protection.outlook.com (mail-db8eur05on2075.outbound.protection.outlook.com [40.107.20.75]) by sourceware.org (Postfix) with ESMTPS id 981FB3834365 for ; Wed, 14 Dec 2022 14:03:31 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 981FB3834365 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=arm.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=arm.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=armh.onmicrosoft.com; s=selector2-armh-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=VtuvNUTofh+QW3G8sbDPBxVR1oKQ3DOUNq3fBYTJ5eI=; b=bRGXVL9mkQAYvyEjzn5htOTMMQcW8nq9EdWrYrHKWLOsOCsKUd5jW3X4alZz+qkNVKmcMzi2f0QuiYBMiiu08bpWDmRub6maNCZQ192odQzqegSUqhhayBE+7sTFFDed1MuQidlpZGSOXdMcVdpyRERB9QJgz2c3lWDKzLDzmXU= Received: from ZR0P278CA0158.CHEP278.PROD.OUTLOOK.COM (2603:10a6:910:41::17) by AS4PR08MB8143.eurprd08.prod.outlook.com (2603:10a6:20b:58e::6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5924.11; Wed, 14 Dec 2022 14:03:24 +0000 Received: from VI1EUR03FT055.eop-EUR03.prod.protection.outlook.com (2603:10a6:910:41:cafe::af) by ZR0P278CA0158.outlook.office365.com (2603:10a6:910:41::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5924.11 via Frontend Transport; Wed, 14 Dec 2022 14:03:24 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 63.35.35.123) smtp.mailfrom=arm.com; dkim=pass (signature was verified) header.d=armh.onmicrosoft.com;dmarc=pass action=none header.from=arm.com; Received-SPF: Pass (protection.outlook.com: domain of arm.com designates 63.35.35.123 as permitted sender) receiver=protection.outlook.com; client-ip=63.35.35.123; helo=64aa7808-outbound-1.mta.getcheckrecipient.com; pr=C Received: from 64aa7808-outbound-1.mta.getcheckrecipient.com (63.35.35.123) by VI1EUR03FT055.mail.protection.outlook.com (100.127.144.130) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5901.21 via Frontend Transport; Wed, 14 Dec 2022 14:03:23 +0000 Received: ("Tessian outbound 73ab5f36653e:v130"); Wed, 14 Dec 2022 14:03:23 +0000 X-CheckRecipientChecked: true X-CR-MTA-CID: b9735175c79b5864 X-CR-MTA-TID: 64aa7808 Received: from 49e537e6098e.1 by 64aa7808-outbound-1.mta.getcheckrecipient.com id B17105A7-A11D-45E2-8B53-E68246D26378.1; Wed, 14 Dec 2022 14:03:13 +0000 Received: from EUR03-VI1-obe.outbound.protection.outlook.com by 64aa7808-outbound-1.mta.getcheckrecipient.com with ESMTPS id 49e537e6098e.1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384); Wed, 14 Dec 2022 14:03:13 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=HTCbVW7a8ASDUGZMbyRW6u58hoNwG1lRx3LhFfU83+2c+WNbMml48tsPWBxGyabgOZrhGkwBV0/6aisUScdRX+5K0taYbYMXxiEs7bCJ6YO48gbIbQxItbouFiJV7qaNiGjgfp4oOc7k/b6r3Qp1v1DWB9L6R+1MVUzzyH5Nsk4FjWWwIsY+F6fFfbd9zs9UKBBOpyI027RYuFh/AlRskpNpw7I7A1I/ajA2MyADwSvqULq6U2jxsGB4u4HK5uOsGX81DDMOnkg3U+KMmZyyoMXuyClsr4aWp+adxBttgXrLO2FDAxGSlUJqvkW2+NE6Shl48UAKZ8Bkegaus7dGpQ== 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-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=VtuvNUTofh+QW3G8sbDPBxVR1oKQ3DOUNq3fBYTJ5eI=; b=QYcPWuDY2SzoO5d1vckQ3A2KshFJbO+bn071S8EBziCO5TF/qIU3hwj02fgWSkB7jeHZ8HcMPmw8i4hLo5orBHP/v2zBn+sqC00wIbis8eTBu7eIN36ZK3Ybiis290KPEFo1IoRXa82D/cYKgOE8jF2M1bm7wSvUr2MIH0a0JY4oU70BHBGGRRxFVWYKq45h0340VnCzWGWa1v88EObnN2RejXroIN7XLvRS61aYaLWTqCKy5JYiqa+5/zNXfZ+jMFq4BBWUyddz8Mcw6b0wZn5GA8+erNEAw1WXsilK5RN5K8w/AZNQ26GEXQo5ZMM3f0Gst7FwtTNkCF1nemFWLg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=arm.com; dmarc=pass action=none header.from=arm.com; dkim=pass header.d=arm.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=armh.onmicrosoft.com; s=selector2-armh-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=VtuvNUTofh+QW3G8sbDPBxVR1oKQ3DOUNq3fBYTJ5eI=; b=bRGXVL9mkQAYvyEjzn5htOTMMQcW8nq9EdWrYrHKWLOsOCsKUd5jW3X4alZz+qkNVKmcMzi2f0QuiYBMiiu08bpWDmRub6maNCZQ192odQzqegSUqhhayBE+7sTFFDed1MuQidlpZGSOXdMcVdpyRERB9QJgz2c3lWDKzLDzmXU= Authentication-Results-Original: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=arm.com; Received: from VI1PR08MB3919.eurprd08.prod.outlook.com (2603:10a6:803:c4::31) by AM8PR08MB6417.eurprd08.prod.outlook.com (2603:10a6:20b:362::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5924.11; Wed, 14 Dec 2022 14:03:03 +0000 Received: from VI1PR08MB3919.eurprd08.prod.outlook.com ([fe80::eed7:25a3:e4ea:187a]) by VI1PR08MB3919.eurprd08.prod.outlook.com ([fe80::eed7:25a3:e4ea:187a%7]) with mapi id 15.20.5924.011; Wed, 14 Dec 2022 14:03:03 +0000 Message-ID: Date: Wed, 14 Dec 2022 14:03:02 +0000 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.4.2 From: Luis Machado Subject: Re: [PATCH v2 2/2] gas: re-work line number tracking for macros and their expansions To: Jan Beulich , Binutils Cc: Nick Clifton , "ramana.radhakrishnan@arm.com" , Richard Earnshaw , Marcus Shawcroft , Alan Modra , Peter Bergner , Geoff Keating , Palmer Dabbelt , Andrew Waterman , Jim Wilson , Nelson Chu , "H.J. Lu" References: <1d528267-9450-12c7-4c4c-fe4deb3b0617@suse.com> <8eff1de6-871d-24cc-8804-9af7da0a86cf@suse.com> Content-Language: en-US In-Reply-To: <8eff1de6-871d-24cc-8804-9af7da0a86cf@suse.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-ClientProxiedBy: LO4P123CA0620.GBRP123.PROD.OUTLOOK.COM (2603:10a6:600:294::16) To VI1PR08MB3919.eurprd08.prod.outlook.com (2603:10a6:803:c4::31) MIME-Version: 1.0 X-MS-TrafficTypeDiagnostic: VI1PR08MB3919:EE_|AM8PR08MB6417:EE_|VI1EUR03FT055:EE_|AS4PR08MB8143:EE_ X-MS-Office365-Filtering-Correlation-Id: d11f68d5-9212-4422-a94b-08dadddbf709 X-LD-Processed: f34e5979-57d9-4aaa-ad4d-b122a662184d,ExtAddr x-checkrecipientrouted: true NoDisclaimer: true X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam-Untrusted: BCL:0; X-Microsoft-Antispam-Message-Info-Original: 3UtIiCZolrB+wBSdj0WdiBf4PPZrMaDeg/tnwtacWcZYEYwZjOjThP7OJ77alwnFAyG5g+XwWw+gLn7diOUvHe4ioMdprbq+H32cHUKr+QVcN3rf35zAgLNirz3S4AONK9zvsKWjhk7L3SksuynpXwqaOWY4M2BJlnCPOx+oeUSo+xgMSMy/1G1+wDEcssHapUyreyoQ+tZa2XVmy0w5z9EWXeLWrbEN60MXPFGA3L2i0f3yw/sqZo3PYIlCLpDgTjiqdOisuD6YtvWf7wMg+wKEpCsicC+gjmldvnkVYW6hvD3L8uQOnVr555v2zvNvmoAM414q2w0F7yEqrCcDn1qO8FZcHj9W+pOG5ST/WgXgFL0d+GgZhMVUNMascwVaVKIg4Bs423yawxIIHqAgLqx0OFCE+f1XvZEZV2yclRa6ikgYcfcH834FTk+clwGM2o2UZVK1UaVgi8g/fgrIEhgSLcxEv6TDyvashlRxN+3eW/aaAOoTO/GWe/t1boNdwrycpfhiFnCGnPCENt1vUlfB4Qm6eD4/0iXV0FzYwNyqMOYC6XU02paIqf06wwrLrWzk+9sGUEOilRKFO6w9/AYnYUr7LhtNZiGLCBlaQpEOJGQsTdXO4GeLDL2OnbY7vP91shc7ec6KmrpoevdrxmBDNTwyFRBrU34XZN+DDNN5yle1BrfMeFxA1D/uwVKV2LhFXHpTdwx7wE0zcMMNaAp8Uyn45qzAJX4ezThZWQQXU7TPNmIJDkV4Ngj2Gywf X-Forefront-Antispam-Report-Untrusted: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:VI1PR08MB3919.eurprd08.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230022)(4636009)(376002)(136003)(346002)(396003)(366004)(39860400002)(451199015)(36756003)(83380400001)(31696002)(86362001)(316002)(110136005)(54906003)(478600001)(6486002)(7416002)(2906002)(44832011)(4326008)(5660300002)(8676002)(66556008)(66476007)(30864003)(66946007)(8936002)(41300700001)(26005)(38100700002)(186003)(6512007)(53546011)(6506007)(2616005)(84970400001)(31686004)(43740500002)(45980500001);DIR:OUT;SFP:1101; X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM8PR08MB6417 Original-Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=arm.com; X-EOPAttributedMessage: 0 X-MS-Exchange-Transport-CrossTenantHeadersStripped: VI1EUR03FT055.eop-EUR03.prod.protection.outlook.com X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id-Prvs: d5610678-13fe-49e7-6128-08dadddbead5 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: yTj8PKJnMizWwd1kpr/EKs0JxTi/7ZT2qQRHxzbvCGwzNObrlkvV5rsUWx122aYFuwkdkdmagqaJCQts0zoZV2Y6MEbtSFC/GpJF9lg8N/FcNPx5s/O5sO4S0UvoJkjdp/C/wqvifSOZkb4z4YygyZ6HyW7jgkOCdCX+jTURsPyVQo7xA/u107INUNB7bRA9mO/xVGy+fVPOfHEJdHfpizuTbObGkzUf/O95lb9kK6PmdIKa2cvBtpcn/KlprWCWIQemUaAmh9LykI73knhwyErQno/e6RqYwGOFxTyx7MFjsbwFxHQN20qG5LadE49ZkGCiJjQpbzn9uV2YnJjyxTNMjTH5nPjzESo8fwi7TRB4K9KilQBlQm+evjZvv/3lEAnQkAIfMFj1UPUyCa1v4iWV5WqYnySd2rYsn4LAxJPWlnxxcahT5+moSF+LAbNSqC7ZlCbCMpainDWLAQ2Zi0/FPHQa5d7inVCyzm/yGPgDMOgtiT1ZSx4SKe48AZffPLhwx0KF9N087uEk1raVQYL+jcwnrMuvzqMjc6nKni+1DV46YpDZEDxvaAWejY1gUBGIrX5INlG5StUTMMKOJLWqWGcTZ7Kbbgt+zZaLnvIsP2UbTM3AzdBAjaMHAiOJhwVGq+/1/TqGDxS59W5iSxYJ4EMxK/MGho09kgWZOPUZzvUFWYUJ7Id/HHoMFGphjcqSg6MZfhHJn4mo1FIC0CTivetnpaiPJLNrIKVxBg9rhsVCU6TYQw56TJ7r6oCzNTr6pfdYV+r8nkqyXCDu8A== X-Forefront-Antispam-Report: CIP:63.35.35.123;CTRY:IE;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:64aa7808-outbound-1.mta.getcheckrecipient.com;PTR:ec2-63-35-35-123.eu-west-1.compute.amazonaws.com;CAT:NONE;SFS:(13230022)(4636009)(376002)(39860400002)(346002)(396003)(136003)(451199015)(40470700004)(46966006)(36840700001)(44832011)(30864003)(83380400001)(5660300002)(8936002)(2906002)(336012)(41300700001)(47076005)(31696002)(40460700003)(86362001)(82740400003)(40480700001)(356005)(82310400005)(81166007)(36756003)(36860700001)(84970400001)(6486002)(316002)(26005)(478600001)(6512007)(110136005)(54906003)(8676002)(70206006)(53546011)(4326008)(2616005)(70586007)(6506007)(31686004)(107886003)(186003)(43740500002);DIR:OUT;SFP:1101; X-OriginatorOrg: arm.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 14 Dec 2022 14:03:23.7122 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: d11f68d5-9212-4422-a94b-08dadddbf709 X-MS-Exchange-CrossTenant-Id: f34e5979-57d9-4aaa-ad4d-b122a662184d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=f34e5979-57d9-4aaa-ad4d-b122a662184d;Ip=[63.35.35.123];Helo=[64aa7808-outbound-1.mta.getcheckrecipient.com] X-MS-Exchange-CrossTenant-AuthSource: VI1EUR03FT055.eop-EUR03.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: AS4PR08MB8143 X-Spam-Status: No, score=-6.2 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,FORGED_SPF_HELO,KAM_DMARC_NONE,NICE_REPLY_A,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_PASS,SPF_NONE,TXREP,UNPARSEABLE_RELAY autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: Hi, I'm not yet sure how, but this patch has broken at least one gdb test (gdb.asm/asm-source.exp) for aarch64-linux (Ubuntu 22.04 and 20.04). Could you please take a look at it? I can do some testing with the aarch64 machines if that's helpful. FAIL: gdb.asm/asm-source.exp: f at main FAIL: gdb.asm/asm-source.exp: n at main FAIL: gdb.asm/asm-source.exp: next over macro FAIL: gdb.asm/asm-source.exp: list FAIL: gdb.asm/asm-source.exp: f in foo2 FAIL: gdb.asm/asm-source.exp: n in foo2 FAIL: gdb.asm/asm-source.exp: bt ALL in foo2 FAIL: gdb.asm/asm-source.exp: bt 2 in foo2 FAIL: gdb.asm/asm-source.exp: bt 3 in foo3 FAIL: gdb.asm/asm-source.exp: finish from foo3 FAIL: gdb.asm/asm-source.exp: info source asmsrc2.s FAIL: gdb.asm/asm-source.exp: info line FAIL: gdb.asm/asm-source.exp: next over foo3 FAIL: gdb.asm/asm-source.exp: return from foo2 === gdb Summary === # of expected passes 15 # of unexpected failures 14 On 12/9/22 10:52, Jan Beulich via Binutils wrote: > The PR gas/16908 workaround aimed at uniformly reporting line numbers > to reference macro invocation sites. As mentioned in a comment this may > be desirable for small macros, but often isn't for larger ones. As a > first step improve diagnostics to report both locations, while aiming at > leaving generated debug info unaltered. > > Note that macro invocation context is lost for any diagnostics issued > only after all input was processed (or more generally for any use of > as_*_where(), as the functions can't know whether the passed in location > is related to [part of] the present stack of locations). To maintain the > intended workaround behavior for PR gas/16908, a new as_where() is > introduced to "look through" macro invocations, while the existing > as_where() is renamed (and used in only very few places for now). Down > the road as_where() will likely want to return a list of (file,line) > pairs. > --- > v2: Fully cover Arm testsuite. > --- > Omitting testsuite adjustments from the inline patch, for its sheer size; > please see the attachment for the full (compressed) patch. > --- > Adding > > if (subseg_text_p (now_seg)) > dwarf2_emit_insn (0); > > to try_macro() (alongside using as_where_top() in dwarf2_where()) would > get .debug_line contents into reasonable shape (expressing both macro > invocation site and macro definition location). But that's likely > insufficient: We may want / need to represent macros as inline > subprograms and their expansions as inlined subroutines. Which in turn > looks cumbersome especially with the relatively recently added recording > of functions (with which macro expansions then would better be > associated, when marked as such). > > --- a/gas/as.h > +++ b/gas/as.h > @@ -437,6 +437,10 @@ typedef struct _pseudo_type pseudo_typeS > #define PRINTF_WHERE_LIKE(FCN) \ > void FCN (const char *file, unsigned int line, const char *format, ...) \ > __attribute__ ((__format__ (__printf__, 3, 4))) > +#define PRINTF_INDENT_LIKE(FCN) \ > + void FCN (const char *file, unsigned int line, unsigned int indent, \ > + const char *format, ...) \ > + __attribute__ ((__format__ (__printf__, 4, 5))) > > #else /* __GNUC__ < 2 || defined(VMS) */ > > @@ -444,6 +448,10 @@ typedef struct _pseudo_type pseudo_typeS > #define PRINTF_WHERE_LIKE(FCN) void FCN (const char *file, \ > unsigned int line, \ > const char *format, ...) > +#define PRINTF_INDENT_LIKE(FCN) void FCN (const char *file, \ > + unsigned int line, \ > + unsigned int indent, \ > + const char *format, ...) > > #endif /* __GNUC__ < 2 || defined(VMS) */ > > @@ -453,6 +461,7 @@ PRINTF_LIKE (as_tsktsk); > PRINTF_LIKE (as_warn); > PRINTF_WHERE_LIKE (as_bad_where); > PRINTF_WHERE_LIKE (as_warn_where); > +PRINTF_INDENT_LIKE (as_info_where); > > void as_abort (const char *, int, const char *) ATTRIBUTE_NORETURN; > void signal_init (void); > @@ -487,7 +496,9 @@ void cond_finish_check (int); > void cond_exit_macro (int); > int seen_at_least_1_file (void); > void app_pop (char *); > +void as_report_context (void); > const char * as_where (unsigned int *); > +const char * as_where_top (unsigned int *); > const char * as_where_physical (unsigned int *); > void bump_line_counters (void); > void do_scrub_begin (int); > --- a/gas/input-scrub.c > +++ b/gas/input-scrub.c > @@ -104,6 +104,9 @@ static const char *logical_input_file; > static unsigned int physical_input_line; > static unsigned int logical_input_line; > > +/* Indicator whether the origin of an update was a .linefile directive. */ > +static bool is_linefile; > + > /* Struct used to save the state of the input handler during include files */ > struct input_save { > char * buffer_start; > @@ -115,6 +118,7 @@ struct input_save { > const char * logical_input_file; > unsigned int physical_input_line; > unsigned int logical_input_line; > + bool is_linefile; > size_t sb_index; > sb from_sb; > enum expansion from_sb_expansion; /* Should we do a conditional check? */ > @@ -166,6 +170,7 @@ input_scrub_push (char *saved_position) > saved->logical_input_file = logical_input_file; > saved->physical_input_line = physical_input_line; > saved->logical_input_line = logical_input_line; > + saved->is_linefile = is_linefile; > saved->sb_index = sb_index; > saved->from_sb = from_sb; > saved->from_sb_expansion = from_sb_expansion; > @@ -193,6 +198,7 @@ input_scrub_pop (struct input_save *save > logical_input_file = saved->logical_input_file; > physical_input_line = saved->physical_input_line; > logical_input_line = saved->logical_input_line; > + is_linefile = saved->is_linefile; > sb_index = saved->sb_index; > from_sb = saved->from_sb; > from_sb_expansion = saved->from_sb_expansion; > @@ -267,8 +273,6 @@ input_scrub_include_sb (sb *from, char * > as_fatal (_("macros nested too deeply")); > ++macro_nest; > > - gas_assert (expansion < expanding_nested); > - > #ifdef md_macro_start > if (expansion == expanding_macro) > { > @@ -283,8 +287,6 @@ input_scrub_include_sb (sb *from, char * > expansion. */ > newline = from->len >= 1 && from->ptr[0] != '\n'; > sb_build (&from_sb, from->len + newline + 2 * sizeof (".linefile") + 30); > - if (expansion == expanding_repeat && from_sb_expansion >= expanding_macro) > - expansion = expanding_nested; > from_sb_expansion = expansion; > if (newline) > { > @@ -437,10 +439,7 @@ bump_line_counters (void) > if (sb_index == (size_t) -1) > ++physical_input_line; > > - /* PR gas/16908 workaround: Don't bump logical line numbers while > - expanding macros, unless file (and maybe line; see as_where()) are > - used inside the macro. */ > - if (logical_input_line != -1u && from_sb_expansion < expanding_macro) > + if (logical_input_line != -1u) > ++logical_input_line; > } > > @@ -471,10 +470,6 @@ new_logical_line_flags (const char *fnam > case 1 << 3: > if (line_number < 0 || fname != NULL) > abort (); > - /* PR gas/16908 workaround: Ignore updates when nested inside a macro > - expansion. */ > - if (from_sb_expansion == expanding_nested) > - return; > if (next_saved_file == NULL) > fname = physical_input_file; > else if (next_saved_file->logical_input_file) > @@ -486,6 +481,8 @@ new_logical_line_flags (const char *fnam > abort (); > } > > + is_linefile = flags != 1 && (flags != 0 || fname); > + > if (line_number >= 0) > logical_input_line = line_number; > else if (line_number == -1 && fname && !*fname && (flags & (1 << 2))) > @@ -499,15 +496,6 @@ new_logical_line_flags (const char *fnam > && (logical_input_file == NULL > || filename_cmp (logical_input_file, fname))) > logical_input_file = fname; > - > - /* When encountering file or line changes inside a macro, arrange for > - bump_line_counters() to henceforth increment the logical line number > - again, just like it does when expanding repeats. See as_where() for > - why changing file or line alone doesn't alter expansion mode. */ > - if (from_sb_expansion == expanding_macro > - && logical_input_file != NULL > - && logical_input_line != -1u) > - from_sb_expansion = expanding_repeat; > } > > void > @@ -516,6 +504,33 @@ new_logical_line (const char *fname, int > new_logical_line_flags (fname, line_number, 0); > } > > +void > +as_report_context (void) > +{ > + const struct input_save *saved = next_saved_file; > + enum expansion expansion = from_sb_expansion; > + int indent = 1; > + > + if (!macro_nest) > + return; > + > + do > + { > + if (expansion != expanding_macro) > + /* Nothing. */; > + else if (saved->logical_input_file != NULL > + && saved->logical_input_line != -1u) > + as_info_where (saved->logical_input_file, saved->logical_input_line, > + indent, _("macro invoked from here")); > + else > + as_info_where (saved->physical_input_file, saved->physical_input_line, > + indent, _("macro invoked from here")); > + > + expansion = saved->from_sb_expansion; > + ++indent; > + } > + while ((saved = saved->next_saved_file) != NULL); > +} > > /* Return the current physical input file name and line number, if known */ > > @@ -534,11 +549,53 @@ as_where_physical (unsigned int *linep) > return NULL; > } > > -/* Return the current file name and line number. */ > +/* Return the file name and line number at the top most macro > + invocation, unless .file / .line were used inside a macro. */ > > const char * > as_where (unsigned int *linep) > { > + const char *file = as_where_top (linep); > + > + if (macro_nest && is_linefile) > + { > + const struct input_save *saved = next_saved_file; > + enum expansion expansion = from_sb_expansion; > + > + do > + { > + if (!saved->is_linefile) > + break; > + > + if (expansion != expanding_macro) > + /* Nothing. */; > + else if (saved->logical_input_file != NULL > + && (linep == NULL || saved->logical_input_line != -1u)) > + { > + if (linep != NULL) > + *linep = saved->logical_input_line; > + file = saved->logical_input_file; > + } > + else if (saved->physical_input_file != NULL) > + { > + if (linep != NULL) > + *linep = saved->physical_input_line; > + file = saved->physical_input_file; > + } > + > + expansion = saved->from_sb_expansion; > + } > + while ((saved = saved->next_saved_file) != NULL); > + } > + > + return file; > +} > + > +/* Return the current file name and line number. */ > + > +const char * > +as_where_top (unsigned int *linep) > +{ > if (logical_input_file != NULL > && (linep == NULL || logical_input_line != -1u)) > { > @@ -549,4 +606,3 @@ as_where (unsigned int *linep) > > return as_where_physical (linep); > } > - > --- a/gas/macro.c > +++ b/gas/macro.c > @@ -131,23 +131,21 @@ buffer_and_nest (const char *from, const > else > from_len = strlen (from); > > - /* Except for macros record the present source position, such that > - diagnostics and debug info will be properly associated with the > - respective original lines, rather than with the line of the ending > - directive (TO). */ > - if (from == NULL || strcasecmp (from, "MACRO") != 0) > - { > - unsigned int line; > - char *linefile; > - > - as_where (&line); > - if (!flag_m68k_mri) > - linefile = xasprintf ("\t.linefile %u .", line + 1); > - else > - linefile = xasprintf ("\tlinefile %u .", line + 1); > - sb_add_string (ptr, linefile); > - xfree (linefile); > - } > + /* Record the present source position, such that diagnostics and debug info > + can be properly associated with the respective original lines, rather > + than with the line of the ending directive (TO). */ > + { > + unsigned int line; > + char *linefile; > + > + as_where_top (&line); > + if (!flag_m68k_mri) > + linefile = xasprintf ("\t.linefile %u .", line + 1); > + else > + linefile = xasprintf ("\tlinefile %u .", line + 1); > + sb_add_string (ptr, linefile); > + xfree (linefile); > + } > > while (more) > { > @@ -249,14 +247,8 @@ buffer_and_nest (const char *from, const > } > > /* PR gas/16908 > - Apply and discard .linefile directives that appear within > - the macro. For long macros, one might want to report the > - line number information associated with the lines within > - the macro definition, but we would need more infrastructure > - to make that happen correctly (e.g. resetting the line > - number when expanding the macro), and since for short > - macros we clearly prefer reporting the point of expansion > - anyway, there's not an obviously better fix here. */ > + Apply .linefile directives that appear within the macro, alongside > + keeping them for later expansion of the macro. */ > if (from != NULL && strcasecmp (from, "MACRO") == 0 > && len >= 8 && strncasecmp (ptr->ptr + i, "linefile", 8) == 0) > { > @@ -267,7 +259,6 @@ buffer_and_nest (const char *from, const > s_linefile (0); > restore_ilp (); > ptr->ptr[ptr->len] = saved_eol_char; > - ptr->len = line_start; > } > } > > --- a/gas/messages.c > +++ b/gas/messages.c > @@ -18,6 +18,7 @@ > 02110-1301, USA. */ > > #include "as.h" > +#include > #include > > /* If the system doesn't provide strsignal, we get it defined in > @@ -119,7 +120,7 @@ as_show_where (void) > const char *file; > unsigned int line; > > - file = as_where (&line); > + file = as_where_top (&line); > identify (file); > if (file) > { > @@ -130,6 +131,25 @@ as_show_where (void) > } > } > > +/* Send to stderr a string as information, with location data passed in. > + Note that for now this is not intended for general use. */ > + > +void > +as_info_where (const char *file, unsigned int line, unsigned int indent, > + const char *format, ...) > +{ > + va_list args; > + char buffer[2000]; > + > + gas_assert (file != NULL && line > 0 && indent <= INT_MAX); > + > + va_start (args, format); > + vsnprintf (buffer, sizeof (buffer), format, args); > + va_end (args); > + fprintf (stderr, "%s:%u: %*s%s%s\n", > + file, line, (int)indent, "", _("Info: "), buffer); > +} > + > /* Send to stderr a string as a warning, and locate warning > in input file(s). > Please only use this for when we have some recovery action. > @@ -146,6 +166,7 @@ as_tsktsk (const char *format, ...) > vfprintf (stderr, format, args); > va_end (args); > (void) putc ('\n', stderr); > + as_report_context (); > } > > /* The common portion of as_warn and as_warn_where. */ > @@ -153,10 +174,15 @@ as_tsktsk (const char *format, ...) > static void > as_warn_internal (const char *file, unsigned int line, char *buffer) > { > + bool context = false; > + > ++warning_count; > > if (file == NULL) > - file = as_where (&line); > + { > + file = as_where_top (&line); > + context = true; > + } > > identify (file); > if (file) > @@ -168,6 +194,10 @@ as_warn_internal (const char *file, unsi > } > else > fprintf (stderr, "%s%s\n", _("Warning: "), buffer); > + > + if (context) > + as_report_context (); > + > #ifndef NO_LISTING > listing_warning (buffer); > #endif > @@ -194,7 +224,7 @@ as_warn (const char *format, ...) > } > } > > -/* Like as_bad but the file name and line number are passed in. > +/* Like as_warn but the file name and line number are passed in. > Unfortunately, we have to repeat the function in order to handle > the varargs correctly and portably. */ > > @@ -218,10 +248,15 @@ as_warn_where (const char *file, unsigne > static void > as_bad_internal (const char *file, unsigned int line, char *buffer) > { > + bool context = false; > + > ++error_count; > > if (file == NULL) > - file = as_where (&line); > + { > + file = as_where_top (&line); > + context = true; > + } > > identify (file); > if (file) > @@ -233,6 +268,10 @@ as_bad_internal (const char *file, unsig > } > else > fprintf (stderr, "%s%s\n", _("Error: "), buffer); > + > + if (context) > + as_report_context (); > + > #ifndef NO_LISTING > listing_error (buffer); > #endif > @@ -290,6 +329,7 @@ as_fatal (const char *format, ...) > vfprintf (stderr, format, args); > (void) putc ('\n', stderr); > va_end (args); > + as_report_context (); > /* Delete the output file, if it exists. This will prevent make from > thinking that a file was created and hence does not need rebuilding. */ > if (out_file_name != NULL) > @@ -312,6 +352,7 @@ as_abort (const char *file, int line, co > fprintf (stderr, _("Internal error in %s at %s:%d.\n"), fn, file, line); > else > fprintf (stderr, _("Internal error at %s:%d.\n"), file, line); > + as_report_context (); > > fprintf (stderr, _("Please report this bug.\n")); > > --- a/gas/sb.h > +++ b/gas/sb.h > @@ -66,11 +66,9 @@ extern size_t sb_skip_comma (size_t, sb > > /* Actually in input-scrub.c. */ > enum expansion { > - /* Note: Order matters! */ > expanding_none, > expanding_repeat, > expanding_macro, > - expanding_nested, /* Only for internal use of input-scrub.c. */ > }; > extern void input_scrub_include_sb (sb *, char *, enum expansion); >