17
17
versions into symbolic names. By Sasha Pachev <sasha@mysql.com>
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>
21
#include "drizzled/charset_info.h"
22
#include "drizzled/internal/my_sys.h"
23
#include "drizzled/internal/m_string.h"
26
#include <mysys/my_getopt.h>
25
#include "drizzled/my_getopt.h"
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
34
extern "C" bool get_one_option(int optid, const struct my_option *, char *);
35
36
typedef struct sym_entry
37
38
char symbol[MAX_SYM_SIZE];
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;
46
47
static struct my_option my_long_options[] =
63
64
static void print_version(void)
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);
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 *)
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*/
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);
169
static uchar hex_val(char c)
168
static unsigned char hex_val(char c)
172
if (my_isdigit(&my_charset_latin1,c))
171
if (my_isdigit(&my_charset_utf8_general_ci,c))
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')
177
return (uchar)10 + ((uchar)c - (uchar)'a');
176
return (unsigned char)10 + ((unsigned char)c - (unsigned char)'a');
180
179
static unsigned long read_addr(char** buf)
184
183
unsigned long addr = 0;
186
185
while((c = hex_val(*p++)) != HEX_INVALID)
187
186
addr = (addr << 4) + c;
193
192
static int init_sym_entry(SYM_ENTRY* se, char* buf)
196
se->addr = (uchar*)read_addr(&buf);
195
se->addr = (unsigned char*)read_addr(&buf);
200
while (my_isspace(&my_charset_latin1,*buf++))
199
while (my_isspace(&my_charset_utf8_general_ci,*buf++))
203
while (my_isspace(&my_charset_latin1,*buf++))
202
while (my_isspace(&my_charset_utf8_general_ci,*buf++))
204
203
/* empty - skip more space */;
206
205
/* now we are on the symbol */
226
225
if (init_sym_entry(&se, buf))
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");
240
239
static void verify_sort()
242
unsigned char* last = 0;
245
244
for (i = 0; i < sym_table.elements; i++)
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);
257
static SYM_ENTRY* resolve_addr(uchar* addr, SYM_ENTRY* se)
256
static SYM_ENTRY* resolve_addr(unsigned char* addr, SYM_ENTRY* se)
260
get_dynamic(&sym_table, (uchar*)se, 0);
259
get_dynamic(&sym_table, (unsigned char*)se, 0);
261
260
if (addr < se->addr)
264
263
for (i = 1; i < sym_table.elements; i++)
266
get_dynamic(&sym_table, (uchar*)se, i);
265
get_dynamic(&sym_table, (unsigned char*)se, i);
267
266
if (addr < se->addr)
269
get_dynamic(&sym_table, (uchar*)se, i - 1);
268
get_dynamic(&sym_table, (unsigned char*)se, i - 1);
285
while (my_isspace(&my_charset_latin1,*p))
284
while (my_isspace(&my_charset_utf8_general_ci,*p))
288
287
if (*p++ == '0' && *p++ == 'x')
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));