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