Re: [問題]如何去get C variable的scope ?

看板PLT (程式語言與理論)作者 (allstars)時間17年前 (2008/06/26 13:47), 編輯推噓0(000)
留言0則, 0人參與, 最新討論串3/3 (看更多)
※ 引述《godfat (godfat 真常)》之銘言: : ※ 引述《allstarschh (allstars)》之銘言: : : 這裡面.......好像就沒有scope的information??? : : 或者是由上面的某個memory address來知道scope information?? : gdb 我沒用過,不過既然是 lexical scoping, : 那麼 compile time 即可確定 name resolution, : runtime 完全用不到這個資訊,當然就會丟棄了 : : 不過在maint print symbols : : 可以看到有Blockvector 的東西 : : 而這block number 的index : : 就跟我說的scope number 一樣 : : 由這個Blockvector 就可以來作variable的binding了 : 我查了一下 maint print symbols, 好像是 gdb 的功能? : 也就是說,如果你用 gcc 開 debug 模式,可能抓得到這個資訊吧? : 不過這理所當然不是標準 c 就是了 : 你是想做什麼東西?為什麼需要這個資訊? : 也許必須用一些間接方式才行,例如如果是 c++ 的話, : 把你的 get_scope_number_and_print(); 改成某個 scope guard 之類的 感謝godfat大大的回應 其實最主要 我只是想知道scope number的資訊 後來發現gdb 中可以顯示出這個information 也就是 Blockvector 像要在runtime知道的話 前提要像godfat大說的 要開debug option 要不然symtab是會被移掉的 不過像debug information 都會用dwarf 儲存 我發現有libdwarf 這東西 看能不能在runtime 時拿到 debug information的東西就是了 另外第一次聽到有scope guard這東西 待會來看看.. -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 211.22.63.250
文章代碼(AID): #18OorqMf (PLT)
文章代碼(AID): #18OorqMf (PLT)