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