C编程,无法从siginfo获取字段

发布于 2024-11-29 20:57:14 字数 2293 浏览 0 评论 0原文

我想访问 - _addr 驻留在 _sigfault 中,它是 siginfo 结构的一部分。 asm-generic/siginfo 中定义的 siginfo 结构如下 -

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 timers */
                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;

我无法访问 _addr 字段。以下是我为访问它而编写的代码 - siginfo_t sigInfo。 printf("%x",sigInfo._sifields._sigfault._addr);

我在编译过程中遇到的错误是 - SampleTrace.c:在函数“main”中: SampleTrace.c:12:错误:“struct”没有名为“_addr”的成员,

您能建议我在这里做错了什么吗?

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 timers */
                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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

溺ぐ爱和你が 2024-12-06 20:57:14

您想要使用si_addr,如<所述代码>signal.h

标头应将 siginfo_t 类型定义为结构体,
其中至少应包括以下成员:

<前><代码>/* ... */
void *si_addr 错误指令的地址。

尝试:

siginfo_t *info;
/* ... */
printf("%x", info->si_addr);

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);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文