Skip to content

Conversation

@topolarity
Copy link
Member

@topolarity topolarity commented Dec 10, 2024

This change adds two new environmental variables:

  • JULIA_DUMP_IR - when provided, this is a path that all emitted LLVM IR (post-optimization, just before machine code generation) will be saved to
  • JULIA_DEBUGINFO - when set to "LLVM-IR" this will run an additional pass on any emitted functions to rewrite their debuginfo to refer to the LLVM source, rather than the Julia source it was generated from

This allows gdb to open the dumped IR and means you can step through LLVM IR line-by-line, print SSA values, etc. which can be very useful for debugging segfaults, or issues in codegen:
image

The debugir pass that rewrites the debuginfo is vendored from: https://github.com/vaivaswatha/debugir. For simplicity, this is just a copy of the one file that we need for the pass.

}
}
// TODO: This should be conditionally enabled depending on the emission mode for the Execution engine
MPM.addPass(createModuleToFunctionPassAdaptor(InstructionNamerPass()));
Copy link
Member Author

Choose a reason for hiding this comment

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

@gbaraldi Do you know where else I need to add this pass to get complete coverage?

It also needs to be turned on / off depending on the debuginfo mode, but I think I can probably pipe that through the OptimizationOptions maybe

Copy link
Member

@gbaraldi gbaraldi Dec 11, 2024

Choose a reason for hiding this comment

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

It should only be here. Though yeah make it conditional on the options. Similar to #55407 and maybe an llvmpasses test. Not sure if it's super worth it but 🤷

@topolarity topolarity force-pushed the ct/debugir branch 2 times, most recently from 29679d0 to b2bdd73 Compare December 10, 2024 20:38
This change adds two new environmental variables:
  - `JULIA_DUMP_IR` - when provided, this is a path that all emitted
    LLVM IR (post-optimization, just before machine code generation)
    will be saved to
  - `JULIA_DEBUGINFO` - when set to "LLVM-IR" this will run an additional
    pass on any emitted functions to rewrite their debuginfo to refer to
    the LLVM source, rather than the Julia source it was generated from

The `debugir` pass that rewrites the debuginfo is vendored from:
  https://github.com/vaivaswatha/debugir. For simplicity, this is just a
copy of the one file that we need for the pass.

Using both of these together allows `gdb` to open the dumped IR and means
you can step through LLVM IR line-by-line, print SSA values, etc. This can
be very useful for debugging segfaults, or issues in codegen.
@topolarity topolarity changed the title Support (optionally) emitting debuginfo w.r.t. LLVM source Support emitting debuginfo with LLVM IR as source Dec 10, 2024
@topolarity topolarity changed the title Support emitting debuginfo with LLVM IR as source Support emitting debuginfo w.r.t. LLVM IR Dec 10, 2024
@vtjnash vtjnash closed this Sep 17, 2025
@vtjnash
Copy link
Member

vtjnash commented Sep 17, 2025

Seems a lot of code to vendor for a very specific use case

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.

3 participants