Wednesday, 7 August 2013

Why gdb switched to home directory?

Why gdb switched to home directory?

Suppose the current directory is /home/xxx/test, there is a text file
named "test.txt" which contains a single word "hello", and a file named
"test.cpp" is as following,
#include <iostream>
#include <fstream>
#include <unistd.h>
using namespace std;
int main ()
{
char cwd[1024];
getcwd(cwd, 1024);
cout << cwd << endl;
string s;
ifstream i("test.txt");
if (!i.good())
cout << "Can't open test.txt" << endl;
i >> s;
i.close();
cout << s << endl;
return 0;
}
test> g++ test.cpp
test> ./a.out
/home/xxx/test
hello
test> gdb a.out
GNU gdb (GDB) Red Hat Enterprise Linux (7.2-60.el6_4.1)
Copyright (C) 2010 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-redhat-linux-gnu".
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>...
Reading symbols from /home/xxx/test/a.out...(no debugging symbols
found)...done.
(gdb) run
Starting program: /home/xxx/test/a.out
/home/xxx
Can't open test.txt
Program exited normally.
(gdb) pwd
Working directory /home/xxx/test.
(gdb) shell pwd
/home/xxx
My question is why gdb switched to home directory?
Thanks.

No comments:

Post a Comment