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

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