Skip to content

Commit 3cfd931

Browse files
authored
Merge pull request #15893 from ethereum/fix_ethdebug_ir_output_selection
Allow --irOptimized output selection in ethdebug.
2 parents a7e6cb5 + 872805b commit 3cfd931

File tree

129 files changed

+5433
-430
lines changed

Some content is hidden

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

129 files changed

+5433
-430
lines changed

libsolidity/interface/StandardCompiler.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1200,13 +1200,14 @@ std::variant<StandardCompiler::InputsAndSettings, Json> StandardCompiler::parseI
12001200
}
12011201

12021202
if (
1203-
ret.debugInfoSelection.has_value() && ret.debugInfoSelection->ethdebug && ret.language == "Solidity" &&
1203+
ret.debugInfoSelection.has_value() && ret.debugInfoSelection->ethdebug && (ret.language == "Solidity" || ret.language == "Yul") &&
12041204
!pipelineConfig(ret.outputSelection)[""][""].irCodegen && !isEthdebugRequested(ret.outputSelection)
12051205
)
12061206
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.");
12071207

1208-
if (isEthdebugRequested(ret.outputSelection) && (ret.optimiserSettings.runYulOptimiser || isArtifactRequested(ret.outputSelection, "*", "*", "irOptimized", false)))
1209-
return formatFatalError(Error::Type::FatalError, "Optimization is not yet supported with ethdebug.");
1208+
if (isEthdebugRequested(ret.outputSelection))
1209+
if (ret.optimiserSettings.runYulOptimiser)
1210+
solUnimplemented("Optimization is not yet supported with ethdebug.");
12101211

12111212
return {std::move(ret)};
12121213
}

solc/CommandLineParser.cpp

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1342,12 +1342,18 @@ void CommandLineParser::processArgs()
13421342
);
13431343

13441344
if (m_options.compiler.outputs.ethdebug || m_options.compiler.outputs.ethdebugRuntime)
1345+
{
1346+
if (m_options.optimiserSettings().runYulOptimiser)
1347+
solUnimplemented(
1348+
"Optimization (using --" + g_strOptimize + ") is not yet supported with ethdebug."
1349+
);
1350+
13451351
if (!m_options.output.debugInfoSelection.has_value())
13461352
{
13471353
m_options.output.debugInfoSelection = DebugInfoSelection::Default();
13481354
m_options.output.debugInfoSelection->enable("ethdebug");
13491355
}
1350-
1356+
}
13511357
return;
13521358
}
13531359
else if (countEnabledOptions({g_strYulDialect, g_strMachine}) >= 1)
@@ -1486,17 +1492,14 @@ void CommandLineParser::processArgs()
14861492

14871493
bool incompatibleEthdebugOutputs =
14881494
m_options.compiler.outputs.asmJson || m_options.compiler.outputs.irAstJson || m_options.compiler.outputs.irOptimizedAstJson ||
1489-
m_options.compiler.outputs.irOptimized || m_options.optimizer.optimizeYul || m_options.optimizer.optimizeEvmasm;
1495+
m_options.optimizer.optimizeYul || m_options.optimizer.optimizeEvmasm;
14901496

14911497
bool incompatibleEthdebugInputs = m_options.input.mode != InputMode::Compiler;
14921498

14931499
static std::string enableEthdebugMessage =
14941500
"--" + CompilerOutputs::componentName(&CompilerOutputs::ethdebug) + " / --" + CompilerOutputs::componentName(&CompilerOutputs::ethdebugRuntime);
14951501

1496-
static std::string incompatibleEthdebugOptimizerMessage =
1497-
"--" + g_strOptimize + " / --" + CompilerOutputs::componentName(&CompilerOutputs::irOptimized);
1498-
1499-
static std::string enableIrMessage = "--" + CompilerOutputs::componentName(&CompilerOutputs::ir);
1502+
static std::string enableIrMessage = "--" + CompilerOutputs::componentName(&CompilerOutputs::ir) + " / --" + CompilerOutputs::componentName(&CompilerOutputs::irOptimized);
15001503

