From patchwork Fri Feb 6 02:59:33 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luis Machado X-Patchwork-Id: 4936 Received: (qmail 10891 invoked by alias); 6 Feb 2015 02:59:41 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Delivered-To: mailing list gdb-patches@sourceware.org Received: (qmail 10871 invoked by uid 89); 6 Feb 2015 02:59:40 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.4 required=5.0 tests=AWL, BAYES_00, RCVD_IN_DNSWL_LOW, SPF_PASS autolearn=ham version=3.3.2 X-HELO: relay1.mentorg.com Received: from relay1.mentorg.com (HELO relay1.mentorg.com) (192.94.38.131) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Fri, 06 Feb 2015 02:59:39 +0000 Received: from svr-orw-fem-06.mgc.mentorg.com ([147.34.97.120]) by relay1.mentorg.com with esmtp id 1YJZ8p-00056B-U9 from Luis_Gustavo@mentor.com ; Thu, 05 Feb 2015 18:59:35 -0800 Received: from [172.30.11.130] (147.34.91.1) by SVR-ORW-FEM-06.mgc.mentorg.com (147.34.97.120) with Microsoft SMTP Server id 14.3.224.2; Thu, 5 Feb 2015 18:59:35 -0800 Message-ID: <54D42E15.5020108@codesourcery.com> Date: Fri, 6 Feb 2015 00:59:33 -0200 From: Luis Machado Reply-To: User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.4.0 MIME-Version: 1.0 To: "'gdb-patches@sourceware.org'" , Antoine Tremblay Subject: [PATCH] Check for valid inferior before sending tracepoint packets X-IsSubscribed: yes 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 * 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);