Author Topic: Cygwin with CodeBlocks gdb error  (Read 25567 times)

Offline venom4u31

  • Multiple posting newcomer
  • *
  • Posts: 19
Cygwin with CodeBlocks gdb error
« on: December 09, 2013, 08:27:28 pm »
I have Code Blocks 12.11 and I have Cygwin 1.7.27 installed. I have configured C::B to run the Cygwin compiler and it works, but when I try to run the debugger from the Code Blocks environment I get the error:

Quote
Cannot open file /cygdrive/c/some_path/main.c

At /cygdrive/c/some_path/main.c:15

If I try to run gdb on the same file from the cygwin command line interface, it works.

Can somebody please help me fix this problem?

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 13406
    • Travis build status
Re: Cygwin with CodeBlocks gdb error
« Reply #1 on: December 09, 2013, 10:12:35 pm »
Can you post the full log from the debugger? (you should enable it first in settings -> debugger)
(most of the time I ignore long posts)
[strangers don't send me private messages, I'll ignore them; post a topic in the forum, but first read the rules!]

Offline venom4u31

  • Multiple posting newcomer
  • *
  • Posts: 19
Re: Cygwin with CodeBlocks gdb error
« Reply #2 on: December 09, 2013, 10:17:37 pm »
Sure, here it is:


Quote
Building to ensure sources are up-to-date
Selecting target:
Debug
Adding source dir: C:\test_project\
Adding source dir: C:\test_project\
Adding file: C:\test_project\bin\Debug\test_project.exe
Changing directory to: C:/test_project/.
Set variable: PATH=.;C:\cygwin64\bin;C:\cygwin64;C:\Program Files (x86)\CodeBlocks\MinGW\bin;C:\Program Files (x86)\CodeBlocks\MinGW;C:\Program Files (x86)\Common Files\Microsoft Shared\Windows Live

[debug]Command-line: C:\cygwin64\bin\gdb.exe -nx -fullname  -quiet  -args C:/test_project/bin/Debug/test_project.exe
[debug]Working dir : C:\test_project

Starting debugger: C:\cygwin64\bin\gdb.exe -nx -fullname  -quiet  -args C:/test_project/bin/Debug/test_project.exe
done

[debug]> set prompt >>>>>>cb_gdb:

Registered new type: wxString
Registered new type: STL String
Registered new type: STL Vector
Setting breakpoints

[debug]Reading symbols from /cygdrive/c/test_project/bin/Debug/test_project.exe...done.
[debug](gdb) >>>>>>cb_gdb:
[debug]> show version
[debug]GNU gdb (GDB) 7.6.50.20130728-cvs (cygwin-special)
[debug]Copyright (C) 2013 Free Software Foundation, Inc.
[debug]License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
[debug]This is free software: you are free to change and redistribute it.
[debug]There is NO WARRANTY, to the extent permitted by law.  Type "show copying"
[debug]and "show warranty" for details.
[debug]This GDB was configured as "x86_64-pc-cygwin".
[debug]Type "show configuration" for configuration details.
[debug]For bug reporting instructions, please see:
[debug]<http://www.gnu.org/software/gdb/bugs/>.
[debug]Find the GDB manual and other documentation resources online at:
[debug]<http://www.gnu.org/software/gdb/documentation/>.
[debug]For help, type "help".
[debug]Type "apropos word" to search for commands related to "word".
[debug]>>>>>>cb_gdb:
[debug]> set confirm off

Debugger name and version: GNU gdb (GDB) 7.6.50.20130728-cvs (cygwin-special)

[debug]>>>>>>cb_gdb:
[debug]> set width 0
[debug]>>>>>>cb_gdb:
[debug]> set height 0
[debug]>>>>>>cb_gdb:
[debug]> set breakpoint pending on
[debug]>>>>>>cb_gdb:
[debug]> set print asm-demangle on
[debug]>>>>>>cb_gdb:
[debug]> set unwindonsignal on
[debug]>>>>>>cb_gdb:
[debug]> set print elements 0
[debug]>>>>>>cb_gdb:
[debug]> set new-console on
[debug]>>>>>>cb_gdb:
[debug]> set disassembly-flavor att
[debug]>>>>>>cb_gdb:
[debug]> catch throw
[debug]Catchpoint 1 (throw)
[debug]>>>>>>cb_gdb:
[debug]> source C:\Program Files (x86)\CodeBlocks\share\codeblocks/scripts/stl-views-1.0.3.gdb
[debug]>>>>>>cb_gdb:
[debug]> directory C:/test_project/
[debug]Source directories searched: /cygdrive/c/test_project/C:/test_project:$cdir:$cwd
[debug]>>>>>>cb_gdb:
[debug]> break "C:/test_project/main.c:6"
[debug]Breakpoint 2 at 0x1004010dd: file C:\test_project\main.c, line 6.
[debug]>>>>>>cb_gdb:
[debug]> run
[debug]Starting program: /cygdrive/c/test_project/bin/Debug/test_project.exe

Child process PID: 7240

[debug][New Thread 7240.0x6c4]
[debug][New Thread 7240.0x1de8]
[debug]Breakpoint 2, main () at C:\test_project\main.c:6
[debug]/cygdrive/c/test_project/main.c:6:58:beg:0x1004010dd
[debug]>>>>>>cb_gdb:

Cannot open file: /cygdrive/c/test_project/main.c
At /cygdrive/c/test_project/main.c:6

Offline ouch

  • Almost regular
  • **
  • Posts: 223
Re: Cygwin with CodeBlocks gdb error
« Reply #3 on: December 10, 2013, 02:14:47 am »
I would check your source directories:

Code
Source directories searched: /cygdrive/c/test_project/C:/test_project:$cdir:$cwd

because that looks messed up...

Offline ollydbg

  • Developer
  • Lives here!
  • *****
  • Posts: 6077
  • OpenCV and Robotics
    • Chinese OpenCV forum moderator
Re: Cygwin with CodeBlocks gdb error
« Reply #4 on: December 10, 2013, 04:57:42 am »
I have no experience with cygwin(gcc+gdb), but for your problem, I think it is good to build your exe with "relative path" enabled, so that C::B or GDB can try to search/open a file with relative path.

