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

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