@@ -25,7 +25,7 @@ using namespace solidity::evmasm::ethdebug;
25
25
namespace
26
26
{
27
27
28
- Json programInstructions (Assembly const * _assembly, LinkerObject const & _linkerObject, unsigned _sourceId)
28
+ Json programInstructions (Assembly const * _assembly, LinkerObject const * _linkerObject, unsigned _sourceId)
29
29
{
30
30
// e.g. interfaces don't have a valid assembly object.
31
31
if (_assembly)
@@ -36,53 +36,56 @@ Json programInstructions(Assembly const* _assembly, LinkerObject const& _linkerO
36
36
solUnimplementedAssert (instruction.type () != VerbatimBytecode, " Verbatim bytecode is currently not supported by ethdebug." );
37
37
}
38
38
39
- solAssert (_linkerObject.codeSectionLocations .size () == 1 );
40
- solAssert (_linkerObject.codeSectionLocations [0 ].end <= _linkerObject.bytecode .size ());
41
- Json instructions = Json::array ();
42
- for (size_t i = 0 ; i < _linkerObject.codeSectionLocations [0 ].instructionLocations .size (); ++i)
39
+ if (_linkerObject)
43
40
{
44
- solAssert (_assembly);
45
- LinkerObject::InstructionLocation currentInstruction = _linkerObject.codeSectionLocations [0 ].instructionLocations [i];
46
- size_t start = currentInstruction.start ;
47
- size_t end = currentInstruction.end ;
48
- size_t assemblyItemIndex = currentInstruction.assemblyItemIndex ;
49
- solAssert (end <= _linkerObject.bytecode .size ());
50
- solAssert (start < end);
51
- solAssert (assemblyItemIndex < _assembly->codeSections ().at (0 ).items .size ());
52
- Json operation = Json::object ();
53
- operation[" mnemonic" ] = instructionInfo (static_cast <Instruction>(_linkerObject.bytecode [start]), _assembly->evmVersion ()).name ;
54
- static size_t constexpr instructionSize = 1 ;
55
- if (start + instructionSize < end)
41
+ solAssert (_linkerObject->codeSectionLocations .size () == 1 );
42
+ solAssert (_linkerObject->codeSectionLocations [0 ].end <= _linkerObject->bytecode .size ());
43
+ Json instructions = Json::array ();
44
+ for (size_t i = 0 ; i < _linkerObject->codeSectionLocations [0 ].instructionLocations .size (); ++i)
56
45
{
57
- bytes const argumentData (
58
- _linkerObject.bytecode .begin () + static_cast <std::ptrdiff_t >(start) + instructionSize,
59
- _linkerObject.bytecode .begin () + static_cast <std::ptrdiff_t >(end)
60
- );
61
- solAssert (!argumentData.empty ());
62
- operation[" arguments" ] = Json::array ({util::toHex (argumentData, util::HexPrefix::Add)});
63
- }
64
- langutil::SourceLocation const & location = _assembly->codeSections ().at (0 ).items .at (assemblyItemIndex).location ();
65
- Json instruction = Json::object ();
66
- instruction[" offset" ] = start;
67
- instruction[" operation" ] = operation;
46
+ solAssert (_assembly);
47
+ LinkerObject::InstructionLocation currentInstruction = _linkerObject->codeSectionLocations [0 ].instructionLocations [i];
48
+ size_t start = currentInstruction.start ;
49
+ size_t end = currentInstruction.end ;
50
+ size_t assemblyItemIndex = currentInstruction.assemblyItemIndex ;
51
+ solAssert (end <= _linkerObject->bytecode .size ());
52
+ solAssert (start < end);
53
+ solAssert (assemblyItemIndex < _assembly->codeSections ().at (0 ).items .size ());
54
+ Json operation = Json::object ();
55
+ operation[" mnemonic" ] = instructionInfo (static_cast <Instruction>(_linkerObject->bytecode [start]), _assembly->evmVersion ()).name ;
56
+ static size_t constexpr instructionSize = 1 ;
57
+ if (start + instructionSize < end)
58
+ {
59
+ bytes const argumentData (
60
+ _linkerObject->bytecode .begin () + static_cast <std::ptrdiff_t >(start) + instructionSize,
61
+ _linkerObject->bytecode .begin () + static_cast <std::ptrdiff_t >(end)
62
+ );
63
+ solAssert (!argumentData.empty ());
64
+ operation[" arguments" ] = Json::array ({util::toHex (argumentData, util::HexPrefix::Add)});
65
+ }
66
+ langutil::SourceLocation const & location = _assembly->codeSections ().at (0 ).items .at (assemblyItemIndex).location ();
67
+ Json instruction = Json::object ();
68
+ instruction[" offset" ] = start;
69
+ instruction[" operation" ] = operation;
68
70
69
- instruction[" context" ] = Json::object ();
70
- instruction[" context" ][" code" ] = Json::object ();
71
- instruction[" context" ][" code" ][" source" ] = Json::object ();
72
- instruction[" context" ][" code" ][" source" ][" id" ] = static_cast <int >(_sourceId);
71
+ instruction[" context" ] = Json::object ();
72
+ instruction[" context" ][" code" ] = Json::object ();
73
+ instruction[" context" ][" code" ][" source" ] = Json::object ();
74
+ instruction[" context" ][" code" ][" source" ][" id" ] = static_cast <int >(_sourceId);
73
75
74
- instruction[" context" ][" code" ][" range" ] = Json::object ();
75
- instruction[" context" ][" code" ][" range" ][" offset" ] = location.start ;
76
- instruction[" context" ][" code" ][" range" ][" length" ] = location.end - location.start ;
77
- instructions.emplace_back (instruction);
76
+ instruction[" context" ][" code" ][" range" ] = Json::object ();
77
+ instruction[" context" ][" code" ][" range" ][" offset" ] = location.start ;
78
+ instruction[" context" ][" code" ][" range" ][" length" ] = location.end - location.start ;
79
+ instructions.emplace_back (instruction);
80
+ }
81
+ return instructions;
78
82
}
79
-
80
- return instructions;
83
+ return Json::array ();
81
84
}
82
85
83
86
} // anonymous namespace
84
87
85
- Json ethdebug::program (std::string_view _name, unsigned _sourceId, Assembly const * _assembly, LinkerObject const & _linkerObject)
88
+ Json ethdebug::program (std::string_view _name, unsigned _sourceId, Assembly const * _assembly, LinkerObject const * _linkerObject)
86
89
{
87
90
Json result = Json::object ();
88
91
result[" contract" ] = Json::object ();
0 commit comments