To use the relative path, you can try Settings->compilers->other settings->advanced options button->Others

Then, De-select the option "Use full path for source files(GDB workaround)".

BTW: it was a GDB workaround option, but with modern GDB(I think version >7.0) handles source file paths very well. So, it is safe to de-select this option.
If some piece of memory should be reused, turn them to variables (or const variables).
If some piece of operations should be reused, turn them to functions.
If they happened together, then turn them to classes.

Offline venom4u31

  • Multiple posting newcomer
  • *
  • Posts: 19
Re: Cygwin with CodeBlocks gdb error
« Reply #5 on: December 10, 2013, 08:02:17 am »
I have no experience with cygwin(gcc+gdb), but for your problem, I think it is good to build your exe with "relative path" enabled, so that C::B or GDB can try to search/open a file with relative path.

To use the relative path, you can try Settings->compilers->other settings->advanced options button->Others

Then, De-select the option "Use full path for source files(GDB workaround)".

BTW: it was a GDB workaround option, but with modern GDB(I think version >7.0) handles source file paths very well. So, it is safe to de-select this option.

I tried your suggestion, but got the same error, even after I restarted and rebuilt the project. Here's the log information:

Quote
Building to ensure sources are up-to-date
Selecting target:
Debug
Adding source dir: C:\test_project\
Adding source dir: C:\test_project\
Adding file: C:\test_project\bin\Debug\test_project.exe
Changing directory to: C:/test_project/.
Set variable: PATH=.;C:\cygwin64\bin;C:\cygwin64;C:\Program Files (x86)\CodeBlocks\MinGW\bin;C:\Program Files (x86)\CodeBlocks\MinGW;C:\Program Files\Common Files\Microsoft Shared\Windows Live

[debug]Command-line: C:\cygwin64\bin\gdb.exe -nx -fullname  -quiet  -args C:/test_project/bin/Debug/test_project.exe
[debug]Working dir : C:\test_project

Starting debugger: C:\cygwin64\bin\gdb.exe -nx -fullname  -quiet  -args C:/test_project/bin/Debug/test_project.exe
done

[debug]> set prompt >>>>>>cb_gdb:

Registered new type: wxString
Registered new type: STL String
Registered new type: STL Vector
Setting breakpoints

[debug]Reading symbols from /cygdrive/c/test_project/bin/Debug/test_project.exe...done.
[debug](gdb) >>>>>>cb_gdb:
[debug]> show version
[debug]GNU gdb (GDB) 7.6.50.20130728-cvs (cygwin-special)
[debug]Copyright (C) 2013 Free Software Foundation, Inc.
[debug]License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
[debug]This is free software: you are free to change and redistribute it.
[debug]There is NO WARRANTY, to the extent permitted by law.  Type "show copying"
[debug]and "show warranty" for details.
[debug]This GDB was configured as "x86_64-pc-cygwin".
[debug]Type "show configuration" for configuration details.
[debug]For bug reporting instructions, please see:
[debug]<http://www.gnu.org/software/gdb/bugs/>.
[debug]Find the GDB manual and other documentation resources online at:
[debug]<http://www.gnu.org/software/gdb/documentation/>.
[debug]For help, type "help".
[debug]Type "apropos word" to search for commands related to "word".
[debug]>>>>>>cb_gdb:
[debug]> set confirm off

Debugger name and version: GNU gdb (GDB) 7.6.50.20130728-cvs (cygwin-special)

[debug]>>>>>>cb_gdb:
[debug]> set width 0
[debug]>>>>>>cb_gdb:
[debug]> set height 0
[debug]>>>>>>cb_gdb:
[debug]> set breakpoint pending on
[debug]>>>>>>cb_gdb:
[debug]> set print asm-demangle on
[debug]>>>>>>cb_gdb:
[debug]> set unwindonsignal on
[debug]>>>>>>cb_gdb:
[debug]> set print elements 0
[debug]>>>>>>cb_gdb:
[debug]> set new-console on
[debug]>>>>>>cb_gdb:
[debug]> set disassembly-flavor att
[debug]>>>>>>cb_gdb:
[debug]> catch throw
[debug]Catchpoint 1 (throw)
[debug]>>>>>>cb_gdb:
[debug]> source C:\Program Files (x86)\CodeBlocks\share\codeblocks/scripts/stl-views-1.0.3.gdb
[debug]>>>>>>cb_gdb:
[debug]> directory C:/test_project/
[debug]Source directories searched: /cygdrive/c/test_project/C:/test_project:$cdir:$cwd
[debug]>>>>>>cb_gdb:
[debug]> break "C:/test_project/main.c:6"
[debug]Breakpoint 2 at 0x1004010dd: file C:\test_project\main.c, line 6.
[debug]>>>>>>cb_gdb:
[debug]> run
[debug]Starting program: /cygdrive/c/test_project/bin/Debug/test_project.exe

Child process PID: 1448

[debug][New Thread 1448.0x181c]
[debug][New Thread 1448.0x179c]
[debug]Breakpoint 2, main () at C:\test_project\main.c:6
[debug]/cygdrive/c/test_project/main.c:6:58:beg:0x1004010dd
[debug]>>>>>>cb_gdb:

Cannot open file: /cygdrive/c/test_project/main.c
At /cygdrive/c/test_project/main.c:6

Offline venom4u31

  • Multiple posting newcomer
  • *
  • Posts: 19
Re: Cygwin with CodeBlocks gdb error
« Reply #6 on: December 10, 2013, 08:04:59 am »
I would check your source directories:

Code
Source directories searched: /cygdrive/c/test_project/C:/test_project:$cdir:$cwd

because that looks messed up...

I agree that this looks messed up, but I have no idea of what to do about it.

Offline ollydbg

  • Developer
  • Lives here!
  • *****
  • Posts: 6077
  • OpenCV and Robotics
    • Chinese OpenCV forum moderator
Re: Cygwin with CodeBlocks gdb error
« Reply #7 on: December 10, 2013, 08:17:51 am »
Ok, I know the problem.
Code
Source directories searched: /cygdrive/c/test_project/C:/test_project:$cdir:$cwd
This is not the issue, never mind about this.

