~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to tests/resolve_stack_dump.cc

  • Committer: Brian Aker
  • Date: 2010-01-27 18:58:12 UTC
  • Revision ID: brian@gaz-20100127185812-n62n0vwetnx8jrjy
Remove dead code.

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 <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>
 
20
#include "config.h"
 
21
#include "drizzled/charset_info.h"
 
22
#include "drizzled/internal/my_sys.h"
 
23
#include "drizzled/internal/m_string.h"
25
24
#include <errno.h>
26
 
#include <mysys/my_getopt.h>
 
25
#include "drizzled/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
extern "C" bool get_one_option(int optid, const struct my_option *, char *);
34
35
 
35
36
typedef struct sym_entry
36
37
{
37
38
  char symbol[MAX_SYM_SIZE];
38
 
  uchar* addr;
 
39
  unsigned char* addr;
39
40
} SYM_ENTRY;
40
41
 
41
42
 
42
43
static char* dump_fname = 0, *sym_fname = 0;
43
44
static DYNAMIC_ARRAY sym_table; /* how do you like this , static DYNAMIC ? */
44
 
static FILE* fp_dump, *fp_sym = 0, *fp_out; 
 
45
static FILE* fp_dump, *fp_sym = 0, *fp_out;
45
46
 
46
47
static struct my_option my_long_options[] =
47
48
{
62
63
 
63
64
static void print_version(void)
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
  printf("%s  Ver %s Distrib %s, for %s-%s (%s)\n",my_progname,DUMP_VERSION,
 
67
         VERSION,HOST_VENDOR,HOST_OS,HOST_CPU);
67
68
}
68
69
 
69
70
 
95
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
bool get_one_option(int optid, const struct my_option *, char *)
101
100
{
102
101
  switch(optid) {
103
102
  case 'V':
154
153
  fp_out = stdout;
155
154
  fp_dump = stdin;
156
155
 
157
 
  if (dump_fname && !(fp_dump = my_fopen(dump_fname, O_RDONLY, MYF(MY_WME))))
 
156
  if (dump_fname && !(fp_dump= fopen(dump_fname, "r")))
158
157
      die("Could not open %s", dump_fname);
159
158
  /* if name not given, assume stdin*/
160
159
 
161
160
  if (!sym_fname)
162
161
    die("Please run nm --numeric-sort on drizzled binary that produced stack \
163
162
trace dump and specify the path to it with -s or --symbols-file");
164
 
  if (!(fp_sym = my_fopen(sym_fname, O_RDONLY, MYF(MY_WME))))
 
163
  if (!(fp_sym= fopen(sym_fname, "r")))
165
164
    die("Could not open %s", sym_fname);
166
165
 
167
166
}
168
167
 
169
 
static uchar hex_val(char c)
 
168
static unsigned char hex_val(char c)
170
169
{
171
 
  uchar l;
172
 
  if (my_isdigit(&my_charset_latin1,c))
 
170
  unsigned char l;
 
171
  if (my_isdigit(&my_charset_utf8_general_ci,c))
173
172
    return c - '0';
174
 
  l = my_tolower(&my_charset_latin1,c);
 
173
  l = my_tolower(&my_charset_utf8_general_ci,c);
175
174
  if (l < 'a' || l > 'f')
176
 
    return HEX_INVALID; 
177
 
  return (uchar)10 + ((uchar)c - (uchar)'a');
 
175
    return HEX_INVALID;
 
176
  return (unsigned char)10 + ((unsigned char)c - (unsigned char)'a');
178
177
}
179
178
 
180
179
static unsigned long read_addr(char** buf)
181
180
{
182
 
  uchar c;
 
181
  unsigned char c;
183
182
  char* p = *buf;
184
183
  unsigned long addr = 0;
185
184
 
186
185
  while((c = hex_val(*p++)) != HEX_INVALID)
187
186
      addr = (addr << 4) + c;
188
187
 
189
 
  *buf = p; 
 
188
  *buf = p;
190
189
  return addr;
191
190
}
192
191
 
193
192
static int init_sym_entry(SYM_ENTRY* se, char* buf)
194
193
{
195
194
  char* p, *p_end;
196
 
  se->addr = (uchar*)read_addr(&buf);
 
195
  se->addr = (unsigned char*)read_addr(&buf);
197
196
 
198
197
  if (!se->addr)
199
198
    return -1;
200
 
  while (my_isspace(&my_charset_latin1,*buf++))
 
199
  while (my_isspace(&my_charset_utf8_general_ci,*buf++))
201
200
    /* empty */;
202
201
 
203
 
  while (my_isspace(&my_charset_latin1,*buf++))
 
202
  while (my_isspace(&my_charset_utf8_general_ci,*buf++))
204
203
    /* empty - skip more space */;
205
204
  --buf;
206
205
  /* now we are on the symbol */
225
224
    SYM_ENTRY se;
226
225
    if (init_sym_entry(&se, buf))
227
226
      continue;
228
 
    if (insert_dynamic(&sym_table, (uchar*)&se))
 
227
    if (insert_dynamic(&sym_table, (unsigned char*)&se))
229
228
      die("insert_dynamic() failed - looks like we are out of memory");
230
229
  }
231
230
 
239
238
 
240
239
static void verify_sort()
241
240
{
242
 
  uint i;
243
 
  uchar* last = 0;
 
241
  uint32_t i;
 
242
  unsigned char* last = 0;
244
243
 
245
244
  for (i = 0; i < sym_table.elements; i++)
246
245
  {
247
246
    SYM_ENTRY se;
248
 
    get_dynamic(&sym_table, (uchar*)&se, i);
 
247
    get_dynamic(&sym_table, (unsigned char*)&se, i);
249
248
    if (se.addr < last)
250
249
      die("sym table does not appear to be sorted, did you forget \
251
250
--numeric-sort arg to nm? trouble addr = %p, last = %p", se.addr, last);
254
253
}
255
254
 
256
255
 
257
 
static SYM_ENTRY* resolve_addr(uchar* addr, SYM_ENTRY* se)
 
256
static SYM_ENTRY* resolve_addr(unsigned char* addr, SYM_ENTRY* se)
258
257
{
259
 
  uint i;
260
 
  get_dynamic(&sym_table, (uchar*)se, 0);
 
258
  uint32_t i;
 
259
  get_dynamic(&sym_table, (unsigned char*)se, 0);
261
260
  if (addr < se->addr)
262
261
    return 0;
263
262
 
264
263
  for (i = 1; i < sym_table.elements; i++)
265
264
  {
266
 
    get_dynamic(&sym_table, (uchar*)se, i);
 
265
    get_dynamic(&sym_table, (unsigned char*)se, i);
267
266
    if (addr < se->addr)
268
267
    {
269
 
      get_dynamic(&sym_table, (uchar*)se, i - 1);
 
268
      get_dynamic(&sym_table, (unsigned char*)se, i - 1);
270
269
      return se;
271
270
    }
272
271
  }
282
281
  {
283
282
    p = buf;
284
283
    /* skip space */
285
 
    while (my_isspace(&my_charset_latin1,*p))
 
284
    while (my_isspace(&my_charset_utf8_general_ci,*p))
286
285
      ++p;
287
286
 
288
287
    if (*p++ == '0' && *p++ == 'x')
289
288
    {
290
289
      SYM_ENTRY se ;
291
 
      uchar* addr = (uchar*)read_addr(&p);
 
290
      unsigned char* addr = (unsigned char*)read_addr(&p);
292
291
      if (resolve_addr(addr, &se))
293
292
        fprintf(fp_out, "%p %s + %d\n", addr, se.symbol,
294
293
                (int) (addr - se.addr));