forked from LuaJIT/LuaJIT
-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7817ca8
commit 04f0fed
Showing
4 changed files
with
75 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
/* | ||
** Libunwind-based stack collector. | ||
*/ | ||
#include "lj_stack_collector.h" | ||
|
||
/* | ||
** We only need local unwinding, then a special implementation | ||
** can be selected which may run much faster than the generic | ||
** implementation which supports both kinds of unwinding, local | ||
** and remote. | ||
*/ | ||
#define UNW_LOCAL_ONLY | ||
#include <libunwind.h> | ||
|
||
ssize_t collect_stack(void **buffer, int size) | ||
{ | ||
int frame_no = 0; | ||
unw_context_t unw_ctx; | ||
unw_cursor_t unw_cur; | ||
|
||
int rc = unw_getcontext(&unw_ctx); | ||
if (rc != 0) | ||
return -1; | ||
|
||
rc = unw_init_local(&unw_cur, &unw_ctx); | ||
if (rc != 0) | ||
return -1; | ||
|
||
for (; frame_no < size; ++frame_no) { | ||
unw_word_t ip; | ||
rc = unw_get_reg(&unw_cur, UNW_REG_IP, &ip); | ||
if (rc != 0) | ||
return -1; | ||
|
||
buffer[frame_no] = (void *)ip; | ||
rc = unw_step(&unw_cur); | ||
if (rc <= 0) | ||
break; | ||
} | ||
return frame_no; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
/* | ||
** Libunwind-based stack collector. | ||
** | ||
** XXX: This module must be compiled and linked separately from | ||
** other LuaJIT sources. Otherwise, the definitions from | ||
** libunwind and libgcc can collide, leading to unwinding working | ||
** improperly. Compiling this module separately ensures that the | ||
** only place where libunwind is used is here. | ||
*/ | ||
|
||
#ifndef _LJ_STACK_COLLECTOR_H | ||
#define _LJ_STACK_COLLECTOR_H | ||
|
||
#include <sys/types.h> | ||
|
||
ssize_t collect_stack(void **buffer, int size); | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters