fix(library/vm/vm): curr_fn() may not be available

This commit is contained in:
Leonardo de Moura 2017-01-12 11:47:45 -08:00
parent ad8c241129
commit 3967cd28fa
5 changed files with 25 additions and 6 deletions

View file

@ -197,8 +197,10 @@ do
cmd_loop s ["s"]
meta def bp_reached (s : state) : vm bool :=
do fn ← vm.curr_fn,
return $ s^.fn_bps^.any (λ p, p^.is_prefix_of fn)
(do fn ← vm.curr_fn,
return $ s^.fn_bps^.any (λ p, p^.is_prefix_of fn))
<|>
return ff
meta def in_active_bps (s : state) : vm bool :=
do sz ← vm.call_stack_size,

View file

@ -375,7 +375,11 @@ vm_obj vm_get_options(vm_obj const & /*s*/) {
}
vm_obj vm_curr_fn(vm_obj const & /*s*/) {
return mk_vm_success(to_obj(get_vm_state_being_debugged().curr_fn()));
if (auto fn = get_vm_state_being_debugged().curr_fn()) {
return mk_vm_success(to_obj(*fn));
} else {
return mk_vm_failure();
}
}
vm_obj vm_obj_to_string(vm_obj const & o, vm_obj const & /*s*/) {

View file

@ -3034,6 +3034,13 @@ optional<vm_decl> vm_state::get_decl(name const & n) const {
return optional<vm_decl>();
}
optional<name> vm_state::curr_fn() const {
if (m_fn_idx == g_null_fn_idx)
return optional<name>();
else
return optional<name>(m_decl_map.find(m_fn_idx)->get_name());
}
#if defined(LEAN_MULTI_THREAD)
static name * g_profiler = nullptr;
static name * g_profiler_freq = nullptr;

View file

@ -687,7 +687,7 @@ public:
optional<vm_decl> get_decl(name const & n) const;
name curr_fn() const { return m_decl_map.find(m_fn_idx)->get_name(); }
optional<name> curr_fn() const;
void invoke_fn(name const & fn);
void invoke_fn(unsigned fn_idx);

View file

@ -44,12 +44,18 @@ meta def basic_monitor : vm_monitor nat :=
step := λ sz, do
csz ← vm.call_stack_size,
if sz = csz then return sz
else do
else
do {
fn ← vm.curr_fn,
pos ← pos_info fn,
vm.trace (to_fmt "[" ++ csz ++ "]: " ++ to_fmt fn ++ " @ " ++ pos),
display_args,
return csz }
return csz
}
<|>
return csz -- curr_fn failed
}
run_command vm_monitor.register `basic_monitor