gdb调试问题:phantom值出现在gdb调试步骤 [英] gdb debug issue: phantom value seen in gdb debug steps

查看:144
本文介绍了gdb调试问题:phantom值出现在gdb调试步骤的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我跳过第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; //在此行上,y被视为垃圾
23 p = c; //在这行上,y被看作是垃圾
24 c = y;
25 // y = p;
26 return y; //在这行上,y返回正确的数字
27 =>} ***
28
29
30 friend ostream& operator<<(ostream& out,const BigNumber& b);
31};
32
33ostream&运算符<<<<(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)pp
$ 8 = {digits = {0,0,0,0,0,0,0,0,0,0}}
(gdb)pc
$ 9 = {digits = {0,0,0,0,0,0,0,0,0,0}}
(gdb)py $ b b $ 10 = {digits = {1171907,1235664,-1208027616,1,1,0,1,134513360,134520860,0}}
(gdb)n
(gdb)n
gdb)py
$ 11 = {digits = {0,0,0,0,0,0,0,0,0}}


解决方案

它可能与编译器中的错误....
随着它,它开始抛出错误。
gdb错误消息:DW_OP_reg,DW_OP_piece和DW_OP_bit_piece



我还必须清楚,这不是由数组成员引起的,因为编译器应该做成员元素明智的副本。
请参阅有关数组成员的默认副本分配的确认

when I step over line 22, I still can see weird values cameout from y, which makes me think y is not correctly initialized. but when I go 2 step further to hit the return line, the number becomes correct.

what is happening here? I tried to turn off the optimization, but it don't work

 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}}

解决方案

it might be related with bugs in the compiler.... as I go with it, it start to throw errors of it. gdb error message: DW_OP_reg, DW_OP_piece, and DW_OP_bit_piece

I also have to clear that, this is not caused by the array member as the compiler is supposed to do the member element wise copy for it. see confirmations on Default copy assignment with array members

这篇关于gdb调试问题:phantom值出现在gdb调试步骤的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