Skip to content

Commit 7bd4fb0

Browse files
committed
Output to debug console when uncaught_exc occurs.
1 parent a27bb72 commit 7bd4fb0

File tree

4 files changed

+42
-33
lines changed

4 files changed

+42
-33
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
* Fix breakpoints resolution algorithm.
66
* Fix variables pane sometimes flooding by `Assertion_failure(...)` raised at Env_hack.ml.
77
* Fix incorrectly inspect 'a type as int.
8+
* Output to debug console when uncaught_exc occurs.
89

910
## 1.0.2 - 2021-02-22
1011

src/adapter/inspect.ml

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,13 @@ let run ~init_args ~launch_args ~dbg rpc =
3232
Hashtbl.reset value_tbl;
3333
match status with
3434
| Running -> Lwt.return ()
35-
| Stopped (Exited | Uncaught_exc) ->
35+
| Stopped ((Exited | Uncaught_exc) as reason) ->
36+
if reason = Uncaught_exc then
37+
Debug_rpc.send_event rpc
38+
(module Output_event)
39+
Output_event.Payload.(
40+
make ~output:"Program exited due to Uncaught_exc" ())
41+
else Lwt.return ();%lwt
3642
Debug_rpc.send_event rpc
3743
(module Terminated_event)
3844
Terminated_event.Payload.(make ())
@@ -146,7 +152,8 @@ let run ~init_args ~launch_args ~dbg rpc =
146152
let num_named = value#num_named in
147153
let num_indexed = value#num_indexed in
148154
let is_complex =
149-
num_indexed > 0 || num_named > 0 || num_named = -1 || Option.is_some value#vscode_menu_context
155+
num_indexed > 0 || num_named > 0 || num_named = -1
156+
|| Option.is_some value#vscode_menu_context
150157
in
151158
let handle = if is_complex then alloc_handle () else 0 in
152159
Hashtbl.replace value_tbl handle value;
@@ -184,5 +191,6 @@ let run ~init_args ~launch_args ~dbg rpc =
184191
let open VariableGetClosureCodeLocation in
185192
match Hashtbl.find_opt value_tbl arg.handle with
186193
| None -> Lwt.return { Result.location = None }
187-
| Some value -> Lwt.return { Result.location = value#closure_code_location });
194+
| Some value ->
195+
Lwt.return { Result.location = value#closure_code_location });
188196
Lwt.join [ process_state_changes () ]

src/debugger/core/controller.ml

Lines changed: 27 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,9 @@ let _set_frag_events symbols conn frag =
5656
|> Seq.map (fun it -> (module_.frag, it.ev_pos)))
5757
|> Lwt_seq.iter_s (Wire_protocol.set_event conn);%lwt
5858
Lwt.return
59-
( debug_modules
59+
(debug_modules
6060
|> Seq.map (fun (it : Code_module.t) -> (it.frag, it.module_id))
61-
|> FragModuleIdSet_.of_seq )
61+
|> FragModuleIdSet_.of_seq)
6262

6363
let root ?debug_filter debug_sock symbols_file =
6464
let%lwt fd, _ = Lwt_unix.accept debug_sock in
@@ -94,7 +94,7 @@ let fork t debug_sock =
9494
if pid' = pid then Lwt.return conn
9595
else (
9696
Lwt_unix.close fd;%lwt
97-
wait_conn () )
97+
wait_conn ())
9898
in
9999
let%lwt conn = wait_conn () in
100100
Lwt.return
@@ -133,14 +133,14 @@ let stop ?(gracefully = false) t =
133133
if gracefully then Wire_protocol.stop t.conn
134134
else (
135135
Unix.kill t.pid 9;
136-
Lwt.return () );%lwt
136+
Lwt.return ());%lwt
137137
t.dead <- true;
138138
let () =
139139
match t.parent with
140140
| None -> ()
141141
| Some parent -> Lwt.async (fun () -> Wire_protocol.wait parent.conn)
142142
in
143-
Lwt.return () )
143+
Lwt.return ())
144144

145145
let execute ?(yield_steps = Int.max_int)
146146
?(on_yield = fun () -> Lwt.return `Continue) ?trap_barrier
@@ -197,33 +197,31 @@ let execute ?(yield_steps = Int.max_int)
197197
let%lwt r = run () in
198198
if not (t.breakpoints |> PcSet_.mem pc) then (
199199
Wire_protocol.reset_instr t.conn pc;%lwt
200-
Wire_protocol.set_event t.conn pc )
200+
Wire_protocol.set_event t.conn pc)
201201
else Lwt.return ();%lwt
202202
Lwt.return r
203203
in
204-
let run =
205-
match trap_barrier with
206-
| None -> run
207-
| Some trap_barrier ->
208-
fun () ->
209-
Wire_protocol.set_trap_barrier t.conn trap_barrier;%lwt
210-
let%lwt summary, remaining_steps, sp_pc = run () in
211-
Wire_protocol.set_trap_barrier t.conn 0;%lwt
212-
if summary = `Trap_barrier then
213-
let stop_on_event () =
214-
let%lwt summary', remaining_steps', sp_pc' = exec_dynlink _1 in
215-
let remaining_steps =
216-
remaining_steps ++ (_1 -- remaining_steps')
217-
in
218-
match summary' with
219-
| `Trap_barrier -> assert false
220-
| `Event | `Breakpoint ->
221-
Lwt.return (`Trap_barrier, remaining_steps, sp_pc')
222-
| `Exited | `Uncaught_exc | `Yield_stop _ ->
223-
Lwt.return (summary', remaining_steps, sp_pc')
224-
in
225-
stop_on_event ()
226-
else Lwt.return (summary, remaining_steps, sp_pc)
204+
let run () =
205+
let%lwt () =
206+
match trap_barrier with
207+
| None -> Lwt.return ()
208+
| Some trap_barrier -> Wire_protocol.set_trap_barrier t.conn trap_barrier
209+
in
210+
let%lwt summary, remaining_steps, sp_pc = run () in
211+
Wire_protocol.set_trap_barrier t.conn 0;%lwt
212+
if summary = `Trap_barrier then
213+
let rec stop_on_event () =
214+
let%lwt summary', remaining_steps', sp_pc' = exec_dynlink _1 in
215+
let remaining_steps = remaining_steps ++ (_1 -- remaining_steps') in
216+
match summary' with
217+
| `Trap_barrier -> stop_on_event ()
218+
| `Event | `Breakpoint ->
219+
Lwt.return (`Trap_barrier, remaining_steps, sp_pc')
220+
| `Exited | `Uncaught_exc | `Yield_stop _ ->
221+
Lwt.return (summary', remaining_steps, sp_pc')
222+
in
223+
stop_on_event ()
224+
else Lwt.return (summary, remaining_steps, sp_pc)
227225
in
228226
let%lwt summary, remaining_steps, sp_pc = run () in
229227
if summary = `Exited || summary = `Uncaught_exc then stop ~gracefully:true t

src/debugger/debugger.ml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,9 @@ let _summary_to_reason summary =
274274
match summary with
275275
| `Event -> Step
276276
| `Yield_stop 1 -> Pause
277-
| `Yield_stop _ | `Trap_barrier -> raise (Invalid_argument "summary")
277+
| `Yield_stop x ->
278+
raise (Invalid_argument ("summary is `Yield_stop " ^ string_of_int x))
279+
| `Trap_barrier -> raise (Invalid_argument "summary is `Trap_barrier")
278280
| `Breakpoint -> Breakpoint
279281
| `Exited -> Exited
280282
| `Uncaught_exc -> Uncaught_exc

0 commit comments

Comments
 (0)