Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mono/mono.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLarry Ewing <lewing@microsoft.com>2020-01-29 03:47:16 +0300
committerLarry Ewing <lewing@microsoft.com>2020-01-29 03:53:36 +0300
commitedfe20ffc74dc1918a8fc3416a37404a9ad3d35b (patch)
treeed7e0fc2d686f982e4b786fb71f3f1f28f9d17cc
parent0fe46d8d355548a106aa4a99da92d2ca288880b5 (diff)
[wasm][debugger] start reworking logging logic
-rw-r--r--sdks/wasm/Mono.WebAssembly.DebuggerProxy/DevToolsClient.cs7
-rw-r--r--sdks/wasm/Mono.WebAssembly.DebuggerProxy/DevToolsProxy.cs56
-rw-r--r--sdks/wasm/Mono.WebAssembly.DebuggerProxy/MonoProxy.cs43
3 files changed, 59 insertions, 47 deletions
diff --git a/sdks/wasm/Mono.WebAssembly.DebuggerProxy/DevToolsClient.cs b/sdks/wasm/Mono.WebAssembly.DebuggerProxy/DevToolsClient.cs
index 2a2bda65c4c..92272f9ae34 100644
--- a/sdks/wasm/Mono.WebAssembly.DebuggerProxy/DevToolsClient.cs
+++ b/sdks/wasm/Mono.WebAssembly.DebuggerProxy/DevToolsClient.cs
@@ -130,5 +130,10 @@ namespace WebAssembly.Net.Debugging {
return false;
}
+
+ protected virtual void Log (string priority, string msg)
+ {
+ //
+ }
}
-}
+}
diff --git a/sdks/wasm/Mono.WebAssembly.DebuggerProxy/DevToolsProxy.cs b/sdks/wasm/Mono.WebAssembly.DebuggerProxy/DevToolsProxy.cs
index 928b117b9a2..750e037e4a7 100644
--- a/sdks/wasm/Mono.WebAssembly.DebuggerProxy/DevToolsProxy.cs
+++ b/sdks/wasm/Mono.WebAssembly.DebuggerProxy/DevToolsProxy.cs
@@ -27,14 +27,13 @@ namespace WebAssembly.Net.Debugging {
Result (JObject result, JObject error)
{
- Console.WriteLine ($"result: {result}");
this.Value = result;
this.Error = error;
}
public static Result FromJson (JObject obj)
{
- //Console.WriteLine ($"from result: {obj}");
+ //Log ("protocol", $"from result: {obj}");
return new Result (obj ["result"] as JObject, obj ["error"] as JObject);
}
@@ -133,7 +132,7 @@ namespace WebAssembly.Net.Debugging {
while (true) {
if (socket.State != WebSocketState.Open) {
- Console.WriteLine ($"WSProxy: Socket is no longer open.");
+ Log ("error", $"DevToolsProxy: Socket is no longer open.");
client_initiated_close.TrySetResult (true);
return null;
}
@@ -156,14 +155,15 @@ namespace WebAssembly.Net.Debugging {
return queues.FirstOrDefault (q => q.Ws == ws);
}
- DevToolsQueue GetQueueForTask (Task task) {
+ DevToolsQueue GetQueueForTask (Task task)
+ {
return queues.FirstOrDefault (q => q.CurrentSend == task);
}
void Send (WebSocket to, JObject o, CancellationToken token)
{
- var socketName = this.browser == to ? "Send-browser" : "Send-ide";
- //Debug ($"{socketName}: {o}");
+ var sender = browser == to ? "Send-browser" : "Send-ide";
+ Log ("protocol", $"{sender}: {o}");
var bytes = Encoding.UTF8.GetBytes (o.ToString ());
var queue = GetQueueForSocket (to);
@@ -210,7 +210,7 @@ namespace WebAssembly.Net.Debugging {
void ProcessBrowserMessage (string msg, CancellationToken token)
{
- Debug ($"browser: {msg}");
+ Log ("protocol", $"browser: {msg}");
var res = JObject.Parse (msg);
if (res ["id"] == null)
@@ -221,7 +221,7 @@ namespace WebAssembly.Net.Debugging {
void ProcessIdeMessage (string msg, CancellationToken token)
{
- Debug ($"ide: {msg}");
+ Log ("protocol", $"ide: {msg}");
if (!string.IsNullOrEmpty (msg)) {
var res = JObject.Parse (msg);
pending_ops.Add (OnCommand (new MessageId { id = res ["id"].Value<int> (), sessionId = res ["sessionId"]?.Value<string> () }, res ["method"].Value<string> (), res ["params"] as JObject, token));
@@ -229,7 +229,7 @@ namespace WebAssembly.Net.Debugging {
}
internal async Task<Result> SendCommand (SessionId id, string method, JObject args, CancellationToken token) {
- // Debug ($"sending command {method}: {args}");
+ //Log ("verbose", $"sending command {method}: {args}");
return await SendCommandInternal (id, method, args, token);
}
@@ -247,7 +247,7 @@ namespace WebAssembly.Net.Debugging {
var msgId = new MessageId { id = id, sessionId = sessionId.sessionId };
- //Debug ($"add cmd id {sessionId}-{id}");
+ //Log ("verbose", $"add cmd id {sessionId}-{id}");
pending_cmds.Add ((msgId , tcs));
Send (this.browser, o, token);
@@ -256,7 +256,7 @@ namespace WebAssembly.Net.Debugging {
public void SendEvent (SessionId sessionId, string method, JObject args, CancellationToken token)
{
- //Debug ($"sending event {method}: {args}");
+ //Log ("verbose", $"sending event {method}: {args}");
SendEventInternal (sessionId, method, args, token);
}
@@ -273,7 +273,7 @@ namespace WebAssembly.Net.Debugging {
internal void SendResponse (MessageId id, Result result, CancellationToken token)
{
- //Debug ($"sending response: {id}: {result.ToJObject (id)}");
+ //Log ("verbose", $"sending response: {id}: {result.ToJObject (id)}");
SendResponseInternal (id, result, token);
}
@@ -287,16 +287,16 @@ namespace WebAssembly.Net.Debugging {
// , HttpContext context)
public async Task Run (Uri browserUri, WebSocket ideSocket)
{
- Debug ($"WsProxy Starting on {browserUri}");
+ Log ("info", $"DevToolsProxy: Starting on {browserUri}");
using (this.ide = ideSocket) {
- Debug ($"WsProxy: IDE waiting for connection on {browserUri}");
+ Log ("verbose", $"DevToolsProxy: IDE waiting for connection on {browserUri}");
queues.Add (new DevToolsQueue (this.ide));
using (this.browser = new ClientWebSocket ()) {
this.browser.Options.KeepAliveInterval = Timeout.InfiniteTimeSpan;
await this.browser.ConnectAsync (browserUri, CancellationToken.None);
queues.Add (new DevToolsQueue (this.browser));
- Debug ($"WsProxy: Client connected on {browserUri}");
+ Log ("verbose", $"DevToolsProxy: Client connected on {browserUri}");
var x = new CancellationTokenSource ();
pending_ops.Add (ReadOne (browser, x.Token));
@@ -325,7 +325,7 @@ namespace WebAssembly.Net.Debugging {
throw new Exception ("side task must always complete with an exception, what's going on???");
} else if (task == pending_ops [3]) {
var res = ((Task<bool>)task).Result;
- Debug ($"WsProxy: Client initiated close from {browserUri}");
+ Log ("verbose", $"DevToolsProxy: Client initiated close from {browserUri}");
x.Cancel ();
} else {
//must be a background task
@@ -339,7 +339,7 @@ namespace WebAssembly.Net.Debugging {
}
}
} catch (Exception e) {
- Debug ($"WsProxy::Run: Exception {e}");
+ Log ("error", $"DevToolsProxy::Run: Exception {e}");
//throw;
} finally {
if (!x.IsCancellationRequested)
@@ -349,14 +349,22 @@ namespace WebAssembly.Net.Debugging {
}
}
- protected void Debug (string msg)
+ protected void Log (string priority, string msg)
{
- Console.WriteLine (msg);
- }
-
- protected void Info (string msg)
- {
- Console.WriteLine (msg);
+ switch (priority) {
+ case "protocol":
+ Console.WriteLine (msg);
+ break;
+ case "verbose":
+ Console.WriteLine (msg);
+ break;
+ case "info":
+ case "warning":
+ case "error":
+ default:
+ Console.WriteLine (msg);
+ break;
+ }
}
}
}
diff --git a/sdks/wasm/Mono.WebAssembly.DebuggerProxy/MonoProxy.cs b/sdks/wasm/Mono.WebAssembly.DebuggerProxy/MonoProxy.cs
index f7e25dfc546..9cdb0549002 100644
--- a/sdks/wasm/Mono.WebAssembly.DebuggerProxy/MonoProxy.cs
+++ b/sdks/wasm/Mono.WebAssembly.DebuggerProxy/MonoProxy.cs
@@ -163,7 +163,7 @@ namespace WebAssembly.Net.Debugging {
}
case "Debugger.setBreakpointByUrl": {
- Info ($"BP req {args}");
+ Log ("info", $"BP req {args}");
var bp_req = BreakPointRequest.Parse (args, store);
if (bp_req != null) {
await SetBreakPoint (id, bp_req, token);
@@ -236,7 +236,7 @@ namespace WebAssembly.Net.Debugging {
async Task OnRuntimeReady (SessionId sessionId, CancellationToken token)
{
- Info ("RUNTIME READY, PARTY TIME");
+ Log ("info", "RUNTIME READY, PARTY TIME");
await RuntimeReady (sessionId, token);
await SendCommand (sessionId, "Debugger.resume", new JObject (), token);
SendEvent (sessionId, "Mono.runtimeReady", new JObject (), token);
@@ -271,9 +271,9 @@ namespace WebAssembly.Net.Debugging {
return;
}
- Debug ($"call stack (err is {res.Error} value is:\n{res.Value}");
+ Log ("verbose", $"call stack (err is {res.Error} value is:\n{res.Value}");
var bp_id = res_value? ["breakpoint_id"]?.Value<int> ();
- Debug ($"We just hit bp {bp_id}");
+ Log ("verbose", $"We just hit bp {bp_id}");
if (!bp_id.HasValue) {
//Give up and send the original call stack
SendEvent (sessionId, "Debugger.paused", args, token);
@@ -299,14 +299,14 @@ namespace WebAssembly.Net.Debugging {
var asm = store.GetAssemblyByName (assembly_name);
if (asm == null) {
- Info ($"Unable to find assembly: {assembly_name}");
+ Log ("info",$"Unable to find assembly: {assembly_name}");
continue;
}
var method = asm.GetMethodByToken (method_token);
if (method == null) {
- Info ($"Unable to find il offset: {il_pos} in method token: {method_token} assembly name: {assembly_name}");
+ Log ("info", $"Unable to find il offset: {il_pos} in method token: {method_token} assembly name: {assembly_name}");
continue;
}
@@ -320,8 +320,8 @@ namespace WebAssembly.Net.Debugging {
continue;
}
- Info ($"frame il offset: {il_pos} method token: {method_token} assembly name: {assembly_name}");
- Info ($"\tmethod {method.Name} location: {location}");
+ Log ("info", $"frame il offset: {il_pos} method token: {method_token} assembly name: {assembly_name}");
+ Log ("info", $"\tmethod {method.Name} location: {location}");
frames.Add (new Frame (method, location, frame_id));
callFrames.Add (JObject.FromObject (new {
@@ -373,7 +373,7 @@ namespace WebAssembly.Net.Debugging {
async Task OnDefaultContext (MessageId ctx_id, JObject aux_data, CancellationToken token)
{
- Debug ("Default context created, clearing state and sending events");
+ Log ("verbose", "Default context created, clearing state and sending events");
//reset all bps
foreach (var b in this.breakpoints){
@@ -391,12 +391,12 @@ namespace WebAssembly.Net.Debugging {
this.ctx_id = ctx_id.id;
this.aux_ctx_data = aux_data;
- Debug ("checking if the runtime is ready");
+ Log ("verbose", "checking if the runtime is ready");
var res = await SendCommand (ctx_id, "Runtime.evaluate", o, token);
var is_ready = res.Value? ["result"]? ["value"]?.Value<bool> ();
- //Debug ($"\t{is_ready}");
+ //Log ("verbose", $"\t{is_ready}");
if (is_ready.HasValue && is_ready.Value == true) {
- Debug ("RUNTIME LOOK READY. GO TIME!");
+ Log ("verbose", "RUNTIME LOOK READY. GO TIME!");
await OnRuntimeReady (ctx_id, token);
}
}
@@ -479,12 +479,11 @@ namespace WebAssembly.Net.Debugging {
result = var_list
});
} catch (Exception e) {
- Debug ($"failed to parse {res.Value} - {e.Message}");
+ Log ("verbose", $"failed to parse {res.Value} - {e.Message}");
}
SendResponse(msg_id, Result.Ok(o), token);
}
-
async Task GetScopeProperties (MessageId msg_id, int scope_id, CancellationToken token)
{
var scope = this.current_callstack.FirstOrDefault (s => s.Id == scope_id);
@@ -551,7 +550,7 @@ namespace WebAssembly.Net.Debugging {
});
SendResponse (msg_id, Result.Ok (o), token);
} catch (Exception exception) {
- Debug ($"Error resolving scope properties {exception.Message}");
+ Log ("verbose", $"Error resolving scope properties {exception.Message}");
SendResponse (msg_id, res, token);
}
}
@@ -576,7 +575,7 @@ namespace WebAssembly.Net.Debugging {
if (ret_code.HasValue) {
bp.RemoteId = ret_code.Value;
bp.State = BreakPointState.Active;
- //Debug ($"BP local id {bp.LocalId} enabled with remote id {bp.RemoteId}");
+ //Log ("verbose", $"BP local id {bp.LocalId} enabled with remote id {bp.RemoteId}");
}
return res;
@@ -614,7 +613,7 @@ namespace WebAssembly.Net.Debugging {
executionContextAuxData = this.aux_ctx_data,
dotNetUrl = s.DotNetUrl,
});
- //Debug ($"\tsending {s.Url}");
+ //Log ("verbose", $"\tsending {s.Url}");
SendEvent (sessionId, "Debugger.scriptParsed", ok, token);
}
@@ -628,7 +627,7 @@ namespace WebAssembly.Net.Debugging {
var clear_result = await SendCommand (sessionId, "Runtime.evaluate", o, token);
if (clear_result.IsErr) {
- Debug ($"Failed to clear breakpoints due to {clear_result}");
+ Log ("verbose", $"Failed to clear breakpoints due to {clear_result}");
}
@@ -643,7 +642,7 @@ namespace WebAssembly.Net.Debugging {
//if we fail we just buble that to the IDE (and let it panic over it)
if (!ret_code.HasValue) {
//FIXME figure out how to inform the IDE of that.
- Info ($"FAILED TO ENABLE BP {bp.LocalId}");
+ Log ("info", $"FAILED TO ENABLE BP {bp.LocalId}");
bp.State = BreakPointState.Disabled;
}
}
@@ -658,7 +657,7 @@ namespace WebAssembly.Net.Debugging {
var bp = breakpoints.FirstOrDefault (b => b.LocalId == the_id);
if (bp == null) {
- Info ($"Could not find dotnet bp with id {the_id}");
+ Log ("info", $"Could not find dotnet bp with id {the_id}");
return false;
}
@@ -694,10 +693,10 @@ namespace WebAssembly.Net.Debugging {
async Task SetBreakPoint (MessageId msg_id, BreakPointRequest req, CancellationToken token)
{
var bp_loc = store?.FindBestBreakpoint (req);
- Info ($"BP request for '{req}' runtime ready {runtime_ready} location '{bp_loc}'");
+ Log ("info", $"BP request for '{req}' runtime ready {runtime_ready} location '{bp_loc}'");
if (bp_loc == null) {
- Info ($"Could not resolve breakpoint request: {req}");
+ Log ("info", $"Could not resolve breakpoint request: {req}");
SendResponse (msg_id, Result.Err(JObject.FromObject (new {
code = (int)MonoErrorCodes.BpNotFound,
message = $"C# Breakpoint at {req} not found."