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

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