我已经编译了非常简单的程序
$ 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 将向我显示顶部的第一个示例中的源代码?
以下是工具版本:
$ 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.