c++ - Retrieving sigcontext during backtrace -
in writing code print backtraces in c++, came across this answer, includes copying definition of type:
/* structure mirrors 1 found in /usr/include/asm/ucontext.h */ typedef struct _sig_ucontext { unsigned long uc_flags; struct ucontext *uc_link; stack_t uc_stack; struct sigcontext uc_mcontext; sigset_t uc_sigmask; } sig_ucontext_t;
i can't include <asm/ucontext.h>
since there defined ucontext
collides named type <sys/ucontext.h>
(which included necessary <signal.h>
):
/* userlevel context. */ typedef struct ucontext { unsigned long int uc_flags; struct ucontext *uc_link; stack_t uc_stack; mcontext_t uc_mcontext; __sigset_t uc_sigmask; struct _libc_fpstate __fpregs_mem; } ucontext_t;
all need here struct sigcontext uc_mcontext
member asm
version. there better way retrieve value copying out struct? seems incredibly hackish , error-prone me.
one potential workaround make asm/ucontext.h
first include in source file , abuse preprocessor rename conflicting definition:
#define ucontext asm_ucontext #include <asm/ucontext.h> #undef asm_ucontext
you can use asm_ucontext
refer alternative definition of ucontext
.
a bit less hacky approach employ sed automatically extract necessary definitions system file:
$ echo '#include <asm/ucontext.h>' | gcc -x c - -e -o- | sed -n '/^struct ucontext/,/^};/{ s/ucontext/asm_ucontext/; p}' | tee asm_ucontext.h struct asm_ucontext { unsigned long uc_flags; struct asm_ucontext *uc_link; stack_t uc_stack; struct sigcontext uc_mcontext; sigset_t uc_sigmask; };
Comments
Post a Comment