mirror of
https://github.com/MariaDB/server.git
synced 2025-01-16 12:02:42 +01:00
a821703912
BitKeeper/etc/ignore: auto-union BitKeeper/etc/logging_ok: auto-union BitKeeper/deleted/.del-compile-netware-standard: Delete: netware/BUILD/compile-netware-standard BitKeeper/deleted/.del-mwenv: Delete: netware/BUILD/mwenv BitKeeper/deleted/.del-nwbootstrap: Delete: netware/BUILD/nwbootstrap BitKeeper/deleted/.del-compile-AUTOTOOLS: Delete: netware/BUILD/compile-AUTOTOOLS BitKeeper/deleted/.del-compile-linux-tools: Delete: netware/BUILD/compile-linux-tools BitKeeper/deleted/.del-compile-netware-END: Delete: netware/BUILD/compile-netware-END BitKeeper/deleted/.del-compile-netware-START: Delete: netware/BUILD/compile-netware-START BitKeeper/deleted/.del-compile-netware-all: Delete: netware/BUILD/compile-netware-all BitKeeper/deleted/.del-compile-netware-debug: Delete: netware/BUILD/compile-netware-debug BitKeeper/deleted/.del-mwasmnlm~bc5746809d67feb5: Auto merged BitKeeper/deleted/.del-mwenv~35c8b56062f4b6aa: Auto merged BitKeeper/deleted/.del-mwccnlm~be63afd25a14c3f: Auto merged BitKeeper/deleted/.del-mwldnlm~efb26c57cba3c980: Auto merged BitKeeper/deleted/.del-netware.patch~f70a3a965f54d9ee: Auto merged Docs/internals.texi: Auto merged VC++Files/bdb/bdb.dsp: Auto merged VC++Files/bdb/build_win32/Berkeley_DB.dsw: Auto merged VC++Files/bdb/build_win32/db_archive.dsp: Auto merged VC++Files/bdb/build_win32/db_buildall.dsp: Auto merged VC++Files/bdb/build_win32/db_checkpoint.dsp: Auto merged VC++Files/bdb/build_win32/db_deadlock.dsp: Auto merged VC++Files/bdb/build_win32/db_dll.dsp: Auto merged VC++Files/bdb/build_win32/db_dump.dsp: Auto merged VC++Files/bdb/build_win32/db_java.dsp: Auto merged VC++Files/bdb/build_win32/db_load.dsp: Auto merged VC++Files/bdb/build_win32/db_printlog.dsp: Auto merged VC++Files/bdb/build_win32/db_recover.dsp: Auto merged VC++Files/bdb/build_win32/db_stat.dsp: Auto merged VC++Files/bdb/build_win32/db_static.dsp: Auto merged VC++Files/bdb/build_win32/db_static1.dsp: Auto merged VC++Files/bdb/build_win32/db_tcl.dsp: Auto merged VC++Files/bdb/build_win32/db_test.dsp: Auto merged VC++Files/bdb/build_win32/db_upgrade.dsp: Auto merged VC++Files/bdb/build_win32/db_verify.dsp: Auto merged VC++Files/bdb/build_win32/ex_access.dsp: Auto merged VC++Files/bdb/build_win32/ex_btrec.dsp: Auto merged VC++Files/bdb/build_win32/ex_env.dsp: Auto merged VC++Files/bdb/build_win32/ex_lock.dsp: Auto merged VC++Files/bdb/build_win32/ex_mpool.dsp: Auto merged VC++Files/bdb/build_win32/ex_tpcb.dsp: Auto merged VC++Files/bdb/build_win32/excxx_access.dsp: Auto merged VC++Files/bdb/build_win32/excxx_btrec.dsp: Auto merged VC++Files/bdb/build_win32/excxx_env.dsp: Auto merged VC++Files/bdb/build_win32/excxx_lock.dsp: Auto merged VC++Files/bdb/build_win32/excxx_mpool.dsp: Auto merged VC++Files/bdb/build_win32/excxx_tpcb.dsp: Auto merged VC++Files/client/mysql.dsp: Auto merged VC++Files/client/mysqladmin.dsp: Auto merged VC++Files/client/mysqlcheck.dsp: Auto merged VC++Files/client/mysqlclient.dsp: Auto merged VC++Files/client/mysqlclient.dsw: Auto merged VC++Files/client/mysqldump.dsp: Auto merged VC++Files/client/mysqlimport.dsp: Auto merged VC++Files/client/mysqlshow.dsp: Auto merged VC++Files/comp_err/comp_err.dsp: Auto merged VC++Files/contrib/asm386/zlibvc.dsp: Auto merged VC++Files/contrib/asm386/zlibvc.dsw: Auto merged VC++Files/contrib/minizip/zlibvc.dsp: Auto merged VC++Files/contrib/minizip/zlibvc.dsw: Auto merged VC++Files/dbug/dbug.dsp: Auto merged VC++Files/dbug/dbug.dsw: Auto merged VC++Files/heap/heap.dsp: Auto merged VC++Files/innobase/innobase.dsp: Auto merged VC++Files/isam/isam.dsp: Auto merged VC++Files/isam/isam.dsw: Auto merged VC++Files/isamchk/isamchk.dsp: Auto merged VC++Files/libmysql/libmysql.dsp: Auto merged VC++Files/libmysql/libmysql.dsw: Auto merged VC++Files/libmysqld/examples/test_libmysqld.dsp: Auto merged VC++Files/libmysqld/libmysqld.dsp: Auto merged VC++Files/libmysqltest/myTest.dsp: Auto merged VC++Files/libmysqltest/mytest.dsw: Auto merged VC++Files/merge/merge.dsp: Auto merged VC++Files/merge/merge.dsw: Auto merged VC++Files/my_print_defaults/my_print_defaults.dsp: Auto merged VC++Files/myisam/myisam.dsp: Auto merged VC++Files/myisamchk/myisamchk.dsp: Auto merged VC++Files/myisamlog/myisamlog.dsp: Auto merged VC++Files/myisammrg/myisammrg.dsp: Auto merged VC++Files/mysql.dsp: Auto merged VC++Files/mysql.dsw: Auto merged VC++Files/myisampack/myisampack.dsp: Auto merged VC++Files/mysqlbinlog/mysqlbinlog.dsp: Auto merged VC++Files/mysqlcheck/mysqlcheck.dsp: Auto merged VC++Files/mysqldemb/mysqldemb.dsp: Auto merged VC++Files/mysqlmanager/MySqlManager.dsp: Auto merged VC++Files/mysqlmanager/mysqlmanager.dsw: Auto merged VC++Files/mysqlserver/mysqlserver.dsp: Auto merged VC++Files/mysqlshutdown/myshutdown.dsp: Auto merged VC++Files/mysqlshutdown/mysqlshutdown.dsp: Auto merged VC++Files/mysqlwatch/mysqlwatch.dsp: Auto merged VC++Files/mysys/mysys.dsp: Auto merged VC++Files/mysys/mysys.dsw: Auto merged VC++Files/pack_isam/pack_isam.dsp: Auto merged VC++Files/perror/perror.dsp: Auto merged VC++Files/regex/regex.dsp: Auto merged VC++Files/regex/regex.dsw: Auto merged VC++Files/replace/replace.dsp: Auto merged VC++Files/sql/mysqld.dsw: Auto merged VC++Files/sql/mysqldmax.dsp: Auto merged VC++Files/sql/old/mysqld.dsw: Auto merged VC++Files/strings/MASM6x/strings.dsp: Auto merged VC++Files/strings/MASM6x/strings.dsw: Auto merged VC++Files/strings/backup/strings.dsp: Auto merged VC++Files/strings/backup/strings.dsw: Auto merged VC++Files/strings/noMASM/strings.dsp: Auto merged VC++Files/strings/noMASM/strings.dsw: Auto merged VC++Files/strings/strings.dsw: Auto merged VC++Files/test1/test1.dsp: Auto merged VC++Files/thr_insert_test/thr_insert_test.dsp: Auto merged VC++Files/thr_test/thr_test.dsp: Auto merged VC++Files/vio/vio.dsp: Auto merged VC++Files/zlib/zlib.dsp: Auto merged client/mysqlbinlog.cc: Auto merged client/mysqlshow.c: Auto merged include/my_global.h: Auto merged include/my_sys.h: Auto merged include/myisam.h: Auto merged include/thr_lock.h: Auto merged include/violite.h: Auto merged innobase/buf/buf0buf.c: Auto merged innobase/os/os0file.c: Auto merged innobase/row/row0sel.c: Auto merged innobase/srv/srv0start.c: Auto merged innobase/trx/trx0sys.c: Auto merged libmysqld/lib_vio.c: Auto merged myisam/mi_create.c: Auto merged mysql-test/Makefile.am: Auto merged mysql-test/r/create.result: Auto merged mysql-test/r/group_by.result: Auto merged mysql-test/r/innodb.result: Auto merged mysql-test/r/join.result: Auto merged mysql-test/r/rpl000001.result: Auto merged mysql-test/r/select.result: Auto merged mysql-test/t/auto_increment.test: Auto merged mysql-test/t/create.test: Auto merged mysql-test/t/func_like.test: Auto merged mysql-test/t/group_by.test: Auto merged mysql-test/t/innodb.test: Auto merged mysql-test/t/join.test: Auto merged mysql-test/t/type_datetime.test: Auto merged mysql-test/t/type_timestamp.test: Auto merged mysys/default.c: Auto merged mysys/thr_lock.c: Auto merged scripts/make_binary_distribution.sh: Auto merged scripts/mysqld_safe.sh: Auto merged sql/filesort.cc: Auto merged sql/ha_innodb.h: Auto merged sql/ha_myisam.cc: Auto merged sql/handler.cc: Auto merged sql/handler.h: Auto merged sql/item.cc: Auto merged sql/item_cmpfunc.cc: Auto merged sql/item_func.cc: Auto merged sql/lock.cc: Auto merged sql/log.cc: Auto merged sql/log_event.h: Auto merged sql/mf_iocache.cc: Auto merged sql/mysql_priv.h: Auto merged sql/net_serv.cc: Auto merged sql/opt_range.cc: Auto merged sql/repl_failsafe.cc: Auto merged sql/repl_failsafe.h: Auto merged sql/slave.cc: Auto merged sql/slave.h: Auto merged sql/sql_analyse.cc: Auto merged sql/sql_base.cc: Auto merged sql-bench/crash-me.sh: Auto merged sql/share/polish/errmsg.txt: Auto merged sql/sql_class.h: Auto merged sql/sql_rename.cc: Auto merged sql/sql_repl.cc: Auto merged sql/sql_repl.h: Auto merged sql/sql_update.cc: Auto merged sql/stacktrace.c: Auto merged sql/table.cc: Auto merged sql/unireg.h: Auto merged strings/ctype-tis620.c: Auto merged strings/t_ctype.h: Auto merged support-files/mysql.spec.sh: Auto merged tests/grant.res: Auto merged vio/viosocket.c: Auto merged
226 lines
5.9 KiB
C
226 lines
5.9 KiB
C
/* Copyright (C) 2000 MySQL AB
|
|
|
|
This program is free software; you can redistribute it and/or modify
|
|
it under the terms of the GNU General Public License as published by
|
|
the Free Software Foundation; either version 2 of the License, or
|
|
(at your option) any later version.
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
GNU General Public License for more details.
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
along with this program; if not, write to the Free Software
|
|
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
|
|
|
|
#include <my_global.h>
|
|
#include "stacktrace.h"
|
|
#include <signal.h>
|
|
#include <my_pthread.h>
|
|
|
|
#ifdef HAVE_STACKTRACE
|
|
#include <unistd.h>
|
|
|
|
#define PTR_SANE(p) ((p) && (char*)(p) >= heap_start && (char*)(p) <= heap_end)
|
|
|
|
char *heap_start;
|
|
|
|
void safe_print_str(const char* name, const char* val, int max_len)
|
|
{
|
|
char *heap_end= (char*) sbrk(0);
|
|
fprintf(stderr, "%s at %p ", name, val);
|
|
|
|
if (!PTR_SANE(val))
|
|
{
|
|
fprintf(stderr, " is invalid pointer\n");
|
|
return;
|
|
}
|
|
|
|
fprintf(stderr, "= ");
|
|
for (; max_len && PTR_SANE(val) && *val; --max_len)
|
|
fputc(*val++, stderr);
|
|
fputc('\n', stderr);
|
|
}
|
|
|
|
#ifdef HAVE_LINUXTHREADS
|
|
#define SIGRETURN_FRAME_COUNT 2
|
|
|
|
#if defined(__alpha__) && defined(__GNUC__)
|
|
/*
|
|
The only way to backtrace without a symbol table on alpha
|
|
is to find stq fp,N(sp), and the first byte
|
|
of the instruction opcode will give us the value of N. From this
|
|
we can find where the old value of fp is stored
|
|
*/
|
|
|
|
#define MAX_INSTR_IN_FUNC 10000
|
|
|
|
inline uchar** find_prev_fp(uint32* pc, uchar** fp)
|
|
{
|
|
int i;
|
|
for (i = 0; i < MAX_INSTR_IN_FUNC; ++i,--pc)
|
|
{
|
|
uchar* p = (uchar*)pc;
|
|
if (p[2] == 222 && p[3] == 35)
|
|
{
|
|
return (uchar**)((uchar*)fp - *(short int*)p);
|
|
}
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
inline uint32* find_prev_pc(uint32* pc, uchar** fp)
|
|
{
|
|
int i;
|
|
for (i = 0; i < MAX_INSTR_IN_FUNC; ++i,--pc)
|
|
{
|
|
char* p = (char*)pc;
|
|
if (p[1] == 0 && p[2] == 94 && p[3] == -73)
|
|
{
|
|
uint32* prev_pc = (uint32*)*((fp+p[0]/sizeof(fp)));
|
|
return prev_pc;
|
|
}
|
|
}
|
|
return 0;
|
|
}
|
|
#endif /* defined(__alpha__) && defined(__GNUC__) */
|
|
|
|
|
|
void print_stacktrace(gptr stack_bottom, ulong thread_stack)
|
|
{
|
|
uchar** fp;
|
|
uint frame_count = 0;
|
|
#if defined(__alpha__) && defined(__GNUC__)
|
|
uint32* pc;
|
|
#endif
|
|
LINT_INIT(fp);
|
|
|
|
fprintf(stderr,"\
|
|
Attempting backtrace. You can use the following information to find out\n\
|
|
where mysqld died. If you see no messages after this, something went\n\
|
|
terribly wrong...\n");
|
|
#ifdef __i386__
|
|
__asm __volatile__ ("movl %%ebp,%0"
|
|
:"=r"(fp)
|
|
:"r"(fp));
|
|
if (!fp)
|
|
{
|
|
fprintf(stderr, "frame pointer (ebp) is NULL, did you compile with\n\
|
|
-fomit-frame-pointer? Aborting backtrace!\n");
|
|
return;
|
|
}
|
|
#endif
|
|
#if defined(__alpha__) && defined(__GNUC__)
|
|
__asm __volatile__ ("mov $30,%0"
|
|
:"=r"(fp)
|
|
:"r"(fp));
|
|
if (!fp)
|
|
{
|
|
fprintf(stderr, "frame pointer (fp) is NULL, did you compile with\n\
|
|
-fomit-frame-pointer? Aborting backtrace!\n");
|
|
return;
|
|
}
|
|
#endif /* __alpha__ */
|
|
|
|
if (!stack_bottom || (gptr) stack_bottom > (gptr) &fp)
|
|
{
|
|
ulong tmp= min(0x10000,thread_stack);
|
|
/* Assume that the stack starts at the previous even 65K */
|
|
stack_bottom= (gptr) (((ulong) &fp + tmp) &
|
|
~(ulong) 0xFFFF);
|
|
fprintf(stderr, "Cannot determine thread, fp=%p, backtrace may not be correct.\n", fp);
|
|
}
|
|
if (fp > (uchar**) stack_bottom ||
|
|
fp < (uchar**) stack_bottom - thread_stack)
|
|
{
|
|
fprintf(stderr, "Bogus stack limit or frame pointer,\
|
|
fp=%p, stack_bottom=%p, thread_stack=%ld, aborting backtrace.\n",
|
|
fp, stack_bottom, thread_stack);
|
|
return;
|
|
}
|
|
|
|
fprintf(stderr, "Stack range sanity check OK, backtrace follows:\n");
|
|
#if defined(__alpha__) && defined(__GNUC__)
|
|
fprintf(stderr, "Warning: Alpha stacks are difficult -\
|
|
will be taking some wild guesses, stack trace may be incorrect or \
|
|
terminate abruptly\n");
|
|
/* On Alpha, we need to get pc */
|
|
__asm __volatile__ ("bsr %0, do_next; do_next: "
|
|
:"=r"(pc)
|
|
:"r"(pc));
|
|
#endif /* __alpha__ */
|
|
|
|
while (fp < (uchar**) stack_bottom)
|
|
{
|
|
#ifdef __i386__
|
|
uchar** new_fp = (uchar**)*fp;
|
|
fprintf(stderr, "%p\n", frame_count == SIGRETURN_FRAME_COUNT ?
|
|
*(fp+17) : *(fp+1));
|
|
#endif /* __386__ */
|
|
|
|
#if defined(__alpha__) && defined(__GNUC__)
|
|
uchar** new_fp = find_prev_fp(pc, fp);
|
|
if (frame_count == SIGRETURN_FRAME_COUNT - 1)
|
|
{
|
|
new_fp += 90;
|
|
}
|
|
|
|
if (fp && pc)
|
|
{
|
|
pc = find_prev_pc(pc, fp);
|
|
if (pc)
|
|
fprintf(stderr, "%p\n", pc);
|
|
else
|
|
{
|
|
fprintf(stderr, "Not smart enough to deal with the rest\
|
|
of this stack\n");
|
|
goto end;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
fprintf(stderr, "Not smart enough to deal with the rest of this stack\n");
|
|
goto end;
|
|
}
|
|
#endif /* defined(__alpha__) && defined(__GNUC__) */
|
|
if (new_fp <= fp )
|
|
{
|
|
fprintf(stderr, "New value of fp=%p failed sanity check,\
|
|
terminating stack trace!\n", new_fp);
|
|
goto end;
|
|
}
|
|
fp = new_fp;
|
|
++frame_count;
|
|
}
|
|
|
|
fprintf(stderr, "Stack trace seems successful - bottom reached\n");
|
|
|
|
end:
|
|
fprintf(stderr, "Please read http://www.mysql.com/doc/en/Using_stack_trace.html and follow instructions on how to resolve the stack trace. Resolved\n\
|
|
stack trace is much more helpful in diagnosing the problem, so please do \n\
|
|
resolve it\n");
|
|
}
|
|
#endif /* HAVE_LINUXTHREADS */
|
|
#endif /* HAVE_STACKTRACE */
|
|
|
|
/* Produce a core for the thread */
|
|
|
|
#ifdef NOT_USED /* HAVE_LINUXTHREADS */
|
|
void write_core(int sig)
|
|
{
|
|
signal(sig, SIG_DFL);
|
|
if (fork() != 0) exit(1); /* Abort main program */
|
|
/* Core will be written at exit */
|
|
}
|
|
#else
|
|
void write_core(int sig)
|
|
{
|
|
signal(sig, SIG_DFL);
|
|
pthread_kill(pthread_self(), sig);
|
|
#if defined(P_MYID) && !defined(SCO)
|
|
/* On Solaris, the above kill is not enough */
|
|
sigsend(P_PID,P_MYID,sig);
|
|
#endif
|
|
}
|
|
#endif
|