From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-wr1-f54.google.com (mail-wr1-f54.google.com [209.85.221.54]) by sourceware.org (Postfix) with ESMTPS id D7D613850214 for ; Wed, 8 Jun 2022 16:29:38 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org D7D613850214 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=palves.net Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-wr1-f54.google.com with SMTP id k19so29052546wrd.8 for ; Wed, 08 Jun 2022 09:29:38 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:message-id:date:mime-version:user-agent:subject :content-language:to:cc:references:from:in-reply-to :content-transfer-encoding; bh=QYrh+r2pIVgACsbEP1lBsdxapb4ubEg8L469yXM1j4o=; b=jip0sahTCFEh0muxtzwujbYXMed1fcj17v44gzWGe1jTogdGPfO0zIyvAFFJ7l1mqS oKrSyg4ornOAW+t5O1yK+lZZ/Yw62o3NtuQtJaCsEunlZnVfevZ7aSgqjF+8VwfI4Dpe BVdbeOlZTuqK+qSl97yeO5XXqR+u2wgEK7Yk+11bMUuu2a8DU1WqqQQ2W3MlLehYY3vV tP66bgBAcql3omXP9Yzt/wsarr7G4YHPxCk1DKbgZHWwUtK4SSJVTRiAxYOHvoH+VLYa 1BBAK3QDJyUnyzdYTo6R1yneVpCQt8bXt6B1ZA/+7gGE1G4qcQqgThdyQN7TNxFUkoCe JS5g== X-Gm-Message-State: AOAM532xX3+ioYjqCoCoffFzeu81fYeRgovpGOlh4kjldVs12ftSz7Yn I9I2ZVIft+xgFQ7xbae1kzg= X-Google-Smtp-Source: ABdhPJwz49BC/wkp76ATNRsQ+WShw2RO7y8kq7dEE8H9sv+L+8SkyzYfyFbkRdDvszaROmxjGDMX0Q== X-Received: by 2002:a5d:52c7:0:b0:210:ac6:3956 with SMTP id r7-20020a5d52c7000000b002100ac63956mr34399726wrv.379.1654705777621; Wed, 08 Jun 2022 09:29:37 -0700 (PDT) Received: from ?IPV6:2001:8a0:f924:2600:209d:85e2:409e:8726? ([2001:8a0:f924:2600:209d:85e2:409e:8726]) by smtp.gmail.com with ESMTPSA id m3-20020a05600c3b0300b003942a244f2fsm29631946wms.8.2022.06.08.09.29.36 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 08 Jun 2022 09:29:36 -0700 (PDT) Message-ID: <41b119d8-0321-23de-212b-33a328720455@palves.net> Date: Wed, 8 Jun 2022 17:29:35 +0100 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.9.1 Subject: Re: [PATCH] Debug support for global alias variable Content-Language: en-US To: "Natarajan, Kavitha" , Tom Tromey , "Natarajan, Kavitha via Gdb-patches" Cc: "George, Jini Susan" , "Parasuraman, Hariharan" References: <66ca57f9-c3b8-4aeb-f07c-c3c254dfdea6@redhat.com> <87ilra1gcx.fsf@tromey.com> <87sfqawi0v.fsf@tromey.com> <871qxsisr7.fsf@tromey.com> <498102ba-9a88-5ca7-ebe7-7120b655ee9c@palves.net> From: Pedro Alves In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-10.6 required=5.0 tests=BAYES_00, FREEMAIL_FORGED_FROMDOMAIN, FREEMAIL_FROM, GIT_PATCH_0, HEADER_FROM_DIFFERENT_DOMAINS, KAM_DMARC_STATUS, KAM_SHORT, NICE_REPLY_A, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) 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, 08 Jun 2022 16:29:41 -0000 Hi! I'm building current llvm to give this a try, and I'll merge it after some testing. Thanks again for the patch, and sorry for the delays. On 2022-06-07 10:08, Natarajan, Kavitha wrote: > [AMD Official Use Only] > > Ping! > > Can I push this patch? Can someone please approve? > > Below are the related communications for your reference: > https://sourceware.org/pipermail/gdb-patches/2022-March/186329.html > https://sourceware.org/pipermail/gdb-patches/2022-April/187448.html > > I am also attaching the rebased patch here. > > Regards, > Kavitha > ============================================================== > When clang emits the dwarf information of global alias variable > as DW_TAG_imported_declaration, gdb does not handle it. GDB reads > this tag as C++/fortran imported declaration (type alias, namespace > alias and fortran module). Added support to handle this tag as > alias variable. > > This change fixes the failure in gdb.base/symbol-alias.exp testcase. > This testcase is also updated to test nested (recursive) alias. > --- > gdb/dwarf2/read.c | 60 ++++++++++++++--------- > gdb/testsuite/gdb.base/symbol-alias.exp | 63 ++++++++++++++++++++++++- > gdb/testsuite/gdb.base/symbol-alias2.c | 16 +++++++ > 3 files changed, 116 insertions(+), 23 deletions(-) > > diff --git a/gdb/dwarf2/read.c b/gdb/dwarf2/read.c > index 848fd5627b8..972af77c5fd 100644 > --- a/gdb/dwarf2/read.c > +++ b/gdb/dwarf2/read.c > @@ -894,6 +894,10 @@ static void build_type_psymtabs_reader (cutu_reader *reader, > > static void dwarf2_build_psymtabs_hard (dwarf2_per_objfile *per_objfile); > > +static void var_decode_location (struct attribute *attr, > + struct symbol *sym, > + struct dwarf2_cu *cu); > + > static unsigned int peek_abbrev_code (bfd *, const gdb_byte *); > > static const gdb_byte *read_attribute (const struct die_reader_specs *, > @@ -1071,7 +1075,7 @@ static struct using_direct **using_directives (struct dwarf2_cu *cu); > > static void read_import_statement (struct die_info *die, struct dwarf2_cu *); > > -static int read_namespace_alias (struct die_info *die, struct dwarf2_cu *cu); > +static bool read_alias (struct die_info *die, struct dwarf2_cu *cu); > > static struct type *read_module_type (struct die_info *die, > struct dwarf2_cu *cu); > @@ -8679,9 +8683,9 @@ process_die (struct die_info *die, struct dwarf2_cu *cu) > break; > case DW_TAG_imported_declaration: > cu->processing_has_namespace_info = true; > - if (read_namespace_alias (die, cu)) > + if (read_alias (die, cu)) > break; > - /* The declaration is not a global namespace alias. */ > + /* The declaration is not a global namespace or variable alias. */ > /* Fall through. */ > case DW_TAG_imported_module: > cu->processing_has_namespace_info = true; > @@ -9149,18 +9153,19 @@ dwarf2_physname (const char *name, struct die_info *die, struct dwarf2_cu *cu) > return retval; > } > > -/* Inspect DIE in CU for a namespace alias. If one exists, record > - a new symbol for it. > +/* Inspect DIE in CU for a namespace alias or a variable > + with alias attribute. If one exists, record a new symbol > + for it. > > - Returns 1 if a namespace alias was recorded, 0 otherwise. */ > + Returns "true" if an alias was recorded, "false" otherwise. */ > > -static int > -read_namespace_alias (struct die_info *die, struct dwarf2_cu *cu) > +static bool > +read_alias (struct die_info *die, struct dwarf2_cu *cu) > { > struct attribute *attr; > > - /* If the die does not have a name, this is not a namespace > - alias. */ > + /* If the die does not have a name, this is not a namespace alias > + or variable alias. */ > attr = dwarf2_attr (die, DW_AT_name, cu); > if (attr != NULL) > { > @@ -9186,26 +9191,39 @@ read_namespace_alias (struct die_info *die, struct dwarf2_cu *cu) > { > complaint (_("DIE at %s has too many recursively imported " > "declarations"), sect_offset_str (d->sect_off)); > - return 0; > + return false; > } > > if (attr != NULL) > { > struct type *type; > - sect_offset sect_off = attr->get_ref_die_offset (); > - > - type = get_die_type_at_offset (sect_off, cu->per_cu, cu->per_objfile); > - if (type != NULL && type->code () == TYPE_CODE_NAMESPACE) > + if (d->tag == DW_TAG_variable) > { > - /* This declaration is a global namespace alias. Add > - a symbol for it whose type is the aliased namespace. */ > - new_symbol (die, type, cu); > - return 1; > + /* This declaration is a C/C++ global variable alias. Add > + a symbol for it whose type is same as aliased variable. */ > + type = die_type (d, imported_cu); > + struct symbol *sym = new_symbol (die, type, cu); > + attr = dwarf2_attr (d, DW_AT_location, imported_cu); > + sym->set_aclass_index (LOC_UNRESOLVED); > + if (attr != nullptr) > + var_decode_location (attr, sym, cu); > + return true; > + } > + else > + { > + sect_offset sect_off = attr->get_ref_die_offset (); > + type = get_die_type_at_offset (sect_off, cu->per_cu, cu->per_objfile); > + if (type != NULL && type->code () == TYPE_CODE_NAMESPACE) > + { > + /* This declaration is a global namespace alias. Add > + a symbol for it whose type is the aliased namespace. */ > + new_symbol (die, type, cu); > + return true; > + } > } > } > } > - > - return 0; > + return false; > } > > /* Return the using directives repository (global or local?) to use in the > diff --git a/gdb/testsuite/gdb.base/symbol-alias.exp b/gdb/testsuite/gdb.base/symbol-alias.exp > index 289f49bbc3f..564b43086bc 100644 > --- a/gdb/testsuite/gdb.base/symbol-alias.exp > +++ b/gdb/testsuite/gdb.base/symbol-alias.exp > @@ -15,6 +15,9 @@ > # along with this program. If not, see . > > standard_testfile symbol-alias.c symbol-alias2.c > +set using_clang [test_compiler_info clang-*] > +set old_clang [expr [test_compiler_info {clang-1[0-3]-*-*}] \ > + || [test_compiler_info {clang-[1-9]-*}]] > > if { [prepare_for_testing "failed to prepare" ${testfile} [list $srcfile $srcfile2]] } { > return -1 > @@ -31,6 +34,62 @@ foreach f {"func" "func_alias"} { > } > > # Variables. > -foreach v {"g_var_s" "g_var_s_alias"} { > - gdb_test "p $v" "= {field1 = 1, field2 = 2}" > +gdb_test "p g_var_s" "= {field1 = 1, field2 = 2}" > +foreach v {"g_var_s_alias" "g_var_s_alias2"} { > + gdb_test_multiple "p $v" "print alias variable $v" { > + -re -wrap " = {field1 = 1, field2 = 2}" { > + pass $gdb_test_name > + } > + -re -wrap "has unknown type; cast it to its declared type" { > + if { $old_clang } { > + xfail $gdb_test_name > + } else { > + fail $gdb_test_name > + } > + } > + } > +} > + > +# Static Variable. > +gdb_test "p g_var" " = 1" > +gdb_test_multiple "p g_var_alias" "print alias of static variable" { > + -re -wrap " = 1" { > + pass $gdb_test_name > + } > + -re -wrap "has unknown type; cast it to its declared type" { > + if { $old_clang } { > + xfail $gdb_test_name > + } else { > + fail $gdb_test_name > + } > + } > +} > + > +# Deferred Variable. > +gdb_test "p g_def_var" " = 2" > +gdb_test_multiple "p g_def_var_alias" "print alias of deferred variable" { > + -re -wrap " = 2" { > + pass $gdb_test_name > + } > + -re -wrap "has unknown type; cast it to its declared type" { > + if { $using_clang } { > + xfail $gdb_test_name > + } else { > + fail $gdb_test_name > + } > + } > +} > + > +# Alias of deferred Variable alias. > +gdb_test_multiple "p g_def_var2_alias2" "print alias of alias of deferred variable" { > + -re -wrap " = 3" { > + pass $gdb_test_name > + } > + -re -wrap "has unknown type; cast it to its declared type" { > + if { $old_clang } { > + xfail $gdb_test_name > + } else { > + fail $gdb_test_name > + } > + } > } > diff --git a/gdb/testsuite/gdb.base/symbol-alias2.c b/gdb/testsuite/gdb.base/symbol-alias2.c > index 34f4e121e25..41d4b6a53e5 100644 > --- a/gdb/testsuite/gdb.base/symbol-alias2.c > +++ b/gdb/testsuite/gdb.base/symbol-alias2.c > @@ -23,6 +23,8 @@ struct S > > struct S g_var_s = { 1, 2 }; > > +static int g_var = 1; > + > #ifdef __cplusplus > /* So that the alias attribute below work without having to figure out > this function's mangled name. */ > @@ -38,3 +40,17 @@ func (void) > struct S *func_alias (void) __attribute__ ((alias ("func"))); > > extern struct S g_var_s_alias __attribute__ ((alias ("g_var_s"))); > + > +extern struct S g_var_s_alias2 __attribute__ ((alias ("g_var_s_alias"))); > + > +extern int g_var_alias __attribute__ ((alias ("g_var"))); > + > +extern int g_def_var_alias __attribute__ ((alias ("g_def_var"))); > + > +int g_def_var = 2; > + > +extern int g_def_var2_alias __attribute__ ((alias ("g_def_var2"))); > + > +int g_def_var2 = 3; > + > +extern int g_def_var2_alias2 __attribute__ ((alias ("g_def_var2_alias"))); > -- > >