I encountered errors in compiling my signal processor program written in C with gcc displaying the values โโof the reset registers after a segmentation error occurred. When I tried to access it using code:
void print_registers(FILE *fd, ucontext_t *ctx, bool fpu = false) { const char *flags_str[] = { "CF", 0, "PF", 0, "AF", 0, "ZF", "SF", "TP", "IF", "DF", "OF", 0, 0, "NT", 0, "RF", "VM", "AC", "VIF", "VIP", "ID" }; greg_t *regs = ctx->uc_mcontext.gregs; void *eip[1] = { (void*)regs[REG_EIP] }; char **symbol = backtrace_symbols(eip, 1); fprintf(fd, "Registers:\neip is at "); backtrace_symbols_fd(eip, 1, fd->_fileno); size_type flags = regs[REG_EFL]; fprintf(fd, "eflags: %x [ ", flags); for (size_type i = 0; i < sizeof(flags_str) / sizeof(flags_str[0]); ++i) { if (!flags_str[i]) continue; if (flags & (1 << i)) fprintf(fd, "%s ", flags_str[i]); } size_type iopl = (flags & 0x3000) >> 12; fprintf(fd, "] iopl: %i\n" "eax: %08x\tebx: %08x\tecx: %08x\tedx: %08x\n" "esi: %08x\tedi: %08x\tebp: %08x\tesp: %08x\n" "cs: %04x\tgs: %04x\tfs: %04x\n" "ds: %04x\tes: %04x\tss: %04x\n", iopl, regs[REG_EAX], regs[REG_EBX], regs[REG_ECX], regs[REG_EDX], regs[REG_ESI], regs[REG_EDI], regs[REG_EBP], regs[REG_ESP], regs[REG_CS], regs[REG_GS], regs[REG_FS], regs[REG_DS], regs[REG_ES], regs[REG_SS]); } }
I tried the code by adding
#include<sys/ucontext.h>
and
#define _GNU_SOURCE #ifndef REG_EIP #define REG_EIP 0x23b46F #endif
But an error appears:
'REG_EIP' undeclared (first use in this function) (Each undeclared identifier is reported only once for each function it appears in.)
and an error appears for all registers
I tried many documents ... but could not get a solution. Can anyone share the details to fix this error.
Thanks to all users.