Step through the <compiler-generated> functions via a stop hook in konan_lldb.py

^KT-63598
This commit is contained in:
Timofey Solonin
2023-11-22 13:25:02 +01:00
committed by Space Team
parent b83d8595e5
commit 04dec2769b
2 changed files with 310 additions and 0 deletions
@@ -627,6 +627,39 @@ class KonanStepOut(KonanStep):
return self.thread_plan.QueueThreadPlanForStepOut(0)
KONAN_LLDB_DONT_SKIP_BRIDGING_FUNCTIONS = 'KONAN_LLDB_DONT_SKIP_BRIDGING_FUNCTIONS'
MAX_SIZE_FOR_STOP_REASON = 20
PLAN_FROM_STOP_REASON = {
'step in' : KonanStepIn.__name__,
'step out' : KonanStepOut.__name__,
'step over' : KonanStepOver.__name__,
}
class KonanHook:
def __init__(self, target, extra_args, _):
pass
def handle_stop(self, execution_context, stream) -> bool:
is_bridging_functions_skip_enabled = not execution_context.target.GetEnvironment().Get(KONAN_LLDB_DONT_SKIP_BRIDGING_FUNCTIONS)
def is_kotlin_bridging_function() -> bool:
addr = execution_context.frame.addr
function_name = addr.function.name
if function_name is None:
return False
file_name = addr.line_entry.file.basename
if file_name is None:
return False
return function_name.startswith('objc2kotlin_') and file_name == '<compiler-generated>'
if is_bridging_functions_skip_enabled and is_kotlin_bridging_function():
stop_reason = execution_context.frame.thread.GetStopDescription(MAX_SIZE_FOR_STOP_REASON)
plan = PLAN_FROM_STOP_REASON.get(stop_reason)
if plan is not None:
execution_context.thread.StepUsingScriptedThreadPlan('{}.{}'.format(__name__, plan))
return True
def __lldb_init_module(debugger, _):
log(lambda: "init start")
__FACTORY['object'] = lambda x, y, z: KonanObjectSyntheticProvider(x, y, z)
@@ -652,4 +685,5 @@ def __lldb_init_module(debugger, _):
debugger.HandleCommand('command script add -f {}.symbol_by_name_command symbol_by_name'.format(__name__))
# Avoid Kotlin/Native runtime
debugger.HandleCommand('settings set target.process.thread.step-avoid-regexp ^::Kotlin_')
debugger.HandleCommand('target stop-hook add -P {}.KonanHook'.format(__name__))
log(lambda: "init end")