⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 elfcore.h

📁 能把所有线程的数据和环境记录到文件,方便调试.
💻 H
📖 第 1 页 / 共 2 页
字号:
/* Copyright (c) 2005-2007, Google Inc. * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are * met: * *     * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. *     * Redistributions in binary form must reproduce the above * copyright notice, this list of conditions and the following disclaimer * in the documentation and/or other materials provided with the * distribution. *     * Neither the name of Google Inc. nor the names of its * contributors may be used to endorse or promote products derived from * this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * --- * Author: Markus Gutschke */#ifndef _ELFCORE_H#define _ELFCORE_H/* We currently only support x86-32 and x86-64 on Linux. Porting to * other related platforms should not be difficult. */#if (defined(__i386__) || defined(__x86_64__) || defined(__ARM_ARCH_3__)) && \    defined(__linux)#include <stdarg.h>#include <stdint.h>#include <sys/types.h>#include "config.h"/* Define the DUMPER symbol to make sure that there is exactly one * core dumper built into the library. */#define DUMPER "ELF"/* By the time that we get a chance to read CPU registers in the * calling thread, they are already in a not particularly useful * state. Besides, there will be multiple frames on the stack that are * just making the core file confusing. To fix this problem, we take a * snapshot of the frame pointer, stack pointer, and instruction * pointer at an earlier time, and then insert these values into the * core file. */#if defined(__i386__) || defined(__x86_64__)  typedef struct i386_regs {    /* Normal (non-FPU) CPU registers            */  #ifdef __x86_64__    #define BP rbp    #define SP rsp    #define IP rip    uint64_t  r15,r14,r13,r12,rbp,rbx,r11,r10;    uint64_t  r9,r8,rax,rcx,rdx,rsi,rdi,orig_rax;    uint64_t  rip,cs,eflags;    uint64_t  rsp,ss;    uint64_t  fs_base, gs_base;    uint64_t  ds,es,fs,gs;  #else    #define BP ebp    #define SP esp    #define IP eip    uint32_t  ebx, ecx, edx, esi, edi, ebp, eax;    uint16_t  ds, __ds, es, __es;    uint16_t  fs, __fs, gs, __gs;    uint32_t  orig_eax, eip;    uint16_t  cs, __cs;    uint32_t  eflags, esp;    uint16_t  ss, __ss;  #endif  } i386_regs;#elif defined(__ARM_ARCH_3__)  typedef struct arm_regs {     /* General purpose registers                 */    #define BP uregs[11]        /* Frame pointer                             */    #define SP uregs[13]        /* Stack pointer                             */    #define IP uregs[15]        /* Program counter                           */    #define LR uregs[14]        /* Link register                             */    long uregs[18];  } arm_regs;#endif#if defined(__i386__) && defined(__GNUC__)  /* On x86 we provide an optimized version of the FRAME() macro, if the   * compiler supports a GCC-style asm() directive. This results in somewhat   * more accurate values for CPU registers.   */  typedef struct Frame {    struct i386_regs uregs;    int              errno_;    pid_t            tid;  } Frame;  #define FRAME(f) Frame f;                                           \                   do {                                               \                     f.errno_ = errno;                                \                     f.tid    = sys_gettid();                         \                     __asm__ volatile (                               \                       "push %%ebp\n"                                 \                       "push %%ebx\n"                                 \                       "mov  %%ebx,0(%%eax)\n"                        \                       "mov  %%ecx,4(%%eax)\n"                        \                       "mov  %%edx,8(%%eax)\n"                        \                       "mov  %%esi,12(%%eax)\n"                       \                       "mov  %%edi,16(%%eax)\n"                       \                       "mov  %%ebp,20(%%eax)\n"                       \                       "mov  %%eax,24(%%eax)\n"                       \                       "mov  %%ds,%%ebx\n"                            \                       "mov  %%ebx,28(%%eax)\n"                       \                       "mov  %%es,%%ebx\n"                            \                       "mov  %%ebx,32(%%eax)\n"                       \                       "mov  %%fs,%%ebx\n"                            \                       "mov  %%ebx,36(%%eax)\n"                       \                       "mov  %%gs,%%ebx\n"                            \                       "mov  %%ebx, 40(%%eax)\n"                      \                       "call 0f\n"                                    \                     "0:pop %%ebx\n"                                  \                       "add  $1f-0b,%%ebx\n"                          \                       "mov  %%ebx,48(%%eax)\n"                       \                       "mov  %%cs,%%ebx\n"                            \                       "mov  %%ebx,52(%%eax)\n"                       \                       "pushf\n"                                      \                       "pop  %%ebx\n"                                 \                       "mov  %%ebx,56(%%eax)\n"                       \                       "mov  %%esp,%%ebx\n"                           \                       "add  $8,%%ebx\n"                              \                       "mov  %%ebx,60(%%eax)\n"                       \                       "mov  %%ss,%%ebx\n"                            \                       "mov  %%ebx,64(%%eax)\n"                       \                       "pop  %%ebx\n"                                 \                       "pop  %%ebp\n"                                 \                     "1:"                                             \                       : : "a" (&f) : "memory");                      \                     } while (0)  #define SET_FRAME(f,r)                                              \                     do {                                             \                       errno = (f).errno_;                            \                       (r)   = (f).uregs;                             \                     } while (0)

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -