This is the mail archive of the archer@sourceware.org mailing list for the Archer project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[archer-jankratochvil-misc] Fix ignored breakpoint at the entryaddress [resend]


A bit longstanding Fedora bug I was also commonly facing myself.

https://bugzilla.redhat.com/show_bug.cgi?id=162775

2008-12-02  Jan Kratochvil  <jan.kratochvil@redhat.com>

	Fix ignored breakpoint at the entry address of a nostdlib executable.
	* breakpoint.c (bpstat_what): Remove macro `shl', remove it from
	`bpstat_what_main_action'.  Pre-clear whole `retval'
	(bpstat_what <bp_shlib_event>): Set `retval.check_shlib'.
	* breakpoint.h (enum bpstat_what_main_action): Remove
	BPSTAT_WHAT_CHECK_SHLIBS.
	(struct bpstat_what): New field `check_shlib'.
	* infrun.c (handle_inferior_event <BPSTAT_WHAT_CHECK_SHLIBS>): Move ...
	(handle_inferior_event <what.check_shlib>): ... it here.

2008-12-02  Jan Kratochvil  <jan.kratochvil@redhat.com>

	Test ignored breakpoint at the entry address of a nostdlib executable.
	* gdb.base/entry.exp, gdb.base/entry.c: New.
---
 gdb/breakpoint.c                 |   27 +++++-----
 gdb/breakpoint.h                 |    8 ++--
 gdb/infrun.c                     |   98 ++++++++++++++++++-------------------
 gdb/testsuite/gdb.base/entry.c   |   29 +++++++++++
 gdb/testsuite/gdb.base/entry.exp |   46 ++++++++++++++++++
 5 files changed, 140 insertions(+), 68 deletions(-)
 create mode 100644 gdb/testsuite/gdb.base/entry.c
 create mode 100644 gdb/testsuite/gdb.base/entry.exp

diff --git a/gdb/breakpoint.c b/gdb/breakpoint.c
index e55d481..617f657 100644
--- a/gdb/breakpoint.c
+++ b/gdb/breakpoint.c
@@ -3068,7 +3068,6 @@ bpstat_what (bpstat bs)
 #define slr BPSTAT_WHAT_SET_LONGJMP_RESUME
 #define clr BPSTAT_WHAT_CLEAR_LONGJMP_RESUME
 #define sr BPSTAT_WHAT_STEP_RESUME
-#define shl BPSTAT_WHAT_CHECK_SHLIBS
 
 /* "Can't happen."  Might want to print an error message.
    abort() is not out of the question, but chances are GDB is just
@@ -3115,25 +3114,25 @@ bpstat_what (bpstat bs)
   /*       kc    ss    sn    sgl    slr   clr   sr   shl
    */
 /*no_effect */
-    {kc, ss, sn, sgl, slr, clr, sr, shl},
+    {kc, ss, sn, sgl, slr, clr, sr},
 /*wp_silent */
-    {ss, ss, sn, ss, ss, ss, sr, shl},
+    {ss, ss, sn, ss, ss, ss, sr},
 /*wp_noisy */
-    {sn, sn, sn, sn, sn, sn, sr, shl},
+    {sn, sn, sn, sn, sn, sn, sr},
 /*bp_nostop */
-    {sgl, ss, sn, sgl, slr, slr, sr, shl},
+    {sgl, ss, sn, sgl, slr, slr, sr},
 /*bp_silent */
-    {ss, ss, sn, ss, ss, ss, sr, shl},
+    {ss, ss, sn, ss, ss, ss, sr},
 /*bp_noisy */
-    {sn, sn, sn, sn, sn, sn, sr, shl},
+    {sn, sn, sn, sn, sn, sn, sr},
 /*long_jump */
-    {slr, ss, sn, slr, slr, err, sr, shl},
+    {slr, ss, sn, slr, slr, err, sr},
 /*long_resume */
-    {clr, ss, sn, err, err, err, sr, shl},
+    {clr, ss, sn, err, err, err, sr},
 /*step_resume */
-    {sr, sr, sr, sr, sr, sr, sr, sr},
-/*shlib */
-    {shl, shl, shl, shl, shl, shl, sr, shl}
+    {sr, sr, sr, sr, sr, sr, sr},
+/*shlib_event */
+    {kc, ss, sn, sgl, slr, clr, sr}
   };
 
 #undef kc