15011504
if (m_options.compiler.outputs.ethdebug || m_options.compiler.outputs.ethdebugRuntime)
15021505
{
@@ -1509,7 +1512,7 @@ void CommandLineParser::processArgs()
15091512
if (incompatibleEthdebugOutputs)
15101513
solThrow(
15111514
CommandLineValidationError,
1512-
enableEthdebugMessage + " output can only be used with " + enableIrMessage + ". Optimization is not yet supported with ethdebug, e.g. no support for " + incompatibleEthdebugOptimizerMessage + " yet."
1515+
enableEthdebugMessage + " output can only be used with " + enableIrMessage + ". Optimization (using --" + g_strOptimize + ") is not yet supported with ethdebug."
15131516
);
15141517

15151518
if (!m_options.output.debugInfoSelection.has_value())
@@ -1533,7 +1536,7 @@ void CommandLineParser::processArgs()
15331536
)
15341537
solThrow(
15351538
CommandLineValidationError,
1536-
"--debug-info ethdebug can only be used with " + enableIrMessage + " and/or " + enableEthdebugMessage + ". Optimization is not yet supported with ethdebug, e.g. no support for " + incompatibleEthdebugOptimizerMessage + " yet."
1539+
"--debug-info ethdebug can only be used with " + enableIrMessage + " and/or " + enableEthdebugMessage + ". Optimization (using --" + g_strOptimize + ") is not yet supported with ethdebug."
15371540
);
15381541

