1
/* Copyright (C) 2000 MySQL AB
3
This program is free software; you can redistribute it and/or modify
4
it under the terms of the GNU General Public License as published by
5
the Free Software Foundation; version 2 of the License.
7
This program is distributed in the hope that it will be useful,
8
but WITHOUT ANY WARRANTY; without even the implied warranty of
9
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10
GNU General Public License for more details.
12
You should have received a copy of the GNU General Public License
13
along with this program; if not, write to the Free Software
14
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
1
/* - mode: c; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2
* vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
4
* Copyright (C) 2008 Sun Microsystems, Inc.
6
* This program is free software; you can redistribute it and/or modify
7
* it under the terms of the GNU General Public License as published by
8
* the Free Software Foundation; version 2 of the License.
10
* This program is distributed in the hope that it will be useful,
11
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
* GNU General Public License for more details.
15
* You should have received a copy of the GNU General Public License
16
* along with this program; if not, write to the Free Software
17
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
16
20
/* Workaround for Bug#32082: VOID redefinition on Win results in compile errors*/
17
21
#define DONT_DEFINE_VOID 1
60
64
#define SIGRETURN_FRAME_OFFSET 23
63
#if defined(__alpha__) && defined(__GNUC__)
65
The only way to backtrace without a symbol table on alpha
66
is to find stq fp,N(sp), and the first byte
67
of the instruction opcode will give us the value of N. From this
68
we can find where the old value of fp is stored
71
#define MAX_INSTR_IN_FUNC 10000
73
inline uchar** find_prev_fp(uint32* pc, uchar** fp)
76
for (i = 0; i < MAX_INSTR_IN_FUNC; ++i,--pc)
78
uchar* p = (uchar*)pc;
79
if (p[2] == 222 && p[3] == 35)
81
return (uchar**)((uchar*)fp - *(short int*)p);
87
inline uint32* find_prev_pc(uint32* pc, uchar** fp)
90
for (i = 0; i < MAX_INSTR_IN_FUNC; ++i,--pc)
93
if (p[1] == 0 && p[2] == 94 && p[3] == -73)
95
uint32* prev_pc = (uint32*)*((fp+p[0]/sizeof(fp)));
101
#endif /* defined(__alpha__) && defined(__GNUC__) */
103
68
#if BACKTRACE_DEMANGLE
104
69
static void my_demangle_symbols(char **addrs, int n)
173
138
__asm __volatile__ ("movl %%ebp,%0"
177
142
#ifdef __x86_64__
178
143
__asm __volatile__ ("movq %%rbp,%0"
182
147
#if defined(__alpha__) && defined(__GNUC__)
183
148
__asm __volatile__ ("mov $30,%0"
211
176
fprintf(stderr, "Stack range sanity check OK, backtrace follows:\n");
212
#if defined(__alpha__) && defined(__GNUC__)
213
fprintf(stderr, "Warning: Alpha stacks are difficult -\
214
will be taking some wild guesses, stack trace may be incorrect or \
215
terminate abruptly\n");
216
/* On Alpha, we need to get pc */
217
__asm __volatile__ ("bsr %0, do_next; do_next: "
220
#endif /* __alpha__ */
222
178
/* We are 1 frame above signal frame with NPTL and 2 frames above with LT */
223
179
sigreturn_frame_count = thd_lib_detected == THD_LIB_LT ? 2 : 1;
227
183
#if defined(__i386__) || defined(__x86_64__)
228
184
uchar** new_fp = (uchar**)*fp;
229
185
fprintf(stderr, "%p\n", frame_count == sigreturn_frame_count ?
230
*(fp + SIGRETURN_FRAME_OFFSET) : *(fp + 1));
186
*(fp + SIGRETURN_FRAME_OFFSET) : *(fp + 1));
231
187
#endif /* defined(__386__) || defined(__x86_64__) */
233
#if defined(__alpha__) && defined(__GNUC__)
234
uchar** new_fp = find_prev_fp(pc, fp);
235
if (frame_count == sigreturn_frame_count - 1)
242
pc = find_prev_pc(pc, fp);
244
fprintf(stderr, "%p\n", pc);
247
fprintf(stderr, "Not smart enough to deal with the rest\
254
fprintf(stderr, "Not smart enough to deal with the rest of this stack\n");
257
#endif /* defined(__alpha__) && defined(__GNUC__) */
258
189
if (new_fp <= fp )
260
191
fprintf(stderr, "New value of fp=%p failed sanity check,\