diff mbox

[RFC,03/15] Fix crash in enable/disable after detach

Message ID 1b888df5d304f17e169cc2b0ea214cc4115ba4ab.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 enable/disable on a fast tracepoint
after detaching the process, gdbserver tries to
access inferior memory which results in a crash.

gdb/gdbserver/ChangeLog:

	* tracepoint.c (cmd_qtenable_disable): Fix problem with
	enabling tracepoint after inferior have disconnected.

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

Comments

Pedro Alves Oct. 15, 2015, 4:30 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 enable/disable on a fast tracepoint
> after detaching the process, gdbserver tries to
> access inferior memory which results in a crash.
> 
> gdb/gdbserver/ChangeLog:
> 
> 	* tracepoint.c (cmd_qtenable_disable): Fix problem with
> 	enabling tracepoint after inferior have disconnected.

Can you write/show a test case?

Thanks,
Pedro Alves
henrik.wallin@windriver.com Oct. 29, 2015, 5:49 p.m. UTC | #2
2015-10-15 18:30 GMT+02:00 Pedro Alves <palves@redhat.com>:
> On 10/14/2015 12:14 PM, henrik.wallin@windriver.com wrote:
>> From: Par Olsson <par.olsson@windriver.com>
>>
>> When calling enable/disable on a fast tracepoint
>> after detaching the process, gdbserver tries to
>> access inferior memory which results in a crash.
>>
>> gdb/gdbserver/ChangeLog:
>>
>>       * tracepoint.c (cmd_qtenable_disable): Fix problem with
>>       enabling tracepoint after inferior have disconnected.
>
> Can you write/show a test case?

Yes, I will loook into adding that. Same for the other ones :)

thanks,
/ Henrik

>
> Thanks,
> Pedro Alves
>
diff mbox

Patch

diff --git a/gdb/gdbserver/tracepoint.c b/gdb/gdbserver/tracepoint.c
index a2723e39e500..78a5eb028b72 100644
--- a/gdb/gdbserver/tracepoint.c
+++ b/gdb/gdbserver/tracepoint.c
@@ -2775,14 +2775,20 @@  cmd_qtenable_disable (char *own_buf, int enable)
 		   enable ? "Enabling" : "Disabling",
 		   (int) num, paddress (addr));
 
-      tp->enabled = enable;
-
       if (tp->type == fast_tracepoint || tp->type == static_tracepoint)
 	{
 	  int ret;
 	  int offset = offsetof (struct tracepoint, enabled);
 	  CORE_ADDR obj_addr = tp->obj_addr_on_target + offset;
 
+	  if (current_thread == NULL)
+	    {
+	      trace_debug ("Trying to enable/disable the tracepoint "
+			   "without inferior");
+	      strcpy (own_buf, "E.No process attached.");
+	      return;
+	    }
+
 	  ret = prepare_to_access_memory ();
 	  if (ret)
 	    {
@@ -2803,6 +2809,8 @@  cmd_qtenable_disable (char *own_buf, int enable)
 	    }
 	}
 
+      tp->enabled = enable;
+
       write_ok (own_buf);
     }
   else