mirror of
https://github.com/MariaDB/server.git
synced 2025-01-16 20:12:31 +01:00
bbab9ec678
Noteworthy: - New HANDLER code - New multi-update-grant-check code - Table lock code in ha_innodb.cc was not applied BitKeeper/etc/logging_ok: auto-union BitKeeper/deleted/.del-ctype-latin1_de.c~c5d8f9208bceb98e: Auto merged Build-tools/mysql-copyright-2: Auto merged acinclude.m4: Auto merged client/mysqladmin.c: Auto merged client/mysqldump.c: Auto merged include/config-win.h: Auto merged include/my_global.h: Auto merged include/myisam.h: Auto merged innobase/btr/btr0btr.c: Auto merged innobase/buf/buf0buf.c: Auto merged ltmain.sh: Auto merged innobase/dict/dict0dict.c: Auto merged innobase/fsp/fsp0fsp.c: Auto merged innobase/include/dict0dict.h: Auto merged innobase/include/row0mysql.h: Auto merged innobase/log/log0log.c: Auto merged innobase/log/log0recv.c: Auto merged innobase/pars/pars0opt.c: Auto merged innobase/row/row0row.c: Auto merged innobase/sync/sync0arr.c: Auto merged innobase/ut/ut0dbg.c: Auto merged myisam/mi_check.c: Auto merged myisam/mi_close.c: Auto merged myisam/mi_create.c: Auto merged myisam/mi_locking.c: Auto merged myisam/myisampack.c: Auto merged mysql-test/r/delete.result: Auto merged mysql-test/r/func_if.result: Auto merged Build-tools/mysql-copyright: Merge with 4.0 (too most of the code from 4.0) Makefile.am: merge client/mysql.cc: Used 4.1 code configure.in: merge innobase/os/os0file.c: merge innobase/row/row0mysql.c: merge mysql-test/r/ctype_latin1_de.result: merge mysql-test/r/flush_table.result: merge mysql-test/r/func_str.result: merge mysql-test/r/handler.result: merge mysql-test/r/multi_update.result: merge mysql-test/r/type_timestamp.result: Removed testing of 'new' mode, as this is only relevant for 4.0 mysql-test/r/update.result: merge mysql-test/t/delete.test: merge mysql-test/t/flush_table.test: merge mysql-test/t/func_str.test: merge mysql-test/t/handler.test: merge mysql-test/t/multi_update.test: merge mysql-test/t/type_timestamp.test: Removed testing of 'new' mode, as this is only relevant for 4.0 mysql-test/t/update.test: merge mysys/errors.c: merge mysys/my_fstream.c: merge mysys/my_pread.c: merge mysys/my_write.c: merge mysys/mysys_priv.h: merge scripts/mysqlhotcopy.sh: merge sql/field.cc: Keep code from 4.1 sql/field.h: Keep code from 4.1 sql/ha_innodb.cc: Don't merge lock code from 4.0; Heikki will look at this sql/ha_myisam.cc: merge sql/handler.cc: merge sql/item_cmpfunc.cc: merge sql/item_cmpfunc.h: merge sql/item_strfunc.cc: merge sql/mysql_priv.h: merge sql/mysqld.cc: merge sql/protocol.cc: merge sql/records.cc: merge sql/repl_failsafe.cc: merge mysql-test/r/lock_multi.result: merge mysql-test/t/ctype_latin1_de.test: merge mysql-test/t/func_if.test: merge mysql-test/t/lock_multi.test: merge sql/repl_failsafe.h: merge Remove unnessessary header protection sql/slave.h: merge sql/sql_acl.cc: merge sql/sql_base.cc: merge sql/sql_cache.cc: auto merge sql/sql_class.cc: merge sql/sql_class.h: merge sql/sql_delete.cc: merge sql/sql_handler.cc: Get new HANDLER code into 4.1 sql/sql_parse.cc: Keep old file sql/sql_repl.cc: merge sql/sql_repl.h: merge sql/sql_show.cc: merge sql/sql_table.cc: merge sql/sql_union.cc: Applied the examine_rows bug fix from 4.0 by hand sql/sql_update.cc: New multi-update-grant-check code from 4.0 sql/sql_yacc.yy: New multi-update-grant-check code from 4.0 sql/stacktrace.c: merge sql/table.h: merge
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://dev.mysql.com/doc/mysql/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
|