This is the mail archive of the gdb-patches@sourceware.org mailing list for the GDB 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]

[3/3] RFC: fix PR mi/8444


This patch actually fixes the PR.

It at least needs a doc review.

I noticed several stop reasons which were not emitted.  This patch fixes
them all.  I documented all the new reasons.  Most of the patch is
changing various print_it methods to use uiout.  I made the various new
reasons also emit other fields that seemed appropriate.

I added a test case which covers the specific case in the PR (solib
events), but I didn't try to cover every case.

The test case uses "run" instead of "-exec-run" in order to also test
the previous patch.

Tom

2011-11-16  Tom Tromey  <tromey@redhat.com>

	PR mi/8444:
	* mi/mi-common.h (EXEC_ASYNC_SOLIB_EVENT, EXEC_ASYNC_FORK)
	(EXEC_ASYNC_VFORK, EXEC_ASYNC_SYSCALL_ENTRY)
	(EXEC_ASYNC_SYSCALL_RETURN, EXEC_ASYNC_EXEC): New constants.
	* mi/mi-common.c (async_reason_string_lookup): Add new reasons.
	* breakpoint.c (print_it_catch_fork, print_it_catch_vfork)
	(print_it_catch_syscall, print_it_catch_exec)
	(internal_bkpt_print_it): Use ui_out.  Emit stop reason.

2011-11-16  Tom Tromey  <tromey@redhat.com>

	* gdb.texinfo (GDB/MI Async Records): Document new *stopped
	reasons.

2011-11-16  Tom Tromey  <tromey@redhat.com>

	* lib/mi-support.exp (mi_run_cmd_full): Rename from mi_run_cmd.
	Add "use_mi_command" argument.
	(mi_run_cmd, mi_run_with_cli): New procs.
	* gdb.mi/solib-lib.c: New file.
	* gdb.mi/solib-main.c: New file.
	* gdb.mi/mi-solib.exp: New file.

>From f9ccf49896650cd458c4e6e2561d2e9cc48c788d Mon Sep 17 00:00:00 2001
From: Tom Tromey <tromey@redhat.com>
Date: Wed, 16 Nov 2011 08:31:11 -0700
Subject: [PATCH 3/3] fix PR 8444

---
 gdb/ChangeLog                     |   11 +++++
 gdb/breakpoint.c                  |   90 +++++++++++++++++++++++++++++-------
 gdb/doc/ChangeLog                 |    5 ++
 gdb/doc/gdb.texinfo               |   19 ++++++++
 gdb/mi/mi-common.c                |    6 +++
 gdb/mi/mi-common.h                |    6 +++
 gdb/testsuite/ChangeLog           |    9 ++++
 gdb/testsuite/gdb.mi/mi-solib.exp |   55 ++++++++++++++++++++++
 gdb/testsuite/gdb.mi/solib-lib.c  |   20 ++++++++
 gdb/testsuite/gdb.mi/solib-main.c |   24 ++++++++++
 gdb/testsuite/lib/mi-support.exp  |   26 +++++++++--
 11 files changed, 248 insertions(+), 23 deletions(-)
 create mode 100644 gdb/testsuite/gdb.mi/mi-solib.exp
 create mode 100644 gdb/testsuite/gdb.mi/solib-lib.c
 create mode 100644 gdb/testsuite/gdb.mi/solib-main.c

