Skip to content

Commit

Permalink
Add CROSS_DEBUG env variable to debug qemu-system
Browse files Browse the repository at this point in the history
  • Loading branch information
malbarbo committed Oct 9, 2018
1 parent 2951d3e commit bb071d0
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 11 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ sudo: required
matrix:
include:
# Linux
- env: TARGET=aarch64-unknown-linux-gnu CPP=1 DYLIB=1 STD=1 OPENSSL=0.5.5 RUN=1 RUNNERS="qemu-user qemu-system"
- env: TARGET=aarch64-unknown-linux-gnu CPP=1 DYLIB=1 STD=1 OPENSSL=0.5.5 RUN=1 RUNNERS="qemu-user qemu-system" CROSS_DEBUG=1
- env: TARGET=arm-unknown-linux-gnueabi CPP=1 DYLIB=1 STD=1 OPENSSL=0.5.5 RUN=1
- env: TARGET=arm-unknown-linux-musleabi STD=1 RUN=1
- env: TARGET=armv7-unknown-linux-gnueabihf CPP=1 DYLIB=1 STD=1 OPENSSL=0.5.5 RUN=1
Expand Down
31 changes: 21 additions & 10 deletions docker/linux-runner
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,13 @@

set -e

LOG=/tmp/qemu.log
LOCK=/tmp/qemu.lock

if [ -n "$CROSS_DEBUG" ]; then
set -x
fi

# arch in the rust target
arch=$1
shift
Expand All @@ -23,7 +30,9 @@ case "$CROSS_RUNNER" in
;;
esac

# 8 is the max number of cpu supported by qemu-aarch64
n=$(nproc)
n=$(( n > 8 ? 8 : n ))
memory=1G
driver9p="virtio-9p-device"
drivernet="virtio-net-device"
Expand All @@ -40,9 +49,7 @@ esac

echo Booting QEMU virtual machine with $n cpus...

touch /tmp/qemu.log

qemu-system-$arch \
QEMU_CMD="qemu-system-$arch \
-m $memory \
-smp $n \
-nographic \
Expand All @@ -53,17 +60,21 @@ esac
-initrd /qemu/initrd.gz \
$opt \
-fsdev local,id=fs0,path=/target,security_model=mapped \
-device $driver9p,fsdev=fs0,mount_tag=target 2>&1 >> /tmp/qemu.log &
-device $driver9p,fsdev=fs0,mount_tag=target"

touch $LOG
if [ -n "$CROSS_DEBUG" ]; then
($QEMU_CMD 2>&1 | tee -a $LOG) &
else
$QEMU_CMD 2>&1 >> $LOG &
fi

while read line; do
if [[ "$line" == *"Not backgrounding"* ]]; then
break
fi
done < <(tailf /tmp/qemu.log)
# wait for dropbear
tailf $LOG | grep -m1 "Not backgrounding" > /dev/null

echo Booted in $(dbclient -K 1 -p 10022 -y -y root@localhost "cut -d' ' -f1 /proc/uptime") seconds

) 200>/tmp/qemu.lock
) 200>$LOCK

exec dbclient \
-t \
Expand Down
4 changes: 4 additions & 0 deletions src/docker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,10 @@ pub fn run(target: &Target,
docker.args(&["-e", &format!("QEMU_STRACE={}", value)]);
}

if let Some(value) = env::var("CROSS_DEBUG").ok() {
docker.args(&["-e", &format!("CROSS_DEBUG={}", value)]);
}

let mut runner = target.default_runner();

if let Some(toml) = toml {
Expand Down

0 comments on commit bb071d0

Please sign in to comment.