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

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