diff --git a/gdb/breakpoint.c b/gdb/breakpoint.c
index 8f09296..3eed4b2 100644
--- a/gdb/breakpoint.c
+++ b/gdb/breakpoint.c
@@ -6176,12 +6176,25 @@ breakpoint_hit_catch_fork (const struct bp_location *bl,
 static enum print_stop_action
 print_it_catch_fork (bpstat bs)
 {
+  struct ui_out *uiout = current_uiout;
   struct breakpoint *b = bs->breakpoint_at;
   struct fork_catchpoint *c = (struct fork_catchpoint *) bs->breakpoint_at;
 
   annotate_catchpoint (b->number);
-  printf_filtered (_("\nCatchpoint %d (forked process %d), "),
-		   b->number, ptid_get_pid (c->forked_inferior_pid));
+  if (b->disposition == disp_del)
+    ui_out_text (uiout, "\nTemporary catchpoint ");
+  else
+    ui_out_text (uiout, "\nCatchpoint ");
+  if (ui_out_is_mi_like_p (uiout))
+    {
+      ui_out_field_string (uiout, "reason",
+			   async_reason_lookup (EXEC_ASYNC_FORK));
+      ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition));
+    }
+  ui_out_field_int (uiout, "bkptno", b->number);
+  ui_out_text (uiout, " (forked process ");
+  ui_out_field_int (uiout, "newpid", ptid_get_pid (c->forked_inferior_pid));
+  ui_out_text (uiout, "), ");
   return PRINT_SRC_AND_LOC;
 }
 
@@ -6272,12 +6285,25 @@ breakpoint_hit_catch_vfork (const struct bp_location *bl,
 static enum print_stop_action
 print_it_catch_vfork (bpstat bs)
 {
+  struct ui_out *uiout = current_uiout;
   struct breakpoint *b = bs->breakpoint_at;
   struct fork_catchpoint *c = (struct fork_catchpoint *) b;
 
   annotate_catchpoint (b->number);
-  printf_filtered (_("\nCatchpoint %d (vforked process %d), "),
-		   b->number, ptid_get_pid (c->forked_inferior_pid));
+  if (b->disposition == disp_del)
+    ui_out_text (uiout, "\nTemporary catchpoint ");
+  else
+    ui_out_text (uiout, "\nCatchpoint ");
+  if (ui_out_is_mi_like_p (uiout))
+    {
+      ui_out_field_string (uiout, "reason",
+			   async_reason_lookup (EXEC_ASYNC_VFORK));
+      ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition));
+    }
+  ui_out_field_int (uiout, "bkptno", b->number);
+  ui_out_text (uiout, " (vforked process ");
+  ui_out_field_int (uiout, "newpid", ptid_get_pid (c->forked_inferior_pid));
+  ui_out_text (uiout, "), ");
   return PRINT_SRC_AND_LOC;
 }
 