Code
[debug]Breakpoint 2, main () at C:\test_project\main.c:6
[debug]/cygdrive/c/test_project/main.c:6:58:beg:0x1004010dd
[debug]>>>>>>cb_gdb:

Cannot open file: /cygdrive/c/test_project/main.c
At /cygdrive/c/test_project/main.c:6
This is the core point, you see, GDB still return the full path of "/cygdrive/c/test_project/main.c:...."

Now, If I remember correct, there is an option to change this behavior under GDB, like:

Code
set filename-display relative
SEE: http://visualgdb.com/gdbreference/commands/set_filename-display

Now, this will let GDB only print the relative file path, in your case maybe "main.c".

You can put this command in: Debugger settings->Debugger initialization commands.

NOTE: I'm not sure whether the comman
Code
set filename-display relative
can affect the file name format of the breakpoint, it does change the filename display format for backtrace command.





If some piece of memory should be reused, turn them to variables (or const variables).
If some piece of operations should be reused, turn them to functions.
If they happened together, then turn them to classes.

Offline ollydbg

  • Developer
  • Lives here!
  • *****
  • Posts: 6077
  • OpenCV and Robotics
    • Chinese OpenCV forum moderator
Re: Cygwin with CodeBlocks gdb error
« Reply #8 on: December 10, 2013, 08:26:21 am »
Look, I just test it, I create a simple app, and build it with relative paths(advanced settings in compiler setting dialog)
Code
[debug]> set new-console on
[debug]>>>>>>cb_gdb:
[debug]> set disassembly-flavor intel
[debug]>>>>>>cb_gdb:
[debug]> source E:\code\gdb\mybuild\bin\my.gdb
[debug]>>>>>>cb_gdb:
[debug]> directory E:/code/cb/test_code/test-memory-leak/
[debug]Source directories searched: E:/code/cb/test_code/test-memory-leak;$cdir;$cwd
[debug]>>>>>>cb_gdb:
[debug]> break "E:/code/cb/test_code/test-memory-leak/main.cpp:12"
[debug]Breakpoint 1 at 0x401613: file main.cpp, line 12.
[debug]>>>>>>cb_gdb:
[debug]> run
[debug]Starting program: E:\code\cb\test_code\test-memory-leak\bin\Debug\test-memory-leak.exe

Child process PID: 304

[debug][New Thread 304.0xdf4]
[debug]Breakpoint 1, main () at main.cpp:12
[debug]E:\code\cb\test_code\test-memory-leak\main.cpp:12:172:beg:0x401613
[debug]>>>>>>cb_gdb:

At E:\code\cb\test_code\test-memory-leak\main.cpp:12

Then "source E:\code\gdb\mybuild\bin\my.gdb" contains the "set filename-display relative", and look, the return file name is now relative:

Code
Breakpoint 1, main () at main.cpp:12

But the bad thing is, the next line is still full path: "E:\code\cb\test_code\test-memory-leak\main.cpp:12:172:beg:0x401613", C::B need to parse this line to locate the caret. In your case, it is "/cygdrive/c/test_project/main.c", which C::B don't know to translate to "c:test_project/main.c"

One question: can you just try a Mingw version of GDB to debug your problem (Not the one shipped with cygwin).

EDIT:
I see your are using a cygwin 64bit GDB (This GDB was configured as "x86_64-pc-cygwin".), so you are using 64bit GDB, I think TDM-GCC-64bit maybe contains 64bit GDB.exe, since the cygwin GDB will always return a full path which has a prefix "/cygdrive/c/....", can you try to find an option to remove them???



« Last Edit: December 10, 2013, 08:29:30 am by ollydbg »
If some piece of memory should be reused, turn them to variables (or const variables).
If some piece of operations should be reused, turn them to functions.
If they happened together, then turn them to classes.

Offline venom4u31

  • Multiple posting newcomer
  • *
  • Posts: 19
Re: Cygwin with CodeBlocks gdb error
« Reply #9 on: December 10, 2013, 08:37:21 am »
I tried adding the command to the initialization command list, and this is the output... the outcome is the same though. However, the command seems to be called.

Code
Building to ensure sources are up-to-date
Selecting target:
Debug
Adding source dir: C:\test_project\
Adding source dir: C:\test_project\
Adding file: C:\test_project\bin\Debug\test_project.exe
Changing directory to: C:/test_project/.
Set variable: PATH=.;C:\cygwin64\bin;C:\cygwin64;C:\Program Files (x86)\CodeBlocks\MinGW\bin;C:\Program Files (x86)\CodeBlocks\MinGW;C:\Program Files\Common Files\Microsoft Shared\Windows Live

[debug]Command-line: C:\cygwin64\bin\gdb.exe -nx -fullname  -quiet  -args C:/test_project/bin/Debug/test_project.exe
[debug]Working dir : C:\test_project

Starting debugger: C:\cygwin64\bin\gdb.exe -nx -fullname  -quiet  -args C:/test_project/bin/Debug/test_project.exe
done

[debug]> set prompt >>>>>>cb_gdb:

Registered new type: wxString
Registered new type: STL String
Registered new type: STL Vector
Setting breakpoints

[debug]Reading symbols from /cygdrive/c/test_project/bin/Debug/test_project.exe...done.
[debug](gdb) >>>>>>cb_gdb:
[debug]> show version
[debug]GNU gdb (GDB) 7.6.50.20130728-cvs (cygwin-special)
[debug]Copyright (C) 2013 Free Software Foundation, Inc.
[debug]License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
[debug]This is free software: you are free to change and redistribute it.
[debug]There is NO WARRANTY, to the extent permitted by law.  Type "show copying"
[debug]and "show warranty" for details.
[debug]This GDB was configured as "x86_64-pc-cygwin".
[debug]Type "show configuration" for configuration details.
[debug]For bug reporting instructions, please see:
[debug]<http://www.gnu.org/software/gdb/bugs/>.
[debug]Find the GDB manual and other documentation resources online at:
[debug]<http://www.gnu.org/software/gdb/documentation/>.
[debug]For help, type "help".
[debug]Type "apropos word" to search for commands related to "word".
[debug]>>>>>>cb_gdb:
[debug]> set confirm off

