简体   繁体   English

如何编写一个非常简单的Visual Studio调试器可视化工具?

[英]How do I write a very simple Visual Studio debugger visualizer?

I'm trying to write an 'autoexp.dat'-based visualizer for a string type. 我正在尝试为字符串类型编写一个基于'autoexp.dat'的可视化工具。 I've scaled-back my ambitions to attempting to write a visualizer for a really simple test type that contains a null-terminated string field: 我已经缩减了我的野心,试图为一个包含以null结尾的字符串字段的非常简单的测试类型编写可视化工具:

namespace thizz { namespace izz {
        class MyType {
            const char* _ptr;
        public:
            MyType(const char* ptr) : _ptr(ptr) {}
        };
    }
}

This is my stab at a visualiser, but it has no effect on how Visual Studio (2010) displays an instance of this type: 这是我对可视化工具的刺激,但它对Visual Studio(2010)如何显示此类型的实例没有影响:

thizz::izz::MyType
{
 preview ([$e._ptr,s])
}

(That's going at the top of the [Visualizers] section in C:\\Program Files (x86)\\Microsoft Visual Studio 10.0\\Common7\\Packages\\Debugger\\autoexp.dat ). (这是在C:\\ Program Files(x86)\\ Microsoft Visual Studio 10.0 \\ Common7 \\ Packages \\ Debugger \\ autoexp.dat中的[Visualizers]部分的顶部。

Watching an instance of this type: 观看此类型的实例:

thizz::izz::MyType t("testing testing");

Just displays 只是显示

t | {_ptr=0x0f56a6fc "testing testing" } | thizz::izz::MyType

in the Watch window. 在Watch窗口中。

To get an even more versatile viewer try changing to use this: 要获得更多功能的查看器,请尝试更改以使用此功能:

thizz::izz::MyType {
preview ( #( [$e._ptr,s] ) )
stringview ( #( [$e._ptr,sb] ) )
}

this will also give the magnifying glass icon which will open a larger text view window in the case that you have a longer string. 这也将提供放大镜图标,如果你有一个更长的字符串,它将打开一个更大的文本视图窗口。 It'll also give you the option of rendering as HTML or XML. 它还为您提供了以HTML或XML呈现的选项。

Note that as well as the format of the file being sensitive to whitespace, I've also found that you can't use a colon in the string otherwise it generates parse errors. 请注意,除了对空格敏感的文件格式外,我还发现你不能在字符串中使用冒号,否则会生成解析错误。

The debugger visualisers are incredibly powerful, though the syntax can be quite bewildering. 调试器可视化器非常强大,但语法可能非常令人困惑。 As general advice I would suggest creating some entries first in the [AutoExpand] section to summarise the data types that you are most interested in, and then if you have custom containers then copy and adapt the examples for vector , list , etc, which will give you the largest return for the investment in your time. 作为一般建议,我建议首先在[AutoExpand]部分创建一些条目,以总结您最感兴趣的数据类型,然后如果您有自定义容器,则复制并调整vectorlist等的示例,这将是为您提供最大的投资回报。

I can't give a categorical reason why my original 'code' in autoexp.dat was not working, but I found that the same code worked when all the whitespace was removed. 我无法给出一个明确的原因,为什么我在autoexp.dat中的原始'代码'不起作用,但我发现当删除所有空格时,相同的代码都有效。

I then tried re-adding whitespace and found that keeping the initial open brace on the first line was necessary to keep the definition working. 然后我尝试重新添加空格,并发现保持第一行的初始打开括号是保持定义工作所必需的。

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

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