@@ -6486,6 +6512,7 @@ breakpoint_hit_catch_syscall (const struct bp_location *bl,
 static enum print_stop_action
 print_it_catch_syscall (bpstat bs)
 {
+  struct ui_out *uiout = current_uiout;
   struct breakpoint *b = bs->breakpoint_at;
   /* These are needed because we want to know in which state a
      syscall is.  It can be in the TARGET_WAITKIND_SYSCALL_ENTRY
@@ -6494,7 +6521,6 @@ print_it_catch_syscall (bpstat bs)
   ptid_t ptid;
   struct target_waitstatus last;
   struct syscall s;
-  struct cleanup *old_chain;
   char *syscall_id;
 
   get_last_target_status (&ptid, &last);
@@ -6503,21 +6529,31 @@ print_it_catch_syscall (bpstat bs)
 
   annotate_catchpoint (b->number);
 
-  if (s.name == NULL)
-    syscall_id = xstrprintf ("%d", last.value.syscall_number);
+  if (b->disposition == disp_del)
+    ui_out_text (uiout, "\nTemporary catchpoint ");
   else
-    syscall_id = xstrprintf ("'%s'", s.name);
-
-  old_chain = make_cleanup (xfree, syscall_id);
+    ui_out_text (uiout, "\nCatchpoint ");
+  if (ui_out_is_mi_like_p (uiout))
+    {
+      ui_out_field_string (uiout, "reason",
+			   async_reason_lookup (last.kind == TARGET_WAITKIND_SYSCALL_ENTRY
+						? EXEC_ASYNC_SYSCALL_ENTRY
+						: EXEC_ASYNC_SYSCALL_RETURN));
+      ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition));
+    }
+  ui_out_field_int (uiout, "bkptno", b->number);
 
   if (last.kind == TARGET_WAITKIND_SYSCALL_ENTRY)
-    printf_filtered (_("\nCatchpoint %d (call to syscall %s), "),
-                     b->number, syscall_id);
-  else if (last.kind == TARGET_WAITKIND_SYSCALL_RETURN)
-    printf_filtered (_("\nCatchpoint %d (returned from syscall %s), "),
-                     b->number, syscall_id);
+    ui_out_text (uiout, " (call to syscall ");
+  else
+    ui_out_text (uiout, " (returned from syscall ");
 
-  do_cleanups (old_chain);
+  if (s.name == NULL || ui_out_is_mi_like_p (uiout))
+    ui_out_field_int (uiout, "syscall-number", last.value.syscall_number);
+  if (s.name != NULL)
+    ui_out_field_string (uiout, "syscall-name", s.name);
+
+  ui_out_text (uiout, "), ");
 
   return PRINT_SRC_AND_LOC;
 }
@@ -6760,12 +6796,26 @@ breakpoint_hit_catch_exec (const struct bp_location *bl,
 static enum print_stop_action
 print_it_catch_exec (bpstat bs)
 {
+  struct ui_out *uiout = current_uiout;
   struct breakpoint *b = bs->breakpoint_at;
   struct exec_catchpoint *c = (struct exec_catchpoint *) b;
 
   annotate_catchpoint (b->number);
-  printf_filtered (_("\nCatchpoint %d (exec'd %s), "), b->number,
-		   c->exec_pathname);
+  if (b->disposition == disp_del)
+    ui_out_text (uiout, "\nTemporary catchpoint ");
+  else
+    ui_out_text (uiout, "\nCatchpoint ");
+  if (ui_out_is_mi_like_p (uiout))
+    {
+      ui_out_field_string (uiout, "reason",
+			   async_reason_lookup (EXEC_ASYNC_EXEC));
+      ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition));
+    }
+  ui_out_field_int (uiout, "bkptno", b->number);
+  ui_out_text (uiout, " (exec'd ");
+  ui_out_field_string (uiout, "new-exec", c->exec_pathname);
+  ui_out_text (uiout, "), ");
+
   return PRINT_SRC_AND_LOC;
 }
 
@@ -11133,6 +11183,7 @@ internal_bkpt_check_status (bpstat bs)
 static enum print_stop_action
 internal_bkpt_print_it (bpstat bs)
 {
+  struct ui_out *uiout = current_uiout;
   struct breakpoint *b;
 
   b = bs->breakpoint_at;
@@ -11144,6 +11195,9 @@ internal_bkpt_print_it (bpstat bs)
 	 variable?  (If so, we report this as a generic, "Stopped due
 	 to shlib event" message.) */
       printf_filtered (_("Stopped due to shared library event\n"));
+      if (ui_out_is_mi_like_p (uiout))
+	ui_out_field_string (uiout, "reason",
+			     async_reason_lookup (EXEC_ASYNC_SOLIB_EVENT));
       break;
 
     case bp_thread_event:
diff --git a/gdb/doc/gdb.texinfo b/gdb/doc/gdb.texinfo
index f4f7f1e..c13cd62 100644
--- a/gdb/doc/gdb.texinfo
+++ b/gdb/doc/gdb.texinfo
@@ -26130,6 +26130,25 @@ The inferior exited.
 The inferior exited normally.
 @item signal-received 
 A signal was received by the inferior.
+@item solib-event
+The inferior has stopped due to a library being loaded or unloaded.
+This can only happen when @code{stop-on-solib-events} (@pxref{Files})
+is set.
+@item fork
+The inferior has forked.  This is reported when @code{catch fork}
+(@pxref{Set Catchpoints}) has been used.
+@item vfork
+The inferior has vforked.  This is reported in when @code{catch vfork}
+(@pxref{Set Catchpoints}) has been used.
+@item syscall-entry
+The inferior entered a system call.  This is reported when @code{catch
+syscall} (@pxref{Set Catchpoints}) has been used.
+@item syscall-entry
+The inferior returned from a system call.  This is reported when
+@code{catch syscall} (@pxref{Set Catchpoints}) has been used.
+@item exec
+The inferior called @code{exec}.  This is reported when @code{catch exec}
+(@pxref{Set Catchpoints}) has been used.
 @end table
 
 The @var{id} field identifies the thread that directly caused the stop
diff --git a/gdb/mi/mi-common.c b/gdb/mi/mi-common.c
index e7dd3c4..8fb9799 100644
--- a/gdb/mi/mi-common.c
+++ b/gdb/mi/mi-common.c
@@ -35,6 +35,12 @@ static const char * const async_reason_string_lookup[] =
   "exited",
   "exited-normally",
   "signal-received",
+  "solib-event",
+  "fork",
+  "vfork",
+  "syscall-entry",
+  "syscall-return",
+  "exec",
   NULL
 };
 
diff --git a/gdb/mi/mi-common.h b/gdb/mi/mi-common.h
index dc5fc8e..9ecc5a1 100644
--- a/gdb/mi/mi-common.h
+++ b/gdb/mi/mi-common.h
@@ -37,6 +37,12 @@ enum async_reply_reason
   EXEC_ASYNC_EXITED,
   EXEC_ASYNC_EXITED_NORMALLY,
   EXEC_ASYNC_SIGNAL_RECEIVED,
+  EXEC_ASYNC_SOLIB_EVENT,
+  EXEC_ASYNC_FORK,
+  EXEC_ASYNC_VFORK,
+  EXEC_ASYNC_SYSCALL_ENTRY,
+  EXEC_ASYNC_SYSCALL_RETURN,
+  EXEC_ASYNC_EXEC,
   /* This is here only to represent the number of enums.  */
   EXEC_ASYNC_LAST
 };
