Skip to content

Commit

Permalink
support assembly breakpoints for contracts without debuginfo
Browse files Browse the repository at this point in the history
  • Loading branch information
Hecate2 committed Sep 20, 2024
1 parent dafb0ca commit 70b571d
Showing 1 changed file with 13 additions and 9 deletions.
22 changes: 13 additions & 9 deletions Fairy.Debugger.Breakpoint.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ public partial class Fairy
protected virtual JToken SetAssemblyBreakpoints(JArray _params)
{
UInt160 scriptHash = UInt160.Parse(_params[0]!.AsString());
if (!contractScriptHashToInstructionPointerToOpCode.ContainsKey(scriptHash))
{
string? contractName = NativeContract.ContractManagement.GetContract(system.StoreView, scriptHash)?.Manifest.Name;
throw new ArgumentException($"Scripthash {scriptHash} {contractName} not registered for debugging. Call SetDebugInfo(scriptHash, nefDbgNfo, dumpNef) first");
}
//if (!contractScriptHashToInstructionPointerToOpCode.ContainsKey(scriptHash))
//{
// string? contractName = NativeContract.ContractManagement.GetContract(system.StoreView, scriptHash)?.Manifest.Name;
// throw new ArgumentException($"Scripthash {scriptHash} {contractName} not registered for debugging. Call SetDebugInfo(scriptHash, nefDbgNfo, dumpNef) first");
//}
HashSet<uint>? assemblyBreakpoints;
if (!contractScriptHashToAssemblyBreakpoints.TryGetValue(scriptHash, out assemblyBreakpoints))
{
Expand All @@ -29,10 +29,14 @@ protected virtual JToken SetAssemblyBreakpoints(JArray _params)
{
string breakpointInstructionPointerStr = _params[i]!.AsString();
uint breakpointInstructionPointer = uint.Parse(breakpointInstructionPointerStr);
if (contractScriptHashToInstructionPointerToOpCode[scriptHash].ContainsKey(breakpointInstructionPointer))
json[breakpointInstructionPointerStr] = assemblyBreakpoints.Add(breakpointInstructionPointer);
else
throw new ArgumentException($"No instruction at InstructionPointer={breakpointInstructionPointer}");
json[breakpointInstructionPointerStr] = assemblyBreakpoints.Add(breakpointInstructionPointer);
if (contractScriptHashToInstructionPointerToOpCode.TryGetValue(scriptHash, out Dictionary<uint, VM.OpCode>? instructionPointerToOpCode))
{// A contract that has registered debuginfo
if (!instructionPointerToOpCode.ContainsKey(breakpointInstructionPointer))
throw new ArgumentException($"No instruction at InstructionPointer={breakpointInstructionPointer}");
// TODO: we can check whether the addr is valid, without the debuginfo and instructionPointerToOpCode
}
// else this is a contract without debug info registration. Do nothing.
}
return json;
}
Expand Down

0 comments on commit 70b571d

Please sign in to comment.