#include <libunwind.h>
#include <stdlib.h>
#include <string.h>
#define VG_REGNUM 46
__attribute__((noinline)) void baz() {
asm(".cfi_escape 0x16, 0x2e, 0x01, 0x32");
unw_context_t context;
unw_cursor_t cursor;
unw_getcontext(&context);
unw_init_local(&cursor, &context);
uint16_t expected_vgs[]{ 2, 2, 8, 2};
for (uint16_t expected_vg : expected_vgs) {
unw_step(&cursor);
unw_word_t vg;
unw_get_reg(&cursor, VG_REGNUM, &vg);
if (vg != expected_vg)
exit(1);
}
exit(0);
}
__attribute__((noinline)) void qux() { baz(); }
__attribute__((noinline)) void bar() {
asm(".cfi_escape 0x16, 0x2e, 0x01, 0x38");
asm(".cfi_escape 0x16, 0x15, 0x03, 0x92, 0x2e, 0x00");
qux();
}
__attribute__((noinline)) void foo() {
asm(".cfi_escape 0x16, 0x2e, 0x01, 0x32");
asm(".cfi_escape 0x16, 0x15, 0x03, 0x92, 0x2e, 0x00");
bar();
}
int main(int, char **) {
foo();
return 0;
}