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


  • 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: [Select]
#include <iostream>

using namespace std;

int main()
    char 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: [Select]
Active debugger config: GDB/CDB debugger:Default
Building to ensure sources are up-to-date
Selecting target:
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

[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](gdb) >>>>>>cb_gdb:
[debug]> show version
[debug]GNU gdb (Ubuntu 8.1-0ubuntu3)
[debug]Copyright (C) 2018 Free Software Foundation, Inc.
[debug]License GPLv3+: GNU GPL version 3 or later <>
[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]Find the GDB manual and other documentation resources online at:
[debug]For help, type "help".
[debug]Type "apropos word" to search for commands related to "word".
[debug]> set confirm off

Debugger name and version: GNU gdb (Ubuntu 8.1-0ubuntu3)

[debug]> set width 0
[debug]> set height 0
[debug]> set breakpoint pending on
[debug]> set print asm-demangle on
[debug]> set unwindonsignal on
[debug]> set print elements 200
[debug]> set disassembly-flavor intel
[debug]> catch throw
[debug]Catchpoint 1 (throw)
[debug]> directory /home/yaxollum/yax/cpp/proj/
[debug]Source directories searched: /home/yaxollum/yax/cpp/proj:$cdir:$cwd
[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]> tty /dev/tty2
[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]> quit

Debugger finished with status 0

Offline BlueHazzard

  • Developer
  • Lives here!
  • *****
  • Posts: 2850
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: [Select]
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: [Select]
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 »