C programming, unable to get field from siginfo
I want to access - _addr residing in _sigfault which is part of siginfo structure. siginfo structure defined in asm-generic/siginfo is as follows -
typedef struct siginfo {
int si_signo;
int si_errno;
int si_code;
union {
int _pad[SI_PAD_SIZE];
/* kill() */
struct {
pid_t _pid; /* sender's pid */
__ARCH_SI_UID_T _uid; /* sender's uid */
} _kill;
/* POSIX.1b time开发者_如何学编程rs */
struct {
timer_t _tid; /* timer id */
int _overrun; /* overrun count */
char _pad[sizeof( __ARCH_SI_UID_T) - sizeof(int)];
sigval_t _sigval; /* same as below */
int _sys_private; /* not to be passed to user */
} _timer;
/* POSIX.1b signals */
struct {
pid_t _pid; /* sender's pid */
__ARCH_SI_UID_T _uid; /* sender's uid */
sigval_t _sigval;
} _rt;
/* SIGCHLD */
struct {
pid_t _pid; /* which child */
__ARCH_SI_UID_T _uid; /* sender's uid */
int _status; /* exit code */
clock_t _utime;
clock_t _stime;
} _sigchld;
/* SIGILL, SIGFPE, SIGSEGV, SIGBUS */
struct {
void *_addr; /* faulting insn/memory ref. */
#ifdef __ARCH_SI_TRAPNO
int _trapno; /* TRAP # which caused the signal */
#endif
} _sigfault;
/* SIGPOLL */
struct {
__ARCH_SI_BAND_T _band; /* POLL_IN, POLL_OUT, POLL_MSG */
int _fd;
} _sigpoll;
} _sifields;
} siginfo_t;
I am unable to access _addr field. Following is the code i wrote for accessing it - siginfo_t sigInfo. printf("%x",sigInfo._sifields._sigfault._addr);
Error i get during compilation is - sampleTrace.c: In function 'main': sampleTrace.c:12: error: 'struct ' has no member named '_addr'
Can you please suggest what wrong am i doing here?
You want to use si_addr
, as described by signal.h
.
The
<signal.h>
header shall define the siginfo_t type as a structure, which shall include at least the following members:/* ... */ void *si_addr Address of faulting instruction.
Try:
siginfo_t *info;
/* ... */
printf("%x", info->si_addr);
精彩评论