本文介紹了使用 gdb 檢查標準容器 (std::map) 內容的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!
問題描述
假設有這樣的東西:
#include <map>
int main(){
std::map<int,int> m;
m[1] = 2;
m[2] = 4;
return 0;
}
我希望能夠從 gdb 中檢查運行該程序的地圖的內容.
如果我嘗試使用下標運算符,我會得到:
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 方法不會產生更好的結果:
Using the find method does not yield better results:
(gdb) p m.find(1)
Cannot evaluate function -- may be inlined
有沒有辦法做到這一點?
Is there a way to accomplish this?
推薦答案
我認為沒有,至少如果你的源代碼經過優化等沒有.但是,有一些 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
不過,我不使用這個,所以YMMV
However, I don't use this, so YMMV
這篇關于使用 gdb 檢查標準容器 (std::map) 內容的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!
【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!