mirror of
https://github.com/cirosantilli/linux-kernel-module-cheat.git
synced 2026-01-25 19:21:35 +01:00
qemu on background for debug
This commit is contained in:
36
README.md
36
README.md
@@ -44,13 +44,31 @@ We use `printk` a lot, and it shows on the QEMU terminal by default. If that ann
|
|||||||
|
|
||||||
See also: <https://superuser.com/questions/351387/how-to-stop-kernel-messages-from-flooding-my-console>
|
See also: <https://superuser.com/questions/351387/how-to-stop-kernel-messages-from-flooding-my-console>
|
||||||
|
|
||||||
|
## Text mode
|
||||||
|
|
||||||
|
Show serial output of QEMU directly on the current terminal, without opening a QEMU window:
|
||||||
|
|
||||||
|
./run -n
|
||||||
|
|
||||||
|
To exit, just do a regular:
|
||||||
|
|
||||||
|
poweroff
|
||||||
|
|
||||||
|
This is particularly useful to get full panic traces when you start making the kernel crashing :-)
|
||||||
|
|
||||||
|
In case of a panic, you want your terminal back with `Ctrl + C, A` and type `quit`. See also: <http://stackoverflow.com/questions/14165158/how-to-switch-to-qemu-monitor-console-when-running-with-curses>
|
||||||
|
|
||||||
|
See also: <https://unix.stackexchange.com/questions/208260/how-to-scroll-up-after-a-kernel-panic>
|
||||||
|
|
||||||
## Debugging
|
## Debugging
|
||||||
|
|
||||||
To GDB the Linux kernel, first run:
|
To GDB the Linux kernel, first run:
|
||||||
|
|
||||||
./runqemu -d
|
./runqemu -d
|
||||||
|
|
||||||
If you want to break immediately at a symbol, e.g. `start_kernel` of the boot sequence, open another terminal and run:
|
This starts QEMU on the background of the shell, to prepare for running GDB.
|
||||||
|
|
||||||
|
If you want to break immediately at a symbol, e.g. `start_kernel` of the boot sequence, run:
|
||||||
|
|
||||||
./rungdb start_kernel
|
./rungdb start_kernel
|
||||||
|
|
||||||
@@ -83,21 +101,15 @@ And now you can control the counting from GDB:
|
|||||||
|
|
||||||
See also: <http://stackoverflow.com/questions/11408041/how-to-debug-the-linux-kernel-with-gdb-and-qemu>
|
See also: <http://stackoverflow.com/questions/11408041/how-to-debug-the-linux-kernel-with-gdb-and-qemu>
|
||||||
|
|
||||||
## Text mode
|
If you are using text mode:
|
||||||
|
|
||||||
Show serial output of QEMU directly on the current terminal, without opening a QEMU window:
|
./runqemu -d -n
|
||||||
|
|
||||||
./run -n
|
QEMU cannot be put on the background of the current shell, so you will need to open a separate terminal and run:
|
||||||
|
|
||||||
To exit, just do a regular:
|
./rungdb
|
||||||
|
|
||||||
poweroff
|
manually.
|
||||||
|
|
||||||
This is particularly useful to get full panic traces when you start making the kernel crashing :-)
|
|
||||||
|
|
||||||
In case of a panic, you want your terminal back with `Ctrl + C, A` and type `quit`. See also: <http://stackoverflow.com/questions/14165158/how-to-switch-to-qemu-monitor-console-when-running-with-curses>
|
|
||||||
|
|
||||||
See also: <https://unix.stackexchange.com/questions/208260/how-to-scroll-up-after-a-kernel-panic>
|
|
||||||
|
|
||||||
## Table of contents
|
## Table of contents
|
||||||
|
|
||||||
|
|||||||
2
rungdb
2
rungdb
@@ -6,6 +6,7 @@ else
|
|||||||
fi
|
fi
|
||||||
cd buildroot/output/build/linux-*.*.*/
|
cd buildroot/output/build/linux-*.*.*/
|
||||||
cmd="gdb \
|
cmd="gdb \
|
||||||
|
-q \
|
||||||
-ex 'add-auto-load-safe-path $(pwd)' \
|
-ex 'add-auto-load-safe-path $(pwd)' \
|
||||||
-ex 'file vmlinux' \
|
-ex 'file vmlinux' \
|
||||||
-ex 'set arch i386:x86-64:intel' \
|
-ex 'set arch i386:x86-64:intel' \
|
||||||
@@ -16,5 +17,4 @@ cmd="gdb \
|
|||||||
-ex 'set arch i386:x86-64' \
|
-ex 'set arch i386:x86-64' \
|
||||||
-ex 'target remote localhost:1234'
|
-ex 'target remote localhost:1234'
|
||||||
"
|
"
|
||||||
echo "$cmd"
|
|
||||||
eval "$cmd"
|
eval "$cmd"
|
||||||
|
|||||||
20
runqemu
20
runqemu
@@ -3,23 +3,27 @@
|
|||||||
set -e
|
set -e
|
||||||
|
|
||||||
# CLI handling.
|
# CLI handling.
|
||||||
|
debug=false
|
||||||
|
nographic=false
|
||||||
extra_append=''
|
extra_append=''
|
||||||
extra_flags=''
|
extra_flags=''
|
||||||
while getopts dn OPT; do
|
while getopts dn OPT; do
|
||||||
case "$OPT" in
|
case "$OPT" in
|
||||||
d)
|
d)
|
||||||
|
debug=true
|
||||||
extra_flags="$extra_flags -S -s"
|
extra_flags="$extra_flags -S -s"
|
||||||
;;
|
;;
|
||||||
n)
|
n)
|
||||||
extra_append="$extra_append console=ttyS0"
|
extra_append="$extra_append console=ttyS0"
|
||||||
extra_flags="$extra_flags -nographic"
|
extra_flags="$extra_flags -nographic"
|
||||||
|
nographic=true
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
done
|
done
|
||||||
|
|
||||||
qemu-system-x86_64 \
|
cmd="qemu-system-x86_64 \
|
||||||
-M pc \
|
-M pc \
|
||||||
-append "root=/dev/vda $extra_append" \
|
-append 'root=/dev/vda $extra_append' \
|
||||||
-drive file=buildroot/output/images/rootfs.ext2,if=virtio,format=raw \
|
-drive file=buildroot/output/images/rootfs.ext2,if=virtio,format=raw \
|
||||||
-kernel buildroot/output/images/bzImage \
|
-kernel buildroot/output/images/bzImage \
|
||||||
-m 128M \
|
-m 128M \
|
||||||
@@ -28,3 +32,15 @@ qemu-system-x86_64 \
|
|||||||
-smp 1 \
|
-smp 1 \
|
||||||
$extra_flags \
|
$extra_flags \
|
||||||
;
|
;
|
||||||
|
"
|
||||||
|
|
||||||
|
if $debug && ! $nographic; then
|
||||||
|
eval nohup "$cmd" &>/dev/null &
|
||||||
|
# TODO: Ctrl +C gets sent to QEMU? Why? Does not happen if I run
|
||||||
|
# ./rungdb manually from outside this script!!! But why?!?!
|
||||||
|
# eval has nothing to do with it, minimized example with explicit
|
||||||
|
# commands also fails in the same way...
|
||||||
|
#./rungdb
|
||||||
|
else
|
||||||
|
eval "$cmd"
|
||||||
|
fi
|
||||||
|
|||||||
Reference in New Issue
Block a user