copy over changes made to pypy · vmprof/vmprof-python@cbafe71 · GitHub
Skip to content

Commit cbafe71

Browse files
committed
copy over changes made to pypy
1 parent dfae3ea commit cbafe71

8 files changed

Lines changed: 72 additions & 85 deletions

File tree

src/symboltable.c

Lines changed: 2 additions & 2 deletions

src/unwind/vmprof_unwind.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,12 @@ typedef int32_t unw_sword_t;
1515
#define UNW_REG_IP 16
1616
typedef uint64_t unw_word_t;
1717
typedef int64_t unw_sword_t;
18+
#else
19+
// not supported platform
1820
#endif
1921

2022

23+
#ifdef VMP_SUPPORTS_NATIVE_PROFILING
2124
#define UNW_TDEP_CURSOR_LEN 127
2225

2326
typedef struct unw_cursor
@@ -42,4 +45,4 @@ typedef struct unw_proc_info
4245

4346
// end of copy
4447

45-
48+
#endif

src/vmprof.h

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,10 @@
2929

3030
#define DYN_JIT_FLAG 0xbeefbeef
3131

32-
#ifdef VMPROF_UNIX
33-
#define VMP_SUPPORTS_NATIVE_PROFILING
32+
#ifdef _WIN32
33+
#ifndef VMPROF_WINDOWS
34+
#define VMPROF_WINDOWS
35+
#endif
3436
#endif
3537

3638
#ifdef __x86_64__
@@ -39,6 +41,13 @@
3941
#define X86_32
4042
#endif
4143

44+
#ifdef VMPROF_UNIX
45+
#if defined(X86_64) || defined(X86_32)
46+
#define VMP_SUPPORTS_NATIVE_PROFILING
47+
#endif
48+
#endif
49+
50+
4251
#ifdef RPYTHON_VMPROF
4352
// only for pypy
4453
#include "rvmprof.h"

src/vmprof_common.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,12 +190,16 @@ intptr_t vmprof_get_traceback(void *stack, void *ucontext,
190190
if (stack == NULL) {
191191
stack = get_vmprof_stack();
192192
}
193+
#ifdef VMP_SUPPORTS_NATIVE_PROFILING
193194
enabled = vmp_native_enabled();
194195
vmp_native_disable();
196+
#endif
195197
n = get_stack_trace(stack, result_p, result_length - 2, pc);
198+
#ifdef VMP_SUPPORTS_NATIVE_PROFILING
196199
if (enabled) {
197200
vmp_native_enable();
198201
}
202+
#endif
199203
return (intptr_t)n;
200204
}
201205
#endif

src/vmprof_config.h

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,30 @@
1-
#pragma once
1+
#if !defined(__OpenBSD__)
2+
# define HAVE_SYS_UCONTEXT_H
3+
#else
4+
# define HAVE_SIGNAL_H
5+
#endif
26

3-
#define HAVE_SYS_UCONTEXT_H
4-
#if defined(__FreeBSD__) || defined(__APPLE__)
5-
#define PC_FROM_UCONTEXT uc_mcontext.mc_rip
7+
#if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__DragonFly__)
8+
#ifdef __i386__
9+
#define PC_FROM_UCONTEXT uc_mcontext.mc_eip
10+
#else
11+
#define PC_FROM_UCONTEXT uc_mcontext.mc_rip
12+
#endif
13+
#elif defined(__OpenBSD__)
14+
#define PC_FROM_UCONTEXT sc_rip
15+
#elif defined( __APPLE__)
16+
#if ((ULONG_MAX) == (UINT_MAX))
17+
#define PC_FROM_UCONTEXT uc_mcontext->__ss.__eip
18+
#else
19+
#define PC_FROM_UCONTEXT uc_mcontext->__ss.__rip
20+
#endif
21+
#elif defined(__arm__)
22+
#define PC_FROM_UCONTEXT uc_mcontext.arm_ip
23+
#elif defined(__linux) && defined(__i386) && defined(__GNUC__)
24+
#define PC_FROM_UCONTEXT uc_mcontext.gregs[REG_EIP]
25+
#elif defined(__s390x__)
26+
#define PC_FROM_UCONTEXT uc_mcontext.psw.addr
627
#else
7-
#define PC_FROM_UCONTEXT uc_mcontext.gregs[REG_RIP]
28+
/* linux, gnuc */
29+
#define PC_FROM_UCONTEXT uc_mcontext.gregs[REG_RIP]
830
#endif

src/vmprof_get_custom_offset.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
#pragma once
22

3+
#include "vmprof.h"
4+
35
#ifdef VMPROF_WINDOWS
46
#include "msiinttypes/stdint.h"
57
#else

src/vmprof_getpc.h

Lines changed: 20 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -43,15 +43,6 @@
4343

4444
#ifndef BASE_GETPC_H_
4545
#define BASE_GETPC_H_
46-
47-
#if ((ULONG_MAX) == (UINT_MAX))
48-
# define IS32BIT
49-
#else
50-
# define IS64BIT
51-
#endif
52-
53-
#include "vmprof_config.h"
54-
5546
// On many linux systems, we may need _GNU_SOURCE to get access to
5647
// the defined constants that define the register we want to see (eg
5748
// REG_EIP). Note this #define must come first!
@@ -60,8 +51,11 @@
6051
// It will cause problems for FreeBSD though!, because it turns off
6152
// the needed __BSD_VISIBLE.
6253
#ifdef __APPLE__
54+
#include <limits.h>
6355
#define _XOPEN_SOURCE 500
64-
#endif // __APPLE__
56+
#endif
57+
58+
#include "vmprof_config.h"
6559

