Execute settrace only for process threads in lldb (PY-14247).

This commit is contained in:
Dmitry Trofimov
2014-10-28 23:58:48 +01:00
parent 2bc78df638
commit 3c8313f95f
3 changed files with 35 additions and 16 deletions
@@ -418,10 +418,7 @@ def run_python_code_linux(pid, python_code, connect_debugger_tracing=False, show
if not os.path.exists(target_dll):
raise RuntimeError('Could not find dll file to inject: %s' % target_dll)
gdb_threads_settrace_file = os.path.join(filedir, 'linux', 'gdb_threads_settrace.py')
gdb_threads_settrace_file = os.path.normpath(gdb_threads_settrace_file)
if not os.path.exists(gdb_threads_settrace_file):
raise RuntimeError('Could not find file to settrace: %s' % gdb_threads_settrace_file)
gdb_threads_settrace_file = find_helper_script(filedir, 'gdb_threads_settrace.py')
# Note: we currently don't support debug builds
is_debug = 0
@@ -476,6 +473,15 @@ def run_python_code_linux(pid, python_code, connect_debugger_tracing=False, show
return out, err
def find_helper_script(filedir, script_name):
lldb_threads_settrace_file = os.path.join(filedir, 'linux', script_name)
lldb_threads_settrace_file = os.path.normpath(lldb_threads_settrace_file)
if not os.path.exists(lldb_threads_settrace_file):
raise RuntimeError('Could not find file to settrace: %s' % lldb_threads_settrace_file)
return lldb_threads_settrace_file
def run_python_code_mac(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__)
@@ -498,12 +504,10 @@ def run_python_code_mac(pid, python_code, connect_debugger_tracing=False, show_d
if not os.path.exists(target_dll):
raise RuntimeError('Could not find dll file to inject: %s' % target_dll)
lldb_threads_settrace_file = os.path.join(filedir, 'linux', 'lldb_threads_settrace.py')
lldb_threads_settrace_file = os.path.normpath(lldb_threads_settrace_file)
if not os.path.exists(lldb_threads_settrace_file):
raise RuntimeError('Could not find file to settrace: %s' % lldb_threads_settrace_file)
lldb_threads_settrace_file = find_helper_script(filedir, 'lldb_threads_settrace.py')
lldb_threads_prepare_file = find_helper_script(filedir, 'lldb_threads_prepare.py')
# Note: we currently don't support debug builds
is_debug = 0
# Note that the space in the beginning of each line in the multi-line is important!
cmd = [
@@ -521,8 +525,9 @@ def run_python_code_mac(pid, python_code, connect_debugger_tracing=False, show_d
cmd.extend([
"-o 'process attach --pid %d'"%pid,
"-o 'command script import \'%s\''" % (lldb_threads_prepare_file,),
"-o 'expr (void*)dlopen(\"%s\", 2);'" % target_dll,
"-o 'expr (int)hello();'",
# "-o 'expr (int)hello();'",
"-o 'expr (int)DoAttach(%s, \"%s\", %s);'" % (
is_debug, python_code, show_debug_info),
])
@@ -0,0 +1,17 @@
# This file is meant to be run inside lldb as a command before
# attaching the debugger to mark process threads as suspended
# to distinguish them from debugger threads later
def __lldb_init_module(debugger, internal_dict):
import lldb
try:
target = debugger.GetSelectedTarget()
if target:
process = target.GetProcess()
if process:
for thread in process:
internal_dict['_thread_%d' % thread.GetThreadID()] = True
# thread.Suspend()
except:
import traceback;traceback.print_exc()
@@ -15,14 +15,11 @@ def __lldb_init_module(debugger, internal_dict):
for thread in process:
# Get the first frame
print('Thread %s, suspended %s\n'%(thread, thread.IsStopped()))
print(thread.GetName())
process.SetSelectedThread(thread)
if not thread.IsStopped():
error = process.Stop()
print(error)
if thread:
if getattr(internal_dict, '_thread_%d' % thread.GetThreadID(), False):
frame = thread.GetSelectedFrame()
if frame:
print('Will settrace in: %s' % (frame,))
@@ -31,6 +28,6 @@ def __lldb_init_module(debugger, internal_dict):
error = res.GetError()
if error:
print(error)
thread.Resume()
thread.Resume()
except:
import traceback;traceback.print_exc()