diff --git a/solc/CommandLineInterface.cpp b/solc/CommandLineInterface.cpp index 367434c93f2a..f7560e92acfc 100644 --- a/solc/CommandLineInterface.cpp +++ b/solc/CommandLineInterface.cpp @@ -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"; @@ -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(); } } diff --git a/solc/CommandLineParser.cpp b/solc/CommandLineParser.cpp index 737e3dcbae4b..1b900d72d483 100644 --- a/solc/CommandLineParser.cpp +++ b/solc/CommandLineParser.cpp @@ -776,7 +776,13 @@ General Information)").c_str(), ) ( g_strCombinedJson.c_str(), - po::value()->value_name(util::joinHumanReadable(CombinedJsonRequests::componentMap() | ranges::views::keys, ",")), + po::value()->value_name( + util::joinHumanReadable( + CombinedJsonRequests::componentMap() | ranges::views::keys | + ranges::views::filter([](std::string const& key) { return key != "ethdebug"; }) | + ranges::to(), "," + ) + ), "Output a single json document containing the specified information." ) ; @@ -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() diff --git a/solc/CommandLineParser.h b/solc/CommandLineParser.h index b95973562e51..c731537754fd 100644 --- a/solc/CommandLineParser.h +++ b/solc/CommandLineParser.h @@ -135,6 +135,7 @@ struct CombinedJsonRequests {"devdoc", &CombinedJsonRequests::natspecDev}, {"userdoc", &CombinedJsonRequests::natspecUser}, {"ast", &CombinedJsonRequests::ast}, + {"ethdebug", &CombinedJsonRequests::ethdebug}, }; return components; } @@ -156,6 +157,7 @@ struct CombinedJsonRequests bool natspecDev = false; bool natspecUser = false; bool ast = false; + bool ethdebug = false; }; struct CommandLineOptions diff --git a/test/cmdlineTests/combined_json_ethdebug_with_ethdebug_debug_info/args b/test/cmdlineTests/combined_json_ethdebug_with_ethdebug_debug_info/args new file mode 100644 index 000000000000..5829a7cd71c3 --- /dev/null +++ b/test/cmdlineTests/combined_json_ethdebug_with_ethdebug_debug_info/args @@ -0,0 +1 @@ +--combined-json ethdebug --pretty-json --json-indent 3 diff --git a/test/cmdlineTests/combined_json_ethdebug_with_ethdebug_debug_info/err b/test/cmdlineTests/combined_json_ethdebug_with_ethdebug_debug_info/err new file mode 100644 index 000000000000..d14cb3461102 --- /dev/null +++ b/test/cmdlineTests/combined_json_ethdebug_with_ethdebug_debug_info/err @@ -0,0 +1 @@ +Error: --combined-json ethdebug can only be used together with --debug-info ethdebug. diff --git a/test/cmdlineTests/combined_json_ethdebug_with_ethdebug_debug_info/exit b/test/cmdlineTests/combined_json_ethdebug_with_ethdebug_debug_info/exit new file mode 100644 index 000000000000..d00491fd7e5b --- /dev/null +++ b/test/cmdlineTests/combined_json_ethdebug_with_ethdebug_debug_info/exit @@ -0,0 +1 @@ +1 diff --git a/test/cmdlineTests/combined_json_ethdebug_with_ethdebug_debug_info/input.sol b/test/cmdlineTests/combined_json_ethdebug_with_ethdebug_debug_info/input.sol new file mode 100644 index 000000000000..625af568280c --- /dev/null +++ b/test/cmdlineTests/combined_json_ethdebug_with_ethdebug_debug_info/input.sol @@ -0,0 +1,3 @@ +// SPDX-License-Identifier: GPL-3.0 +pragma solidity >=0.0; +contract C {} diff --git a/test/cmdlineTests/combined_json_ethdebug_without_ethdebug_debug_info/args b/test/cmdlineTests/combined_json_ethdebug_without_ethdebug_debug_info/args new file mode 100644 index 000000000000..d17da0440233 --- /dev/null +++ b/test/cmdlineTests/combined_json_ethdebug_without_ethdebug_debug_info/args @@ -0,0 +1 @@ +--via-ir --debug-info ethdebug --combined-json ethdebug --pretty-json --json-indent 3 diff --git a/test/cmdlineTests/combined_json_ethdebug_without_ethdebug_debug_info/input.sol b/test/cmdlineTests/combined_json_ethdebug_without_ethdebug_debug_info/input.sol new file mode 100644 index 000000000000..625af568280c --- /dev/null +++ b/test/cmdlineTests/combined_json_ethdebug_without_ethdebug_debug_info/input.sol @@ -0,0 +1,3 @@ +// SPDX-License-Identifier: GPL-3.0 +pragma solidity >=0.0; +contract C {} diff --git a/test/cmdlineTests/combined_json_ethdebug_without_ethdebug_debug_info/output b/test/cmdlineTests/combined_json_ethdebug_without_ethdebug_debug_info/output new file mode 100644 index 000000000000..6c534ba5467b --- /dev/null +++ b/test/cmdlineTests/combined_json_ethdebug_without_ethdebug_debug_info/output @@ -0,0 +1,8 @@ +{ + "contracts": { + "combined_json_ethdebug_without_ethdebug_debug_info/input.sol:C": { + "ethdebug": {} + } + }, + "version": "" +}