I'm new to cygwin (and *nix for that matter) and don't understand the following gdb behavior.
I've created an executable that intentionally results in a SIGSEGV:
#include <iostream>
void Func(int i)
{
int* pFoo = NULL;
*pFoo = 1;
}
int main(int argc, char** argv)
{
Func(-50);
std::cout << "End of main()" << std::endl;
}
I compile my code by doing:
g++ test.cpp
Using this version of g++:
g++ –version
g++ (GCC) 5.4.0 Copyright (C) 2015 Free Software Foundation, Inc. This is free software; see the source for copying
conditions. There is NO warranty; not even for MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE.
When I try to run this program in gdb, I'm unable to "see" any variables:
>gdb ./a.exe
GNU gdb (GDB) (Cygwin 7.10.1-1) 7.10.1
Copyright (C) 2015 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-pc-cygwin".
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 ./a.exe...done.
(gdb) r
Starting program: /home/user/code/gdbtest/a.exe
[New Thread 6500.0x1c84]
[New Thread 6500.0x7a0]
Program received signal SIGSEGV, Segmentation fault.
0x000000010040111d in Func(int) ()
(gdb) bt
#0 0x000000010040111d in Func(int) ()
#1 0x000000010040113c in main ()
(gdb) f 0
#0 0x000000010040111d in Func(int) ()
(gdb) p i
No symbol "i" in current context.
(gdb) p pFoo
No symbol "pFoo" in current context.
(gdb) info locals
No symbol table info available.
(gdb) f 1
#1 0x000000010040113c in main ()
(gdb) p argc
No symbol "argc" in current context.
(gdb)
Can someone explain why this happens and how I can correct the problem?
I also tried compiling using "g++ -Og test.cpp" but it resulted in no change to the above described.
Best Answer
General note : is a bad idea to call a program test, as there is already a test command.
Changing name ;-)
Where
The debugging section will be: