16 #include "my_global.h"
20 #include "my_stacktrace.h"
21 #include "global_threads.h"
25 #define SIGNAL_FMT "exception 0x%x"
27 #define SIGNAL_FMT "signal %d"
35 static volatile sig_atomic_t segfaulted= 0;
36 extern ulong max_used_connections;
37 extern volatile sig_atomic_t calling_initgroups;
39 extern volatile sig_atomic_t ld_assume_kernel_is_set;
58 extern "C" sig_handler handle_fatal_signal(
int sig)
62 my_safe_printf_stderr(
"Fatal " SIGNAL_FMT
" while backtracing\n", sig);
70 GetSystemTime(&utc_time);
71 const long hrs= utc_time.wHour;
72 const long mins= utc_time.wMinute;
73 const long secs= utc_time.wSecond;
76 const time_t curr_time= time(NULL);
78 const long tmins = curr_time / 60;
79 const long thrs = tmins / 60;
80 const long hrs = thrs % 24;
81 const long mins = tmins % 60;
82 const long secs = curr_time % 60;
85 char hrs_buf[3]=
"00";
86 char mins_buf[3]=
"00";
87 char secs_buf[3]=
"00";
88 my_safe_itoa(10, hrs, &hrs_buf[2]);
89 my_safe_itoa(10, mins, &mins_buf[2]);
90 my_safe_itoa(10, secs, &secs_buf[2]);
92 my_safe_printf_stderr(
"%s:%s:%s UTC - mysqld got " SIGNAL_FMT
" ;\n",
93 hrs_buf, mins_buf, secs_buf, sig);
95 my_safe_printf_stderr(
"%s",
96 "This could be because you hit a bug. It is also possible that this binary\n"
97 "or one of the libraries it was linked against is corrupt, improperly built,\n"
98 "or misconfigured. This error can also be caused by malfunctioning hardware.\n");
100 my_safe_printf_stderr(
"%s",
101 "We will try our best to scrape up some info that will hopefully help\n"
102 "diagnose the problem, but since we have already crashed, \n"
103 "something is definitely wrong and this may fail.\n\n");
105 my_safe_printf_stderr(
"key_buffer_size=%lu\n",
106 (ulong) dflt_key_cache->key_cache_mem_size);
108 my_safe_printf_stderr(
"read_buffer_size=%ld\n",
109 (
long) global_system_variables.read_buff_size);
111 my_safe_printf_stderr(
"max_used_connections=%lu\n",
112 (ulong) max_used_connections);
114 my_safe_printf_stderr(
"max_threads=%u\n",
115 (uint) thread_scheduler->max_threads);
117 my_safe_printf_stderr(
"thread_count=%u\n", get_thread_count());
119 my_safe_printf_stderr(
"connection_count=%u\n", (uint) connection_count);
121 my_safe_printf_stderr(
"It is possible that mysqld could use up to \n"
123 "(read_buffer_size + sort_buffer_size)*max_threads = "
124 "%lu K bytes of memory\n",
125 ((ulong) dflt_key_cache->key_cache_mem_size +
126 (global_system_variables.read_buff_size +
127 global_system_variables.sortbuff_size) *
128 thread_scheduler->max_threads +
129 max_connections *
sizeof(THD)) / 1024);
131 my_safe_printf_stderr(
"%s",
132 "Hope that's ok; if not, decrease some variables in the equation.\n\n");
134 #if defined(HAVE_LINUXTHREADS)
135 #define UNSAFE_DEFAULT_LINUX_THREADS 200
136 if (
sizeof(
char*) == 4 && thread_count > UNSAFE_DEFAULT_LINUX_THREADS)
138 my_safe_printf_stderr(
139 "You seem to be running 32-bit Linux and have "
140 "%d concurrent connections.\n"
141 "If you have not changed STACK_SIZE in LinuxThreads "
142 "and built the binary \n"
143 "yourself, LinuxThreads is quite likely to steal "
144 "a part of the global heap for\n"
145 "the thread stack. Please read "
146 "http://dev.mysql.com/doc/mysql/en/linux-installation.html\n\n"
151 #ifdef HAVE_STACKTRACE
152 THD *thd=current_thd;
154 if (!(test_flags & TEST_NO_STACKTRACE))
156 my_safe_printf_stderr(
"Thread pointer: 0x%p\n", thd);
157 my_safe_printf_stderr(
"%s",
158 "Attempting backtrace. You can use the following "
159 "information to find out\n"
160 "where mysqld died. If you see no messages after this, something went\n"
161 "terribly wrong...\n");
162 my_print_stacktrace(thd ? (uchar*) thd->thread_stack : NULL,
163 my_thread_stack_size);
167 const char *kreason=
"UNKNOWN";
168 switch (thd->killed) {
169 case THD::NOT_KILLED:
170 kreason=
"NOT_KILLED";
172 case THD::KILL_BAD_DATA:
173 kreason=
"KILL_BAD_DATA";
175 case THD::KILL_CONNECTION:
176 kreason=
"KILL_CONNECTION";
178 case THD::KILL_QUERY:
179 kreason=
"KILL_QUERY";
181 case THD::KILLED_NO_VALUE:
182 kreason=
"KILLED_NO_VALUE";
185 my_safe_printf_stderr(
"%s",
"\n"
186 "Trying to get some variables.\n"
187 "Some pointers may be invalid and cause the dump to abort.\n");
189 my_safe_printf_stderr(
"Query (%p): ", thd->query());
190 my_safe_print_str(thd->query(), MY_MIN(1024
U, thd->query_length()));
191 my_safe_printf_stderr(
"Connection ID (thread ID): %lu\n",
192 (ulong) thd->thread_id);
193 my_safe_printf_stderr(
"Status: %s\n\n", kreason);
195 my_safe_printf_stderr(
"%s",
196 "The manual page at "
197 "http://dev.mysql.com/doc/mysql/en/crashing.html contains\n"
198 "information that should help you find out what is causing the crash.\n");
202 #ifdef HAVE_INITGROUPS
203 if (calling_initgroups)
205 my_safe_printf_stderr(
"%s",
"\n"
206 "This crash occured while the server was calling initgroups(). This is\n"
207 "often due to the use of a mysqld that is statically linked against \n"
208 "glibc and configured to use LDAP in /etc/nsswitch.conf.\n"
209 "You will need to either upgrade to a version of glibc that does not\n"
210 "have this problem (2.3.4 or later when used with nscd),\n"
211 "disable LDAP in your nsswitch.conf, or use a "
212 "mysqld that is not statically linked.\n");
217 if (thd_lib_detected == THD_LIB_LT && !ld_assume_kernel_is_set)
219 my_safe_printf_stderr(
"%s",
220 "You are running a statically-linked LinuxThreads binary on an NPTL\n"
221 "system. This can result in crashes on some distributions due to "
222 "LT/NPTL conflicts.\n"
223 "You should either build a dynamically-linked binary, "
224 "or force LinuxThreads\n"
225 "to be used with the LD_ASSUME_KERNEL environment variable.\n"
226 "Please consult the documentation for your distribution "
227 "on how to do that.\n");
231 if (locked_in_memory)
233 my_safe_printf_stderr(
"%s",
"\n"
234 "The \"--memlock\" argument, which was enabled, "
235 "uses system calls that are\n"
236 "unreliable and unstable on some operating systems and "
237 "operating-system versions (notably, some versions of Linux).\n"
238 "This crash could be due to use of those buggy OS calls.\n"
239 "You should consider whether you really need the "
240 "\"--memlock\" parameter and/or consult the OS distributer about "
241 "\"mlockall\" bugs.\n");
244 #ifdef HAVE_WRITE_CORE
245 if (test_flags & TEST_CORE_ON_SIGNAL)
247 my_safe_printf_stderr(
"%s",
"Writing a core file\n");