Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 252283

Summary: [processes] Remote debugged process is not killed on debugger termination
Product: [Tools] CDT Reporter: Ling Wang <ling.5.wang>
Component: cdt-debug-dsf-gdbAssignee: Pawel Piech <pawel.1.piech>
Status: CLOSED FIXED QA Contact:
Severity: normal    
Priority: P3 CC: aleherb+eclipse, cdtdoug, dd.general-inbox, fchouinard, marc.khouzam, pawel.1.piech
Version: 0 DD 1.1Flags: cdtdoug: iplog-
pawel.1.piech: review+
marc.khouzam: review? (Randy.Rohrbach)
marc.khouzam: review? (ted)
fchouinard: review+
aleherb+eclipse: review+
Target Milestone: DD 1.1   
Hardware: PC   
OS: Linux   
Whiteboard:
Attachments:
Description Flags
my fix
none
Suggested fix
none
Final fix cdtdoug: iplog-

Description Ling Wang CLA 2008-10-27 18:27:53 EDT
In a remote DSF-GDB debug session, after terminating the debugger, the debugged process will continue running while it should be terminated.
With local debug, there is no such problem.

There is a related but a bit different bug 234467. That bug is about the debugged process being running whereas this bug is about the debugged process being suspended.

In both cases, I think when debugger is terminated, the debugged process should be killed (as is done in CDT). Only when the debugger is "disconnected" should the debuggee be left live and resumed.
Comment 1 Ling Wang CLA 2008-10-27 18:38:38 EDT
Created attachment 116231 [details]
my fix

