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

Implement #![debugger_visualizer] #1386

Open
bjorn3 opened this issue Jul 22, 2023 · 25 comments
Open

Implement #![debugger_visualizer] #1386

bjorn3 opened this issue Jul 22, 2023 · 25 comments
Labels
A-debuginfo Area: Debugging information at runtime in generated code. C-enhancement Category: An issue proposing an enhancement or a PR with one. good first issue Good for newcomers

Comments

@bjorn3
Copy link
Member

bjorn3 commented Jul 22, 2023

https://doc.rust-lang.org/nightly/reference/attributes/debugger.html#using-debugger_visualizer-with-gdb
https://github.com/rust-lang/rust/blob/ab0f3e680e4fd50218914b8afa6900a67377721c/compiler/rustc_codegen_llvm/src/debuginfo/gdb.rs

The .debug_gdb_scripts section should contain \x01gdb_load_rust_pretty_printers.py followed by for each #![debugger_visualizer(gdb_script_file = "...")] the pretty printer inlined into the executable. Except if one of the conditions to omit .debug_gdb_scripts is true.

@bjorn3 bjorn3 added C-enhancement Category: An issue proposing an enhancement or a PR with one. A-debuginfo Area: Debugging information at runtime in generated code. good first issue Good for newcomers labels Jul 22, 2023
@bjorn3
Copy link
Member Author

bjorn3 commented Feb 5, 2024

@kartva
Copy link

kartva commented Feb 25, 2024

I'm interested in working on this issue.

The code you've linked (https://github.com/rust-lang/rust/blob/ab0f3e680e4fd50218914b8afa6900a67377721c/compiler/rustc_codegen_llvm/src/debuginfo/gdb.rs) seems to already contain logic to add pretty-printers. What exactly is the issue here?

@bjorn3
Copy link
Member Author

bjorn3 commented Feb 26, 2024

That is the implementation in the LLVM backend. We need a separate implementation in rustc_codegen_cranelift.

@kernel-loophole
Copy link

@bjorn3 is this issue still open .wanted to work on this .Looking forward to hear from you .

@bjorn3
Copy link
Member Author

bjorn3 commented Jun 28, 2024

Yes, this change is still wanted. However someone else also asked if they could pick it up at #1462 (comment) a couple of days ago, so I would like to give them a chance first.

@kernel-loophole
Copy link

thanks for your response ,i also add the comment on #1462 if the person wanted to work ,i can help.

@kernel-loophole
Copy link

@bjorn3 i ask the person and said that i can pick this

@kernel-loophole
Copy link

@bjorn3
Copy link
Member Author

bjorn3 commented Jul 6, 2024

All code can probably be placed at

The if block above is an example for how to add a section to the object file.

@kernel-loophole
Copy link

kernel-loophole commented Jul 18, 2024

@bjorn3 any project which use the cranelift backend ,needed to test it

@bjorn3
Copy link
Member Author

bjorn3 commented Jul 18, 2024

You can build hello world with rustc_codegen_cranelift and then check if the .debug_gdb_scripts section is present in the executable.

@kernel-loophole
Copy link

okay thanks

@kernel-loophole
Copy link

@bjorn3 where i can find the corresponding in cranelif like llvm::LLVMSetAlignment(volatile_load_instruction, 1)

@bjorn3
Copy link
Member Author

bjorn3 commented Jul 22, 2024

You don't need LLVMSetAlignment. As for a volatile load, you can use a plain load instruction with MemFlags::new() rather than MemFlags::trusted() to ensure it isn't removed. So for example fx.bcx.ins().load(types::I8, MemFlags::new(), ptr, 0). To get the actual pointer to use for the load, you can do something like

let local_data_id = fx.module.declare_data_in_func(data_id, fx.bcx.func);
if fx.clif_comments.enabled() {
fx.add_comment(local_data_id, "vtable");
}
fx.bcx.ins().global_value(fx.pointer_type, local_data_id)

@kernel-loophole
Copy link

okay let me check

@kernel-loophole
Copy link

@bjorn3 the LLVM use the x01gdb_load_rust_pretty_printers.py file,did not get any information about it .what this file contain.https://github.com/rust-lang/rust/blob/ab0f3e680e4fd50218914b8afa6900a67377721c/compiler/rustc_codegen_llvm/src/debuginfo/gdb.rs

@bjorn3
Copy link
Member Author

bjorn3 commented Aug 12, 2024

\x01gdb_load_rust_pretty_printers.py\0 indicates that the gdb_load_rust_pretty_printers.py file should be loaded by gdb at runtime. This file can be found at https://github.com/rust-lang/rust/blob/master/src/etc/gdb_load_rust_pretty_printers.py and at lib/rustlib/etc/gdb_load_rust_pretty_printers.py in the rustc sysroot.

@kernel-loophole
Copy link

oh great thanks

@kernel-loophole
Copy link

@bjorn3 how can i use the builder create in cranelift https://github.com/rust-lang/rust/blob/ab0f3e680e4fd50218914b8afa6900a67377721c/compiler/rustc_codegen_llvm/src/builder.rs , for debug_gdb_scripts global is referenced, so it isn't removed by the linker.

@bjorn3
Copy link
Member Author

bjorn3 commented Aug 15, 2024

The volatile load for keeping the section around should be inserted at

As Cranelift currently doesn't support volatile loads, it should be a regular load with a FIXME to make it a volatile load in the future.

@kernel-loophole
Copy link

how i am gonna Load just the first byte .

@bjorn3
Copy link
Member Author

bjorn3 commented Aug 15, 2024

You can use types::I8 as type argument for the load.

@kernel-loophole
Copy link

hi @bjorn3 ,i have pick the PR of previous person who is working on it .here are changes ,any feedback on this master...kernel-loophole:rustc_codegen_cranelift:master

@bjorn3
Copy link
Member Author

bjorn3 commented Oct 10, 2024

@kernel-loophole It seems in your commit there are a lot of reverts of changes I made within the last couple of months to the debuginfo code. Did a rebase go wrong? Also please remove the files in .idea.

@kernel-loophole
Copy link

@bjorn3 okay i just pick the PR .okay will do

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-debuginfo Area: Debugging information at runtime in generated code. C-enhancement Category: An issue proposing an enhancement or a PR with one. good first issue Good for newcomers
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants