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

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