@@ -3145,11 +3144,10 @@ bpstat_what (bpstat bs)
 #undef err
 #undef sr
 #undef ts
-#undef shl
   enum bpstat_what_main_action current_action = BPSTAT_WHAT_KEEP_CHECKING;
   struct bpstat_what retval;
 
-  retval.call_dummy = 0;
+  memset (&retval, 0, sizeof (retval));
   for (; bs != NULL; bs = bs->next)
     {
       enum class bs_class = no_effect;
@@ -3215,6 +3213,7 @@ bpstat_what (bpstat bs)
 	  break;
 	case bp_shlib_event:
 	  bs_class = shlib_event;
+	  retval.check_shlib = 1;
 	  break;
 	case bp_thread_event:
 	case bp_overlay_event:
diff --git a/gdb/breakpoint.h b/gdb/breakpoint.h
index ef8121b..93dc559 100644
--- a/gdb/breakpoint.h
+++ b/gdb/breakpoint.h
@@ -515,10 +515,6 @@ enum bpstat_what_main_action
     /* Clear step resume breakpoint, and keep checking.  */
     BPSTAT_WHAT_STEP_RESUME,
 
-    /* Check the dynamic linker's data structures for new libraries, then
-       keep checking.  */
-    BPSTAT_WHAT_CHECK_SHLIBS,
-
     /* This is just used to keep track of how many enums there are.  */
     BPSTAT_WHAT_LAST
   };
@@ -532,6 +528,10 @@ struct bpstat_what
        continuing from a call dummy without popping the frame is not a
        useful one).  */
     int call_dummy;
+
+    /* Check the dynamic linker's data structures for new libraries, then
+       keep checking.  */
+    int check_shlib;
   };
 
 /* The possible return values for print_bpstat, print_it_normal,
diff --git a/gdb/infrun.c b/gdb/infrun.c
index 7264c02..c4bcd50 100644
--- a/gdb/infrun.c
+++ b/gdb/infrun.c
@@ -3055,6 +3055,54 @@ process_event_stop_test:
 	stop_stack_dummy = 1;
       }
 
+    if (what.check_shlib)
+      {
+	if (debug_infrun)
+	  fprintf_unfiltered (gdb_stdlog, "infrun: check_shlib\n");
+
+	/* Check for any newly added shared libraries if we're
+	   supposed to be adding them automatically.  Switch
+	   terminal for any messages produced by
+	   breakpoint_re_set.  */
+	target_terminal_ours_for_output ();
+	/* NOTE: cagney/2003-11-25: Make certain that the target
+	   stack's section table is kept up-to-date.  Architectures,
+	   (e.g., PPC64), use the section table to perform
+	   operations such as address => section name and hence
+	   require the table to contain all sections (including
+	   those found in shared libraries).  */
+	/* NOTE: cagney/2003-11-25: Pass current_target and not
+	   exec_ops to SOLIB_ADD.  This is because current GDB is
+	   only tooled to propagate section_table changes out from
+	   the "current_target" (see target_resize_to_sections), and
+	   not up from the exec stratum.  This, of course, isn't
+	   right.  "infrun.c" should only interact with the
+	   exec/process stratum, instead relying on the target stack
+	   to propagate relevant changes (stop, section table
+	   changed, ...) up to other layers.  */
+#ifdef SOLIB_ADD
+	SOLIB_ADD (NULL, 0, &current_target, auto_solib_add);
+#else
+	solib_add (NULL, 0, &current_target, auto_solib_add);
+#endif
+	target_terminal_inferior ();
+
+	/* If requested, stop when the dynamic linker notifies
+	   gdb of events.  This allows the user to get control
+	   and place breakpoints in initializer routines for
+	   dynamically loaded objects (among other things).  */
+	if (stop_on_solib_events || stop_stack_dummy)
+	  {
+	    stop_stepping (ecs);
+	    return;
+	  }
+	else
+	  {
+	    /* We want to step over this breakpoint, then keep going.  */
+	    ecs->event_thread->stepping_over_breakpoint = 1;
+	  }
+      }
+
     switch (what.main_action)
       {
       case BPSTAT_WHAT_SET_LONGJMP_RESUME:
@@ -3160,56 +3208,6 @@ infrun: BPSTAT_WHAT_SET_LONGJMP_RESUME (!gdbarch_get_longjmp_target)\n");
 	  }
 	break;
 
