Make run_python_code_linux quote safe
@@ -266,9 +266,17 @@ def _win_write_to_shared_named_memory(python_code, pid):
finally:
CloseHandle(filemap)
+def escape_for_gdb_and_lldb(s):
+ """Returns a version of given string suitable for use as gdb
+ and lldb function argument"""
+ if not s:
+ return '""'
+
+ # wrap string in double qoutes, and escape any inner double
+ # quotes
+ return '"' + s.replace('"', '\\"') + '"'
def run_python_code_linux(pid, python_code, connect_debugger_tracing=False, show_debug_info=0):
- assert '\'' not in python_code, 'Having a single quote messes with our command.'
filedir = os.path.dirname(__file__)
# Valid arguments for arch are i386, i386:x86-64, i386:x64-32, i8086,
@@ -304,14 +312,14 @@ def run_python_code_linux(pid, python_code, connect_debugger_tracing=False, show
# '--batch-silent',
]
- cmd.extend(["--eval-command='set scheduler-locking off'"]) # If on we'll deadlock.
+ cmd.extend(["--eval-command=set scheduler-locking off"]) # If on we'll deadlock.
- cmd.extend(["--eval-command='set architecture %s'" % arch])
+ cmd.extend(["--eval-command=set architecture %s" % arch])
cmd.extend([
- "--eval-command='call (void*)dlopen(\"%s\", 2)'" % target_dll,
- "--eval-command='call (int)DoAttach(%s, \"%s\", %s)'" % (
- is_debug, python_code, show_debug_info)
+ "--eval-command=call (void*)dlopen(\"%s\", 2)" % target_dll,
+ '--eval-command=call (int)DoAttach(%s, %s, %s)' % (
+ is_debug, escape_for_gdb_and_lldb(python_code), show_debug_info)
])
# print ' '.join(cmd)
@@ -323,8 +331,7 @@ def run_python_code_linux(pid, python_code, connect_debugger_tracing=False, show
env.pop('PYTHONPATH', None)
print('Running: %s' % (' '.join(cmd)))
p = subprocess.Popen(
- ' '.join(cmd),
- shell=True,
+ cmd,
env=env,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
