QtBase  v6.3.1
debug_script.py
Go to the documentation of this file.
1 
28 
29 import os
30 import sys
31 import imp
32 
33 from distutils.version import LooseVersion
34 
35 MODULE_NAME = 'qt'
36 
37 def import_bridge(path, debugger, session_dict, reload_module=False):
38  if not reload_module and MODULE_NAME in sys.modules:
39  del sys.modules[MODULE_NAME]
40 
41  if sys.version_info[0] >= 3:
42  sys.path.append(os.path.dirname(path))
43  bridge = imp.load_source(MODULE_NAME, path)
44 
45  if not hasattr(bridge, '__lldb_init_module'):
46  return None
47 
48  # Make available for the current LLDB session, so that LLDB
49  # can find the functions when initializing the module.
50  session_dict[MODULE_NAME] = bridge
51 
52  # Initialize the module now that it's available globally
53  bridge.__lldb_init_module(debugger, session_dict)
54 
55  if not debugger.GetCategory('Qt'):
56  # Summary provider failed for some reason
57  del session_dict[MODULE_NAME]
58  return None
59 
60  return bridge
61 
62 def report_success(bridge):
63  print("Using Qt summary providers from Creator {} in '{}'".format(
64  bridge.CREATOR_VERSION, bridge.CREATOR_PATH))
65 
66 def __lldb_init_module(debugger, session_dict):
67  # Check if the module has already been imported globally. This ensures
68  # that the Qt Creator application search is only performed once per
69  # LLDB process invocation, while still reloading for each session.
70  if MODULE_NAME in sys.modules:
71  module = sys.modules[MODULE_NAME]
72  # Reload module for this sessions
73  bridge = import_bridge(module.__file__, debugger, session_dict,
74  reload_module = True)
75  if bridge:
76  report_success(bridge)
77  return
78 
79  versions = {}
80  for install in os.popen(
81  'mdfind kMDItemCFBundleIdentifier=org.qt-project.qtcreator'
82  '| while read p;'
83  'do echo $p=$(mdls "$p" -name kMDItemVersion -raw);'
84  'done'):
85  install = install.strip()
86  (p, v) = install.split('=')
87  versions[v] = p
88 
89  for version in sorted(versions, key=LooseVersion, reverse=True):
90  path = versions[version]
91 
92  bridge_path = '{}/Contents/Resources/debugger/lldbbridge.py'.format(path)
93  bridge = import_bridge(bridge_path, debugger, session_dict)
94  if bridge:
95  bridge.CREATOR_VERSION = version
96  bridge.CREATOR_PATH = path
97  report_success(bridge)
98  return
99 
100  print("Could not find Qt Creator installation, no Qt summary providers installed")
def report_success(bridge)
Definition: debug_script.py:62
def import_bridge(path, debugger, session_dict, reload_module=False)
Definition: debug_script.py:37
C sorted(C c)