1
현재 디렉토리가/home/xxx/test라고 가정하고 "hello"라는 단어가 포함 된 "test.txt"라는 텍스트 파일이 있으며 "test.cpp"라는 파일은 다음과 같습니다.gdb가 홈 디렉토리로 전환 된 이유는 무엇입니까?
#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
제 질문은 'test.txt'를 찾을 수없는 gdb가 홈 디렉토리로 전환 된 이유는 무엇입니까? 'pwd'와 'shell pwd'가 다른 결과를 표시하는 이유는 무엇입니까?
감사합니다.
gdb 자체로해서는 안됩니다. "gdb -nx"에서 발생합니까? 이렇게하면 .gdbinit가 비활성화됩니다. 또한, gdb와 쉘의 pwd 개념 사이의 불일치는 이상합니다. 왜 그런지 궁금합니다. gdb를 실행하기 전에 "pwd"결과를 보여줘야합니다. –
안녕하세요 톰, 여기에 힌트를 보내 주셔서 감사합니다. –