Debian Codegraph @

rpython/rlib/rvmprof/src/shared/vmprof_get_custom_offset.h

raw symbols SCIP
1 #pragma once
2
3 #ifdef PYPY_JIT_CODEMAP
4 #include "vmprof.h"
5
6 #ifdef VMPROF_WINDOWS
7 #include "msiinttypes/stdint.h"
8 #else
9 #include <stdint.h>
10 #endif
11
12 void *pypy_find_codemap_at_addr(long addr, long *start_addr);
13 long pypy_yield_codemap_at_addr(void *codemap_raw, long addr,
14 long *current_pos_addr);
15
16 #define MAX_INLINE_DEPTH 384
17
18 long vmprof_write_header_for_jit_addr(intptr_t *result, long n,
19 intptr_t addr, int max_depth)
20 {
21 void *codemap;
22 long current_pos = 0;
23 intptr_t ident, local_stack[MAX_INLINE_DEPTH];
24 long m;
25 long start_addr = 0;
26
27 codemap = pypy_find_codemap_at_addr(addr, &start_addr);
28 if (codemap == NULL || n >= max_depth - 2)
29 // not a jit code at all or almost max depth
30 return n;
31
32 // modify the last entry to point to start address and not the random one
33 // in the middle
34 result[n++] = VMPROF_ASSEMBLER_TAG;
35 result[n++] = start_addr;
36
37 // build the list of code idents corresponding to the current
38 // position inside this particular piece of assembler. If (very
39 // unlikely) we get more than MAX_INLINE_DEPTH recursion levels
40 // all inlined inside this single piece of assembler, then stop:
41 // there will be some missing frames then. Otherwise, we need to
42 // first collect 'local_stack' and then write it to 'result' in the
43 // opposite order, stopping at 'max_depth'. Previous versions of
44 // the code would write the oldest calls and then stop---whereas
45 // what we really need it to write the newest calls and then stop.
46 m = 0;
47 while (m < MAX_INLINE_DEPTH) {
48 ident = pypy_yield_codemap_at_addr(codemap, addr, &current_pos);
49 if (ident == -1)
50 // finish
51 break;
52 if (ident == 0)
53 continue; // not main codemap
54 local_stack[m++] = ident;
55 }
56 while (m > 0 && n < max_depth) {
57 result[n++] = VMPROF_JITTED_TAG;
58 result[n++] = local_stack[--m];
59 }
60 return n;
61 }
62 #endif