My goal is to observe a container of value which is pointed by a pointer. I am recommended to use natvis
for this purpose. I am using VSCode
to develop my project in Linux system. Unfortunately, I am not succeeded to get the desired value. I can only see the first address
and value
pointed by the pointer.
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
I have tried to create<?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
). Syntax is not clear to me.<?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
file{
// 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
with the index.pointer_array
natvis
to achieve this goal. I have tried by following 1 but failed.natvis
is not so much clear. I guess I have to use CustomListItems
to achieve the goal where suing Loop
I can display the value pointed by the pointer but found this, this where it has told that using VSCode
it is not possible. Though, I am not sure whether I am walking in right track or not.natvis
file? If a working example is given would be really helpful to understand.VSCode
?Finally, found the solution though came lots of other questions which will post in new post. I was wrongly interpreting the syntax.
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
has the ArrayItems
element.