Skip to content

Commit df4a941

Browse files
committed
iiiiiiiiiiiiiii
1 parent 1abbdbd commit df4a941

File tree

22 files changed

+111
-89
lines changed

22 files changed

+111
-89
lines changed

libevmasm/AbstractAssemblyStack.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,8 @@ class AbstractAssemblyStack
4040
virtual std::string const* sourceMapping(std::string const& _contractName) const = 0;
4141
virtual std::string const* runtimeSourceMapping(std::string const& _contractName) const = 0;
4242

43-
virtual Json ethdebug(std::string const& _contractName, bool _runtime) const = 0;
44-
43+
virtual Json ethdebug(std::string const& _contractName) const = 0;
44+
virtual Json ethdebugRuntime(std::string const& _contractName) const = 0;
4545
virtual Json ethdebug() const = 0;
4646

4747
virtual Json assemblyJSON(std::string const& _contractName) const = 0;

libevmasm/EVMAssemblyStack.cpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,10 +103,16 @@ std::string const* EVMAssemblyStack::runtimeSourceMapping(std::string const& _co
103103
return &m_runtimeSourceMapping;
104104
}
105105

106-
Json EVMAssemblyStack::ethdebug(std::string const& _contractName, bool _runtime) const
106+
Json EVMAssemblyStack::ethdebug(std::string const& _contractName) const
107107
{
108108
solAssert(_contractName == m_name);
109-
return _runtime ? m_runtimeEthdebug : m_ethdebug;
109+
return *m_ethdebug;
110+
}
111+
112+
Json EVMAssemblyStack::ethdebugRuntime(std::string const& _contractName) const
113+
{
114+
solAssert(_contractName == m_name);
115+
return *m_ethdebugRuntime;
110116
}
111117

112118
Json EVMAssemblyStack::ethdebug() const

libevmasm/EVMAssemblyStack.h

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,9 @@ class EVMAssemblyStack: public AbstractAssemblyStack
5959
virtual std::string const* sourceMapping(std::string const& _contractName) const override;
6060
virtual std::string const* runtimeSourceMapping(std::string const& _contractName) const override;
6161

62-
virtual Json ethdebug(std::string const& _contractName, bool _runtime) const override;
63-
virtual Json ethdebug() const override;
62+
Json ethdebug(std::string const& _contractName) const override;
63+
Json ethdebugRuntime(std::string const& _contractName) const override;
64+
Json ethdebug() const override;
6465

6566
virtual Json assemblyJSON(std::string const& _contractName) const override;
6667
virtual std::string assemblyString(std::string const& _contractName, StringMap const& _sourceCodes) const override;
@@ -90,8 +91,8 @@ class EVMAssemblyStack: public AbstractAssemblyStack
9091
langutil::DebugInfoSelection m_debugInfoSelection = langutil::DebugInfoSelection::Default();
9192
std::string m_sourceMapping;
9293
std::string m_runtimeSourceMapping;
93-
Json m_ethdebug;
94-
Json m_runtimeEthdebug;
94+
std::unique_ptr<Json> m_ethdebug;
95+
std::unique_ptr<Json> m_ethdebugRuntime;
9596
};
9697

9798
} // namespace solidity::evmasm

liblangutil/DebugInfoSelection.cpp

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

