~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to tests/resolve_stack_dump.c

  • Committer: Monty Taylor
  • Date: 2008-08-16 21:06:22 UTC
  • Revision ID: monty@inaugust.com-20080816210622-zpnn13unyinqzn72
Updated po files.

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