Skip to content

Commit b67a917

Browse files
committed
torture: Add gdb support
This commit adds a "--gdb" parameter to kvm.sh, which causes "CONFIG_DEBUG_INFO=y" to be added to the Kconfig options, "nokaslr" to be added to the boot parameters, and "-s -S" to be added to the qemu arguments. Furthermore, the scripting prints messages telling the user how to start up gdb for the run in question. Because of the interactive nature of gdb sessions, only one "--configs" scenario is permitted when "--gdb" is specified. For most torture types, this means that a "--configs" argument is required, and that argument must specify the single scenario of interest. The usual cautions about breakpoints and timing apply, for example, staring at your gdb prompt for too long will likely get you many complaints, including RCU CPU stall warnings. Omar Sandoval further suggests using gdb's "hbreak" command instead of the "break" command on systems supporting hardware breakpoints, and further using the "commands" option because the resulting non-interactive breakpoints are less likely to get you RCU CPU stall warnings. Signed-off-by: Paul E. McKenney <paulmck@kernel.org>
1 parent d685514 commit b67a917

2 files changed

Lines changed: 46 additions & 8 deletions

File tree

tools/testing/selftests/rcutorture/bin/kvm-test-1-run.sh

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ config_override_param () {
6666
echo > $T/KcList
6767
config_override_param "$config_dir/CFcommon" KcList "`cat $config_dir/CFcommon 2> /dev/null`"
6868
config_override_param "$config_template" KcList "`cat $config_template 2> /dev/null`"
69+
config_override_param "--gdb options" KcList "$TORTURE_KCONFIG_GDB_ARG"
6970
config_override_param "--kasan options" KcList "$TORTURE_KCONFIG_KASAN_ARG"
7071
config_override_param "--kcsan options" KcList "$TORTURE_KCONFIG_KCSAN_ARG"
7172
config_override_param "--kconfig argument" KcList "$TORTURE_KCONFIG_ARG"
@@ -152,7 +153,11 @@ qemu_append="`identify_qemu_append "$QEMU"`"
152153
boot_args="`configfrag_boot_params "$boot_args" "$config_template"`"
153154
# Generate kernel-version-specific boot parameters
154155
boot_args="`per_version_boot_params "$boot_args" $resdir/.config $seconds`"
155-
echo $QEMU $qemu_args -m $TORTURE_QEMU_MEM -kernel $KERNEL -append \"$qemu_append $boot_args\" > $resdir/qemu-cmd
156+
if test -n "$TORTURE_BOOT_GDB_ARG"
157+
then
158+
boot_args="$boot_args $TORTURE_BOOT_GDB_ARG"
159+
fi
160+
echo $QEMU $qemu_args -m $TORTURE_QEMU_MEM -kernel $KERNEL -append \"$qemu_append $boot_args\" $TORTURE_QEMU_GDB_ARG > $resdir/qemu-cmd
156161

157162
if test -n "$TORTURE_BUILDONLY"
158163
then
@@ -171,14 +176,26 @@ echo "NOTE: $QEMU either did not run or was interactive" > $resdir/console.log
171176
# Attempt to run qemu
172177
( . $T/qemu-cmd; wait `cat $resdir/qemu_pid`; echo $? > $resdir/qemu-retval ) &
173178
commandcompleted=0
174-
sleep 10 # Give qemu's pid a chance to reach the file
175-
if test -s "$resdir/qemu_pid"
179+
if test -z "$TORTURE_KCONFIG_GDB_ARG"
176180
then
177-
qemu_pid=`cat "$resdir/qemu_pid"`
178-
echo Monitoring qemu job at pid $qemu_pid
179-
else
180-
qemu_pid=""
181-
echo Monitoring qemu job at yet-as-unknown pid
181+
sleep 10 # Give qemu's pid a chance to reach the file
182+
if test -s "$resdir/qemu_pid"
183+
then
184+
qemu_pid=`cat "$resdir/qemu_pid"`
185+
echo Monitoring qemu job at pid $qemu_pid
186+
else
187+
qemu_pid=""
188+
echo Monitoring qemu job at yet-as-unknown pid
189+
fi
190+
fi
191+
if test -n "$TORTURE_KCONFIG_GDB_ARG"
192+
then
193+
echo Waiting for you to attach a debug session, for example: > /dev/tty
194+
echo " gdb $base_resdir/vmlinux" > /dev/tty
195+
echo 'After symbols load and the "(gdb)" prompt appears:' > /dev/tty
196+
echo " target remote :1234" > /dev/tty
197+
echo " continue" > /dev/tty
198+
kstarttime=`gawk 'BEGIN { print systime() }' < /dev/null`
182199
fi
183200
while :
184201
do

tools/testing/selftests/rcutorture/bin/kvm.sh

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@ TORTURE_DEFCONFIG=defconfig
3131
TORTURE_BOOT_IMAGE=""
3232
TORTURE_INITRD="$KVM/initrd"; export TORTURE_INITRD
3333
TORTURE_KCONFIG_ARG=""
34+
TORTURE_KCONFIG_GDB_ARG=""
35+
TORTURE_BOOT_GDB_ARG=""
36+
TORTURE_QEMU_GDB_ARG=""
3437
TORTURE_KCONFIG_KASAN_ARG=""
3538
TORTURE_KCONFIG_KCSAN_ARG=""
3639
TORTURE_KMAKE_ARG=""
@@ -56,6 +59,7 @@ usage () {
5659
echo " --defconfig string"
5760
echo " --dryrun sched|script"
5861
echo " --duration minutes"
62+
echo " --gdb"
5963
echo " --help"
6064
echo " --interactive"
6165
echo " --jitter N [ maxsleep (us) [ maxspin (us) ] ]"
@@ -128,6 +132,11 @@ do
128132
dur=$(($2*60))
129133
shift
130134
;;
135+
--gdb)
136+
TORTURE_KCONFIG_GDB_ARG="CONFIG_DEBUG_INFO=y"; export TORTURE_KCONFIG_GDB_ARG
137+
TORTURE_BOOT_GDB_ARG="nokaslr"; export TORTURE_BOOT_GDB_ARG
138+
TORTURE_QEMU_GDB_ARG="-s -S"; export TORTURE_QEMU_GDB_ARG
139+
;;
131140
--help|-h)
132141
usage
133142
;;
@@ -253,6 +262,15 @@ do
253262
done
254263
touch $T/cfgcpu
255264
configs_derep="`echo $configs_derep | sed -e "s/\<CFLIST\>/$defaultconfigs/g"`"
265+
if test -n "$TORTURE_KCONFIG_GDB_ARG"
266+
then
267+
if test "`echo $configs_derep | wc -w`" -gt 1
268+
then
269+
echo "The --config list is: $configs_derep."
270+
echo "Only one --config permitted with --gdb, terminating."
271+
exit 1
272+
fi
273+
fi
256274
for CF1 in $configs_derep
257275
do
258276
if test -f "$CONFIGFRAG/$CF1"
@@ -328,6 +346,9 @@ TORTURE_BUILDONLY="$TORTURE_BUILDONLY"; export TORTURE_BUILDONLY
328346
TORTURE_DEFCONFIG="$TORTURE_DEFCONFIG"; export TORTURE_DEFCONFIG
329347
TORTURE_INITRD="$TORTURE_INITRD"; export TORTURE_INITRD
330348
TORTURE_KCONFIG_ARG="$TORTURE_KCONFIG_ARG"; export TORTURE_KCONFIG_ARG
349+
TORTURE_KCONFIG_GDB_ARG="$TORTURE_KCONFIG_GDB_ARG"; export TORTURE_KCONFIG_GDB_ARG
350+
TORTURE_BOOT_GDB_ARG="$TORTURE_BOOT_GDB_ARG"; export TORTURE_BOOT_GDB_ARG
351+
TORTURE_QEMU_GDB_ARG="$TORTURE_QEMU_GDB_ARG"; export TORTURE_QEMU_GDB_ARG
331352
TORTURE_KCONFIG_KASAN_ARG="$TORTURE_KCONFIG_KASAN_ARG"; export TORTURE_KCONFIG_KASAN_ARG
332353
TORTURE_KCONFIG_KCSAN_ARG="$TORTURE_KCONFIG_KCSAN_ARG"; export TORTURE_KCONFIG_KCSAN_ARG
333354
TORTURE_KMAKE_ARG="$TORTURE_KMAKE_ARG"; export TORTURE_KMAKE_ARG

0 commit comments

Comments
 (0)