Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue #33 stack traces do not work on OS X #266

Merged
merged 1 commit into from
Nov 27, 2011
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions src/task.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,13 @@
#include <libgen.h>
#include <unistd.h>
#include "julia.h"
#if defined(__APPLE__)
#include <execinfo.h>
#else
// This gives unwind only local unwinding options ==> faster code
#define UNW_LOCAL_ONLY
#include <libunwind.h>
#endif

/* This probing code is derived from Douglas Jones' user thread library */

Expand Down Expand Up @@ -445,6 +449,36 @@ static void init_task(jl_task_t *t)

void getFunctionInfo(char **name, int *line, const char **filename, size_t pointer);

#if defined(__APPLE__)
// stacktrace using execinfo
static jl_value_t *build_backtrace(void)
{
void *array[1024];
size_t ip;
size_t* p;
jl_array_t *a;
a = jl_alloc_cell_1d(0);
JL_GC_PUSH(&a);
int j = 0;

backtrace(array, 1023);
p = array;
while ((ip = *(p++)) != 0) {
char *func_name;
int line_num;
const char *file_name;
getFunctionInfo(&func_name, &line_num, &file_name, ip);
if (func_name != NULL) {
jl_array_grow_end(a, 3);
jl_arrayset(a, j, (jl_value_t*)jl_symbol(func_name)); j++;
jl_arrayset(a, j, (jl_value_t*)jl_symbol(file_name)); j++;
jl_arrayset(a, j, jl_box_long(line_num)); j++;
}
}
JL_GC_POP();
return (jl_value_t*)a;
}
#else
// stacktrace using libunwind
static jl_value_t *build_backtrace(void)
{
Expand Down Expand Up @@ -474,6 +508,7 @@ static jl_value_t *build_backtrace(void)
JL_GC_POP();
return (jl_value_t*)a;
}
#endif

#if 0
static _Unwind_Reason_Code tracer(void *ctx, void *arg)
Expand Down