Debugger name and version: GNU gdb (GDB) 7.6.50.20130728-cvs (cygwin-special)

[debug]>>>>>>cb_gdb:
[debug]> set width 0
[debug]>>>>>>cb_gdb:
[debug]> set height 0
[debug]>>>>>>cb_gdb:
[debug]> set breakpoint pending on
[debug]>>>>>>cb_gdb:
[debug]> set print asm-demangle on
[debug]>>>>>>cb_gdb:
[debug]> set unwindonsignal on
[debug]>>>>>>cb_gdb:
[debug]> set print elements 0
[debug]>>>>>>cb_gdb:
[debug]> set new-console on
[debug]>>>>>>cb_gdb:
[debug]> set disassembly-flavor att
[debug]>>>>>>cb_gdb:
[debug]> catch throw
[debug]Catchpoint 1 (throw)
[debug]>>>>>>cb_gdb:
[debug]> source C:\Program Files (x86)\CodeBlocks\share\codeblocks/scripts/stl-views-1.0.3.gdb
[debug]>>>>>>cb_gdb:
[debug]> set filename-display relative
[debug]>>>>>>cb_gdb:
[debug]> directory C:/test_project/
[debug]Source directories searched: /cygdrive/c/test_project/C:/test_project:$cdir:$cwd
[debug]>>>>>>cb_gdb:
[debug]> break "C:/test_project/main.c:6"
[debug]Breakpoint 2 at 0x1004010dd: file main.c, line 6.
[debug]>>>>>>cb_gdb:
[debug]> run
[debug]Starting program: /cygdrive/c/test_project/bin/Debug/test_project.exe

Child process PID: 3920

[debug][New Thread 3920.0x19d8]
[debug][New Thread 3920.0x11a8]
[debug]Breakpoint 2, main () at main.c:6
[debug]/cygdrive/c/test_project/main.c:6:58:beg:0x1004010dd
[debug]>>>>>>cb_gdb:

Cannot open file: /cygdrive/c/test_project/main.c
At /cygdrive/c/test_project/main.c:6


This is the output from the minGW debugger: There also seems to be some problem with it that hasn't occurred before trying out the cygwin debugger (it has no modification done to it, and it produces the same output to older projects as well).

Code
Building to ensure sources are up-to-date
Selecting target:
Debug
Adding source dir: C:\test_project\
Adding source dir: C:\test_project\
Adding file: C:\test_project\bin\Debug\test_project.exe
Changing directory to: C:/test_project/.
Set variable: PATH=.;C:\Program Files (x86)\CodeBlocks\MinGW\bin;C:\Program Files (x86)\CodeBlocks\MinGW;C:\cygwin64\bin;C:\cygwin64;C:\Program Files\Common Files\Microsoft Shared\Windows Live

[debug]Command-line: C:\cygwin64\bin\gdb.exe -nx -fullname  -quiet  -args C:/test_project/bin/Debug/test_project.exe
[debug]Working dir : C:\test_project

Starting debugger: C:\cygwin64\bin\gdb.exe -nx -fullname  -quiet  -args C:/test_project/bin/Debug/test_project.exe
done

[debug]> set prompt >>>>>>cb_gdb:

Registered new type: wxString
Registered new type: STL String
Registered new type: STL Vector
Setting breakpoints

[debug]Reading symbols from /cygdrive/c/test_project/bin/Debug/test_project.exe...done.
[debug](gdb) >>>>>>cb_gdb:
[debug]> show version
[debug]GNU gdb (GDB) 7.6.50.20130728-cvs (cygwin-special)
[debug]Copyright (C) 2013 Free Software Foundation, Inc.
[debug]License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
[debug]This is free software: you are free to change and redistribute it.
[debug]There is NO WARRANTY, to the extent permitted by law.  Type "show copying"
[debug]and "show warranty" for details.
[debug]This GDB was configured as "x86_64-pc-cygwin".
[debug]Type "show configuration" for configuration details.
[debug]For bug reporting instructions, please see:
[debug]<http://www.gnu.org/software/gdb/bugs/>.
[debug]Find the GDB manual and other documentation resources online at:
[debug]<http://www.gnu.org/software/gdb/documentation/>.
[debug]For help, type "help".
[debug]Type "apropos word" to search for commands related to "word".
[debug]>>>>>>cb_gdb:
[debug]> set confirm off

Debugger name and version: GNU gdb (GDB) 7.6.50.20130728-cvs (cygwin-special)

[debug]>>>>>>cb_gdb:
[debug]> set width 0
[debug]>>>>>>cb_gdb:
[debug]> set height 0
[debug]>>>>>>cb_gdb:
[debug]> set breakpoint pending on
[debug]>>>>>>cb_gdb:
[debug]> set print asm-demangle on
[debug]>>>>>>cb_gdb:
[debug]> set unwindonsignal on
[debug]>>>>>>cb_gdb:
[debug]> set print elements 0
[debug]>>>>>>cb_gdb:
[debug]> set new-console on
[debug]>>>>>>cb_gdb:
[debug]> set disassembly-flavor att
[debug]>>>>>>cb_gdb:
[debug]> catch throw
[debug]Catchpoint 1 (throw)
[debug]>>>>>>cb_gdb:
[debug]> source C:\Program Files (x86)\CodeBlocks\share\codeblocks/scripts/stl-views-1.0.3.gdb
[debug]>>>>>>cb_gdb:
[debug]> set filename-display relative
[debug]>>>>>>cb_gdb:
[debug]> directory C:/test_project/
[debug]Source directories searched: /cygdrive/c/test_project/C:/test_project:$cdir:$cwd
[debug]>>>>>>cb_gdb:
[debug]> break "C:/test_project/main.c:6"
[debug]Breakpoint 2 at 0x401342: file C:\test_project\main.c, line 6.
[debug]>>>>>>cb_gdb:
[debug]> run
[debug]dll path too long
[debug]dll path too long
[debug]dll path too long
[debug]dll path too long
[debug]dll path too long
[debug]Starting program: /cygdrive/c/test_project/bin/Debug/test_project.exe

Child process PID: 7016

[debug][New Thread 7016.0x10f4]
[debug]Program received signal ?, Unknown signal.
[debug]0x0008da98 in ?? ()
[debug]>>>>>>cb_gdb:

