4

I wrote a simple test.cc as follows:

#include <iostream>
using namespace std;

int main()
{
  cout << "Hello world" << endl;
  return 0;
}

And I compiled with:

g++ -g test.cc -o test.o

I ran gdb and put a breakpoint at the "Hello world" line:

$ gdb test.o
(gdb) b 7
(gdb) c

Then gdb stops at the "Hello world" line, but when I run

(gdb) s

It fails to step into the cout function. So my question is, how can I step into the cout function?

Ciro Santilli OurBigBook.com
  • 347,512
  • 102
  • 1,199
  • 985
stackunderflow
  • 877
  • 4
  • 13
  • 28

2 Answers2

6

If it wasn't linked against a version of the standard library with debugging information, it doesn't know how to step into the library; it can only step over it (that is, run until control returns to the code with the debugging information).

Consult the documentation for your system to find out how to install the debug version of the standard C and C++ libraries.

geekosaur
  • 59,309
  • 11
  • 123
  • 114
  • yes, your answer is quite what I was expecting. Step into cout need something additional information. – stackunderflow Apr 16 '12 at 00:54
  • The above question is not my real point. In my another program, I tried to step into a function (not standard C/C++ libraries) in another file. But it fails and said ".gdbinit: No such file or directory. ", "Stopped due to shared library event", "Cannot access memory at address 0x1". Do you know what the problem might be? – stackunderflow Apr 16 '12 at 00:57
  • You might have done better asking that to begin with. It sounds confused, but there isn't enough information to determine why — do you have a more concrete example where this failure occurs? (Also, include platform. OS X's `gdb` has some known bugs, for example.) – geekosaur Apr 16 '12 at 01:02
1

Without the debugging information it's still possible to debug it, just a whole lot more painful. See here.

If like me, you just want to break on other calls to the same function without digging any deeper, it's not too difficult to set a breakpoint on the function address obtained from the disassembly with disas.

Community
  • 1
  • 1
jozxyqk
  • 16,424
  • 12
  • 91
  • 180