GDB调试问题:在GDB调试步骤中看到的虚值
gdb debug issue: phantom value seen in gdb debug steps
当我跳过第22行时,我仍然可以看到从y输出的奇怪值,这使我认为y没有正确初始化。但是当我再走2步到达返回行时,数字就正确了。
这里发生了什么?我试图关闭优化,但它不工作
1#include <iostream>
2#include <cstring>
3#include <cmath>
4using namespace std;
5
6const int MD = 10;
7struct BigNumber{
8 int digits[MD];
15 }
16
17 BigNumber(){
18 memset( digits, 0, sizeof(digits));
19 }
20
***21 BigNumber test(){
22 BigNumber p,c,y;// on this line , y is seen as garbage
23 p=c;// on this line , y is seen as garbage
24 c=y;
25 //y=p;
26 return y; // on this line, y returned to correct number
27=>}***
28
29
30 friend ostream& operator<<(ostream& out, const BigNumber& b );
31};
32
33ostream& operator<<(ostream& out, const BigNumber& b){
34 for( int i=MD-1; i>=0; i-- ){
35 out << b.digits[i];
36 }
37 return out;
38}
39
40
41
42int main( ){
43 BigNumber l("4");
44 BigNumber r;
45 BigNumber p,c,y;
46
47 r=l.test();
48 cout << r << endl;
49 cout << l.test() << endl;
50 return 0;
51}
28
(gdb) p p
$8 = {digits = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0}}
(gdb) p c
$9 = {digits = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0}}
(gdb) p y
$10 = {digits = {1171907, 1235664, -1208027616, 1, 1, 0, 1, 134513360, 134520860, 0}}
(gdb) n
(gdb) n
(gdb) p y
$11 = {digits = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0}}
这可能与编译器中的bug有关....随着我的操作,它开始出现错误。gdb错误信息:DW_OP_reg, DW_OP_piece, and DW_OP_bit_piece
我还必须澄清,这不是由数组成员引起的,因为编译器应该为它做成员元素明智的复制。参见对数组成员
相关文章:
- 带有 GDB 调试器的 VS 代码内存视图
- 使用 Windows 10 和 MINGW 编译器在 VS Code 上使用 gdb 调试器进行调试时出错
- 使用 ssh 重新连接到远程 Ubuntu 机器后,如何继续使用 gdb 调试 c++ 代码?
- 标识gdb调试器中符号的源文件名
- 如何在启动过程中崩溃时使用 gdb 调试可执行文件
- 使用 gdb 调试 linux 守护程序的初始启动
- 如何在使用 gdb 调试期间从 stdin 读取
- GDB 调试器访问未找到的文件
- "gdb"调试器奇怪地跳过断点
- VS Code 上的简单 GDB C++调试失败,并显示 NullReferenceException
- 如何使用 gdb 调试 LLVM 检查器时以图形方式查看 CFG
- 在用GDB调试核心转储时,知道谁是继承者
- 如何通过GDB调试nodejs addon
- gdb 7.5.1调试通过g 4.7.2构建的可执行文件的问题
- 如何在我自己的全系统模拟器上实现 GDB 调试
- 使用GDB调试时,分段故障消失
- 找不到GDB调试符号
- 如何在 Eclipse 中启动 gdb 调试之前运行 linux 脚本
- 如何使用 GDB 调试插件
- 如何使用 GDB 调试 GUI 程序