In ?? () ()

[debug]> bt 30
[debug]#0  0x0008da98 in ?? ()
[debug]>>>>>>cb_gdb:

EDIT:

I deleted the Cygwin compiler and debogger from C::B and everything works normally. I am going to remove the 64-bit cygwin and install the 32-bit one and see what happens then.

« Last Edit: December 10, 2013, 08:45:42 am by venom4u31 »

Offline ollydbg

  • Developer
  • Lives here!
  • *****
  • Posts: 6077
  • OpenCV and Robotics
    • Chinese OpenCV forum moderator
Re: Cygwin with CodeBlocks gdb error
« Reply #10 on: December 10, 2013, 08:42:48 am »
I just read the C::B source code, and I found several functions to handle cygdrive related paths:

Code
// Cygwin check code
#ifdef __WXMSW__

enum{ BUFSIZE = 64 };

// routines to handle cygwin compiled programs on a Windows compiled C::B IDE
void GDB_driver::DetectCygwinMount(void)
{
....

    m_CygwinPresent  = true;           // if we end up here all was OK
    m_CygdrivePrefix = (szCygwinRoot); // convert to wxString type for later use
}

void GDB_driver::CorrectCygwinPath(wxString& path)
{
...
}
#else
    void GDB_driver::DetectCygwinMount(void){/* dummy */}
    void GDB_driver::CorrectCygwinPath(cb_unused wxString& path){/* dummy */}
#endif


So, normally, the cygwin installation is detected.

Especially, there are code to do the translation:
Code
        // Check for possibility of a cygwin compiled program
        // convert to valid path
        if (platform::windows && m_CygwinPresent)
            CorrectCygwinPath(lines.Item(i));

Now, here comes my guess, you have installed the cygwin 64 bit, which our function: void GDB_driver::DetectCygwinMount(void) failed to detect as a cygwin. The detecting algorithm is simply check the Windows registry like:

Code
// routines to handle cygwin compiled programs on a Windows compiled C::B IDE
void GDB_driver::DetectCygwinMount(void)
{
    LONG lRegistryAPIresult;
    HKEY hKey_CU;
    HKEY hKey_LM;
    TCHAR szCygwinRoot[BUFSIZE];
    DWORD dwBufLen=BUFSIZE*sizeof(TCHAR);

    // checking if cygwin mounts are present under HKCU
    lRegistryAPIresult = RegOpenKeyEx( HKEY_CURRENT_USER,
                         TEXT("Software\\Cygnus Solutions\\Cygwin\\mounts v2"),
                         0, KEY_QUERY_VALUE, &hKey_CU );
    if ( lRegistryAPIresult == ERROR_SUCCESS )
    {
        // try to readback cygwin root (might not exist!)
        lRegistryAPIresult = RegQueryValueEx( hKey_CU, TEXT("cygdrive prefix"), NULL, NULL,
                             (LPBYTE) szCygwinRoot, &dwBufLen);
    }

    // lRegistryAPIresult can be erroneous for two reasons:
    // 1.) Cygwin entry is not present (could not be opened) in HKCU
    // 2.) "cygdrive prefix" is not present (could not be read) in HKCU
    if ( lRegistryAPIresult != ERROR_SUCCESS )
    {
        // Now check if probably present under HKLM
        lRegistryAPIresult = RegOpenKeyEx( HKEY_LOCAL_MACHINE,
                             TEXT("SOFTWARE\\Cygnus Solutions\\Cygwin\\mounts v2"),
                             0, KEY_QUERY_VALUE, &hKey_LM );
        if ( lRegistryAPIresult != ERROR_SUCCESS )
        {
            // cygwin definitely not installed
            m_CygwinPresent = false;
            return;
        }

        // try to readback cygwin root (now it really should exist here)
        lRegistryAPIresult = RegQueryValueEx( hKey_LM, TEXT("cygdrive prefix"), NULL, NULL,
                             (LPBYTE) szCygwinRoot, &dwBufLen);
    }

    // handle a possible query error
    if ( (lRegistryAPIresult != ERROR_SUCCESS) || (dwBufLen > BUFSIZE*sizeof(TCHAR)) )
    {
        // bit of an assumption, but we won't be able to find the root without it
        m_CygwinPresent = false;
        return;
    }

    // close opened keys
    RegCloseKey( hKey_CU ); // ignore key close errors
    RegCloseKey( hKey_LM ); // ignore key close errors

    m_CygwinPresent  = true;           // if we end up here all was OK
    m_CygdrivePrefix = (szCygwinRoot); // convert to wxString type for later use
}

Can you try to see in your Windows registry that those expect value exist? If not, can you create some dummy ones to cheat C::B's DetectCygwinMount function?
If some piece of memory should be reused, turn them to variables (or const variables).
If some piece of operations should be reused, turn them to functions.
If they happened together, then turn them to classes.

Offline venom4u31

  • Multiple posting newcomer
  • *
  • Posts: 19
Re: Cygwin with CodeBlocks gdb error
« Reply #11 on: December 10, 2013, 08:49:35 am »
I don't have those registers... I'll create some dummy ones and let you know if it worked.

Offline ollydbg

  • Developer
  • Lives here!
  • *****
  • Posts: 6077
  • OpenCV and Robotics
    • Chinese OpenCV forum moderator
Re: Cygwin with CodeBlocks gdb error
« Reply #12 on: December 10, 2013, 08:50:04 am »
I tried adding the command to the initialization command list, and this is the output... the outcome is the same though. However, the command seems to be called.

Code
...
[debug]> set filename-display relative
[debug]>>>>>>cb_gdb:
[debug]> directory C:/test_project/
[debug]Source directories searched: /cygdrive/c/test_project/C:/test_project:$cdir:$cwd
[debug]>>>>>>cb_gdb:
[debug]> break "C:/test_project/main.c:6"
[debug]Breakpoint 2 at 0x1004010dd: file main.c, line 6.
[debug]>>>>>>cb_gdb:
[debug]> run
[debug]Starting program: /cygdrive/c/test_project/bin/Debug/test_project.exe

Child process PID: 3920

