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

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