diff options
author | Jo-Philipp Wich <jo@mein.io> | 2021-07-09 19:35:19 +0200 |
---|---|---|
committer | Jo-Philipp Wich <jo@mein.io> | 2021-07-11 15:49:14 +0200 |
commit | 1d60418132460c23b216a2f8a9e0ea8897d32ea4 (patch) | |
tree | fe1640e8d9b2f2a00f9113c971c86a7c5eb28fcd /vm.c | |
parent | 48f33ad70bf584a97a2e2d3870b04bbc970194b7 (diff) |
vm: add API to control trace mode
Add a public getter and setter to read and set the VM trace level
respectively. Use the new API to control the trace mode with a newly
introduced `-t` command line switch.
Drop support for honouring the `TRACE` environment variable as
host programs embedding ucode might want to prevent that behaviour
or handle it differently.
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
Diffstat (limited to 'vm.c')
-rw-r--r-- | vm.c | 19 |
1 files changed, 14 insertions, 5 deletions
@@ -14,7 +14,6 @@ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -#include <stdlib.h> #include <stdarg.h> #include <string.h> #include <assert.h> @@ -137,13 +136,9 @@ uc_vm_output_exception(uc_vm *vm, uc_exception *ex); void uc_vm_init(uc_vm *vm, uc_parse_config *config) { - char *s = getenv("TRACE"); - vm->exception.type = EXCEPTION_NONE; vm->exception.message = NULL; - vm->trace = s ? strtoul(s, NULL, 0) : 0; - vm->config = config; vm->open_upvals = NULL; @@ -160,6 +155,8 @@ void uc_vm_init(uc_vm *vm, uc_parse_config *config) uc_vm_alloc_global_scope(vm); uc_vm_exception_handler_set(vm, uc_vm_output_exception); + + uc_vm_trace_set(vm, 0); } void uc_vm_free(uc_vm *vm) @@ -2409,3 +2406,15 @@ uc_vm_exception_handler_set(uc_vm *vm, uc_exception_handler_t *exhandler) { vm->exhandler = exhandler; } + +uint32_t +uc_vm_trace_get(uc_vm *vm) +{ + return vm->trace; +} + +void +uc_vm_trace_set(uc_vm *vm, uint32_t level) +{ + vm->trace = level; +} |