[debug][New Thread 3920.0x19d8]
[debug][New Thread 3920.0x11a8]
[debug]Breakpoint 2, main () at main.c:6
[debug]/cygdrive/c/test_project/main.c:6:58:beg:0x1004010dd
[debug]>>>>>>cb_gdb:

Cannot open file: /cygdrive/c/test_project/main.c
At /cygdrive/c/test_project/main.c:6
yes, the change filename display command works OK.



Quote
This is the output from the minGW debugger: There also seems to be some problem with it that hasn't occurred before trying out the cygwin debugger (it has no modification done to it, and it produces the same output to older projects as well).

Code
Building to ensure sources are up-to-date
Selecting target:
Debug
Adding source dir: C:\test_project\
Adding source dir: C:\test_project\
Adding file: C:\test_project\bin\Debug\test_project.exe
Changing directory to: C:/test_project/.
Set variable: PATH=.;C:\Program Files (x86)\CodeBlocks\MinGW\bin;C:\Program Files (x86)\CodeBlocks\MinGW;C:\cygwin64\bin;C:\cygwin64;C:\Program Files\Common Files\Microsoft Shared\Windows Live

[debug]Command-line: C:\cygwin64\bin\gdb.exe -nx -fullname  -quiet  -args C:/test_project/bin/Debug/test_project.exe
[debug]Working dir : C:\test_project

Starting debugger: C:\cygwin64\bin\gdb.exe -nx -fullname  -quiet  -args C:/test_project/bin/Debug/test_project.exe
done
....

You are still using cygwin GDB 64 bit, right? see "Starting debugger: C:\cygwin64\bin\gdb.exe".


Please see my previous posts, there I think you can have a workaround, C::B already have mechanisms to translate the cygdrive style drive to normal windows path.
If some piece of memory should be reused, turn them to variables (or const variables).
If some piece of operations should be reused, turn them to functions.
If they happened together, then turn them to classes.

Offline venom4u31

  • Multiple posting newcomer
  • *
  • Posts: 19
Re: Cygwin with CodeBlocks gdb error
« Reply #13 on: December 10, 2013, 08:51:48 am »
Yes, I did install the 64-bit Cygwin. However, when I add them to C::B, and try to use the MinGW compiler it produces that output (it fails to read the file). After I removed it it works just fine, even though I didn't modify anything to the MinGW compiler/debugger settings.

Ok, I'll re-add the compiler and debugger to C::B and try your suggestions. I'll let you know of the results.
« Last Edit: December 10, 2013, 09:01:08 am by venom4u31 »

Offline venom4u31

  • Multiple posting newcomer
  • *
  • Posts: 19
Re: Cygwin with CodeBlocks gdb error
« Reply #14 on: December 10, 2013, 09:15:42 am »
Ok, I tried your solution and created a registry entry as described on this page: http://forums.codeblocks.org/index.php/topic,13791.msg92903.html and this is the output I received when I retried debugging the program (the compiler and debugger have the exact settings restored, including the set filename-display relative initialisation command and the Use full path for source files(GDB workaround) checkbox)

Code
Building to ensure sources are up-to-date
Selecting target:
Debug
Adding source dir: C:\test_project\
Adding source dir: C:\test_project\
Adding file: C:\test_project\bin\Debug\test_project.exe
Changing directory to: C:/test_project/.
Set variable: PATH=.;C:\cygwin64\bin;C:\cygwin64;C:\Program Files (x86)\CodeBlocks\MinGW\bin;C:\Program Files (x86)\CodeBlocks\MinGW;C:\Program Files\Common Files\Microsoft Shared\Windows Live

[debug]Command-line: C:\cygwin64\bin\gdb.exe -nx -fullname  -quiet  -args C:/test_project/bin/Debug/test_project.exe
[debug]Working dir : C:\test_project

Starting debugger: C:\cygwin64\bin\gdb.exe -nx -fullname  -quiet  -args C:/test_project/bin/Debug/test_project.exe
done

[debug]> set prompt >>>>>>cb_gdb:

Registered new type: wxString
Registered new type: STL String
Registered new type: STL Vector
Setting breakpoints

[debug]Reading symbols from /cygdrive/c/test_project/bin/Debug/test_project.exe...done.
[debug](gdb) >>>>>>cb_gdb:
[debug]> show version
[debug]GNU gdb (GDB) 7.6.50.20130728-cvs (cygwin-special)
[debug]Copyright (C) 2013 Free Software Foundation, Inc.
[debug]License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
[debug]This is free software: you are free to change and redistribute it.
[debug]There is NO WARRANTY, to the extent permitted by law.  Type "show copying"
[debug]and "show warranty" for details.
[debug]This GDB was configured as "x86_64-pc-cygwin".
[debug]Type "show configuration" for configuration details.
[debug]For bug reporting instructions, please see:
[debug]<http://www.gnu.org/software/gdb/bugs/>.
[debug]Find the GDB manual and other documentation resources online at:
[debug]<http://www.gnu.org/software/gdb/documentation/>.
[debug]For help, type "help".
[debug]Type "apropos word" to search for commands related to "word".
[debug]>>>>>>cb_gdb:
[debug]> set confirm off

Debugger name and version: GNU gdb (GDB) 7.6.50.20130728-cvs (cygwin-special)

[debug]>>>>>>cb_gdb:
[debug]> set width 0
[debug]>>>>>>cb_gdb:
[debug]> set height 0
[debug]>>>>>>cb_gdb:
[debug]> set breakpoint pending on
[debug]>>>>>>cb_gdb:
[debug]> set print asm-demangle on
[debug]>>>>>>cb_gdb:
[debug]> set unwindonsignal on
[debug]>>>>>>cb_gdb:
[debug]> set print elements 0
[debug]>>>>>>cb_gdb:
[debug]> set new-console on
[debug]>>>>>>cb_gdb:
[debug]> set disassembly-flavor att
[debug]>>>>>>cb_gdb:
[debug]> catch throw
[debug]Catchpoint 1 (throw)
[debug]>>>>>>cb_gdb:
[debug]> source C:\Program Files (x86)\CodeBlocks\share\codeblocks/scripts/stl-views-1.0.3.gdb
[debug]>>>>>>cb_gdb:
[debug]> set filename-display relative
[debug]>>>>>>cb_gdb:
[debug]> directory C:/test_project/
[debug]Source directories searched: /cygdrive/c/test_project/C:/test_project:$cdir:$cwd
[debug]>>>>>>cb_gdb:
[debug]> break "C:/test_project/main.c:6"
[debug]Breakpoint 2 at 0x1004010dd: file main.c, line 6.
[debug]>>>>>>cb_gdb:
[debug]> run
[debug]Starting program: /cygdrive/c/test_project/bin/Debug/test_project.exe

