Merge lp:~vjsamuel/drizzle/refacor-resolve-stack-dump into lp:~drizzle-trunk/drizzle/development

Proposed by Vijay Samuel
Status: Merged
Approved by: Brian Aker
Approved revision: 1685
Merged at revision: 1688
Proposed branch: lp:~vjsamuel/drizzle/refacor-resolve-stack-dump
Merge into: lp:~drizzle-trunk/drizzle/development
Diff against target: 248 lines (+77/-104)
2 files modified
tests/include.am (+1/-1)
tests/resolve_stack_dump.cc (+76/-103)
To merge this branch: bzr merge lp:~vjsamuel/drizzle/refacor-resolve-stack-dump
Reviewer Review Type Date Requested Status
Brian Aker Approve
Review via email: mp+31834@code.launchpad.net
To post a comment you must log in.
Revision history for this message
Brian Aker (brianaker) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'tests/include.am'
--- tests/include.am 2010-06-19 19:28:47 +0000
+++ tests/include.am 2010-08-05 11:50:58 +0000
@@ -27,7 +27,7 @@
27CLEANFILES += $(GENSCRIPTS) tests/mtr27CLEANFILES += $(GENSCRIPTS) tests/mtr
28noinst_PROGRAMS += tests/resolve_stack_dump28noinst_PROGRAMS += tests/resolve_stack_dump
29tests_resolve_stack_dump_SOURCES = tests/resolve_stack_dump.cc29tests_resolve_stack_dump_SOURCES = tests/resolve_stack_dump.cc
30tests_resolve_stack_dump_LDADD = ${TEST_LDADD}30tests_resolve_stack_dump_LDADD = ${TEST_LDADD} ${BOOST_LIBS}
3131
32TEST_LDADD= drizzled/internal/libinternal.la \32TEST_LDADD= drizzled/internal/libinternal.la \
33 $(LIBINTL)33 $(LIBINTL)
3434
=== modified file 'tests/resolve_stack_dump.cc'
--- tests/resolve_stack_dump.cc 2010-08-02 18:35:08 +0000
+++ tests/resolve_stack_dump.cc 2010-08-05 11:50:58 +0000
@@ -18,7 +18,7 @@
18 */18 */
1919
20#include "config.h"20#include "config.h"
2121#include <iostream>
22#include <cstdio>22#include <cstdio>
23#include <cerrno>23#include <cerrno>
2424
@@ -26,7 +26,10 @@
26#include "drizzled/internal/my_sys.h"26#include "drizzled/internal/my_sys.h"
27#include "drizzled/internal/m_string.h"27#include "drizzled/internal/m_string.h"
28#include "drizzled/option.h"28#include "drizzled/option.h"
29#include <boost/program_options.hpp>
2930
31using namespace std;
32namespace po= boost::program_options;
30using namespace drizzled;33using namespace drizzled;
3134
32#define INIT_SYM_TABLE 409635#define INIT_SYM_TABLE 4096
@@ -42,53 +45,12 @@
42} SYM_ENTRY;45} SYM_ENTRY;
4346
4447
45static char* dump_fname = 0, *sym_fname = 0;48std::string dump_fname, sym_fname;
46static DYNAMIC_ARRAY sym_table; /* how do you like this , static DYNAMIC ? */49static DYNAMIC_ARRAY sym_table; /* how do you like this , static DYNAMIC ? */
47static FILE* fp_dump, *fp_sym = 0, *fp_out;50static FILE* fp_dump, *fp_sym = 0, *fp_out;
4851
49static struct option my_long_options[] =
50{
51 {"help", 'h', "Display this help and exit.",
52 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
53 {"version", 'V', "Output version information and exit.",
54 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
55 {"symbols-file", 's', "Use specified symbols file.", (char**) &sym_fname,
56 (char**) &sym_fname, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
57 {"numeric-dump-file", 'n', "Read the dump from specified file.",
58 (char**) &dump_fname, (char**) &dump_fname, 0, GET_STR, REQUIRED_ARG,
59 0, 0, 0, 0, 0, 0},
60 { 0, 0, 0, 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0}
61};
62
63
64static void verify_sort(void);52static void verify_sort(void);
6553
66static void print_version(void)
67{
68 printf("%s Ver %s Distrib %s, for %s-%s (%s)\n",internal::my_progname,DUMP_VERSION,
69 VERSION,HOST_VENDOR,HOST_OS,HOST_CPU);
70}
71
72
73static void usage(void)
74{
75 print_version();
76 printf("MySQL AB, by Sasha Pachev\n");
77 printf("This software comes with ABSOLUTELY NO WARRANTY\n\n");
78 printf("Resolve numeric stack strace dump into symbols.\n\n");
79 printf("Usage: %s [OPTIONS] symbols-file [numeric-dump-file]\n",
80 internal::my_progname);
81 my_print_help(my_long_options);
82 my_print_variables(my_long_options);
83 printf("\n"
84 "The symbols-file should include the output from: \n"
85 " 'nm --numeric-sort drizzled'.\n"
86 "The numeric-dump-file should contain a numeric stack trace "
87 "from drizzled.\n"
88 "If the numeric-dump-file is not given, the stack trace is "
89 "read from stdin.\n");
90}
91
92static void die(const char* fmt, ...)54static void die(const char* fmt, ...)
93{55{
94 va_list args;56 va_list args;
@@ -100,73 +62,20 @@
100 exit(1);62 exit(1);
101}63}
10264
103
104static int get_one_option(int optid, const struct option *, char *)
105{
106 switch(optid) {
107 case 'V':
108 print_version();
109 exit(0);
110 case '?':
111 usage();
112 exit(0);
113 }
114 return 0;
115}
116
117
118static int parse_args(int argc, char **argv)
119{
120 int ho_error;
121
122 if ((ho_error= handle_options(&argc, &argv, my_long_options, get_one_option)))
123 exit(ho_error);
124
125 /*
126 The following code is to make the command compatible with the old
127 version that required one to use the -n and -s options
128 */
129
130 if (argc == 2)
131 {
132 sym_fname= argv[0];
133 dump_fname= argv[1];
134 }
135 else if (argc == 1)
136 {
137 if (!sym_fname)
138 sym_fname = argv[0];
139 else if (!dump_fname)
140 dump_fname = argv[0];
141 else
142 {
143 usage();
144 exit(1);
145 }
146 }
147 else if (argc != 0 || !sym_fname)
148 {
149 usage();
150 exit(1);
151 }
152 return 0;
153}
154
155
156static void open_files(void)65static void open_files(void)
157{66{
158 fp_out = stdout;67 fp_out = stdout;
159 fp_dump = stdin;68 fp_dump = stdin;
16069
161 if (dump_fname && !(fp_dump= fopen(dump_fname, "r")))70 if (! dump_fname.empty() && !(fp_dump= fopen(dump_fname.c_str(), "r")))
162 die("Could not open %s", dump_fname);71 die("Could not open %s", dump_fname.c_str());
163 /* if name not given, assume stdin*/72 /* if name not given, assume stdin*/
16473
165 if (!sym_fname)74 if (sym_fname.empty())
166 die("Please run nm --numeric-sort on drizzled binary that produced stack "75 die("Please run nm --numeric-sort on drizzled binary that produced stack "
167 "trace dump and specify the path to it with -s or --symbols-file");76 "trace dump and specify the path to it with -s or --symbols-file");
168 if (!(fp_sym= fopen(sym_fname, "r")))77 if (!(fp_sym= fopen(sym_fname.c_str(), "r")))
169 die("Could not open %s", sym_fname);78 die("Could not open %s", sym_fname.c_str());
17079
171}80}
17281
@@ -312,11 +221,75 @@
312221
313int main(int argc, char** argv)222int main(int argc, char** argv)
314{223{
224try
225{
315 MY_INIT(argv[0]);226 MY_INIT(argv[0]);
316 parse_args(argc, argv);227
228 po::options_description commandline_options("Options specific to the commandline");
229 commandline_options.add_options()
230 ("help,h", "Display this help and exit.")
231 ("version,V", "Output version information and exit.")
232 ;
233
234 po::options_description positional_options("Positional Options");
235 positional_options.add_options()
236 ("symbols-file,s", po::value<string>(),
237 "Use specified symbols file.")
238 ("numeric-dump-file,n", po::value<string>(),
239 "Read the dump from specified file.")
240 ;
241
242 po::options_description long_options("Allowed Options");
243 long_options.add(commandline_options).add(positional_options);
244
245 po::positional_options_description p;
246 p.add("symbols-file,s", 1);
247 p.add("numeric-dump-file,n",1);
248
249 po::variables_map vm;
250 po::store(po::command_line_parser(argc, argv).options(long_options).positional(p).run(), vm);
251 po::notify(vm);
252
253 if (vm.count("help"))
254 {
255 printf("%s Ver %s Distrib %s, for %s-%s (%s)\n",internal::my_progname,DUMP_VERSION,
256 VERSION,HOST_VENDOR,HOST_OS,HOST_CPU);
257 printf("MySQL AB, by Sasha Pachev\n");
258 printf("This software comes with ABSOLUTELY NO WARRANTY\n\n");
259 printf("Resolve numeric stack strace dump into symbols.\n\n");
260 printf("Usage: %s [OPTIONS] symbols-file [numeric-dump-file]\n",
261 internal::my_progname);
262 cout << long_options << endl;
263 printf("\n"
264 "The symbols-file should include the output from: \n"
265 " 'nm --numeric-sort drizzled'.\n"
266 "The numeric-dump-file should contain a numeric stack trace "
267 "from drizzled.\n"
268 "If the numeric-dump-file is not given, the stack trace is "
269 "read from stdin.\n");
270 }
271
272 if (vm.count("version"))
273 {
274 printf("%s Ver %s Distrib %s, for %s-%s (%s)\n",internal::my_progname,DUMP_VERSION,
275 VERSION,HOST_VENDOR,HOST_OS,HOST_CPU);
276 }
277
278 if (vm.count("symbols-file") && vm.count("numeric-file-dump"))
279 {
280 sym_fname= vm["symbols-file"].as<string>();
281 dump_fname= vm["numeric-dump-file"].as<string>();
282 }
283
317 open_files();284 open_files();
318 init_sym_table();285 init_sym_table();
319 do_resolve();286 do_resolve();
320 clean_up();287 clean_up();
321 return 0;288}
289 catch(exception &err)
290 {
291 cerr << err.what() << endl;
292 }
293
294 return 0;
322}295}