Blame SOURCES/gdb-bz533176-fortran-omp-step.patch

7bc85d
From FEDORA_PATCHES Mon Sep 17 00:00:00 2001
7bc85d
From: Fedora GDB patches <invalid@email.com>
7bc85d
Date: Fri, 27 Oct 2017 21:07:50 +0200
7bc85d
Subject: gdb-bz533176-fortran-omp-step.patch
7bc85d
7bc85d
;; Fix stepping with OMP parallel Fortran sections (BZ 533176).
7bc85d
;;=push+jan: It requires some better DWARF annotations.
7bc85d
7bc85d
https://bugzilla.redhat.com/show_bug.cgi?id=533176#c4
7bc85d
7bc85d
I find it a bug in DWARF and gdb behaves correctly according to it.  From the
7bc85d
current DWARF's point of view the is a function call which you skip by "next".
7bc85d
7bc85d
If you hide any /usr/lib/debug such as using:
7bc85d
gdb -nx -ex 'set debug-file-directory /qwe' -ex 'file ./tpcommon_gfortran44'
7bc85d
and use "step" command instead of "next" there it will work.
7bc85d
(You need to hide debuginfo from libgomp as you would step into libgomp sources
7bc85d
to maintain the threads for execution.)
7bc85d
7bc85d
There should be some DWARF extension for it, currently tried to detect
7bc85d
substring ".omp_fn." as this function is called "MAIN__.omp_fn.0" and do not
7bc85d
consider such sub-function as a skippable by "next".
7bc85d
7bc85d
Another problem is that with "set scheduler-locking" being "off" (default
7bc85d
upstream) or "step" (default in F/RHEL) the simultaneous execution of the
7bc85d
threads is inconvenient.  Setting it to "on" will lockup the debugging as the
7bc85d
threads need to get synchronized at some point.  This is a more general
7bc85d
debugging problem of GOMP outside of the scope of this Bug.
7bc85d
7bc85d
diff --git a/gdb/infrun.c b/gdb/infrun.c
7bc85d
--- a/gdb/infrun.c
7bc85d
+++ b/gdb/infrun.c
7bc85d
@@ -6695,6 +6695,16 @@ process_event_stop_test (struct execution_control_state *ecs)
7bc85d
 
7bc85d
       if (ecs->event_thread->control.step_over_calls == STEP_OVER_ALL)
7bc85d
 	{
7bc85d
+	  struct symbol *stop_fn = find_pc_function (stop_pc);
7bc85d
+	  struct minimal_symbol *stopf = lookup_minimal_symbol_by_pc (stop_pc).minsym;
7bc85d
+
7bc85d
+	  if ((stop_fn == NULL
7bc85d
+	       || strstr (SYMBOL_LINKAGE_NAME (stop_fn), ".omp_fn.") == NULL)
7bc85d
+	      /* gcc-4.7.2-9.fc19.x86_64 uses a new format.  */
7bc85d
+	      && (stopf == NULL
7bc85d
+		  || strstr (MSYMBOL_LINKAGE_NAME (stopf), "._omp_fn.") == NULL))
7bc85d
+{	/* ".omp_fn." */
7bc85d
+
7bc85d
 	  /* We're doing a "next".
7bc85d
 
7bc85d
 	     Normal (forward) execution: set a breakpoint at the
7bc85d
@@ -6728,6 +6738,7 @@ process_event_stop_test (struct execution_control_state *ecs)
7bc85d
 
7bc85d
 	  keep_going (ecs);
7bc85d
 	  return;
7bc85d
+}	/* ".omp_fn." */
7bc85d
 	}
7bc85d
 
7bc85d
       /* If we are in a function call trampoline (a stub between the
7bc85d
diff --git a/gdb/testsuite/gdb.fortran/omp-step.exp b/gdb/testsuite/gdb.fortran/omp-step.exp
7bc85d
new file mode 100644
7bc85d
--- /dev/null
7bc85d
+++ b/gdb/testsuite/gdb.fortran/omp-step.exp
7bc85d
@@ -0,0 +1,31 @@
7bc85d
+# Copyright 2009 Free Software Foundation, Inc.
7bc85d
+
7bc85d
+# This program is free software; you can redistribute it and/or modify
7bc85d
+# it under the terms of the GNU General Public License as published by
7bc85d
+# the Free Software Foundation; either version 3 of the License, or
7bc85d
+# (at your option) any later version.
7bc85d
+#
7bc85d
+# This program is distributed in the hope that it will be useful,
7bc85d
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
7bc85d
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
7bc85d
+# GNU General Public License for more details.
7bc85d
+#
7bc85d
+# You should have received a copy of the GNU General Public License
7bc85d
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
7bc85d
+
7bc85d
+set testfile "omp-step"
7bc85d
+set srcfile ${testfile}.f90
7bc85d
+if { [prepare_for_testing $testfile.exp $testfile $srcfile {debug f90 additional_flags=-fopenmp}] } {
7bc85d
+    return -1
7bc85d
+}
7bc85d
+
7bc85d
+if ![runto [gdb_get_line_number "start-here"]] {
7bc85d
+    perror "Couldn't run to start-here"
7bc85d
+    return 0
7bc85d
+}
7bc85d
+
7bc85d
+gdb_test "next" {!\$omp parallel} "step closer"
7bc85d
+gdb_test "next" {a\(omp_get_thread_num\(\) \+ 1\) = 1} "step into omp"
7bc85d
+
7bc85d
+gdb_breakpoint [gdb_get_line_number "success"]
7bc85d
+gdb_continue_to_breakpoint "success" ".*success.*"
7bc85d
diff --git a/gdb/testsuite/gdb.fortran/omp-step.f90 b/gdb/testsuite/gdb.fortran/omp-step.f90
7bc85d
new file mode 100644
7bc85d
--- /dev/null
7bc85d
+++ b/gdb/testsuite/gdb.fortran/omp-step.f90
7bc85d
@@ -0,0 +1,32 @@
7bc85d
+! Copyright 2009 Free Software Foundation, Inc.
7bc85d
+
7bc85d
+! This program is free software; you can redistribute it and/or modify
7bc85d
+! it under the terms of the GNU General Public License as published by
7bc85d
+! the Free Software Foundation; either version 3 of the License, or
7bc85d
+! (at your option) any later version.
7bc85d
+!
7bc85d
+! This program is distributed in the hope that it will be useful,
7bc85d
+! but WITHOUT ANY WARRANTY; without even the implied warranty of
7bc85d
+! MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
7bc85d
+! GNU General Public License for more details.
7bc85d
+!
7bc85d
+! You should have received a copy of the GNU General Public License
7bc85d
+! along with this program.  If not, see <http://www.gnu.org/licenses/>.
7bc85d
+
7bc85d
+      use omp_lib
7bc85d
+      integer nthreads, i, a(1000)
7bc85d
+      nthreads = omp_get_num_threads()
7bc85d
+      if (nthreads .gt. 1000) call abort
7bc85d
+
7bc85d
+      do i = 1, nthreads
7bc85d
+          a(i) = 0
7bc85d
+      end do
7bc85d
+      print *, "start-here"
7bc85d
+!$omp parallel
7bc85d
+      a(omp_get_thread_num() + 1) = 1
7bc85d
+!$omp end parallel
7bc85d
+      do i = 1, nthreads
7bc85d
+          if (a(i) .ne. 1) call abort
7bc85d
+      end do
7bc85d
+      print *, "success"
7bc85d
+      end