Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Luis Machado <lgustavo@codesourcery.com>
To: "'gdb-patches@sourceware.org'" <gdb-patches@sourceware.org>,
	Antoine Tremblay <antoine.tremblay@ericsson.com>
Subject: [PATCH] Check for valid inferior before sending tracepoint packets
Date: Fri, 06 Feb 2015 02:59:00 -0000	[thread overview]
Message-ID: <54D42E15.5020108@codesourcery.com> (raw)

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

             reply	other threads:[~2015-02-06  2:59 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-02-06  2:59 Luis Machado [this message]
2015-02-06  7:57 ` Doug Evans
2015-02-06  8:02   ` Doug Evans

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=54D42E15.5020108@codesourcery.com \
    --to=lgustavo@codesourcery.com \
    --cc=antoine.tremblay@ericsson.com \
    --cc=gdb-patches@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox