Skip to content

Commit 71bf655

Browse files
committed
[ethdebug] Enable ethdebug debug info selection.
1 parent 17c3614 commit 71bf655

File tree

28 files changed

+446
-3
lines changed

28 files changed

+446
-3
lines changed

liblangutil/DebugInfoSelection.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ DebugInfoSelection const DebugInfoSelection::All(bool _value) noexcept
3939
DebugInfoSelection result;
4040
for (bool DebugInfoSelection::* member: componentMap() | ranges::views::values)
4141
result.*member = _value;
42+
result.ethdebug = false;
4243
return result;
4344
}
4445

liblangutil/DebugInfoSelection.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,13 +72,15 @@ struct DebugInfoSelection
7272
{"location", &DebugInfoSelection::location},
7373
{"snippet", &DebugInfoSelection::snippet},
7474
{"ast-id", &DebugInfoSelection::astID},
75+
{"ethdebug", &DebugInfoSelection::ethdebug},
7576
};
7677
return components;
7778
}
7879

7980
bool location = false; ///< Include source location. E.g. `@src 3:50:100`
8081
bool snippet = false; ///< Include source code snippet next to location. E.g. `@src 3:50:100 "contract C {..."`
8182
bool astID = false; ///< Include ID of the Solidity AST node. E.g. `@ast-id 15`
83+
bool ethdebug = false; ///< Include ethdebug related debug information.
8284
};
8385

8486
std::ostream& operator<<(std::ostream& _stream, DebugInfoSelection const& _selection);

libsolidity/codegen/ir/IRGenerator.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ std::string IRGenerator::generate(
118118
);
119119
};
120120

121-
Whiskers t(R"(
121+
Whiskers t(R"(<?isEthdebugEnabled>/// ethdebug: enabled</isEthdebugEnabled>
122122
/// @use-src <useSrcMapCreation>
123123
object "<CreationObject>" {
124124
code {
@@ -155,6 +155,7 @@ std::string IRGenerator::generate(
155155
for (VariableDeclaration const* var: ContractType(_contract).immutableVariables())
156156
m_context.registerImmutableVariable(*var);
157157

158+
t("isEthdebugEnabled", m_context.debugInfoSelection().ethdebug);
158159
t("CreationObject", IRNames::creationObject(_contract));
159160
t("sourceLocationCommentCreation", dispenseLocationComment(_contract));
160161
t("library", _contract.isLibrary());

libsolidity/interface/CompilerStack.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1486,7 +1486,8 @@ void CompilerStack::generateIR(ContractDefinition const& _contract)
14861486
YulStack stack = parseYul(compiledContract.yulIR);
14871487
compiledContract.yulIRAst = stack.astJson();
14881488
stack.optimize();
1489-
compiledContract.yulIROptimized = stack.print(this);
1489+
compiledContract.yulIROptimized = m_debugInfoSelection.ethdebug ? "/// ethdebug: enabled\n" : "";
1490+
compiledContract.yulIROptimized += stack.print(this);
14901491
}
14911492
{
14921493
// Optimizer does not maintain correct native source locations in the AST.

libsolidity/interface/StandardCompiler.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1324,6 +1324,12 @@ Json StandardCompiler::compileSolidity(StandardCompiler::InputsAndSettings _inpu
13241324

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

1327+
if (_inputsAndSettings.debugInfoSelection.has_value() &&
1328+
_inputsAndSettings.debugInfoSelection->ethdebug &&
1329+
!isIRRequested(_inputsAndSettings.outputSelection)
1330+
)
1331+
errors.emplace_back(formatError(Error::Type::FatalError, "general", "debug.debugInfo setting for ethdebug only valid, if 'ir', 'irAst', 'irOptimized' or 'irOptimizedAst' where requested."));
1332+
13271333
bool const binariesRequested = isBinaryRequested(_inputsAndSettings.outputSelection);
13281334

13291335
try

solc/CommandLineParser.cpp

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -637,7 +637,12 @@ General Information)").c_str(),
637637
po::value<std::string>()->default_value(util::toString(DebugInfoSelection::Default())),
638638
("Debug info components to be included in the produced EVM assembly and Yul code. "
639639
"Value can be all, none or a comma-separated list containing one or more of the "
640-
"following components: " + util::joinHumanReadable(DebugInfoSelection::componentMap() | ranges::views::keys) + ".").c_str()
640+
"following components: " +
641+
util::joinHumanReadable(
642+
DebugInfoSelection::componentMap() | ranges::views::keys |
643+
ranges::views::filter([](std::string const& key) { return key != "ethdebug"; }) |
644+
ranges::to<std::vector>()
645+
) + ".").c_str()
641646
)
642647
(
643648
g_strStopAfter.c_str(),
@@ -1439,6 +1444,14 @@ void CommandLineParser::processArgs()
14391444
m_options.input.mode == InputMode::CompilerWithASTImport ||
14401445
m_options.input.mode == InputMode::EVMAssemblerJSON
14411446
);
1447+
1448+
if (m_options.output.debugInfoSelection.has_value() && m_options.output.debugInfoSelection->ethdebug &&
1449+
!(m_options.output.viaIR || m_options.compiler.outputs.ir || m_options.compiler.outputs.irOptimized)
1450+
)
1451+
solThrow(CommandLineValidationError,
1452+
"--debug-info ethdebug can only be used with --" + g_strViaIR + ", --" + CompilerOutputs::componentName(&CompilerOutputs::ir) +
1453+
" and/or --" + CompilerOutputs::componentName(&CompilerOutputs::irOptimized) + "."
1454+
);
14421455
}
14431456

14441457
void CommandLineParser::parseCombinedJsonOption()
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
--debug-info ethdebug
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Error: --debug-info ethdebug can only be used with --via-ir, --ir and/or --ir-optimized.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
1
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
// SPDX-License-Identifier: GPL-2.0
2+
pragma solidity >=0.0;
3+
4+
contract C {
5+
function f() public {}
6+
}

0 commit comments

Comments
 (0)