Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
* [PATCH] Check for valid inferior before sending tracepoint packets
@ 2015-02-06  2:59 Luis Machado
  2015-02-06  7:57 ` Doug Evans
  0 siblings, 1 reply; 3+ messages in thread
From: Luis Machado @ 2015-02-06  2:59 UTC (permalink / raw)
  To: 'gdb-patches@sourceware.org', Antoine Tremblay

[-- Attachment #1: Type: text/plain, Size: 368 bytes --]

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

[-- Attachment #2: trace_cmds.diff --]
[-- Type: text/x-patch, Size: 3062 bytes --]

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);
 

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] Check for valid inferior before sending tracepoint packets
  2015-02-06  2:59 [PATCH] Check for valid inferior before sending tracepoint packets Luis Machado
@ 2015-02-06  7:57 ` Doug Evans
  2015-02-06  8:02   ` Doug Evans
  0 siblings, 1 reply; 3+ messages in thread
From: Doug Evans @ 2015-02-06  7:57 UTC (permalink / raw)
  To: lgustavo; +Cc: 'gdb-patches@sourceware.org', Antoine Tremblay

Luis Machado <lgustavo@codesourcery.com> writes:
> 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.

Hi.
The gdb.server/ext-run.exp testcase looks like it would be a
good starting point for such a testcase.


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] Check for valid inferior before sending tracepoint packets
  2015-02-06  7:57 ` Doug Evans
@ 2015-02-06  8:02   ` Doug Evans
  0 siblings, 0 replies; 3+ messages in thread
From: Doug Evans @ 2015-02-06  8:02 UTC (permalink / raw)
  To: lgustavo; +Cc: gdb-patches, Antoine Tremblay

On Thu, Feb 5, 2015 at 11:56 PM, Doug Evans <xdje42@gmail.com> wrote:
> Luis Machado <lgustavo@codesourcery.com> writes:
>> 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.
>
> Hi.
> The gdb.server/ext-run.exp testcase looks like it would be a
> good starting point for such a testcase.

Or this, if this is indeed non-gdbserver-specific.

https://sourceware.org/ml/gdb-patches/2015-02/msg00138.html


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2015-02-06  8:02 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-02-06  2:59 [PATCH] Check for valid inferior before sending tracepoint packets Luis Machado
2015-02-06  7:57 ` Doug Evans
2015-02-06  8:02   ` Doug Evans

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox