diff mbox

[RFC,05/15] Fix crash when tstart after detach.

Message ID 49392b36dcf57bbe3f941d9dd684e91c734a99f6.1444820235.git.henrik.wallin@windriver.com
State New
Headers show

Commit Message

henrik.wallin@windriver.com Oct. 14, 2015, 11:14 a.m. UTC
From: Par Olsson <par.olsson@windriver.com>

When calling tstart after detaching the process,
gdbserver tries to access inferior memory which
results in a crash.
Also add error message when calling tstart if
there is no inferior.

gdb/gdbserver/ChangeLog:

	* tracepoint.c (cmd_qtinit): Add check that inferior is
	present before calling clear_inferior_trace_buffer.
	(cmd_qtstart): Add check that inferior is present.

Signed-off-by: Par Olsson <par.olsson@windriver.com>
Signed-off-by: Henrik Wallin <henrik.wallin@windriver.com>
---
 gdb/gdbserver/tracepoint.c | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)

Comments

Pedro Alves Oct. 15, 2015, 5:24 p.m. UTC | #1
On 10/14/2015 12:14 PM, henrik.wallin@windriver.com wrote:
> From: Par Olsson <par.olsson@windriver.com>
> 
> When calling tstart after detaching the process,
> gdbserver tries to access inferior memory which
> results in a crash.
> Also add error message when calling tstart if
> there is no inferior.
> 

You know what I'll ask for by now.  :-)

Thanks,
Pedro Alves
diff mbox

Patch

diff --git a/gdb/gdbserver/tracepoint.c b/gdb/gdbserver/tracepoint.c
index 78a5eb028b72..d2ad197e58ab 100644
--- a/gdb/gdbserver/tracepoint.c
+++ b/gdb/gdbserver/tracepoint.c
@@ -2402,7 +2402,8 @@  cmd_qtinit (char *packet)
     }
 
   clear_trace_buffer ();
-  clear_inferior_trace_buffer ();
+  if (agent_loaded_p ())
+    clear_inferior_trace_buffer ();
 
   write_ok (packet);
 }
@@ -3203,6 +3204,13 @@  cmd_qtstart (char *packet)
   struct tracepoint *tpoint, *prev_ftpoint, *prev_stpoint;
   CORE_ADDR tpptr = 0, prev_tpptr = 0;
 
+  if (current_thread == NULL)
+    {
+      trace_debug ("Trying to start the trace without inferior");
+      strcpy (packet, "E.No process attached.");
+      return;
+    }
+
   trace_debug ("Starting the trace");
 
   /* Pause all threads temporarily while we patch tracepoints.  */