0

Here is a simple program:

#include <iostream>
#include <vector>

namespace Example
{

  template <int dim>
  class Problem
  {
  public:

    void run() {
        std::cout<<"here.."<<std::endl;
    }   
  };
}

int main(int argc, char *argv[])
{
  Example::Problem<2> problem;
  problem.run();
  return 0;
}

compiled with Macport's gcc 4.7.3:

g++-mp-4.7 -g -O0 prog.cc -o prog

If I try to debug in gdb 7.7 (self-compiled, not Macport's one!):

$gdb
file prog
b main
r
s

I can't step-in the function:

34    problem.run();
(gdb) s
here..
36    return 0;
(gdb)

Am i doing something wrong? Or does it look like a bug of gdb when used on os-x mavericks?

UPDATE:

I don't see any warning/errors when using gdb:

$ gdb ./prog
GNU gdb (GDB) 7.7
Copyright (C) 2014 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 "x86_64-apple-darwin13.1.0".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
<http://www.gnu.org/software/gdb/documentation/>.
For help, type "help".
Type "apropos word" to search for commands related to "word"...
Reading symbols from ./prog...Reading symbols from /Users/bla-bla-bla/prog.dSYM/Contents/Resources/DWARF/prog...done.
done.
(gdb)

also '-gdwarf-2 -gstrict-dwarf' do not change the behaviour....

UDAPTE2:

I see the same missing call-stack behaviour as here. Although I was not able to check if compiling with -m32 helps in my case, since I have everything for 64bit and thus get undefined symbols problems.

Another stepping problem while debugging is reported here and here on SO.

Community
  • 1
  • 1
Denis
  • 1,526
  • 6
  • 24
  • 40
  • You do know you have *undefined behavior* in your code? You create a vector containing five elements, but then you assign to the eleventh element. That means all bets are off. – Some programmer dude Mar 22 '14 at 18:22
  • @JoachimPileborg sure, it's just a stupid example, the point is not the code, but inability to step-in. – Denis Mar 22 '14 at 18:27
  • The point is, with undefined behavior you can't say what will happen. Like I said, all bets are off. Yes, it will probably not do anything in this specific case, but as long as you have undefined behavior you can't say anything about the behavior about the program or how the debugger will work or not work when running it. – Some programmer dude Mar 22 '14 at 18:35
  • @JoachimPileborg so you are saying that it is normal that I can't step-in the function and actually go line-by-line and debug?.. – Denis Mar 22 '14 at 18:38
  • @JoachimPileborg p.s. updated the question to avoid this discussion.... – Denis Mar 22 '14 at 18:41

1 Answers1

0

You need to add -gdwarf-2 option along with -g to debug using gdb for newer version of gcc.

g++-mp-4.7 -g -gdwarf-2 -O0 prog.cc -o prog

Mantosh Kumar
  • 5,659
  • 3
  • 24
  • 48
  • thanks for your suggestion, but this did not change the behaviour... :( – Denis Mar 22 '14 at 18:26
  • @Denis: It looks like there is some problem/bug on the gdb macport and you can find more information on the link: http://stackoverflow.com/a/11705195/2724703 – Mantosh Kumar Mar 22 '14 at 18:38
  • thanks for the link, i don't experience any GDB warning/errors, but it could easily be related... – Denis Mar 22 '14 at 18:51