Skip to content

Commit 3813bce

Browse files
committed
ethdebug: correct handling of interfaces.
1 parent fbbe2dd commit 3813bce

File tree

1 file changed

+13
-15
lines changed

1 file changed

+13
-15
lines changed

libevmasm/Ethdebug.cpp

+13-15
Original file line numberDiff line numberDiff line change
@@ -25,32 +25,27 @@ using namespace solidity::evmasm::ethdebug;
2525
namespace
2626
{
2727

28-
Json programInstructions(Assembly const* _assembly, LinkerObject const& _linkerObject, unsigned _sourceId)
28+
Json programInstructions(Assembly const& _assembly, LinkerObject const& _linkerObject, unsigned _sourceId)
2929
{
30-
// e.g. interfaces don't have a valid assembly object.
31-
if (_assembly)
32-
{
33-
solUnimplementedAssert(_assembly->eofVersion() == std::nullopt, "ethdebug does not yet support EOF.");
34-
solUnimplementedAssert(_assembly->codeSections().size() == 1, "ethdebug does not yet support multiple code-sections.");
35-
for (auto const& instruction: _assembly->codeSections()[0].items)
36-
solUnimplementedAssert(instruction.type() != VerbatimBytecode, "Verbatim bytecode is currently not supported by ethdebug.");
37-
}
30+
solUnimplementedAssert(_assembly.eofVersion() == std::nullopt, "ethdebug does not yet support EOF.");
31+
solUnimplementedAssert(_assembly.codeSections().size() == 1, "ethdebug does not yet support multiple code-sections.");
32+
for (auto const& instruction: _assembly.codeSections()[0].items)
33+
solUnimplementedAssert(instruction.type() != VerbatimBytecode, "Verbatim bytecode is currently not supported by ethdebug.");
3834

3935
solAssert(_linkerObject.codeSectionLocations.size() == 1);
4036
solAssert(_linkerObject.codeSectionLocations[0].end <= _linkerObject.bytecode.size());
4137
Json instructions = Json::array();
4238
for (size_t i = 0; i < _linkerObject.codeSectionLocations[0].instructionLocations.size(); ++i)
4339
{
44-
solAssert(_assembly);
4540
LinkerObject::InstructionLocation currentInstruction = _linkerObject.codeSectionLocations[0].instructionLocations[i];
4641
size_t start = currentInstruction.start;
4742
size_t end = currentInstruction.end;
4843
size_t assemblyItemIndex = currentInstruction.assemblyItemIndex;
4944
solAssert(end <= _linkerObject.bytecode.size());
5045
solAssert(start < end);
51-
solAssert(assemblyItemIndex < _assembly->codeSections().at(0).items.size());
46+
solAssert(assemblyItemIndex < _assembly.codeSections().at(0).items.size());
5247
Json operation = Json::object();
53-
operation["mnemonic"] = instructionInfo(static_cast<Instruction>(_linkerObject.bytecode[start]), _assembly->evmVersion()).name;
48+
operation["mnemonic"] = instructionInfo(static_cast<Instruction>(_linkerObject.bytecode[start]), _assembly.evmVersion()).name;
5449
static size_t constexpr instructionSize = 1;
5550
if (start + instructionSize < end)
5651
{
@@ -61,7 +56,7 @@ Json programInstructions(Assembly const* _assembly, LinkerObject const& _linkerO
6156
solAssert(!argumentData.empty());
6257
operation["arguments"] = Json::array({util::toHex(argumentData, util::HexPrefix::Add)});
6358
}
64-
langutil::SourceLocation const& location = _assembly->codeSections().at(0).items.at(assemblyItemIndex).location();
59+
langutil::SourceLocation const& location = _assembly.codeSections().at(0).items.at(assemblyItemIndex).location();
6560
Json instruction = Json::object();
6661
instruction["offset"] = start;
6762
instruction["operation"] = operation;
@@ -90,8 +85,11 @@ Json ethdebug::program(std::string_view _name, unsigned _sourceId, Assembly cons
9085
result["contract"]["definition"] = Json::object();
9186
result["contract"]["definition"]["source"] = Json::object();
9287
result["contract"]["definition"]["source"]["id"] = _sourceId;
93-
result["environment"] = (!_assembly || _assembly->isCreation()) ? "create" : "call";
94-
result["instructions"] = programInstructions(_assembly, _linkerObject, _sourceId);
88+
if (_assembly)
89+
{
90+
result["environment"] = _assembly->isCreation() ? "create" : "call";
91+
result["instructions"] = programInstructions(*_assembly, _linkerObject, _sourceId);
92+
}
9593
return result;
9694
}
9795

0 commit comments

Comments
 (0)