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

Add rudimentry debug info metadata emission #4225

Merged

Conversation

dwblaikie
Copy link
Contributor

@dwblaikie dwblaikie commented Aug 16, 2024

This adds just the debug info metadata for Compilation Units (the top level container of debug info) - but without anything in them, LLVM won't emit them at all, so while this is testable at the IR level, it isn't observable at the object level until more debug info is added.

A couple of starting points in this patch:

  • A flag (--debug-info, seems to match the naming/style of other flags in the carbon driver, though this is different from the naming conventions of clang/gcc) that enables debug info when lowering. Open to other names/approaches (on by default? historically debug info's been to large/expensive to do this, so sticking with that precedent for now).
  • Enabling that flag by default in the lowering tests - I do find the churn on golden tests a bit rough, and adding more features to all the tests means more churn, but it seems consistent with the approach so far - keep an eye on this and perhaps revisit this if the churn gets too annoying

This adds just the debug info metadata for Compilation Units (the top
level container of debug info) - but without anything in them, LLVM
won't emit them at all, so while this is testable at the IR level, it
isn't observable at the object level until more debug info is added.
toolchain/lower/file_context.cpp Outdated Show resolved Hide resolved
toolchain/lower/file_context.cpp Outdated Show resolved Hide resolved
toolchain/lower/file_context.h Outdated Show resolved Hide resolved
Copy link
Contributor

@jonmeow jonmeow left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good! Thank you for the contributions. Just a few style comments.

Are you using pre-commit (pre-commit install)? I think it would've automatically fixed this by running clang-format for you.

toolchain/lower/file_context.h Outdated Show resolved Hide resolved
toolchain/lower/file_context.cpp Outdated Show resolved Hide resolved
CARBON_CHECK(!sem_ir.has_errors())
<< "Generating LLVM IR from invalid SemIR::File is unsupported.";
BuildCompileUnit(module_name);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe rename this to BuildDICompileUnit? I was having trouble seeing where di_compile_unit_ was initialized -- but maybe it'd be even better to have the method be static and return the DICompileUnit* instead of void, allowing initializing as di_compile_unit_(BuildDICompileUnit(module_name))?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, renamed to BuildDICompileUnit.
It'd take a few more parameters to make it static (include_debug_info_ (though we could move that out into the call site), di_builder_, and llvm_module_)) - I'll give it a go and you can see whether it feels better that way.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks good, I think one nice thing about static is it's harder to accidentally use uninitialized members.

toolchain/lower/file_context.cpp Outdated Show resolved Hide resolved
dwblaikie and others added 7 commits August 19, 2024 10:59
Co-authored-by: Carbon Infra Bot <carbon-external-infra@google.com>
Co-authored-by: Carbon Infra Bot <carbon-external-infra@google.com>
Co-authored-by: Jon Ross-Perkins <jperkins@google.com>
(also rename it, adding the 'DI' in the name to match the type and
member variable name)

This renders `include_debug_info_` unused, so remove it - we can rely on
the CU being non-null as the marker for debug info emission in future
patches/work.
@dwblaikie
Copy link
Contributor Author

Are you using pre-commit (pre-commit install)? I think it would've automatically fixed this by running clang-format for you.

Ah, nope - missed that, sorry. Thanks for the pointer/reminder. Think I managed to run it on some of my stuff that's already committed (with pre-commit run --all-files) to the branch - it caught one formatting error, but otherwise seems clean

Copy link
Contributor

@jonmeow jonmeow left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, glad to have debug info being added!

@chandlerc
Copy link
Contributor

Mostly this'll be a place to discuss the flag naming/functionality, and testing strategy. Should we have debug info on in all lowering tests? Should there be some separate directory just for debug info lowering test coverage? I'm open to ideas/suggestions/requests.

Not a comment on the patch, but maybe update the description before merging to summarize what your suggested starting point is for these questions, and what motivates that starting point?

(FWIW, not disagreeing with the current behavior, mostly looking to have a record of it.)

@dwblaikie
Copy link
Contributor Author

Mostly this'll be a place to discuss the flag naming/functionality, and testing strategy. Should we have debug info on in all lowering tests? Should there be some separate directory just for debug info lowering test coverage? I'm open to ideas/suggestions/requests.

Not a comment on the patch, but maybe update the description before merging to summarize what your suggested starting point is for these questions, and what motivates that starting point?

(FWIW, not disagreeing with the current behavior, mostly looking to have a record of it.)

Updated - hopefully that's something along the lines of what you're looking for.

@jonmeow jonmeow enabled auto-merge August 20, 2024 19:34
auto-merge was automatically disabled August 20, 2024 19:41

Head branch was pushed to by a user without write access

@jonmeow jonmeow added this pull request to the merge queue Aug 20, 2024
Merged via the queue into carbon-language:trunk with commit d57aa57 Aug 20, 2024
8 checks passed
@dwblaikie dwblaikie deleted the debug_info_flag_and_compilation_unit branch August 21, 2024 01:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants