Author Topic: Can't set GDB breakpoints in other directories  (Read 13904 times)

Offline HillClimber

  • Single posting newcomer
  • *
  • Posts: 4
Can't set GDB breakpoints in other directories
« on: January 04, 2007, 08:06:53 pm »
Hi,

I haven't been able to successfully use the GDB integration.  The main issue seems to be that CodeBlocks is sending a relative path for a source file, which GDB doesn't accept. 

I have a workspace with multiple projects in separate directories.  If I hit F8 and click in some source to add a breakpoint, cb_gdb sends a command which GDB doesn't like:

Code
>>>>>>cb_gdb:
> break "../Atlas/Exception.cpp:61"
No source file named ../Atlas/Exception.cpp.
Breakpoint 1 ("../Atlas/Exception.cpp:61) pending.
>>>>>>cb_gdb:

GDB does seem to like just a base filename (which it finds in the source directory serarch paths), or an absolute path to a file.  It only chokes on the relative paths.

By the way, I also tried setting breakpoints by hand, and although GDB stops on them, CB_GDB immediately issues a "cont" command so I can't inspect anything :(

I'm running on Ubuntu Edgy, and I've tried the last three or four nightly builds with Edgy packages.  I've also tried both the stock GDB unbuntu package (6.4.90-ubuntu) and compiling GDB from the 6.6 source.

TIA for your help, and thanks much for creating a great IDE!

- AC

Offline MortenMacFly

  • Administrator
  • Lives here!
  • *****
  • Posts: 9616
Re: Can't set GDB breakpoints in other directories
« Reply #1 on: January 04, 2007, 10:09:04 pm »
This is a known issue and is currently being investigated. For a quick (better) solution (and in case you compile C::B yourself) you may want to comment the following lines in debuggerstate.cpp:
Code
        else
        {
        // for foreign files, we still should use a relative path
        wxFileName f(filename);
        f.MakeRelativeTo(prj->GetBasePath());
        fname = f.GetFullPath();
        }
This isn't complete - there are still cases where this doesn't work properly yet...
Yiannis: Do you remember my PM of the other day (back in the old year 2006)...?! ;-)
With regards, Morten.
Compiler logging: Settings->Compiler & Debugger->tab "Other"->Compiler logging="Full command line"
C::B Manual: http://www.codeblocks.org/docs/main_codeblocks_en.html
C::B FAQ: http://wiki.codeblocks.org/index.php?title=FAQ

Offline HillClimber

  • Single posting newcomer
  • *
  • Posts: 4
Re: Can't set GDB breakpoints in other directories
« Reply #2 on: January 09, 2007, 03:31:30 am »
Morten,

Thanks for the tip.  I hacked up the source as you suggested, and actually had to make a number of additional changes to get the debugger to work for me.  I posted a patch on the developer forum:

http://forums.codeblocks.org/index.php?topic=4896.msg38219#msg38219

Thanks!
- HC

Offline MortenMacFly

  • Administrator
  • Lives here!
  • *****
  • Posts: 9616
Re: Can't set GDB breakpoints in other directories
« Reply #3 on: January 10, 2007, 12:52:30 pm »
http://forums.codeblocks.org/index.php?topic=4896.msg38219#msg38219
I think it is important to notice why this "else" tree (I believe even the whole method) was actually implemented.
The reason was due to issues with breakpoints in a project where the *project* file is in another sub-directory (not at the project's top-level path).
I wonder if that will still work with your changes applied. Could you give that a try, please?
Thus, have e.g. such a folder structure:
C:\MyProject\src\includes -> header files
C:\MyProject\src\sources -> implementation files
C:\MyProject\src\project -> C::B project (workspace) file
With regards, Morten.
Compiler logging: Settings->Compiler & Debugger->tab "Other"->Compiler logging="Full command line"
C::B Manual: http://www.codeblocks.org/docs/main_codeblocks_en.html
C::B FAQ: http://wiki.codeblocks.org/index.php?title=FAQ

Offline Game_Ender

  • Lives here!
  • ****
  • Posts: 551
Re: Can't set GDB breakpoints in other directories
« Reply #4 on: January 11, 2007, 09:52:22 am »
Could this all be solved if CB used absolute paths for compiling debug executables?  Then the absolute path will be encoded into the binary and when CB sends it an absolute path for the breakpoint it will have no problem finding the proper file.  Or does GDB work in some other way?

Offline killerbot

  • Administrator
  • Lives here!
  • *****
  • Posts: 5300
Re: Can't set GDB breakpoints in other directories
« Reply #5 on: January 11, 2007, 11:01:19 am »
I feel we are something missing in our understanding of gdb. Or GDB is missing a serious feature ;-)

