From 911dd8be329f1b1f7b4a7c1384e766903495872b 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: Wed, 31 Oct 2018 00:00:00 +0000 Subject: [PATCH] remove some more kernel_module- references make kgdb x86_64 work once again, now pending a decent serial refactor --- README.adoc | 9 +++++---- common.py | 1 + run | 9 +++++---- run-gdb | 15 +++++++++++++-- 4 files changed, 24 insertions(+), 10 deletions(-) diff --git a/README.adoc b/README.adoc index e964230..cd86942 100644 --- a/README.adoc +++ b/README.adoc @@ -1317,7 +1317,7 @@ Useless, but a good way to show how hardcore you are. Disable `lx-symbols` with: From inside guest: .... -insmod /fops.ko +insmod /timer.ko cat /proc/modules .... @@ -1336,7 +1336,8 @@ And then tell GDB where the module was loaded with: .... 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 <> which shows the load address: @@ -1353,6 +1354,8 @@ And then search for a line of type: [ 84.877482] 0xfffffffa00000000 .text .... +Tested on 4f4749148273c282e80b58c59db1b47049e190bf + 1. + === GDB step debug early boot TODO sucessfully debu the very first instruction that the Linux kernel runs, before `start_kernel`! @@ -1834,8 +1837,6 @@ Bibliography: == KGDB -TODO: only working with <>. 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. It is useless with QEMU since we already have full system visibility with `-gdb`, but this is a good way to learn it. diff --git a/common.py b/common.py index eab4ae4..5b1b369 100644 --- a/common.py +++ b/common.py @@ -823,6 +823,7 @@ def setup(parser): 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_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 # Baremetal. diff --git a/run b/run index 474ee7c..ad8a652 100755 --- a/run +++ b/run @@ -83,6 +83,8 @@ def main(args, extra_args=None): if not args.graphic: if args.arch == 'x86_64': kernel_cli += ' console=ttyS0' + else: + kernel_cli += ' console=ttyAMA0' extra_qemu_args.append('-nographic') if 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.kvm: 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': # 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? @@ -232,8 +234,7 @@ def main(args, extra_args=None): serial_monitor = ['-serial', 'mon:stdio'] if args.kvm: extra_emulator_args.append('-enable-kvm') - if args.kgdb: - extra_emulator_args.extend(['-serial', 'tcp::{},server,nowait'.format(common.gdb_port)]) + extra_emulator_args.extend(['-serial', 'tcp::{},server,nowait'.format(common.extra_serial_port)]) cmd.extend( [ qemu_executable, @@ -295,7 +296,7 @@ def main(args, extra_args=None): virtio_gpu_pci = ['-device', 'virtio-gpu-pci'] if args.arch == 'x86_64': if args.kgdb: - kernel_cli += ' kgdboc=ttyS0,115200' + kernel_cli += ' kgdboc=ttyS1,115200' append = ['-append', '{} nopat {}'.format(root, kernel_cli)] cmd.extend([ '-M', common.machine, diff --git a/run-gdb b/run-gdb index 5b1e653..9433939 100755 --- a/run-gdb +++ b/run-gdb @@ -60,7 +60,11 @@ def main(args, extra_args=None): if args.sim: target = 'sim' 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([ '-ex', 'file {}'.format(image), '-ex', 'target {}'.format(target), @@ -91,7 +95,14 @@ def main(args, extra_args=None): if not args.no_lxsymbols and linux_full_system: cmd.extend(['-ex', 'lx-symbols {}'.format(common.kernel_modules_build_subdir)]) 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__': parser = common.get_argparse(argparse_args={'description': 'Connect with GDB to an emulator to debug Linux itself'})