【发布时间】:2023-04-07 04:35:01
【问题描述】:
在编写一些用 C++ 打印回溯的代码时,我遇到了this answer,其中包括复制类型的定义:
/* This structure mirrors the one 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;
我不能只包含<asm/ucontext.h>,因为它被简单地定义为ucontext,它与<sys/ucontext.h> 中类似命名的类型发生冲突(包含在必要的<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;
我在这里只需要asm 版本中的struct sigcontext uc_mcontext 成员。有没有比复制这个结构更好的方法来检索该值?对我来说,这似乎令人难以置信的骇人听闻且容易出错。
【问题讨论】: