Files
linux-kernel-module-cheat/run-gdb
Ciro Santilli 六四事件 法轮功 74b51fc044 gem5: update to 7bfb7f3a43f382eb49853f47b140bfd6caad0fb8
The update is required to include 3c3ca64b5f0dd9eef7b1ce1c65cc6e8e9147dd38
otherwise baremetal does not on VExpress.

baremetal: create a baremetal setup with crosstool-ng

buildroot: improve directory location: move out/dl inside
out/buildroot/download, and add a new out/buildroot/build level

tagline: generalize, deliver more value than howto, since now howtos
are starting to multiply

rename all top scripts to separate words with hyphen more consistently,
e.g. run-gdb instead of rungdb

getvar: list all variables

gem5: make m5out section to focus all releated information at

Prevent m5term Text file busy when rebuilding gem5 while it is running.
2018-09-23 13:56:20 +01:00

122 lines
4.0 KiB
Python
Executable File

#!/usr/bin/env python3
import os
import shlex
import sys
import signal
import subprocess
import common
defaults = {
'after': '',
'before': '',
'sim': False,
'no_continue': False,
'kgdb': False,
'no_lxsymbols': False,
'break_at': None,
}
def main(args, extra_args=None):
'''
:param args: argparse parse_argument() output. Must contain all the common options,
but does not need GDB specific ones.
:type args: argparse.Namespace
:param extra_args: extra arguments to be added to args
:type extra_args: Dict[str,Any]
:return: GDB exit status
:rtype: int
'''
global defaults
args = common.resolve_args(defaults, args, extra_args)
after = shlex.split(args.after)
before = shlex.split(args.before)
if args.no_lxsymbols or args.baremetal is not None:
lx_symbols = []
else:
lx_symbols = ['-ex', 'lx-symbols ../kernel_modules-1.0/']
if args.break_at is not None:
break_at = ['-ex', 'break {}'.format(args.break_at)]
else:
break_at = []
if args.baremetal is None:
image = common.vmlinux
else:
image = common.image
cmd = (
[common.get_toolchain_tool('gdb')] +
before +
['-q']
)
if args.baremetal is None:
cmd.extend(['-ex', 'add-auto-load-safe-path {}'.format(common.linux_variant_dir)])
if args.sim:
target = 'sim'
else:
target = 'remote localhost:{}'.format(common.gdb_port)
cmd.extend([
'-ex', 'file {}'.format(image),
'-ex', 'target {}'.format(target),
])
if not args.kgdb:
cmd.extend(break_at)
if not args.no_continue:
# ## lx-symbols
#
# ### lx-symbols after continue
#
# lx symbols must be run after continue.
#
# running it immediately after the connect on the bootloader leads to failure,
# likely because kernel structure on which it depends are not yet available.
#
# With this setup, continue runs, and lx-symbols only runs when a break happens,
# either by hitting the breakpoint, or by entering Ctrl + C.
#
# Sure, if the user sets a break on a raw address of the bootloader,
# problems will still arise, but let's think about that some other time.
#
# ### lx-symbols autoload
#
# The lx-symbols commands gets loaded through the file vmlinux-gdb.py
# which gets put on the kernel build root when python debugging scripts are enabled.
cmd.extend(['-ex', 'continue'] + lx_symbols)
cmd.extend(after)
return common.run_cmd(cmd, cmd_file=os.path.join(common.run_dir, 'run-gdb.sh'), cwd=common.linux_variant_dir)
if __name__ == '__main__':
parser = common.get_argparse(argparse_args={'description': 'Connect with GDB to an emulator to debug Linux itself'})
parser.add_argument(
'-A', '--after', default=defaults['after'],
help='Pass extra arguments to GDB, to be appended after all other arguments'
)
parser.add_argument(
'-b', '--before', default=defaults['before'],
help='Pass extra arguments to GDB to be prepended before any of the arguments passed by this script'
)
parser.add_argument(
'-C', '--no-continue', default=defaults['no_continue'], action='store_true',
help="Don't run continue after connecting"
)
parser.add_argument(
'-k', '--kgdb', default=defaults['kgdb'], action='store_true'
)
parser.add_argument(
'--sim', default=defaults['sim'], action='store_true',
help='''Use the built-in GDB CPU simulator
See: https://github.com/cirosantilli/linux-kernel-module-cheat#gdb-builtin-cpu-simulator
'''
)
parser.add_argument(
'-X', '--no-lxsymbols', default=defaults['no_lxsymbols'], action='store_true'
)
parser.add_argument(
'break_at', nargs='?',
help='Extra options to append at the end of the emulator command line'
)
args = common.setup(parser)
sys.exit(main(args))