Author Topic: Debugger Does Not Stop At Breakpoint  (Read 3819 times)

yaxollum

  • Guest
Debugger Does Not Stop At Breakpoint
« on: December 30, 2018, 07:13:27 pm »
I wrote this short program and put it into a codeblocks project:
Code
#include <iostream>

using namespace std;

int main()
{
    char c;
    cin>>c;
    cout<<c;
}
I added a breakpoint to line 7, rebuilt the project, and clicked debug. The debugger started and skipped over the breakpoint, automatically quitting.

I am running codeblocks 17.12. In compiler options [-g] is enabled and [-s] is disabled

Here is the Debug log:
Code
Active debugger config: GDB/CDB debugger:Default
Building to ensure sources are up-to-date
Selecting target:
Debug
Adding source dir: /home/yaxollum/yax/cpp/proj/
Adding source dir: /home/yaxollum/yax/cpp/proj/
Adding file: /home/yaxollum/yax/cpp/proj/bin/Debug/proj
Changing directory to: /home/yaxollum/yax/cpp/proj/.
Set variable: LD_LIBRARY_PATH=.:

[debug]Command-line: /usr/bin/gdb -nx -fullname -quiet  -args /home/yaxollum/yax/cpp/proj/bin/Debug/proj
[debug]Working dir : /home/yaxollum/yax/cpp/proj

Starting debugger: /usr/bin/gdb -nx -fullname -quiet  -args /home/yaxollum/yax/cpp/proj/bin/Debug/proj
done

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

Setting breakpoints

[debug]Reading symbols from /home/yaxollum/yax/cpp/proj/bin/Debug/proj...
[debug]Using terminal's PID as console PID 16553, TTY /dev/tty2
[debug]Queued:[tty /dev/tty2]
[debug]done.
[debug](gdb) >>>>>>cb_gdb:
[debug]> show version
[debug]GNU gdb (Ubuntu 8.1-0ubuntu3) 8.1.0.20180409-git
[debug]Copyright (C) 2018 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-linux-gnu".
[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 (Ubuntu 8.1-0ubuntu3) 8.1.0.20180409-git

[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 200
[debug]>>>>>>cb_gdb:
[debug]> set disassembly-flavor intel
[debug]>>>>>>cb_gdb:
[debug]> catch throw
[debug]Catchpoint 1 (throw)
[debug]>>>>>>cb_gdb:
[debug]> directory /home/yaxollum/yax/cpp/proj/
[debug]Source directories searched: /home/yaxollum/yax/cpp/proj:$cdir:$cwd
[debug]>>>>>>cb_gdb:
[debug]> break "/home/yaxollum/yax/cpp/proj/hello.cpp:7"
[debug]Breakpoint 2 at 0x941: file /home/yaxollum/yax/cpp/proj/hello.cpp, line 7.
[debug]>>>>>>cb_gdb:
[debug]> tty /dev/tty2
[debug]>>>>>>cb_gdb:
[debug]> run
[debug]Starting program: /home/yaxollum/yax/cpp/proj/bin/Debug/proj
[debug]Breakpoint 2, main () at /home/yaxollum/yax/cpp/proj/hello.cpp:8
[debug]/home/yaxollum/yax/cpp/proj/hello.cpp:8:68:beg:0x555555554941
[debug]>>>>>>cb_gdb:
[debug]> quit

Debugger finished with status 0


Offline BlueHazzard

  • Developer
  • Lives here!
  • *****
  • Posts: 3352
Re: Debugger Does Not Stop At Breakpoint
« Reply #1 on: December 30, 2018, 07:48:37 pm »
Line 7 is a variable declaration. This is optimized out by the compiler (also if you do not use the -s flag. What should the program do at line 7 to give the debugger a halt point? A variable declaration is simply a reservation in memory and does not require a cpu instruction, where the debugger can halt) Put the break point in line 8 and the debugger will stop.

Note that other ides do not allow to set a breakpoint at this line, because it is not possible to break here. Codeblocks does not have this advanced logik yet...

[edit:] a other thing would be if you write:
Code
char c = someFunction();
Here the processor makes a jump and the debugger can stop at this instruction.
I am not sure, but i think even this is optimized out:
Code
char c = 0xAA;
because this could be done during initialization of the program memory

PS.: thank you for providing some logs in the question. Some additional useful log would be the build log (but not needed, because the question is answered ;) )
« Last Edit: December 30, 2018, 07:51:31 pm by BlueHazzard »