作者Japie (Japie)
看板EE_DSnP
標題[問題] cannot access mem??
時間Fri Jan 13 11:35:19 2012
下面是gdb資訊
=====
(gdb) p c->getFanIn2()
$41 = (CirGate *) 0x6377a0
//c是個CirGate* 其中c的getFanIn2是有東西,也是CirGate*,
而兩者都不是UndefGate
isUndef是CirGate中的virtual fun
(gdb) p c->getFanIn2()->isUndef
$40 = {bool (const CirGate * const)} 0x40fdf2 <CirGate::isUndef() const>
(gdb) p c->isUndef
$43 = {bool (const CirGate * const)} 0x40fdf2 <CirGate::isUndef() const>
(gdb) p (c->getFanIn2()->isUndef)()
Cannot access memory at address 0xb0
(gdb) p c->isUndef()
$44 = false
(gdb) p (c->getFanIn2())->isUndef()
Cannot access memory at address 0xb0
====
我想詢問造成黃字和紅色部份結果不同的原因>"<
在做sweep時候 必須要把要刪掉的gate的fanin和fanout 連結一起刪掉
但是每次一寫到
c->getFanIn2()->xxxfunction()時候
根本就沒有跳進xxxfunction裡面(再最一開始cout東西 沒有印出來)就直接segfault了...
但是xxxfunction有些又可以用 (在gdb裡面印getID()是可以的)
是因為virtual與否的關係嗎?
請問這邊應該要怎麼寫或是檢查哪邊呢...."orz
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 140.112.25.108
※ 編輯: Japie 來自: 140.112.25.108 (01/13 11:43)
1F:推 yangjiunru:黃色的pointer是指到CirGate::isUndef() 01/13 12:48
2F:→ yangjiunru:紅色的0xb0是你的c->getFanIn2()是NULL的關係 01/13 12:48
3F:→ yangjiunru:可以在c->getFanIn2()->xxxfunction()之前加上 01/13 12:49
4F:→ yangjiunru:assert(c->getFanIn2() != NULL) 01/13 12:49
5F:→ Japie:我在前面有加上if(c->getFanIn2()) 而且把圖畫出來(p.8)的確 01/13 13:37
6F:→ Japie:不應該是NULL 另外c->getFanIn2->getID()可以看到4....."orz 01/13 13:39
7F:→ wmin0:有可能不小心call了 delete c->getFanIn2() 之類的東西 01/13 14:20
8F:→ wmin0:造成那邊被砍掉 這邊pointer沒改成NULL 01/13 14:20
9F:→ wmin0:getID() 拿得到只是因為剛好的吧我想@@" 01/13 14:22
10F:→ wmin0:黃字丟出來的是function pointer的位置這樣 01/13 14:23
11F:推 yangjiunru:用valgrind測是不是讀到delete過的地方 01/13 14:36
12F:推 ric2k1:你是用自己的 cir 嗎? 01/13 18:04
13F:推 ric2k1:直接呼叫 p c->getFanIn2()->isUndef() 呢? 01/13 18:06
14F:→ Japie:我是用自己的cir 直接那樣會一樣顯示cannot access memory.. 01/13 19:34
15F:推 ric2k1:Oh, 你也可以 p* c->getFanin2() 看看裡面的內容是不是 01/13 21:17
16F:→ ric2k1:garbage, 像是 data members 的值是否正常, vptr 是否正確 01/13 21:18
17F:→ Japie:找到問題了 真的是不小心delete掉...謝謝教授和大家m(_ _)m 01/14 13:17