34
34
#define PTR_SANE(p) ((p) && (char*)(p) >= heap_start && (char*)(p) <= heap_end)
38
void safe_print_str(const char* name, const char* val, int max_len)
36
static char *heap_start;
39
extern char *__bss_start;
42
void my_init_stacktrace()
45
heap_start = (char*) &__bss_start;
49
void my_safe_print_str(const char* name, const char* val, int max_len)
40
51
char *heap_end= (char*) sbrk(0);
41
52
fprintf(stderr, "%s at %p ", name, val);
43
54
if (!PTR_SANE(val))
45
fprintf(stderr, " is invalid pointer\n");
56
fprintf(stderr, "is an invalid pointer\n");
52
63
fputc('\n', stderr);
55
#ifdef TARGET_OS_LINUX
58
#define SIGRETURN_FRAME_OFFSET 17
62
#define SIGRETURN_FRAME_OFFSET 23
65
#if defined(__alpha__) && defined(__GNUC__)
67
The only way to backtrace without a symbol table on alpha
68
is to find stq fp,N(sp), and the first byte
69
of the instruction opcode will give us the value of N. From this
70
we can find where the old value of fp is stored
73
#define MAX_INSTR_IN_FUNC 10000
75
inline uchar** find_prev_fp(uint32* pc, uchar** fp)
78
for (i = 0; i < MAX_INSTR_IN_FUNC; ++i,--pc)
80
uchar* p = (uchar*)pc;
81
if (p[2] == 222 && p[3] == 35)
83
return (uchar**)((uchar*)fp - *(short int*)p);
89
inline uint32* find_prev_pc(uint32* pc, uchar** fp)
92
for (i = 0; i < MAX_INSTR_IN_FUNC; ++i,--pc)
95
if (p[1] == 0 && p[2] == 94 && p[3] == -73)
97
uint32* prev_pc = (uint32*)*((fp+p[0]/sizeof(fp)));
103
#endif /* defined(__alpha__) && defined(__GNUC__) */
66
#if HAVE_BACKTRACE && (HAVE_BACKTRACE_SYMBOLS || HAVE_BACKTRACE_SYMBOLS_FD)
105
68
#if BACKTRACE_DEMANGLE
70
char __attribute__ ((weak)) *my_demangle(const char *mangled_name, int *status)
106
75
static void my_demangle_symbols(char **addrs, int n)
132
101
fprintf(stderr, "%s\n", addrs[i]);
139
static void backtrace_current_thread(void)
105
#endif /* BACKTRACE_DEMANGLE */
107
void my_print_stacktrace(uchar* stack_bottom, ulong thread_stack)
141
109
void *addrs[128];
142
110
char **strings= NULL;
143
111
int n = backtrace(addrs, array_elements(addrs));
112
fprintf(stderr, "stack_bottom = %p thread_stack 0x%lx\n",
113
stack_bottom, thread_stack);
144
114
#if BACKTRACE_DEMANGLE
145
115
if ((strings= backtrace_symbols(addrs, n)))
161
void print_stacktrace(uchar* stack_bottom, ulong thread_stack)
164
backtrace_current_thread();
129
#elif defined(TARGET_OS_LINUX)
132
#define SIGRETURN_FRAME_OFFSET 17
136
#define SIGRETURN_FRAME_OFFSET 23
139
#if defined(__alpha__) && defined(__GNUC__)
141
The only way to backtrace without a symbol table on alpha
142
is to find stq fp,N(sp), and the first byte
143
of the instruction opcode will give us the value of N. From this
144
we can find where the old value of fp is stored
147
#define MAX_INSTR_IN_FUNC 10000
149
inline uchar** find_prev_fp(uint32* pc, uchar** fp)
152
for (i = 0; i < MAX_INSTR_IN_FUNC; ++i,--pc)
154
uchar* p = (uchar*)pc;
155
if (p[2] == 222 && p[3] == 35)
157
return (uchar**)((uchar*)fp - *(short int*)p);
163
inline uint32* find_prev_pc(uint32* pc, uchar** fp)
166
for (i = 0; i < MAX_INSTR_IN_FUNC; ++i,--pc)
169
if (p[1] == 0 && p[2] == 94 && p[3] == -73)
171
uint32* prev_pc = (uint32*)*((fp+p[0]/sizeof(fp)));
177
#endif /* defined(__alpha__) && defined(__GNUC__) */
179
void my_print_stacktrace(uchar* stack_bottom, ulong thread_stack)
168
182
uint frame_count = 0, sigreturn_frame_count;
169
183
#if defined(__alpha__) && defined(__GNUC__)
281
295
#endif /* HAVE_STACKTRACE */
283
297
/* Produce a core for the thread */
285
#ifdef NOT_USED /* HAVE_LINUXTHREADS */
286
void write_core(int sig)
288
signal(sig, SIG_DFL);
289
if (fork() != 0) exit(1); /* Abort main program */
290
/* Core will be written at exit */
293
void write_core(int sig)
298
void my_write_core(int sig)
295
300
signal(sig, SIG_DFL);
405
414
#define SYMOPT_NO_PROMPTS 0
408
void print_stacktrace(uchar* unused1, ulong unused2)
417
void my_print_stacktrace(uchar* unused1, ulong unused2)
410
419
HANDLE hProcess= GetCurrentProcess();
411
420
HANDLE hThread= GetCurrentThread();
563
void safe_print_str(const char *name, const char *val, int len)
572
void my_safe_print_str(const char *name, const char *val, int len)
565
574
fprintf(stderr,"%s at %p", name, val);