Showing the changes to src/exec/main.cpp (1 of 16 files). Show all
Unified · Split
| @@ -231,14 +231,54 @@ void print_banner(const exec_options &options) · 230 unmodified lines | |||
| 231 | void print_help() | 231 | void print_help() |
| 232 | { | 232 | { |
| 233 | std::cout | 233 | std::cout |
| 234 | << "Usage: disvm-exec [-d[e|m|x]*] [-t <num>] [-q] [-?] <entry module> <args>*\n" | 234 | << "Usage: disvm-exec [-d[e|m|x]*] [-l[s|g|t|T|e|m]*] [-t <num>] [-q] [-?] <entry module> <args>*\n" |
| 235 | << " d - Enable debugger\n" | 235 | " d - Enable debugger\n" |
| 236 | << " e - Break on entry\n" | 236 | " e - Break on entry\n" |
| 237 | << " m - Break on module load\n" | 237 | " m - Break on module load\n" |
| 238 | << " x - Break on exception (first chance)\n" | 238 | " x - Break on exception (first chance)\n" |
| 239 | << " q - Suppress banner and configuration\n" | 239 | " l - Enable logging in a component\n" |
| 240 | << " t - Specify the number of system threads to use (0 < x <= 4)\n" | 240 | " s - Scheduler\n" |
| 241 | << " ? - Print help\n"; | 241 | " g - Garbage collector\n" |
| 242 | " t - Tool extensions\n" | ||
| 243 | " T - Threads\n" | ||
| 244 | " e - Exceptions\n" | ||
| 245 | " m - Memory allocations (noisy)\n" | ||
| 246 | " q - Suppress banner and configuration\n" | ||
| 247 | " t - Specify the number of system threads to use (0 < x <= 4)\n" | ||
| 248 | " ? - Print help\n"; | ||
| 249 | } | ||
| 250 | |||
| 251 | void log_callback(const debug::component_trace_t origin, const debug::log_level_t level, const char *msg_fmt, std::va_list args) | ||
| 252 | { | ||
| 253 | std::stringstream ss; | ||
| 254 | |||
| 255 | switch (level) | ||
| 256 | { | ||
| 257 | case debug::log_level_t::warning: | ||
| 258 | ss << "w: "; | ||
| 259 | break; | ||
| 260 | case debug::log_level_t::debug: | ||
| 261 | ss << "d: "; | ||
| 262 | break; | ||
| 263 | } | ||
| 264 | |||
| 265 | std::array<char, 1024> buffer; | ||
| 266 | const auto r = std::vsnprintf(buffer.data(), buffer.size(), msg_fmt, args); | ||
| 267 | buffer[r] = '\0'; | ||
| 268 | |||
| 269 | ss << buffer.data() << "\n"; | ||
| 270 | if (r == buffer.size() - 1) | ||
| 271 | ss << " <Possible truncation>\n"; | ||
| 272 | |||
| 273 | std::cout << ss.str(); | ||
| 274 | } | ||
| 275 | |||
| 276 | void enable_logging(debug::component_trace_t c) | ||
| 277 | { | ||
| 278 | debug::set_component_tracing(c, true); | ||
| 279 | |||
| 280 | // Constantly setting the callback | ||
| 281 | debug::set_logging_callback(log_callback); | ||
| 242 | } | 282 | } |
| 243 | 283 | ||
| 244 | void process_arg(char* arg, std::function<char *()> next, exec_options &options) | 284 | void process_arg(char* arg, std::function<char *()> next, exec_options &options) |
| @@ -289,6 +329,27 @@ void process_arg(char* arg, std::function<char *()> next, exec_options &options) · 44 unmodified lines | |||
| 289 | } | 329 | } |
| 290 | break; | 330 | break; |
| 291 | 331 | ||
| 332 | case 'l': | ||
| 333 | for (auto i = std::size_t{ 2 }; i < arg_len; ++i) | ||
| 334 | { | ||
| 335 | switch (arg[i]) | ||
| 336 | { | ||
| 337 | case 's': enable_logging(debug::component_trace_t::scheduler); | ||
| 338 | break; | ||
| 339 | case 'g': enable_logging(debug::component_trace_t::garbage_collector); | ||
| 340 | break; | ||
| 341 | case 't': enable_logging(debug::component_trace_t::tool); | ||
| 342 | break; | ||
| 343 | case 'T': enable_logging(debug::component_trace_t::thread); | ||
| 344 | break; | ||
| 345 | case 'e': enable_logging(debug::component_trace_t::exception); | ||
| 346 | break; | ||
| 347 | case 'm': enable_logging(debug::component_trace_t::memory); | ||
| 348 | break; | ||
| 349 | } | ||
| 350 | } | ||
| 351 | break; | ||
| 352 | |||
| 292 | case 'q': | 353 | case 'q': |
| 293 | options.quiet_start = true; | 354 | options.quiet_start = true; |
| 294 | break; | 355 | break; |