godzie44 / BugStalker

Rust debugger for Linux x86-64
MIT License
594 stars 15 forks source link

F8 - step over leads to libunwind error #2

Open phideg opened 7 months ago

phideg commented 7 months ago

single stepping with F7 works.

However using the step over function fails with following libunwind error

grafik

I reproduced this behaviour with the current HEAD revision. In order to be able to build I had to update the unwind crate. See my other issue #1.

godzie44 commented 7 months ago

Thank you for participating! Could you please check: 1) does next work in console mode? 2) provide some code for the repro? (or is this behavior observed in any code?)

Also debugger can be built with own unwinder (instead of libunwind), but i'm strongly doesnt recomend it, so JFYI :)

phideg commented 7 months ago

I tried debugging my own little project: https://github.com/phideg/neptungen

I started the debugger with

bs ../neptungen/target/debug/neptungen
(bs) b main
New breakpoint 1 at 0x00000000849836: /home/phil/Projekte/neptungen/src/main.rs:85
(bs) r
Hit breakpoint 1 at 0x00555555D9D836: /home/phil/Projekte/neptungen/src/main.rs:85
  85     let arguments = Arguments::parse();
(bs) next
Error: libunwind error: unsupported operation or bad value

I tried the same thing with the helix project. Here I ran in a completely different error

helix/target/debug on  master 
❯ bs hx

BugStalker greets

(bs) b main
New breakpoint 1 at 0x00000000D7A184: /home/phil/Projekte/helix/helix-term/src/main.rs:37 
(bs) r
Error: memory region offset not found (unknown segment)
phideg commented 7 months ago

neptungen has been build with rust 1.71.1 while helix required 1.70.0 via rust-toolchain.toml

godzie44 commented 7 months ago

hm, i'm test both repro in my dev pc (ubuntu 22.04 + rust 1.77) and it is worked fine. So can you provide your output of dpkg -l | grep unwind command? Also you use Fedora 39 right? And last thing - debugger support rustc version 1.75+, may be problem at this point.

phideg commented 7 months ago

❯ dnf list installed | grep unwind libunwind.x86_64 1.7.0-0.2.rc2.fc39 @fedora
libunwind-devel.x86_64 1.7.0-0.2.rc2.fc39 @fedora
llvm-libunwind.x86_64 17.0.6-1.fc39 @updates
llvm-libunwind-devel.x86_64 17.0.6-1.fc39 @updates

phideg commented 7 months ago

so I build a bs version with --no-default-features

cargo install --path . --no-default-features

with that version of BugStalker stepping with F8 worked 👍🏽.

phideg commented 7 months ago

I debugged the issue. The error comes from the following line: https://github.com/sfackler/rstack/blob/master/unwind/src/lib.rs#L370

let ret = unw_step(&mut self.0);

ret has error code -8. According to the error codes here it means the following??:

...
UNW_EINVAL,         /* unsupported operation or bad value */
...
godzie44 commented 7 months ago

Interesting, is this error occures at first stack frame? I mean, may be a fast solve of this problem at bs side - just cut backtrace from libunwind at error point? (because I'm afraid that the general solution should not be in bs, but in libunwind)

Upd. Oh, I see that error at next commands. Libunwind used here for determine a return address…

godzie44 commented 7 months ago

I tried to reproduce at fresh Fedora 39

Rustc version 1.77.1

Libunwind version:

dnf list installed | grep unwind
libunwind.x86_64                                     1.7.0-0.2.rc2.fc39                  @anaconda
libunwind-devel.x86_64                               1.7.0-0.2.rc2.fc39                  @fedora

And looks like i'm got an expected results:

k@fedora:~$ bs ./neptungen/target/debug/neptungen

BugStalker greets

(bs) b main
New breakpoint 1 at 0x000000003DE3B6: /home/k/neptungen/src/main.rs:85 
(bs) r
Hit breakpoint 1 at 0x005555559323B6: /home/k/neptungen/src/main.rs:85
  85     let arguments = Arguments::parse();
(bs) next
Simple static website generator
...

I'm also tried to downgrade rustc to 1.71.1, and still no errors.

It looks like the solution of the problem lies in some features of your setup...

phideg commented 7 months ago

I now tried it on my worstation running on fedora 39, too. And I can confirm that the error on that machine is not reproducible, too. No, idea why its still failing on my laptop.

phideg commented 5 months ago

sorry I did not have the time to follow up on this for some time. This evening I updated my rust compiler to version 1.79 and pulled latest BugStalker revision (a9668f5bb181328c94ea426d7a00ff9c0e4d0c8b). I repeated the steps to debug main of my neptungen project. And there is an interesting new effect. The first time I run I get

Error: memory region offset not found (unknown segment)

If I run it a second time the breakpoint does not get hit and instead I get the help overview of clap

(bs) b main
New breakpoint 1 at 0x00000000849836: /home/phideg/neptungen/src/main.rs:85 
(bs) run
Error: memory region offset not found (unknown segment)
(bs) run
Restart a program?
(bs y/n) y
Simple static website generator

Usage: neptungen [OPTIONS] <COMMAND>

Commands:
  print-config  Print the configuration of the config.toml file
  build         Generate the website
  sync          Synchronize the website with an sftp or ftp server
  serve         Start a local http server that allows testing the site
  help          Print this message or the help of the given subcommand(s)

Options:
  -p, --project-path <FILE>  Specify the path to the project. By default current directory is used
  -h, --help                 Print help
  -V, --version              Print version
Program exit with code: 2
godzie44 commented 5 months ago

No problem, are you observe this behavior with libunwind or builtin unwinder (--no-default-features)?