Skip to content

Missing rust-gdb pretty printer for cdylib shared objects #96365

Open
@cjermain

Description

@cjermain

Problem

Debugging in rust-gdb with a shared object library does not activate pretty-printers supplied by rustup.

Running cargo build with crate-type of bin or lib results in a .debug_gdb_scripts section on the target or library, allowing rust-gdb to auto-load the Python pretty printers dynamically during debugging. The pretty printers are great!

let section_name = b".debug_gdb_scripts\0";
let section_contents = b"\x01gdb_load_rust_pretty_printers.py\0";

However, for crate-type of cdylib, the .debug_gdb_scripts section is not written. This results in a lack of pretty printing in rust-gdb, and makes it more challenging to use rust-gdb to best effect. I'm seeing this when working with Python bindings of Rust code with pyo3. Is there a reason cdylib did not receive this pretty-printer support?

Workaround

I've confirmed that manually adding the .debug_gdb_scripts section to a .so library generated with crate-type=cdylib activates the pretty printers. I did noticed some Python exceptions in the pretty printers, but have not investigated further.

$ objcopy --add-section .debug_gdb_scripts=<(echo -ne "\x01gdb_load_rust_pretty_printers.py\0") ./libmytest_lib.so
$ objdump -sj .debug_gdb_scripts libmytest_lib.so

libmytest_lib.so:     file format elf64-x86-64

Contents of section .debug_gdb_scripts:
 0000 01676462 5f6c6f61 645f7275 73745f70  .gdb_load_rust_p
 0010 72657474 795f7072 696e7465 72732e70  retty_printers.p
 0020 7900                                 y.      

Version information

rustc 1.60.0 (7737e0b 2022-04-04)
cargo 1.60.0 (d1fd9fe 2022-03-01)

Metadata

Metadata

Assignees

No one assigned

    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