Skip to content
Snippets Groups Projects
Commit 37acafe3 authored by Per Lindgren's avatar Per Lindgren
Browse files

replay support (wip2)

parent b7466925
No related branches found
No related tags found
No related merge requests found
...@@ -3,10 +3,10 @@ use failure::format_err; ...@@ -3,10 +3,10 @@ use failure::format_err;
use std::{ use std::{
env, env,
error::Error, error::Error,
fmt, fmt, fs,
path::{Path, PathBuf}, path::{Path, PathBuf},
process::{self, Command, Stdio}, process::{self, Command, Stdio},
time::Instant, time::{Instant, SystemTime},
}; };
use structopt::StructOpt; use structopt::StructOpt;
...@@ -80,18 +80,27 @@ fn run() -> Result<i32, failure::Error> { ...@@ -80,18 +80,27 @@ fn run() -> Result<i32, failure::Error> {
println!("args {:?}", args); println!("args {:?}", args);
let status = Command::new("cargo") let mut cargo = Command::new("cargo");
.arg("rustc")
.args(args) // forwarding of user arguments
cargo.arg("rustc").args(args);
// klee specifics
cargo
.args(&["--features", "klee-analysis"])
.arg("--") .arg("--")
// ignore linking // ignore linking
.args(&["-C", "linker=true"]) .args(&["-C", "linker=true"])
// force LTO, to get a single oject file // force LTO, to get a single object file
.args(&["-C", "lto"]) .args(&["-C", "lto"])
// output the LLVM-IR (.ll file) for KLEE analysis // output the LLVM-IR (.ll file) for KLEE analysis
.arg("--emit=llvm-ir") .arg("--emit=llvm-ir");
// force panic=abort in all crates, override .cargo settings // force panic=abort in all crates, override .cargo settings
.env("RUSTFLAGS", "-C panic=abort") //.env("RUSTFLAGS", "-C panic=abort");
println!("cargo {:?}", cargo);
let status = cargo
.stdout(Stdio::inherit()) .stdout(Stdio::inherit())
.stderr(Stdio::inherit()) .stderr(Stdio::inherit())
.spawn()? .spawn()?
...@@ -143,7 +152,58 @@ fn run() -> Result<i32, failure::Error> { ...@@ -143,7 +152,58 @@ fn run() -> Result<i32, failure::Error> {
None => panic!(), None => panic!(),
}; };
println!(" {} {}", "Flashing".green().bold(), path_str); // get the directory of the binary;
let dir = path.parent().expect("unreachable").to_path_buf();
// lookup the latest .ll file
// llvm-ir file
let mut ll = None;
// most recently modified
let mut mrm = SystemTime::UNIX_EPOCH;
// let prefix = format!("{}-", file.replace('-', "_"));
println!("path {:?}", &dir);
for e in fs::read_dir(&dir)? {
println!("e {:?}", e);
let e = e?;
let p = e.path();
if p.extension().map(|e| e == "ll").unwrap_or(false) {
if p.file_stem()
.expect("unreachable")
.to_str()
.expect("unreachable")
.starts_with(&name)
{
let modified = e.metadata()?.modified()?;
if ll.is_none() {
ll = Some(p);
mrm = modified;
} else {
if modified > mrm {
ll = Some(p);
mrm = modified;
}
}
}
}
}
println!("ll {:?}", ll);
// klee analysis
let mut klee = Command::new("klee");
klee
// ll file to analyse
.arg(ll.unwrap());
// execute the command and unwrap the result into status
let status = klee.status()?;
if !status.success() {
return Ok(status.code().unwrap_or(1));
}
// println!(" {} {}", "Flashing".green().bold(), path_str);
return Ok(0); return Ok(0);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment