~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/stacktrace.cc

  • Committer: Brian Aker
  • Date: 2008-10-06 06:47:29 UTC
  • Revision ID: brian@tangent.org-20081006064729-2i9mhjkzyvow9xsm
RemoveĀ uint.

Show diffs side-by-side

added added

removed removed

Lines of Context:
17
17
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
18
18
 */
19
19
 
20
 
#include "config.h"
21
 
#include "drizzled/stacktrace.h"
22
 
#include <cstddef>
 
20
#include "stacktrace.h"
23
21
 
24
22
#include <signal.h>
25
 
#include "drizzled/internal/my_pthread.h"
26
 
#include "drizzled/internal/m_string.h"
 
23
#include <mysys/my_pthread.h>
 
24
#include <mystrings/m_string.h>
27
25
#ifdef HAVE_STACKTRACE
28
26
#include <unistd.h>
29
27
#include <strings.h>
32
30
#include <execinfo.h>
33
31
#endif
34
32
 
35
 
#include <cstring>
36
 
#include <cstdio>
37
 
#include <algorithm>
38
 
 
39
 
#include "drizzled/definitions.h"
40
 
 
41
 
using namespace std;
42
 
 
43
 
namespace drizzled
44
 
{
45
 
 
46
33
#define PTR_SANE(p) ((p) && (char*)(p) >= heap_start && (char*)(p) <= heap_end)
47
34
 
48
35
char *heap_start;
131
118
#endif
132
119
 
133
120
 
134
 
void  print_stacktrace(unsigned char* stack_bottom, size_t thread_stack)
 
121
void  print_stacktrace(unsigned char* stack_bottom, ulong thread_stack)
135
122
{
136
123
#if HAVE_BACKTRACE
137
124
  backtrace_current_thread();
159
146
 
160
147
  if (!stack_bottom || (unsigned char*) stack_bottom > (unsigned char*) &fp)
161
148
  {
162
 
    ulong tmp= min((size_t)0x10000,thread_stack);
 
149
    ulong tmp= cmin(0x10000,thread_stack);
163
150
    /* Assume that the stack starts at the previous even 65K */
164
151
    stack_bottom= (unsigned char*) (((ulong) &fp + tmp) &
165
152
                          ~(ulong) 0xFFFF);
169
156
      fp < (unsigned char**) stack_bottom - thread_stack)
170
157
  {
171
158
    fprintf(stderr, "Bogus stack limit or frame pointer,\
172
 
 fp=%p, stack_bottom=%p, thread_stack=%"PRIu64", aborting backtrace.\n",
173
 
            (void *)fp, (void *)stack_bottom, (uint64_t)thread_stack);
 
159
 fp=%p, stack_bottom=%p, thread_stack=%ld, aborting backtrace.\n",
 
160
            (void *)fp, (void *)stack_bottom, thread_stack);
174
161
    return;
175
162
  }
176
163
 
177
164
  fprintf(stderr, "Stack range sanity check OK, backtrace follows:\n");
178
165
 
179
166
  /* We are 1 frame above signal frame with NPTL and 2 frames above with LT */
180
 
  sigreturn_frame_count = internal::thd_lib_detected == THD_LIB_LT ? 2 : 1;
 
167
  sigreturn_frame_count = thd_lib_detected == THD_LIB_LT ? 2 : 1;
181
168
 
182
169
  while (fp < (unsigned char**) stack_bottom)
183
170
  {
207
194
          "problem, so please do resolve it\n");
208
195
}
209
196
#endif /* TARGET_OS_LINUX */
210
 
 
211
 
} /* namespace drizzled */
212
 
 
213
197
#endif /* HAVE_STACKTRACE */
214
198
 
215
199
/* Produce a core for the thread */
216
200
 
217
 
namespace drizzled
218
 
{
219
 
 
220
201
void write_core(int sig)
221
202
{
222
203
  signal(sig, SIG_DFL);
235
216
  sigsend(P_PID,P_MYID,sig);
236
217
#endif
237
218
}
238
 
 
239
 
} /* namespace drizzled */