問(wèn)題描述
假設(shè)有這樣的東西:
#include <map>
int main(){
std::map<int,int> m;
m[1] = 2;
m[2] = 4;
return 0;
}
我希望能夠從 gdb 中檢查運(yùn)行該程序的地圖的內(nèi)容.
如果我嘗試使用下標(biāo)運(yùn)算符,我會(huì)得到:
I would like to be able to inspect the contents of the map running the program from gdb.
If I try using the subscript operator I get:
(gdb) p m[1]
Attempt to take address of value not located in memory.
使用 find 方法不會(huì)產(chǎn)生更好的結(jié)果:
Using the find method does not yield better results:
(gdb) p m.find(1)
Cannot evaluate function -- may be inlined
有沒(méi)有辦法做到這一點(diǎn)?
Is there a way to accomplish this?
推薦答案
我認(rèn)為沒(méi)有,至少如果你的源代碼經(jīng)過(guò)優(yōu)化等沒(méi)有.但是,有一些 gdb 宏可以為你檢查 STL 容器:
I think there isn't, at least not if your source is optimized etc. However, there are some macros for gdb that can inspect STL containers for you:
http://sourceware.org/ml/gdb/2008-02/msg00064.html
不過(guò),我不使用這個(gè),所以YMMV
However, I don't use this, so YMMV
這篇關(guān)于使用 gdb 檢查標(biāo)準(zhǔn)容器 (std::map) 內(nèi)容的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!