Browse Source

[eval] support exception modes

Simon Krajewski 7 years ago
parent
commit
047c0a7957

+ 6 - 0
src/macro/eval/evalContext.ml

@@ -103,6 +103,11 @@ type debug_socket = {
 	mutable socket : Unix.file_descr option;
 }
 
+type exception_mode =
+	| CatchAll
+	| CatchUncaught
+	| CatchNone
+
 type debug = {
 	debug : bool;
 	breakpoints : (int,(int,breakpoint) Hashtbl.t) Hashtbl.t;
@@ -112,6 +117,7 @@ type debug = {
 	caught_types : (int,bool) Hashtbl.t;
 	mutable environment_offset_delta : int;
 	mutable debug_socket : debug_socket option;
+	mutable exception_mode : exception_mode;
 }
 
 type eval = {

+ 6 - 1
src/macro/eval/evalDebug.ml

@@ -67,6 +67,11 @@ let debug_loop jit e f =
 		| Some socket -> EvalDebugSocket.make_connection socket
 		| None -> EvalDebugCLI.connection
 	in
+	let debugger_catches v = match ctx.debug.exception_mode with
+		| CatchAll -> true
+		| CatchUncaught -> not (is_caught ctx v)
+		| CatchNone -> false
+	in
 	(* Checks if we hit a breakpoint, runs the code if not. *)
 	let rec run_check_breakpoint env =
 		try
@@ -85,7 +90,7 @@ let debug_loop jit e f =
 		with Not_found -> try
 			f env
 		with
-		| RunTimeException(v,_,_) when not (is_caught ctx v) ->
+		| RunTimeException(v,_,_) when debugger_catches v ->
 			conn.exc_stop ctx v e.epos;
 			ctx.debug.debug_state <- DbgWaiting;
 			run_loop ctx conn.wait run_check_breakpoint env

+ 9 - 0
src/macro/eval/evalDebugSocket.ml

@@ -535,6 +535,15 @@ let make_connection socket =
 					| Exit ->
 						error "Don't know how to handle this expression"
 					end
+				| "setExceptionOptions" ->
+					let sl = match params with
+						| Some (JArray ja) -> List.map (function JString s -> s | _ -> invalid_params()) ja
+						| _ -> invalid_params()
+					in
+					ctx.debug.exception_mode <- if List.mem "all" sl then CatchAll
+						else if List.mem "uncaught" sl then CatchUncaught
+						else CatchNone;
+					Loop(JNull)
 				| meth ->
 					let open JsonRpc in
 					raise (JsonRpc_error (Method_not_found (id, meth)))

+ 1 - 0
src/macro/eval/evalMain.ml

@@ -88,6 +88,7 @@ let create com api is_macro =
 				caught_types = Hashtbl.create 0;
 				environment_offset_delta = 0;
 				debug_socket = socket;
+				exception_mode = CatchUncaught;
 			} in
 			debug := Some debug';
 			debug'