Skip to content

Commit c052a83

Browse files
committed
nokaslr, thanks to @dakami at close #12
1 parent 7bd1508 commit c052a83

File tree

3 files changed

+28
-24
lines changed

3 files changed

+28
-24
lines changed

gdb-step-debugging.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,10 @@ which counts to infinity to stdout, and then in GDB:
3434

3535
And you now control the counting from GDB.
3636

37-
See also: <http://stackoverflow.com/questions/11408041/how-to-debug-the-linux-kernel-with-gdb-and-qemu>
37+
See also:
38+
39+
- <http://stackoverflow.com/questions/11408041/how-to-debug-the-linux-kernel-with-gdb-and-qemu/33203642#33203642>
40+
- <http://stackoverflow.com/questions/4943857/linux-kernel-live-debugging-how-its-done-and-what-tools-are-used/42316607#42316607>
3841

3942
`O=0` is an impossible dream, `O=2` being the default: <https://stackoverflow.com/questions/29151235/how-to-de-optimize-the-linux-kernel-to-and-compile-it-with-o0> So get ready for some weird jumps, and `<value optimized out>` fun. Why, Linux, why.
4043

@@ -73,6 +76,8 @@ Just don't forget to remove your breakpoints after `rmmod`, or they will point t
7376

7477
TODO: why does `break work_func` for `insmod kthread.ko` not break the first time I `insmod`, but breaks the second time?
7578

79+
See also: <http://stackoverflow.com/questions/28607538/how-to-debug-linux-kernel-modules-with-qemu/44095831#44095831>
80+
7681
### Bypassing lx-symbols
7782

7883
Useless, but a good way to show how hardcore you are. From inside QEMU:

run

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@ kgdb=false
1010
nographic=false
1111
# norandmaps: Don't use address space randomization. Equivalent to echo 0 > /proc/sys/kernel/randomize_va_space.
1212
# printk.time=y: log in format: "[time ] msg" for all printk messages.
13-
extra_append='norandmaps printk.devkmsg=on printk.time=y'
13+
# nokaslr: https://unix.stackexchange.com/questions/397939/turning-off-kaslr-to-debug-linux-kernel-using-qemu-and-gdb
14+
# Turned on by default since v4.12
15+
extra_append='nokaslr norandmaps printk.devkmsg=on printk.time=y'
1416
extra_flags=''
1517
while getopts a:de:knqt:x OPT; do
1618
case "$OPT" in

rungdb

Lines changed: 19 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -42,32 +42,29 @@ if "$kgdb"; then
4242
else
4343
case "$arch" in
4444
'x86_64')
45-
# http://stackoverflow.com/questions/11408041/how-to-debug-the-linux-kernel-with-gdb-and-qemu/33203642#33203642
46-
# http://stackoverflow.com/questions/4943857/linux-kernel-live-debugging-how-its-done-and-what-tools-are-used/42316607#42316607
47-
# http://stackoverflow.com/questions/28607538/how-to-debug-linux-kernel-modules-with-qemu/44095831#44095831
4845
cmd="$gdb \
49-
-q \
50-
-ex 'add-auto-load-safe-path $(pwd)' \
51-
-ex 'file vmlinux' \
52-
-ex 'set arch i386:x86-64:intel' \
53-
-ex 'target remote localhost:1234' \
54-
$brk \
55-
-ex 'continue' \
56-
-ex 'disconnect' \
57-
-ex 'set arch i386:x86-64' \
58-
-ex 'target remote localhost:1234' \
59-
-ex 'lx-symbols ../kernel_module-1.0/' \
60-
"
46+
-q \
47+
-ex 'add-auto-load-safe-path $(pwd)' \
48+
-ex 'file vmlinux' \
49+
-ex 'set arch i386:x86-64:intel' \
50+
-ex 'target remote localhost:1234' \
51+
$brk \
52+
-ex 'continue' \
53+
-ex 'disconnect' \
54+
-ex 'set arch i386:x86-64' \
55+
-ex 'target remote localhost:1234' \
56+
-ex 'lx-symbols ../kernel_module-1.0/' \
57+
"
6158
;;
6259
'arm'|'aarch64'|'mips64')
6360
cmd="$gdb \
64-
-q \
65-
-ex 'add-auto-load-safe-path $(pwd)' \
66-
-ex 'file vmlinux' \
67-
-ex 'target remote localhost:1234' \
68-
-ex 'lx-symbols ../kernel_module-1.0/' \
69-
$brk \
70-
"
61+
-q \
62+
-ex 'add-auto-load-safe-path $(pwd)' \
63+
-ex 'file vmlinux' \
64+
-ex 'target remote localhost:1234' \
65+
-ex 'lx-symbols ../kernel_module-1.0/' \
66+
$brk \
67+
"
7168
;;
7269
esac
7370
fi

0 commit comments

Comments
 (0)