Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to debug crashes in external libraries

Tags:

rust

My rust code is crashing somewhere inside rust-http and I have no clue how to debug it.

I get this error when I run it:

$ ./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 to get some instruction on how to find the code calling the Option::unwrap().

How can I trigger a core file or is there any other way to get more info?

My programming experience is mainly in the dynamic languages, where a crash gives a full backtrace and it's fairly easy to find the problematic code. How can I get similar info with rust?

Later edit:

Based on the answer from Steve K, I enabled backtrace env but, unfortunately, the 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

Am I missing something?

Thanks

like image 788
mhristache Avatar asked Aug 14 '14 20:08

mhristache


1 Answers

The RUST_BACKTRACE environment variable will give you a backtrace. Try

$ RUST_BACKTRACE=1 ./target/ecmiwc -i www.google.com -u testuser -v test
like image 115
Steve Klabnik Avatar answered Nov 09 '22 22:11

Steve Klabnik