On termination, the DSF-GDB implementation just exit gdb without explicitly killing the debugged process. That works ok with local debug but not with remote debug.
My proposed fix is to send "kill" command on termination before "exit" command, as is done in CDT.
Comment 2 Marc Khouzam CLA 2008-10-29 11:31:21 EDT
(In reply to comment #1)
> Created an attachment (id=116231) [details]
> my fix
> My proposed fix is to send "kill" command on termination before "exit" command,
> as is done in CDT. 

I don't have a problem with this, but I would like to understand better what is going on.

What version of GDB are you using?  Are you using gdbserver?

When I try this with GDB/gdbserver 6.8, I see the inferior being killed automatically with the -gdb-exit command.  

The problem then is that the gdbserver remains active.
This is a weird situation because we can re-launch DSF-GDB, but the gdbserver will then complain that the program is not running.

I never really bothered with this because I got the feeling this functionality was not very consistent between GDB versions.

But maybe we can discuss this a bit. I'm looking for what we really want to do here.  The options I see are:
1- explicitly tell the gdbserver to exit when the DSF launch terminates (even though the user started it manually.)
2- leave the gdbserver running, since it still accepts connections.  However, when the -exec-continue fails, issue an -exec-run to start the program again.  Sadly, in some cases, this crashes GDB.

Opinions?

Comment 3 Ling Wang CLA 2008-10-29 16:37:20 EDT
(In reply to comment #2)
> What version of GDB are you using?  Are you using gdbserver?

I'm using gdb 6.4.90 for ARM target. Yes, I'm using gdbserver running on remote device.

> 
> When I try this with GDB/gdbserver 6.8, I see the inferior being killed
> automatically with the -gdb-exit command.  
> 
> The problem then is that the gdbserver remains active.
> This is a weird situation because we can re-launch DSF-GDB, but the gdbserver
> will then complain that the program is not running.
> 
> I never really bothered with this because I got the feeling this functionality
> was not very consistent between GDB versions.
> 
> But maybe we can discuss this a bit. I'm looking for what we really want to do
> here.  The options I see are:
> 1- explicitly tell the gdbserver to exit when the DSF launch terminates (even
> though the user started it manually.)
> 2- leave the gdbserver running, since it still accepts connections.  However,
> when the -exec-continue fails, issue an -exec-run to start the program again. 
> Sadly, in some cases, this crashes GDB.
> 
> Opinions?

I definitely prefer the option #1. First, the gdb & gdbserver behavior is not consistent between versions. Second and most important, having one gdbserver instance to server different GDB connections is too risky and error prone. We need to first make sure fresh GDB & GDBserver session works well:)
> 

Comment 4 Marc Khouzam CLA 2008-10-29 22:09:48 EDT
(In reply to comment #3)
> (In reply to comment #2)
> > What version of GDB are you using?  Are you using gdbserver?
> I'm using gdb 6.4.90 for ARM target. Yes, I'm using gdbserver running on remote
> device.

Wow... We are only using GDB 6.6 and later.
However, if it works for you, I guess it doesn't hurt to use an older GDB.

> > 1- explicitly tell the gdbserver to exit when the DSF launch terminates (even
> > though the user started it manually.)
> > 2- leave the gdbserver running, since it still accepts connections.  However,
> > when the -exec-continue fails, issue an -exec-run to start the program again. 
> > Sadly, in some cases, this crashes GDB.
> > 
> > Opinions?
> I definitely prefer the option #1. First, the gdb & gdbserver behavior is not
> consistent between versions. Second and most important, having one gdbserver
> instance to server different GDB connections is too risky and error prone. We
> need to first make sure fresh GDB & GDBserver session works well:)

Can you try this:
instead of sending 'kill' as your patch did, send 'monitor exit' instead.
This is what I would need to do for GDB 6.8.  Let me know if it works for you.

Thanks


Comment 5 Ling Wang CLA 2008-10-30 14:24:10 EDT
(In reply to comment #4)
> Wow... We are only using GDB 6.6 and later.

Ok, I think my "gdb --version" command gave me wrong data. The debian package info says it's 6.6, and my gdbserver is 6.6.

> Can you try this:
> instead of sending 'kill' as your patch did, send 'monitor exit' instead.
> This is what I would need to do for GDB 6.8.  Let me know if it works for you.
> 
> Thanks
> 

Hmm, the "monitor exit" command is not supported by my gdbserver.

990,838 &"monitor exit\n"
990,845 &"Target does not support this command.\n"

BTW, FYI, in my env, without the "kill" command, the "exit" command will kill both gdb and gdbserver but leaving the inferior running. I'm surprised to see that in your case it kills gdb and inferior but leaves gdbserver running.
Comment 6 Ling Wang CLA 2008-11-06 12:04:08 EST
Hi, Marc, is it ok to commit my fix ? Thanks.
Comment 7 Marc Khouzam CLA 2008-11-06 13:42:09 EST
Created attachment 117232 [details]
Suggested fix

Try this patch instead.  The problem you were having was probably caused by the fact that we were using 
-target-select extended-remote
instead of 
-target-select remote

even for a normal GDB server.

The problem with this patch is that it adds two methods to the API.  I'll need to get approval.  But let's first confirm it works for you.
Comment 8 Marc Khouzam CLA 2008-11-06 13:44:47 EST
BTW, I tested this suggested fix with 6.6, 6.7 6.8 and HEAD.  Looks good on my side.
Comment 9 Ling Wang CLA 2008-11-07 16:25:17 EST
(In reply to comment #7)
Marc, I tried it and it does not work for me. From the MI tracing I can see this:

...
574,316 7-target-select remote 192.168.2.15:1234
...
594,225 42monitor exit
594,227 &"monitor exit\n"
594,233 &"Target does not support this command.\n"
594,233 42^error,msg="Target does not support this command."
594,233 (gdb) 
594,237 43-gdb-exit
594,244 43^exit



Comment 10 Marc Khouzam CLA 2008-11-07 21:32:14 EST
(In reply to comment #9)
> (In reply to comment #7)
> Marc, I tried it and it does not work for me. From the MI tracing I can see
> this:
> ...
> 574,316 7-target-select remote 192.168.2.15:1234
> ...
> 594,225 42monitor exit
> 594,227 &"monitor exit\n"
> 594,233 &"Target does not support this command.\n"

This new patch does not use "monitor exit".  
You probably have the old patch still applied.
The only thing this new patch does is use remote instead of extended-remote.

Let me know.
Comment 11 Ling Wang CLA 2008-11-10 16:46:38 EST
(In reply to comment #10)
Sorry I misunderstood you. 
Yes, the new patch works for me ! Thanks.

Comment 12 Marc Khouzam CLA 2008-11-10 22:43:36 EST
I would like to commit this small fix.  However, it adds two methods to the MI command file MITargetSelect.java while deprecating the two original ones (the deprecation is not necessary, but I felt it was more appropriate to prepare for a cleanup for 2.0).

This is a change in the API after the API freeze so I need a vote.
Please let me know if you approve.  I've added all committers in the review list.

Thanks
Comment 13 Anton Leherbauer CLA 2008-11-11 03:03:24 EST
+1 
That's fine with me.
Comment 14 Pawel Piech CLA 2008-11-11 12:08:43 EST
Looks good to me.
Comment 15 Ling Wang CLA 2008-11-11 14:02:07 EST
Oh, Marc, I think there's an error (a typo) in your patch for the case of serial connection:

public MITargetSelect(IDMContext ctx, String serialDevice, boolean extended) {
  super(ctx, "-target-select extended-remote", ...
}

where the super() should be
  super(ctx, "-target-select", ...
Comment 16 Marc Khouzam CLA 2008-11-11 14:07:07 EST
(In reply to comment #15)
> where the super() should be
>   super(ctx, "-target-select", ...

Woops!
Thanks for catching this. 

Comment 17 Pawel Piech CLA 2008-11-12 16:47:13 EST
Hi Marc,
According to our ramp down policy you have plenty of approval to commit this change.  Please go ahead.
Comment 18 Marc Khouzam CLA 2008-11-13 09:40:50 EST
Created attachment 117776 [details]
Final fix

Committed this fix.
Comment 19 Marc Khouzam CLA 2008-11-13 09:42:32 EST
Fixed.
Pawel, can you verify?
Comment 20 Pawel Piech CLA 2008-11-13 12:17:27 EST
I reviewed the changes, although I don't think they made it into RC1.  Also I removed the NON-NLS comment from the strings that need to be externalized.  See bug 252068.
Comment 21 Pawel Piech CLA 2008-11-13 12:17:51 EST
Marking verified.
Comment 22 Marc Khouzam CLA 2008-11-13 13:13:41 EST
(In reply to comment #20)
> I reviewed the changes, although I don't think they made it into RC1.  

How come the RC1 build was a day early?

> Also I
> removed the NON-NLS comment from the strings that need to be externalized.  See
> bug 252068.

I saw that bug, but I didn't understand what it really meant...  I guess we can talk about it in a future meeting.

Comment 23 Pawel Piech CLA 2008-11-13 15:01:01 EST
(In reply to comment #22)
> (In reply to comment #20)
> > I reviewed the changes, although I don't think they made it into RC1.  
> 
> How come the RC1 build was a day early?
I'm sorry I should have communicated this.  I asked Ted to kick off the build last night so we could test it today.  But he didn't email the list as usual so you guys didn't know about it.  In the next couple of weeks I'll be more clear about when we perform the candidate build.

> I saw that bug, but I didn't understand what it really meant...  I guess we can
> talk about it in a future meeting.

Except for internal error messages we have an obligation to externalize all user-facing strings.
Comment 24 Marc Khouzam CLA 2008-11-13 16:07:17 EST
(In reply to comment #23)
> > How come the RC1 build was a day early?
> I'm sorry I should have communicated this.  I asked Ted to kick off the build
> last night so we could test it today.  But he didn't email the list as usual so
> you guys didn't know about it.  In the next couple of weeks I'll be more clear
> about when we perform the candidate build.

No problem.
Comment 25 Pawel Piech CLA 2009-01-07 16:01:12 EST
DD 1.1 reelased!