Skip to content
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

Closed
wants to merge 28 commits into from

Conversation

ghost
Copy link

@ghost ghost commented Oct 10, 2024

…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.

@ghost
Copy link
Author

ghost commented Oct 10, 2024

Add debug-info to the immutables-load function.

Copy link
Member

@xermicus xermicus left a 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!

@ghost ghost force-pushed the debug-info branch 6 times, most recently from 6620874 to 38e8e3b Compare October 15, 2024 09:40
@ghost
Copy link
Author

ghost commented Oct 15, 2024

Reworked 'set_debug_location' to make it easier to set debug locations.

Copy link
Member

@xermicus xermicus left a 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.

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;
Copy link
Member

@xermicus xermicus Oct 15, 2024

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.
wpt967 and others added 3 commits October 15, 2024 16:30
…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"
Copy link
Member

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

Copy link
Member

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?

Copy link
Author

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.

Copy link
Member

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?

wpt967 added 3 commits October 17, 2024 10:16
…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");
Copy link
Member

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() {
Copy link
Member

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).

Comment on lines 42 to 49
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);
}

Copy link
Member

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.

wpt967 added 3 commits October 18, 2024 11:56
…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.
@ghost ghost marked this pull request as draft October 31, 2024 10:27
xermicus and others added 4 commits October 31, 2024 12:07
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>
xermicus and others added 12 commits October 31, 2024 12:07
…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.
@ghost ghost marked this pull request as ready for review November 4, 2024 11:52
Copy link
Member

@xermicus xermicus left a 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", () => {
Copy link
Member

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.
Repository owner closed this by deleting the head repository Nov 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants