Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Toggle main menu visibility
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
4
import
os
5
import
sys
6
import
imp
7
8
from
distutils.version
import
LooseVersion
9
10
MODULE_NAME =
'qt'
11
12
debug =
print
if
'QT_LLDB_SUMMARY_PROVIDER_DEBUG'
in
os.environ \
13
else
lambda
*a, **k:
None
14
15
def
import_bridge
(path, debugger, session_dict, reload_module=False):
16
if
not
reload_module
and
MODULE_NAME
in
sys.modules:
17
del sys.modules[MODULE_NAME]
18
19
if
sys.version_info[0] >= 3:
20
sys.path.append(os.path.dirname(path))
21
debug
(f
"Loading source of Qt Creator bridge from '{path}'"
)
22
bridge = imp.load_source(MODULE_NAME, path)
23
24
if
not
hasattr(bridge,
'__lldb_init_module'
):
25
print
(
"Could not find '__lldb_init_module'. Ignoring."
)
26
return
None
27
28
# Make available for the current LLDB session, so that LLDB
29
# can find the functions when initializing the module.
30
session_dict[MODULE_NAME] = bridge
31
32
# Initialize the module now that it's available globally
33
debug
(f
"Initializing Qt Creator bridge by calling __lldb_init_module(): {bridge}"
)
34
bridge.__lldb_init_module(debugger, session_dict)
35
36
if
not
debugger.GetCategory(
'Qt'
):
37
debug
(
"Could not find Qt debugger category. Qt Creator summary providers not loaded."
)
38
# Summary provider failed for some reason
39
del session_dict[MODULE_NAME]
40
return
None
41
42
debug
(
"Bridge loaded successfully"
)
43
return
bridge
44
45
def
__lldb_init_module(debugger, session_dict):
46
qtc_env_vars = [
'QTC_DEBUGGER_PROCESS'
,
'QT_CREATOR_LLDB_PROCESS'
]
47
if
any(v
in
os.environ
for
v
in
qtc_env_vars)
and
\
48
not
'QT_FORCE_LOAD_LLDB_SUMMARY_PROVIDER'
in
os.environ:
49
debug
(
"Qt Creator lldb bridge not loaded because we're already in a debugging session."
)
50
return
51
52
# Check if the module has already been imported globally. This ensures
53
# that the Qt Creator application search is only performed once per
54
# LLDB process invocation, while still reloading for each session.
55
if
MODULE_NAME
in
sys.modules:
56
module = sys.modules[MODULE_NAME]
57
debug
(f
"Module '{module.__file__}' already imported. Reloading for this session."
)
58
# Reload module for this sessions
59
bridge =
import_bridge
(module.__file__, debugger, session_dict,
60
reload_module =
True
)
61
if
bridge:
62
debug
(
"Qt summary providers successfully reloaded."
)
63
return
64
else
:
65
print
(
"Bridge reload failed. Trying to find other Qt Creator bridges."
)
66
67
versions = {}
68
for
path
in
os.popen(
'mdfind kMDItemCFBundleIdentifier=org.qt-project.qtcreator'
):
69
path = path.strip()
70
file =
open
(os.path.join(path,
'Contents'
,
'Info.plist'
),
"rb"
)
71
72
import
plistlib
73
plist = plistlib.load(file)
74
75
version =
None
76
for
key
in
[
"CFBundleVersion"
,
"CFBundleShortVersionString"
]:
77
if
key
in
plist:
78
version = plist[key]
79
break
80
81
if
not
version:
82
print
(f
"Could not resolve version for '{path}'. Ignoring."
)
83
continue
84
85
versions[version] = path
86
87
if
not
len(versions):
88
print
(
"Could not find Qt Creator installation. No Qt summary providers installed."
)
89
return
90
91
for
version
in
sorted(versions, key=LooseVersion, reverse=
True
):
92
path = versions[version]
93
debug
(f
"Loading Qt summary providers from Creator Qt {version} in '{path}'"
)
94
bridge_path =
'{}/Contents/Resources/debugger/lldbbridge.py'
.format(path)
95
bridge =
import_bridge
(bridge_path, debugger, session_dict)
96
if
bridge:
97
debug
(f
"Qt summary providers successfully loaded."
)
98
return
99
100
if
'QT_LLDB_SUMMARY_PROVIDER_DEBUG'
not
in
os.environ:
101
print
(
"Could not find any valid Qt Creator bridges with summary providers. "
102
"Launch lldb or Qt Creator with the QT_LLDB_SUMMARY_PROVIDER_DEBUG environment "
103
"variable to debug."
)
debug_script.debug
None debug
Definition
debug_script.py:12
debug_script.import_bridge
import_bridge(path, debugger, session_dict, reload_module=False)
Definition
debug_script.py:15
print
QDebug print(QDebug debug, QSslError::SslError error)
Definition
qsslerror.cpp:344
open
file open(QIODevice::ReadOnly)
qtbase
src
corelib
debug_script.py
Generated on
for Qt by
1.18.0