GDB Python pretty printers

转自:http://lumiera.org/documentation/technical/howto/DebugGdbPretty.html


Since some time, GDB supports Python written extension modules, especially for pretty printing of data structures. A selection of pre-defined pretty printers for STL containers is part of the standard distribution. The graphical debugger frontend provided by the Eclipse CDT automatically uses this debugger provided presentation to show the value of variables in the detail pane of the variables view. The most recent version of CDT (Version 8 for Eclipe 3.7 »Indigo«) is even able to populate the structure view based on the python pretty printer’s output, which is a big step ahead towards easy debugging of more elaborate data structures based on STL containers.

Installation notes

This feature requires an python enabled GDB (>6.8.50). Actually, even the most recent stable GDB (Version 7.2) is recommended, because it contains some relevant bugfixes. Debian users might want to backport the the GDB package from Debian/Wheezy (GDB-7.2). Moreover, you need to check out and install a recent version of the python pretty-printers from the GNU Subversion repository:

#
# .gdbinit : GDB Config file
#
# 3/2010 - Ichthyo: add python pretty printers for STL

python
import sys
sys.path.insert(0, '/opt/gdb/stlPrettyPrinter')
from libstdcxx.v6.printers import register_libstdcxx_printers
register_libstdcxx_printers (None)
end

For more informations see here..

Hello World
#include <iostream>
#include <string>
#include <vector>

using std::string;
using std::cout;
using std::endl;


int
main (int, char**)
  {
    std::string str = "hullo wöld";
    std::vector<int> vec (1000);

    for (uint i = 0; i < vec.size(); ++i)
        vec[i] = i;

    cout << str <<  "\n.gulp.\n";
    return 0;
  }

When selecting the string or the vector in the Eclipse variables view (or when issuing "print str" at the GDB prompt), the GDB python pretty-printer should be activated.

Note to get the full support in Eclipse Indigo + CDT-8, you need to activate the setting “enable pretty printers in variable/expression tree”, which can be accessed as Window/Preferences > C++ / debug / GDB

gdb提供了一些python接口来进行扩展编写。其中最常用的是gdb.execute和gdb.parse_and_eval。gdb.execute用于执行gdb命令,而gdb.parse_and_eval用于解析并评估gdb表达式。这两个接口允许我们在python中直接与gdb进行交互,以实现自定义功能和脚本。 在《用python拓展gdb》的第二篇中,我们学习了gdb提供的常用python接口,并使用python实现了自定义命令和调试脚本。在该教程中,我们介绍了一种DSL(领域特定语言),用于自动化gdb的操作,并实现了一个自定义命令和一个调试脚本。 如果你希望深入学习如何使用python来编写gdb扩展脚本,可以继续阅读《用python拓展gdb》系列的后续篇章。该系列教程将详细介绍如何使用python来给gdb编写脚本,并将分为四篇进行讲解。通过这些教程,你将学习如何利用python的强大功能来扩展gdb的功能并实现自定义需求。希望这对你有帮助!<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* *3* [用 Python 拓展 GDB(一)](https://blog.csdn.net/weixin_39734493/article/details/110777811)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"] - *2* [用 Python 拓展 GDB(二)](https://blog.csdn.net/weixin_39795971/article/details/111025138)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"] [ .reference_list ]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值