| @@ -12,6 +12,7 @@ · 11 unmodified lines |
| 12 | #include <debug.h> | 12 | #include <debug.h> |
| 13 | #include <exceptions.h> | 13 | #include <exceptions.h> |
| 14 | #include <vm_asm.h> | 14 | #include <vm_asm.h> |
| | 15 | #include <vm_version.h> |
| 15 | #include "exec.h" | 16 | #include "exec.h" |
| 16 | | 17 | |
| 17 | using namespace disvm; | 18 | using namespace disvm; |
| @@ -169,7 +170,7 @@ namespace · 151 unmodified lines |
| 169 | | 170 | |
| 170 | struct arg_exception_t : std::runtime_error | 171 | struct arg_exception_t : std::runtime_error |
| 171 | { | 172 | { |
| 172 | arg_exception_t(const char *m, const char *arg) | 173 | arg_exception_t(const char *m, const char *arg = nullptr) |
| 173 | : std::runtime_error{ m } | 174 | : std::runtime_error{ m } |
| 174 | , arg{ arg } | 175 | , arg{ arg } |
| 175 | { } | 176 | { } |
| @@ -179,8 +180,20 @@ struct arg_exception_t : std::runtime_error · 3 unmodified lines |
| 179 | | 180 | |
| 180 | struct exec_options | 181 | struct exec_options |
| 181 | { | 182 | { |
| | 183 | exec_options() |
| | 184 | : debugger{} |
| | 185 | , enabled_debugger{ false } |
| | 186 | , quiet_start{ false } |
| | 187 | , print_help{ false } |
| | 188 | , sys_thread_count{ vm_t::default_system_thread_count } |
| | 189 | , thread_quanta{ vm_t::default_thread_quanta } |
| | 190 | { } |
| | 191 | |
| 182 | std::vector<char *> vm_args; | 192 | std::vector<char *> vm_args; |
| 183 | | 193 | |
| | 194 | uint32_t sys_thread_count; |
| | 195 | uint32_t thread_quanta; |
| | 196 | |
| 184 | bool print_help; | 197 | bool print_help; |
| 185 | bool quiet_start; | 198 | bool quiet_start; |
| 186 | bool enabled_debugger; | 199 | bool enabled_debugger; |
| @@ -189,10 +202,15 @@ struct exec_options · 2 unmodified lines |
| 189 | | 202 | |
| 190 | void print_banner(const exec_options &options) | 203 | void print_banner(const exec_options &options) |
| 191 | { | 204 | { |
| | 205 | std::cout << "DisVM " << DISVM_VERSION_MAJOR << '.' << DISVM_VERSION_MINOR << '.' << DISVM_VERSION_PATCH; |
| | 206 | |
| | 207 | if (DISVM_VERSION_LABEL != nullptr) |
| | 208 | std::cout << '-' << DISVM_VERSION_LABEL; |
| | 209 | |
| 192 | std::cout | 210 | std::cout |
| 193 | << "DisVM\n" | 211 | << "\n----------------\n" |
| 194 | << "----------------\n" | 212 | << "Debugger enabled: " << std::boolalpha << options.enabled_debugger << "\n" |
| 195 | << "Debugger enabled: " << std::boolalpha << options.enabled_debugger << "\n"; | 213 | << "System thread usage: " << options.sys_thread_count << "\n"; |
| 196 | | 214 | |
| 197 | if (options.enabled_debugger) | 215 | if (options.enabled_debugger) |
| 198 | std::cout << options.debugger << "\n"; | 216 | std::cout << options.debugger << "\n"; |
| @@ -203,12 +221,13 @@ void print_banner(const exec_options &options) · 4 unmodified lines |
| 203 | void print_help() | 221 | void print_help() |
| 204 | { | 222 | { |
| 205 | std::cout | 223 | std::cout |
| 206 | << "Usage: disvm-exec [-d[e|m|x]*] [-q] [-?] <entry module> <args>*\n" | 224 | << "Usage: disvm-exec [-d[e|m|x]*] [-t <num>] [-q] [-?] <entry module> <args>*\n" |
| 207 | << " d - Enable debugger\n" | 225 | << " d - Enable debugger\n" |
| 208 | << " e - Break on entry\n" | 226 | << " e - Break on entry\n" |
| 209 | << " m - Break on module load\n" | 227 | << " m - Break on module load\n" |
| 210 | << " x - Break on exception (first chance)\n" | 228 | << " x - Break on exception (first chance)\n" |
| 211 | << " q - Suppress banner and configuration\n" | 229 | << " q - Suppress banner and configuration\n" |
| | 230 | << " t - Specify the number of system threads to use (0 < x <= 4)\n" |
| 212 | << " ? - Print help\n"; | 231 | << " ? - Print help\n"; |
| 213 | } | 232 | } |
| 214 | | 233 | |
| @@ -243,7 +262,21 @@ void process_arg(char* arg, std::function<char *()> next, exec_options &options) · 28 unmodified lines |
| 243 | break; | 262 | break; |
| 244 | } | 263 | } |
| 245 | } | 264 | } |
| | 265 | break; |
| | 266 | |
| | 267 | case 't': |
| | 268 | { |
| | 269 | auto sys_threads_str = next(); |
| | 270 | if (sys_threads_str == nullptr) |
| | 271 | throw arg_exception_t{ "System thread requires count" }; |
| 246 | | 272 | |
| | 273 | char *end; |
| | 274 | auto sys_threads = ::strtol(sys_threads_str, &end, 10); |
| | 275 | if (sys_threads <= 0 || 4 < sys_threads) |
| | 276 | throw arg_exception_t{ "Invalid system thread value", sys_threads_str }; |
| | 277 | |
| | 278 | options.sys_thread_count = sys_threads; |
| | 279 | } |
| 247 | break; | 280 | break; |
| 248 | | 281 | |
| 249 | case 'q': | 282 | case 'q': |
| @@ -293,7 +326,7 @@ int main(int argc, char* argv[]) · 43 unmodified lines |
| 293 | return EXIT_SUCCESS; | 326 | return EXIT_SUCCESS; |
| 294 | } | 327 | } |
| 295 | | 328 | |
| 296 | vm_t vm; | 329 | vm_t vm{ options.sys_thread_count, options.thread_quanta }; |
| 297 | | 330 | |
| 298 | if (options.enabled_debugger) | 331 | if (options.enabled_debugger) |
| 299 | vm.load_tool(std::make_shared<debugger>(options.debugger)); | 332 | vm.load_tool(std::make_shared<debugger>(options.debugger)); |