提交 bf201a18 编写于 作者: L Lucas Meneghel Rodrigues

Merge pull request #266 from clebergnu/gdb_path_v2

GDB: support for setting gdb/gdbserver paths [v2]
......@@ -165,16 +165,19 @@ class GDB(object):
Wraps a GDB subprocess for easier manipulation
"""
GDB_PATH = '/usr/bin/gdb'
GDB_ARGS = [GDB_PATH,
'--interpreter=mi',
'--quiet']
REQUIRED_ARGS = ['--interpreter=mi',
'--quiet']
DEFAULT_BREAK = 'main'
def __init__(self):
self.process = subprocess.Popen(self.GDB_ARGS,
def __init__(self, path='/usr/bin/gdb', *extra_args):
self.path = path
args = [self.path]
args += self.REQUIRED_ARGS
args += extra_args
self.process = subprocess.Popen(args,
stdin=subprocess.PIPE,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
......@@ -443,14 +446,22 @@ class GDBServer(object):
"""
#: The default arguments used when starting the GDB server process
ARGS = ['/usr/bin/gdbserver',
'--multi']
REQUIRED_ARGS = ['--multi']
#: The range from which a port to GDB server will try to be allocated from
PORT_RANGE = (20000, 20999)
def __init__(self):
self.port = network.find_free_port(*self.PORT_RANGE)
def __init__(self, path='/usr/bin/gdbserver', port=None, *extra_args):
self.path = path
args = [self.path]
args += self.REQUIRED_ARGS
if port is None:
self.port = network.find_free_port(*self.PORT_RANGE)
else:
self.port = port
args.append(":%s" % self.port)
prefix = 'avocado_gdbserver_%s_' % self.port
_, self.stdout_path = tempfile.mkstemp(prefix=prefix + 'stdout_')
......@@ -458,8 +469,6 @@ class GDBServer(object):
_, self.stderr_path = tempfile.mkstemp(prefix=prefix + 'stderr_')
self.stderr = open(self.stderr_path, 'w')
args = self.ARGS[:]
args.append(":%s" % self.port)
self.process = subprocess.Popen(args,
stdin=subprocess.PIPE,
stdout=self.stdout,
......
......@@ -15,6 +15,7 @@
"""Run tests with GDB goodies enabled."""
from avocado import runtime
from avocado.utils import process
from avocado.plugins import plugin
......@@ -43,6 +44,28 @@ class GDB(plugin.Plugin):
' inferior process received a fatal signal '
'such as SIGSEGV or SIGABRT'))
default_gdb_path = '/usr/bin/gdb'
try:
system_gdb_path = process.find_command('gdb')
except process.CmdNotFoundError:
system_gdb_path = default_gdb_path
gdb_grp.add_argument('--gdb-path',
default=system_gdb_path, metavar='PATH',
help=('Path to the GDB executable, should you '
'need to use a custom GDB version. Defaults '
'to "%(default)s"'))
default_gdbserver_path = '/usr/bin/gdbserver'
try:
system_gdbserver_path = process.find_command('gdbserver')
except process.CmdNotFoundError:
system_gdbserver_path = default_gdbserver_path
gdb_grp.add_argument('--gdbserver-path',
default=system_gdbserver_path, metavar='PATH',
help=('Path to the gdbserver executable, should you '
'need to use a custom version. Defaults '
'to "%(default)s"'))
self.configured = True
def activate(self, app_args):
......@@ -51,5 +74,7 @@ class GDB(plugin.Plugin):
runtime.GDB_RUN_BINARY_NAMES_EXPR.append(binary)
if app_args.gdb_enable_core:
runtime.GDB_ENABLE_CORE = True
runtime.GDB_PATH = app_args.gdb_path
runtime.GDBSERVER_PATH = app_args.gdbserver_path
except AttributeError:
pass
......@@ -25,6 +25,12 @@ GDB_RUN_BINARY_NAMES_EXPR = []
#: that are run inside the GNU debugger
GDB_ENABLE_CORE = False
#: Path to the GDB binary
GDB_PATH = None
#: Path to the gdbserver binary
GDBSERVER_PATH = None
#: Sometimes it's useful for the framework and API to know about the test that
#: is currently running, if one exists
CURRENT_TEST = None
......@@ -553,8 +553,8 @@ class GDBSubProcess(object):
self.binary_path = os.path.abspath(self.cmd)
self.result = CmdResult(cmd)
self.gdb_server = gdb.GDBServer()
self.gdb = gdb.GDB()
self.gdb_server = gdb.GDBServer(runtime.GDBSERVER_PATH)
self.gdb = gdb.GDB(runtime.GDB_PATH)
self.gdb.connect(self.gdb_server.port)
self.gdb.set_file(self.binary)
......@@ -615,7 +615,7 @@ class GDBSubProcess(object):
script = open(script_path, 'w')
script.write("#!/bin/sh\n")
script.write("%s -x %s\n" % (gdb.GDB.GDB_PATH, cmds))
script.write("%s -x %s\n" % (runtime.GDB_PATH, cmds))
script.write("echo -n 'C' > %s\n" % fifo_path)
script.close()
os.chmod(script_path, stat.S_IRUSR | stat.S_IWUSR | stat.S_IXUSR)
......
......@@ -286,6 +286,16 @@ while you are debugging it, avocado has no way to know about its status.
Avocado will automatically send a `continue` command to the debugger
when you disconnect from and exit gdb.
If, for some reason you have a custom GDB, or your system does not put
GDB on what avocado believes to be the standard location (`/usr/bin/gdb`),
you can override that with::
$ avocado run --gdb-path=~/code/gdb/gdb --gdb-run-bin=foo:main footest
The same applies to `gdbserver`, which can be chosen with a command line like::
$ avocado run --gdbserver-path=~/code/gdb/gdbserver --gdb-run-bin=foo:main footest
RECORDING TEST REFERENCE OUTPUT
===============================
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册