Offline MortenMacFly

  • Administrator
  • Lives here!
  • *****
  • Posts: 9616
Re: Can't set GDB breakpoints in other directories
« Reply #6 on: January 11, 2007, 11:06:50 am »
I feel we are something missing in our understanding of gdb. Or GDB is missing a serious feature ;-)
This I honestly believe, too. ;-)
Compiler logging: Settings->Compiler & Debugger->tab "Other"->Compiler logging="Full command line"
C::B Manual: http://www.codeblocks.org/docs/main_codeblocks_en.html
C::B FAQ: http://wiki.codeblocks.org/index.php?title=FAQ

Offline mandrav

  • Project Leader
  • Administrator
  • Lives here!
  • *****
  • Posts: 4315
    • Code::Blocks IDE
Re: Can't set GDB breakpoints in other directories
« Reply #7 on: January 11, 2007, 12:11:57 pm »
I feel we are something missing in our understanding of gdb. Or GDB is missing a serious feature ;-)
This I honestly believe, too. ;-)

I can explain exactly what happens if you want but the problem is actually how gdb looks for source files. If you ask me, having looked at it extensively, it's a borked implementation in gdb. It all stems from the fact that for gdb C:\Devel\foo\bar\..\foo.cpp is a different file from C:\Devel\foo\foo.cpp.

The only solution I can think of is for C::B to use full file path when compiling (not linking) a file. Have to test it though.
Be patient!
This bug will be fixed soon...

Offline Game_Ender

  • Lives here!
  • ****
  • Posts: 551
Re: Can't set GDB breakpoints in other directories
« Reply #8 on: January 12, 2007, 06:04:20 am »
It might be slower but I thought is a best practice to at least normalize and at best make absolute paths that you pass off to other tools, because you can make no assumptions about how they handle them.   I do agree GDB should really do the same thing and normalize all paths before comparison.

Offline mandrav

  • Project Leader
  • Administrator
  • Lives here!
  • *****
  • Posts: 4315
    • Code::Blocks IDE
Re: Can't set GDB breakpoints in other directories
« Reply #9 on: January 15, 2007, 11:51:00 am »
Since revision 3491, absolute filenames are used when compiling source files. I tested it and debugging works fine this way :).

This means that you should rebuild your libraries (at least those that you 're having trouble putting breakpoints into when debugging other projects).
Be patient!
This bug will be fixed soon...

Offline MortenMacFly

  • Administrator
  • Lives here!
  • *****
  • Posts: 9616
Re: Can't set GDB breakpoints in other directories
« Reply #10 on: January 15, 2007, 12:38:20 pm »
Since revision 3491, absolute filenames are used when compiling source files. I tested it and debugging works fine this way :).
I wouldn't say "fine" but "better" due to:
http://forums.codeblocks.org/index.php?topic=4896.msg38390#msg38390
;-)
With regards, Morten.
Compiler logging: Settings->Compiler & Debugger->tab "Other"->Compiler logging="Full command line"
C::B Manual: http://www.codeblocks.org/docs/main_codeblocks_en.html
C::B FAQ: http://wiki.codeblocks.org/index.php?title=FAQ