This commit is contained in:
Ciro Santilli
2018-09-04 07:39:27 +01:00
parent a6a712acef
commit 6ae0c43cf5
2 changed files with 30 additions and 6 deletions

29
rungdb
View File

@@ -1,5 +1,6 @@
#!/usr/bin/env python3
import copy
import os
import shlex
import sys
@@ -8,7 +9,29 @@ import subprocess
import common
def main(args):
defaults = {
'after': '',
'before': '',
'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]
"""
global defaults
if extra_args is None:
extra_args = {}
args = copy.copy(args)
args.__dict__ = dict(list(defaults.items()) + list(args.__dict__.items()) + list(extra_args.items()))
after = shlex.split(args.after)
before = shlex.split(args.before)
if args.no_lxsymbols:
@@ -61,11 +84,11 @@ def main(args):
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='',
'-A', '--after', default=defaults['after'],
help='Pass extra arguments to GDB, to be appended after all other arguments'
)
parser.add_argument(
'-b', '--before', default='',
'-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(

View File

@@ -36,10 +36,11 @@ for line in readelf_header.decode().split('\n'):
addr = line.split()[-1]
break
print(addr)
args.before = '-ex \"add-symbol-file {} {}\"'.format(args.executable, addr)
extra_args = {}
extra_args['before'] = '-ex \"add-symbol-file {} {}\"'.format(args.executable, addr)
# Or else lx-symbols throws for arm:
# gdb.MemoryError: Cannot access memory at address 0xbf0040cc
# TODO understand better.
# Also, lx-symbols overrides the add-symbol-file commands.
args.no_lxsymbols = True
rungdb.main(args)
extra_args['no_lxsymbols'] = True
rungdb.main(args, extra_args)