Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
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 __lldb_init_module(debugger, session_dict):
38 # Check if the module has already been imported globally. This ensures
39 # that the Qt Creator application search is only performed once per
40 # LLDB process invocation, while still reloading for each session.
41 if MODULE_NAME in sys.modules:
42 module = sys.modules[MODULE_NAME]
43 # Reload module for this sessions
44 bridge = import_bridge(module.__file__, debugger, session_dict,
45 reload_module = True)
46 if bridge:
47 return
48
49 versions = {}
50 for path in os.popen('mdfind kMDItemCFBundleIdentifier=org.qt-project.qtcreator'):
51 path = path.strip()
52 file = open(os.path.join(path, 'Contents', 'Info.plist'), "rb")
53
54 import plistlib
55 plist = plistlib.load(file)
56
57 version = None
58 for key in ["CFBundleVersion", "CFBundleShortVersionString"]:
59 if key in plist:
60 version = plist[key]
61 break
62
63 if not version:
64 print(f"Could not resolve version for '{path}'. Ignoring.")
65 continue
66
67 versions[version] = path
68
69 if not len(versions):
70 print("Could not find Qt Creator installation. No Qt summary providers installed.")
71 return
72
73 for version in sorted(versions, key=LooseVersion, reverse=True):
74 path = versions[version]
75 print(f"Loading Qt summary providers from Creator {version} in '{path}'")
76 bridge_path = '{}/Contents/Resources/debugger/lldbbridge.py'.format(path)
77 bridge = import_bridge(bridge_path, debugger, session_dict)
78 if bridge:
79 return
import_bridge(path, debugger, session_dict, reload_module=False)
file open(QIODevice::ReadOnly)