gpt4 book ai didi

python - c++ STL - 手动使用标准 gdb pretty-print

转载 作者:行者123 更新时间:2023-11-30 02:18:45 24 4
gpt4 key购买 nike

我如何使用 https://github.com/gcc-mirror/gcc/blob/gcc-6_3_0-release/libstdc%2B%2B-v3/python/libstdcxx/v6/printers.py 的 StdVectorPrinter创建我自己的输出样式?
IE。使用现有工具访问元素,但自行驱动输出。

例如对于

#include <string>
#include <vector>
#include <iostream>

int main(int, char**)
{
std::vector<std::string> data = { "hello", "world", "all", "is", "fine" };

for ( auto && i : data) {
std::cout << i << std::endl;
}
return 0;
}

输出不得

(gdb) p data
$2 = std::vector of length 5, capacity 5 = {"hello", "world", "all", "is", "fine"}

但是

(gdb) p data
$2 = "hello|world|all|is|fine"

使用 StdVectorPrinter(例如)的通用打印机的框架代码在哪里?

最佳答案

Where is the skeleton code for the generic printer, that uses the StdVectorPrinter

这可能取决于您的操作系统。在 Ubuntu 上:

$ dpkg -L libstdc++6:amd64 | grep '\.py'
/usr/share/gcc-8/python/libstdcxx/__init__.py
/usr/share/gcc-8/python/libstdcxx/v6/__init__.py
/usr/share/gcc-8/python/libstdcxx/v6/printers.py
/usr/share/gcc-8/python/libstdcxx/v6/xmethods.py
/usr/share/gdb/auto-load/usr/lib/x86_64-linux-gnu/libstdc++.so.6.0.25-gdb.py

printers.py 包含这一行:

    libstdcxx_printer.add_container('std::', 'vector', StdVectorPrinter)

StdVectorPrinterstd::vector 相关联。您可以覆盖 StdVectorPrinter 本身,或者您可以将 std::vector 与不同的 pretty-print 相关联。

关于python - c++ STL - 手动使用标准 gdb pretty-print ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51902317/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com