Qt 6.x
The Qt SDK
Loading...
Searching...
No Matches
debug_script.py
Go to the documentation of this file.
1# Copyright (C) 2017 The Qt Company Ltd.
2# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
3
4import os
5import sys
6import imp
7
8from distutils.version import LooseVersion
9
10MODULE_NAME = 'qt'
11
12def import_bridge(path, debugger, session_dict, reload_module=False):
13 if not reload_module and MODULE_NAME in sys.modules:
14 del sys.modules[MODULE_NAME]
15
16 if sys.version_info[0] >= 3:
17 sys.path.append(os.path.dirname(path))
18 bridge = imp.load_source(MODULE_NAME, path)
19
20 if not hasattr(bridge, '__lldb_init_module'):
21 return None
22
23 # Make available for the current LLDB session, so that LLDB
24 # can find the functions when initializing the module.
25 session_dict[MODULE_NAME] = bridge
26
27 # Initialize the module now that it's available globally
28 bridge.__lldb_init_module(debugger, session_dict)
29
30 if not debugger.GetCategory('Qt'):
31 # Summary provider failed for some reason
32 del session_dict[MODULE_NAME]
33 return None
34
35 return bridge
36
37def report_success(bridge):
38 print("Using Qt summary providers from Creator {} in '{}'".format(
39 bridge.CREATOR_VERSION, bridge.CREATOR_PATH))
40
41def __lldb_init_module(debugger, session_dict):
42 # Check if the module has already been imported globally. This ensures
43 # that the Qt Creator application search is only performed once per
44 # LLDB process invocation, while still reloading for each session.
45 if MODULE_NAME in sys.modules:
46 module = sys.modules[MODULE_NAME]
47 # Reload module for this sessions
48 bridge = import_bridge(module.__file__, debugger, session_dict,
49 reload_module = True)
50 if bridge:
51 report_success(bridge)
52 return
53
54 versions = {}
55 for install in os.popen(
56 'mdfind kMDItemCFBundleIdentifier=org.qt-project.qtcreator'
57 '| while read p;'
58 'do echo $p=$(mdls "$p" -name kMDItemVersion -raw);'
59 'done'):
60 install = install.strip()
61 (p, v) = install.split('=')
62 versions[v] = p
63
64 for version in sorted(versions, key=LooseVersion, reverse=True):
65 path = versions[version]
66
67 bridge_path = '{}/Contents/Resources/debugger/lldbbridge.py'.format(path)
68 bridge = import_bridge(bridge_path, debugger, session_dict)
69 if bridge:
70 bridge.CREATOR_VERSION = version
71 bridge.CREATOR_PATH = path
72 report_success(bridge)
73 return
74
75 print("Could not find Qt Creator installation, no Qt summary providers installed")
report_success(bridge)
import_bridge(path, debugger, session_dict, reload_module=False)