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]

[PATCH] Check for valid inferior before sending tracepoint packets


This almost trivial patch prevents GDB from sending a few tracepoint packets when no inferior is selected. This robustifies things a bit and complements the fix Antoine submitted for gdbserver.

I'm not quite sure how a testcase for this would look like given it needs extended-remote mode and also needs to connect to the target without a running inferior.

Luis
2015-02-06  Luis Machado  <lgustavo@codesourcery.com>

	* tracefile.c: Include inferior.h.
	(trace_save_command): Error out if no inferior is selected.
	* tracepoint.c (trace_start_command): Likewise.
	(trace_stop_command): Likewise.
	(trace_status_command): Likewise.
	(trace_status_mi): Return if no inferior is selected.
	(trace_find_command): Error out if no inferior is selected.
	(trace_dump_command): Likewise.

diff --git a/gdb/tracefile.c b/gdb/tracefile.c
index a31a589..80680a0 100644
--- a/gdb/tracefile.c
+++ b/gdb/tracefile.c
@@ -22,6 +22,7 @@
 #include "ctf.h"
 #include "exec.h"
 #include "regcache.h"
+#include "inferior.h"
 
 /* Helper macros.  */
 
@@ -312,6 +313,9 @@ trace_save_command (char *args, int from_tty)
   int generate_ctf = 0;
   struct trace_file_writer *writer = NULL;
 
+  if (ptid_equal (inferior_ptid, null_ptid))
+    error (_("No active process to save trace data from."));
+
   if (args == NULL)
     error_no_arg (_("file in which to save trace data"));
 
diff --git a/gdb/tracepoint.c b/gdb/tracepoint.c
index 0774f5e..a90ad4b 100644
--- a/gdb/tracepoint.c
+++ b/gdb/tracepoint.c
@@ -1908,6 +1908,9 @@ trace_start_command (char *args, int from_tty)
 {
   dont_repeat ();	/* Like "run", dangerous to repeat accidentally.  */
 
+  if (ptid_equal (inferior_ptid, null_ptid))
+    error (_("No active process to start trace for."));
+
   if (current_trace_status ()->running)
     {
       if (from_tty
@@ -1926,6 +1929,9 @@ trace_start_command (char *args, int from_tty)
 static void
 trace_stop_command (char *args, int from_tty)
 {
+  if (ptid_equal (inferior_ptid, null_ptid))
+    error (_("No active process to stop trace for."));
+
   if (!current_trace_status ()->running)
     error (_("Trace is not running."));
 
@@ -1988,6 +1994,9 @@ trace_status_command (char *args, int from_tty)
   VEC(breakpoint_p) *tp_vec = NULL;
   struct breakpoint *t;
   
+  if (ptid_equal (inferior_ptid, null_ptid))
+    error (_("No active process to fetch trace status from."));
+
   status = target_get_trace_status (ts);
 
   if (status == -1)
@@ -2150,6 +2159,9 @@ trace_status_mi (int on_stop)
   struct trace_status *ts = current_trace_status ();
   int status;
 
+  if (ptid_equal (inferior_ptid, null_ptid))
+    return;
+
   status = target_get_trace_status (ts);
 
   if (status == -1 && ts->filename == NULL)
@@ -2472,6 +2484,9 @@ trace_find_command (char *args, int from_tty)
 { /* This should only be called with a numeric argument.  */
   int frameno = -1;
 
+  if (ptid_equal (inferior_ptid, null_ptid))
+    error (_("No active process to select trace frames from."));
+
   check_trace_running (current_trace_status ());
   
   if (args == 0 || *args == 0)
@@ -3051,6 +3066,9 @@ trace_dump_command (char *args, int from_tty)
   struct cleanup *old_chain;
   struct command_line *actions;
 
+  if (ptid_equal (inferior_ptid, null_ptid))
+    error (_("No active process to dump trace data for."));
+
   /* This throws an error is not inspecting a trace frame.  */
   loc = get_traceframe_location (&stepping_frame);
 

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