From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-ed1-x52f.google.com (mail-ed1-x52f.google.com [IPv6:2a00:1450:4864:20::52f]) by sourceware.org (Postfix) with ESMTPS id 528A93857C48 for ; Wed, 29 Mar 2023 19:11:16 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 528A93857C48 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=embecosm.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=embecosm.com Received: by mail-ed1-x52f.google.com with SMTP id h8so67450931ede.8 for ; Wed, 29 Mar 2023 12:11:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=embecosm.com; s=google; t=1680117075; h=mime-version:user-agent:references:message-id:in-reply-to:subject :cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=OWRT5RLypHWWsyQ8WHEUesj6PcALkHBNFHNkr6yYIis=; b=AGP1M5lXtTw9BixQyu9RIT5MYTuEq/HZsEzuuzRt8IkAT+UwdnGoh/nmlQK19zZ8Dn WEH5qGigLPH7cI7JEUShDOfmvJUHlEw9eDkPsnjyQAUkaGu6lXRLhCmjID+gGNiLZblJ pjdCwrejw8SN58fDY5vhOOjlOWZ9XLCzIZ9wYz26LHMwLbs47qu8juU1hqshKfBS6FKY 2WZzErq4zNS7fJKvUZPl08hk74ACdrzq2Z0Ef9e0nG2csHEjQQn4Pdr7a66BxEf7J/BO a0ln+b1VV0Sf1fn8ScxqY6WWgt2/+GXrvEm2d0mw4OdypaEi7YpbDmCTi66W7g9fzjni X7pw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680117075; h=mime-version:user-agent:references:message-id:in-reply-to:subject :cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=OWRT5RLypHWWsyQ8WHEUesj6PcALkHBNFHNkr6yYIis=; b=vn4OiheVLeoSdL+28U5iig6nY7KOSnwDF/cgI8I4tKO712RwQAg4pfaf/wdfiPpXSZ MxcgCspLvo9QVGORDOMAKd89/9ClV1mEPz6R0iyOjBaWj+87WPRHGospO468sTo4yoed wqwYfY7GXStCJyu9M/WUserlb/xJ4F10WIZtfChkJLPmMet1n0jeUfQrQZ/28mSuuq0R NQl6uMjc6/97ZveplfGx66Lba0Ri/dxsjqfiAx4MYghmsLFB6ZJfy9UoMcKd+uSZFjQo vsMIH+ddGP650X6iUi3H84nQ48d22mdfPPpCSwyp6dzrWQG/tY1BrLdXXNY/iEIg+UdN d8Ow== X-Gm-Message-State: AAQBX9dNI10sAsRBjDMa43mQHRrRpPumiIejnQeXtsRRMvrF0qPy7O24 jmhpUYi6e0j9SP+ZBsv3ZkpJEP1+0ey/rBKrYes= X-Google-Smtp-Source: AKy350aSyISmQFg7MTSctamxgpwpLKbJNynOH/5uHBOeARBGUI6s6TgPgkcn7PWdmmS6dwK1aS6Prg== X-Received: by 2002:a17:906:3592:b0:934:8043:ebf8 with SMTP id o18-20020a170906359200b009348043ebf8mr20652078ejb.26.1680117075171; Wed, 29 Mar 2023 12:11:15 -0700 (PDT) Received: from annie.orcam.me.uk (annie.orcam.me.uk. [2001:4190:8020::48]) by smtp.gmail.com with ESMTPSA id 21-20020a508755000000b004fc920655basm17490003edv.54.2023.03.29.12.11.14 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Wed, 29 Mar 2023 12:11:14 -0700 (PDT) Date: Wed, 29 Mar 2023 20:11:13 +0100 (BST) From: "Maciej W. Rozycki" To: gdb-patches@sourceware.org cc: Tom Tromey , Richard Bunt Subject: [PATCH v3 2/3] GDB: Bring back the handling of DW_CC_program In-Reply-To: Message-ID: References: User-Agent: Alpine 2.20 (DEB 67 2015-01-07) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII X-Spam-Status: No, score=-2.5 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: Fix a functional regression and restore the handling of DW_CC_program code of DW_AT_calling_convention attribute for determining the name of the starting function of the program where the DW_AT_main_subprogram attribute has not been provided, such as with Fortran code compiled with GCC versions 4.5.4 and below, or where DWARF version 3 or below has been requested. Without it "main" is considered the starting function. Cf. GCC PR fortran/43414. Original code was removed with commit 6209cde4ddb8 ("Delete DWARF psymtab code"), and then an update to complement commit 81873cc81eff ("[gdb/symtab] Support DW_AT_main_subprogram with -readnow.") has also been included here. --- NB this was discovered with and is covered by the test case included with 3/3; it has been verified to trigger with GCC 4.4.7 and will likely also with other configurations. Changes from v2: - Add inline documentation for the history of DW_AT_main_subprogram and DW_AT_calling_convention == DW_CC_program DWARF attributes. No change from v1. --- gdb/dwarf2/read.c | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) gdb-main-name-dw-cc-program.diff Index: src/gdb/dwarf2/read.c =================================================================== --- src.orig/gdb/dwarf2/read.c +++ src/gdb/dwarf2/read.c @@ -9994,6 +9994,22 @@ inherit_abstract_dies (struct die_info * compute_delayed_physnames (origin_cu); } +/* Return TRUE if the given DIE is the program's "main". DWARF 4 has + defined a dedicated DW_AT_main_subprogram attribute to indicate the + starting function of the program, however with older versions the + DW_CC_program value of the DW_AT_calling_convention attribute was + used instead as the only means available. We handle both variants. */ + +static bool +dwarf2_func_is_main_p (struct die_info *die, struct dwarf2_cu *cu) +{ + if (dwarf2_flag_true_p (die, DW_AT_main_subprogram, cu)) + return true; + struct attribute *attr = dwarf2_attr (die, DW_AT_calling_convention, cu); + return (attr != nullptr + && attr->constant_value (DW_CC_normal) == DW_CC_program); +} + static void read_func_scope (struct die_info *die, struct dwarf2_cu *cu) { @@ -10084,7 +10100,7 @@ read_func_scope (struct die_info *die, s newobj = cu->get_builder ()->push_context (0, lowpc); newobj->name = new_symbol (die, read_type_die (die, cu), cu, templ_func); - if (dwarf2_flag_true_p (die, DW_AT_main_subprogram, cu)) + if (dwarf2_func_is_main_p (die, cu)) set_objfile_main_name (objfile, newobj->name->linkage_name (), cu->lang ()); @@ -16136,11 +16152,21 @@ cooked_indexer::scan_attributes (dwarf2_ *linkage_name = attr.as_string (); break; + /* DWARF 4 has defined a dedicated DW_AT_main_subprogram + attribute to indicate the starting function of the program... */ case DW_AT_main_subprogram: if (attr.as_boolean ()) *flags |= IS_MAIN; break; + /* ... however with older versions the DW_CC_program value of + the DW_AT_calling_convention attribute was used instead as + the only means available. We handle both variants then. */ + case DW_AT_calling_convention: + if (attr.constant_value (DW_CC_normal) == DW_CC_program) + *flags |= IS_MAIN; + break; + case DW_AT_declaration: is_declaration = attr.as_boolean (); break;