Child process PID: 132

[debug][New Thread 132.0x88c]
[debug][New Thread 132.0x1808]
[debug]Breakpoint 2, main () at main.c:6
[debug]/cygdrive/c/test_project/main.c:6:58:beg:0x1004010dd
[debug]>>>>>>cb_gdb:

Cannot open file: /cygdrive/c/test_project/main.c
At /cygdrive/c/test_project/main.c:6

Offline ollydbg

  • Developer
  • Lives here!
  • *****
  • Posts: 6077
  • OpenCV and Robotics
    • Chinese OpenCV forum moderator
Re: Cygwin with CodeBlocks gdb error
« Reply #15 on: December 10, 2013, 09:36:06 am »
Ok, I tried your solution and created a registry entry as described on this page: http://forums.codeblocks.org/index.php/topic,13791.msg92903.html
Yes, the above link shows a work around, the author said that the debugging works OK with his change to Windows registry.

Quote
and this is the output I received when I retried debugging the program (the compiler and debugger have the exact settings restored, including the set filename-display relative initialisation command and the Use full path for source files(GDB workaround) checkbox)
Yes, you can leave these two settings to their default value.

Quote
Code
Building to ensure sources are up-to-date
Selecting target:
Debug
Adding source dir: C:\test_project\
Adding source dir: C:\test_project\
Adding file: C:\test_project\bin\Debug\test_project.exe
Changing directory to: C:/test_project/.
Set variable: PATH=.;C:\cygwin64\bin;C:\cygwin64;C:\Program Files (x86)\CodeBlocks\MinGW\bin;C:\Program Files (x86)\CodeBlocks\MinGW;C:\Program Files\Common Files\Microsoft Shared\Windows Live

[debug]Command-line: C:\cygwin64\bin\gdb.exe -nx -fullname  -quiet  -args C:/test_project/bin/Debug/test_project.exe
[debug]Working dir : C:\test_project

Starting debugger: C:\cygwin64\bin\gdb.exe -nx -fullname  -quiet  -args C:/test_project/bin/Debug/test_project.exe
done

[debug]> set prompt >>>>>>cb_gdb:

Registered new type: wxString
Registered new type: STL String
Registered new type: STL Vector
Setting breakpoints

[debug]Reading symbols from /cygdrive/c/test_project/bin/Debug/test_project.exe...done.
[debug](gdb) >>>>>>cb_gdb:
[debug]> show version
[debug]GNU gdb (GDB) 7.6.50.20130728-cvs (cygwin-special)
[debug]Copyright (C) 2013 Free Software Foundation, Inc.
[debug]License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
[debug]This is free software: you are free to change and redistribute it.
[debug]There is NO WARRANTY, to the extent permitted by law.  Type "show copying"
[debug]and "show warranty" for details.
[debug]This GDB was configured as "x86_64-pc-cygwin".
[debug]Type "show configuration" for configuration details.
[debug]For bug reporting instructions, please see:
[debug]<http://www.gnu.org/software/gdb/bugs/>.
[debug]Find the GDB manual and other documentation resources online at:
[debug]<http://www.gnu.org/software/gdb/documentation/>.
[debug]For help, type "help".
[debug]Type "apropos word" to search for commands related to "word".
[debug]>>>>>>cb_gdb:
[debug]> set confirm off

Debugger name and version: GNU gdb (GDB) 7.6.50.20130728-cvs (cygwin-special)

[debug]>>>>>>cb_gdb:
[debug]> set width 0
[debug]>>>>>>cb_gdb:
[debug]> set height 0
[debug]>>>>>>cb_gdb:
[debug]> set breakpoint pending on
[debug]>>>>>>cb_gdb:
[debug]> set print asm-demangle on
[debug]>>>>>>cb_gdb:
[debug]> set unwindonsignal on
[debug]>>>>>>cb_gdb:
[debug]> set print elements 0
[debug]>>>>>>cb_gdb:
[debug]> set new-console on
[debug]>>>>>>cb_gdb:
[debug]> set disassembly-flavor att
[debug]>>>>>>cb_gdb:
[debug]> catch throw
[debug]Catchpoint 1 (throw)
[debug]>>>>>>cb_gdb:
[debug]> source C:\Program Files (x86)\CodeBlocks\share\codeblocks/scripts/stl-views-1.0.3.gdb
[debug]>>>>>>cb_gdb:
[debug]> set filename-display relative
[debug]>>>>>>cb_gdb:
[debug]> directory C:/test_project/
[debug]Source directories searched: /cygdrive/c/test_project/C:/test_project:$cdir:$cwd
[debug]>>>>>>cb_gdb:
[debug]> break "C:/test_project/main.c:6"
[debug]Breakpoint 2 at 0x1004010dd: file main.c, line 6.
[debug]>>>>>>cb_gdb:
[debug]> run
[debug]Starting program: /cygdrive/c/test_project/bin/Debug/test_project.exe

Child process PID: 132

[debug][New Thread 132.0x88c]
[debug][New Thread 132.0x1808]
[debug]Breakpoint 2, main () at main.c:6
[debug]/cygdrive/c/test_project/main.c:6:58:beg:0x1004010dd
[debug]>>>>>>cb_gdb:

Cannot open file: /cygdrive/c/test_project/main.c
At /cygdrive/c/test_project/main.c:6

OK, it looks like the GDB_driver::DetectCygwinMount functions does not works Ok in your case. Read the function source, it looks like there are some regestries in HKEY_CURRENT_USER? Can you try again?

I don't have more ways now, also I think the simplest way is to add an option (translate the cygdrive) in debugger setting dialog of C::B.


If some piece of memory should be reused, turn them to variables (or const variables).
If some piece of operations should be reused, turn them to functions.
If they happened together, then turn them to classes.

