[RFA,5/5] Darwin: fix SIGTRAP when debugging

Message ID 1534932677-9496-6-git-send-email-roirand@adacore.com
State New, archived
Headers

Commit Message

Xavier Roirand Aug. 22, 2018, 10:11 a.m. UTC
  Debugging a program under Darwin does not work:

(gdb) start
Temporary breakpoint 1 at 0x100000fb4: file /tmp/helloworld.c, line 1.
Starting program: /private/tmp/helloworld
[New Thread 0x2903 of process 60326]
During startup program terminated with signal SIGTRAP, Trace/breakpoint trap.

Field signaled from darwin_thread_info is not initialized thus signal sent to
the debuggee is considered as not sent by GDB whereas it should.

This patch fixes this problem.

gdb/ChangeLog:

    * darwin-nat.c (darwin_check_new_threads): Initialize signaled
    field.

Change-Id: I02052473f1f8d28106cc343f440fa784b110bbf5
---
 gdb/darwin-nat.c | 1 +
 1 file changed, 1 insertion(+)
  

Comments

Simon Marchi Aug. 22, 2018, 2:34 p.m. UTC | #1
On 2018-08-22 06:11, Xavier Roirand wrote:
> Debugging a program under Darwin does not work:
> 
> (gdb) start
> Temporary breakpoint 1 at 0x100000fb4: file /tmp/helloworld.c, line 1.
> Starting program: /private/tmp/helloworld
> [New Thread 0x2903 of process 60326]
> During startup program terminated with signal SIGTRAP, Trace/breakpoint 
> trap.
> 
> Field signaled from darwin_thread_info is not initialized thus signal 
> sent to
> the debuggee is considered as not sent by GDB whereas it should.
> 
> This patch fixes this problem.
> 
> gdb/ChangeLog:
> 
>     * darwin-nat.c (darwin_check_new_threads): Initialize signaled
>     field.
> 
> Change-Id: I02052473f1f8d28106cc343f440fa784b110bbf5
> ---
>  gdb/darwin-nat.c | 1 +
>  1 file changed, 1 insertion(+)
> 
> diff --git a/gdb/darwin-nat.c b/gdb/darwin-nat.c
> index 9ad4a87..bbd2700 100644
> --- a/gdb/darwin-nat.c
> +++ b/gdb/darwin-nat.c
> @@ -341,6 +341,7 @@ darwin_check_new_threads (struct inferior *inf)
>  	  /* A thread was created.  */
>  	  darwin_thread_info *pti = new darwin_thread_info;
> 
> +	  pti->signaled = 0;
>  	  pti->gdb_port = new_id;
>  	  pti->msg_state = DARWIN_RUNNING;

Oh, good catch.  Though instead, can we initialize the fields directly 
in the class declaration, so if we ever create darwin_thread_info at 
some other place, the object will be correctly initialized?  In C++11, 
you can initialize the fields directly like this:

   unsigned char signaled = 0;

I think we might as well initialize all the fields to a sensible value, 
and you could also change the "char" fields to "bool" at the same time.

Thanks,

Simon
  

Patch

diff --git a/gdb/darwin-nat.c b/gdb/darwin-nat.c
index 9ad4a87..bbd2700 100644
--- a/gdb/darwin-nat.c
+++ b/gdb/darwin-nat.c
@@ -341,6 +341,7 @@  darwin_check_new_threads (struct inferior *inf)
 	  /* A thread was created.  */
 	  darwin_thread_info *pti = new darwin_thread_info;
 
+	  pti->signaled = 0;
 	  pti->gdb_port = new_id;
 	  pti->msg_state = DARWIN_RUNNING;