15391542
if (m_options.output.debugInfoSelection.has_value() && m_options.output.debugInfoSelection->ethdebug && incompatibleEthdebugInputs)
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
--debug-info ethdebug --via-ir --ir --ir-optimized --ethdebug --ethdebug-runtime
Lines changed: 193 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,193 @@
1+
======= Debug Data (ethdebug/format/info/resources) =======
2+
{"sources":["debug_info_ethdebug_compatible/input.sol"]}
3+
4+
======= debug_info_ethdebug_compatible/input.sol:C =======
5+
IR:
6+
/// ethdebug: enabled
7+
/// @use-src 0:"debug_info_ethdebug_compatible/input.sol"
8+
object "C_6" {
9+
code {
10+
/// @src 0:60:101
11+
mstore(64, memoryguard(128))
12+
if callvalue() { revert_error_ca66f745a3ce8ff40e2ccaf1ad45db7774001b90d25810abd9040049be7bf4bb() }
13+
14+
constructor_C_6()
15+
16+
let _1 := allocate_unbounded()
17+
codecopy(_1, dataoffset("C_6_deployed"), datasize("C_6_deployed"))
18+
19+
return(_1, datasize("C_6_deployed"))
20+
21+
function allocate_unbounded() -> memPtr {
22+
memPtr := mload(64)
23+
}
24+
25+
function revert_error_ca66f745a3ce8ff40e2ccaf1ad45db7774001b90d25810abd9040049be7bf4bb() {
26+
revert(0, 0)
27+
}
28+
29+
/// @src 0:60:101
30+
function constructor_C_6() {
31+
32+
/// @src 0:60:101
33+
34+
}
35+
/// @src 0:60:101
36+
37+
}
38+
/// @use-src 0:"debug_info_ethdebug_compatible/input.sol"
39+
object "C_6_deployed" {
40+
code {
41+
/// @src 0:60:101
42+
mstore(64, memoryguard(128))
43+
44+
if iszero(lt(calldatasize(), 4))
45+
{
46+
let selector := shift_right_224_unsigned(calldataload(0))
47+
switch selector
48+
49+
case 0x26121ff0
50+
{
51+
// f()
52+
53+
external_fun_f_5()
54+
}
55+
56+
default {}
57+
}
58+
59+
revert_error_42b3090547df1d2001c96683413b8cf91c1b902ef5e3cb8d9f6f304cf7446f74()
60+
61+
function shift_right_224_unsigned(value) -> newValue {
62+
newValue :=
63+
64+
shr(224, value)
65+
66+
}
67+
68+
function allocate_unbounded() -> memPtr {
69+
memPtr := mload(64)
70+
}
71+
72+
function revert_error_ca66f745a3ce8ff40e2ccaf1ad45db7774001b90d25810abd9040049be7bf4bb() {
73+
revert(0, 0)
74+
}
75+
76+
function revert_error_dbdddcbe895c83990c08b3492a0e83918d802a52331272ac6fdb6a7c4aea3b1b() {
77+
revert(0, 0)
78+
}
79+
80+
function abi_decode_tuple_(headStart, dataEnd) {
81+
if slt(sub(dataEnd, headStart), 0) { revert_error_dbdddcbe895c83990c08b3492a0e83918d802a52331272ac6fdb6a7c4aea3b1b() }
82+
83+
}
84+
85+
function abi_encode_tuple__to__fromStack(headStart ) -> tail {
86+
tail := add(headStart, 0)
87+
88+
}
89+
90+
function external_fun_f_5() {
91+
92+
if callvalue() { revert_error_ca66f745a3ce8ff40e2ccaf1ad45db7774001b90d25810abd9040049be7bf4bb() }
93+
abi_decode_tuple_(4, calldatasize())
94+
fun_f_5()
95+
let memPos := allocate_unbounded()
96+
let memEnd := abi_encode_tuple__to__fromStack(memPos )
97+
return(memPos, sub(memEnd, memPos))
98+
99+
}
100+
101+
function revert_error_42b3090547df1d2001c96683413b8cf91c1b902ef5e3cb8d9f6f304cf7446f74() {
102+
revert(0, 0)
103+
}
104+
105+
/// @src 0:77:99
106+
function fun_f_5() {
107+
108+
}
109+
/// @src 0:60:101
110+
111+
}
112+
113+
data ".metadata" hex"<BYTECODE REMOVED>"
114+
}
115+
116+
}
117+
118+
119+
Optimized IR:
120+
/// ethdebug: enabled
121+
/// @use-src 0:"debug_info_ethdebug_compatible/input.sol"
122+
object "C_6" {
123+
code {
124+
{
125+
/// @src 0:60:101
126+
mstore(64, memoryguard(0x80))
127+
if callvalue()
128+
{
129+
revert_error_ca66f745a3ce8ff40e2ccaf1ad45db7774001b90d25810abd9040049be7bf4bb()
130+
}
131+
let _1 := allocate_unbounded()
132+
codecopy(_1, dataoffset("C_6_deployed"), datasize("C_6_deployed"))
133+
return(_1, datasize("C_6_deployed"))
134+
}
135+
function allocate_unbounded() -> memPtr
136+
{ memPtr := mload(64) }
137+
function revert_error_ca66f745a3ce8ff40e2ccaf1ad45db7774001b90d25810abd9040049be7bf4bb()
138+
{ revert(0, 0) }
139+
}
140+
/// @use-src 0:"debug_info_ethdebug_compatible/input.sol"
141+
object "C_6_deployed" {
142+
code {
143+
{
144+
/// @src 0:60:101
145+
mstore(64, memoryguard(0x80))
146+
if iszero(lt(calldatasize(), 4))
147+
{
148+
let selector := shift_right_unsigned(calldataload(0))
149+
switch selector
150+
case 0x26121ff0 { external_fun_f() }
151+
default { }
152+
}
153+
revert_error_42b3090547df1d2001c96683413b8cf91c1b902ef5e3cb8d9f6f304cf7446f74()
154+
}
155+
function shift_right_unsigned(value) -> newValue
156+
{ newValue := shr(224, value) }
157+
function allocate_unbounded() -> memPtr
158+
{ memPtr := mload(64) }
159+
function revert_error_ca66f745a3ce8ff40e2ccaf1ad45db7774001b90d25810abd9040049be7bf4bb()
160+
{ revert(0, 0) }
161+
function revert_error_dbdddcbe895c83990c08b3492a0e83918d802a52331272ac6fdb6a7c4aea3b1b()
162+
{ revert(0, 0) }
163+
function abi_decode(headStart, dataEnd)
164+
{
165+
if slt(sub(dataEnd, headStart), 0)
166+
{
167+
revert_error_dbdddcbe895c83990c08b3492a0e83918d802a52331272ac6fdb6a7c4aea3b1b()
168+
}
169+
}
170+
function abi_encode_tuple(headStart) -> tail
171+
{ tail := add(headStart, 0) }
172+
function external_fun_f()
173+
{
174+
if callvalue()
175+
{
176+
revert_error_ca66f745a3ce8ff40e2ccaf1ad45db7774001b90d25810abd9040049be7bf4bb()
177+
}
178+
abi_decode(4, calldatasize())
179+
let memPos := allocate_unbounded()
180+
let memEnd := abi_encode_tuple(memPos)
181+
return(memPos, sub(memEnd, memPos))
182+
}
183+
function revert_error_42b3090547df1d2001c96683413b8cf91c1b902ef5e3cb8d9f6f304cf7446f74()
184+
{ revert(0, 0) }
185+
}
186+
data ".metadata" hex"<BYTECODE REMOVED>"
187+
}
188+
}
189+
190+
Debug Data (ethdebug/format/program):
191+
{}
192+
Debug Data of the runtime part (ethdebug/format/program):
193+
{}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
--debug-info ethdebug --via-ir --asm
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 --ir / --ir-optimized and/or --ethdebug / --ethdebug-runtime. Optimization (using --optimize) is not yet supported with ethdebug.

0 commit comments

Comments
 (0)