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

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