-      case BPSTAT_WHAT_CHECK_SHLIBS:
-	{
-          if (debug_infrun)
-	    fprintf_unfiltered (gdb_stdlog, "infrun: BPSTAT_WHAT_CHECK_SHLIBS\n");
-
-	  /* Check for any newly added shared libraries if we're
-	     supposed to be adding them automatically.  Switch
-	     terminal for any messages produced by
-	     breakpoint_re_set.  */
-	  target_terminal_ours_for_output ();
-	  /* NOTE: cagney/2003-11-25: Make certain that the target
-	     stack's section table is kept up-to-date.  Architectures,
-	     (e.g., PPC64), use the section table to perform
-	     operations such as address => section name and hence
-	     require the table to contain all sections (including
-	     those found in shared libraries).  */
-	  /* NOTE: cagney/2003-11-25: Pass current_target and not
-	     exec_ops to SOLIB_ADD.  This is because current GDB is
-	     only tooled to propagate section_table changes out from
-	     the "current_target" (see target_resize_to_sections), and
-	     not up from the exec stratum.  This, of course, isn't
-	     right.  "infrun.c" should only interact with the
-	     exec/process stratum, instead relying on the target stack
-	     to propagate relevant changes (stop, section table
-	     changed, ...) up to other layers.  */
-#ifdef SOLIB_ADD
-	  SOLIB_ADD (NULL, 0, &current_target, auto_solib_add);
-#else
-	  solib_add (NULL, 0, &current_target, auto_solib_add);
-#endif
-	  target_terminal_inferior ();
-
-	  /* If requested, stop when the dynamic linker notifies
-	     gdb of events.  This allows the user to get control
-	     and place breakpoints in initializer routines for
-	     dynamically loaded objects (among other things).  */
-	  if (stop_on_solib_events || stop_stack_dummy)
-	    {
-	      stop_stepping (ecs);
-	      return;
-	    }
-	  else
-	    {
-	      /* We want to step over this breakpoint, then keep going.  */
-	      ecs->event_thread->stepping_over_breakpoint = 1;
-	      break;
-	    }
-	}
-	break;
-
       case BPSTAT_WHAT_LAST:
 	/* Not a real code, but listed here to shut up gcc -Wall.  */
 
diff --git a/gdb/testsuite/gdb.base/entry.c b/gdb/testsuite/gdb.base/entry.c
new file mode 100644
index 0000000..770c78c
--- /dev/null
+++ b/gdb/testsuite/gdb.base/entry.c
@@ -0,0 +1,29 @@
+/* This testcase is part of GDB, the GNU debugger.
+
+   Copyright 2008 Free Software Foundation, Inc.
+
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 3 of the License, or
+   (at your option) any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
+
+void
+_start (void)
+{
+  for (;;)
+    *(int *) _start = 1;
+}
+
+int
+main (void)
+{
+  return 0;
+}
diff --git a/gdb/testsuite/gdb.base/entry.exp b/gdb/testsuite/gdb.base/entry.exp
new file mode 100644
index 0000000..7616ec1
--- /dev/null
+++ b/gdb/testsuite/gdb.base/entry.exp
@@ -0,0 +1,46 @@
+# Copyright 2008 Free Software Foundation, Inc.
+
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+# Test ignored breakpoint at the entry address of a nostdlib executable.
+
+if [get_compiler_info "ignored"] {
+    return -1
+}
+
+# Require GCC for -nostdlib.
+if {$gcc_compiled == 0} {
+    return -1
+}
+
+# -nostdlib is required as the testcase needs to force GDB to place the
+# breakpoint at `_start'.  With libc it would find `_dl_debug_state' and place
+# it there which would not match the address of our user breakpoint set below.
+
+set testfile entry
+set srcfile ${testfile}.c
+set binfile ${objdir}/${subdir}/${testfile}
+if  { [gdb_compile "${srcdir}/${subdir}/${srcfile} -static -nostdlib" "${binfile}" executable {debug}] != "" } {
+    untested "Couldn't compile test program"
+    return -1
+}
+
+gdb_exit
+gdb_start
+gdb_reinitialize_dir $srcdir/$subdir
+gdb_load ${binfile}
+
+gdb_breakpoint "*_start"
+gdb_run_cmd
+gdb_test "" "Breakpoint \[0-9\]+, _start .*" "run"
-- 
1.6.0.4


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]