~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to tests/resolve_stack_dump.cc

  • Committer: Monty Taylor
  • Date: 2009-01-30 21:02:37 UTC
  • mto: (779.7.3 devel)
  • mto: This revision was merged to the branch mainline in revision 823.
  • Revision ID: mordred@inaugust.com-20090130210237-3n6ld8a9jc084jko
Commented out a test in subselect_sj - I think it might be a regression. Jay?

Show diffs side-by-side

added added

removed removed

Lines of Context:
21
21
#include <mystrings/m_ctype.h>
22
22
#include <mysys/my_sys.h>
23
23
#include <mystrings/m_string.h>
24
 
#include <drizzled/version.h>
25
24
#include <errno.h>
26
25
#include <mysys/my_getopt.h>
 
26
#include <stdio.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
34
 
35
35
typedef struct sym_entry
36
36
{
37
37
  char symbol[MAX_SYM_SIZE];
38
 
  uchar* addr;
 
38
  unsigned char* addr;
39
39
} SYM_ENTRY;
40
40
 
41
41
 
42
42
static char* dump_fname = 0, *sym_fname = 0;
43
43
static DYNAMIC_ARRAY sym_table; /* how do you like this , static DYNAMIC ? */
44
 
static FILE* fp_dump, *fp_sym = 0, *fp_out; 
 
44
static FILE* fp_dump, *fp_sym = 0, *fp_out;
45
45
 
46
46
static struct my_option my_long_options[] =
47
47
{
63
63
static void print_version(void)
64
64
{
65
65
  printf("%s  Ver %s Distrib %s, for %s (%s)\n",my_progname,DUMP_VERSION,
66
 
         DRIZZLE_SERVER_VERSION,SYSTEM_TYPE,MACHINE_TYPE);
 
66
         VERSION,SYSTEM_TYPE,MACHINE_TYPE);
67
67
}
68
68
 
69
69
 
96
96
 
97
97
 
98
98
static bool
99
 
get_one_option(int optid, const struct my_option *opt __attribute__((unused)),
100
 
               char *argument __attribute__((unused)))
 
99
get_one_option(int optid, const struct my_option *,
 
100
               char *)
101
101
{
102
102
  switch(optid) {
103
103
  case 'V':
166
166
 
167
167
}
168
168
 
169
 
static uchar hex_val(char c)
 
169
static unsigned char hex_val(char c)
170
170
{
171
 
  uchar l;
172
 
  if (my_isdigit(&my_charset_latin1,c))
 
171
  unsigned char l;
 
172
  if (my_isdigit(&my_charset_utf8_general_ci,c))
173
173
    return c - '0';
174
 
  l = my_tolower(&my_charset_latin1,c);
 
174
  l = my_tolower(&my_charset_utf8_general_ci,c);
175
175
  if (l < 'a' || l > 'f')
176
 
    return HEX_INVALID; 
177
 
  return (uchar)10 + ((uchar)c - (uchar)'a');
 
176
    return HEX_INVALID;
 
177
  return (unsigned char)10 + ((unsigned char)c - (unsigned char)'a');
178
178
}
179
179
 
180
180
static unsigned long read_addr(char** buf)
181
181
{
182
 
  uchar c;
 
182
  unsigned char c;
183
183
  char* p = *buf;
184
184
  unsigned long addr = 0;
185
185
 
186
186
  while((c = hex_val(*p++)) != HEX_INVALID)
187
187
      addr = (addr << 4) + c;
188
188
 
189
 
  *buf = p; 
 
189
  *buf = p;
190
190
  return addr;
191
191
}
192
192
 
193
193
static int init_sym_entry(SYM_ENTRY* se, char* buf)
194
194
{
195
195
  char* p, *p_end;
196
 
  se->addr = (uchar*)read_addr(&buf);
 
196
  se->addr = (unsigned char*)read_addr(&buf);
197
197
 
198
198
  if (!se->addr)
199
199
    return -1;
200
 
  while (my_isspace(&my_charset_latin1,*buf++))
 
200
  while (my_isspace(&my_charset_utf8_general_ci,*buf++))
201
201
    /* empty */;
202
202
 
203
 
  while (my_isspace(&my_charset_latin1,*buf++))
 
203
  while (my_isspace(&my_charset_utf8_general_ci,*buf++))
204
204
    /* empty - skip more space */;
205
205
  --buf;
206
206
  /* now we are on the symbol */
225
225
    SYM_ENTRY se;
226
226
    if (init_sym_entry(&se, buf))
227
227
      continue;
228
 
    if (insert_dynamic(&sym_table, (uchar*)&se))
 
228
    if (insert_dynamic(&sym_table, (unsigned char*)&se))
229
229
      die("insert_dynamic() failed - looks like we are out of memory");
230
230
  }
231
231
 
239
239
 
240
240
static void verify_sort()
241
241
{
242
 
  uint i;
243
 
  uchar* last = 0;
 
242
  uint32_t i;
 
243
  unsigned char* last = 0;
244
244
 
245
245
  for (i = 0; i < sym_table.elements; i++)
246
246
  {
247
247
    SYM_ENTRY se;
248
 
    get_dynamic(&sym_table, (uchar*)&se, i);
 
248
    get_dynamic(&sym_table, (unsigned char*)&se, i);
249
249
    if (se.addr < last)
250
250
      die("sym table does not appear to be sorted, did you forget \
251
251
--numeric-sort arg to nm? trouble addr = %p, last = %p", se.addr, last);
254
254
}
255
255
 
256
256
 
257
 
static SYM_ENTRY* resolve_addr(uchar* addr, SYM_ENTRY* se)
 
257
static SYM_ENTRY* resolve_addr(unsigned char* addr, SYM_ENTRY* se)
258
258
{
259
 
  uint i;
260
 
  get_dynamic(&sym_table, (uchar*)se, 0);
 
259
  uint32_t i;
 
260
  get_dynamic(&sym_table, (unsigned char*)se, 0);
261
261
  if (addr < se->addr)
262
262
    return 0;
263
263
 
264
264
  for (i = 1; i < sym_table.elements; i++)
265
265
  {
266
 
    get_dynamic(&sym_table, (uchar*)se, i);
 
266
    get_dynamic(&sym_table, (unsigned char*)se, i);
267
267
    if (addr < se->addr)
268
268
    {
269
 
      get_dynamic(&sym_table, (uchar*)se, i - 1);
 
269
      get_dynamic(&sym_table, (unsigned char*)se, i - 1);
270
270
      return se;
271
271
    }
272
272
  }
282
282
  {
283
283
    p = buf;
284
284
    /* skip space */
285
 
    while (my_isspace(&my_charset_latin1,*p))
 
285
    while (my_isspace(&my_charset_utf8_general_ci,*p))
286
286
      ++p;
287
287
 
288
288
    if (*p++ == '0' && *p++ == 'x')
289
289
    {
290
290
      SYM_ENTRY se ;
291
 
      uchar* addr = (uchar*)read_addr(&p);
 
291
      unsigned char* addr = (unsigned char*)read_addr(&p);
292
292
      if (resolve_addr(addr, &se))
293
293
        fprintf(fp_out, "%p %s + %d\n", addr, se.symbol,
294
294
                (int) (addr - se.addr));