Skip to content

Long Functions Cause Invalid DWARF, Debug/ Breaking Unavailable #78657

Closed
@dan-fritchman

Description

@dan-fritchman

Including long functions appears to cause rustc to create invalid DWARF debug files. This leaves debugging and break-pointing unavailable. Debugging fails throughout the program, not just in the long functions.

Originally uncovered while porting (someone else's!) C code, which included a function of about 5k LOC. Also reproduced with macro-generated long methods. A minimal example is available here:
https://github.com/dan-fritchman/DwDemo

Previously reported this to LLDB, whose maintainers helped point out that the DWARF files appear invalid. Building from a fresh clone of that demo repo -

DwDemo $ cargo build
   Compiling dwdemo v0.0.1 (/Users/dan/dev/HW21/DwDemo)
    Finished dev [unoptimized + debuginfo] target(s) in 8.50s
DwDemo $ dwarfdump --debug-line target/debug/dwdemo.dSYM 
error: target/debug/dwdemo.dSYM/Contents/Resources/DWARF/dwdemo: The file was not recognized as a valid object file

The demo's macros expand to a few similar-length functions, about 5-6k LOC. Shortening them (via shortening the structure/ schema files) causes dwarfdump and lldb to be happy with rustc's output -

DwDemo $ cargo build          
   Compiling dwdemo v0.0.1 (/Users/dan/dev/HW21/DwDemo)
    Finished dev [unoptimized + debuginfo] target(s) in 4.11s
DwDemo $ dwarfdump --debug-line target/debug/dwdemo.dSYM | head -n 30
target/debug/dwdemo.dSYM/Contents/Resources/DWARF/dwdemo:       file format Mach-O 64-bit x86-64

.debug_line contents:
debug_line[0x00000000]
Line table prologue:
    total_length: 0x000000ca
         version: 2
 prologue_length: 0x00000075
 min_inst_length: 1
 default_is_stmt: 1
       line_base: -5
      line_range: 14
     opcode_base: 13
standard_opcode_lengths[DW_LNS_copy] = 0
standard_opcode_lengths[DW_LNS_advance_pc] = 1
standard_opcode_lengths[DW_LNS_advance_line] = 1
standard_opcode_lengths[DW_LNS_set_file] = 1
standard_opcode_lengths[DW_LNS_set_column] = 1
standard_opcode_lengths[DW_LNS_negate_stmt] = 0
standard_opcode_lengths[DW_LNS_set_basic_block] = 0
standard_opcode_lengths[DW_LNS_const_add_pc] = 0
standard_opcode_lengths[DW_LNS_fixed_advance_pc] = 1
standard_opcode_lengths[DW_LNS_set_prologue_end] = 0
standard_opcode_lengths[DW_LNS_set_epilogue_begin] = 0
standard_opcode_lengths[DW_LNS_set_isa] = 1
include_directories[  1] = "/Users/dan/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/src/rust/src/libstd"
file_names[  1]:
           name: "rt.rs"
      dir_index: 1
       mod_time: 0x00000000

All of that was run on MacOS with the stable rust toolchain.

DwDemo $ rustup show
Default host: x86_64-apple-darwin
rustup home:  /Users/dan/.rustup

installed toolchains
--------------------

stable-x86_64-apple-darwin (default)
nightly-x86_64-apple-darwin

active toolchain
----------------

stable-x86_64-apple-darwin (default)
rustc 1.46.0 (04488afe3 2020-08-24)

Thanks for all of the team's work on this project.
Please let me know if there's any further info I can provide.

Metadata

Metadata

Assignees

Labels

A-debuginfoArea: Debugging information in compiled programs (DWARF, PDB, etc.)C-bugCategory: This is a bug.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions