How to resolve REG_EIP uneclared error (first use of this function) on a 32-bit Linux machine?

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.

+4
source share
4 answers

Try defining __USE_GNU before including <ucontext.h :

 #define __USE_GNU #include <ucontext.h> 

You do not need to explicitly specify <sys/ucontext.h> , <ucontext.h> will do this.

+3
source

I suggest that you should either have #define _GNU_SOURCE as the first line of your source file, or it is better to place -D_GNU_SOURCE in CFLAGS (on the command line). Then make sure you include <signal.h> and <ucontext.h> .

+5
source

Try using the 32-bit version, as these are 32-bit mode values. gcc -m32 should solve this problem.

0
source

For me it was allowed: yum install openssl-devel.x86_64 yum install openssl-devel.i686

on CentOS 6.4 (x86_64)

Hope this helps.

0
source

All Articles