Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/variables/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
为什么gdb切换到主目录?_Gdb - Fatal编程技术网

为什么gdb切换到主目录?

为什么gdb切换到主目录?,gdb,Gdb,假设当前目录为/home/xxx/test,有一个名为“test.txt”的文本文件,其中包含一个单词“hello”,一个名为“test.cpp”的文件如下所示: #include <iostream> #include <fstream> #include <unistd.h> using namespace std; int main () { char cwd[1024]; getcwd(cwd, 1024);

假设当前目录为/home/xxx/test,有一个名为“test.txt”的文本文件,其中包含一个单词“hello”,一个名为“test.cpp”的文件如下所示:

#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
#包括
#包括
#包括
使用名称空间std;
int main()
{
char-cwd[1024];
getcwd(cwd,1024);

coutmy.cshrc中有一个“cd~”,这是“shell pwd”和“pwd”之间差异的根本原因

拆下后,所有问题都得到解决


谢谢。

我的.cshrc中有一个“cd~”,这是“shell pwd”和“pwd”之间差异的根本原因

拆下后,所有问题都得到解决


谢谢。

gdb本身不应该这样做。它会发生在“gdb-nx”上吗?这会禁用你的.gdbinit。而且,gdb和shell的pwd概念之间的差异很奇怪。我想知道为什么会这样。你应该显示“pwd”的结果在运行gdb之前。嗨,汤姆,谢谢你在这里的提示。gdb本身不应该这样做。它发生在“gdb-nx”上吗?这会禁用你的.gdbinit。而且,gdb和shell的pwd概念之间的差异很奇怪。我想知道为什么。你应该在运行gdb之前显示“pwd”的结果。嗨,汤姆,谢谢你在这里的提示。