0
#include <iostream>
int main ()
{
  int* a = new int[15];
  a[0] = 42;
  a[1] = 43;
  std::cerr << a[0];

  return 0;
}

gdb says a = 0xffffffff and 'print a[0]' gives 'cannot access memory address' but why? If run outside of gdb, the program prints out '42' as expected. What is going on here? Compiled with 'g++ test2.cpp -gstabs+ -O0 -o test2'.

1
  • 2
    Are you sure you aren't trying to access a before new is invoked? Commented May 2, 2011 at 21:20

2 Answers 2

1

Which platform are you are on? The gstabs+ debugger format is not universally supported, if you want to use it you must acquaint yourself with the fascinating differences between COFF, DWARF 2 and probably some other exe/debug formats I've never heard of. Bottom line - read the gdb manual. But your code will almost certainly work correctly if you simply use the -g flag.

Sign up to request clarification or add additional context in comments.

1 Comment

I started using stabs+ years ago when I was having problems with debugging a c++ program. I tried all the formats and stabs+ was the only one that worked correctly at the time. I have stuck with it ever since, and this is the first problem I've had with it.
0

Yep I can reproduce that, but only with -gstabs+

So: why are you using -gstabs+?

It doesn't sound fair, but it is an honest question, what advantage does stabs+ bring over 'normal' debug info?

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.