Rust not showing useful line number on panic. Showing line number in slice.rs of stdlib


#1

Hello, I have a problem I’m hoping I could get some help with.
When my program crashes instead of showing the relevant line number in my program, it instead displays the line number in slice.rs of the Rust lib.

panicked at 'assertion failed: index < self.len()', src/libcore/slice.rs:530
stack backtrace: fatal runtime error: Could not unwind stack, error = 5

The only way I can recreate the specific error message is by explicitly calling the index method on an array as shown [here (rust playground)](https://play.rust-lang.org/?code=use%20std%3A%3Aops%3A%3AIndex%3B fn%20main()%20{ %20%20%20%20let%20test_vec%20%3D%20[0%2C1%2C2%2C3%2C4%2C5%2C6]%3B %20%20%20%20println!("{%3A%3F}"%2C%20test_vec.index(10))%3B%0A%20%20%20%20println!(%22%7B%3A%3F%7D%22%2C%20test_vec%5B10%5D)%3B%0A%7D%0A&version=stable&backtrace=0) with the code below.

use std::ops::Index;
fn main() {
    let test_vec = [0,1,2,3,4,5,6];

    println!("{:?}", test_vec.index(10));
    // println!("{:?}", test_vec[10]);
}

When I index into the array with the bracket syntax, I get line number in my code to where it crashed.

However, I don’t use that .index() method anywhere in my code, so I’m not sure why I get that error output with the slice.rs line number. Is it possible one of my dependencies is using that method?

Has anyone else had this type of behavior? Thank you.


#2

Normally Rust tells you to run with RUST_BACKTRACE=1. When you do, you’ll get more useful information.

Here’s a version that does this that doesn’t require calling index manually.

fn main() {
    let test_vec = &[0,1,2,3,4,5,6];
    println!("{:?}", test_vec[10]);
}

The issue is that you’re indexing into a slice beyond the end of the slice.


#3

Thanks for the reply. I do actually run it with the backtrace crate here


but it still doesn’t show a backtrace, not sure why. The original error output I posted above does have

stack backtrace: fatal runtime error: Could not unwind stack, error = 5

but I’m not sure if that’s the backtrace failing or something else.

Also, that example you listed, when run on rust playground, https://is.gd/CqAqcD, it shows the right line number (3) instead of showing the error occurring in line 530 of slice.rs which is the issue I’m having. I know there’s an out of bound indexing going on, I just can’t figure out where and am not sure why I’m getting a not useful line number in the error output.


#4

What platform are you working on? What happens if you don’t use the backtrace crate? When you compile a program like

fn main() {
    panic!("test")
}

do you still get that stack backtrace error?


#5

That platform that it’s being run on is a 32 bit RHEL 5 machine (very old I know). It’s a client machine, and I don’t have much access to it. I can’t recreate the crash since it crashes when running on their network data. I’m just trying to figure where the index out of bounds is without having to put a check in place before every single vector index. Sorry for the inconvenient situation.

I’ve also tried running it where RUST_BACKTRACE=1 is set as an environment variable in a script before running our program, and that works for me but not them, and I’m not sure how they’re running it differently.


#6

That does sound like a fatal problem when trying to unwind and print the stack trace.

If you’re using RHEL 5, that means you’re using kernel 2.6.18 or later, which is also Rust’s minimum kernel version. I don’t know what version of glbic Rust links against, bit it looks like there is an attempt to support back to RHEL 5 based on the kernel version.

I would probably file a ticket on the bug,