Skip to content

Commit

Permalink
[ethdebug] Add output selection support for ethdebug.
Browse files Browse the repository at this point in the history
  • Loading branch information
aarlt committed Jul 24, 2024
1 parent 71bf655 commit 77c474a
Show file tree
Hide file tree
Showing 17 changed files with 142 additions and 3 deletions.
9 changes: 7 additions & 2 deletions libsolidity/interface/StandardCompiler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1326,10 +1326,11 @@ Json StandardCompiler::compileSolidity(StandardCompiler::InputsAndSettings _inpu

if (_inputsAndSettings.debugInfoSelection.has_value() &&
_inputsAndSettings.debugInfoSelection->ethdebug &&
!isIRRequested(_inputsAndSettings.outputSelection)
!(isIRRequested(_inputsAndSettings.outputSelection) || _inputsAndSettings.viaIR)
)
errors.emplace_back(formatError(Error::Type::FatalError, "general", "debug.debugInfo setting for ethdebug only valid, if 'ir', 'irAst', 'irOptimized' or 'irOptimizedAst' where requested."));


bool const binariesRequested = isBinaryRequested(_inputsAndSettings.outputSelection);

try
Expand Down Expand Up @@ -1435,7 +1436,7 @@ Json StandardCompiler::compileSolidity(StandardCompiler::InputsAndSettings _inpu
Json output;

if (errors.size() > 0)
output["errors"] = std::move(errors);
output["errors"] = std::move(errors);

if (!compilerStack.unhandledSMTLib2Queries().empty())
for (std::string const& query: compilerStack.unhandledSMTLib2Queries())
Expand Down Expand Up @@ -1488,6 +1489,10 @@ Json StandardCompiler::compileSolidity(StandardCompiler::InputsAndSettings _inpu
if (compilationSuccess && isArtifactRequested(_inputsAndSettings.outputSelection, file, name, "irOptimizedAst", wildcardMatchesExperimental))
contractData["irOptimizedAst"] = compilerStack.yulIROptimizedAst(contractName);

// ethdebug
if (compilationSuccess && isArtifactRequested(_inputsAndSettings.outputSelection, file, name, "ethdebug", wildcardMatchesExperimental))
contractData["ethdebug"] = Json::object();

// EVM
Json evmData;
if (compilationSuccess && isArtifactRequested(_inputsAndSettings.outputSelection, file, name, "evm.assembly", wildcardMatchesExperimental))
Expand Down
3 changes: 3 additions & 0 deletions solc/CommandLineInterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ static std::string const g_strSignatureHashes = "hashes";
static std::string const g_strSourceList = "sourceList";
static std::string const g_strSources = "sources";
static std::string const g_strSrcMap = "srcmap";
static std::string const g_strEthdebug = "ethdebug";
static std::string const g_strSrcMapRuntime = "srcmap-runtime";
static std::string const g_strStorageLayout = "storage-layout";
static std::string const g_strVersion = "version";
Expand Down Expand Up @@ -995,6 +996,8 @@ void CommandLineInterface::handleCombinedJSON()
contractData[g_strFunDebugRuntime] = StandardCompiler::formatFunctionDebugData(
m_assemblyStack->runtimeObject(contractName).functionDebugData
);
if (m_options.compiler.combinedJsonRequests->ethdebug)
contractData[g_strEthdebug] = Json::object();
}
}

Expand Down
13 changes: 12 additions & 1 deletion solc/CommandLineParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -776,7 +776,13 @@ General Information)").c_str(),
)
(
g_strCombinedJson.c_str(),
po::value<std::string>()->value_name(util::joinHumanReadable(CombinedJsonRequests::componentMap() | ranges::views::keys, ",")),
po::value<std::string>()->value_name(
util::joinHumanReadable(
CombinedJsonRequests::componentMap() | ranges::views::keys |
ranges::views::filter([](std::string const& key) { return key != "ethdebug"; }) |
ranges::to<std::vector>(), ","
)
),
"Output a single json document containing the specified information."
)
;
Expand Down Expand Up @@ -1452,6 +1458,11 @@ void CommandLineParser::processArgs()
"--debug-info ethdebug can only be used with --" + g_strViaIR + ", --" + CompilerOutputs::componentName(&CompilerOutputs::ir) +
" and/or --" + CompilerOutputs::componentName(&CompilerOutputs::irOptimized) + "."
);

