mirror of
https://github.com/cirosantilli/linux-kernel-module-cheat.git
synced 2026-01-23 02:05:57 +01:00
remove some more kernel_module- references
make kgdb x86_64 work once again, now pending a decent serial refactor
This commit is contained in:
@@ -1317,7 +1317,7 @@ Useless, but a good way to show how hardcore you are. Disable `lx-symbols` with:
|
|||||||
From inside guest:
|
From inside guest:
|
||||||
|
|
||||||
....
|
....
|
||||||
insmod /fops.ko
|
insmod /timer.ko
|
||||||
cat /proc/modules
|
cat /proc/modules
|
||||||
....
|
....
|
||||||
|
|
||||||
@@ -1336,7 +1336,8 @@ And then tell GDB where the module was loaded with:
|
|||||||
|
|
||||||
....
|
....
|
||||||
Ctrl-C
|
Ctrl-C
|
||||||
add-symbol-file ../kernel_modules-1.0/fops.ko 0xfffffffa00000000
|
add-symbol-file ../../../rootfs_overlay/x86_64/timer.ko 0xffffffffc0000000
|
||||||
|
0xffffffffc0000000
|
||||||
....
|
....
|
||||||
|
|
||||||
Alternatively, if the module panics before you can read `/proc/modules`, there is a <<pr_debug>> which shows the load address:
|
Alternatively, if the module panics before you can read `/proc/modules`, there is a <<pr_debug>> which shows the load address:
|
||||||
@@ -1353,6 +1354,8 @@ And then search for a line of type:
|
|||||||
[ 84.877482] 0xfffffffa00000000 .text
|
[ 84.877482] 0xfffffffa00000000 .text
|
||||||
....
|
....
|
||||||
|
|
||||||
|
Tested on 4f4749148273c282e80b58c59db1b47049e190bf + 1.
|
||||||
|
|
||||||
=== GDB step debug early boot
|
=== GDB step debug early boot
|
||||||
|
|
||||||
TODO sucessfully debu the very first instruction that the Linux kernel runs, before `start_kernel`!
|
TODO sucessfully debu the very first instruction that the Linux kernel runs, before `start_kernel`!
|
||||||
@@ -1834,8 +1837,6 @@ Bibliography:
|
|||||||
|
|
||||||
== KGDB
|
== KGDB
|
||||||
|
|
||||||
TODO: only working with <<qemu-graphic-mode>>. Without it, nothing shows on the terminal. So likely something linked to the option `console=ttyS0`.
|
|
||||||
|
|
||||||
KGDB is kernel dark magic that allows you to GDB the kernel on real hardware without any extra hardware support.
|
KGDB is kernel dark magic that allows you to GDB the kernel on real hardware without any extra hardware support.
|
||||||
|
|
||||||
It is useless with QEMU since we already have full system visibility with `-gdb`, but this is a good way to learn it.
|
It is useless with QEMU since we already have full system visibility with `-gdb`, but this is a good way to learn it.
|
||||||
|
|||||||
@@ -823,6 +823,7 @@ def setup(parser):
|
|||||||
this_module.qemu_hostfwd_generic_port = this_module.qemu_base_port + 1
|
this_module.qemu_hostfwd_generic_port = this_module.qemu_base_port + 1
|
||||||
this_module.qemu_hostfwd_ssh_port = this_module.qemu_base_port + 2
|
this_module.qemu_hostfwd_ssh_port = this_module.qemu_base_port + 2
|
||||||
this_module.qemu_gdb_port = this_module.qemu_base_port + 3
|
this_module.qemu_gdb_port = this_module.qemu_base_port + 3
|
||||||
|
this_module.extra_serial_port = this_module.qemu_base_port + 4
|
||||||
this_module.gdb_port = this_module.qemu_gdb_port
|
this_module.gdb_port = this_module.qemu_gdb_port
|
||||||
|
|
||||||
# Baremetal.
|
# Baremetal.
|
||||||
|
|||||||
9
run
9
run
@@ -83,6 +83,8 @@ def main(args, extra_args=None):
|
|||||||
if not args.graphic:
|
if not args.graphic:
|
||||||
if args.arch == 'x86_64':
|
if args.arch == 'x86_64':
|
||||||
kernel_cli += ' console=ttyS0'
|
kernel_cli += ' console=ttyS0'
|
||||||
|
else:
|
||||||
|
kernel_cli += ' console=ttyAMA0'
|
||||||
extra_qemu_args.append('-nographic')
|
extra_qemu_args.append('-nographic')
|
||||||
if kernel_cli_after_dash:
|
if kernel_cli_after_dash:
|
||||||
kernel_cli += " -{}".format(kernel_cli_after_dash)
|
kernel_cli += " -{}".format(kernel_cli_after_dash)
|
||||||
@@ -159,7 +161,7 @@ def main(args, extra_args=None):
|
|||||||
if args.arch == 'x86_64':
|
if args.arch == 'x86_64':
|
||||||
if args.kvm:
|
if args.kvm:
|
||||||
cmd.extend(['--cpu-type', 'X86KvmCPU'])
|
cmd.extend(['--cpu-type', 'X86KvmCPU'])
|
||||||
cmd.extend(['--command-line', 'earlyprintk=ttyS0 console=ttyS0 lpj=7999923 root=/dev/sda {}'.format(kernel_cli)])
|
cmd.extend(['--command-line', 'earlyprintk=ttyS0 lpj=7999923 root=/dev/sda {}'.format(kernel_cli)])
|
||||||
elif args.arch == 'arm' or args.arch == 'aarch64':
|
elif args.arch == 'arm' or args.arch == 'aarch64':
|
||||||
# TODO why is it mandatory to pass mem= here? Not true for QEMU.
|
# TODO why is it mandatory to pass mem= here? Not true for QEMU.
|
||||||
# Anything smaller than physical blows up as expected, but why can't it auto-detect the right value?
|
# Anything smaller than physical blows up as expected, but why can't it auto-detect the right value?
|
||||||
@@ -232,8 +234,7 @@ def main(args, extra_args=None):
|
|||||||
serial_monitor = ['-serial', 'mon:stdio']
|
serial_monitor = ['-serial', 'mon:stdio']
|
||||||
if args.kvm:
|
if args.kvm:
|
||||||
extra_emulator_args.append('-enable-kvm')
|
extra_emulator_args.append('-enable-kvm')
|
||||||
if args.kgdb:
|
extra_emulator_args.extend(['-serial', 'tcp::{},server,nowait'.format(common.extra_serial_port)])
|
||||||
extra_emulator_args.extend(['-serial', 'tcp::{},server,nowait'.format(common.gdb_port)])
|
|
||||||
cmd.extend(
|
cmd.extend(
|
||||||
[
|
[
|
||||||
qemu_executable,
|
qemu_executable,
|
||||||
@@ -295,7 +296,7 @@ def main(args, extra_args=None):
|
|||||||
virtio_gpu_pci = ['-device', 'virtio-gpu-pci']
|
virtio_gpu_pci = ['-device', 'virtio-gpu-pci']
|
||||||
if args.arch == 'x86_64':
|
if args.arch == 'x86_64':
|
||||||
if args.kgdb:
|
if args.kgdb:
|
||||||
kernel_cli += ' kgdboc=ttyS0,115200'
|
kernel_cli += ' kgdboc=ttyS1,115200'
|
||||||
append = ['-append', '{} nopat {}'.format(root, kernel_cli)]
|
append = ['-append', '{} nopat {}'.format(root, kernel_cli)]
|
||||||
cmd.extend([
|
cmd.extend([
|
||||||
'-M', common.machine,
|
'-M', common.machine,
|
||||||
|
|||||||
15
run-gdb
15
run-gdb
@@ -60,7 +60,11 @@ def main(args, extra_args=None):
|
|||||||
if args.sim:
|
if args.sim:
|
||||||
target = 'sim'
|
target = 'sim'
|
||||||
else:
|
else:
|
||||||
target = 'remote localhost:{}'.format(common.gdb_port)
|
if args.kgdb:
|
||||||
|
port = common.extra_serial_port
|
||||||
|
else:
|
||||||
|
port = common.gdb_port
|
||||||
|
target = 'remote localhost:{}'.format(port)
|
||||||
cmd.extend([
|
cmd.extend([
|
||||||
'-ex', 'file {}'.format(image),
|
'-ex', 'file {}'.format(image),
|
||||||
'-ex', 'target {}'.format(target),
|
'-ex', 'target {}'.format(target),
|
||||||
@@ -91,7 +95,14 @@ def main(args, extra_args=None):
|
|||||||
if not args.no_lxsymbols and linux_full_system:
|
if not args.no_lxsymbols and linux_full_system:
|
||||||
cmd.extend(['-ex', 'lx-symbols {}'.format(common.kernel_modules_build_subdir)])
|
cmd.extend(['-ex', 'lx-symbols {}'.format(common.kernel_modules_build_subdir)])
|
||||||
cmd.extend(after)
|
cmd.extend(after)
|
||||||
return common.run_cmd(cmd, cmd_file=os.path.join(common.run_dir, 'run-gdb.sh'), cwd=common.linux_build_dir)
|
# I would rather have cwd be out_rootfs_overlay_dir,
|
||||||
|
# but then lx-symbols cannot fine the vmlinux and fails with:
|
||||||
|
# vmlinux: No such file or directory.
|
||||||
|
return common.run_cmd(
|
||||||
|
cmd,
|
||||||
|
cmd_file=os.path.join(common.run_dir, 'run-gdb.sh'),
|
||||||
|
cwd=common.linux_build_dir
|
||||||
|
)
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
parser = common.get_argparse(argparse_args={'description': 'Connect with GDB to an emulator to debug Linux itself'})
|
parser = common.get_argparse(argparse_args={'description': 'Connect with GDB to an emulator to debug Linux itself'})
|
||||||
|
|||||||
Reference in New Issue
Block a user