Wow, __builtin_dump_struct is an amazing clang feature, how did I never hear about this before?

$ cat test.c
#include <stdio.h>

struct nested {
int n;
};
struct foo {
int member_a;
unsigned long member_b;
char *str;
void *ptr;
struct nested nested;
};

int main(void) {
struct foo f = {
.member_a = 123,
.member_b = 0x4141414141414141,
.str = "foobar",
.ptr = &f,
.nested = {.n = 42}
};
__builtin_dump_struct(&f, printf);
}
$ clang -o test test.c && ./test
struct foo {
int member_a = 123
unsigned long member_b = 4702111234474983745
char * str = "foobar"
void * ptr = 0x7fff1df41b78
struct nested nested = {
int n = 42
}
}

The original version of this feature was introduced back in 2018 (though it was reimplemented since in 2022).

0
0
0

If you have a fediverse account, you can quote this note from your own instance. Search https://infosec.exchange/users/jann/statuses/114241610482728821 on your instance and quote it. (Note that quoting is not supported in Mastodon.)