Bug 196154 - "Run to Line" command fails with native windows paths
Summary: "Run to Line" command fails with native windows paths
Status: RESOLVED FIXED
Alias: None
Product: CDT
Classification: Tools
Component: cdt-debug (show other bugs)
Version: 4.0   Edit
Hardware: PC Windows XP
: P3 normal (vote)
Target Milestone: 7.0.2   Edit
Assignee: John Cortell CLA
QA Contact: Ken Ryall CLA
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2007-07-11 09:44 EDT by Mike Wrighton CLA
Modified: 2010-09-28 11:06 EDT (History)
4 users (show)

See Also:
marc.khouzam: review+


Attachments
Patch for CDT V201006141710 (2.24 KB, patch)
2010-09-24 10:28 EDT, Francisco Gortázar CLA
no flags Details | Diff
reworked fix (2.38 KB, patch)
2010-09-27 12:19 EDT, John Cortell CLA
john.cortell: iplog-
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Mike Wrighton CLA 2007-07-11 09:44:53 EDT
Build ID:  I20070323-1616

Steps To Reproduce:
Issue a 'run to line' command from CDT when using a windows gdb that uses native windows paths e.g. not cygpath.

More information:
Full windows paths contain colons after the drive letter - gdb cannot parse this in an exec-until command at is requires a colon to specify the source line number. Run to line needs to use the same mechanism as breakpoints i.e. relative paths, to avoid this problem.
Comment 1 Francisco Gortázar CLA 2010-09-22 09:23:50 EDT
I found this problem when running Eclipse Helios CDT on Windows with Wascana installed. 

As Mike suggests, it could be fixed by making run to line sets breakpoints the same way as breakpoints mechanism. Is there any other problem that makes this issue remain open?