52-
DebugInfoSelection const DebugInfoSelection::Except(std::vector<bool DebugInfoSelection::*> const& _members) noexcept
52+
DebugInfoSelection const DebugInfoSelection::AllExcept(std::vector<bool DebugInfoSelection::*> const& _members) noexcept
5353
{
5454
DebugInfoSelection result = All();
5555
for (bool DebugInfoSelection::* member: _members)
@@ -64,7 +64,7 @@ std::optional<DebugInfoSelection> DebugInfoSelection::fromString(std::string_vie
6464
solAssert(componentMap().count("none") == 0, "");
6565

6666
if (_input == "all")
67-
return ExceptExperimental();
67+
return AllExceptExperimental();
6868
if (_input == "none")
6969
return None();
7070

@@ -82,7 +82,7 @@ std::optional<DebugInfoSelection> DebugInfoSelection::fromComponents(
8282
for (auto const& component: _componentNames)
8383
{
8484
if (component == "*")
85-
return (_acceptWildcards ? std::make_optional(ExceptExperimental()) : std::nullopt);
85+
return (_acceptWildcards ? std::make_optional(AllExceptExperimental()) : std::nullopt);
8686

8787
if (!selection.enable(component))
8888
return std::nullopt;

liblangutil/DebugInfoSelection.h

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +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 ExceptExperimental(); }
46-
static DebugInfoSelection const Except(std::vector<bool DebugInfoSelection::*> const& _members) noexcept;
47-
static DebugInfoSelection const ExceptExperimental() noexcept { return Except({&DebugInfoSelection::ethdebug}); }
45+
static DebugInfoSelection const Default() noexcept { return AllExceptExperimental(); }
46+
static DebugInfoSelection const AllExcept(std::vector<bool DebugInfoSelection::*> const& _members) noexcept;
47+
static DebugInfoSelection const AllExceptExperimental() noexcept { return AllExcept({&DebugInfoSelection::ethdebug}); }
4848

4949
static std::optional<DebugInfoSelection> fromString(std::string_view _input);
5050
static std::optional<DebugInfoSelection> fromComponents(
@@ -79,6 +79,15 @@ struct DebugInfoSelection
7979
return components;
8080
}
8181

82+
std::vector<std::string> selectedNames() const
83+
{
84+
std::vector<std::string> result;
85+
for (auto const& component: componentMap())
86+
if (this->*(component.second))
87+
result.push_back(component.first);
88+
return result;
89+
}
90+
8291
bool location = false; ///< Include source location. E.g. `@src 3:50:100`
8392
bool snippet = false; ///< Include source code snippet next to location. E.g. `@src 3:50:100 "contract C {..."`
8493
bool astID = false; ///< Include ID of the Solidity AST node. E.g. `@ast-id 15`

libsolidity/interface/CompilerStack.cpp

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1183,15 +1183,21 @@ Json CompilerStack::interfaceSymbols(std::string const& _contractName) const
11831183

11841184
Json CompilerStack::ethdebug() const
11851185
{
1186+
solAssert(m_stackState >= AnalysisSuccessful, "Analysis was not successful.");
1187+
solAssert(!m_contracts.empty());
11861188
Json result = Json::object();
11871189
result["sources"] = sourceNames();
11881190
return result;
11891191
}
11901192

1191-
Json CompilerStack::ethdebug(std::string const& _contractName, bool _runtime) const
1193+
Json CompilerStack::ethdebug(std::string const& _contractName) const
11921194
{
1193-
solAssert(m_stackState >= AnalysisSuccessful, "Analysis was not successful.");
1194-
return ethdebug(contract(_contractName), _runtime);
1195+
return ethdebug(contract(_contractName), /* runtime */ false);
1196+
}
1197+
1198+
Json CompilerStack::ethdebugRuntime(std::string const& _contractName) const
1199+
{
1200+
return ethdebug(contract(_contractName), /* runtime */ true);
11951201
}
11961202

11971203
Json CompilerStack::ethdebug(Contract const& _contract, bool _runtime) const

libsolidity/interface/CompilerStack.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -393,7 +393,11 @@ class CompilerStack: public langutil::CharStreamProvider, public evmasm::Abstrac
393393

394394
/// @returns a JSON representing the ethdebug data of the specified contract.
395395
/// Prerequisite: Successful call to parse or compile.
396-
Json ethdebug(std::string const& _contractName, bool _runtime) const override;
396+
Json ethdebug(std::string const& _contractName) const override;
397+
398+
/// @returns a JSON representing the ethdebug data of the specified contract.
399+
/// Prerequisite: Successful call to parse or compile.
400+
Json ethdebugRuntime(std::string const& _contractName) const override;
397401

398402
/// @returns a JSON representing the top-level ethdebug data (types, etc.).
399403
/// Prerequisite: Successful call to parse or compile.
@@ -581,6 +585,7 @@ class CompilerStack: public langutil::CharStreamProvider, public evmasm::Abstrac
581585

582586
/// @returns the Contract ethdebug data.
583587
/// This will generate the JSON object and store it in the Contract object if it is not present yet.
588+
/// Prerequisite: Successful call to parse or compile.
584589
Json ethdebug(Contract const& _contract, bool _runtime) const;
585590

586591
/// @returns the offset of the entry point of the given function into the list of assembly items

libsolidity/interface/StandardCompiler.cpp

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -184,9 +184,10 @@ bool isArtifactRequested(Json const& _outputSelection, std::string const& _artif
184184
// TODO: yulCFGJson is only experimental now, so it should not be matched by "*".
185185
if (_artifact == "yulCFGJson")
186186
return false;
187-
// "ir", "irOptimized" can only be matched by "*" if activated.
187+
// TODO: everything ethdebug related is only experimental for now, so it should not be matched by "*".
188188
if (_artifact.find("ethdebug") != std::string::npos)
189189
return false;
190+
// "ir", "irOptimized" can only be matched by "*" if activated.
190191
if (experimental.count(_artifact) == 0 || _wildcardMatchesExperimental)
191192
return true;
192193
}
@@ -1201,7 +1202,7 @@ std::variant<StandardCompiler::InputsAndSettings, Json> StandardCompiler::parseI
12011202
ret.debugInfoSelection.has_value() && ret.debugInfoSelection->ethdebug && ret.language == "Solidity" &&
12021203
!pipelineConfig(ret.outputSelection)[""][""].irCodegen && !isEthdebugRequested(ret.outputSelection)
12031204
)
1204-
return formatFatalError(Error::Type::FatalError, "'settings.debug.debugInfo' can only include 'ethdebug', if output 'ir', 'irOptimized', 'evm.bytecode.ethdebug' or 'evm.deployedBytecode.ethdebug' was selected.");
1205+
return formatFatalError(Error::Type::FatalError, "'settings.debug.debugInfo' can only include 'ethdebug', if output 'ir', 'irOptimized', 'evm.bytecode.ethdebug', or 'evm.deployedBytecode.ethdebug' was selected.");
12051206

12061207
return {std::move(ret)};
12071208
}
@@ -1287,7 +1288,7 @@ Json StandardCompiler::importEVMAssembly(StandardCompiler::InputsAndSettings _in
12871288
if (evmCreationArtifactRequested("linkReferences"))
12881289
creationJSON["linkReferences"] = formatLinkReferences(stack.object(sourceName).linkReferences);
12891290
if (evmCreationArtifactRequested("ethdebug"))
1290-
creationJSON["ethdebug"] = stack.ethdebug(sourceName, false);
1291+
creationJSON["ethdebug"] = stack.ethdebug(sourceName);
12911292
evmData["bytecode"] = creationJSON;
12921293
}
12931294

@@ -1317,7 +1318,7 @@ Json StandardCompiler::importEVMAssembly(StandardCompiler::InputsAndSettings _in
13171318
if (evmDeployedArtifactRequested("immutableReferences"))
13181319
deployedJSON["immutableReferences"] = formatImmutableReferences(stack.runtimeObject(sourceName).immutableReferences);
13191320
if (evmDeployedArtifactRequested("ethdebug"))
1320-
deployedJSON["ethdebug"] = stack.ethdebug(sourceName, true);
1321+
deployedJSON["ethdebug"] = stack.ethdebugRuntime(sourceName);
13211322
evmData["deployedBytecode"] = deployedJSON;
13221323
}
13231324

@@ -1559,7 +1560,7 @@ Json StandardCompiler::compileSolidity(StandardCompiler::InputsAndSettings _inpu
15591560
if (evmCreationArtifactRequested("generatedSources"))
15601561
creationJSON["generatedSources"] = compilerStack.generatedSources(contractName, /* _runtime */ false);
15611562
if (evmCreationArtifactRequested("ethdebug"))
1562-
creationJSON["ethdebug"] = compilerStack.ethdebug(contractName, false);
1563+
creationJSON["ethdebug"] = compilerStack.ethdebug(contractName);
15631564
evmData["bytecode"] = creationJSON;
15641565
}
15651566

@@ -1591,7 +1592,7 @@ Json StandardCompiler::compileSolidity(StandardCompiler::InputsAndSettings _inpu
15911592
if (evmDeployedArtifactRequested("generatedSources"))
15921593
deployedJSON["generatedSources"] = compilerStack.generatedSources(contractName, /* _runtime */ true);
15931594
if (evmDeployedArtifactRequested("ethdebug"))
1594-
deployedJSON["ethdebug"] = compilerStack.ethdebug(contractName, true);
1595+
deployedJSON["ethdebug"] = compilerStack.ethdebugRuntime(contractName);
15951596
evmData["deployedBytecode"] = deployedJSON;
15961597
}
15971598

solc/CommandLineInterface.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -561,7 +561,7 @@ void CommandLineInterface::handleEthdebug()
561561
if (!m_options.output.dir.empty())
562562
createFile("ethdebug.json", ethdebug);
563563
else
564-
sout() << "======= Debug Data (ethdebug/format/object) =======" << std::endl << ethdebug << std::endl;
564+
sout() << "======= Debug Data (ethdebug/format/info) =======" << std::endl << ethdebug << std::endl;
565565
}
566566
}
567567

