获取在i386 arch下运行的进程中的cpu_subtype_t

时间:2016-01-28 09:11:12

标签: c macos lldb coredump mach-o

我使用一些C代码从基于Mach-o的进程生成coredump文件。

然而,在为32位进程生成coredump之后,我在lldb调试器加载它时会得到一些解析损坏:

(lldb) target create --core "/tmp/core_pid_1354"
Core file '/tmp/x/core.1354' (unknown-mach-32) was loaded.

这个未知的32架构问题,源自struct mach_header中的错误cpu_subtype。

为了在以下方法中获取cpu_type + cpu_subtype:

struct current_arch cpuArch = {0};
int mib[CTL_MAXNAME];
size_t mibLen;
size_t cpuTypeSize;
pid_t pid = getpid();
mibLen  = CTL_MAXNAME;
int err = sysctlnametomib("sysctl.proc_cputype", mib, &mibLen);
if (err) {
    log_error("coultn't get mib for cpu type using sysctlnametomib. err = %d ", err);
    return KERN_FAILURE;
}

mib[mibLen] = pid;
mibLen += 0x1;
cpuTypeSize = sizeof(cpuArch.type);
err = sysctl(mib, (u_int)mibLen, &(cpuArch.type), &cpuTypeSize, 0x0, 0x0);
if (err) {
    log_error("coultn't get cpu_type+cpu_subtype for mib using syctl. err = %d ", err);
    return KERN_FAILURE;
}

*cpu_type = cpuArch.type;
*cpu_subtype = cpuArch.subtype;
return KERN_SUCCESS;

我已经在通用格式(32/64位)下编译了核心转储工具。并且当在arch = i386下尝试时,我得到cpu_subtype = 0,这是i386的无效子类型。 我希望得到在machine.h文件(= 3)中定义的宏CPU_SUBTYPE_386的值:

#define CPU_SUBTYPE_INTEL(f, m) ((cpu_subtype_t) (f) + ((m) << 4))
#define CPU_SUBTYPE_386                 CPU_SUBTYPE_INTEL(3, 0)

知道我的代码中有什么错误来获取cpu_subtype_t?

0 个答案:

没有答案