我编写了一个非常简单的程序
$ cat main.cpp
#include <iostream>
int main() {
uint64_t val=1;
// val = htobe64(val);
std::cout << val << std::endl;
}
$ g++ -g main.cpp -o a.out当我使用cgdb调试它时,我得到以下信息:
$ cgdb a.out

但是,当我取消评论行// val = htobe64(val)时,会发生一些奇怪的事情:
$ cat main.cpp
#include <iostream>
int main() {
uint64_t val=1;
val = htobe64(val);
std::cout << val << std::endl;
}
$ g++ -g main.cpp -o a.out
$ cgdb a.out

取消注释这一行将导致cgdb开始显示启动屏幕,当我在屏幕截图中键入start时,它只给我汇编程序代码(在cgdb开始直接显示源代码而不是它的启动屏幕之前)。此外,文件路径/home/user/byteswap.h出现在屏幕截图中,但是这个文件不存在(在本例中,user是我的用户名,/home/user是我的工作目录)。
有人能告诉我这里发生了什么,我能做些什么来调试一个调用htobe64**,的程序,例如,如何实现?**
以下是工具版本:
$ cgdb --version
CGDB 0.7.1
Copyright 2002-2019 Bob Rossi and Mike Mueller.
CGDB is free software, covered by the GNU General Public License, and you are
welcome to change it and/or distribute copies of it under certain conditions.
There is absolutely no warranty for CGDB.
$ gdb --version
GNU gdb (Debian 8.2.1-2+b3) 8.2.1
Copyright (C) 2018 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.
$ g++ --version
g++ (Debian 11.2.0-10) 11.2.0
Copyright (C) 2021 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.发布于 2021-11-30 15:35:31
在发布这个问题时,我意识到与gdb版本相比,我的g++版本是非常新的(我最近更新了它,以获得更好的C++20支持)。
我发现更新gdb版本解决了这个问题:对于gdb版本GNU gdb (Debian 10.1-2) 10.1.90.20210103-git,问题不再存在。我承认我应该在发帖前核实这一点,但我不删除这个问题,因为它可能会帮助其他人有类似的奇怪的观察。
https://stackoverflow.com/questions/70171722
复制相似问题