__builtin_dump_struct
is an amazing clang feature, how did I never hear about this before?$ cat test.c<br>#[url=https://infosec.exchange/tags/include]include[/url] <stdio.h><br><br>struct nested {<br> int n;<br>};<br>struct foo {<br> int member_a;<br> unsigned long member_b;<br> char *str;<br> void *ptr;<br> struct nested nested;<br>};<br><br>int main(void) {<br> struct foo f = {<br> .member_a = 123,<br> .member_b = 0x4141414141414141,<br> .str = "foobar",<br> .ptr = &f,<br> .nested = {.n = 42}<br> };<br> __builtin_dump_struct(&f, printf);<br>}<br>$ clang -o test test.c && ./test<br>struct foo {<br> int member_a = 123<br> unsigned long member_b = 4702111234474983745<br> char * str = "foobar"<br> void * ptr = 0x7fff1df41b78<br> struct nested nested = {<br> int n = 42<br> }<br>}<br>
The original version of this feature was introduced back in 2018 (though it was reimplemented since in 2022).
Introduce a new builtin, __builtin_dump_struct, that is useful for du… · llvm/llvm-project@0652534
…mping structure contents at runtime in circumstances where debuggers may not be easily available (such as in kernel work). Patch by Paul Semel. llvm-svn: 329762GitHub