How to debug crashes in external libraries

My rusty code gets stuck somewhere inside rust-http, and I don't know how to debug it.

I get this error on startup:

$ ./target/ecmiwc -i www.google.com -u testuser -v test task '<main>' failed at 'called `Option::unwrap()` on a `None` value', /Users/rustbuild/src/rust-buildbot/slave/nightly-mac/build/src/libcore/option.rs:262 

I would like some instruction on how to find the code that calls Option::unwrap() .

How can I run the main file or is there any other way to get additional information?

My programming experience is mainly related to dynamic languages, where a crash gives you full backtracking, and it is quite easy to find the problematic code. How to get similar information with rust?

Next edit:

Based on a response from Steve K, I included backtrace env, but unfortunately backtrace is not very useful:

 $ RUST_BACKTRACE=1 ./target/ecmiwc -i www.google.com -u testuser -v test task '<main>' failed at 'called `Option::unwrap()` on a `None` value', /Users/rustbuild/src/rust-buildbot/slave/nightly-mac/build/src/libcore/option.rs:262 stack backtrace: 1: 0x10b70c065 - rt::backtrace::imp::write::h471bb232e1b48857jar 2: 0x10b70f1ef - failure::on_fail::h05edea1dadf8fbaaOqr 3: 0x10b715e25 - unwind::begin_unwind_inner::h7c6fecebc6991c8bS5d 4: 0x10b715a5b - unwind::begin_unwind_fmt::h227376fe1e021a36n3d 5: 0x10b7158b2 - rust_begin_unwind 6: 0x10b73769c - failure::begin_unwind::h7d8f396ab219c1bbn5j 7: 0x10b5a2cce - option::Option<T>::unwrap::h6219013626023885255 8: 0x10b5a25e8 - client::request::RequestWriter<S>::connect::h10689478801106876767 9: 0x10b59d523 - Ecm::login::h463674fdedafce079ja 10: 0x10b5ab502 - main::h2d8f53839ca9df9eDJa 11: 0x10b6fd879 - start::closure.8479 12: 0x10b716b3c - rust_try_inner 13: 0x10b716b26 - rust_try 14: 0x10b713e0b - unwind::try::h5982dbe8fdfe64a5nUd 15: 0x10b713beb - task::Task::run::h1c9de674e75b1485v2c 16: 0x10b6fd6af - start::h15d3cd64eea8fd88hve 17: 0x10b6fd4dc - lang_start::h7823875e69d425d0Bue 18: 0x10b5ab6df - main 

Did I miss something?

thanks

+6
source share
2 answers

The environment variable RUST_BACKTRACE will give you backtrace. Try

 $ RUST_BACKTRACE=1 ./target/ecmiwc -i www.google.com -u testuser -v test 
+9
source

The reverse mapping shows that client::request::RequestWriter<S>::connect from rust-http is what causes unwrap , which fails. This is the body of the method:

 pub fn connect(&mut self) -> IoResult<()> { if !self.stream.is_none() { fail!("I don't think you meant to call connect() twice, you know."); } self.stream = match self.remote_addr { Some(addr) => { let stream = try!(Connecter::connect( addr, self.headers.host.as_ref().unwrap().name.as_slice(), self.use_ssl)); Some(BufferedStream::new(stream)) }, None => fail!("connect() called before remote_addr was set"), }; Ok(()) } 

The unwrap call is on self.headers.host.as_ref() ; this means that self.headers.host is None , which it should not ( new / new_request set, did it change?).

You can also do more thorough debugging work by building debugging symbols (Im really not sure if Cargo can do this) and using gdb. The breakpoint for the installation is called rust_fail .

0
source

Source: https://habr.com/ru/post/973839/


All Articles