简体   繁体   中英

gdb reports wrong values in simple program. Why?

#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'.

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.

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?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM