Author: Armin Rigo <ar...@tunes.org> Branch: vmprof-review Changeset: r78743:0f949cb3ea81 Date: 2015-08-02 16:49 +0200 http://bitbucket.org/pypy/pypy/changeset/0f949cb3ea81/
Log: Add some files from pypy/module/_vmprof/src diff --git a/rpython/rlib/rvmprof/cintf.py b/rpython/rlib/rvmprof/cintf.py --- a/rpython/rlib/rvmprof/cintf.py +++ b/rpython/rlib/rvmprof/cintf.py @@ -43,7 +43,6 @@ ## compilation_info=eci, _nowrapper=True) -def vmprof_init(): pass def vmprof_enable(fileno, interval_usec): return 0 def vmprof_ignore_signals(ignore): pass diff --git a/rpython/rlib/rvmprof/src/rvmprof.c b/rpython/rlib/rvmprof/src/rvmprof.c --- a/rpython/rlib/rvmprof/src/rvmprof.c +++ b/rpython/rlib/rvmprof/src/rvmprof.c @@ -1,11 +1,46 @@ - +#define _GNU_SOURCE 1 +#include "common_header.h" #ifndef VMPROF_ADDR_OF_TRAMPOLINE # error "RPython program using rvmprof, but not calling vmprof_execute_code()" #endif +#include "rvmprof_getpc.h" +#include "rvmprof_base.h" +#include <dlfcn.h> + + +/************************************************************/ + +// functions copied from libunwind using dlopen + +static int (*unw_get_reg)(unw_cursor_t*, int, unw_word_t*) = NULL; +static int (*unw_step)(unw_cursor_t*) = NULL; +static int (*unw_init_local)(unw_cursor_t *, unw_context_t *) = NULL; +static int (*unw_get_proc_info)(unw_cursor_t *, unw_proc_info_t *) = NULL; + + char *rpython_vmprof_init(void) { - xxxx; + if (!unw_get_reg) { + void *libhandle; + + if (!(libhandle = dlopen("libunwind.so", RTLD_LAZY | RTLD_LOCAL))) + goto error; + if (!(unw_get_reg = dlsym(libhandle, "_ULx86_64_get_reg"))) + goto error; + if (!(unw_get_proc_info = dlsym(libhandle, "_ULx86_64_get_proc_info"))) + goto error; + if (!(unw_init_local = dlsym(libhandle, "_ULx86_64_init_local"))) + goto error; + if (!(unw_step = dlsym(libhandle, "_ULx86_64_step"))) + goto error; + } + return NULL; + + error: + return dlerror(); } + +/************************************************************/ diff --git a/rpython/rlib/rvmprof/src/rvmprof_base.h b/rpython/rlib/rvmprof/src/rvmprof_base.h new file mode 100644 --- /dev/null +++ b/rpython/rlib/rvmprof/src/rvmprof_base.h @@ -0,0 +1,90 @@ +#include <stddef.h> +#include <stdint.h> +#include <ucontext.h> + +// copied from libunwind.h + +typedef enum + { + UNW_X86_64_RAX, + UNW_X86_64_RDX, + UNW_X86_64_RCX, + UNW_X86_64_RBX, + UNW_X86_64_RSI, + UNW_X86_64_RDI, + UNW_X86_64_RBP, + UNW_X86_64_RSP, + UNW_X86_64_R8, + UNW_X86_64_R9, + UNW_X86_64_R10, + UNW_X86_64_R11, + UNW_X86_64_R12, + UNW_X86_64_R13, + UNW_X86_64_R14, + UNW_X86_64_R15, + UNW_X86_64_RIP, +#ifdef CONFIG_MSABI_SUPPORT + UNW_X86_64_XMM0, + UNW_X86_64_XMM1, + UNW_X86_64_XMM2, + UNW_X86_64_XMM3, + UNW_X86_64_XMM4, + UNW_X86_64_XMM5, + UNW_X86_64_XMM6, + UNW_X86_64_XMM7, + UNW_X86_64_XMM8, + UNW_X86_64_XMM9, + UNW_X86_64_XMM10, + UNW_X86_64_XMM11, + UNW_X86_64_XMM12, + UNW_X86_64_XMM13, + UNW_X86_64_XMM14, + UNW_X86_64_XMM15, + UNW_TDEP_LAST_REG = UNW_X86_64_XMM15, +#else + UNW_TDEP_LAST_REG = UNW_X86_64_RIP, +#endif + + /* XXX Add other regs here */ + + /* frame info (read-only) */ + UNW_X86_64_CFA, + + UNW_TDEP_IP = UNW_X86_64_RIP, + UNW_TDEP_SP = UNW_X86_64_RSP, + UNW_TDEP_BP = UNW_X86_64_RBP, + UNW_TDEP_EH = UNW_X86_64_RAX + } +x86_64_regnum_t; + +typedef uint64_t unw_word_t; + +#define UNW_TDEP_CURSOR_LEN 127 + +typedef struct unw_cursor + { + unw_word_t opaque[UNW_TDEP_CURSOR_LEN]; + } +unw_cursor_t; + +#define UNW_REG_IP UNW_X86_64_RIP +#define UNW_REG_SP UNW_X86_64_RSP + +typedef ucontext_t unw_context_t; + +typedef struct unw_proc_info + { + unw_word_t start_ip; /* first IP covered by this procedure */ + unw_word_t end_ip; /* first IP NOT covered by this procedure */ + unw_word_t lsda; /* address of lang.-spec. data area (if any) */ + unw_word_t handler; /* optional personality routine */ + unw_word_t gp; /* global-pointer value for this procedure */ + unw_word_t flags; /* misc. flags */ + + int format; /* unwind-info format (arch-specific) */ + int unwind_info_size; /* size of the information (if applicable) */ + void *unwind_info; /* unwind-info (arch-specific) */ + } +unw_proc_info_t; + +// end of copy diff --git a/rpython/rlib/rvmprof/src/rvmprof_config.h b/rpython/rlib/rvmprof/src/rvmprof_config.h new file mode 100644 --- /dev/null +++ b/rpython/rlib/rvmprof/src/rvmprof_config.h @@ -0,0 +1,6 @@ +#define HAVE_SYS_UCONTEXT_H +#if defined(__FreeBSD__) || defined(__APPLE__) +#define PC_FROM_UCONTEXT uc_mcontext.mc_rip +#else +#define PC_FROM_UCONTEXT uc_mcontext.gregs[REG_RIP] +#endif diff --git a/pypy/module/_vmprof/src/getpc.h b/rpython/rlib/rvmprof/src/rvmprof_getpc.h rename from pypy/module/_vmprof/src/getpc.h rename to rpython/rlib/rvmprof/src/rvmprof_getpc.h --- a/pypy/module/_vmprof/src/getpc.h +++ b/rpython/rlib/rvmprof/src/rvmprof_getpc.h @@ -44,7 +44,7 @@ #ifndef BASE_GETPC_H_ #define BASE_GETPC_H_ -#include "config.h" +#include "rvmprof_config.h" // On many linux systems, we may need _GNU_SOURCE to get access to // the defined constants that define the register we want to see (eg _______________________________________________ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit