简体   繁体   English

如何在gdb中打印std :: map值

[英]how to print std::map value in gdb

I have a std::map< std::string, std::string> cont; 我有一个std :: map <std :: string,std :: string> cont;

I want to see cont[ "some_key" ] in gdb. 我想在gdb中看到cont [“some_key”]。 When I'm trying 当我在尝试

p cont[ "some_ket" ] p cont [“some_ket”]

I'm getting this message: One of the arguments you tried to pass to operator[] could not be converted to what the function wants. 我收到此消息:您尝试传递给operator []的其中一个参数无法转换为函数所需的内容。

I'm using GNU gdb Red Hat Linux (6.3.0.0-1.162.el4rh). 我正在使用GNU gdb Red Hat Linux(6.3.0.0-1.162.el4rh)。 Thanks 谢谢

You can write your own dump functions and call them: 您可以编写自己的转储函数并调用它们:

(gdb) call dump(m)

see this thread: http://www.mail-archive.com/help-gplusplus@gnu.org/msg02109.html 看到这个帖子: http//www.mail-archive.com/help-gplusplus@gnu.org/msg02109.html

I'm curious about the GDB helper macros. 我很好奇GDB助手宏。

The latest gdb has python support baked in so one could easily write a function to print out the contents of any stl structure. 最新的gdb具有python支持,因此可以轻松编写一个函数来打印出任何stl结构的内容。 However you'd have to learn the API and write the script. 但是,您必须学习API并编写脚本。 Luckily gcc 4.5 will ship with the needed python scripts to get gdb to intelligently handle stl data structures. 幸运的是,gcc 4.5将附带所需的python脚本,以使gdb能够智能地处理stl数据结构。

EDIT: you don't have to wait for GCC 4.5 (which by the way has already been released), you can just grab the code from SVN . 编辑:您不必等待GCC 4.5(顺便说一下已经发布),您可以从SVN获取代码

Gdb不了解C ++运算符重载。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM