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
1=== modified file 'tests/include.am'
2--- tests/include.am 2010-06-19 19:28:47 +0000
3+++ tests/include.am 2010-08-05 11:50:58 +0000
4@@ -27,7 +27,7 @@
5 CLEANFILES += $(GENSCRIPTS) tests/mtr
6 noinst_PROGRAMS += tests/resolve_stack_dump
7 tests_resolve_stack_dump_SOURCES = tests/resolve_stack_dump.cc
8-tests_resolve_stack_dump_LDADD = ${TEST_LDADD}
9+tests_resolve_stack_dump_LDADD = ${TEST_LDADD} ${BOOST_LIBS}
10
11 TEST_LDADD= drizzled/internal/libinternal.la \
12 $(LIBINTL)
13
14=== modified file 'tests/resolve_stack_dump.cc'
15--- tests/resolve_stack_dump.cc 2010-08-02 18:35:08 +0000
16+++ tests/resolve_stack_dump.cc 2010-08-05 11:50:58 +0000
17@@ -18,7 +18,7 @@
18 */
19
20 #include "config.h"
21-
22+#include <iostream>
23 #include <cstdio>
24 #include <cerrno>
25
26@@ -26,7 +26,10 @@
27 #include "drizzled/internal/my_sys.h"
28 #include "drizzled/internal/m_string.h"
29 #include "drizzled/option.h"
30+#include <boost/program_options.hpp>
31
32+using namespace std;
33+namespace po= boost::program_options;
34 using namespace drizzled;
35
36 #define INIT_SYM_TABLE 4096
37@@ -42,53 +45,12 @@
38 } SYM_ENTRY;
39
40
41-static char* dump_fname = 0, *sym_fname = 0;
42+std::string dump_fname, sym_fname;
43 static DYNAMIC_ARRAY sym_table; /* how do you like this , static DYNAMIC ? */
44 static FILE* fp_dump, *fp_sym = 0, *fp_out;
45
46-static struct option my_long_options[] =
47-{
48- {"help", 'h', "Display this help and exit.",
49- 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
50- {"version", 'V', "Output version information and exit.",
51- 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
52- {"symbols-file", 's', "Use specified symbols file.", (char**) &sym_fname,
53- (char**) &sym_fname, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
54- {"numeric-dump-file", 'n', "Read the dump from specified file.",
55- (char**) &dump_fname, (char**) &dump_fname, 0, GET_STR, REQUIRED_ARG,
56- 0, 0, 0, 0, 0, 0},
57- { 0, 0, 0, 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0}
58-};
59-
60-
61 static void verify_sort(void);
62
63-static void print_version(void)
64-{
65- printf("%s Ver %s Distrib %s, for %s-%s (%s)\n",internal::my_progname,DUMP_VERSION,
66- VERSION,HOST_VENDOR,HOST_OS,HOST_CPU);
67-}
68-
69-
70-static void usage(void)
71-{
72- print_version();
73- printf("MySQL AB, by Sasha Pachev\n");
74- printf("This software comes with ABSOLUTELY NO WARRANTY\n\n");
75- printf("Resolve numeric stack strace dump into symbols.\n\n");
76- printf("Usage: %s [OPTIONS] symbols-file [numeric-dump-file]\n",
77- internal::my_progname);
78- my_print_help(my_long_options);
79- my_print_variables(my_long_options);
80- printf("\n"
81- "The symbols-file should include the output from: \n"
82- " 'nm --numeric-sort drizzled'.\n"
83- "The numeric-dump-file should contain a numeric stack trace "
84- "from drizzled.\n"
85- "If the numeric-dump-file is not given, the stack trace is "
86- "read from stdin.\n");
87-}
88-
89 static void die(const char* fmt, ...)
90 {
91 va_list args;
92@@ -100,73 +62,20 @@
93 exit(1);
94 }
95
96-
97-static int get_one_option(int optid, const struct option *, char *)
98-{
99- switch(optid) {
100- case 'V':
101- print_version();
102- exit(0);
103- case '?':
104- usage();
105- exit(0);
106- }
107- return 0;
108-}
109-
110-
111-static int parse_args(int argc, char **argv)
112-{
113- int ho_error;
114-
115- if ((ho_error= handle_options(&argc, &argv, my_long_options, get_one_option)))
116- exit(ho_error);
117-
118- /*
119- The following code is to make the command compatible with the old
120- version that required one to use the -n and -s options
121- */
122-
123- if (argc == 2)
124- {
125- sym_fname= argv[0];
126- dump_fname= argv[1];
127- }
128- else if (argc == 1)
129- {
130- if (!sym_fname)
131- sym_fname = argv[0];
132- else if (!dump_fname)
133- dump_fname = argv[0];
134- else
135- {
136- usage();
137- exit(1);
138- }
139- }
140- else if (argc != 0 || !sym_fname)
141- {
142- usage();
143- exit(1);
144- }
145- return 0;
146-}
147-
148-
149 static void open_files(void)
150 {
151 fp_out = stdout;
152 fp_dump = stdin;
153
154- if (dump_fname && !(fp_dump= fopen(dump_fname, "r")))
155- die("Could not open %s", dump_fname);
156+ if (! dump_fname.empty() && !(fp_dump= fopen(dump_fname.c_str(), "r")))
157+ die("Could not open %s", dump_fname.c_str());
158 /* if name not given, assume stdin*/
159
160- if (!sym_fname)
161+ if (sym_fname.empty())
162 die("Please run nm --numeric-sort on drizzled binary that produced stack "
163 "trace dump and specify the path to it with -s or --symbols-file");
164- if (!(fp_sym= fopen(sym_fname, "r")))
165- die("Could not open %s", sym_fname);
166+ if (!(fp_sym= fopen(sym_fname.c_str(), "r")))
167+ die("Could not open %s", sym_fname.c_str());
168
169 }
170
171@@ -312,11 +221,75 @@
172
173 int main(int argc, char** argv)
174 {
175+try
176+{
177 MY_INIT(argv[0]);
178- parse_args(argc, argv);
179+
180+ po::options_description commandline_options("Options specific to the commandline");
181+ commandline_options.add_options()
182+ ("help,h", "Display this help and exit.")
183+ ("version,V", "Output version information and exit.")
184+ ;
185+
186+ po::options_description positional_options("Positional Options");
187+ positional_options.add_options()
188+ ("symbols-file,s", po::value<string>(),
189+ "Use specified symbols file.")
190+ ("numeric-dump-file,n", po::value<string>(),
191+ "Read the dump from specified file.")
192+ ;
193+
194+ po::options_description long_options("Allowed Options");
195+ long_options.add(commandline_options).add(positional_options);
196+
197+ po::positional_options_description p;
198+ p.add("symbols-file,s", 1);
199+ p.add("numeric-dump-file,n",1);
200+
201+ po::variables_map vm;
202+ po::store(po::command_line_parser(argc, argv).options(long_options).positional(p).run(), vm);
203+ po::notify(vm);
204+
205+ if (vm.count("help"))
206+ {
207+ printf("%s Ver %s Distrib %s, for %s-%s (%s)\n",internal::my_progname,DUMP_VERSION,
208+ VERSION,HOST_VENDOR,HOST_OS,HOST_CPU);
209+ printf("MySQL AB, by Sasha Pachev\n");
210+ printf("This software comes with ABSOLUTELY NO WARRANTY\n\n");
211+ printf("Resolve numeric stack strace dump into symbols.\n\n");
212+ printf("Usage: %s [OPTIONS] symbols-file [numeric-dump-file]\n",
213+ internal::my_progname);
214+ cout << long_options << endl;
215+ printf("\n"
216+ "The symbols-file should include the output from: \n"
217+ " 'nm --numeric-sort drizzled'.\n"
218+ "The numeric-dump-file should contain a numeric stack trace "
219+ "from drizzled.\n"
220+ "If the numeric-dump-file is not given, the stack trace is "
221+ "read from stdin.\n");
222+ }
223+
224+ if (vm.count("version"))
225+ {
226+ printf("%s Ver %s Distrib %s, for %s-%s (%s)\n",internal::my_progname,DUMP_VERSION,
227+ VERSION,HOST_VENDOR,HOST_OS,HOST_CPU);
228+ }
229+
230+ if (vm.count("symbols-file") && vm.count("numeric-file-dump"))
231+ {
232+ sym_fname= vm["symbols-file"].as<string>();
233+ dump_fname= vm["numeric-dump-file"].as<string>();
234+ }
235+
236 open_files();
237 init_sym_table();
238 do_resolve();
239 clean_up();
240- return 0;
241+}
242+ catch(exception &err)
243+ {
244+ cerr << err.what() << endl;
245+ }
246+
247+ return 0;
248 }