rust-lang / rustc_codegen_cranelift

Cranelift based backend for rustc
Apache License 2.0
1.64k stars 101 forks source link

Implement #![debugger_visualizer] #1386

Open bjorn3 opened 1 year ago

bjorn3 commented 1 year ago

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 commented 9 months ago

The function to insert this section is called at https://github.com/rust-lang/rust/blob/8c0b4f67c9b4bf477df38c16669fd576d46a2b3d/compiler/rustc_codegen_ssa/src/base.rs#L464

kartva commented 9 months ago

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 commented 9 months ago

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

kernel-loophole commented 5 months ago

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

bjorn3 commented 5 months ago

Yes, this change is still wanted. However someone else also asked if they could pick it up at https://github.com/rust-lang/rustc_codegen_cranelift/pull/1462#issuecomment-2191170590 a couple of days ago, so I would like to give them a chance first.

kernel-loophole commented 5 months ago

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

kernel-loophole commented 4 months ago

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

kernel-loophole commented 4 months ago

@bjorn3 should a create sprit module for gdb and call in the base.rs file as in the https://github.com/rust-lang/rust/blob/7606c13961ddc1174b70638e934df0439b7dc515/compiler/rustc_codegen_llvm/src/debuginfo/gdb.rs#L85-L117

bjorn3 commented 4 months ago

All code can probably be placed at https://github.com/rust-lang/rustc_codegen_cranelift/blob/253436c04c87b7d8dfed2fb14e42a67427196bc1/src/driver/aot.rs#L396 The if block above is an example for how to add a section to the object file.

kernel-loophole commented 4 months ago

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

bjorn3 commented 4 months ago

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 commented 4 months ago

okay thanks

kernel-loophole commented 4 months ago

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

bjorn3 commented 4 months ago

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 https://github.com/rust-lang/rustc_codegen_cranelift/blob/4fb3c4bf863f2ab32fee13405f71b6785763e909/src/vtable.rs#L96-L100

kernel-loophole commented 4 months ago

okay let me check

kernel-loophole commented 3 months ago

@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 commented 3 months ago

\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 commented 3 months ago

oh great thanks

kernel-loophole commented 3 months ago

@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 commented 3 months ago

The volatile load for keeping the section around should be inserted at https://github.com/rust-lang/rustc_codegen_cranelift/blob/b4e46de5f35727b31d80bf8a9a58191e63e6e57e/src/main_shim.rs#L100 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 commented 3 months ago

how i am gonna Load just the first byte .

bjorn3 commented 3 months ago

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

kernel-loophole commented 1 month ago

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

bjorn3 commented 1 month ago

@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 commented 1 month ago

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