Skip to content

Commit

Permalink
Merge branch 'vscode-debugger' into 'master'
Browse files Browse the repository at this point in the history
Vscode debugger

See merge request company-projects/Meadow!42
  • Loading branch information
zone117x committed Oct 7, 2018
2 parents e95c181 + 8b72b4a commit 1ab946e
Show file tree
Hide file tree
Showing 9 changed files with 171 additions and 107 deletions.
2 changes: 1 addition & 1 deletion src/Meadow.Contract/ContractDeployer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public async Task<TContract> Deploy()
public async Task ExpectRevert()
{
var txParams = await GetTransactionParams();
(JsonRpcError error, Hash transactionHash) = await ContractFactory.TryDeploy(_contractAttribute, _rpcClient, _bytecode, txParams, _abiEncodedConstructorArgs);
(JsonRpcError error, Hash transactionHash) = await ContractFactory.TryDeploy(expectException: true, _contractAttribute, _rpcClient, _bytecode, txParams, _abiEncodedConstructorArgs);

if (error == null)
{
Expand Down
5 changes: 3 additions & 2 deletions src/Meadow.Contract/ContractFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public static class ContractFactory
TransactionParams sendParams,
ReadOnlyMemory<byte> abiEncodedConstructorArgs = default)
{
(JsonRpcError error, Hash transactionHash) = await TryDeploy(contractAttribute, rpcClient, bytecode, sendParams, abiEncodedConstructorArgs);
(JsonRpcError error, Hash transactionHash) = await TryDeploy(expectException: false, contractAttribute, rpcClient, bytecode, sendParams, abiEncodedConstructorArgs);
if (error != null)
{
if (rpcClient.ErrorFormatter != null)
Expand Down Expand Up @@ -62,6 +62,7 @@ public static class ContractFactory
}

public static async Task<(JsonRpcError Error, Hash TransactionHash)> TryDeploy(
bool expectException,
SolidityContractAttribute contractAttribute,
IJsonRpcClient rpcClient,
byte[] bytecode,
Expand All @@ -88,7 +89,7 @@ public static class ContractFactory
sendParams.Data = bytecode;
}

return await rpcClient.TrySendTransaction(sendParams);
return await rpcClient.TrySendTransaction(sendParams, expectException);
}


Expand Down
4 changes: 2 additions & 2 deletions src/Meadow.Contract/EthFunc.cs
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public async Task ExpectRevertTransaction(TransactionParams transactionParams =
{
transactionParams = _contract.GetTransactionParams(transactionParams);
transactionParams.Data = _callData;
var (error, transactionHash) = await _contract.JsonRpcClient.TrySendTransaction(transactionParams);
var (error, transactionHash) = await _contract.JsonRpcClient.TrySendTransaction(transactionParams, expectingException: true);
if (error == null)
{
var receipt = await _contract.JsonRpcClient.GetTransactionReceipt(transactionHash);
Expand Down Expand Up @@ -362,7 +362,7 @@ public async Task ExpectRevertCall(CallParams callParams = null, DefaultBlockPar
callParams = _contract.GetCallParams(callParams);
callParams.Data = _callData;
blockParameter = blockParameter ?? BlockParameterType.Latest;
var (error, callResult) = await _contract.JsonRpcClient.TryCall(callParams, blockParameter);
var (error, callResult) = await _contract.JsonRpcClient.TryCall(callParams, blockParameter, expectingException: true);
if (error == null)
{
// Check if call is void (no return value)
Expand Down
91 changes: 45 additions & 46 deletions src/Meadow.CoverageReport/Debugging/ExecutionTraceAnalysis.cs
Original file line number Diff line number Diff line change
Expand Up @@ -576,64 +576,60 @@ public ExecutionTraceException GetException(int traceIndex)
return traceException;
}

public string GetExceptionStackTrace(ExecutionTraceException traceException)
public string GetCallStackString(int traceIndex)
{

// Define our unresolved label
const string unresolved = "<unresolved>";

var message = new StringBuilder();

// If we have a trace index, we have a callstack, we add that to the message.
if (traceException.TraceIndex.HasValue)
{
// Obtain our callstack and add every frame to it.
var callstack = GetCallStack(traceException.TraceIndex.Value);
for (int i = 0; i < callstack.Length; i++)
{
// Grab our current call frame
var currentStackFrame = callstack[i];
// Obtain our callstack and add every frame to it.
var callstack = GetCallStack(traceIndex);

// Verify we could resolve the current position.
if (currentStackFrame.Error)
{
message.AppendLine("-> <error: could not resolve stack frame>");
continue;
}
for (int i = 0; i < callstack.Length; i++)
{
// Grab our current call frame
var currentStackFrame = callstack[i];

// Verify we could resolve the function we're in
if (!currentStackFrame.ResolvedFunction)
{
message.AppendLine($"-> at <code outside of mapped function>");
continue;
}
// Verify we could resolve the current position.
if (currentStackFrame.Error)
{
message.AppendLine("-> <error: could not resolve stack frame>");
continue;
}

// Obtain method descriptor information if possible
string methodDescriptor = null;
if (currentStackFrame.IsFunctionConstructor)
{
methodDescriptor = $"'{currentStackFrame.FunctionName ?? unresolved}' constructor";
}
else
{
methodDescriptor = $"method '{currentStackFrame.FunctionName ?? unresolved}'";
}
// Verify we could resolve the function we're in
if (!currentStackFrame.ResolvedFunction)
{
message.AppendLine($"-> at <code outside of mapped function>");
continue;
}

// Obtain method descriptor information if possible
string methodDescriptor = null;
if (currentStackFrame.IsFunctionConstructor)
{
methodDescriptor = $"'{currentStackFrame.FunctionName ?? unresolved}' constructor";
}
else
{
methodDescriptor = $"method '{currentStackFrame.FunctionName ?? unresolved}'";
}

// Obtain our line information if possible.
string lineFirstLine = "<unresolved code line>";
long lineNumber = -1;
string lineFileName = "<unresolved filename>";
if (currentStackFrame.CurrentPositionLines.Length > 0)
{
lineFirstLine = currentStackFrame.CurrentPositionLines[0].LiteralSourceCodeLine.Trim();
lineNumber = currentStackFrame.CurrentPositionLines[0].LineNumber;
lineFileName = currentStackFrame.CurrentPositionLines[0].SourceFileMapParent.SourceFilePath;
}

// Else, we obtain the line for the previous' call.
message.AppendLine($"-> at '{lineFirstLine}' in {methodDescriptor} in file '{lineFileName}' : line {lineNumber}");
// Obtain our line information if possible.
string lineFirstLine = "<unresolved code line>";
long lineNumber = -1;
string lineFileName = "<unresolved filename>";
if (currentStackFrame.CurrentPositionLines.Length > 0)
{
lineFirstLine = currentStackFrame.CurrentPositionLines[0].LiteralSourceCodeLine.Trim();
lineNumber = currentStackFrame.CurrentPositionLines[0].LineNumber;
lineFileName = currentStackFrame.CurrentPositionLines[0].SourceFileMapParent.SourceFilePath;
}

// Else, we obtain the line for the previous' call.
message.AppendLine($"-> at '{lineFirstLine}' in {methodDescriptor} in file '{lineFileName}' : line {lineNumber}");
}

// Trim the end of our message.
Expand All @@ -650,7 +646,10 @@ private string GetExceptionMessage(ExecutionTraceException traceException)
{
var message = new StringBuilder();
message.AppendLine(traceException.Message);
message.AppendLine(GetExceptionStackTrace(traceException));
if (traceException.TraceIndex.HasValue)
{
message.AppendLine(GetCallStackString(traceException.TraceIndex.Value));
}
return message.ToString().TrimEnd();
}

Expand Down
6 changes: 5 additions & 1 deletion src/Meadow.DebugAdapterServer/MeadowDebugAdapterState.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,13 @@ public ExecutionTrace ExecutionTrace

public IJsonRpcClient RpcClient { get; }

public bool ExpectingException { get; }

public SemaphoreSlim Semaphore { get; }
#endregion

#region Constructors
public MeadowDebugAdapterThreadState(IJsonRpcClient rpcClient, ExecutionTraceAnalysis traceAnalysis, int threadId)
public MeadowDebugAdapterThreadState(IJsonRpcClient rpcClient, ExecutionTraceAnalysis traceAnalysis, int threadId, bool expectingException)
{
// Initialize our thread locking
Semaphore = new SemaphoreSlim(0, int.MaxValue);
Expand All @@ -64,6 +66,8 @@ public MeadowDebugAdapterThreadState(IJsonRpcClient rpcClient, ExecutionTraceAna

// Set our thread id
ThreadId = threadId;

ExpectingException = expectingException;
}
#endregion

Expand Down

0 comments on commit 1ab946e

Please sign in to comment.