if (m_options.compiler.combinedJsonRequests.has_value() && m_options.compiler.combinedJsonRequests->ethdebug &&
!(m_options.output.debugInfoSelection.has_value() && m_options.output.debugInfoSelection->ethdebug)
)
solThrow(CommandLineValidationError, "--combined-json ethdebug can only be used together with --debug-info ethdebug.");
}

void CommandLineParser::parseCombinedJsonOption()
Expand Down
2 changes: 2 additions & 0 deletions solc/CommandLineParser.h
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ struct CombinedJsonRequests
{"devdoc", &CombinedJsonRequests::natspecDev},
{"userdoc", &CombinedJsonRequests::natspecUser},
{"ast", &CombinedJsonRequests::ast},
{"ethdebug", &CombinedJsonRequests::ethdebug},
};
return components;
}
Expand All @@ -156,6 +157,7 @@ struct CombinedJsonRequests
bool natspecDev = false;
bool natspecUser = false;
bool ast = false;
bool ethdebug = false;
};

struct CommandLineOptions
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
--combined-json ethdebug --pretty-json --json-indent 3
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Error: --combined-json ethdebug can only be used together with --debug-info ethdebug.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
1
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// SPDX-License-Identifier: GPL-3.0
pragma solidity >=0.0;
contract C {}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
--via-ir --debug-info ethdebug --combined-json ethdebug --pretty-json --json-indent 3
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// SPDX-License-Identifier: GPL-3.0
pragma solidity >=0.0;
contract C {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"contracts": {
"combined_json_ethdebug_without_ethdebug_debug_info/input.sol:C": {
"ethdebug": {}
}
},
"version": "<VERSION REMOVED>"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"language": "Solidity",
"sources":
{
"A":
{
"content": "// SPDX-License-Identifier: GPL-3.0\npragma solidity >=0.0; pragma abicoder v2; contract C { function f() public pure {} }"
}
},
"settings":
{
"viaIR": true,
"debug": {"debugInfo": ["ethdebug"]},
"outputSelection":
{
"*": { "*": ["ethdebug", "evm.bytecode.object"] }
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"contracts": {
"A": {
"C": {
"ethdebug": {},
"evm": {
"bytecode": {
"object": "<BYTECODE REMOVED>"
}
}
}
}
},
"sources": {
"A": {
"id": 0
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"language": "Solidity",
"sources":
{
"A":
{
"content": "// SPDX-License-Identifier: GPL-3.0\npragma solidity >=0.0; pragma abicoder v2; contract C { function f() public pure {} }"
}
},
"settings":
{
"outputSelection":
{
"*": { "*": ["ethdebug", "evm.bytecode.object"] }
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"contracts": {
"A": {
"C": {
"ethdebug": {},
"evm": {
"bytecode": {
"object": "<BYTECODE REMOVED>"
}
}
}
}
},
"sources": {
"A": {
"id": 0
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"language": "Solidity",
"sources":
{
"A":
{
"content": "// SPDX-License-Identifier: GPL-3.0\npragma solidity >=0.0; pragma abicoder v2; contract C { function f() public pure {} }"
}
},
"settings":
{
"viaIR": true,
"debug": {"debugInfo": ["ethdebug"]},
"outputSelection":
{
"*": { "*": ["ethdebug"] }
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"sources": {
"A": {
"id": 0
}
}
}

0 comments on commit 77c474a

Please sign in to comment.