~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to tests/resolve_stack_dump.c

  • Committer: Monty Taylor
  • Date: 2008-10-08 01:10:45 UTC
  • mto: This revision was merged to the branch mainline in revision 491.
  • Revision ID: monty@inaugust.com-20081008011045-zqozbc81f8qhmxok
Get rid of pragma interface/pragma implementation.

Show diffs side-by-side

added added

removed removed

Lines of Context:
17
17
   versions into symbolic names. By Sasha Pachev <sasha@mysql.com>
18
18
 */
19
19
 
20
 
#include <my_global.h>
21
 
#include <m_ctype.h>
22
 
#include <my_sys.h>
23
 
#include <m_string.h>
24
 
#include <drizzle_version.h>
 
20
#include <drizzled/global.h>
 
21
#include <mystrings/m_ctype.h>
 
22
#include <mysys/my_sys.h>
 
23
#include <mystrings/m_string.h>
 
24
#include <drizzled/version.h>
25
25
#include <errno.h>
26
 
#include <my_getopt.h>
 
26
#include <mysys/my_getopt.h>
27
27
 
28
28
#define INIT_SYM_TABLE  4096
29
29
#define INC_SYM_TABLE  4096
30
30
#define MAX_SYM_SIZE   128
31
31
#define DUMP_VERSION "1.4"
32
 
#define HEX_INVALID  (uchar)255
 
32
#define HEX_INVALID  (unsigned char)255
33
33
 
34
 
typedef ulong my_long_addr_t ; /* at some point, we need to fix configure
35
 
                                * to define this for us  
36
 
                                */
37
34
 
38
35
typedef struct sym_entry
39
36
{
40
37
  char symbol[MAX_SYM_SIZE];
41
 
  uchar* addr;
 
38
  unsigned char* addr;
42
39
} SYM_ENTRY;
43
40
 
44
41
 
63
60
 
64
61
static void verify_sort(void);
65
62
 
66
 
 
67
 
#include <help_start.h>
68
 
 
69
63
static void print_version(void)
70
64
{
71
65
  printf("%s  Ver %s Distrib %s, for %s (%s)\n",my_progname,DUMP_VERSION,
72
 
         MYSQL_SERVER_VERSION,SYSTEM_TYPE,MACHINE_TYPE);
 
66
         DRIZZLE_SERVER_VERSION,SYSTEM_TYPE,MACHINE_TYPE);
73
67
}
74
68
 
75
69
 
89
83
If the numeric-dump-file is not given, the stack trace is read from stdin.\n");
90
84
}
91
85
 
92
 
#include <help_end.h>
93
 
 
94
 
 
95
86
static void die(const char* fmt, ...)
96
87
{
97
88
  va_list args;
175
166
 
176
167
}
177
168
 
178
 
static uchar hex_val(char c)
 
169
static unsigned char hex_val(char c)
179
170
{
180
 
  uchar l;
181
 
  if (my_isdigit(&my_charset_latin1,c))
 
171
  unsigned char l;
 
172
  if (my_isdigit(&my_charset_utf8_general_ci,c))
182
173
    return c - '0';
183
 
  l = my_tolower(&my_charset_latin1,c);
 
174
  l = my_tolower(&my_charset_utf8_general_ci,c);
184
175
  if (l < 'a' || l > 'f')
185
176
    return HEX_INVALID; 
186
 
  return (uchar)10 + ((uchar)c - (uchar)'a');
 
177
  return (unsigned char)10 + ((unsigned char)c - (unsigned char)'a');
187
178
}
188
179
 
189
 
static my_long_addr_t read_addr(char** buf)
 
180
static unsigned long read_addr(char** buf)
190
181
{
191
 
  uchar c;
 
182
  unsigned char c;
192
183
  char* p = *buf;
193
 
  my_long_addr_t addr = 0;
 
184
  unsigned long addr = 0;
194
185
 
195
186
  while((c = hex_val(*p++)) != HEX_INVALID)
196
187
      addr = (addr << 4) + c;
202
193
static int init_sym_entry(SYM_ENTRY* se, char* buf)
203
194
{
204
195
  char* p, *p_end;
205
 
  se->addr = (uchar*)read_addr(&buf);
 
196
  se->addr = (unsigned char*)read_addr(&buf);
206
197
 
207
198
  if (!se->addr)
208
199
    return -1;
209
 
  while (my_isspace(&my_charset_latin1,*buf++))
 
200
  while (my_isspace(&my_charset_utf8_general_ci,*buf++))
210
201
    /* empty */;
211
202
 
212
 
  while (my_isspace(&my_charset_latin1,*buf++))
 
203
  while (my_isspace(&my_charset_utf8_general_ci,*buf++))
213
204
    /* empty - skip more space */;
214
205
  --buf;
215
206
  /* now we are on the symbol */
234
225
    SYM_ENTRY se;
235
226
    if (init_sym_entry(&se, buf))
236
227
      continue;
237
 
    if (insert_dynamic(&sym_table, (uchar*)&se))
 
228
    if (insert_dynamic(&sym_table, (unsigned char*)&se))
238
229
      die("insert_dynamic() failed - looks like we are out of memory");
239
230
  }
240
231
 
248
239
 
249
240
static void verify_sort()
250
241
{
251
 
  uint i;
252
 
  uchar* last = 0;
 
242
  uint32_t i;
 
243
  unsigned char* last = 0;
253
244
 
254
245
  for (i = 0; i < sym_table.elements; i++)
255
246
  {
256
247
    SYM_ENTRY se;
257
 
    get_dynamic(&sym_table, (uchar*)&se, i);
 
248
    get_dynamic(&sym_table, (unsigned char*)&se, i);
258
249
    if (se.addr < last)
259
250
      die("sym table does not appear to be sorted, did you forget \
260
251
--numeric-sort arg to nm? trouble addr = %p, last = %p", se.addr, last);
263
254
}
264
255
 
265
256
 
266
 
static SYM_ENTRY* resolve_addr(uchar* addr, SYM_ENTRY* se)
 
257
static SYM_ENTRY* resolve_addr(unsigned char* addr, SYM_ENTRY* se)
267
258
{
268
 
  uint i;
269
 
  get_dynamic(&sym_table, (uchar*)se, 0);
 
259
  uint32_t i;
 
260
  get_dynamic(&sym_table, (unsigned char*)se, 0);
270
261
  if (addr < se->addr)
271
262
    return 0;
272
263
 
273
264
  for (i = 1; i < sym_table.elements; i++)
274
265
  {
275
 
    get_dynamic(&sym_table, (uchar*)se, i);
 
266
    get_dynamic(&sym_table, (unsigned char*)se, i);
276
267
    if (addr < se->addr)
277
268
    {
278
 
      get_dynamic(&sym_table, (uchar*)se, i - 1);
 
269
      get_dynamic(&sym_table, (unsigned char*)se, i - 1);
279
270
      return se;
280
271
    }
281
272
  }
291
282
  {
292
283
    p = buf;
293
284
    /* skip space */
294
 
    while (my_isspace(&my_charset_latin1,*p))
 
285
    while (my_isspace(&my_charset_utf8_general_ci,*p))
295
286
      ++p;
296
287
 
297
288
    if (*p++ == '0' && *p++ == 'x')
298
289
    {
299
290
      SYM_ENTRY se ;
300
 
      uchar* addr = (uchar*)read_addr(&p);
 
291
      unsigned char* addr = (unsigned char*)read_addr(&p);
301
292
      if (resolve_addr(addr, &se))
302
293
        fprintf(fp_out, "%p %s + %d\n", addr, se.symbol,
303
294
                (int) (addr - se.addr));