File tree 4 files changed +73
-43
lines changed
4 files changed +73
-43
lines changed Original file line number Diff line number Diff line change @@ -264,6 +264,15 @@ set_property(TARGET vm_static vm_shared APPEND PROPERTY
264
264
COMPILE_FLAGS "${TARGET_VM_FLAGS} "
265
265
)
266
266
267
+ add_library (stack_collector OBJECT EXCLUDE_FROM_ALL lj_stack_collector.c)
268
+ set_property (TARGET stack_collector APPEND PROPERTY
269
+ COMPILE_FLAGS "${TARGET_C_FLAGS} "
270
+ )
271
+ set_property (TARGET stack_collector APPEND PROPERTY
272
+ POSITION_INDEPENDENT_CODE ON
273
+ )
274
+ target_link_libraries (stack_collector PRIVATE ${LIBUNWIND_LIBRARIES} )
275
+
267
276
# Platform core.
268
277
add_library (core_static OBJECT EXCLUDE_FROM_ALL ${SOURCES_CORE} )
269
278
add_library (core_shared OBJECT EXCLUDE_FROM_ALL ${SOURCES_CORE} )
@@ -283,10 +292,7 @@ add_dependencies(core_shared buildvm_output)
283
292
# Compiling and linking library binaries (static, shared).
284
293
285
294
list (APPEND TARGET_LIBS m)
286
-
287
- if (NOT LUAJIT_DISABLE_SYSPROF)
288
- list (APPEND TARGET_LIBS ${LIBUNWIND_LIBRARIES} )
289
- endif ()
295
+ list (APPEND TARGET_LIBS stack_collector)
290
296
291
297
set (LIB_OBJECTS_STATIC
292
298
$<TARGET_OBJECTS:vm_static>
Original file line number Diff line number Diff line change
1
+ /*
2
+ ** Libunwind-based stack collector.
3
+ */
4
+ #include "lj_stack_collector.h"
5
+
6
+ /*
7
+ ** We only need local unwinding, then a special implementation
8
+ ** can be selected which may run much faster than the generic
9
+ ** implementation which supports both kinds of unwinding, local
10
+ ** and remote.
11
+ */
12
+ #define UNW_LOCAL_ONLY
13
+ #include <libunwind.h>
14
+
15
+ ssize_t collect_stack (void * * buffer , int size )
16
+ {
17
+ int frame_no = 0 ;
18
+ unw_context_t unw_ctx ;
19
+ unw_cursor_t unw_cur ;
20
+
21
+ int rc = unw_getcontext (& unw_ctx );
22
+ if (rc != 0 )
23
+ return -1 ;
24
+
25
+ rc = unw_init_local (& unw_cur , & unw_ctx );
26
+ if (rc != 0 )
27
+ return -1 ;
28
+
29
+ for (; frame_no < size ; ++ frame_no ) {
30
+ unw_word_t ip ;
31
+ rc = unw_get_reg (& unw_cur , UNW_REG_IP , & ip );
32
+ if (rc != 0 )
33
+ return -1 ;
34
+
35
+ buffer [frame_no ] = (void * )ip ;
36
+ rc = unw_step (& unw_cur );
37
+ if (rc <= 0 )
38
+ break ;
39
+ }
40
+ return frame_no ;
41
+ }
Original file line number Diff line number Diff line change
1
+ /*
2
+ ** Libunwind-based stack collector.
3
+ **
4
+ ** XXX: This module must be compiled and linked separately from
5
+ ** other LuaJIT sources. Otherwise, the definitions from
6
+ ** libunwind and libgcc can collide, leading to unwinding working
7
+ ** improperly. Compiling this module separately ensures that the
8
+ ** only place where libunwind is used is here.
9
+ */
10
+
11
+ #ifndef _LJ_STACK_COLLECTOR_H
12
+ #define _LJ_STACK_COLLECTOR_H
13
+
14
+ #include <sys/types.h>
15
+
16
+ ssize_t collect_stack (void * * buffer , int size );
17
+
18
+ #endif
Original file line number Diff line number Diff line change 20
20
#include "lj_trace.h"
21
21
#endif
22
22
23
+ #ifndef LUAJIT_EXTERNAL_SYSPROF_BACKTRACER
24
+ #include "lj_stack_collector.h"
25
+ #endif
26
+
23
27
#include "lj_wbuf.h"
24
28
#include "lj_profile_timer.h"
25
29
#include "lj_symtab.h"
26
30
27
31
#include <pthread.h>
28
32
#include <errno.h>
29
33
30
- #ifndef LUAJIT_EXTERNAL_SYSPROF_BACKTRACER
31
- /*
32
- ** We only need local unwinding, then a special implementation
33
- ** can be selected which may run much faster than the generic
34
- ** implementation which supports both kinds of unwinding, local
35
- ** and remote.
36
- */
37
- #define UNW_LOCAL_ONLY
38
- #include <libunwind.h>
39
- #endif
40
-
41
34
/*
42
35
** Number of profiler frames we need to omit during stack
43
36
** unwinding.
@@ -97,34 +90,6 @@ static struct sysprof sysprof = {0};
97
90
98
91
#ifndef LUAJIT_EXTERNAL_SYSPROF_BACKTRACER
99
92
100
- static ssize_t collect_stack (void * * buffer , int size )
101
- {
102
- int frame_no = 0 ;
103
- unw_context_t unw_ctx ;
104
- unw_cursor_t unw_cur ;
105
-
106
- int rc = unw_getcontext (& unw_ctx );
107
- if (rc != 0 )
108
- return -1 ;
109
-
110
- rc = unw_init_local (& unw_cur , & unw_ctx );
111
- if (rc != 0 )
112
- return -1 ;
113
-
114
- for (; frame_no < size ; ++ frame_no ) {
115
- unw_word_t ip ;
116
- rc = unw_get_reg (& unw_cur , UNW_REG_IP , & ip );
117
- if (rc != 0 )
118
- return -1 ;
119
-
120
- buffer [frame_no ] = (void * )ip ;
121
- rc = unw_step (& unw_cur );
122
- if (rc <= 0 )
123
- break ;
124
- }
125
- return frame_no ;
126
- }
127
-
128
93
static void default_backtrace_host (void * (writer )(int frame_no , void * addr ))
129
94
{
130
95
static void * backtrace_buf [SYSPROF_BACKTRACE_FRAME_MAX ] = {};
You can’t perform that action at this time.
0 commit comments