From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2114) id 496263857432; Sun, 22 May 2022 16:18:40 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 496263857432 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable From: Alok Kumar Sharma To: gdb-cvs@sourceware.org Subject: [binutils-gdb] Accept functions with DW_AT_linkage_name present X-Act-Checkin: binutils-gdb X-Git-Author: Alok Kumar Sharma X-Git-Refname: refs/heads/master X-Git-Oldrev: cb3a7614feb82ffdc25161bf60529116c6112ab3 X-Git-Newrev: 6f9b09edaee43ea34d34b1998fe7b844834f251a Message-Id: <20220522161840.496263857432@sourceware.org> Date: Sun, 22 May 2022 16:18:40 +0000 (GMT) X-BeenThere: gdb-cvs@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-cvs mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 22 May 2022 16:18:40 -0000 https://sourceware.org/git/gitweb.cgi?p=3Dbinutils-gdb.git;h=3D6f9b09edaee4= 3ea34d34b1998fe7b844834f251a commit 6f9b09edaee43ea34d34b1998fe7b844834f251a Author: Alok Kumar Sharma Date: Sun May 22 21:46:06 2022 +0530 Accept functions with DW_AT_linkage_name present =20 Currently GDB is not able to debug (Binary generated with Clang) variab= les present in shared/private clause of OpenMP Task construct. Please note = that LLVM debugger LLDB is able to debug. =20 In case of OpenMP, compilers generate artificial functions which are not present in actual program. This is done to apply parallelism to block of code. =20 For non-artifical functions, DW_AT_name attribute should contains the n= ame exactly as present in actual program. (Ref# http://wiki.dwarfstd.org/index.php?title=3DBest_Practices) Since artificial functions are not present in actual program they not h= aving DW_AT_name and having DW_AT_linkage_name instead should be fine. =20 Currently GDB is invalidating any function not havnig DW_AT_name which = is why it is not able to debug OpenMP (Clang). =20 It should be fair to fallback to check DW_AT_linkage_name in case DW_AT= _name is absent. Diff: --- gdb/dwarf2/read.c | 16 ++++++++++- gdb/testsuite/gdb.threads/omp-task.c | 49 ++++++++++++++++++++++++++++++= ++ gdb/testsuite/gdb.threads/omp-task.exp | 51 ++++++++++++++++++++++++++++++= ++++ 3 files changed, 115 insertions(+), 1 deletion(-) diff --git a/gdb/dwarf2/read.c b/gdb/dwarf2/read.c index d146d525066..b7ad75e3a29 100644 --- a/gdb/dwarf2/read.c +++ b/gdb/dwarf2/read.c @@ -11926,6 +11926,8 @@ read_func_scope (struct die_info *die, struct dwarf= 2_cu *cu) baseaddr =3D objfile->text_section_offset (); =20 name =3D dwarf2_name (die, cu); + if (name =3D=3D nullptr) + name =3D dw2_linkage_name (die, cu); =20 /* Ignore functions with missing or empty names. These are actually illegal according to the DWARF standard. */ @@ -18320,7 +18322,14 @@ cooked_indexer::index_dies (cutu_reader *reader, but not an ordinary name. */ if (name !=3D nullptr) flags =3D flags & ~IS_MAIN; - m_index_storage->add (this_die, abbrev->tag, flags | IS_LINKAGE, + /* Set the IS_LINKAGE on for everything except when functions + have linkage name present but name is absent. */ + if (name !=3D nullptr + || (abbrev->tag !=3D DW_TAG_subprogram + && abbrev->tag !=3D DW_TAG_inlined_subroutine + && abbrev->tag !=3D DW_TAG_entry_point)) + flags =3D flags | IS_LINKAGE; + m_index_storage->add (this_die, abbrev->tag, flags, linkage_name, nullptr, m_per_cu); } =20 @@ -20597,6 +20606,11 @@ new_symbol (struct die_info *die, struct type *typ= e, struct dwarf2_cu *cu, baseaddr =3D objfile->text_section_offset (); =20 name =3D dwarf2_name (die, cu); + if (name =3D=3D nullptr && (die->tag =3D=3D DW_TAG_subprogram + || die->tag =3D=3D DW_TAG_inlined_subroutine + || die->tag =3D=3D DW_TAG_entry_point)) + name =3D dw2_linkage_name (die, cu); + if (name) { int suppress_add =3D 0; diff --git a/gdb/testsuite/gdb.threads/omp-task.c b/gdb/testsuite/gdb.threa= ds/omp-task.c new file mode 100644 index 00000000000..bdeeae501cb --- /dev/null +++ b/gdb/testsuite/gdb.threads/omp-task.c @@ -0,0 +1,49 @@ +/* This testcase is part of GDB, the GNU debugger. + + Copyright 2022 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 . + + Tests which verify (or not) that GDB can access shared and private + clauses of OpenMP task construct. +*/ + +#include +#include + +int foo(int n) { + int share1 =3D 9, share2 =3D 11, share3 =3D 13, priv1, priv2, fpriv; + fpriv =3D n + 4; + + if (n < 2) + return n; + else { +#pragma omp task shared(share1, share2) private(priv1, priv2) firstprivate= (fpriv) shared(share3) + { + priv1 =3D n; + priv2 =3D n + 2; + share2 +=3D share3; + printf("share1 =3D %d, share2 =3D %d, share3 =3D %d\n", share1, shar= e2, share3); + share1 =3D priv1 + priv2 + fpriv + foo(n - 1) + share2 + share3; + } +#pragma omp taskwait + return share1 + share2 + share3; + } +} + +int main() { + int n =3D 10; + printf("foo(%d) =3D %d\n", n, foo(n)); + return 0; +} diff --git a/gdb/testsuite/gdb.threads/omp-task.exp b/gdb/testsuite/gdb.thr= eads/omp-task.exp new file mode 100644 index 00000000000..8f46658fe0d --- /dev/null +++ b/gdb/testsuite/gdb.threads/omp-task.exp @@ -0,0 +1,51 @@ +# Copyright 2022 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 . + +# This file is part of the gdb testsuite. + +# Tests which verify (or not) that GDB can access shared and private +# clauses of OpenMP task construct. + +standard_testfile + +set have_nested_function_support 0 +set opts {openmp debug} + +if {[prepare_for_testing "failed to prepare" $testfile $srcfile $opts]} { + return -1 +} + +if {[info procs gdb_openmp_setup] !=3D ""} { + if {[gdb_openmp_setup $binfile] !=3D ""} { + untested "could not set up OpenMP environment" + return -1 + } +} + +if {![runto_main]} { + return -1 +} + +gdb_breakpoint [gdb_get_line_number "omp task shared"] +gdb_test "continue" ".*Breakpoint 2.*" "continue 1" +gdb_test "print share1" "=3D 9" +gdb_test "print share2" "=3D 11" +gdb_test "print share3" "=3D 13" +gdb_test "disable 2" ".*" +gdb_breakpoint [gdb_get_line_number "share1 =3D priv1"] +gdb_test "continue" ".*Breakpoint 3.*" "continue 2" +gdb_test "print priv1" "=3D 10" +gdb_test "print priv2" "=3D 12" +gdb_test "print fpriv" "=3D 14"