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

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