Skip to content

Commit

Permalink
backtrace on apple
Browse files Browse the repository at this point in the history
  • Loading branch information
vtjnash committed Nov 26, 2011
1 parent 2e3cd7e commit 22a0823
Showing 1 changed file with 35 additions and 0 deletions.
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

1 comment on commit 22a0823

@JeffBezanson
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fantastic. Many thanks.

Please sign in to comment.