diff --git a/gdb/testsuite/gdb.mi/mi-solib.exp b/gdb/testsuite/gdb.mi/mi-solib.exp
new file mode 100644
index 0000000..a8ef84c
--- /dev/null
+++ b/gdb/testsuite/gdb.mi/mi-solib.exp
@@ -0,0 +1,55 @@
+# Copyright 2011 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/>.
+
+load_lib mi-support.exp
+set MIFLAGS "-i=mi2"
+
+gdb_exit
+if [mi_gdb_start] {
+    continue
+}
+
+set libname "solib-lib"
+set srcfile_lib ${srcdir}/${subdir}/${libname}.c
+set binfile_lib ${objdir}/${subdir}/${libname}.so
+set lib_flags [list debug ldflags=-Wl,-Bsymbolic]
+
+set testfile "solib-main"
+set srcfile ${srcdir}/${subdir}/${testfile}.c
+set binfile ${objdir}/${subdir}/${testfile}
+set bin_flags [list debug shlib=${binfile_lib}]
+
+if [get_compiler_info ${binfile}] {
+    return -1
+}
+
+if { [gdb_compile_shlib ${srcfile_lib} ${binfile_lib} $lib_flags] != ""
+     || [gdb_compile ${srcfile} ${binfile} executable $bin_flags] != "" } {
+  untested "Could not compile $binfile_lib or $binfile."
+  return -1
+}
+
+mi_delete_breakpoints
+mi_gdb_reinitialize_dir $srcdir/$subdir
+mi_gdb_reinitialize_dir $srcdir/$subdir
+mi_gdb_load ${binfile}
+
+mi_gdb_test "777-gdb-set stop-on-solib-events 1" "777\\^done" \
+    "set stop-on-solib-events"
+
+# We use "run" rather than "-exec-run" here in order to test that CLI
+# commands still cause the correct MI output to be generated.
+mi_run_with_cli
+mi_expect_stop solib-event .* .* .* .* .* "check for solib event"
diff --git a/gdb/testsuite/gdb.mi/solib-lib.c b/gdb/testsuite/gdb.mi/solib-lib.c
new file mode 100644
index 0000000..00a1595
--- /dev/null
+++ b/gdb/testsuite/gdb.mi/solib-lib.c
@@ -0,0 +1,20 @@
+/* Copyright 2011 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/>.
+*/
+#include <stdio.h>
+
+void solibfunction(void)
+{
+}
diff --git a/gdb/testsuite/gdb.mi/solib-main.c b/gdb/testsuite/gdb.mi/solib-main.c
new file mode 100644
index 0000000..df58efc
--- /dev/null
+++ b/gdb/testsuite/gdb.mi/solib-main.c
@@ -0,0 +1,24 @@
+/* Copyright 2011 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/>.
+*/
+#include <stdio.h>
+
+extern void solibfunction(void);
+
+int main ()
+{
+  solibfunction ();
+  return 0;
+}
diff --git a/gdb/testsuite/lib/mi-support.exp b/gdb/testsuite/lib/mi-support.exp
index 63097cb..e07562d 100644
--- a/gdb/testsuite/lib/mi-support.exp
+++ b/gdb/testsuite/lib/mi-support.exp
@@ -788,7 +788,7 @@ proc mi_gdb_test { args } {
 # In patterns, the newline sequence ``\r\n'' is matched explicitly as
 # ``.*$'' could swallow up output that we attempt to match elsewhere.
 
-proc mi_run_cmd {args} {
+proc mi_run_cmd_full {use_mi_command args} {
     global suppress_flag
     if { $suppress_flag } {
 	return -1
@@ -797,6 +797,14 @@ proc mi_run_cmd {args} {
     global thread_selected_re
     global library_loaded_re
 
+    if {$use_mi_command} {
+	set run_prefix "220-exec-"
+	set run_match "220"
+    } else {
+	set run_prefix ""
+	set run_match ""
+    }
+
     if [target_info exists gdb_init_command] {
 	send_gdb "[target_info gdb_init_command]\n";
 	gdb_expect 30 {
@@ -814,9 +822,9 @@ proc mi_run_cmd {args} {
 
     if [target_info exists use_gdb_stub] {
 	if [target_info exists gdb,do_reload_on_run] {
-	    send_gdb "220-exec-continue\n";
+	    send_gdb "${run_prefix}continue\n";
 	    gdb_expect 60 {
-		-re "220\\^running\[\r\n\]+\\*running,thread-id=\"\[^\"\]+\"\r\n$mi_gdb_prompt" {}
+		-re "${run_match}\\^running\[\r\n\]+\\*running,thread-id=\"\[^\"\]+\"\r\n$mi_gdb_prompt" {}
 		default {}
 	    }
 	    return 0;
@@ -835,9 +843,9 @@ proc mi_run_cmd {args} {
 	return 0
     }
 
-    send_gdb "220-exec-run $args\n"
+    send_gdb "${run_prefix}run $args\n"
     gdb_expect {
-	-re "220\\^running\r\n(\\*running,thread-id=\"\[^\"\]+\"\r\n|=thread-created,id=\"1\",group-id=\"\[0-9\]+\"\r\n)*(${library_loaded_re})*(${thread_selected_re})?${mi_gdb_prompt}" {
+	-re "${run_match}\\^running\r\n(\\*running,thread-id=\"\[^\"\]+\"\r\n|=thread-created,id=\"1\",group-id=\"\[0-9\]+\"\r\n)*(${library_loaded_re})*(${thread_selected_re})?${mi_gdb_prompt}" {
 	}
 	-re "\\^error,msg=\"The target does not support running in non-stop mode.\"" {
 	    unsupported "Non-stop mode not supported"
@@ -853,6 +861,14 @@ proc mi_run_cmd {args} {
     return 0
 }
 
+proc mi_run_cmd {args} {
+    return [eval mi_run_cmd_full 1 $args]
+}
+
+proc mi_run_with_cli {args} {
+    return [eval mi_run_cmd_full 0 $args]
+}
+
 #
 # Just like run-to-main but works with the MI interface
 #
-- 
1.7.6.4


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