@@ -574,7 +574,7 @@ void CommandLineInterface::handleEthdebug(std::string const& _contract)
574574

575575
if (m_options.compiler.outputs.ethdebug)
576576
{
577-
std::string ethdebug{jsonPrint(removeNullMembers(m_compiler->ethdebug(_contract, false)), m_options.formatting.json)};
577+
std::string ethdebug{jsonPrint(removeNullMembers(m_compiler->ethdebug(_contract)), m_options.formatting.json)};
578578
if (!m_options.output.dir.empty())
579579
createFile(m_compiler->filesystemFriendlyName(_contract) + "_ethdebug.json", ethdebug);
580580
else
@@ -583,7 +583,7 @@ void CommandLineInterface::handleEthdebug(std::string const& _contract)
583583

584584
if (m_options.compiler.outputs.ethdebugRuntime)
585585
{
586-
std::string ethdebugRuntime{jsonPrint(removeNullMembers(m_compiler->ethdebug(_contract, true)), m_options.formatting.json)};
586+
std::string ethdebugRuntime{jsonPrint(removeNullMembers(m_compiler->ethdebugRuntime(_contract)), m_options.formatting.json)};
587587
if (!m_options.output.dir.empty())
588588
createFile(m_compiler->filesystemFriendlyName(_contract) + "_ethdebug-runtime.json", ethdebugRuntime);
589589
else
@@ -1336,7 +1336,7 @@ void CommandLineInterface::assembleYul(yul::YulStack::Language _language, yul::Y
13361336
{
13371337
Json ethdebugObject = Json::object();
13381338
ethdebugObject["sources"] = m_fileReader.sourceUnits() | ranges::views::keys;
1339-
sout() << "======= Debug Data (ethdebug/format/object) =======" << std::endl;
1339+
sout() << "======= Debug Data (ethdebug/format/info) =======" << std::endl;
13401340
sout() << util::jsonPrint(
13411341
ethdebugObject,
13421342
m_options.formatting.json

solc/CommandLineParser.cpp

Lines changed: 11 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -652,13 +652,7 @@ General Information)").c_str(),
652652
po::value<std::string>()->default_value(util::toString(DebugInfoSelection::Default())),
653653
("Debug info components to be included in the produced EVM assembly and Yul code. "
654654
"Value can be all, none or a comma-separated list containing one or more of the "
655-
"following components: " +
656-
util::joinHumanReadable(
657-
DebugInfoSelection::componentMap() | ranges::views::keys |
658-
// Note: We intentionally keep ethdebug undocumented for now.
659-
ranges::views::filter([](std::string const& key) { return key != "ethdebug"; }) |
660-
ranges::to<std::vector>()
661-
) + ".").c_str()
655+
"following components: " + util::joinHumanReadable(DebugInfoSelection::Default().selectedNames()) + ".").c_str()
662656
)
663657
(
664658
g_strStopAfter.c_str(),
@@ -1490,27 +1484,29 @@ void CommandLineParser::processArgs()
14901484
m_options.input.mode == InputMode::EVMAssemblerJSON
14911485
);
14921486

1493-
std::string ethdebugOutputSelection =
1494-
"--" + CompilerOutputs::componentName(&CompilerOutputs::ethdebug) + " / --" + CompilerOutputs::componentName(&CompilerOutputs::ethdebugRuntime);
1495-
14961487
bool incompatibleEthdebugOutputs =
14971488
m_options.compiler.outputs.asmJson || m_options.compiler.outputs.irAstJson || m_options.compiler.outputs.irOptimizedAstJson;
14981489

14991490
bool incompatibleEthdebugInputs = m_options.input.mode != InputMode::Compiler;
15001491

1492+
static std::string enableEthdebugMessage =
1493+
"--" + CompilerOutputs::componentName(&CompilerOutputs::ethdebug) + " / --" + CompilerOutputs::componentName(&CompilerOutputs::ethdebugRuntime);
1494+
1495+
static std::string enableIrMessage =
1496+
"--" + CompilerOutputs::componentName(&CompilerOutputs::ir) + " / --" + CompilerOutputs::componentName(&CompilerOutputs::irOptimized) ;
1497+
15011498
if (m_options.compiler.outputs.ethdebug || m_options.compiler.outputs.ethdebugRuntime)
15021499
{
15031500
if (!m_options.output.viaIR)
15041501
solThrow(
15051502
CommandLineValidationError,
1506-
"--" + CompilerOutputs::componentName(&CompilerOutputs::ethdebug) + " / --" + CompilerOutputs::componentName(&CompilerOutputs::ethdebugRuntime) + " output can only be selected, if --via-ir was specified."
1503+
enableEthdebugMessage + " output can only be selected, if --via-ir was specified."
15071504
);
15081505

15091506
if (incompatibleEthdebugOutputs)
15101507
solThrow(
15111508
CommandLineValidationError,
1512-
ethdebugOutputSelection + " output can only be used with --" + CompilerOutputs::componentName(&CompilerOutputs::ir) +
1513-
", --" + CompilerOutputs::componentName(&CompilerOutputs::irOptimized) + "."
1509+
enableEthdebugMessage + " output can only be used with " + enableIrMessage + "."
15141510
);
15151511

15161512
if (!m_options.output.debugInfoSelection.has_value())
@@ -1523,7 +1519,7 @@ void CommandLineParser::processArgs()
15231519
if (!m_options.output.debugInfoSelection->ethdebug)
15241520
solThrow(
15251521
CommandLineValidationError,
1526-
"--debug-info must contain ethdebug, when compiling with " + ethdebugOutputSelection + "."
1522+
"--debug-info must contain ethdebug, when compiling with " + enableEthdebugMessage + "."
15271523
);
15281524
}
15291525
}
@@ -1534,9 +1530,7 @@ void CommandLineParser::processArgs()
15341530
)
15351531
solThrow(
15361532
CommandLineValidationError,
1537-
"--debug-info ethdebug can only be used with --" + CompilerOutputs::componentName(&CompilerOutputs::ir) +
1538-
", --" + CompilerOutputs::componentName(&CompilerOutputs::irOptimized) +
1539-
" and/or " + ethdebugOutputSelection + "."
1533+
"--debug-info ethdebug can only be used with " + enableIrMessage + " and/or " + enableEthdebugMessage + "."
15401534
);
15411535

15421536
if (m_options.output.debugInfoSelection.has_value() && m_options.output.debugInfoSelection->ethdebug && incompatibleEthdebugInputs)

0 commit comments

Comments
 (0)