Regards,
Patxi.
Comment 2 Marc Khouzam CLA 2010-09-22 14:13:38 EDT
As a note, DSF-GDB uses a temporary breakpoint for "run-to-line" instead of 
-exec-until, which may solve your problem.
Comment 3 Francisco Gortázar CLA 2010-09-23 19:11:02 EDT
(In reply to comment #2)
> As a note, DSF-GDB uses a temporary breakpoint for "run-to-line" instead of 
> -exec-until, which may solve your problem.

But I think the problem is the path, which I suppose still needs to be specified when using -exec-until (please, tell me if I'm wrong). 

I've made some investigation on this problem. My C project structure:

HelloC
 +-Debug
   +-HelloC.exe
 +-src
   +-HelloC.c

If I start gdb from src folder, and I try to set a breakpoint using absolute path it fails. I've tried in several ways (like single and double backslashes), and none work. However, if I just specify the name of the source file (HelloC.c), it works perfectly. I'm not an expert and have no idea why absolute paths don't work on Windows (I'm using MinGW).

Having a look at the code, I've seen that the method that sets the temporary breakpoint is RunToLine.runToLine().

If I change the method, so that only the last segment of the path is passed into the IRunControl2.runToLine call, it works perfectly. Obviously, this approach doesn't work if the file is within a folder (which sounds strange, but my days as C develeoper passed by some years ago, so I can be wrong) or there are several source folders. Also, I don't know the impact of this change in other OS:

##code##
public void runToLine(final String fileName, final int lineNumber, final boolean skipBreakpoints) throws DebugException {
  ...
  IPath path = Path.fromPortableString(fileName);
  String lastSegment = path.lastSegment();
  runControl.runToLine(fContext, lastSegment, lineNumber, skipBreakpoints, rm);
  ...
}
##code##

Ideally, I would have made the path relative (Path.makeRelative()) to the src folder. But I don't know if that information could be retrieved from that method in some way.

Another approach would be to modify MIBreakInsert.PathAdjustable, which seems to "normalize" the path for gdb. I think it makes more sense for me.

Any suggestions?
Comment 4 Francisco Gortázar CLA 2010-09-24 10:28:56 EDT
Created attachment 179524 [details]
Patch for CDT V201006141710

This is a patch for tag 201006141710
Comment 5 John Cortell CLA 2010-09-24 10:35:04 EDT
I'll take a look at this patch.
Comment 6 John Cortell CLA 2010-09-27 11:56:07 EDT
This patch fixes the problem at an inappropriate location. The fix should be somewhere in the MI plugin, not the dsf action code. Reducing the path down to a simple filename is an ugly hack, but a seemingly unavoidable one (see bug 232415). The obvious pitfall with the hack is that it drops support for executables with same-named files (e.g., two foo.cpp files in different directories). The hack should be as closely tied to the problem environment as possible. In this case, that environment is GDB, specifically MinGW's. Unfortunately, the MinGW distinction is not one I think we currently are able to make in dsf-gdb, but at least the fix should be pushed down into the MI plugin. I'll relocate the fix.
Comment 7 John Cortell CLA 2010-09-27 12:19:42 EDT
Created attachment 179662 [details]
reworked fix
Comment 8 John Cortell CLA 2010-09-27 12:21:02 EDT
Committed to HEAD. Marc please review. If you think this is safe enough, I'll commit it to the 7.0.x branch, too.
Comment 9 Marc Khouzam CLA 2010-09-27 16:09:24 EDT
(In reply to comment #8)
> Committed to HEAD. Marc please review. If you think this is safe enough, I'll
> commit it to the 7.0.x branch, too.

Nice.  I'll try it on my Windows machine tonight.

Why do we need 
path = path.replace('\\', '/');
which we didn't before?

I think you need the same fix in GDBRunControl_7_0_NS#runToLine.
Comment 10 Marc Khouzam CLA 2010-09-27 16:10:24 EDT
Just a note that this bug is assigned to CDI...  Should we move it to the DSF-GDB component and open a new one for CDI?
Comment 11 John Cortell CLA 2010-09-27 16:23:38 EDT
(In reply to comment #9)
> (In reply to comment #8)
> > Committed to HEAD. Marc please review. If you think this is safe enough, I'll
> > commit it to the 7.0.x branch, too.
> 
> Nice.  I'll try it on my Windows machine tonight.
> 
> Why do we need 
> path = path.replace('\\', '/');
> which we didn't before?

In some cases, the input path has forward slashes. In some, it has backslashes. Depends on the calling feature (e.g., breakpoint vs run-to-line).

> I think you need the same fix in GDBRunControl_7_0_NS#runToLine.

OK. I'll add it there, too.
Comment 12 John Cortell CLA 2010-09-27 16:25:07 EDT
(In reply to comment #10)
> Just a note that this bug is assigned to CDI...  Should we move it to the
> DSF-GDB component and open a new one for CDI?

Yes. We should move it to dsf-gdb. As for CDI...I don't know. I guess we'd have to try reproducing the problem with a CDI session.
Comment 13 Marc Khouzam CLA 2010-09-28 07:27:50 EDT
(In reply to comment #11)
> (In reply to comment #9)
> > (In reply to comment #8)
> > > Committed to HEAD. Marc please review. If you think this is safe enough, I'll
> > > commit it to the 7.0.x branch, too.
> > 
> > Nice.  I'll try it on my Windows machine tonight.

Looks good to me.

Does making MIBreakpointsManager.adjustDebuggerPath visible not require a @since tag?  The API tooling did not ask for one.  I guess because it is static?

+1 for the 7_0 branch, once GDBRunControl_7_0_NS has the same fix.

Thanks
Comment 14 Marc Khouzam CLA 2010-09-28 07:30:10 EDT
(In reply to comment #12)
> (In reply to comment #10)
> > Just a note that this bug is assigned to CDI...  Should we move it to the
> > DSF-GDB component and open a new one for CDI?
> 
> Yes. We should move it to dsf-gdb. As for CDI...I don't know. I guess we'd have
> to try reproducing the problem with a CDI session.

I tried to reproduce it with CDI with GDB 6.8 and 7.0 and I didn't see the problem.  I'm thinking that Francisco, in comment #1, was using DSF-GDB since it is the default for Helios.

So, I figured we can move this bug to cdt-debug and use it to mark both DSF-GDB and CDI fixed for this issue.
Comment 15 John Cortell CLA 2010-09-28 07:32:48 EDT
(In reply to comment #13)
> Does making MIBreakpointsManager.adjustDebuggerPath visible not require a
> @since tag?  The API tooling did not ask for one.  I guess because it is
> static?

My fix changed the method to package (default) visibility, which is still non-public.
Comment 16 John Cortell CLA 2010-09-28 10:36:29 EDT
(In reply to comment #13)
> +1 for the 7_0 branch, once GDBRunControl_7_0_NS has the same fix.

The fix is now in 7.0.x and in GDBRunControl_7_0_NS
Comment 17 Marc Khouzam CLA 2010-09-28 10:47:27 EDT
(In reply to comment #16)
> (In reply to comment #13)
> > +1 for the 7_0 branch, once GDBRunControl_7_0_NS has the same fix.
> 
> The fix is now in 7.0.x and in GDBRunControl_7_0_NS

Should we make MIBreakpointsManager.adjustDebuggerPath public in HEAD (only) to avoid duplication of code in GDBRunControl_7_0_NS ?

I can do it if you agree.
Comment 18 John Cortell CLA 2010-09-28 10:50:34 EDT
(In reply to comment #17)
> (In reply to comment #16)
> > (In reply to comment #13)
> > > +1 for the 7_0 branch, once GDBRunControl_7_0_NS has the same fix.
> > 
> > The fix is now in 7.0.x and in GDBRunControl_7_0_NS
> 
> Should we make MIBreakpointsManager.adjustDebuggerPath public in HEAD (only) to
> avoid duplication of code in GDBRunControl_7_0_NS ?
> 
> I can do it if you agree.

I don't think we should. It's a method that exists only to support a hack. I don't think we should make it API. It's a small enough method that duplicating it is not a big deal, IMO.
Comment 19 Marc Khouzam CLA 2010-09-28 11:00:24 EDT
(In reply to comment #18)
> (In reply to comment #17)
> > (In reply to comment #16)
> > > (In reply to comment #13)
> > > > +1 for the 7_0 branch, once GDBRunControl_7_0_NS has the same fix.
> > > 
> > > The fix is now in 7.0.x and in GDBRunControl_7_0_NS
> > 
> > Should we make MIBreakpointsManager.adjustDebuggerPath public in HEAD (only) to
> > avoid duplication of code in GDBRunControl_7_0_NS ?
> > 
> > I can do it if you agree.
> 
> I don't think we should. It's a method that exists only to support a hack. I
> don't think we should make it API. It's a small enough method that duplicating
> it is not a big deal, IMO.

Valid point. Ok.

thanks for the fix.
Comment 20 John Cortell CLA 2010-09-28 11:04:33 EDT
(In reply to comment #19)
> Valid point. Ok.

That said, we could move the method to some internal package and make it public. It's up to you.
Comment 21 Marc Khouzam CLA 2010-09-28 11:06:32 EDT
(In reply to comment #20)
> (In reply to comment #19)
> > Valid point. Ok.
> 
> That said, we could move the method to some internal package and make it
> public. It's up to you.

No worth the effort I think.  Maybe when and if we have to use it again somewhere else.