Bug 414959 - Attach to process fails in all-stop mode
Summary: Attach to process fails in all-stop mode
Status: RESOLVED FIXED
Alias: None
Product: CDT
Classification: Tools
Component: cdt-debug-dsf-gdb (show other bugs)
Version: Next   Edit
Hardware: PC Linux
: P3 normal (vote)
Target Milestone: 8.3.0   Edit
Assignee: Marc Dumais CLA
QA Contact: Marc Khouzam CLA
URL:
Whiteboard:
Keywords:
Depends on: 412471
Blocks:
  Show dependency tree
 
Reported: 2013-08-13 08:14 EDT by Lidia Gutu CLA
Modified: 2014-08-27 12:07 EDT (History)
6 users (show)

See Also:


Attachments
This is the desired result, that is not working. The process should be attached, like in the image. Instead of that the gdb is empty (181.36 KB, image/png)
2013-08-13 08:14 EDT, Lidia Gutu CLA
no flags Details
Select a Process dialog (48.81 KB, image/png)
2013-08-13 08:15 EDT, Lidia Gutu CLA
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Lidia Gutu CLA 2013-08-13 08:14:59 EDT
Created attachment 234348 [details]
This is the desired result, that is not working. The process should be attached, like in the image. Instead of that the gdb is empty

The attach to process functionality is not working on master branch, with both gdb or gdbserver selected. 

I have tested on ubuntu 12.04 with different eclipse versions:

1) Eclipse-SDK-3.8.2 for linux-gtk 32-bit:
http://download.eclipse.org/eclipse/downloads/drops/R-3.8.2-201301310800/
and then Help -> Install New Software -> org.eclipse.cdt.repo.zip from Hudson Job https://hudson.eclipse.org/hudson/job/cdt-nightly/

2) “Eclipse for Automotive” Kepler package. Linux 32-bit
http://eclipse.org/downloads/packages/eclipse-ide-automotive-software-developers-includes-incubating-components/keplerr
and then imported master branch from git://git.eclipse.org/gitroot/cdt/org.eclipse.cdt.git

3) a custom eclipse from Windriver: worbench 3.3 and imported the cdt sources from the same git repository (git://git.eclipse.org/gitroot/cdt/org.eclipse.cdt.git)

I have tested this functionality on few branches from the above repository, on cdt_8_1 and cdt_8_2 it worked, but on master branch it doesn't worked.
I am also sure that this is a recent issue, because it have been working before, as I used it to add new functionalities, and then, when I wanted to push my changes to git respository, after a git pull, it didn't worked any more.

Steps to reproduce are:
Start a gdb server from terminal: sudo gdbserver --multi :2345
start my process ./MyProcess (optional) or use ubuntu processes

1. click on Debug pop-up icon.
2. click on "Debug Configurations"  
3. Double click to "C/C++ Attach to application" (the new configuration page is created). 
4. On right side  select "Debugger tab" 
5. select gdbserver from spinner
6. on "Connection" tab type port number (2345)
7. Apply and Debug.
8. Click on green icon "Connect to a process".  The "Select Processes" dialog opens with all running processes listed (image "Screenshot 1" ).
9. Select my process, double click on it or press OK Button.
10. A "Choose binary for process" dialog opens , browse and select my binary. 
11. On OK button pressed nothing happens. It should attach and display the process to my "C/C++ Attach to Application" as on the attached image "Screenshort 2".
Comment 1 Lidia Gutu CLA 2013-08-13 08:15:54 EDT
Created attachment 234349 [details]
Select a Process dialog
Comment 2 Marc Dumais CLA 2013-08-13 10:31:53 EDT
Hi Lidia,

We were able to reproduce the issue.

In the GDB traces, I noticed this error:

989,016 19-target-attach --thread-group i1 24375 ''
989,017 (gdb) 
989,018 19^error,msg="Illegal process-id: 24375 ''."
989,021 (gdb) 

It seems that the two single quotes at the end of the command are interpreted as an invalid pid by GDB.

After investigation, it seems that the change for Bug 412471 is why the two quotes are now appearing at the end of the attach command (only in 'all-stop' mode). According to the bug description, it seems that the intent was to be able to pass empty strings parameters as program arguments. But since the change was made in the base class MICommand, it also impacts other commands.

The attach command happens to be impacted by this. For this command, an empty string is passed as argument, in the all-stop mode (see MITargetAttach, the constructor with 3 arguments). In the non-stop mode, an ampersand is instead passed. Before the change for Bug 412471, the empty string argument was ignored while building the command string in MICommand. Now it's instead translated to two single quotes (''), which GDB doesn't like.   

We could fix that easily enough. However there might be other commands that also pass an empty string, expecting it to be ignored, and it might not be easy to find all those cases. Another approach that might be less risky would be to revert the fix for Bug 412471 and instead re-implement it more narrowly, so that it doesn't impact all MI commands.

Any opinions on this? 

Good catch finding this, BTW!
Comment 3 Marc Dumais CLA 2013-08-13 10:42:59 EDT
Hi again,

This is what a simple, narrow, fix for this could look like:

https://git.eclipse.org/r/#/c/15425/

It avoids the issue by passing a concatenation of the two passed parameters, avoiding an empty string param from reaching MICommand.  

However a more thought-out solution might be better.
Comment 4 Marc Khouzam CLA 2013-08-13 11:33:26 EDT
(In reply to comment #3)
> Hi again,
> 
> This is what a simple, narrow, fix for this could look like:
> 
> https://git.eclipse.org/r/#/c/15425/
> 
> It avoids the issue by passing a concatenation of the two passed parameters,
> avoiding an empty string param from reaching MICommand.  

+1 for this fix.
Let's address the general risk of the fix of Bug 412471 separately.
Comment 5 Marc Khouzam CLA 2013-08-13 13:01:04 EDT
I committed Marc D's fix.

Thanks Lidia for reporting the problem.
Comment 6 Martin Oberhuber CLA 2013-08-16 05:40:14 EDT
Thanks for the fix !

Linking to bug 412471 since that one caused the regression. No backport is needed since the regression was introduced post 8.2 .