Skip to content

Commit

Permalink
[Dexter] Add target_run_args option
Browse files Browse the repository at this point in the history
Adds an option to Dexter that passes command line arguments to the
debugged process, following (and in addition to) any arguments given by
the DexCommandLine command.

Differential Revision: https://reviews.llvm.org/D144979
  • Loading branch information
SLTozer committed Mar 15, 2023
1 parent ade336d commit 2e7f339
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 1 deletion.
Expand Up @@ -114,6 +114,14 @@ def add_debugger_tool_arguments(parser, context, defaults):
action='store_true',
default=False,
help='pass the debugger paths relative to --source-root-dir')
parser.add_argument(
'--target-run-args',
type=str,
metavar='<flags>',
default='',
help='command line arguments for the test program, in addition to any '
'provided by DexCommandLine')


def handle_debugger_tool_base_options(context, defaults): # noqa
options = context.options
Expand Down
Expand Up @@ -96,7 +96,7 @@ def delete_breakpoints(self, ids):
raise NotImplementedError('delete_conditional_breakpoint is not yet implemented by dbgeng')

def launch(self, cmdline):
assert len(cmdline) == 0, "Command lines unimplemented for dbgeng right now"
assert len(cmdline) == 0 and not self.context.options.target_run_args, "Command lines unimplemented for dbgeng right now"
# We are, by this point, already launched.
self.step_info = probe_process.probe_state(self.client)

Expand Down
Expand Up @@ -9,6 +9,7 @@

import imp
import os
import shlex
from subprocess import CalledProcessError, check_output, STDOUT
import sys

Expand Down Expand Up @@ -171,6 +172,8 @@ def delete_breakpoints(self, ids):
self._target.BreakpointDelete(id)

def launch(self, cmdline):
if self.context.options.target_run_args:
cmdline += shlex.split(self.context.options.target_run_args)
self._process = self._target.LaunchSimple(cmdline, None, os.getcwd())
if not self._process or self._process.GetNumThreads() == 0:
raise DebuggerException('could not launch process')
Expand Down
Expand Up @@ -250,6 +250,8 @@ def _fetch_property(self, props, name):

def launch(self, cmdline):
cmdline_str = ' '.join(cmdline)
if self.context.options.target_run_args:
cmdline_str += f" {self.context.options.target_run_args}"

# In a slightly baroque manner, lookup the VS project that runs when
# you click "run", and set its command line options to the desired
Expand Down
@@ -0,0 +1,15 @@
// The dbgeng driver doesn't support --target-run-args yet.
// UNSUPPORTED: system-windows
//
// RUN: %dexter_regression_test --target-run-args "a b 'c d'" -- %s | FileCheck %s
// CHECK: target_run_args.c:

int main(int argc, const char **argv) {
if (argc == 4)
return 0; // DexLabel('retline')

return 1; // DexUnreachable()
}

// DexExpectWatchValue('argc', '4', on_line=ref('retline'))
// DexExpectWatchValue('argv[1][0]', "'a'", on_line=ref('retline'))
@@ -0,0 +1,16 @@
// The dbgeng driver doesn't support --target-run-args yet.
// UNSUPPORTED: system-windows
//
// RUN: %dexter_regression_test --target-run-args "a b 'c d'" -- %s | FileCheck %s
// CHECK: target_run_args_with_command.c:

int main(int argc, const char **argv) {
if (argc == 6)
return 0; // DexLabel('retline')

return 1; // DexUnreachable()
}

// DexCommandLine(['e', 'f'])
// DexExpectWatchValue('argc', '6', on_line=ref('retline'))
// DexExpectWatchValue('argv[1][0]', "'e'", on_line=ref('retline'))

0 comments on commit 2e7f339

Please sign in to comment.