Skip to content

Commit

Permalink
Merge branch 'develop' into 'master'
Browse files Browse the repository at this point in the history
Develop

See merge request company-projects/Meadow!20
  • Loading branch information
zone117x committed Sep 28, 2018
2 parents 25a31aa + bc6a357 commit 4d832ae
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 18 deletions.
2 changes: 1 addition & 1 deletion Meadow.DebugAdapterServer/MeadowDebugAdapterState.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public ExecutionTrace ExecutionTrace
public MeadowDebugAdapterThreadState(ExecutionTraceAnalysis traceAnalysis, int threadId)
{
// Initialize our thread locking
Semaphore = new SemaphoreSlim(0, 1);
Semaphore = new SemaphoreSlim(0, int.MaxValue);

// Set our execution trace analysis
ExecutionTraceAnalysis = traceAnalysis;
Expand Down
48 changes: 37 additions & 11 deletions Meadow.DebugAdapterServer/MeadowSolidityDebugAdapter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,14 +51,19 @@ public class MeadowSolidityDebugAdapter : DebugAdapterBase
private System.Threading.SemaphoreSlim _processTraceSemaphore = new System.Threading.SemaphoreSlim(SIMULTANEOUS_TRACE_COUNT, SIMULTANEOUS_TRACE_COUNT);

readonly ConcurrentDictionary<string, int[]> _sourceBreakpoints = new ConcurrentDictionary<string, int[]>();

#endregion

#region Properties
public Task Terminated => _terminatedTcs.Task;
public SolidityMeadowConfigurationProperties ConfigurationProperties { get; private set; }
public ConcurrentDictionary<int, MeadowDebugAdapterThreadState> ThreadStates { get; }
public ReferenceContainer ReferenceContainer;
public bool Exiting { get; private set; }
#endregion

#region Events
public delegate void ExitingEventHandler(MeadowSolidityDebugAdapter sender);
public event ExitingEventHandler OnExiting;
#endregion

#region Constructor
Expand Down Expand Up @@ -97,24 +102,28 @@ public async Task ProcessExecutionTraceAnalysis(ExecutionTraceAnalysis traceAnal
// Set the thread state in our lookup
ThreadStates[threadId] = threadState;

// Send an event that our thread has exited.
Protocol.SendEvent(new ThreadEvent(ThreadEvent.ReasonValue.Started, threadState.ThreadId));
// If we're not exiting, step through our
if (!Exiting)
{
// Send an event that our thread has exited.
Protocol.SendEvent(new ThreadEvent(ThreadEvent.ReasonValue.Started, threadState.ThreadId));

// Continue our execution.
ContinueExecution(threadState, DesiredControlFlow.Continue);
// Continue our execution.
ContinueExecution(threadState, DesiredControlFlow.Continue);

// Lock execution is complete.
await threadState.Semaphore.WaitAsync();

// Lock execution is complete.
await threadState.Semaphore.WaitAsync();
// Send an event that our thread has exited.
Protocol.SendEvent(new ThreadEvent(ThreadEvent.ReasonValue.Exited, threadState.ThreadId));
}

// Remove the thread from our lookup.
ThreadStates.Remove(threadId, out _);

// Unlink our data for our thread id.
ReferenceContainer.UnlinkThreadId(threadId);

// Send an event that our thread has exited.
Protocol.SendEvent(new ThreadEvent(ThreadEvent.ReasonValue.Exited, threadState.ThreadId));

// Release the semaphore for processing a trace.
_processTraceSemaphore.Release();
}
Expand Down Expand Up @@ -165,7 +174,7 @@ private void ContinueExecution(MeadowDebugAdapterThreadState threadState, Desire
case DesiredControlFlow.Continue:
{
// Process the execution trace analysis
while (threadState.CurrentStepIndex.HasValue)
while (threadState.CurrentStepIndex.HasValue && !Exiting)
{
// Obtain our breakpoints.
bool hitBreakpoint = CheckBreakpointExists(threadState);
Expand Down Expand Up @@ -320,6 +329,23 @@ protected override void HandleConfigurationDoneRequestAsync(IRequestResponder<Co

protected override void HandleDisconnectRequestAsync(IRequestResponder<DisconnectArguments> responder)
{
// Set our exiting status
Exiting = true;

// Loop for each thread
foreach (var threadStateKeyValuePair in ThreadStates)
{
// Release the execution lock on this thread state.
// NOTE: This already happens when setting exiting status,
// but only if the thread is currently stepping/continuing,
// and not paused. This will allow it to continue if stopped.
threadStateKeyValuePair.Value.Semaphore.Release();
}

// If we have an event, invoke it
OnExiting?.Invoke(this);

// Set our response to the disconnect request.
responder.SetResponse(new DisconnectResponse());
Protocol.SendEvent(new TerminatedEvent());
Protocol.SendEvent(new ExitedEvent(0));
Expand Down
14 changes: 14 additions & 0 deletions Meadow.UnitTestTemplate/Debugging.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ private Debugging(string debugSessionID)
_debugSessionID = debugSessionID;
_pipeServer = new NamedPipeServerStream(_debugSessionID, PipeDirection.InOut, 1, PipeTransmissionMode.Byte, PipeOptions.Asynchronous);
_debugAdapter = new MeadowSolidityDebugAdapter();
_debugAdapter.OnExiting += TeardownRpcDebuggingHook;
}

public void InitializeDebugConnection()
Expand All @@ -74,8 +75,21 @@ public void InitializeDebugConnection()

public void SetupRpcDebuggingHook()
{
// Set our method to execute for our hook.
JsonRpcClient.JsonRpcExecutionAnalysis = RpcExecutionCallback;
}

public void TeardownRpcDebuggingHook()
{
// Teardown our hook by setting the target as null.
TeardownRpcDebuggingHook(null);
}

private void TeardownRpcDebuggingHook(MeadowSolidityDebugAdapter debugAdapter)
{
// Teardown our hook by setting the target as null.
JsonRpcClient.JsonRpcExecutionAnalysis = null;
}

public async Task RpcExecutionCallback(IJsonRpcClient client)
{
Expand Down
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,24 +12,24 @@

# Meadow

An Ethereum implementation geared towards Solidity testing and development. Written in fully cross platform C# with .NET Core. Use Meadow in VSCode, Visual Studio, and JetBrains Rider.
An Ethereum implementation geared towards Solidity testing and development. Written completely in cross-platform C# with .NET Core. Use may use Meadow in VSCode, Visual Studio, and JetBrains Rider.


#### Powerful Solidity contract development, deployment, and interaction

<img src="/images/screenshot1.png?raw=true" width="700" />

Provides an intuitive framework for writing C# tests against contract deployments and interactions. Includes a personal Ethereum test node that is automatically setup during test executions.
Provides an intuitive framework for writing C# tests against contract deployments and interactions. Includes a personal Ethereum test node that automatically is setup during test executions.

---

#### Visibility into Solidity revert call stacks
#### Visibility into Solidity revert / exception call stacks

<img src="/images/screenshot2.png?raw=true" width="700" />

---

#### Solidity debugging with breakpoints, stepping, rewinding, variable inspection, etc
#### Solidity debugging with breakpoints, stepping, rewinding, variable inspection, et cetera

<img src="/images/screenshot3.png?raw=true" width="800" />

Expand All @@ -55,7 +55,7 @@ Provides an intuitive framework for writing C# tests against contract deployment

| Library | Package | |
|---------|-----------|-------------|
| [Meadow.EVM](Meadow.EVM) | [![nuget](https://img.shields.io/nuget/v/Meadow.EVM.svg?colorB=blue)](https://www.nuget.org/packages/Meadow.EVM) | An Ethereum Virtual Machine that includes: <ul><li>Instructions/opcodes, calling conventions/messages/return values, memory/stack, logs/events, gas, charges/limits, precompiles, contract creation logic. <li>Core Ethereum components: account storage, transaction receipts, transaction pool, blocks, world state, snapshoting/reverting, chain, mining/consensus mechanism/scoring/difficulty/uncles. <li>Underlying dependencies: configuration/genesis block/fork/versioning/chain ID support, modified Merkle Patricia Tries, bloom filters, elliptic curve signing + public key recovery, Ethash, in-memory storage database.</ul> |
| [Meadow.EVM](Meadow.EVM) | [![nuget](https://img.shields.io/nuget/v/Meadow.EVM.svg?colorB=blue)](https://www.nuget.org/packages/Meadow.EVM) | An Ethereum Virtual Machine that includes: <ul><li>Instructions/opcodes, calling conventions/messages/return values, memory/stack, logs/events, gas, charges/limits, precompiles, contract creation logic. <li>Core Ethereum components: account storage, transaction receipts, transaction pool, blocks, world state, snapshoting/reverting, chain, mining/consensus mechanism/scoring/difficulty/uncles. <li>Underlying dependencies: configuration/genesis block/fork/versioning/chain ID support, modified Merkle Patricia Trees, bloom filters, elliptic curve signing + public key recovery, Ethash, in-memory storage database.</ul> |
| [Meadow.TestNode](Meadow.TestNode) | [![nuget](https://img.shields.io/nuget/v/Meadow.TestNode.svg?colorB=blue)](https://www.nuget.org/packages/Meadow.TestNode) | Ethereum "personal blockchain" / "test node" / "RPC Server" / "Ethereum client". Ran as either a standalone server or via programmatic setup / teardown during unit test execution. Supports several non-standard RPC methods for debugging, testing, and coverage report generation. |
| [Meadow.SolCodeGen](Meadow.SolCodeGen) | [![nuget](https://img.shields.io/nuget/v/Meadow.SolCodeGen.svg?colorB=blue)](https://www.nuget.org/packages/Meadow.SolCodeGen) | Tool that compiles Solidity source files and generates a C# class for each contract. All public methods and events in the contract ABI are translated to corresponding idiomatic C# methods and event log classes. Solidity NatSpec comments / docs are also translated to IntelliSense / code-completion tooltips. This nuget package can be simply added to a project and Solidity files in the project `contracts` directory are automatically compiled. |
| [Meadow.CoverageReport](Meadow.CoverageReport) | [![nuget](https://img.shields.io/nuget/v/Meadow.CoverageReport.svg?colorB=blue)](https://www.nuget.org/packages/Meadow.CoverageReport) | Generates HTML and JSON code coverage reports for Solidity source files. Uses execution trace data from the EVM. |
Expand All @@ -65,4 +65,4 @@ Provides an intuitive framework for writing C# tests against contract deployment
| [Meadow.Core](Meadow.Core) | [![nuget](https://img.shields.io/nuget/v/Meadow.Core.svg?colorB=blue)](https://www.nuget.org/packages/Meadow.Core) | <ul><li>RLP and ABI encoding & decoding utils. <li>Implementations of Ethereum / solidity types such as Address, UInt256, Hash, etc. <li>BIP32, BIP39, BIP44, HD account derivation implementation. <li>Fast managed Keccak hashing. <li> ECDSA / secp256k1 utils.</ul> |
| [Meadow.JsonRpc](Meadow.JsonRpc) | [![nuget](https://img.shields.io/nuget/v/Meadow.JsonRpc.svg?colorB=blue)](https://www.nuget.org/packages/Meadow.JsonRpc) | <ul><li>.NET types for the Ethereum JSON-RPC request & response data structures. <li>.NET interface for all RPC methods. <li>Serialization for JSON/hex object formats <-> Solidity/.NET types.</ul> |
| [Meadow.JsonRpc.Client](Meadow.JsonRpc.Client) | [![nuget](https://img.shields.io/nuget/v/Meadow.JsonRpc.Client.svg?colorB=blue)](https://www.nuget.org/packages/Meadow.JsonRpc.Client) | JSON-RPC client implementation, supported transports: http, WebSocket, and IPC. |
| [Meadow.JsonRpc.Server](Meadow.JsonRpc.Server) | [![nuget](https://img.shields.io/nuget/v/Meadow.JsonRpc.Server.svg?colorB=blue)](https://www.nuget.org/packages/Meadow.JsonRpc.Server) | Fast and lightweight HTTP and WebSockets JSON-RPC server - using Kestrel and managed sockets. |
| [Meadow.JsonRpc.Server](Meadow.JsonRpc.Server) | [![nuget](https://img.shields.io/nuget/v/Meadow.JsonRpc.Server.svg?colorB=blue)](https://www.nuget.org/packages/Meadow.JsonRpc.Server) | Fast and lightweight HTTP and WebSockets JSON-RPC server - using Kestrel and managed sockets. |

0 comments on commit 4d832ae

Please sign in to comment.