Skip to content

Commit 5560978

Browse files
committed
LOC: qemu dbg
1 parent 022047d commit 5560978

File tree

2 files changed

+37
-1
lines changed

2 files changed

+37
-1
lines changed

src/tools/qemu-test-client/src/main.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,9 @@ fn main() {
5151
}
5252

5353
fn spawn_emulator(rootfs: &Path, tmpdir: &Path) {
54+
use std::os::unix::io::{FromRawFd, IntoRawFd};
55+
use std::fs::OpenOptions;
56+
5457
// Generate a new rootfs image now that we've updated the test server
5558
// executable. This is the equivalent of:
5659
//
@@ -71,6 +74,10 @@ fn spawn_emulator(rootfs: &Path, tmpdir: &Path) {
7174
&mut t!(File::create(&rootfs_img))));
7275
assert!(t!(child.wait()).success());
7376

77+
let log = OpenOptions::new().create(true).append(true).open("qemu.log").unwrap();
78+
let qout = unsafe { Stdio::from_raw_fd(log.try_clone().unwrap().into_raw_fd()) };
79+
let qerr = unsafe { Stdio::from_raw_fd(log.try_clone().unwrap().into_raw_fd()) };
80+
7481
// Start up the emulator, in the background
7582
let mut cmd = Command::new("qemu-system-arm");
7683
cmd.arg("-M").arg("vexpress-a15")
@@ -80,7 +87,8 @@ fn spawn_emulator(rootfs: &Path, tmpdir: &Path) {
8087
.arg("-dtb").arg("/tmp/vexpress-v2p-ca15-tc1.dtb")
8188
.arg("-append").arg("console=ttyAMA0 root=/dev/ram rdinit=/sbin/init init=/sbin/init")
8289
.arg("-nographic")
83-
.arg("-redir").arg("tcp:12345::12345");
90+
.arg("-redir").arg("tcp:12345::12345")
91+
.stdout(qout).stderr(qerr);
8492
t!(cmd.spawn());
8593

8694
// Wait for the emulator to come online

src/tools/qemu-test-server/src/main.rs

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11+
#![feature(libc)]
12+
13+
extern crate libc;
14+
1115
/// This is a small server which is intended to run inside of an emulator. This
1216
/// server pairs with the `qemu-test-client` program in this repository. The
1317
/// `qemu-test-client` connects to this server over a TCP socket and performs
@@ -41,7 +45,31 @@ macro_rules! t {
4145

4246
static TEST: AtomicUsize = ATOMIC_USIZE_INIT;
4347

48+
fn debug() {
49+
::std::env::set_var("RUST_BACKTRACE", "1");
50+
51+
unsafe {
52+
let pid = libc::fork();
53+
if pid == 0 {
54+
println!("@@ Child is running.");
55+
return; // we are the child
56+
}
57+
assert!(pid > 0);
58+
59+
println!("@@ Watcher is running.");
60+
61+
let mut status: libc::c_int = 0;
62+
libc::waitpid(pid, &mut status, 0);
63+
64+
println!("@@EXIT@@: {}", status);
65+
66+
::std::process::exit(0);
67+
}
68+
}
69+
4470
fn main() {
71+
debug();
72+
4573
println!("starting test server");
4674
let listener = t!(TcpListener::bind("10.0.2.15:12345"));
4775
println!("listening!");

0 commit comments

Comments
 (0)