Offline ollydbg

  • Developer
  • Lives here!
  • *****
  • Posts: 6077
  • OpenCV and Robotics
    • Chinese OpenCV forum moderator
Re: Cygwin with CodeBlocks gdb error
« Reply #16 on: December 10, 2013, 09:55:47 am »
For the record, currently, the GDB debugger plugin use an old GDB interface called annotated interface, see http://www.sourceware.org/gdb/onlinedocs/annotate.html

Here, the full(absolute path) is always used:

Quote
13 Displaying Source

The following annotation is used instead of displaying source code:

     ^Z^Zsource filename:line:character:middle:addr

where filename is an absolute file name indicating which source file, line is the line number within that file (where 1 is the first line in the file), character is the character position within the file (where 0 is the first character in the file) (for most debug formats this will necessarily point to the beginning of a line), middle is ‘middle’ if addr is in the middle of the line, or ‘beg’ if addr is at the beginning of the line, and addr is the address in the target program associated with the source which is being displayed. addr is in the form ‘0x’ followed by one or more lowercase hex digits (note that this does not depend on the language).

So, I'm wondering there is an options to change this.... Can't find one.

The debugger plugin for GDB-MI mode is still under development, so I think we still need a solution currently.

If some piece of memory should be reused, turn them to variables (or const variables).
If some piece of operations should be reused, turn them to functions.
If they happened together, then turn them to classes.

Offline venom4u31

  • Multiple posting newcomer
  • *
  • Posts: 19
Re: Cygwin with CodeBlocks gdb error
« Reply #17 on: December 10, 2013, 10:02:08 am »
Wow, your suggestion absolutely worked.

For the record, to solve this problem I have created two registers under

HKEY_CURRENT_USER\\Software\\Cygnus Solutions\\Cygwin\\mounts v2

HKEY_LOCAL_MACHINE\\Software\\Cygnus Solutions\\Cygwin\\mounts v2

(the folders were manually created)

with the name cygdrive prefix
and the value /cygdrive

That's it. It worked.

However, the problem with the MinGW debugger has persisted. Apparently it's fixed if I just remove the Cygwin compiler and debugger settings from C::B, so it's not such a big problem.

Thank you so much for the support. You have been a huge help.

Offline ollydbg

  • Developer
  • Lives here!
  • *****
  • Posts: 6077
  • OpenCV and Robotics
    • Chinese OpenCV forum moderator
Re: Cygwin with CodeBlocks gdb error
« Reply #18 on: December 10, 2013, 10:08:12 am »
Wow, your suggestion absolutely worked.

For the record, to solve this problem I have created two registers under

HKEY_CURRENT_USER\\Software\\Cygnus Solutions\\Cygwin\\mounts v2

HKEY_LOCAL_MACHINE\\Software\\Cygnus Solutions\\Cygwin\\mounts v2

(the folders were manually created)

with the name cygdrive prefix
and the value /cygdrive

That's it. It worked.

Nice to hear!!

Quote
However, the problem with the MinGW debugger has persisted. Apparently it's fixed if I just remove the Cygwin compiler and debugger settings from C::B, so it's not such a big problem.
In-fact, I don't understand this problem, what's exactly the MinGW GDB problem??

I just see you have a problem when you try use GDB.exe(64bit, cygwin) to debug a program(build from GCC 64bit, cygwin), and now this problem is solved.

Basically, you should use a MinGW GDB to debug the application build from MinGW GCC compiler, never mixed the different type of GDB and GCC. (unless you are using cross building)

Quote
Thank you so much for the support. You have been a huge help.
You are welcome, hope you will enjoy the Free/Open Source C::B IDE.
If some piece of memory should be reused, turn them to variables (or const variables).
If some piece of operations should be reused, turn them to functions.
If they happened together, then turn them to classes.

Offline venom4u31

  • Multiple posting newcomer
  • *
  • Posts: 19
Re: Cygwin with CodeBlocks gdb error
« Reply #19 on: December 10, 2013, 10:18:16 am »
Quote
In-fact, I don't understand this problem, what's exactly the MinGW GDB problem??
Well, the problem is the one I mentioned in http://forums.codeblocks.org/index.php/topic,18663.msg127883.html#msg127883
The output is when I try to debug any program that uses the MinGW debugger.
The debugger seems to be stuck. I can't figure out why. This only happens if I have the Cygwin debug configuration in the Settings->Debugger window (asside the default one). After I delete it it works fine.

I have no idea of why this would happen.
« Last Edit: December 10, 2013, 10:20:07 am by venom4u31 »

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 13406
    • Travis build status
Re: Cygwin with CodeBlocks gdb error
« Reply #20 on: December 10, 2013, 10:37:09 am »
venom4u31: Can you tell me what are the new default regkeys that C::B should look for, instead of the old ones that you've added manually?
(most of the time I ignore long posts)
[strangers don't send me private messages, I'll ignore them; post a topic in the forum, but first read the rules!]

Offline venom4u31

  • Multiple posting newcomer
  • *
  • Posts: 19
Re: Cygwin with CodeBlocks gdb error
« Reply #21 on: December 10, 2013, 10:50:19 am »
Well, the only registers I had when Cygwin was installed were the ones in

HKLM\SOFTWARE\Cygwin\

and

HKCU\Software\Cygwin

the HKCU Cygwin key had two keys called Program Options and Setup which were empty (they only contained the (Default) REG_SZ which was empty)

The HKLM Cygwin key had the following sub-keys:

Installations - which contained some registers regarding an .exe C program I ran with cmd which had cygwin1.dll copied there and also, the install path of Cygwin.
Program options - which was empty
setup - which had a registry called rootdir with the install path of Cygwin as its value.

Anything else related to cygwin was what I added (the mounts v2 key) or the PATH variable.

Therefore, I think that C::B should add the registry key automatically if it doesn't exist, since, at least by default the registry that has to be added has a known name and value (cygdrive prefix and /cygdrive).

You can add a setting that is enabled by default to create that registry.

Or, you can add the compiler presets for cygwin by default. Just ask the user for the install dir.
« Last Edit: December 10, 2013, 11:06:23 am by venom4u31 »