Use function debug data.

This commit is contained in:
chriseth 2021-09-09 18:15:43 +02:00
parent e6f0fe8ae3
commit 2741175507
3 changed files with 14 additions and 10 deletions

View File

@ -38,6 +38,7 @@
#include <fstream>
#include <range/v3/algorithm/any_of.hpp>
#include <range/v3/view/enumerate.hpp>
using namespace std;
using namespace solidity;
@ -761,8 +762,16 @@ LinkerObject const& Assembly::assemble() const
for (auto const& [name, tagInfo]: m_namedTags)
{
size_t position = m_tagPositionsInBytecode.at(tagInfo.id);
optional<size_t> tagIndex;
for (auto&& [index, item]: m_items | ranges::views::enumerate)
if (item.type() == Tag && static_cast<size_t>(item.data()) == tagInfo.id)
{
tagIndex = index;
break;
}
ret.functionDebugData[name] = {
position == numeric_limits<size_t>::max() ? nullopt : optional<size_t>{position},
tagIndex,
tagInfo.sourceID,
tagInfo.params,
tagInfo.returns

View File

@ -48,6 +48,7 @@ struct LinkerObject
struct FunctionDebugData
{
std::optional<size_t> bytecodeOffset;
std::optional<size_t> instructionIndex;
std::optional<size_t> sourceID;
size_t params = {};
size_t returns = {};

View File

@ -1054,16 +1054,10 @@ size_t CompilerStack::functionEntryPoint(
if (m_stackState != CompilationSuccessful)
BOOST_THROW_EXCEPTION(CompilerError() << errinfo_comment("Compilation was not successful."));
shared_ptr<Compiler> const& compiler = contract(_contractName).compiler;
if (!compiler)
return 0;
evmasm::AssemblyItem tag = compiler->functionEntryLabel(_function);
if (tag.type() == evmasm::UndefinedItem)
return 0;
evmasm::AssemblyItems const& items = compiler->runtimeAssembly().items();
for (size_t i = 0; i < items.size(); ++i)
if (items.at(i).type() == evmasm::Tag && items.at(i).data() == tag.data())
return i;
for (auto&& [name, data]: contract(_contractName).runtimeObject.functionDebugData)
if (data.sourceID == _function.id())
if (data.instructionIndex)
return *data.instructionIndex;
return 0;
}