public inbox for gdb-cvs@sourceware.org
help / color / mirror / Atom feed
* [binutils-gdb] Accept functions with DW_AT_linkage_name present
@ 2022-05-22 16:18 Alok Kumar Sharma
  0 siblings, 0 replies; only message in thread
From: Alok Kumar Sharma @ 2022-05-22 16:18 UTC (permalink / raw)
  To: gdb-cvs

https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=6f9b09edaee43ea34d34b1998fe7b844834f251a

commit 6f9b09edaee43ea34d34b1998fe7b844834f251a
Author: Alok Kumar Sharma <AlokKumar.Sharma@amd.com>
Date:   Sun May 22 21:46:06 2022 +0530

    Accept functions with DW_AT_linkage_name present
    
    Currently GDB is not able to debug (Binary generated with Clang) variables
    present in shared/private clause of OpenMP Task construct. Please note that
    LLVM debugger LLDB is able to debug.
    
    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.
    
    For non-artifical functions, DW_AT_name attribute should contains the name
    exactly as present in actual program.
    (Ref# http://wiki.dwarfstd.org/index.php?title=Best_Practices)
    Since artificial functions are not present in actual program they not having
    DW_AT_name and having DW_AT_linkage_name instead should be fine.
    
    Currently GDB is invalidating any function not havnig DW_AT_name which is why
    it is not able to debug OpenMP (Clang).
    
    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 dwarf2_cu *cu)
   baseaddr = objfile->text_section_offset ();
 
   name = dwarf2_name (die, cu);
+  if (name == nullptr)
+    name = dw2_linkage_name (die, cu);
 
   /* 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 != nullptr)
 	    flags = 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 != nullptr
+	      || (abbrev->tag != DW_TAG_subprogram
+	          && abbrev->tag != DW_TAG_inlined_subroutine
+	          && abbrev->tag != DW_TAG_entry_point))
+	    flags = flags | IS_LINKAGE;
+	  m_index_storage->add (this_die, abbrev->tag, flags,
 				linkage_name, nullptr, m_per_cu);
 	}
 
@@ -20597,6 +20606,11 @@ new_symbol (struct die_info *die, struct type *type, struct dwarf2_cu *cu,
   baseaddr = objfile->text_section_offset ();
 
   name = dwarf2_name (die, cu);
+  if (name == nullptr && (die->tag == DW_TAG_subprogram
+                          || die->tag == DW_TAG_inlined_subroutine
+                          || die->tag == DW_TAG_entry_point))
+    name = dw2_linkage_name (die, cu);
+
   if (name)
     {
       int suppress_add = 0;
diff --git a/gdb/testsuite/gdb.threads/omp-task.c b/gdb/testsuite/gdb.threads/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 <http://www.gnu.org/licenses/>.
+
+   Tests which verify (or not) that GDB can access shared and private
+   clauses of OpenMP task construct.
+*/
+
+#include <stdio.h>
+#include <omp.h>
+
+int foo(int n) {
+  int share1 = 9, share2 = 11, share3 = 13, priv1, priv2, fpriv;
+  fpriv = n + 4;
+
+  if (n < 2)
+    return n;
+  else {
+#pragma omp task shared(share1, share2) private(priv1, priv2) firstprivate(fpriv) shared(share3)
+    {
+      priv1 = n;
+      priv2 = n + 2;
+      share2 += share3;
+      printf("share1 = %d, share2 = %d, share3 = %d\n", share1, share2, share3);
+      share1 = priv1 + priv2 + fpriv + foo(n - 1) + share2 + share3;
+    }
+#pragma omp taskwait
+    return share1 + share2 + share3;
+  }
+}
+
+int main() {
+  int n = 10;
+  printf("foo(%d) = %d\n", n, foo(n));
+  return 0;
+}
diff --git a/gdb/testsuite/gdb.threads/omp-task.exp b/gdb/testsuite/gdb.threads/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 <http://www.gnu.org/licenses/>.
+
+# 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] != ""} {
+    if {[gdb_openmp_setup $binfile] != ""} {
+	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" "= 9"
+gdb_test "print share2" "= 11"
+gdb_test "print share3" "= 13"
+gdb_test "disable 2" ".*"
+gdb_breakpoint [gdb_get_line_number "share1 = priv1"]
+gdb_test "continue" ".*Breakpoint 3.*" "continue 2"
+gdb_test "print priv1" "= 10"
+gdb_test "print priv2" "= 12"
+gdb_test "print fpriv" "= 14"


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2022-05-22 16:18 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-05-22 16:18 [binutils-gdb] Accept functions with DW_AT_linkage_name present Alok Kumar Sharma

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).