Author Topic: Problem with debugging  (Read 31305 times)

Offline Piotrek_16

  • Single posting newcomer
  • *
  • Posts: 6
Problem with debugging
« on: June 30, 2013, 01:42:27 pm »
Hi.
I want to debug this part of code and i have problem with it.
https://imageshack.com/scaled/large/713/otp2.jpg
When I try to debug and press F7 few times, debugger stops.
Here you have debugger logs:
https://imageshack.com/scaled/large/812/5tpl.jpg
If I try to stop debbuger (Shift-F8) I obtain message: Trying to pause the running process...
And It doesn't stop!
There is not a problem with integer value or even with float. There is a problem with double, long e.g.
Please help.
I have C::B 12.11 with minGW
« Last Edit: June 30, 2013, 01:48:20 pm by Piotrek_16 »

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 13413
    • Travis build status
Re: Problem with debugging
« Reply #1 on: June 30, 2013, 01:50:00 pm »
1. enable full logging (see settings -> debugger),
2. then try to debug again
3. then copy-paste the full log using code tags (use the '#' button in the new post interface of the forum)

Have you used the callstack/backtrace window?
Probably gdb is executing step-into instead of next-line, because either you have optimizations enabled or some inlining has happened.
(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 Piotrek_16

  • Single posting newcomer
  • *
  • Posts: 6
Re: Problem with debugging
« Reply #2 on: June 30, 2013, 02:01:59 pm »
Code
Building to ensure sources are up-to-date
Selecting target:
Debug
Adding source dir: C:\Users\Piotrek\Documents\CodeBlocksWorkspace\NewProject\
Adding source dir: C:\Users\Piotrek\Documents\CodeBlocksWorkspace\NewProject\
Adding file: C:\Users\Piotrek\Documents\CodeBlocksWorkspace\NewProject\bin\Debug\NewProject.exe
Changing directory to: C:/Users/Piotrek/Documents/CodeBlocksWorkspace/NewProject/.
Set variable: PATH=.;C:\CodeBlocks\MinGW\bin;C:\CodeBlocks\MinGW;C:\Program Files (x86)\NVIDIA Corporation\PhysX\Common;C:\Windows\System32;C:\Windows;C:\Windows\System32\wbem;C:\Windows\System32\WindowsPowerShell\v1.0;C:\Program Files\Microsoft SQL Server\110\Tools\Binn;C:\Program Files\MATLAB\R2013a\runtime\win64;C:\Program Files\MATLAB\R2013a\bin;C:\Program Files\Microsoft\Web Platform Installer;C:\Program Files (x86)\Microsoft ASP.NET\ASP.NET Web Pages\v1.0;C:\Program Files (x86)\Windows Kits\8.0\Windows Performance Toolkit

[debug]Command-line: C:\CodeBlocks\MinGW\bin\gdb.exe -nx -fullname  -quiet  -args C:/Users/Piotrek/Documents/CodeBlocksWorkspace/NewProject/bin/Debug/NewProject.exe
[debug]Working dir : C:\Users\Piotrek\Documents\CodeBlocksWorkspace\NewProject

Starting debugger: C:\CodeBlocks\MinGW\bin\gdb.exe -nx -fullname  -quiet  -args C:/Users/Piotrek/Documents/CodeBlocksWorkspace/NewProject/bin/Debug/NewProject.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 C:\Users\Piotrek\Documents\CodeBlocksWorkspace\NewProject\bin\Debug\NewProject.exe...done.
[debug](gdb) >>>>>>cb_gdb:
[debug]> show version
[debug]GNU gdb (GDB) 7.5
[debug]Copyright (C) 2012 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 "i686-pc-mingw32".
[debug]For bug reporting instructions, please see:
[debug]<http://www.gnu.org/software/gdb/bugs/>.
[debug]>>>>>>cb_gdb:
[debug]> set confirm off

Debugger name and version: GNU gdb (GDB) 7.5

[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:\CodeBlocks\share\codeblocks/scripts/stl-views-1.0.3.gdb
[debug]>>>>>>cb_gdb:
[debug]> directory C:/Users/Piotrek/Documents/CodeBlocksWorkspace/NewProject/
[debug]Source directories searched: C:/Users/Piotrek/Documents/CodeBlocksWorkspace/NewProject;$cdir;$cwd
[debug]>>>>>>cb_gdb:
[debug]> break "C:/Users/Piotrek/Documents/CodeBlocksWorkspace/NewProject/main.cpp:8"
[debug]Breakpoint 2 at 0x40135a: file C:\Users\Piotrek\Documents\CodeBlocksWorkspace\NewProject\main.cpp, line 8.
[debug]>>>>>>cb_gdb:
[debug]> run
[debug]Starting program: C:\Users\Piotrek\Documents\CodeBlocksWorkspace\NewProject\bin\Debug\NewProject.exe

Child process PID: 7872

[debug][New Thread 7872.0x1258]
[debug]Breakpoint 2, main () at C:\Users\Piotrek\Documents\CodeBlocksWorkspace\NewProject\main.cpp:8
[debug]C:\Users\Piotrek\Documents\CodeBlocksWorkspace\NewProject\main.cpp:8:88:beg:0x40135a
[debug]>>>>>>cb_gdb:

At C:\Users\Piotrek\Documents\CodeBlocksWorkspace\NewProject\main.cpp:8

[debug]> next
[debug]0x004496c4 in std::ostream::operator<<(double) ()
[debug]>>>>>>cb_gdb:

In std::ostream::operator<<(double) () ()

[debug]> bt 30
[debug]#0  0x004496c4 in std::ostream::operator<<(double) ()
[debug]#1  0x758d1162 in onexit () from C:\Windows\syswow64\msvcrt.dll
[debug]#2  0x75925bc4 in msvcrt!atexit () from C:\Windows\syswow64\msvcrt.dll
[debug]Backtrace stopped: previous frame inner to this frame (corrupt stack?)
[debug]>>>>>>cb_gdb:
[debug]> next
[debug]Single stepping until exit from function _ZNSolsEd,
[debug]which has no line number information.
[debug]0x00448018 in std::ostream& std::ostream::_M_insert<double>(double) ()
[debug]>>>>>>cb_gdb:

In std::ostream& std::ostream::_M_insert<double>(double) () ()

[debug]> bt 30
[debug]#0  0x00448018 in std::ostream& std::ostream::_M_insert<double>(double) ()
[debug]#1  0x00401371 in main () at C:\Users\Piotrek\Documents\CodeBlocksWorkspace\NewProject\main.cpp:8
[debug]>>>>>>cb_gdb:
[debug]> frame 1
[debug]#1  0x00401371 in main () at C:\Users\Piotrek\Documents\CodeBlocksWorkspace\NewProject\main.cpp:8
[debug]C:\Users\Piotrek\Documents\CodeBlocksWorkspace\NewProject\main.cpp:8:88:beg:0x401371
[debug]>>>>>>cb_gdb:

#1  0x00401371 in main () at C:\Users\Piotrek\Documents\CodeBlocksWorkspace\NewProject\main.cpp:8
C:\Users\Piotrek\Documents\CodeBlocksWorkspace\NewProject\main.cpp:8:88:beg:0x401371
At C:\Users\Piotrek\Documents\CodeBlocksWorkspace\NewProject\main.cpp:8

[debug]> next
[debug]127 ../../../../src/gcc-4.7.1/libgcc/unwind-sjlj.c: No such file or directory.
[debug]Single stepping until exit from function _ZNSo9_M_insertIdEERSoT_,
[debug]which has no line number information.
[debug]_Unwind_SjLj_Register (fc=0x28fe8c) at ../../../../src/gcc-4.7.1/libgcc/unwind-sjlj.c:127
[debug]>>>>>>cb_gdb:
I used only Watches window.
I have this from Callstack window: std::ostream& std::ostream::_M_insert<double>(double) () (??:??)
I don't know what is backtrace window?!
I've installed C::B on my PC yesterday and I was trying to test this IDE and I obtained this problem.
« Last Edit: June 30, 2013, 02:04:55 pm by Piotrek_16 »

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 13413
    • Travis build status
Re: Problem with debugging
« Reply #3 on: June 30, 2013, 04:30:31 pm »
Do you have optimizations enabled in your target options?

For me this is a problem of gdb/mingw you have installed, not in C::B.
Can you try to use gdb from the command line to see if the problem happens there, too?
(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 Piotrek_16

  • Single posting newcomer
  • *
  • Posts: 6
Re: Problem with debugging
« Reply #4 on: June 30, 2013, 06:05:58 pm »
Do you have optimizations enabled in your target options?
Can you try to use gdb from the command line to see if the problem happens there, too?
As I mentioned I'm newbie :) Can you tell me what exactly I have to do? I didn't change anything except c++11 option, I set it on in project -> build options.
Where can I find target options?
From the command line I used command
Code
c++ main.cpp -o file
I obtain executable file which worked.

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 13413
    • Travis build status
Re: Problem with debugging
« Reply #5 on: June 30, 2013, 06:16:25 pm »
Where can I find target options?
Project -> Build options -> Your target in the tree

From the command line I used command
Code
c++ main.cpp -o file
I obtain executable file which worked.
This is not related to the debugger. The debugger is gdb. Search for a command line tutorial.

Also make sure you've setup your project correctly.
See here for details: http://wiki.codeblocks.org/index.php?title=Debugging_with_Code::Blocks
(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 Piotrek_16

  • Single posting newcomer
  • *
  • Posts: 6
Re: Problem with debugging
« Reply #6 on: June 30, 2013, 07:00:58 pm »
Code
Microsoft Windows [Wersja 6.1.7601]
Copyright (c) 2009 Microsoft Corporation. Wszelkie prawa zastrzeżone.

C:\Users\Piotrek>cd ..

C:\Users>cd ..

C:\>cd CodeBlocks

C:\CodeBlocks>cd MinGW

C:\CodeBlocks\MinGW>cd bin

C:\CodeBlocks\MinGW\bin>gdb
GNU gdb (GDB) 7.5
Copyright (C) 2012 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.  Type "show copying"
and "show warranty" for details.
This GDB was configured as "i686-pc-mingw32".
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>.
(gdb) file plik
Reading symbols from C:\CodeBlocks\MinGW\bin\plik.exe...done.
(gdb) break main
Breakpoint 1 at 0x401342
(gdb) run > outfile.txt
Starting program: C:\CodeBlocks\MinGW\bin\plik.exe > outfile.txt
[New Thread 1664.0x1eec]

Breakpoint 1, 0x00401342 in main ()
(gdb) next
Single stepping until exit from function main,
which has no line number information.
0x004496d4 in std::ostream::operator<<(double) ()
(gdb) next
Single stepping until exit from function _ZNSolsEd,
which has no line number information.
0x00448028 in std::ostream& std::ostream::_M_insert<double>(double) ()
(gdb) next
Single stepping until exit from function _ZNSo9_M_insertIdEERSoT_,
which has no line number information.
_Unwind_SjLj_Register (fc=0x28fe8c)
    at ../../../../src/gcc-4.7.1/libgcc/unwind-sjlj.c:127
127     ../../../../src/gcc-4.7.1/libgcc/unwind-sjlj.c: No such file or director
y.
(gdb) next
129     in ../../../../src/gcc-4.7.1/libgcc/unwind-sjlj.c
I have something like that.
Now I'm going to build options:
I have set on in Debug and Release:
- Produce debugging symbols [-g]
- Enable all compiler warnings [-Wall]
- Have g++ follow the C++11 ISO bla bla bla [-std=c++11]
Nothing more.

I will try on my laptop. If there will be the same issue I don't know what will should I do.
On laptop the same problem. So I don't know what's going on.
« Last Edit: July 03, 2013, 11:52:41 am by Piotrek_16 »

Offline ollydbg

  • Developer
  • Lives here!
  • *****
  • Posts: 5913
  • OpenCV and Robotics
    • Chinese OpenCV forum moderator
Re: Problem with debugging
« Reply #7 on: July 03, 2013, 02:10:37 am »
Code
...
(gdb) file plik
Reading symbols from C:\CodeBlocks\MinGW\bin\plik.exe...done.
(gdb) break main
Breakpoint 1 at 0x401342
(gdb) run > outfile.txt
Starting program: C:\CodeBlocks\MinGW\bin\plik.exe > outfile.txt
[New Thread 1664.0x1eec]

Breakpoint 1, 0x00401342 in main ()
(gdb) next
Single stepping until exit from function main,
which has no line number information.
0x004496d4 in std::ostream::operator<<(double) ()
...
Looks like a GDB issue, isn't it? Try a newer GDB?

Quote
- Produce debugging symbols [-s]
Typo? should be -g.
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 Piotrek_16

  • Single posting newcomer
  • *
  • Posts: 6
Re: Problem with debugging
« Reply #8 on: July 03, 2013, 11:55:32 am »
Quote
Typo? should be -g.
Yeah. There should be -g. My fault.

I have gdb which is added to this codeblocks-12.11mingw-setup.exe  from codeblocks.org/download  so is it possible to be down?
 
Maybe someone of you can propose me from which source I have to download new gdb ? Any link ?
« Last Edit: July 03, 2013, 11:58:47 am by Piotrek_16 »

Offline ollydbg

  • Developer
  • Lives here!
  • *****
  • Posts: 5913
  • OpenCV and Robotics
    • Chinese OpenCV forum moderator
« Last Edit: July 04, 2013, 05:19:31 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 Piotrek_16

  • Single posting newcomer
  • *
  • Posts: 6
Re: Problem with debugging
« Reply #10 on: July 04, 2013, 05:56:01 pm »
It doesn't work or I do something wrong.

Offline ollydbg

  • Developer
  • Lives here!
  • *****
  • Posts: 5913
  • OpenCV and Robotics
    • Chinese OpenCV forum moderator
Re: Problem with debugging
« Reply #11 on: July 10, 2013, 11:27:31 am »
It doesn't work or I do something wrong.
Then you can provide a minimal test code snippet, so I can build it on my PC and debug it to see whether I have the same issue.
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 G-Shadow

  • Multiple posting newcomer
  • *
  • Posts: 16
Re: Problem with debugging
« Reply #12 on: July 20, 2013, 12:04:10 am »
I have similar issue. Debugger hangs when I try to step or use breakpoints and no way to stop it except closing whole C::B or killing gdb process.
I wasted some time and found that problem appears when I using Linux line endings in the .cpp file (C::B is running under Windows).
If I convert .cpp to the Windows line endings, problem disappears.

Now I have a question, is I really have to use Windows line endings to debug under Windows, or there is some options could help me?
If I have to use Windows line endings, then how about Linux? Will debugger / gdb work fine with Windows line endings under the Linux?

PS: Don`t sure if it usefull, but my system is: Win8 x64, C::B 12.11 release, GNU gdb (GDB) 7.5 (installed with C::B). Also tried nightly C::B build.
« Last Edit: July 20, 2013, 12:07:55 am by G-Shadow »

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 13413
    • Travis build status
Re: Problem with debugging
« Reply #13 on: July 20, 2013, 12:36:34 am »
If I convert .cpp to the Windows line endings, problem disappears.
This is quite strange.
Please post the full log from the debugger in code tags.
(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 G-Shadow

  • Multiple posting newcomer
  • *
  • Posts: 16
Re: Problem with debugging
« Reply #14 on: July 20, 2013, 07:11:00 pm »
I`m sorry, looks like I was wrong, it is not Linux line endings. The problem is when CR (0x0D) line endings are used in source file. So, my question about Linux is meaningless. But may be topic starter still has same problem with CR line ends.

Code
Building to ensure sources are up-to-date
Selecting target:
Debug
Adding source dir: E:\DENIS\Projects\zzzzzzzzzzzz\
Adding source dir: E:\DENIS\Projects\zzzzzzzzzzzz\
Adding file: E:\DENIS\Projects\zzzzzzzzzzzz\bin\Debug\zzzzzzzzzzzz.exe
Changing directory to: E:/DENIS/Projects/zzzzzzzzzzzz/.
Set variable: PATH=.;C:\Program Files (x86)\CodeBlocks\MinGW\bin;C:\Program Files (x86)\CodeBlocks\MinGW;C:\Program Files (x86)\NVIDIA Corporation\PhysX\Common;C:\Windows\System32;C:\Windows;C:\Windows\System32\wbem;C:\Windows\System32\WindowsPowerShell\v1.0;C:\Program Files (x86)\Windows Kits\8.0\Windows Performance Toolkit;C:\Program Files\Microsoft SQL Server\110\Tools\Binn;C:\Resource\bin;C:\Program Files\TortoiseSVN\bin

[debug]Command-line: C:\Program Files (x86)\CodeBlocks\MinGW\bin\gdb.exe -nx -fullname  -quiet  -args E:/DENIS/Projects/zzzzzzzzzzzz/bin/Debug/zzzzzzzzzzzz.exe
[debug]Working dir : E:\DENIS\Projects\zzzzzzzzzzzz

Starting debugger: C:\Program Files (x86)\CodeBlocks\MinGW\bin\gdb.exe -nx -fullname  -quiet  -args E:/DENIS/Projects/zzzzzzzzzzzz/bin/Debug/zzzzzzzzzzzz.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 E:\DENIS\Projects\zzzzzzzzzzzz\bin\Debug\zzzzzzzzzzzz.exe...done.
[debug](gdb) >>>>>>cb_gdb:
[debug]> show version
[debug]GNU gdb (GDB) 7.5
[debug]Copyright (C) 2012 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 "i686-pc-mingw32".
[debug]For bug reporting instructions, please see:
[debug]<http://www.gnu.org/software/gdb/bugs/>.
[debug]>>>>>>cb_gdb:
[debug]> set confirm off

Debugger name and version: GNU gdb (GDB) 7.5

[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 E:/DENIS/Projects/zzzzzzzzzzzz/
[debug]Source directories searched: E:/DENIS/Projects/zzzzzzzzzzzz;$cdir;$cwd
[debug]>>>>>>cb_gdb:
[debug]> break "E:/DENIS/Projects/zzzzzzzzzzzz/main.cpp:7"
[debug]Breakpoint 2 at 0x40134a: file E:\DENIS\Projects\zzzzzzzzzzzz\main.cpp, line 7.
[debug]>>>>>>cb_gdb:
[debug]> run
[debug]Starting program: E:\DENIS\Projects\zzzzzzzzzzzz\bin\Debug\zzzzzzzzzzzz.exe

Child process PID: 732

[debug][New Thread 732.0x12c8]
[debug]Breakpoint 2, main () at E:\DENIS\Projects\zzzzzzzzzzzz\main.cpp:7
[debug]>>>>>>cb_gdb:

And in case of good source file, changes are only in those last lines:

Code
Child process PID: 4820

[debug][New Thread 4820.0xf70]
[debug]Breakpoint 2, main () at E:\DENIS\Projects\zzzzzzzzzzzz\main.cpp:7
[debug]E:\DENIS\Projects\zzzzzzzzzzzz\main.cpp:7:62:beg:0x40134a
[debug]>>>>>>cb_gdb:

At E:\DENIS\Projects\zzzzzzzzzzzz\main.cpp:7

So, added only one line "... main.cpp:7:62:beg:0x40134a", and successfull "at ...\main.cpp:7" in the end.