-
Notifications
You must be signed in to change notification settings - Fork 5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[llvm-context, solidity] Add CLI option '-g' to generate debug inform… #74
Conversation
Add debug-info to the immutables-load function. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As a rule of thumb, repeated code-gen logic should be implemented as methods to the context and this applies to debug info as well. I suggest basically any if let Some(dinfo) = context.debug_info()
be a method context.debug_info_something
instead. They can all return early using let else
if debug info isn't requested. This will 1) solve the issue of the heavy code duplication, 2) greatly ease the reading flow of the implementation as all the debug info related stuff can be skipped by skipping just over a single line of code and 3) make it consistent with the regular code-gen related code.
Can you please also enable debug info in the integration test suite by default to get test coverage?
Thanks!
crates/llvm-context/src/polkavm/context/function/runtime/deploy_code.rs
Outdated
Show resolved
Hide resolved
crates/llvm-context/src/polkavm/context/function/runtime/immutable_data_load.rs
Outdated
Show resolved
Hide resolved
crates/llvm-context/src/polkavm/context/function/runtime/runtime_code.rs
Outdated
Show resolved
Hide resolved
crates/llvm-context/src/polkavm/context/function/runtime/entry.rs
Outdated
Show resolved
Hide resolved
crates/solidity/src/yul/parser/statement/function_definition.rs
Outdated
Show resolved
Hide resolved
6620874
to
38e8e3b
Compare
Reworked 'set_debug_location' to make it easier to set debug locations. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reworked 'set_debug_location' to make it easier to set debug locations.
Thanks! I really like it. Half of the lines added are gone :) However there are still some inconsistencies I'd like to iron out.
Also the EVMLA is rather untouched yet, I think it requires some changes to emit correct debug info too.
crates/llvm-context/src/polkavm/context/function/runtime/immutable_data_load.rs
Outdated
Show resolved
Hide resolved
crates/llvm-context/src/polkavm/context/function/runtime/immutable_data_load.rs
Outdated
Show resolved
Hide resolved
crates/llvm-context/src/polkavm/context/function/runtime/entry.rs
Outdated
Show resolved
Hide resolved
crates/llvm-context/src/polkavm/context/function/runtime/entry.rs
Outdated
Show resolved
Hide resolved
scope: Option<DIScope<'ctx>>, | ||
) -> anyhow::Result<()> { | ||
if let Some(dinfo) = self.debug_info() { | ||
let line_num: u32 = std::cmp::min(line, u32::MAX as usize) as u32; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We have a lot of those. A line number greater than u32::MAX should never occur. I doubt solc does emit this. So this should be try_into?
However, the parser must handle this, i.e. error out if reported line and column numbers can not be parsed. During codegen we expect a syntactically correct program. And then this is no longer necessary.
…ation. Add command line option '-g' to generate source level debug information in the output code. This only works with the LLVM-IR code generator. Add flag 'emit_debug_info' to the llvm-context optimizer/code-gen settings structure, to record the setting of the '-g' CLI option. Generate source level debug information for the functions defined when YUL is lowered to LLVM-IR. This includes the deploy_code and runtime functions generated by the compiler. Generate debug-location information for other constructs that may appear in a contract.
…ation. Add command line option '-g' to generate source level debug information in the output code. This only works with the LLVM-IR code generator. Add flag 'emit_debug_info' to the llvm-context optimizer/code-gen settings structure, to record the setting of the '-g' CLI option. Generate source level debug information for the functions defined when YUL is lowered to LLVM-IR. This includes the deploy_code and runtime functions generated by the compiler. Generate debug-location information for other constructs that may appear in a contract.
Signed-off-by: Cyrill Leutwiler <bigcyrill@hotmail.com>
…ation. Add command line option '-g' to generate source level debug information in the output code. This only works with the LLVM-IR code generator. Add flag 'emit_debug_info' to the llvm-context optimizer/code-gen settings structure, to record the setting of the '-g' CLI option. Generate source level debug information for the functions defined when YUL is lowered to LLVM-IR. This includes the deploy_code and runtime functions generated by the compiler. Generate debug-location information for other constructs that may appear in a contract.
Cargo.toml
Outdated
polkavm-linker = "0.10" | ||
polkavm-disassembler = "0.10" | ||
polkavm = "0.10" | ||
polkavm-common = "0.12" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't get it - this is already in paritytech:main
? :D
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe this goes away after a rebase against main?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is part of a commit on the main branch that was accidentally included.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, can you please rebase so we get a clean diff?
…ation. Add command line option '-g' to generate source level debug information in the output code. This only works with the LLVM-IR code generator. Add flag 'emit_debug_info' to the llvm-context optimizer/code-gen settings structure, to record the setting of the '-g' CLI option. Generate source level debug information for the functions defined when YUL is lowered to LLVM-IR. This includes the deploy_code and runtime functions generated by the compiler. Generate debug-location information for other constructs that may appear in a contract.
…ation. Add command line option '-g' to generate source level debug information in the output code. This only works with the LLVM-IR code generator. Add flag 'emit_debug_info' to the llvm-context optimizer/code-gen settings structure, to record the setting of the '-g' CLI option. Generate source level debug information for the functions defined when YUL is lowered to LLVM-IR. This includes the deploy_code and runtime functions generated by the compiler. Generate debug-location information for other constructs that may appear in a contract.
…ation. Add command line option '-g' to generate source level debug information in the output code. This only works with the LLVM-IR code generator. Add flag 'emit_debug_info' to the llvm-context optimizer/code-gen settings structure, to record the setting of the '-g' CLI option. Generate source level debug information for the functions defined when YUL is lowered to LLVM-IR. This includes the deploy_code and runtime functions generated by the compiler. Generate debug-location information for other constructs that may appear in a contract.
name: &str, | ||
line_no: u32, | ||
) -> anyhow::Result<inkwell::debug_info::DISubprogram<'ctx>> { | ||
let dinfo = self.debug_info().expect("expected debug-info builder"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is this not a let else
with an early return?
Ok(()) | ||
} | ||
|
||
/// Pushes a debug-info scope to the stack. | ||
pub fn push_debug_scope(&self, scope: DIScope<'ctx>) { | ||
if self.debug_info().is_some() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should prefer if let
instead of is_some()
followed by unwraps when we operate on optional values only if they are Some
(noticed this in other places too).
if context.debug_info().is_some() { | ||
context.builder().unset_current_debug_location(); | ||
let func_scope = context | ||
.set_current_function_debug_info(runtime::FUNCTION_LOAD_IMMUTABLE_DATA, 0)? | ||
.as_debug_info_scope(); | ||
context.push_debug_scope(func_scope); | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This code is duplicated 3x. Since it is needed every time we lower functions it should be a helper on context instead.
…ation. Add command line option '-g' to generate source level debug information in the output code. This only works with the LLVM-IR code generator. Add flag 'emit_debug_info' to the llvm-context optimizer/code-gen settings structure, to record the setting of the '-g' CLI option. Generate source level debug information for the functions defined when YUL is lowered to LLVM-IR. This includes the deploy_code and runtime functions generated by the compiler. Generate debug-location information for other constructs that may appear in a contract.
…ation. Add command line option '-g' to generate source level debug information in the output code. This only works with the LLVM-IR code generator. Add flag 'emit_debug_info' to the llvm-context optimizer/code-gen settings structure, to record the setting of the '-g' CLI option. Generate source level debug information for the functions defined when YUL is lowered to LLVM-IR. This includes the deploy_code and runtime functions generated by the compiler. Generate debug-location information for other constructs that may appear in a contract.
…ation. Add command line option '-g' to generate source level debug information in the output code. This only works with the LLVM-IR code generator. Add flag 'emit_debug_info' to the llvm-context optimizer/code-gen settings structure, to record the setting of the '-g' CLI option. Generate source level debug information for the functions defined when YUL is lowered to LLVM-IR. This includes the deploy_code and runtime functions generated by the compiler. Generate debug-location information for other constructs that may appear in a contract.
Signed-off-by: Cyrill Leutwiler <bigcyrill@hotmail.com>
- remove unused runtime API imports and constants - move runtime api symbols into the revive-runtime-api crate Signed-off-by: Cyrill Leutwiler <bigcyrill@hotmail.com>
Signed-off-by: xermicus <cyrill@parity.io>
…l object (#52) Signed-off-by: Cyrill Leutwiler <bigcyrill@hotmail.com>
- The storage pointer values will no longer be truncated to the register size, allowing for the use of arbitrary storage keys - Failed storage value reads will now guarantee to return the zero value
Signed-off-by: Cyrill Leutwiler <bigcyrill@hotmail.com>
Signed-off-by: xermicus <cyrill@parity.io>
Signed-off-by: Cyrill Leutwiler <bigcyrill@hotmail.com>
Signed-off-by: Cyrill Leutwiler <bigcyrill@hotmail.com>
Signed-off-by: Cyrill Leutwiler <bigcyrill@hotmail.com>
…ation. Add command line option '-g' to generate source level debug information in the output code. This only works with the LLVM-IR code generator. Add flag 'emit_debug_info' to the llvm-context optimizer/code-gen settings structure, to record the setting of the '-g' CLI option. Generate source level debug information for the functions defined when YUL is lowered to LLVM-IR. This includes the deploy_code and runtime functions generated by the compiler. Generate debug-location information for other constructs that may appear in a contract.
…ation. Add command line option '-g' to generate source level debug information in the output code. This only works with the LLVM-IR code generator. Add flag 'emit_debug_info' to the llvm-context optimizer/code-gen settings structure, to record the setting of the '-g' CLI option. Generate source level debug information for the functions defined when YUL is lowered to LLVM-IR. This includes the deploy_code and runtime functions generated by the compiler. Generate debug-location information for other constructs that may appear in a contract.
…ation. Add command line option '-g' to generate source level debug information in the output code. This only works with the LLVM-IR code generator. Add flag 'emit_debug_info' to the llvm-context optimizer/code-gen settings structure, to record the setting of the '-g' CLI option. Generate source level debug information for the functions defined when YUL is lowered to LLVM-IR. This includes the deploy_code and runtime functions generated by the compiler. Generate debug-location information for other constructs that may appear in a contract.
…ation. Add command line option '-g' to generate source level debug information in the output code. This only works with the LLVM-IR code generator. Add flag 'emit_debug_info' to the llvm-context optimizer/code-gen settings structure, to record the setting of the '-g' CLI option. Generate source level debug information for the functions defined when YUL is lowered to LLVM-IR. This includes the deploy_code and runtime functions generated by the compiler. Generate debug-location information for other constructs that may appear in a contract.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Debug info generation is not enabled by default in our integration test right? All test pass when I switch the default behavior to always generate debug info, so we should be good to enable it.
@@ -76,3 +76,57 @@ describe("Default run a command from the help", () => { | |||
expect(result.output).not.toMatch(/([Ee]rror|[Ww]arning|[Ff]ail)/i); | |||
}); | |||
}); | |||
|
|||
describe("Run resolc with source debug information enabled", () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we verify in this test that some of the expected debug info is in the actual final code blob? Doesn't need to be fancy, a string match or something we expect only to appear with debug info would be sufficient.
…ation. Add command line option '-g' to generate source level debug information in the output code. This only works with the LLVM-IR code generator. Add flag 'emit_debug_info' to the llvm-context optimizer/code-gen settings structure, to record the setting of the '-g' CLI option. Generate source level debug information for the functions defined when YUL is lowered to LLVM-IR. This includes the deploy_code and runtime functions generated by the compiler. Generate debug-location information for other constructs that may appear in a contract.
…ation.
Add command line option '-g' to generate source level debug information in the output code. This only works with the LLVM-IR code generator.
Add flag 'emit_debug_info' to the llvm-context optimizer/code-gen settings structure, to record the setting of the '-g' CLI option.
Generate source level debug information for the functions defined when YUL is lowered to LLVM-IR. This includes the deploy_code and runtime functions generated by the compiler.
Generate debug-location information for other constructs that may appear in a contract.