使用Valgrind测量Rust内存使用量会导致SIGSEV

时间:2018-11-06 18:32:27

标签: rust valgrind

我有一个用Rust 1.30.0编译的Rust程序:

use std::collections::HashMap;
use std::fs::File;
use std::io::{BufRead, BufReader, Result};

fn main() -> Result<()> {
    let file = File::open("file.txt")?;
    let mut scores = HashMap::new();
    let mut i = 0;
    for line in BufReader::new(file).lines() {
        let line = line.expect("Unable to read line");
        scores.insert(line, i);
        i = i + 1;
    }
    Ok(())
}

首先,我将其构建:

cargo build --release
cd target/release

单独运行即可:

./hello_cargo

但是在运行Valgrind时:

valgrind --tool=massif --main-stacksize=1900000000 ./hello_cargo
==11619== Massif, a heap profiler
==11619== Copyright (C) 2003-2017, and GNU GPL'd, by Nicholas Nethercote
==11619== Using Valgrind-3.13.0 and LibVEX; rerun with -h for copyright info
==11619== Command: ./hello_cargo
==11619==
==11619==
==11619== Process terminating with default action of signal 11 (SIGSEGV)
==11619==  Access not within mapped region at address 0x8193A990
==11619==    at 0x4863B9E: __dlerror_main_freeres (dlerror.c:189)
==11619==    by 0x4A3EA41: __libc_freeres (in /lib/x86_64-linux-gnu/libc-2.28.so)
==11619==    by 0x482D19E: _vgnU_freeres (in /usr/lib/valgrind/vgpreload_core-amd64-linux.so)
==11619==    by 0x48F1529: __run_exit_handlers (exit.c:132)
==11619==    by 0x48F1559: exit (exit.c:139)
==11619==    by 0x48D10A1: (below main) (libc-start.c:342)
==11619==  If you believe this happened as a result of a stack
==11619==  overflow in your program's main thread (unlikely but
==11619==  possible), you can try to increase the size of the
==11619==  main thread stack using the --main-stacksize= flag.
==11619==  The main thread stack size used in this run was 1900003328.

我尝试使用main-stacksize的不同参数,但这没有帮助。

我该如何解决这个问题?

0 个答案:

没有答案