我的目标是观察一个由指针指向的值容器。为此,建议我使用natvis。我正在使用VSCode在Linux系统中开发我的项目。不幸的是,我没有成功地获得所期望的价值。我只能看到指针所指向的first address和value。
我在这里给出的示例代码。
foo.h#include <iostream>
class FOO
{
public:
FOO(uint32_t a_, uint32_t b_) : a{a_}, b{b_}
{}
void Print_Value();
uint32_t *pointer_array;
protected:
uint32_t a, b;
};foo.cpp#include "foo.h"
void FOO :: Print_Value()
{
std::cout << "a: " << a << std::endl
<< "b: " << b << std::endl;
}main.cpp#include "foo.h"
int main()
{
FOO obj_1(58,9);
obj_1.Print_Value();
uint32_t foo_array[5] = {5,15,96,8,77};
obj_1.pointer_array = foo_array;
return 0;
}natvis file<?xml version="1.0" encoding="utf-8"?>
<AutoVisualizer xmlns="http://schemas.microsoft.com/vstudio/debugger/natvis/2010">
<Type Name="FOO">
<DisplayString>Test</DisplayString>
<Expand>
<Item Name="[pointer_array]">pointer_array</Item>
</Expand>
</Type>
</AutoVisualizer>a,b)。我不清楚语法。<?xml version="1.0" encoding="utf-8"?>
<AutoVisualizer xmlns="http://schemas.microsoft.com/vstudio/debugger/natvis/2010">
<Type Name="FOO::pointer_array">
<DisplayString>Test</DisplayString>
<Expand>
<CustomListItems>
<Variable Name="pointer_array" InitialValue="0" />
<Size>5</Size>
<Loop Condition="pointer_array < 5">
<Item Name="{pointer_array}"> 1 </Item>
<Exec> ++pointer_array </Exec>
</Loop>
</CustomListItems>
</Expand>
</Type>
</AutoVisualizer>launch.json文件中添加行{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "(gdb) Launch",
"type": "cppdbg",
"request": "launch",
"program": "${workspaceFolder}/bin/foo_example",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceFolder}/bin/",
"environment": [],
"externalConsole": false,
"MIMode": "gdb",
"visualizerFile": "${workspaceFolder}/natvis_file/file.natvis",
"showDisplayString": true,
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
},
{
"description": "Set Disassembly Flavor to Intel",
"text": "-gdb-set disassembly-flavor intel",
"ignoreFailures": true
}
]
}
]
}我所期望的
foo_array的值。pointer_array来观察这个值。natvis来实现这个目标。我通过跟踪1尝试过,但是失败了。natvis的想法/理解不太清楚。我想我必须使用CustomListItems来达到起诉Loop的目的--我可以显示指针指向的值,但是找到了这,这,在那里它告诉使用VSCode是不可能的。虽然,我不确定我是否走在正确的轨道上。我的疑问
natvis文件?如果给出一个有用的例子,就会对理解很有帮助。VSCode中实现?发布于 2022-05-20 21:08:49
最后,找到了解决方案,尽管出现了许多其他问题,这些问题将在新的帖子中发布。我错误地解释了语法。
file.natvis<?xml version="1.0" encoding="utf-8"?>
<AutoVisualizer xmlns="http://schemas.microsoft.com/vstudio/debugger/natvis/2010">
<Type Name="FOO">
<DisplayString>Test</DisplayString>
<Expand>
<Item Name="[a]">a</Item>
<ArrayItems>
<Size>5</Size>
<ValuePointer>pointer_array</ValuePointer>
</ArrayItems>
</Expand>
</Type>
</AutoVisualizer>natvis有ArrayItems元素。https://stackoverflow.com/questions/72310540
复制相似问题