Skip to content

Commit ec729b3

Browse files
committed
[ethdebug] Enable ethdebug debug info selection.
1 parent b4c395b commit ec729b3

File tree

43 files changed

+553
-16
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+553
-16
lines changed

liblangutil/DebugInfoSelection.cpp

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,14 +49,22 @@ DebugInfoSelection const DebugInfoSelection::Only(bool DebugInfoSelection::* _me
4949
return result;
5050
}
5151

52+
DebugInfoSelection const DebugInfoSelection::Except(std::vector<bool DebugInfoSelection::*> const& _members) noexcept
53+
{
54+
DebugInfoSelection result = All();
55+
for (bool DebugInfoSelection::* member: _members)
56+
result.*member = false;
57+
return result;
58+
}
59+
5260
std::optional<DebugInfoSelection> DebugInfoSelection::fromString(std::string_view _input)
5361
{
5462
// TODO: Make more stuff constexpr and make it a static_assert().
5563
solAssert(componentMap().count("all") == 0, "");
5664
solAssert(componentMap().count("none") == 0, "");
5765

5866
if (_input == "all")
59-
return All();
67+
return ExceptExperimental();
6068
if (_input == "none")
6169
return None();
6270

@@ -74,7 +82,7 @@ std::optional<DebugInfoSelection> DebugInfoSelection::fromComponents(
7482
for (auto const& component: _componentNames)
7583
{
7684
if (component == "*")
77-
return (_acceptWildcards ? std::make_optional(DebugInfoSelection::All()) : std::nullopt);
85+
return (_acceptWildcards ? std::make_optional(ExceptExperimental()) : std::nullopt);
7886

7987
if (!selection.enable(component))
8088
return std::nullopt;

liblangutil/DebugInfoSelection.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,9 @@ struct DebugInfoSelection
4242
static DebugInfoSelection const All(bool _value = true) noexcept;
4343
static DebugInfoSelection const None() noexcept { return All(false); }
4444
static DebugInfoSelection const Only(bool DebugInfoSelection::* _member) noexcept;
45-
static DebugInfoSelection const Default() noexcept { return All(); }
45+
static DebugInfoSelection const Default() noexcept { return ExceptExperimental(); }
46+
static DebugInfoSelection const Except(std::vector<bool DebugInfoSelection::*> const& _members) noexcept;
47+
static DebugInfoSelection const ExceptExperimental() noexcept { return Except({&DebugInfoSelection::ethdebug}); }
4648

4749
static std::optional<DebugInfoSelection> fromString(std::string_view _input);
4850
static std::optional<DebugInfoSelection> fromComponents(
@@ -72,13 +74,15 @@ struct DebugInfoSelection
7274
{"location", &DebugInfoSelection::location},
7375
{"snippet", &DebugInfoSelection::snippet},
7476
{"ast-id", &DebugInfoSelection::astID},
77+
{"ethdebug", &DebugInfoSelection::ethdebug},
7578
};
7679
return components;
7780
}
7881

7982
bool location = false; ///< Include source location. E.g. `@src 3:50:100`
8083
bool snippet = false; ///< Include source code snippet next to location. E.g. `@src 3:50:100 "contract C {..."`
8184
bool astID = false; ///< Include ID of the Solidity AST node. E.g. `@ast-id 15`
85+
bool ethdebug = false; ///< Include ethdebug related debug information.
8286
};
8387

8488
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/StandardCompiler.cpp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1321,10 +1321,18 @@ Json StandardCompiler::compileSolidity(StandardCompiler::InputsAndSettings _inpu
13211321
compilerStack.setModelCheckerSettings(_inputsAndSettings.modelCheckerSettings);
13221322

13231323
compilerStack.enableEvmBytecodeGeneration(isEvmBytecodeRequested(_inputsAndSettings.outputSelection));
1324-
compilerStack.requestIROutputs(irOutputSelection(_inputsAndSettings.outputSelection));
1324+
CompilerStack::IROutputSelection selectedIrOutput = irOutputSelection(_inputsAndSettings.outputSelection);
1325+
compilerStack.requestIROutputs(selectedIrOutput);
13251326

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

1329+
if (
1330+
_inputsAndSettings.debugInfoSelection.has_value() &&
1331+
_inputsAndSettings.debugInfoSelection->ethdebug &&
1332+
(selectedIrOutput == CompilerStack::IROutputSelection::None && !_inputsAndSettings.viaIR)
1333+
)
1334+
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."));
1335+
13281336
bool const binariesRequested = isBinaryRequested(_inputsAndSettings.outputSelection);
13291337

13301338
try

libyul/YulStack.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -365,7 +365,8 @@ std::string YulStack::print(
365365
yulAssert(m_stackState >= Parsed);
366366
yulAssert(m_parserResult, "");
367367
yulAssert(m_parserResult->code, "");
368-
return m_parserResult->toString(&languageToDialect(m_language, m_evmVersion), m_debugInfoSelection, _soliditySourceProvider) + "\n";
368+
return (m_debugInfoSelection.ethdebug ? "/// ethdebug: enabled\n" : "") +
369+
m_parserResult->toString(&languageToDialect(m_language, m_evmVersion), m_debugInfoSelection, _soliditySourceProvider) + "\n";
369370
}
370371

371372
Json YulStack::astJson() const

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)