From e54635c3abd8d1c3de2723ced0e6b94a0dd98711 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ciro=20Santilli=20=E5=85=AD=E5=9B=9B=E4=BA=8B=E4=BB=B6=20?= =?UTF-8?q?=E6=B3=95=E8=BD=AE=E5=8A=9F?= Date: Tue, 13 Nov 2018 00:00:00 +0000 Subject: [PATCH] make gdb test automation even awesomer --- README.adoc | 20 ++++++++++-- baremetal/arch/aarch64/regs.S | 1 - baremetal/arch/aarch64/regs.py | 4 +++ baremetal/arch/arm/regs.S | 8 +++++ baremetal/arch/arm/regs.py | 8 +++++ baremetal/lib/common.c | 1 + build | 2 +- test-gdb | 60 +++++++++++++++------------------- 8 files changed, 65 insertions(+), 39 deletions(-) create mode 100644 baremetal/arch/arm/regs.S create mode 100644 baremetal/arch/arm/regs.py diff --git a/README.adoc b/README.adoc index 80649bf..ea913e8 100644 --- a/README.adoc +++ b/README.adoc @@ -32,7 +32,7 @@ Reserve 12Gb of disk and run: .... git clone https://github.com/cirosantilli/linux-kernel-module-cheat cd linux-kernel-module-cheat -./build --download-dependencies +./build --download-dependencies qemu-buildroot ./run .... @@ -1321,7 +1321,7 @@ Tested on 4f4749148273c282e80b58c59db1b47049e190bf + 1. === GDB step debug early boot -TODO sucessfully debu the very first instruction that the Linux kernel runs, before `start_kernel`! +TODO successfully debug the very first instruction that the Linux kernel runs, before `start_kernel`! Break at the very first instruction executed by QEMU: @@ -9116,6 +9116,8 @@ Remote debugging using localhost:7000 Remote 'g' packet reply is too long: 000000000000000090a4f90fc0ffffff4875450ec0ffffff01000000000000000100000000000000000000000000000001000000000000000000000000000000ffffffffffffffff646d60616b64fffe7f7f7f7f7f7f7f7f0101010101010101300000000000000000000000ffffffff48454422207d2c2017162f21262820160100000000000000070000000000000001000000000000004075450ec0ffffffc073450ec0ffffff82080000000000004075450ec0ffffff8060f90fc0ffffffc073450ec0fffffff040900880ffffff40ab400ec0ffffff586d900880ffffff0068a20ec0ffffff903b010880ffffffc8ff210880ffffff903b010880ffffffccff210880ffffff050000200000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 .... +See: <> + and gem5 says: .... @@ -10165,6 +10167,10 @@ You can also find executables that don't use the bootloader at all under `bareme ./run --arch arm --baremetal arch/arm/no_bootloader/semihost_exit --wait-gdb .... +The cool thing about those examples is that you start at the very first instruction of your program, which gives more control. + +However, those examples tend to be less portable, so we use examples with the bootloader for the most part. + Alternatively, skip directly to the C program main function with: .... @@ -11450,6 +11456,8 @@ We have some link:https://github.com/pexpect/pexpect[pexpect] automated tests fo ./test-gdb .... +Not all of them are passing right now due to: <>. + If something goes wrong, re-run the test commands manually and use `--verbose` to understand what happened: .... @@ -11457,12 +11465,18 @@ If something goes wrong, re-run the test commands manually and use `--verbose` t ./run-gdb --arch arm --baremetal add --test --verbose .... +and possibly repeat the GDB steps manually with the usual: + +.... +./run-gdb --arch arm --baremetal add --no-continue --verbose +.... + Sources: * link:build-test-gdb[] * link:test-gdb[] -For the Linux kenel, do the following manual tests for now. +For the Linux kernel, do the following manual tests for now. Shell 1: diff --git a/baremetal/arch/aarch64/regs.S b/baremetal/arch/aarch64/regs.S index f7f626f..b042e60 100644 --- a/baremetal/arch/aarch64/regs.S +++ b/baremetal/arch/aarch64/regs.S @@ -3,7 +3,6 @@ * - read x30 */ .global main main: - /* test-gdb-before-x29 */ mov x0, #1 /* test-gdb-x0 */ mov x1, #2 diff --git a/baremetal/arch/aarch64/regs.py b/baremetal/arch/aarch64/regs.py index fdad4ec..51dc917 100644 --- a/baremetal/arch/aarch64/regs.py +++ b/baremetal/arch/aarch64/regs.py @@ -1,7 +1,11 @@ def test(self): self.sendline('tbreak main') self.sendline('continue') + self.continue_to('x0') + self.sendline('set $x0 = 3') self.continue_to('x1') + assert self.get_int('$x0') == 3 + assert self.get_int('$x1') == 2 self.sendline('set $x30 = 3') self.continue_to('x29') assert self.get_int('$x29') == 1 diff --git a/baremetal/arch/arm/regs.S b/baremetal/arch/arm/regs.S new file mode 100644 index 0000000..dfca10c --- /dev/null +++ b/baremetal/arch/arm/regs.S @@ -0,0 +1,8 @@ +/* See the aarch64 version. */ +.global main +main: + mov r0, #1 + /* test-gdb-r0 */ + mov r1, #2 + /* test-gdb-r1 */ + bx lr diff --git a/baremetal/arch/arm/regs.py b/baremetal/arch/arm/regs.py new file mode 100644 index 0000000..83034a4 --- /dev/null +++ b/baremetal/arch/arm/regs.py @@ -0,0 +1,8 @@ +def test(self): + self.sendline('tbreak main') + self.sendline('continue') + self.continue_to('r0') + self.sendline('set $r0 = 3') + self.continue_to('r1') + assert self.get_int('$r0') == 3 + assert self.get_int('$r1') == 2 diff --git a/baremetal/lib/common.c b/baremetal/lib/common.c index 42bf4d8..dd5090e 100644 --- a/baremetal/lib/common.c +++ b/baremetal/lib/common.c @@ -1,3 +1,4 @@ +#include #include #include diff --git a/build b/build index d22c7b9..f955d04 100755 --- a/build +++ b/build @@ -307,7 +307,7 @@ Extra args to pass to all scripts. ''' ) parser.add_argument('components', choices=list(name_to_component_map.keys()) + [[]], default=[], nargs='*', help='''\ -Which components to build. +Which components to build. Default: qemu-buildroot '''.format(common.default_arch)) common.add_dry_run_argument(parser) args = parser.parse_args() diff --git a/test-gdb b/test-gdb index e118b8c..4d64229 100755 --- a/test-gdb +++ b/test-gdb @@ -1,36 +1,28 @@ #!/usr/bin/env bash set -eux - -# QEMU -./run --arch arm --background --baremetal add --wait-gdb & -./run-gdb --arch arm --baremetal add --test "$@" -wait -./run --arch arm --background --baremetal arch/arm/add --wait-gdb & -./run-gdb --arch arm --baremetal arch/arm/add --test "$@" -wait -./run --arch aarch64 --background --baremetal add --wait-gdb & -./run-gdb --arch aarch64 --baremetal add --test "$@" -wait -./run --arch aarch64 --background --baremetal arch/aarch64/add --wait-gdb & -./run-gdb --arch aarch64 --baremetal arch/aarch64/add --test "$@" -wait - -# gem5 -./run --arch arm --background --baremetal add --gem5 --wait-gdb & -./run-gdb --arch arm --baremetal add --gem5 --test "$@" -wait -./run --arch arm --background --baremetal arch/arm/add --gem5 --wait-gdb & -./run-gdb --arch arm --baremetal arch/arm/add --gem5 --test "$@" -wait -./run --arch aarch64 --background --baremetal add --gem5 --wait-gdb & -./run-gdb --arch aarch64 --baremetal add --gem5 --test "$@" -wait -./run --arch aarch64 --background --baremetal arch/aarch64/add --gem5 --wait-gdb & -./run-gdb --arch aarch64 --baremetal arch/aarch64/add --gem5 --test "$@" -wait -./run --arch aarch64 --background --baremetal arch/aarch64/regs --gem5 --wait-gdb & -./run-gdb --arch aarch64 --baremetal arch/aarch64/regs --gem5 --test "$@" -wait -./run --arch aarch64 --background --baremetal arch/aarch64/fadd --gem5 --wait-gdb & -./run-gdb --arch aarch64 --baremetal arch/aarch64/fadd --gem5 --test "$@" -wait +for gem5 in '' --gem5; do + ./run --arch arm --background --baremetal add $gem5 --wait-gdb & + ./run-gdb --arch arm --baremetal add $gem5 --test "$@" + wait + ./run --arch arm --background --baremetal arch/arm/add $gem5 --wait-gdb & + ./run-gdb --arch arm --baremetal arch/arm/add $gem5 --test "$@" + wait + ./run --arch arm --background --baremetal arch/arm/regs $gem5 --wait-gdb & + ./run-gdb --arch arm --baremetal arch/arm/regs $gem5 --test "$@" + wait + ./run --arch aarch64 --background --baremetal add $gem5 --wait-gdb & + ./run-gdb --arch aarch64 --baremetal add $gem5 --test "$@" + wait + ./run --arch aarch64 --background --baremetal arch/aarch64/add $gem5 --wait-gdb & + ./run-gdb --arch aarch64 --baremetal arch/aarch64/add $gem5 --test "$@" + wait + ./run --arch aarch64 --background --baremetal arch/aarch64/regs $gem5 --wait-gdb & + ./run-gdb --arch aarch64 --baremetal arch/aarch64/regs $gem5 --test "$@" + wait + ./run --arch aarch64 --background --baremetal arch/aarch64/fadd $gem5 --wait-gdb & + ./run-gdb --arch aarch64 --baremetal arch/aarch64/fadd $gem5 --test "$@" + wait + ./run --arch aarch64 --background --baremetal arch/aarch64/regs $gem5 --wait-gdb & + ./run-gdb --arch aarch64 --baremetal arch/aarch64/regs $gem5 --test "$@" + wait +done