]> git.saurik.com Git - apple/xnu.git/blob - tools/lldbmacros/core/xnu_lldb_init.py
b518246449066b8ab5ec238c2288c5e68d477c80
[apple/xnu.git] / tools / lldbmacros / core / xnu_lldb_init.py
1 import os
2
3 def GetSettingsValues(debugger, setting_variable_name):
4 """ Queries the lldb internal settings
5 params:
6 debugger : lldb.SBDebugger instance
7 setting_variable_name: str - string name of the setting(eg prompt)
8 returns:
9 [] : Array of strings. Empty array if setting is not found/set
10 """
11 retval = []
12 settings_val_list = debugger.GetInternalVariableValue(setting_variable_name, debugger.GetInstanceName())
13 for s in settings_val_list:
14 retval.append(str(s))
15 return retval
16
17 def __lldb_init_module(debugger, internal_dict):
18 debug_session_enabled = False
19 if "DEBUG_XNU_LLDBMACROS" in os.environ and len(os.environ['DEBUG_XNU_LLDBMACROS']) > 0:
20 debug_session_enabled = True
21 prev_os_plugin = "".join(GetSettingsValues(debugger, 'target.process.python-os-plugin-path'))
22 print "Loading kernel debugging from %s" % __file__
23 print "LLDB version %s" % debugger.GetVersionString()
24 self_path = str(__file__)
25 base_dir_name = self_path[:self_path.rfind("/")]
26 core_os_plugin = base_dir_name + "/lldbmacros/core/operating_system.py"
27 osplugin_cmd = "settings set target.process.python-os-plugin-path \"%s\"" % core_os_plugin
28 intel_whitelist = ['hndl_allintrs', 'hndl_alltraps', 'trap_from_kernel', 'hndl_double_fault', 'hndl_machine_check']
29 arm_whitelist = ['_fleh_prefabt', '_ExceptionVectorsBase', '_ExceptionVectorsTable', '_fleh_undef', '_fleh_dataabt', '_fleh_irq', '_fleh_decirq', '_fleh_fiq_generic', '_fleh_dec']
30 whitelist_trap_cmd = "settings set target.trap-handler-names %s %s" % (' '.join(intel_whitelist), ' '.join(arm_whitelist))
31 xnu_debug_path = base_dir_name + "/lldbmacros/xnu.py"
32 xnu_load_cmd = "command script import \"%s\"" % xnu_debug_path
33 if debug_session_enabled :
34 if len(prev_os_plugin) > 0:
35 print "\nDEBUG_XNU_LLDBMACROS is set. Skipping the setting of OS plugin from dSYM.\nYou can manually set the OS plugin by running\n" + osplugin_cmd
36 else:
37 print osplugin_cmd
38 debugger.HandleCommand(osplugin_cmd)
39 print "\nDEBUG_XNU_LLDBMACROS is set. Skipping the load of xnu debug framework.\nYou can manually load the framework by running\n" + xnu_load_cmd
40 else:
41 print osplugin_cmd
42 debugger.HandleCommand(osplugin_cmd)
43 print whitelist_trap_cmd
44 debugger.HandleCommand(whitelist_trap_cmd)
45 print xnu_load_cmd
46 debugger.HandleCommand(xnu_load_cmd)
47 print "\n"
48