John Harrison e9799e51ed
[lldb-dap] Improve support for variables with anonymous fields and types (#186482)
While looking at the '[raw]' value of a std::vector I noticed we didn't
handle the anonymous inner struct very well. The 'evaluateName' was
incorrect (e.g. the evaluateName would return `<var>.` for the anonymous
struct).

This improves support for variables with anonymous fields and anonymous
types.

* Changed the name of anonymous fields from `<null>` to `(anonymous)`,
which matches other tooling like clangd's representation and how types
are presented if the field is not defined.
* Adjusts variables to not return an 'evaluateName' for anonymous
fields.
* Adjusted '[raw]' values to be marked as 'internal' which deemphasizes
them in the UI.

While working in this area, I also consolidated some helpers that are
only used within Variables.cpp.

Before my changes:
<img width="513" height="460" alt="before"
src="https://github.com/user-attachments/assets/3da0aada-8ba3-415d-bbec-56b41a9b9415"
/>

After my changes:
<img width="414" height="467" alt="after"
src="https://github.com/user-attachments/assets/66a47108-ee44-4e01-8eab-e89edb348fde"
/>
2026-03-18 11:39:22 -07:00

91 lines
1.9 KiB
C++

#define BUFFER_SIZE 16
struct PointType {
int x;
int y;
int buffer[BUFFER_SIZE];
};
#include <cstdio>
#include <vector>
extern int g_global;
int g_global = 123;
static int s_global = 234;
int test_indexedVariables();
int test_return_variable();
int test_anonymous_types();
int test_anonymous_fields();
void test_unnamed_bitfields();
int main(int argc, char const *argv[]) {
static float s_local = 2.25;
PointType pt = {11, 22, {0}};
for (int i = 0; i < BUFFER_SIZE; ++i)
pt.buffer[i] = i;
const char *valid_str = "𐌶𐌰L𐌾𐍈 C𐍈𐌼𐌴𐍃";
const char *malformed_str = "lone trailing \x81\x82 bytes";
printf("print malformed utf8 %s %s\n", valid_str, malformed_str);
int x = s_global - g_global - pt.y; // breakpoint 1
{
int x = 42;
{
int x = 72;
s_global = x; // breakpoint 2
}
}
{
int return_result = test_return_variable();
}
test_anonymous_types();
test_anonymous_fields();
test_unnamed_bitfields();
return test_indexedVariables(); // breakpoint 3
}
int test_indexedVariables() {
int small_array[5] = {1, 2, 3, 4, 5};
int large_array[200];
std::vector<int> small_vector;
std::vector<int> large_vector;
small_vector.assign(5, 0);
large_vector.assign(200, 0);
return 0; // breakpoint 4
}
int test_return_variable() {
return 300; // breakpoint 5
}
int test_anonymous_types() {
struct {
char name[16];
int x, y;
} my_var = {"hello world!", 42, 7};
return my_var.x + my_var.y; // breakpoint 6
}
struct MySock {
union {
unsigned char ipv4[4];
unsigned char ipv6[6];
};
};
int test_anonymous_fields() {
MySock home = {{{0}}};
home.ipv4[0] = 127;
home.ipv4[1] = 0;
home.ipv4[2] = 0;
home.ipv4[1] = 1;
return 1; // breakpoint 7
}
void test_unnamed_bitfields() {
struct example {
unsigned int lo : 4;
unsigned int : 0;
unsigned int hi : 4;
};
example e = {0xA, 0xB};
printf("lo: %u, hi: %u\n", e.lo, e.hi); // breakpoint 8
}