Drew
Drew

Reputation: 1777

GDB not breaking on breakpoints set on object creation in C++

I've got a c++ app, with the following main.cpp:

1:  #include <stdio.h>
2:  #include "HeatMap.h"
3:  #include <iostream>
4:
5:  int main (int argc, char * const argv[])
6:  {
7:    HeatMap heatMap();
8:    printf("message");
9:    return 0;
10: }

Everything compiles without errors, I'm using gdb (GNU gdb 6.3.50-20050815 (Apple version gdb-1346) (Fri Sep 18 20:40:51 UTC 2009)), and compiled the app with gcc (gcc version 4.2.1 (Apple Inc. build 5646) (dot 1)) with the commands "-c -g".

When I add breakpoints to lines 7, 8, and 9, and run gdb, I get the following...

(gdb) break main.cpp:7
Breakpoint 1 at 0x10000177f: file src/main.cpp, line 8.
(gdb) break main.cpp:8
Note: breakpoint 1 also set at pc 0x10000177f.
Breakpoint 2 at 0x10000177f: file src/main.cpp, line 8.
(gdb) break main.cpp:9
Breakpoint 3 at 0x100001790: file src/main.cpp, line 9.
(gdb) run
Starting program: /DevProjects/DataManager/build/DataManager 
Reading symbols for shared libraries ++. done

Breakpoint 1, main (argc=1, argv=0x7fff5fbff960) at src/main.cpp:8
8       printf("message");
(gdb) 

So, why of why, does anyone know, why my app does not break on the breakpoints for the object creation, but does break on the printf line?

Drew J. Sonne.

EDIT: Answer - GDB skips over my code!

Upvotes: 2

Views: 764

Answers (1)

WhirlWind
WhirlWind

Reputation: 14112

You need to instantiate HeatMap as:

HeatMap heatMap;

HeatMap heatMap(); declares a function that returns HeatMap.

Upvotes: 5

Related Questions