6660
#include <string.h> // for memcmp
6761
#if defined(HAVE_SYS_UCONTEXT_H)
@@ -71,6 +65,10 @@
7165
#elif defined(HAVE_CYGWIN_SIGNAL_H)
7266
#include <cygwin/signal.h>
7367
typedef ucontext ucontext_t;
68+
#elif defined(HAVE_SIGNAL_H)
69+
#include <signal.h>
70+
#else
71+
# error "don't know how to get the pc on this platform"
7472
#endif
7573

7674

@@ -117,52 +115,8 @@ struct CallUnrollInfo {
117115
// PC_FROM_UCONTEXT in config.h. The only thing we need to do here,
118116
// then, is to do the magic call-unrolling for systems that support it.
119117

120-
// -- Special case 1: linux x86, for which we have CallUnrollInfo
121-
#if defined(__linux) && defined(__i386) && defined(__GNUC__)
122-
static const struct CallUnrollInfo callunrollinfo[] = {
123-
// Entry to a function: push %ebp; mov %esp,%ebp
124-
// Top-of-stack contains the caller IP.
125-
{ 0,
126-
{0x55, 0x89, 0xe5}, 3,
127-
0
128-
},
129-
// Entry to a function, second instruction: push %ebp; mov %esp,%ebp
130-
// Top-of-stack contains the old frame, caller IP is +4.
131-
{ -1,
132-
{0x55, 0x89, 0xe5}, 3,
133-
4
134-
},
135-
// Return from a function: RET.
136-
// Top-of-stack contains the caller IP.
137-
{ 0,
138-
{0xc3}, 1,
139-
0
140-
}
141-
};
142-
143-
void* GetPC(ucontext_t *signal_ucontext) {
144-
// See comment above struct CallUnrollInfo. Only try instruction
145-
// flow matching if both eip and esp looks reasonable.
146-
const int eip = signal_ucontext->uc_mcontext.gregs[REG_EIP];
147-
const int esp = signal_ucontext->uc_mcontext.gregs[REG_ESP];
148-
if ((eip & 0xffff0000) != 0 && (~eip & 0xffff0000) != 0 &&
149-
(esp & 0xffff0000) != 0) {
150-
char* eip_char = (char*)(eip);
151-
int i;
152-
for (i = 0; i < sizeof(callunrollinfo)/sizeof(*callunrollinfo); ++i) {
153-
if (!memcmp(eip_char + callunrollinfo[i].pc_offset,
154-
callunrollinfo[i].ins, callunrollinfo[i].ins_size)) {
155-
// We have a match.
156-
void **retaddr = (void**)(esp + callunrollinfo[i].return_sp_offset);
157-
return *retaddr;
158-
}
159-
}
160-
}
161-
return (void*)eip;
162-
}
163-
164-
// Special case #2: Windows, which has to do something totally different.
165-
#elif defined(_WIN32) || defined(__CYGWIN__) || defined(__CYGWIN32__) || defined(__MINGW32__)
118+
// Special case Windows, which has to do something totally different.
119+
#if defined(_WIN32) || defined(__CYGWIN__) || defined(__CYGWIN32__) || defined(__MINGW32__)
166120
// If this is ever implemented, probably the way to do it is to have
167121
// profiler.cc use a high-precision timer via timeSetEvent:
168122
// http://msdn2.microsoft.com/en-us/library/ms712713.aspx
@@ -172,31 +126,24 @@ void* GetPC(ucontext_t *signal_ucontext) {
172126
// how we'd get the PC (using StackWalk64?)
173127
// http://msdn2.microsoft.com/en-us/library/ms680650.aspx
174128

175-
#include "base/logging.h" // for RAW_LOG
176-
#ifndef HAVE_CYGWIN_SIGNAL_H
177-
typedef int ucontext_t;
178-
#endif
129+
// #include "base/logging.h" // for RAW_LOG
130+
// #ifndef HAVE_CYGWIN_SIGNAL_H
131+
// typedef int ucontext_t;
132+
// #endif
179133

180-
void* GetPC(ucontext_t *signal_ucontext) {
181-
RAW_LOG(ERROR, "GetPC is not yet implemented on Windows\n");
134+
static intptr_t GetPC(ucontext_t *signal_ucontext) {
135+
// RAW_LOG(ERROR, "GetPC is not yet implemented on Windows\n");
136+
fprintf(stderr, "GetPC is not yet implemented on Windows\n");
182137
return NULL;
183138
}
184139

185140
// Normal cases. If this doesn't compile, it's probably because
186141
// PC_FROM_UCONTEXT is the empty string. You need to figure out
187142
// the right value for your system, and add it to the list in
188-
// configure.ac (or set it manually in your config.h).
189-
#else
190-
void* GetPC(ucontext_t *signal_ucontext) {
191-
#ifdef __APPLE__
192-
#ifdef IS32BIT
193-
return (void*)(signal_ucontext->uc_mcontext->__ss.__eip);
194-
#else
195-
return (void*)(signal_ucontext->uc_mcontext->__ss.__rip);
196-
#endif
143+
// vmrpof_config.h
197144
#else
198-
return (void*)signal_ucontext->PC_FROM_UCONTEXT; // defined in config.h
199-
#endif
145+
static intptr_t GetPC(ucontext_t *signal_ucontext) {
146+
return signal_ucontext->PC_FROM_UCONTEXT; // defined in config.h
200147
}
201148

202149
#endif

src/vmprof_main_win32.h

Lines changed: 2 additions & 2 deletions

0 commit comments

Comments
 (0)