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

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