Skip to content

Commit

Permalink
Enable ethdebug debug info and output selection via standard-json.
Browse files Browse the repository at this point in the history
  • Loading branch information
aarlt committed Aug 5, 2024
1 parent 15d8377 commit 53e12ef
Show file tree
Hide file tree
Showing 22 changed files with 103 additions and 45 deletions.
30 changes: 21 additions & 9 deletions libsolidity/interface/StandardCompiler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ bool hashMatchesContent(std::string const& _hash, std::string const& _content)

bool isArtifactRequested(Json const& _outputSelection, std::string const& _artifact, bool _wildcardMatchesExperimental)
{
static std::set<std::string> experimental{"ir", "irAst", "irOptimized", "irOptimizedAst"};
static std::set<std::string> experimental{"ir", "irAst", "irOptimized", "irOptimizedAst", "ethdebug"};
for (auto const& selectedArtifactJson: _outputSelection)
{
std::string const& selectedArtifact = selectedArtifactJson.get<std::string>();
Expand Down Expand Up @@ -265,7 +265,7 @@ bool isBinaryRequested(Json const& _outputSelection)
static std::vector<std::string> const outputsThatRequireBinaries = std::vector<std::string>{
"*",
"ir", "irAst", "irOptimized", "irOptimizedAst",
"evm.gasEstimates", "evm.legacyAssembly", "evm.assembly"
"evm.gasEstimates", "evm.legacyAssembly", "evm.assembly", "ethdebug"
} + evmObjectComponents("bytecode") + evmObjectComponents("deployedBytecode");

for (auto const& fileRequests: _outputSelection)
Expand Down Expand Up @@ -295,6 +295,21 @@ bool isEvmBytecodeRequested(Json const& _outputSelection)
return false;
}

/// @returns true if ethdebug was requested.
bool isEthdebugRequested(Json const& _outputSelection)
{
if (!_outputSelection.is_object())
return false;

for (auto const& fileRequests: _outputSelection)
for (auto const& requests: fileRequests)
for (auto const& request: requests)
if (request == "ethdebug")
return true;

return false;
}

/// @returns The IR output selection for CompilerStack, based on outputs requested in the JSON.
/// Note that as an exception, '*' does not yet match "ir", "irAst", "irOptimized" or "irOptimizedAst".
CompilerStack::IROutputSelection irOutputSelection(Json const& _outputSelection)
Expand Down Expand Up @@ -1306,7 +1321,7 @@ Json StandardCompiler::compileSolidity(StandardCompiler::InputsAndSettings _inpu
compilerStack.setSources(sourceList);
for (auto const& smtLib2Response: _inputsAndSettings.smtLib2Responses)
compilerStack.addSMTLib2Response(smtLib2Response.first, smtLib2Response.second);
compilerStack.setViaIR(_inputsAndSettings.viaIR);
compilerStack.setViaIR(_inputsAndSettings.viaIR || isEthdebugRequested(_inputsAndSettings.outputSelection));
compilerStack.setEVMVersion(_inputsAndSettings.evmVersion);
compilerStack.setRemappings(std::move(_inputsAndSettings.remappings));
compilerStack.setOptimiserSettings(std::move(_inputsAndSettings.optimiserSettings));
Expand All @@ -1326,12 +1341,9 @@ Json StandardCompiler::compileSolidity(StandardCompiler::InputsAndSettings _inpu

Json errors = std::move(_inputsAndSettings.errors);

if (
_inputsAndSettings.debugInfoSelection.has_value() &&
_inputsAndSettings.debugInfoSelection->ethdebug &&
(selectedIrOutput == CompilerStack::IROutputSelection::None && !_inputsAndSettings.viaIR)
)
errors.emplace_back(formatError(Error::Type::FatalError, "general", "'ethdebug' can only be selected in 'settings.debug.debugInfo' when at least one of the IR outputs is selected or 'viaIR' was set."));
if (_inputsAndSettings.debugInfoSelection.has_value() && _inputsAndSettings.debugInfoSelection->ethdebug)
if (selectedIrOutput == CompilerStack::IROutputSelection::None && !isEthdebugRequested(_inputsAndSettings.outputSelection))
errors.emplace_back(formatError(Error::Type::FatalError, "general", "'ethdebug' can only be selected in 'settings.debug.debugInfo' when either an IR output or 'ethdebug' was selected as output."));

bool const binariesRequested = isBinaryRequested(_inputsAndSettings.outputSelection);

Expand Down
32 changes: 0 additions & 32 deletions test/cmdlineTests/standard_debug_info_ethdebug_no_ir/output.json

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
{
"language": "Solidity",
"sources": {
"C": {"urls": ["standard_debug_info_ethdebug_no_ir/in.sol"]}
"C": {"urls": ["standard_debug_info_in_yul_ethdebug_output_ethdebug/in.sol"]}
},
"settings": {
"debug": {"debugInfo": ["ethdebug"]},
"outputSelection": {
"*": {"*": ["evm.bytecode"]}
"*": {"*": ["ethdebug", "metadata"]}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"contracts": {
"C": {
"C": {
"metadata": "{\"compiler\":{\"version\":\"<VERSION REMOVED>\"},\"language\":\"Solidity\",\"output\":{\"abi\":[{\"inputs\":[],\"name\":\"f\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"}],\"devdoc\":{\"kind\":\"dev\",\"methods\":{},\"version\":1},\"userdoc\":{\"kind\":\"user\",\"methods\":{},\"version\":1}},\"settings\":{\"compilationTarget\":{\"C\":\"C\"},\"evmVersion\":\"cancun\",\"libraries\":{},\"metadata\":{\"bytecodeHash\":\"ipfs\"},\"optimizer\":{\"enabled\":false,\"runs\":200},\"remappings\":[],\"viaIR\":true},\"sources\":{\"C\":{\"keccak256\":\"0xd664727da2d62b6156845f13be0ecb2d8d8223c0f736d39575a3bdfbb062c320\",\"license\":\"GPL-2.0\",\"urls\":[\"bzz-raw://470d51a492c4368fac9c29ebb491b0eaa1bc8a660445a014276dc686531742b8\",\"dweb:/ipfs/QmVVnjC3Z35AXGo3GUNPMuKBD2MdFcZxhVg1qHi4fmHzKo\"]}},\"version\":1}"
}
}
},
"sources": {
"C": {
"id": 0
}
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"language": "Solidity",
"sources": {
"C": {"urls": ["standard_debug_info_in_yul_ethdebug/in.sol"]}
"C": {"urls": ["standard_debug_info_in_yul_ethdebug_output_ir/in.sol"]}
},
"settings": {
"debug": {"debugInfo": ["ethdebug"]},
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"language": "Solidity",
"sources": {
"C": {"urls": ["standard_debug_info_in_yul_ethdebug_optimized/in.sol"]}
"C": {"urls": ["standard_debug_info_in_yul_ethdebug_output_ir_optimized/in.sol"]}
},
"settings": {
"debug": {"debugInfo": ["ethdebug"]},
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
--allow-paths .
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
// SPDX-License-Identifier: GPL-2.0
pragma solidity >=0.0;

contract C {
function f() public {}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"language": "Solidity",
"sources": {
"C": {"urls": ["standard_debug_info_in_yul_ethdebug_output_no_ir/in.sol"]}
},
"settings": {
"debug": {"debugInfo": ["ethdebug"]}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"errors": [
{
"component": "general",
"formattedMessage": "'ethdebug' can only be selected in 'settings.debug.debugInfo' when either an IR output or 'ethdebug' was selected as output.",
"message": "'ethdebug' can only be selected in 'settings.debug.debugInfo' when either an IR output or 'ethdebug' was selected as output.",
"severity": "error",
"type": "FatalError"
}
],
"sources": {
"C": {
"id": 0
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
--allow-paths .
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
// SPDX-License-Identifier: GPL-2.0
pragma solidity >=0.0;

contract C {
function f() public {}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"language": "Solidity",
"sources": {
"C": {"urls": ["standard_ethdebug_output_enables_via_ir/in.sol"]}
},
"settings": {
"outputSelection": {
"*": {"*": ["ethdebug", "metadata"]}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"contracts": {
"C": {
"C": {
"metadata": "{\"compiler\":{\"version\":\"<VERSION REMOVED>\"},\"language\":\"Solidity\",\"output\":{\"abi\":[{\"inputs\":[],\"name\":\"f\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"}],\"devdoc\":{\"kind\":\"dev\",\"methods\":{},\"version\":1},\"userdoc\":{\"kind\":\"user\",\"methods\":{},\"version\":1}},\"settings\":{\"compilationTarget\":{\"C\":\"C\"},\"evmVersion\":\"cancun\",\"libraries\":{},\"metadata\":{\"bytecodeHash\":\"ipfs\"},\"optimizer\":{\"enabled\":false,\"runs\":200},\"remappings\":[],\"viaIR\":true},\"sources\":{\"C\":{\"keccak256\":\"0xd664727da2d62b6156845f13be0ecb2d8d8223c0f736d39575a3bdfbb062c320\",\"license\":\"GPL-2.0\",\"urls\":[\"bzz-raw://470d51a492c4368fac9c29ebb491b0eaa1bc8a660445a014276dc686531742b8\",\"dweb:/ipfs/QmVVnjC3Z35AXGo3GUNPMuKBD2MdFcZxhVg1qHi4fmHzKo\"]}},\"version\":1}"
}
}
},
"sources": {
"C": {
"id": 0
}
}
}

0 comments on commit 53e12ef

Please sign in to comment.