fornwall / rust-script

Run Rust files and expressions as scripts without any setup or compilation step.
https://rust-script.org
Apache License 2.0
1.21k stars 41 forks source link

rust-gdb - easy way to run rust-scripts with gdb #54

Closed gwpl closed 1 year ago

gwpl commented 2 years ago

rust-gdb -

Could you please add some feature to make it easy to run rust-scripts with gdb ?

I've found flag --debug to build in debug mode. However it : 1. also runs script and 2. still I need to sk cache directory looking for path to debug build binary.

What about flag (maybe with shorter name) --build-only-and-return-absolute-path-to-binary ?

That way I could run rust-gdb "$(rust-script --debug --build-only-and-return-absolute-path-to-binary my_script.rs)" to comfortably run script in debugger ?

0x003e commented 2 years ago
 rust-gdb $(rust-script --debug -o  ./my_rust_script.rs --version 2>&1  | rg -w '.+Running `(.+) --version`' -r '$1')
gwpl commented 1 year ago

I guess this covers most of my question! Thank you! If someone see more work to be done , please reopen issue.

joseluis commented 1 year ago

This no longer seems to work (BTW old -o argument is now -c). The compiled binary path doesn't seem to be shown anymore.

fornwall commented 1 year ago

@joseluis Nowadays rust-script runs the executable directly on subsequent runs for speed (to avoid the small overhead of running cargo, instead of the binary directly.

You can run -f/--force to force cargo to be used:

 rust-gdb $(rust-script --debug -f -c  ./my_rust_script.rs --version 2>&1  | rg -w '.+Running `(.+) --version`' -r '$1')

Does that work for you?

Still probably makes sense to make this easier.

joseluis commented 1 year ago

The first time the script is run (or after calling rust-script --clear-cache) there doesn't seem to be anything to grep:

$ rust-script --debug -f -c .my_rust_script.rs --version
   Compiling rust-script_b9303157d5d5afccc45846fa v0.1.0 (/home/USER/.cache/rust-script/projects/b9303157d5d5afccc45846fa)
    Finished dev [unoptimized + debuginfo] target(s) in 0.32s

afterwards subsequent invocations show even less:

$ rust-script --debug -f -c ./scripts/rust-script.rs --version
    Finished dev [unoptimized + debuginfo] target(s) in 0.00s
fornwall commented 1 year ago

@joseluis The just released 0.31.0 version now suports a -w/--wrapper option, so after updating to that you should be able to use e.g. rust-gdb as a wrapper by running:

rust-script --debug --wrapper rust-gdb my-script.rs

Does that work as expected for you?

joseluis commented 1 year ago

Works wonderfully! thank you @fornwall