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

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