2016-01-15 14:53:55 +01:00
|
|
|
############################################################################
|
|
|
|
#
|
|
|
|
# Copyright (C) 2016 The Qt Company Ltd.
|
|
|
|
# Contact: https://www.qt.io/licensing/
|
|
|
|
#
|
|
|
|
# This file is part of Qt Creator.
|
|
|
|
#
|
|
|
|
# Commercial License Usage
|
|
|
|
# Licensees holding valid commercial Qt licenses may use this file in
|
|
|
|
# accordance with the commercial license agreement provided with the
|
|
|
|
# Software or, alternatively, in accordance with the terms contained in
|
|
|
|
# a written agreement between you and The Qt Company. For licensing terms
|
|
|
|
# and conditions see https://www.qt.io/terms-conditions. For further
|
|
|
|
# information use the contact form at https://www.qt.io/contact-us.
|
|
|
|
#
|
|
|
|
# GNU General Public License Usage
|
|
|
|
# Alternatively, this file may be used under the terms of the GNU
|
|
|
|
# General Public License version 3 as published by the Free Software
|
|
|
|
# Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
|
|
|
|
# included in the packaging of this file. Please review the following
|
|
|
|
# information to ensure the GNU General Public License requirements will
|
|
|
|
# be met: https://www.gnu.org/licenses/gpl-3.0.html.
|
|
|
|
#
|
|
|
|
############################################################################
|
2013-04-11 18:11:54 +02:00
|
|
|
|
2013-09-11 21:35:39 +02:00
|
|
|
try:
|
|
|
|
import __builtin__
|
|
|
|
except:
|
|
|
|
import builtins
|
|
|
|
|
2016-09-20 12:07:46 +02:00
|
|
|
import gdb
|
2013-04-11 18:11:54 +02:00
|
|
|
import os
|
2013-05-15 15:42:55 +02:00
|
|
|
import os.path
|
2013-04-12 16:58:25 +02:00
|
|
|
import sys
|
2013-09-11 21:35:39 +02:00
|
|
|
import struct
|
2014-10-14 21:13:22 +02:00
|
|
|
import types
|
2013-09-11 21:35:39 +02:00
|
|
|
|
|
|
|
from dumper import *
|
2014-10-14 21:13:22 +02:00
|
|
|
|
2013-04-10 13:55:15 +02:00
|
|
|
|
|
|
|
#######################################################################
|
|
|
|
#
|
|
|
|
# Infrastructure
|
|
|
|
#
|
|
|
|
#######################################################################
|
|
|
|
|
2015-06-25 09:10:25 +02:00
|
|
|
def safePrint(output):
|
2013-04-10 13:55:15 +02:00
|
|
|
try:
|
|
|
|
print(output)
|
|
|
|
except:
|
|
|
|
out = ""
|
|
|
|
for c in output:
|
|
|
|
cc = ord(c)
|
|
|
|
if cc > 127:
|
|
|
|
out += "\\\\%d" % cc
|
|
|
|
elif cc < 0:
|
|
|
|
out += "\\\\%d" % (cc + 256)
|
|
|
|
else:
|
|
|
|
out += c
|
|
|
|
print(out)
|
|
|
|
|
|
|
|
def registerCommand(name, func):
|
|
|
|
|
|
|
|
class Command(gdb.Command):
|
|
|
|
def __init__(self):
|
|
|
|
super(Command, self).__init__(name, gdb.COMMAND_OBSCURE)
|
|
|
|
def invoke(self, args, from_tty):
|
2015-06-25 09:10:25 +02:00
|
|
|
safePrint(func(args))
|
2013-04-10 13:55:15 +02:00
|
|
|
|
|
|
|
Command()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#######################################################################
|
|
|
|
#
|
|
|
|
# Convenience
|
|
|
|
#
|
|
|
|
#######################################################################
|
|
|
|
|
|
|
|
# Just convienience for 'python print ...'
|
|
|
|
class PPCommand(gdb.Command):
|
|
|
|
def __init__(self):
|
|
|
|
super(PPCommand, self).__init__("pp", gdb.COMMAND_OBSCURE)
|
|
|
|
def invoke(self, args, from_tty):
|
|
|
|
print(eval(args))
|
|
|
|
|
|
|
|
PPCommand()
|
|
|
|
|
|
|
|
# Just convienience for 'python print gdb.parse_and_eval(...)'
|
|
|
|
class PPPCommand(gdb.Command):
|
|
|
|
def __init__(self):
|
|
|
|
super(PPPCommand, self).__init__("ppp", gdb.COMMAND_OBSCURE)
|
|
|
|
def invoke(self, args, from_tty):
|
|
|
|
print(gdb.parse_and_eval(args))
|
|
|
|
|
|
|
|
PPPCommand()
|
|
|
|
|
|
|
|
|
|
|
|
def scanStack(p, n):
|
2013-09-11 21:35:39 +02:00
|
|
|
p = int(p)
|
2013-04-10 13:55:15 +02:00
|
|
|
r = []
|
|
|
|
for i in xrange(n):
|
|
|
|
f = gdb.parse_and_eval("{void*}%s" % p)
|
|
|
|
m = gdb.execute("info symbol %s" % f, to_string=True)
|
|
|
|
if not m.startswith("No symbol matches"):
|
|
|
|
r.append(m)
|
|
|
|
p += f.type.sizeof
|
|
|
|
return r
|
|
|
|
|
|
|
|
class ScanStackCommand(gdb.Command):
|
|
|
|
def __init__(self):
|
|
|
|
super(ScanStackCommand, self).__init__("scanStack", gdb.COMMAND_OBSCURE)
|
|
|
|
def invoke(self, args, from_tty):
|
|
|
|
if len(args) == 0:
|
|
|
|
args = 20
|
2015-06-25 09:10:25 +02:00
|
|
|
safePrint(scanStack(gdb.parse_and_eval("$sp"), int(args)))
|
2013-04-10 13:55:15 +02:00
|
|
|
|
|
|
|
ScanStackCommand()
|
|
|
|
|
2013-04-11 18:11:54 +02:00
|
|
|
|
2013-04-12 16:58:25 +02:00
|
|
|
#######################################################################
|
|
|
|
#
|
|
|
|
# Import plain gdb pretty printers
|
|
|
|
#
|
|
|
|
#######################################################################
|
|
|
|
|
|
|
|
class PlainDumper:
|
|
|
|
def __init__(self, printer):
|
|
|
|
self.printer = printer
|
2015-07-10 10:09:34 +02:00
|
|
|
self.typeCache = {}
|
2013-04-12 16:58:25 +02:00
|
|
|
|
|
|
|
def __call__(self, d, value):
|
2016-08-22 13:45:15 +02:00
|
|
|
try:
|
|
|
|
printer = self.printer.gen_printer(value)
|
|
|
|
except:
|
|
|
|
printer = self.printer.invoke(value)
|
2013-04-12 16:58:25 +02:00
|
|
|
lister = getattr(printer, "children", None)
|
|
|
|
children = [] if lister is None else list(lister())
|
|
|
|
d.putType(self.printer.name)
|
2015-01-14 15:00:09 +01:00
|
|
|
val = printer.to_string()
|
|
|
|
if isinstance(val, str):
|
|
|
|
d.putValue(val)
|
2016-03-23 08:53:30 +01:00
|
|
|
elif sys.version_info[0] <= 2 and isinstance(val, unicode):
|
|
|
|
d.putValue(val)
|
2015-01-14 15:00:09 +01:00
|
|
|
else: # Assuming LazyString
|
2016-09-06 08:54:43 +02:00
|
|
|
d.putCharArrayHelper(val.address, val.length, val.type)
|
2015-01-14 15:00:09 +01:00
|
|
|
|
2013-04-12 16:58:25 +02:00
|
|
|
d.putNumChild(len(children))
|
|
|
|
if d.isExpanded():
|
|
|
|
with Children(d):
|
|
|
|
for child in children:
|
|
|
|
d.putSubItem(child[0], child[1])
|
|
|
|
|
|
|
|
def importPlainDumpers(args):
|
2015-01-25 01:36:08 +01:00
|
|
|
if args == "off":
|
2016-05-23 13:49:47 +02:00
|
|
|
try:
|
|
|
|
gdb.execute("disable pretty-printer .* .*")
|
|
|
|
except:
|
|
|
|
# Might occur in non-ASCII directories
|
|
|
|
warn("COULD NOT DISABLE PRETTY PRINTERS")
|
2015-01-25 01:36:08 +01:00
|
|
|
else:
|
|
|
|
theDumper.importPlainDumpers()
|
2013-04-12 16:58:25 +02:00
|
|
|
|
|
|
|
registerCommand("importPlainDumpers", importPlainDumpers)
|
|
|
|
|
|
|
|
|
2013-05-15 15:42:55 +02:00
|
|
|
|
|
|
|
class OutputSafer:
|
|
|
|
def __init__(self, d):
|
|
|
|
self.d = d
|
|
|
|
|
|
|
|
def __enter__(self):
|
|
|
|
self.savedOutput = self.d.output
|
|
|
|
self.d.output = []
|
|
|
|
|
|
|
|
def __exit__(self, exType, exValue, exTraceBack):
|
|
|
|
if self.d.passExceptions and not exType is None:
|
|
|
|
showException("OUTPUTSAFER", exType, exValue, exTraceBack)
|
|
|
|
self.d.output = self.savedOutput
|
|
|
|
else:
|
|
|
|
self.savedOutput.extend(self.d.output)
|
|
|
|
self.d.output = self.savedOutput
|
|
|
|
return False
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#######################################################################
|
|
|
|
#
|
|
|
|
# The Dumper Class
|
|
|
|
#
|
|
|
|
#######################################################################
|
|
|
|
|
|
|
|
|
2013-09-11 21:35:39 +02:00
|
|
|
class Dumper(DumperBase):
|
|
|
|
|
2013-10-30 12:38:29 +01:00
|
|
|
def __init__(self):
|
2013-09-11 21:35:39 +02:00
|
|
|
DumperBase.__init__(self)
|
|
|
|
|
2015-10-08 16:19:57 +02:00
|
|
|
# These values will be kept between calls to 'fetchVariables'.
|
2013-09-11 21:35:39 +02:00
|
|
|
self.isGdb = True
|
2015-07-10 10:09:34 +02:00
|
|
|
self.typeCache = {}
|
2015-10-09 15:00:20 +02:00
|
|
|
self.interpreterBreakpointResolvers = []
|
2013-10-30 12:38:29 +01:00
|
|
|
|
Debugger: Make dumpers somewhat work in command line GDB
With
python sys.path.insert(1, '/data/dev/creator/share/qtcreator/debugger/')
python from gdbbridge import *
in .gdbinit there's a new "GDB command", called "pp".
With code like
int main(int argc, char *argv[])
{
QString ss = "Hello";
QApplication app(argc, argv);
app.setObjectName(ss);
// break here
}
the 'pp' command can be used as follows:
(gdb) pp app
app =
[
<Myns::QGuiApplication> = {"Hello"}
staticMetaObject = <Myns::QMetaObject> = {""}
[parent] = <Myns::QObject *> = {"0x0"}
[children] = <Myns::QObjectList> = {"<3 items>"}
[properties] = "<>0 items>"
[methods] = "<6 items>"
[signals] = "<1 items>"
],<Myns::QApplication> = {"Hello"}
(gdb) pp app [properties],[children]
app =
[
<Myns::QGuiApplication> = {"Hello"}
staticMetaObject = <Myns::QMetaObject> = {""}
[parent] = <Myns::QObject *> = {"0x0"}
[children] = [
<Myns::QObject> = {""}
<Myns::QObject> = {""}
<Myns::QObject> = {"fusion"}
],<Myns::QObjectList> = {"<3 items>"}
[properties] = [
windowIcon = <Myns::QVariant (QIcon)> = {""}
cursorFlashTime = <Myns::QVariant (int)> = {"1000"}
doubleClickInterval = <Myns::QVariant (int)> = {"400"}
keyboardInputInterval = <Myns::QVariant (int)> = {"400"}
wheelScrollLines = <Myns::QVariant (int)> = {"3"}
globalStrut = <Myns::QVariant (QSize)> = {"(0, 0)"}
startDragTime = <Myns::QVariant (int)> = {"500"}
startDragDistance = <Myns::QVariant (int)> = {"10"}
styleSheet = <Myns::QVariant (QString)> = {""}
autoSipEnabled = <Myns::QVariant (bool)> = {"true"}
],"<10 items>"
[methods] = "<6 items>"
[signals] = "<1 items>"
],<Myns::QApplication> = {"Hello"}
(gdb) pp ss
ss =
<Myns::QString> = {"Hello"}
Change-Id: I6e4714a5cfe34c38917500d114ad9a70d20cff39
Reviewed-by: Christian Stenger <christian.stenger@digia.com>
Reviewed-by: hjk <hjk121@nokiamail.com>
2014-06-13 17:45:34 +02:00
|
|
|
def prepare(self, args):
|
2013-05-15 15:42:55 +02:00
|
|
|
self.output = []
|
2016-10-07 12:23:35 +02:00
|
|
|
self.setVariableFetchingOptions(args)
|
2016-07-05 16:52:32 +02:00
|
|
|
|
2016-10-25 15:32:13 +02:00
|
|
|
def fromFrameValue(self, nativeValue):
|
|
|
|
val = nativeValue
|
2016-09-06 08:54:43 +02:00
|
|
|
if self.useDynamicType:
|
|
|
|
try:
|
2016-10-25 15:32:13 +02:00
|
|
|
val = nativeValue.cast(nativeValue.dynamic_type)
|
2016-09-06 08:54:43 +02:00
|
|
|
except:
|
|
|
|
pass
|
2016-10-25 15:32:13 +02:00
|
|
|
return self.fromNativeValue(val)
|
2016-09-06 08:54:43 +02:00
|
|
|
|
|
|
|
def fromNativeValue(self, nativeValue):
|
2016-10-25 15:32:13 +02:00
|
|
|
#warn("FROM NATIVE VALUE: %s" % nativeValue)
|
|
|
|
self.check(isinstance(nativeValue, gdb.Value))
|
2016-09-26 14:29:16 +02:00
|
|
|
nativeType = nativeValue.type
|
2016-10-25 15:32:13 +02:00
|
|
|
code = nativeType.code
|
|
|
|
if code == gdb.TYPE_CODE_REF:
|
|
|
|
targetType = self.fromNativeType(nativeType.target().unqualified())
|
|
|
|
val = self.createReferenceValue(toInteger(nativeValue.address), targetType)
|
|
|
|
#warn("CREATED REF: %s" % val)
|
|
|
|
return val
|
|
|
|
if code == gdb.TYPE_CODE_PTR:
|
|
|
|
targetType = self.fromNativeType(nativeType.target().unqualified())
|
|
|
|
val = self.createPointerValue(toInteger(nativeValue), targetType)
|
|
|
|
#warn("CREATED PTR 1: %s" % val)
|
|
|
|
if not nativeValue.address is None:
|
|
|
|
val.laddress = toInteger(nativeValue.address)
|
|
|
|
#warn("CREATED PTR 2: %s" % val)
|
|
|
|
return val
|
|
|
|
if code == gdb.TYPE_CODE_TYPEDEF:
|
|
|
|
targetType = nativeType.strip_typedefs().unqualified()
|
|
|
|
#warn("TARGET TYPE: %s" % targetType)
|
|
|
|
if targetType.code == gdb.TYPE_CODE_ARRAY:
|
|
|
|
val = self.Value(self)
|
|
|
|
val.laddress = toInteger(nativeValue.address)
|
|
|
|
else:
|
|
|
|
# Cast may fail (e.g for arrays, see test for Bug5799)
|
|
|
|
val = self.fromNativeValue(nativeValue.cast(targetType))
|
|
|
|
val.type = self.fromNativeType(nativeType)
|
|
|
|
#warn("CREATED TYPEDEF: %s" % val)
|
|
|
|
return val
|
|
|
|
|
2016-09-06 08:54:43 +02:00
|
|
|
val = self.Value(self)
|
|
|
|
if not nativeValue.address is None:
|
|
|
|
val.laddress = toInteger(nativeValue.address)
|
2016-09-26 14:29:16 +02:00
|
|
|
else:
|
|
|
|
size = nativeType.sizeof
|
|
|
|
chars = self.lookupNativeType("unsigned char")
|
|
|
|
y = nativeValue.cast(chars.array(0, int(nativeType.sizeof - 1)))
|
|
|
|
buf = bytearray(struct.pack('x' * size))
|
|
|
|
for i in range(size):
|
|
|
|
buf[i] = int(y[i])
|
|
|
|
val.ldata = bytes(buf)
|
|
|
|
|
|
|
|
val.type = self.fromNativeType(nativeType)
|
2016-09-06 08:54:43 +02:00
|
|
|
val.lIsInScope = not nativeValue.is_optimized_out
|
2016-09-26 14:29:16 +02:00
|
|
|
code = nativeType.code
|
|
|
|
if code == gdb.TYPE_CODE_ENUM:
|
|
|
|
val.ldisplay = str(nativeValue)
|
|
|
|
intval = int(nativeValue)
|
|
|
|
if val.ldisplay != intval:
|
|
|
|
val.ldisplay += ' (%s)' % intval
|
|
|
|
elif code == gdb.TYPE_CODE_COMPLEX:
|
|
|
|
val.ldisplay = str(nativeValue)
|
2016-10-25 15:32:13 +02:00
|
|
|
#elif code == gdb.TYPE_CODE_ARRAY:
|
|
|
|
# val.type.ltarget = nativeValue[0].type.unqualified()
|
2016-09-06 08:54:43 +02:00
|
|
|
return val
|
|
|
|
|
2016-10-25 15:32:13 +02:00
|
|
|
def ptrSize(self):
|
|
|
|
result = gdb.lookup_type('void').pointer().sizeof
|
|
|
|
self.ptrSize = lambda: result
|
|
|
|
return result
|
|
|
|
|
2016-09-06 08:54:43 +02:00
|
|
|
def fromNativeType(self, nativeType):
|
|
|
|
self.check(isinstance(nativeType, gdb.Type))
|
2016-10-25 15:32:13 +02:00
|
|
|
code = nativeType.code
|
|
|
|
#warn('FROM NATIVE TYPE: %s' % nativeType)
|
|
|
|
#nativeType = nativeType.unqualified()
|
|
|
|
|
|
|
|
if code == gdb.TYPE_CODE_PTR:
|
|
|
|
#warn('PTR')
|
|
|
|
targetType = self.fromNativeType(nativeType.target().unqualified())
|
|
|
|
return self.createPointerType(targetType)
|
|
|
|
|
|
|
|
if code == gdb.TYPE_CODE_REF:
|
|
|
|
#warn('REF')
|
|
|
|
targetType = self.fromNativeType(nativeType.target().unqualified())
|
|
|
|
return self.createReferenceType(targetType)
|
|
|
|
|
|
|
|
if code == gdb.TYPE_CODE_ARRAY:
|
|
|
|
#warn('ARRAY')
|
|
|
|
nativeTargetType = nativeType.target().unqualified()
|
|
|
|
targetType = self.fromNativeType(nativeTargetType)
|
|
|
|
count = nativeType.sizeof // nativeTargetType.sizeof
|
|
|
|
return self.createArrayType(targetType, count)
|
|
|
|
|
|
|
|
if code == gdb.TYPE_CODE_TYPEDEF:
|
|
|
|
#warn('TYPEDEF')
|
|
|
|
nativeTargetType = nativeType.unqualified()
|
|
|
|
while nativeTargetType.code == gdb.TYPE_CODE_TYPEDEF:
|
|
|
|
nativeTargetType = nativeTargetType.strip_typedefs().unqualified()
|
|
|
|
targetType = self.fromNativeType(nativeTargetType)
|
|
|
|
return self.createTypedefedType(targetType, str(nativeType))
|
|
|
|
|
|
|
|
if code == gdb.TYPE_CODE_ERROR:
|
|
|
|
warn('Type error: %s' % nativeType)
|
|
|
|
return self.Type(self, '')
|
|
|
|
|
|
|
|
typeId = self.nativeTypeId(nativeType)
|
|
|
|
res = self.typeData.get(typeId, None)
|
|
|
|
if res is None:
|
|
|
|
tdata = self.TypeData(self)
|
|
|
|
tdata.name = str(nativeType)
|
|
|
|
tdata.typeId = typeId
|
|
|
|
tdata.lbitsize = nativeType.sizeof * 8
|
|
|
|
tdata.code = {
|
|
|
|
#gdb.TYPE_CODE_TYPEDEF : TypeCodeTypedef, # Handled above.
|
|
|
|
gdb.TYPE_CODE_METHOD : TypeCodeFunction,
|
|
|
|
gdb.TYPE_CODE_VOID : TypeCodeVoid,
|
|
|
|
gdb.TYPE_CODE_FUNC : TypeCodeFunction,
|
|
|
|
gdb.TYPE_CODE_METHODPTR : TypeCodeFunction,
|
|
|
|
gdb.TYPE_CODE_MEMBERPTR : TypeCodeFunction,
|
|
|
|
#gdb.TYPE_CODE_PTR : TypeCodePointer, # Handled above.
|
|
|
|
#gdb.TYPE_CODE_REF : TypeCodeReference, # Handled above.
|
|
|
|
gdb.TYPE_CODE_BOOL : TypeCodeIntegral,
|
|
|
|
gdb.TYPE_CODE_CHAR : TypeCodeIntegral,
|
|
|
|
gdb.TYPE_CODE_INT : TypeCodeIntegral,
|
|
|
|
gdb.TYPE_CODE_FLT : TypeCodeFloat,
|
|
|
|
gdb.TYPE_CODE_ENUM : TypeCodeEnum,
|
|
|
|
#gdb.TYPE_CODE_ARRAY : TypeCodeArray,
|
|
|
|
gdb.TYPE_CODE_STRUCT : TypeCodeStruct,
|
|
|
|
gdb.TYPE_CODE_UNION : TypeCodeStruct,
|
|
|
|
gdb.TYPE_CODE_COMPLEX : TypeCodeComplex,
|
|
|
|
gdb.TYPE_CODE_STRING : TypeCodeFortranString,
|
|
|
|
}[code]
|
|
|
|
if tdata.code == TypeCodeEnum:
|
2016-11-01 09:50:31 +01:00
|
|
|
tdata.enumDisplay = lambda intval : \
|
|
|
|
self.nativeTypeEnumDisplay(nativeType, intval)
|
|
|
|
if tdata.code == TypeCodeStruct:
|
|
|
|
tdata.lalignment = lambda : \
|
|
|
|
self.nativeStructAlignment(nativeType)
|
|
|
|
tdata.lfields = lambda value : \
|
|
|
|
self.listMembers(nativeType, value)
|
|
|
|
#tdata.lfieldByName = lambda name : \
|
|
|
|
# self.nativeTypeFieldTypeByName(nativeType, name)
|
2016-10-25 15:32:13 +02:00
|
|
|
tdata.templateArguments = self.listTemplateParameters(nativeType)
|
|
|
|
self.registerType(typeId, tdata) # Fix up fields and template args
|
|
|
|
# warn('CREATE TYPE: %s' % typeId)
|
|
|
|
#else:
|
|
|
|
# warn('REUSE TYPE: %s' % typeId)
|
|
|
|
return self.Type(self, typeId)
|
|
|
|
|
|
|
|
def listTemplateParameters(self, nativeType):
|
|
|
|
targs = []
|
|
|
|
pos = 0
|
|
|
|
while True:
|
|
|
|
try:
|
|
|
|
targ = nativeType.template_argument(pos)
|
|
|
|
except:
|
|
|
|
break
|
|
|
|
if isinstance(targ, gdb.Type):
|
|
|
|
targs.append(self.fromNativeType(targ.unqualified()))
|
|
|
|
elif isinstance(targ, gdb.Value):
|
|
|
|
targs.append(self.fromNativeValue(targ).value())
|
|
|
|
else:
|
2016-11-01 09:50:31 +01:00
|
|
|
error('UNKNOWN TEMPLATE PARAMETER')
|
2016-10-25 15:32:13 +02:00
|
|
|
pos += 1
|
|
|
|
return targs
|
2016-09-06 08:54:43 +02:00
|
|
|
|
2016-09-15 12:31:28 +02:00
|
|
|
def nativeTypeEnumDisplay(self, nativeType, intval):
|
|
|
|
try:
|
2016-10-25 15:32:13 +02:00
|
|
|
val = gdb.parse_and_eval('(%s)%d' % (nativeType, intval))
|
|
|
|
return '%s (%d)' % (val, intval)
|
2016-09-15 12:31:28 +02:00
|
|
|
except:
|
2016-10-25 15:32:13 +02:00
|
|
|
return '%d' % intval
|
|
|
|
|
|
|
|
def nativeTypeId(self, nativeType):
|
|
|
|
name = str(nativeType)
|
|
|
|
if len(name) == 0:
|
|
|
|
c = '0'
|
|
|
|
elif name == 'union {...}':
|
|
|
|
c = 'u'
|
2016-11-01 09:50:31 +01:00
|
|
|
elif name.endswith('{...}'):
|
|
|
|
c = 's'
|
2016-10-25 15:32:13 +02:00
|
|
|
else:
|
|
|
|
return name
|
2016-11-01 09:50:31 +01:00
|
|
|
typeId = c + ''.join(['{%s:%s}' % (f.name, self.nativeTypeId(f.type))
|
|
|
|
for f in nativeType.fields()])
|
2016-10-25 15:32:13 +02:00
|
|
|
return typeId
|
2016-09-15 12:31:28 +02:00
|
|
|
|
2016-11-01 09:50:31 +01:00
|
|
|
def nativeStructAlignment(self, nativeType):
|
|
|
|
#warn("NATIVE ALIGN FOR %s" % nativeType.name)
|
|
|
|
def handleItem(nativeFieldType, align):
|
|
|
|
a = self.fromNativeType(nativeFieldType).alignment()
|
|
|
|
return a if a > align else align
|
|
|
|
align = 1
|
|
|
|
for f in nativeType.fields():
|
|
|
|
align = handleItem(f.type, align)
|
|
|
|
return align
|
|
|
|
|
|
|
|
def listMembers(self, nativeType, value):
|
2016-09-19 12:05:16 +02:00
|
|
|
if not nativeType.code in (gdb.TYPE_CODE_STRUCT, gdb.TYPE_CODE_UNION):
|
2016-11-01 09:50:31 +01:00
|
|
|
return
|
|
|
|
|
|
|
|
if value.laddress == 0:
|
|
|
|
warn("CANNOT LIST MEMBERS OF NULL VALUE OF %s" % nativeType)
|
|
|
|
return
|
|
|
|
if value.laddress is None:
|
|
|
|
# FIXME: Happens e.g. for QVariant(QBitArray)
|
|
|
|
addr = self.pokeValue(value) # FIXME: Far too expensive.
|
|
|
|
else:
|
|
|
|
addr = value.laddress
|
|
|
|
nativeTypePointer = nativeType.unqualified().pointer()
|
|
|
|
nativeValue = gdb.Value(addr).cast(nativeTypePointer).dereference()
|
2016-09-06 08:54:43 +02:00
|
|
|
|
|
|
|
baseIndex = 0
|
2016-10-25 15:32:13 +02:00
|
|
|
anonNumber = 0
|
2016-11-01 09:50:31 +01:00
|
|
|
#warn('FIELDS FOR %s' % nativeType)
|
|
|
|
for nativeField in nativeType.fields():
|
2016-10-25 15:32:13 +02:00
|
|
|
#warn('FIELD: %s' % nativeField)
|
|
|
|
#warn(' BITSIZE: %s' % nativeField.bitsize)
|
|
|
|
#warn(' ARTIFICIAL: %s' % nativeField.artificial)
|
2016-11-01 09:50:31 +01:00
|
|
|
#warn(' NAME: %s' % nativeField.name)
|
|
|
|
#warn(' TYPE: %s' % nativeField.type)
|
|
|
|
#warn(' TYPEID: %s' % self.nativeTypeId(nativeField.type))
|
|
|
|
val = nativeValue[nativeField]
|
|
|
|
#warn('VAL: %s' % val)
|
|
|
|
try:
|
|
|
|
# Remove 'const', fails for 'const bool' members in some containers.
|
|
|
|
val = val.cast(nativeField.type.unqualified())
|
|
|
|
except:
|
|
|
|
pass
|
|
|
|
try:
|
|
|
|
member = self.fromNativeValue(val)
|
|
|
|
except:
|
|
|
|
#warn('CANNOT CREATE FIELD: %s' % nativeField.name)
|
|
|
|
continue
|
2016-09-06 08:54:43 +02:00
|
|
|
if nativeField.is_base_class:
|
2016-11-01 09:50:31 +01:00
|
|
|
member.isBaseClass = True
|
|
|
|
member.baseIndex = baseIndex
|
2016-09-06 08:54:43 +02:00
|
|
|
baseIndex += 1
|
2016-11-01 09:50:31 +01:00
|
|
|
member.name = nativeField.name
|
2016-09-06 08:54:43 +02:00
|
|
|
else:
|
|
|
|
if nativeField.name is None or len(nativeField.name) == 0:
|
|
|
|
# Something without a name.
|
|
|
|
# Anonymous union? We need a dummy name to distinguish
|
|
|
|
# multiple anonymous unions in the struct.
|
2016-10-25 15:32:13 +02:00
|
|
|
anonNumber += 1
|
2016-11-01 09:50:31 +01:00
|
|
|
member.name = '#%s' % anonNumber
|
2016-09-06 08:54:43 +02:00
|
|
|
else:
|
2016-11-01 09:50:31 +01:00
|
|
|
# Normal named member.
|
|
|
|
member.name = nativeField.name
|
|
|
|
if hasattr(nativeField, 'bitpos'):
|
|
|
|
member.lbitpos = nativeField.bitpos
|
|
|
|
# Correction for some bitfields. Size 0 can occur for
|
|
|
|
# types without debug information.
|
|
|
|
bitsize = 8 * nativeField.type.sizeof
|
|
|
|
if bitsize > 0:
|
|
|
|
member.lbitpos = nativeField.bitpos % bitsize
|
|
|
|
if hasattr(nativeField, 'bitsize') and nativeField.bitsize != 0:
|
|
|
|
member.lbitsize = nativeField.bitsize
|
|
|
|
else:
|
|
|
|
member.lbitsize = 8 * nativeField.type.sizeof
|
|
|
|
#warn('MEMBER: %s' % member)
|
|
|
|
yield member
|
|
|
|
if value.laddress is None:
|
|
|
|
self.releaseValue(addr)
|
2016-09-06 08:54:43 +02:00
|
|
|
|
2016-11-01 09:50:31 +01:00
|
|
|
def listLocals(self, partialVar):
|
2014-12-12 10:12:18 +01:00
|
|
|
frame = gdb.selected_frame()
|
|
|
|
|
|
|
|
try:
|
|
|
|
block = frame.block()
|
2016-10-25 15:32:13 +02:00
|
|
|
#warn('BLOCK: %s ' % block)
|
2014-12-12 10:12:18 +01:00
|
|
|
except RuntimeError as error:
|
2016-10-25 15:32:13 +02:00
|
|
|
#warn('BLOCK IN FRAME NOT ACCESSIBLE: %s' % error)
|
2014-12-12 10:12:18 +01:00
|
|
|
return []
|
|
|
|
except:
|
2016-10-25 15:32:13 +02:00
|
|
|
warn('BLOCK NOT ACCESSIBLE FOR UNKNOWN REASONS')
|
2014-12-12 10:12:18 +01:00
|
|
|
return []
|
|
|
|
|
|
|
|
items = []
|
|
|
|
shadowed = {}
|
|
|
|
while True:
|
|
|
|
if block is None:
|
|
|
|
warn("UNEXPECTED 'None' BLOCK")
|
|
|
|
break
|
|
|
|
for symbol in block:
|
2015-10-08 16:05:29 +02:00
|
|
|
|
|
|
|
# Filter out labels etc.
|
|
|
|
if symbol.is_variable or symbol.is_argument:
|
2014-12-12 10:12:18 +01:00
|
|
|
name = symbol.print_name
|
|
|
|
|
|
|
|
if name == "__in_chrg" or name == "__PRETTY_FUNCTION__":
|
|
|
|
continue
|
|
|
|
|
2016-09-20 11:52:06 +02:00
|
|
|
if not partialVar is None and partialVar != name:
|
|
|
|
continue
|
|
|
|
|
2014-12-12 10:12:18 +01:00
|
|
|
# "NotImplementedError: Symbol type not yet supported in
|
|
|
|
# Python scripts."
|
|
|
|
#warn("SYMBOL %s (%s, %s)): " % (symbol, name, symbol.name))
|
2016-10-25 15:32:13 +02:00
|
|
|
if False and self.passExceptions:
|
|
|
|
value = self.fromFrameValue(frame.read_var(name, block))
|
|
|
|
value.name = name
|
|
|
|
#warn("READ 1: %s" % value.stringify())
|
|
|
|
items.append(value)
|
|
|
|
continue
|
|
|
|
|
2014-12-12 10:12:18 +01:00
|
|
|
try:
|
2016-10-25 15:32:13 +02:00
|
|
|
# Same as above, but for production.
|
|
|
|
value = self.fromFrameValue(frame.read_var(name, block))
|
2016-09-20 11:52:06 +02:00
|
|
|
value.name = name
|
2016-10-25 15:32:13 +02:00
|
|
|
#warn("READ 1: %s" % value.stringify())
|
2016-09-06 08:54:43 +02:00
|
|
|
items.append(value)
|
2014-12-12 10:12:18 +01:00
|
|
|
continue
|
|
|
|
except:
|
|
|
|
pass
|
|
|
|
|
|
|
|
try:
|
|
|
|
#warn("READ 2: %s" % item.value)
|
2016-10-25 15:32:13 +02:00
|
|
|
value = self.fromFrameValue(frame.read_var(name))
|
2016-09-20 11:52:06 +02:00
|
|
|
value.name = name
|
2016-09-06 08:54:43 +02:00
|
|
|
items.append(value)
|
2014-12-12 10:12:18 +01:00
|
|
|
continue
|
|
|
|
except:
|
|
|
|
# RuntimeError: happens for
|
|
|
|
# void foo() { std::string s; std::wstring w; }
|
|
|
|
# ValueError: happens for (as of 2010/11/4)
|
|
|
|
# a local struct as found e.g. in
|
|
|
|
# gcc sources in gcc.c, int execute()
|
|
|
|
pass
|
|
|
|
|
|
|
|
try:
|
|
|
|
#warn("READ 3: %s %s" % (name, item.value))
|
|
|
|
#warn("ITEM 3: %s" % item.value)
|
2016-10-25 15:32:13 +02:00
|
|
|
value = self.fromFrameValue(gdb.parse_and_eval(name))
|
|
|
|
value.name = name
|
2016-09-06 08:54:43 +02:00
|
|
|
items.append(value)
|
2014-12-12 10:12:18 +01:00
|
|
|
except:
|
|
|
|
# Can happen in inlined code (see last line of
|
|
|
|
# RowPainter::paintChars(): "RuntimeError:
|
|
|
|
# No symbol \"__val\" in current context.\n"
|
|
|
|
pass
|
|
|
|
|
|
|
|
# The outermost block in a function has the function member
|
|
|
|
# FIXME: check whether this is guaranteed.
|
|
|
|
if not block.function is None:
|
|
|
|
break
|
|
|
|
|
|
|
|
block = block.superblock
|
|
|
|
|
|
|
|
return items
|
|
|
|
|
2015-04-15 12:38:11 +02:00
|
|
|
# Hack to avoid QDate* dumper timeouts with GDB 7.4 on 32 bit
|
|
|
|
# due to misaligned %ebx in SSE calls (qstring.cpp:findChar)
|
|
|
|
# This seems to be fixed in 7.9 (or earlier)
|
|
|
|
def canCallLocale(self):
|
2016-09-14 14:44:58 +02:00
|
|
|
return self.ptrSize() == 8
|
2014-12-12 10:12:18 +01:00
|
|
|
|
2015-10-08 16:19:57 +02:00
|
|
|
def fetchVariables(self, args):
|
2016-07-22 10:20:01 +02:00
|
|
|
self.resetStats()
|
Debugger: Make dumpers somewhat work in command line GDB
With
python sys.path.insert(1, '/data/dev/creator/share/qtcreator/debugger/')
python from gdbbridge import *
in .gdbinit there's a new "GDB command", called "pp".
With code like
int main(int argc, char *argv[])
{
QString ss = "Hello";
QApplication app(argc, argv);
app.setObjectName(ss);
// break here
}
the 'pp' command can be used as follows:
(gdb) pp app
app =
[
<Myns::QGuiApplication> = {"Hello"}
staticMetaObject = <Myns::QMetaObject> = {""}
[parent] = <Myns::QObject *> = {"0x0"}
[children] = <Myns::QObjectList> = {"<3 items>"}
[properties] = "<>0 items>"
[methods] = "<6 items>"
[signals] = "<1 items>"
],<Myns::QApplication> = {"Hello"}
(gdb) pp app [properties],[children]
app =
[
<Myns::QGuiApplication> = {"Hello"}
staticMetaObject = <Myns::QMetaObject> = {""}
[parent] = <Myns::QObject *> = {"0x0"}
[children] = [
<Myns::QObject> = {""}
<Myns::QObject> = {""}
<Myns::QObject> = {"fusion"}
],<Myns::QObjectList> = {"<3 items>"}
[properties] = [
windowIcon = <Myns::QVariant (QIcon)> = {""}
cursorFlashTime = <Myns::QVariant (int)> = {"1000"}
doubleClickInterval = <Myns::QVariant (int)> = {"400"}
keyboardInputInterval = <Myns::QVariant (int)> = {"400"}
wheelScrollLines = <Myns::QVariant (int)> = {"3"}
globalStrut = <Myns::QVariant (QSize)> = {"(0, 0)"}
startDragTime = <Myns::QVariant (int)> = {"500"}
startDragDistance = <Myns::QVariant (int)> = {"10"}
styleSheet = <Myns::QVariant (QString)> = {""}
autoSipEnabled = <Myns::QVariant (bool)> = {"true"}
],"<10 items>"
[methods] = "<6 items>"
[signals] = "<1 items>"
],<Myns::QApplication> = {"Hello"}
(gdb) pp ss
ss =
<Myns::QString> = {"Hello"}
Change-Id: I6e4714a5cfe34c38917500d114ad9a70d20cff39
Reviewed-by: Christian Stenger <christian.stenger@digia.com>
Reviewed-by: hjk <hjk121@nokiamail.com>
2014-06-13 17:45:34 +02:00
|
|
|
self.prepare(args)
|
2015-03-26 13:03:38 +01:00
|
|
|
|
2015-10-09 15:00:20 +02:00
|
|
|
(ok, res) = self.tryFetchInterpreterVariables(args)
|
|
|
|
if ok:
|
|
|
|
safePrint(res)
|
|
|
|
return
|
2015-10-08 16:19:57 +02:00
|
|
|
|
Debugger: Make dumpers somewhat work in command line GDB
With
python sys.path.insert(1, '/data/dev/creator/share/qtcreator/debugger/')
python from gdbbridge import *
in .gdbinit there's a new "GDB command", called "pp".
With code like
int main(int argc, char *argv[])
{
QString ss = "Hello";
QApplication app(argc, argv);
app.setObjectName(ss);
// break here
}
the 'pp' command can be used as follows:
(gdb) pp app
app =
[
<Myns::QGuiApplication> = {"Hello"}
staticMetaObject = <Myns::QMetaObject> = {""}
[parent] = <Myns::QObject *> = {"0x0"}
[children] = <Myns::QObjectList> = {"<3 items>"}
[properties] = "<>0 items>"
[methods] = "<6 items>"
[signals] = "<1 items>"
],<Myns::QApplication> = {"Hello"}
(gdb) pp app [properties],[children]
app =
[
<Myns::QGuiApplication> = {"Hello"}
staticMetaObject = <Myns::QMetaObject> = {""}
[parent] = <Myns::QObject *> = {"0x0"}
[children] = [
<Myns::QObject> = {""}
<Myns::QObject> = {""}
<Myns::QObject> = {"fusion"}
],<Myns::QObjectList> = {"<3 items>"}
[properties] = [
windowIcon = <Myns::QVariant (QIcon)> = {""}
cursorFlashTime = <Myns::QVariant (int)> = {"1000"}
doubleClickInterval = <Myns::QVariant (int)> = {"400"}
keyboardInputInterval = <Myns::QVariant (int)> = {"400"}
wheelScrollLines = <Myns::QVariant (int)> = {"3"}
globalStrut = <Myns::QVariant (QSize)> = {"(0, 0)"}
startDragTime = <Myns::QVariant (int)> = {"500"}
startDragDistance = <Myns::QVariant (int)> = {"10"}
styleSheet = <Myns::QVariant (QString)> = {""}
autoSipEnabled = <Myns::QVariant (bool)> = {"true"}
],"<10 items>"
[methods] = "<6 items>"
[signals] = "<1 items>"
],<Myns::QApplication> = {"Hello"}
(gdb) pp ss
ss =
<Myns::QString> = {"Hello"}
Change-Id: I6e4714a5cfe34c38917500d114ad9a70d20cff39
Reviewed-by: Christian Stenger <christian.stenger@digia.com>
Reviewed-by: hjk <hjk121@nokiamail.com>
2014-06-13 17:45:34 +02:00
|
|
|
self.output.append('data=[')
|
2015-02-05 12:51:25 +01:00
|
|
|
|
2016-09-20 11:52:06 +02:00
|
|
|
partialVar = args.get("partialvar", "")
|
|
|
|
isPartial = len(partialVar) > 0
|
|
|
|
partialName = partialVar.split('.')[1].split('@')[0] if isPartial else None
|
2013-05-15 15:42:55 +02:00
|
|
|
|
2016-11-01 09:50:31 +01:00
|
|
|
variables = self.listLocals(partialName)
|
2015-12-16 17:17:38 +01:00
|
|
|
|
2013-05-15 15:42:55 +02:00
|
|
|
# Take care of the return value of the last function call.
|
Debugger: Make dumpers somewhat work in command line GDB
With
python sys.path.insert(1, '/data/dev/creator/share/qtcreator/debugger/')
python from gdbbridge import *
in .gdbinit there's a new "GDB command", called "pp".
With code like
int main(int argc, char *argv[])
{
QString ss = "Hello";
QApplication app(argc, argv);
app.setObjectName(ss);
// break here
}
the 'pp' command can be used as follows:
(gdb) pp app
app =
[
<Myns::QGuiApplication> = {"Hello"}
staticMetaObject = <Myns::QMetaObject> = {""}
[parent] = <Myns::QObject *> = {"0x0"}
[children] = <Myns::QObjectList> = {"<3 items>"}
[properties] = "<>0 items>"
[methods] = "<6 items>"
[signals] = "<1 items>"
],<Myns::QApplication> = {"Hello"}
(gdb) pp app [properties],[children]
app =
[
<Myns::QGuiApplication> = {"Hello"}
staticMetaObject = <Myns::QMetaObject> = {""}
[parent] = <Myns::QObject *> = {"0x0"}
[children] = [
<Myns::QObject> = {""}
<Myns::QObject> = {""}
<Myns::QObject> = {"fusion"}
],<Myns::QObjectList> = {"<3 items>"}
[properties] = [
windowIcon = <Myns::QVariant (QIcon)> = {""}
cursorFlashTime = <Myns::QVariant (int)> = {"1000"}
doubleClickInterval = <Myns::QVariant (int)> = {"400"}
keyboardInputInterval = <Myns::QVariant (int)> = {"400"}
wheelScrollLines = <Myns::QVariant (int)> = {"3"}
globalStrut = <Myns::QVariant (QSize)> = {"(0, 0)"}
startDragTime = <Myns::QVariant (int)> = {"500"}
startDragDistance = <Myns::QVariant (int)> = {"10"}
styleSheet = <Myns::QVariant (QString)> = {""}
autoSipEnabled = <Myns::QVariant (bool)> = {"true"}
],"<10 items>"
[methods] = "<6 items>"
[signals] = "<1 items>"
],<Myns::QApplication> = {"Hello"}
(gdb) pp ss
ss =
<Myns::QString> = {"Hello"}
Change-Id: I6e4714a5cfe34c38917500d114ad9a70d20cff39
Reviewed-by: Christian Stenger <christian.stenger@digia.com>
Reviewed-by: hjk <hjk121@nokiamail.com>
2014-06-13 17:45:34 +02:00
|
|
|
if len(self.resultVarName) > 0:
|
2013-05-15 15:42:55 +02:00
|
|
|
try:
|
2016-09-06 08:54:43 +02:00
|
|
|
value = self.parseAndEvaluate(self.resultVarName)
|
|
|
|
value.name = self.resultVarName
|
|
|
|
value.iname = "return." + self.resultVarName
|
|
|
|
variables.append(value)
|
2013-05-15 15:42:55 +02:00
|
|
|
except:
|
|
|
|
# Don't bother. It's only supplementary information anyway.
|
|
|
|
pass
|
|
|
|
|
2016-09-20 11:52:06 +02:00
|
|
|
self.handleLocals(variables)
|
|
|
|
self.handleWatches(args)
|
2013-05-15 15:42:55 +02:00
|
|
|
|
2013-10-31 10:28:11 +01:00
|
|
|
self.output.append('],typeinfo=[')
|
|
|
|
for name in self.typesToReport.keys():
|
2014-01-24 15:13:20 +01:00
|
|
|
typeobj = self.typesToReport[name]
|
2013-10-31 10:28:11 +01:00
|
|
|
# Happens e.g. for '(anonymous namespace)::InsertDefOperation'
|
2016-09-06 08:54:43 +02:00
|
|
|
#if not typeobj is None:
|
|
|
|
# self.output.append('{name="%s",size="%s"}'
|
|
|
|
# % (self.hexencode(name), typeobj.sizeof))
|
2013-10-31 10:28:11 +01:00
|
|
|
self.output.append(']')
|
|
|
|
self.typesToReport = {}
|
2014-01-24 15:13:20 +01:00
|
|
|
|
2015-02-11 17:51:15 +01:00
|
|
|
if self.forceQtNamespace:
|
2014-07-24 13:22:19 +02:00
|
|
|
self.qtNamepaceToReport = self.qtNamespace()
|
2014-03-07 15:48:13 +01:00
|
|
|
|
2014-02-27 12:54:20 +01:00
|
|
|
if self.qtNamespaceToReport:
|
|
|
|
self.output.append(',qtnamespace="%s"' % self.qtNamespaceToReport)
|
|
|
|
self.qtNamespaceToReport = None
|
2015-03-26 13:03:38 +01:00
|
|
|
|
|
|
|
self.output.append(',partial="%d"' % isPartial)
|
|
|
|
|
2016-07-22 10:20:01 +02:00
|
|
|
self.preping('safePrint')
|
2015-06-25 09:10:25 +02:00
|
|
|
safePrint(''.join(self.output))
|
2016-07-22 10:20:01 +02:00
|
|
|
self.ping('safePrint')
|
|
|
|
safePrint('"%s"' % str(self.dumpStats()))
|
2013-05-23 15:47:28 +02:00
|
|
|
|
2016-09-06 08:54:43 +02:00
|
|
|
def parseAndEvaluate(self, exp):
|
|
|
|
#warn("EVALUATE '%s'" % exp)
|
2013-09-11 21:35:39 +02:00
|
|
|
try:
|
2016-09-06 08:54:43 +02:00
|
|
|
val = gdb.parse_and_eval(exp)
|
|
|
|
except RuntimeError as error:
|
|
|
|
if self.passExceptions:
|
2016-11-01 17:22:56 +01:00
|
|
|
warn("Cannot evaluate '%s': %s" % (exp, error))
|
|
|
|
return None
|
2016-09-06 08:54:43 +02:00
|
|
|
return self.fromNativeValue(val)
|
2013-09-11 21:35:39 +02:00
|
|
|
|
2016-09-06 08:54:43 +02:00
|
|
|
def callHelper(self, rettype, value, function, args):
|
2013-09-11 21:35:39 +02:00
|
|
|
# args is a tuple.
|
|
|
|
arg = ""
|
|
|
|
for i in range(len(args)):
|
|
|
|
if i:
|
|
|
|
arg += ','
|
|
|
|
a = args[i]
|
|
|
|
if (':' in a) and not ("'" in a):
|
|
|
|
arg = "'%s'" % a
|
|
|
|
else:
|
|
|
|
arg += a
|
|
|
|
|
2015-10-08 16:19:57 +02:00
|
|
|
#warn("CALL: %s -> %s(%s)" % (value, function, arg))
|
2016-09-30 13:56:46 +02:00
|
|
|
typeName = value.type.name
|
2014-01-29 00:41:48 +01:00
|
|
|
if typeName.find(":") >= 0:
|
|
|
|
typeName = "'" + typeName + "'"
|
2013-09-11 21:35:39 +02:00
|
|
|
# 'class' is needed, see http://sourceware.org/bugzilla/show_bug.cgi?id=11912
|
2016-11-01 09:50:31 +01:00
|
|
|
#exp = "((class %s*)%s)->%s(%s)" % (typeName, value.laddress, function, arg)
|
|
|
|
addr = value.laddress
|
|
|
|
if addr is None:
|
|
|
|
addr = self.pokeValue(value)
|
2016-09-06 08:54:43 +02:00
|
|
|
#warn("PTR: %s -> %s(%s)" % (value, function, addr))
|
|
|
|
exp = "((%s*)0x%x)->%s(%s)" % (typeName, addr, function, arg)
|
2013-09-11 21:35:39 +02:00
|
|
|
#warn("CALL: %s" % exp)
|
2014-01-29 00:41:48 +01:00
|
|
|
result = gdb.parse_and_eval(exp)
|
2016-10-25 15:32:13 +02:00
|
|
|
warn(" -> %s" % result)
|
|
|
|
res = self.fromNativeValue(result)
|
2016-11-01 09:50:31 +01:00
|
|
|
if value.laddress is None:
|
|
|
|
self.releaseValue(addr)
|
2016-10-25 15:32:13 +02:00
|
|
|
return res
|
2013-10-16 17:04:34 +02:00
|
|
|
|
|
|
|
def makeExpression(self, value):
|
2016-09-30 13:56:46 +02:00
|
|
|
typename = "::" + value.type.name
|
2014-12-12 09:00:30 +01:00
|
|
|
#warn(" TYPE: %s" % typename)
|
2016-09-06 08:54:43 +02:00
|
|
|
exp = "(*(%s*)(0x%x))" % (typename, value.address())
|
2013-10-16 17:04:34 +02:00
|
|
|
#warn(" EXP: %s" % exp)
|
|
|
|
return exp
|
|
|
|
|
|
|
|
def makeStdString(init):
|
|
|
|
# Works only for small allocators, but they are usually empty.
|
|
|
|
gdb.execute("set $d=(std::string*)calloc(sizeof(std::string), 2)");
|
|
|
|
gdb.execute("call($d->basic_string(\"" + init +
|
|
|
|
"\",*(std::allocator<char>*)(1+$d)))")
|
2014-02-21 17:34:08 +01:00
|
|
|
value = gdb.parse_and_eval("$d").dereference()
|
2013-10-16 17:04:34 +02:00
|
|
|
#warn(" TYPE: %s" % value.type)
|
|
|
|
#warn(" ADDR: %s" % value.address)
|
|
|
|
#warn(" VALUE: %s" % value)
|
|
|
|
return value
|
|
|
|
|
2014-01-29 00:41:48 +01:00
|
|
|
def pokeValue(self, value):
|
2016-09-06 08:54:43 +02:00
|
|
|
# Allocates inferior memory and copies the contents of value.
|
|
|
|
# Returns a pointer to the copy.
|
2014-01-29 00:41:48 +01:00
|
|
|
# Avoid malloc symbol clash with QVector
|
2016-09-06 08:54:43 +02:00
|
|
|
size = value.type.size()
|
|
|
|
data = value.data()
|
|
|
|
h = self.hexencode(data)
|
|
|
|
#warn("DATA: %s" % h
|
|
|
|
string = ''.join("\\x" + h[2*i:2*i+2] for i in range(size))
|
2016-11-01 09:50:31 +01:00
|
|
|
exp = '(%s*)memcpy(calloc(%d, 1), "%s", %d)' \
|
|
|
|
% (value.type.name, size, string, size)
|
2014-01-29 00:41:48 +01:00
|
|
|
#warn("EXP: %s" % exp)
|
2016-09-06 08:54:43 +02:00
|
|
|
res = gdb.parse_and_eval(exp)
|
|
|
|
#warn("RES: %s" % res)
|
|
|
|
return toInteger(res)
|
2013-06-28 14:04:05 +02:00
|
|
|
|
2016-11-01 09:50:31 +01:00
|
|
|
def releaseValue(self, address):
|
|
|
|
gdb.parse_and_eval('free(0x%x)' % address)
|
|
|
|
|
2014-12-12 09:00:30 +01:00
|
|
|
def setValue(self, address, typename, value):
|
|
|
|
cmd = "set {%s}%s=%s" % (typename, address, value)
|
2013-11-20 18:55:09 +01:00
|
|
|
gdb.execute(cmd)
|
|
|
|
|
2014-12-12 09:00:30 +01:00
|
|
|
def setValues(self, address, typename, values):
|
2013-11-20 18:55:09 +01:00
|
|
|
cmd = "set {%s[%s]}%s={%s}" \
|
2014-12-12 09:00:30 +01:00
|
|
|
% (typename, len(values), address, ','.join(map(str, values)))
|
2013-11-20 18:55:09 +01:00
|
|
|
gdb.execute(cmd)
|
|
|
|
|
2013-10-30 11:40:53 +01:00
|
|
|
def selectedInferior(self):
|
|
|
|
try:
|
2013-10-30 12:38:29 +01:00
|
|
|
# gdb.Inferior is new in gdb 7.2
|
2013-10-30 15:07:54 +01:00
|
|
|
self.cachedInferior = gdb.selected_inferior()
|
2013-10-30 11:40:53 +01:00
|
|
|
except:
|
|
|
|
# Pre gdb 7.4. Right now we don't have more than one inferior anyway.
|
2013-10-30 15:07:54 +01:00
|
|
|
self.cachedInferior = gdb.inferiors()[0]
|
|
|
|
|
|
|
|
# Memoize result.
|
|
|
|
self.selectedInferior = lambda: self.cachedInferior
|
|
|
|
return self.cachedInferior
|
2013-10-30 11:40:53 +01:00
|
|
|
|
2015-10-08 16:19:57 +02:00
|
|
|
def readRawMemory(self, address, size):
|
2016-09-06 08:54:43 +02:00
|
|
|
return self.selectedInferior().read_memory(address, size)
|
2013-07-09 14:19:45 -07:00
|
|
|
|
2014-12-12 09:00:30 +01:00
|
|
|
def findStaticMetaObject(self, typename):
|
2016-09-06 08:54:43 +02:00
|
|
|
symbolName = typename + "::staticMetaObject"
|
|
|
|
symbol = gdb.lookup_global_symbol(symbolName, gdb.SYMBOL_VAR_DOMAIN)
|
|
|
|
if not symbol:
|
|
|
|
return 0
|
2014-02-28 12:05:48 +01:00
|
|
|
try:
|
2016-09-06 08:54:43 +02:00
|
|
|
# Older GDB ~7.4 don't have gdb.Symbol.value()
|
|
|
|
return toInteger(symbol.value().address)
|
2014-02-28 12:05:48 +01:00
|
|
|
except:
|
|
|
|
pass
|
2016-09-06 08:54:43 +02:00
|
|
|
|
|
|
|
address = gdb.parse_and_eval("&'%s'" % symbolName)
|
|
|
|
return toInteger(address)
|
2014-02-25 15:52:22 +01:00
|
|
|
|
2013-05-15 15:42:55 +02:00
|
|
|
def put(self, value):
|
|
|
|
self.output.append(value)
|
|
|
|
|
2013-11-11 09:54:54 +01:00
|
|
|
def isArmArchitecture(self):
|
|
|
|
return 'arm' in gdb.TARGET_CONFIG.lower()
|
|
|
|
|
|
|
|
def isQnxTarget(self):
|
|
|
|
return 'qnx' in gdb.TARGET_CONFIG.lower()
|
|
|
|
|
2014-04-01 18:11:57 +02:00
|
|
|
def isWindowsTarget(self):
|
|
|
|
# We get i686-w64-mingw32
|
|
|
|
return 'mingw' in gdb.TARGET_CONFIG.lower()
|
|
|
|
|
2016-10-06 13:36:02 +02:00
|
|
|
def isMsvcTarget(self):
|
|
|
|
return False
|
|
|
|
|
2016-10-31 17:59:49 +01:00
|
|
|
def prettySymbolByAddress(self, address):
|
|
|
|
try:
|
|
|
|
return str(gdb.parse_and_eval('(void(*))0x%x' % address))
|
|
|
|
except:
|
|
|
|
return '0x%x' % address
|
|
|
|
|
2014-03-07 18:46:44 +01:00
|
|
|
def qtVersionString(self):
|
|
|
|
try:
|
|
|
|
return str(gdb.lookup_symbol("qVersion")[0].value()())
|
|
|
|
except:
|
|
|
|
pass
|
2013-10-30 15:07:54 +01:00
|
|
|
try:
|
2014-01-30 12:40:24 +01:00
|
|
|
ns = self.qtNamespace()
|
2014-03-07 18:46:44 +01:00
|
|
|
return str(gdb.parse_and_eval("((const char*(*)())'%sqVersion')()" % ns))
|
|
|
|
except:
|
|
|
|
pass
|
|
|
|
return None
|
|
|
|
|
|
|
|
def qtVersion(self):
|
2015-08-13 12:12:54 +02:00
|
|
|
try:
|
|
|
|
# Only available with Qt 5.3+
|
2016-06-03 09:36:34 +02:00
|
|
|
qtversion = int(str(gdb.parse_and_eval("((void**)&qtHookData)[2]")), 16)
|
2015-08-13 12:12:54 +02:00
|
|
|
self.qtVersion = lambda: qtversion
|
|
|
|
return qtversion
|
|
|
|
except:
|
|
|
|
pass
|
|
|
|
|
2014-03-07 18:46:44 +01:00
|
|
|
try:
|
|
|
|
version = self.qtVersionString()
|
2013-10-31 10:28:11 +01:00
|
|
|
(major, minor, patch) = version[version.find('"')+1:version.rfind('"')].split('.')
|
2014-03-07 18:46:44 +01:00
|
|
|
qtversion = 0x10000 * int(major) + 0x100 * int(minor) + int(patch)
|
|
|
|
self.qtVersion = lambda: qtversion
|
|
|
|
return qtversion
|
2013-10-30 15:07:54 +01:00
|
|
|
except:
|
2014-03-07 15:48:13 +01:00
|
|
|
# Use fallback until we have a better answer.
|
|
|
|
return self.fallbackQtVersion
|
2013-10-30 15:07:54 +01:00
|
|
|
|
2013-11-11 09:54:54 +01:00
|
|
|
def isQt3Support(self):
|
|
|
|
if self.qtVersion() >= 0x050000:
|
|
|
|
return False
|
|
|
|
else:
|
|
|
|
try:
|
|
|
|
# This will fail on Qt 4 without Qt 3 support
|
|
|
|
gdb.execute("ptype QChar::null", to_string=True)
|
|
|
|
self.cachedIsQt3Suport = True
|
|
|
|
except:
|
|
|
|
self.cachedIsQt3Suport = False
|
|
|
|
|
|
|
|
# Memoize good results.
|
|
|
|
self.isQt3Support = lambda: self.cachedIsQt3Suport
|
|
|
|
return self.cachedIsQt3Suport
|
|
|
|
|
2015-11-02 16:01:43 +01:00
|
|
|
def createSpecialBreakpoints(self, args):
|
|
|
|
self.specialBreakpoints = []
|
|
|
|
def newSpecial(spec):
|
|
|
|
class SpecialBreakpoint(gdb.Breakpoint):
|
|
|
|
def __init__(self, spec):
|
|
|
|
super(SpecialBreakpoint, self).\
|
|
|
|
__init__(spec, gdb.BP_BREAKPOINT, internal=True)
|
|
|
|
self.spec = spec
|
|
|
|
|
|
|
|
def stop(self):
|
|
|
|
print("Breakpoint on '%s' hit." % self.spec)
|
|
|
|
return True
|
|
|
|
return SpecialBreakpoint(spec)
|
|
|
|
|
|
|
|
# FIXME: ns is accessed too early. gdb.Breakpoint() has no
|
|
|
|
# 'rbreak' replacement, and breakpoints created with
|
|
|
|
# 'gdb.execute("rbreak...") cannot be made invisible.
|
|
|
|
# So let's ignore the existing of namespaced builds for this
|
|
|
|
# fringe feature here for now.
|
|
|
|
ns = self.qtNamespace()
|
|
|
|
if args.get('breakonabort', 0):
|
|
|
|
self.specialBreakpoints.append(newSpecial("abort"))
|
|
|
|
|
|
|
|
if args.get('breakonwarning', 0):
|
|
|
|
self.specialBreakpoints.append(newSpecial(ns + "qWarning"))
|
|
|
|
self.specialBreakpoints.append(newSpecial(ns + "QMessageLogger::warning"))
|
|
|
|
|
|
|
|
if args.get('breakonfatal', 0):
|
|
|
|
self.specialBreakpoints.append(newSpecial(ns + "qFatal"))
|
|
|
|
self.specialBreakpoints.append(newSpecial(ns + "QMessageLogger::fatal"))
|
|
|
|
|
2014-03-11 13:24:19 +01:00
|
|
|
#def threadname(self, maximalStackDepth, objectPrivateType):
|
|
|
|
# e = gdb.selected_frame()
|
|
|
|
# out = ""
|
|
|
|
# ns = self.qtNamespace()
|
|
|
|
# while True:
|
|
|
|
# maximalStackDepth -= 1
|
|
|
|
# if maximalStackDepth < 0:
|
|
|
|
# break
|
|
|
|
# e = e.older()
|
|
|
|
# if e == None or e.name() == None:
|
|
|
|
# break
|
|
|
|
# if e.name() == ns + "QThreadPrivate::start" \
|
|
|
|
# or e.name() == "_ZN14QThreadPrivate5startEPv@4":
|
|
|
|
# try:
|
|
|
|
# thrptr = e.read_var("thr").dereference()
|
|
|
|
# d_ptr = thrptr["d_ptr"]["d"].cast(objectPrivateType).dereference()
|
|
|
|
# try:
|
|
|
|
# objectName = d_ptr["objectName"]
|
|
|
|
# except: # Qt 5
|
|
|
|
# p = d_ptr["extraData"]
|
|
|
|
# if not self.isNull(p):
|
|
|
|
# objectName = p.dereference()["objectName"]
|
|
|
|
# if not objectName is None:
|
2016-09-06 08:54:43 +02:00
|
|
|
# (data, size, alloc) = self.stringData(objectName)
|
2014-03-11 13:24:19 +01:00
|
|
|
# if size > 0:
|
|
|
|
# s = self.readMemory(data, 2 * size)
|
|
|
|
#
|
|
|
|
# thread = gdb.selected_thread()
|
2015-12-11 13:28:21 +01:00
|
|
|
# inner = '{valueencoded="uf16:2:0",id="'
|
2014-03-11 13:24:19 +01:00
|
|
|
# inner += str(thread.num) + '",value="'
|
|
|
|
# inner += s
|
|
|
|
# #inner += self.encodeString(objectName)
|
|
|
|
# inner += '"},'
|
|
|
|
#
|
|
|
|
# out += inner
|
|
|
|
# except:
|
|
|
|
# pass
|
|
|
|
# return out
|
2013-10-30 12:38:29 +01:00
|
|
|
|
|
|
|
def threadnames(self, maximalStackDepth):
|
2013-11-20 00:34:58 +01:00
|
|
|
# FIXME: This needs a proper implementation for MinGW, and only there.
|
2014-03-11 13:24:19 +01:00
|
|
|
# Linux, Mac and QNX mirror the objectName() to the underlying threads,
|
2013-11-20 00:34:58 +01:00
|
|
|
# so we get the names already as part of the -thread-info output.
|
|
|
|
return '[]'
|
2014-03-11 13:24:19 +01:00
|
|
|
#out = '['
|
|
|
|
#oldthread = gdb.selected_thread()
|
|
|
|
#if oldthread:
|
|
|
|
# try:
|
|
|
|
# objectPrivateType = gdb.lookup_type(ns + "QObjectPrivate").pointer()
|
|
|
|
# inferior = self.selectedInferior()
|
|
|
|
# for thread in inferior.threads():
|
|
|
|
# thread.switch()
|
|
|
|
# out += self.threadname(maximalStackDepth, objectPrivateType)
|
|
|
|
# except:
|
|
|
|
# pass
|
|
|
|
# oldthread.switch()
|
|
|
|
#return out + ']'
|
2013-10-30 12:38:29 +01:00
|
|
|
|
|
|
|
|
2013-10-30 15:07:54 +01:00
|
|
|
def importPlainDumper(self, printer):
|
|
|
|
name = printer.name.replace("::", "__")
|
|
|
|
self.qqDumpers[name] = PlainDumper(printer)
|
|
|
|
self.qqFormats[name] = ""
|
|
|
|
|
|
|
|
def importPlainDumpers(self):
|
|
|
|
for obj in gdb.objfiles():
|
|
|
|
for printers in obj.pretty_printers + gdb.pretty_printers:
|
|
|
|
for printer in printers.subprinters:
|
|
|
|
self.importPlainDumper(printer)
|
|
|
|
|
|
|
|
def qtNamespace(self):
|
2014-03-27 13:53:33 +01:00
|
|
|
if not self.currentQtNamespaceGuess is None:
|
|
|
|
return self.currentQtNamespaceGuess
|
|
|
|
|
2014-03-07 15:48:13 +01:00
|
|
|
# This only works when called from a valid frame.
|
|
|
|
try:
|
|
|
|
cand = "QArrayData::shared_null"
|
|
|
|
symbol = gdb.lookup_symbol(cand)[0]
|
|
|
|
if symbol:
|
|
|
|
ns = symbol.name[:-len(cand)]
|
|
|
|
self.qtNamespaceToReport = ns
|
|
|
|
self.qtNamespace = lambda: ns
|
|
|
|
return ns
|
|
|
|
except:
|
|
|
|
pass
|
|
|
|
|
2013-10-30 15:07:54 +01:00
|
|
|
try:
|
2014-03-07 15:48:13 +01:00
|
|
|
# This is Qt, but not 5.x.
|
|
|
|
cand = "QByteArray::shared_null"
|
|
|
|
symbol = gdb.lookup_symbol(cand)[0]
|
|
|
|
if symbol:
|
|
|
|
ns = symbol.name[:-len(cand)]
|
|
|
|
self.qtNamespaceToReport = ns
|
|
|
|
self.qtNamespace = lambda: ns
|
|
|
|
self.fallbackQtVersion = 0x40800
|
|
|
|
return ns
|
2013-10-30 15:07:54 +01:00
|
|
|
except:
|
|
|
|
pass
|
|
|
|
|
2014-07-24 13:22:19 +02:00
|
|
|
try:
|
2014-10-10 12:05:47 +02:00
|
|
|
# Last fall backs.
|
2014-07-24 13:22:19 +02:00
|
|
|
s = gdb.execute("ptype QByteArray", to_string=True)
|
2014-10-10 12:05:47 +02:00
|
|
|
if s.find("QMemArray") >= 0:
|
|
|
|
# Qt 3.
|
|
|
|
self.qtNamespaceToReport = ""
|
|
|
|
self.qtNamespace = lambda: ""
|
|
|
|
self.qtVersion = lambda: 0x30308
|
|
|
|
self.fallbackQtVersion = 0x30308
|
|
|
|
return ""
|
|
|
|
# Seemingly needed with Debian's GDB 7.4.1
|
2016-06-03 09:36:34 +02:00
|
|
|
pos1 = s.find("class")
|
|
|
|
pos2 = s.find("QByteArray")
|
|
|
|
if pos1 > -1 and pos2 > -1:
|
|
|
|
ns = s[s.find("class") + 6:s.find("QByteArray")]
|
2014-07-24 13:22:19 +02:00
|
|
|
self.qtNamespaceToReport = ns
|
|
|
|
self.qtNamespace = lambda: ns
|
|
|
|
return ns
|
|
|
|
except:
|
|
|
|
pass
|
2014-03-27 13:53:33 +01:00
|
|
|
self.currentQtNamespaceGuess = ""
|
2014-03-07 15:48:13 +01:00
|
|
|
return ""
|
2013-10-30 15:07:54 +01:00
|
|
|
|
2015-02-10 13:40:26 +01:00
|
|
|
def assignValue(self, args):
|
|
|
|
typeName = self.hexdecode(args['type'])
|
|
|
|
expr = self.hexdecode(args['expr'])
|
|
|
|
value = self.hexdecode(args['value'])
|
|
|
|
simpleType = int(args['simpleType'])
|
2013-10-30 15:07:54 +01:00
|
|
|
ns = self.qtNamespace()
|
2013-11-20 18:55:09 +01:00
|
|
|
if typeName.startswith(ns):
|
|
|
|
typeName = typeName[len(ns):]
|
|
|
|
typeName = typeName.replace("::", "__")
|
|
|
|
pos = typeName.find('<')
|
2013-10-30 15:07:54 +01:00
|
|
|
if pos != -1:
|
2013-11-20 18:55:09 +01:00
|
|
|
typeName = typeName[0:pos]
|
2015-02-10 13:40:26 +01:00
|
|
|
if typeName in self.qqEditable and not simpleType:
|
|
|
|
#self.qqEditable[typeName](self, expr, value)
|
|
|
|
expr = gdb.parse_and_eval(expr)
|
|
|
|
self.qqEditable[typeName](self, expr, value)
|
2013-10-30 15:07:54 +01:00
|
|
|
else:
|
2015-02-10 13:40:26 +01:00
|
|
|
cmd = "set variable (%s)=%s" % (expr, value)
|
2013-11-20 18:55:09 +01:00
|
|
|
gdb.execute(cmd)
|
2013-10-30 15:07:54 +01:00
|
|
|
|
2016-09-26 14:29:16 +02:00
|
|
|
def nativeDynamicTypeName(self, address, baseType):
|
2016-09-28 23:03:48 +02:00
|
|
|
try:
|
|
|
|
vtbl = gdb.execute("info symbol {%s*}0x%x" % (baseType.name, address), to_string = True)
|
|
|
|
except:
|
|
|
|
return None
|
2016-09-26 14:29:16 +02:00
|
|
|
pos1 = vtbl.find("vtable ")
|
|
|
|
if pos1 == -1:
|
|
|
|
return None
|
|
|
|
pos1 += 11
|
|
|
|
pos2 = vtbl.find(" +", pos1)
|
|
|
|
if pos2 == -1:
|
|
|
|
return None
|
|
|
|
return vtbl[pos1 : pos2]
|
2013-10-31 10:28:11 +01:00
|
|
|
|
2014-01-10 20:01:35 +01:00
|
|
|
def enumExpression(self, enumType, enumValue):
|
|
|
|
return self.qtNamespace() + "Qt::" + enumValue
|
|
|
|
|
2016-09-06 08:54:43 +02:00
|
|
|
def lookupNativeType(self, typeName):
|
|
|
|
nativeType = self.lookupNativeTypeHelper(typeName)
|
|
|
|
if not nativeType is None:
|
|
|
|
self.check(isinstance(nativeType, gdb.Type))
|
|
|
|
return nativeType
|
|
|
|
|
|
|
|
def lookupNativeTypeHelper(self, typeName):
|
|
|
|
typeobj = self.typeCache.get(typeName)
|
|
|
|
#warn("LOOKUP 1: %s -> %s" % (typeName, typeobj))
|
2014-12-12 09:00:30 +01:00
|
|
|
if not typeobj is None:
|
|
|
|
return typeobj
|
2013-10-31 10:28:11 +01:00
|
|
|
|
2016-09-06 08:54:43 +02:00
|
|
|
if typeName == "void":
|
|
|
|
typeobj = gdb.lookup_type(typeName)
|
|
|
|
self.typeCache[typeName] = typeobj
|
|
|
|
self.typesToReport[typeName] = typeobj
|
2014-12-12 09:00:30 +01:00
|
|
|
return typeobj
|
2013-10-31 10:28:11 +01:00
|
|
|
|
|
|
|
#try:
|
2016-09-06 08:54:43 +02:00
|
|
|
# typeobj = gdb.parse_and_eval("{%s}&main" % typeName).typeobj
|
2014-12-12 09:00:30 +01:00
|
|
|
# if not typeobj is None:
|
2016-09-06 08:54:43 +02:00
|
|
|
# self.typeCache[typeName] = typeobj
|
|
|
|
# self.typesToReport[typeName] = typeobj
|
2014-12-12 09:00:30 +01:00
|
|
|
# return typeobj
|
2013-10-31 10:28:11 +01:00
|
|
|
#except:
|
|
|
|
# pass
|
|
|
|
|
|
|
|
# See http://sourceware.org/bugzilla/show_bug.cgi?id=13269
|
|
|
|
# gcc produces "{anonymous}", gdb "(anonymous namespace)"
|
|
|
|
# "<unnamed>" has been seen too. The only thing gdb
|
|
|
|
# understands when reading things back is "(anonymous namespace)"
|
2016-09-06 08:54:43 +02:00
|
|
|
if typeName.find("{anonymous}") != -1:
|
|
|
|
ts = typeName
|
2013-10-31 10:28:11 +01:00
|
|
|
ts = ts.replace("{anonymous}", "(anonymous namespace)")
|
2016-09-06 08:54:43 +02:00
|
|
|
typeobj = self.lookupNativeType(ts)
|
2014-12-12 09:00:30 +01:00
|
|
|
if not typeobj is None:
|
2016-09-06 08:54:43 +02:00
|
|
|
self.typeCache[typeName] = typeobj
|
|
|
|
self.typesToReport[typeName] = typeobj
|
2014-12-12 09:00:30 +01:00
|
|
|
return typeobj
|
2013-10-31 10:28:11 +01:00
|
|
|
|
2016-09-06 08:54:43 +02:00
|
|
|
#warn(" RESULT FOR 7.2: '%s': %s" % (typeName, typeobj))
|
2013-10-31 10:28:11 +01:00
|
|
|
|
|
|
|
# This part should only trigger for
|
|
|
|
# gdb 7.1 for types with namespace separators.
|
|
|
|
# And anonymous namespaces.
|
|
|
|
|
2016-09-06 08:54:43 +02:00
|
|
|
ts = typeName
|
2013-10-31 10:28:11 +01:00
|
|
|
while True:
|
|
|
|
#warn("TS: '%s'" % ts)
|
|
|
|
if ts.startswith("class "):
|
|
|
|
ts = ts[6:]
|
|
|
|
elif ts.startswith("struct "):
|
|
|
|
ts = ts[7:]
|
|
|
|
elif ts.startswith("const "):
|
|
|
|
ts = ts[6:]
|
|
|
|
elif ts.startswith("volatile "):
|
|
|
|
ts = ts[9:]
|
|
|
|
elif ts.startswith("enum "):
|
|
|
|
ts = ts[5:]
|
|
|
|
elif ts.endswith(" const"):
|
|
|
|
ts = ts[:-6]
|
|
|
|
elif ts.endswith(" volatile"):
|
|
|
|
ts = ts[:-9]
|
|
|
|
elif ts.endswith("*const"):
|
|
|
|
ts = ts[:-5]
|
|
|
|
elif ts.endswith("*volatile"):
|
|
|
|
ts = ts[:-8]
|
|
|
|
else:
|
|
|
|
break
|
|
|
|
|
|
|
|
if ts.endswith('*'):
|
2016-09-06 08:54:43 +02:00
|
|
|
typeobj = self.lookupNativeType(ts[0:-1])
|
2014-12-12 09:00:30 +01:00
|
|
|
if not typeobj is None:
|
|
|
|
typeobj = typeobj.pointer()
|
2016-09-06 08:54:43 +02:00
|
|
|
self.typeCache[typeName] = typeobj
|
|
|
|
self.typesToReport[typeName] = typeobj
|
2014-12-12 09:00:30 +01:00
|
|
|
return typeobj
|
2013-10-31 10:28:11 +01:00
|
|
|
|
|
|
|
try:
|
2016-09-06 08:54:43 +02:00
|
|
|
#warn("LOOKING UP 1 '%s'" % ts)
|
2014-12-12 09:00:30 +01:00
|
|
|
typeobj = gdb.lookup_type(ts)
|
2013-10-31 10:28:11 +01:00
|
|
|
except RuntimeError as error:
|
2016-09-06 08:54:43 +02:00
|
|
|
#warn("LOOKING UP 2 '%s' ERROR %s" % (ts, error))
|
2013-10-31 10:28:11 +01:00
|
|
|
# See http://sourceware.org/bugzilla/show_bug.cgi?id=11912
|
|
|
|
exp = "(class '%s'*)0" % ts
|
|
|
|
try:
|
2016-09-06 08:54:43 +02:00
|
|
|
typeobj = self.parse_and_eval(exp).type.target()
|
|
|
|
#warn("LOOKING UP 3 '%s'" % typeobj)
|
2013-10-31 10:28:11 +01:00
|
|
|
except:
|
|
|
|
# Can throw "RuntimeError: No type named class Foo."
|
|
|
|
pass
|
|
|
|
except:
|
|
|
|
#warn("LOOKING UP '%s' FAILED" % ts)
|
|
|
|
pass
|
|
|
|
|
2014-12-12 09:00:30 +01:00
|
|
|
if not typeobj is None:
|
2016-09-06 08:54:43 +02:00
|
|
|
#warn("CACHING: %s" % typeobj)
|
|
|
|
self.typeCache[typeName] = typeobj
|
|
|
|
self.typesToReport[typeName] = typeobj
|
2013-10-31 10:28:11 +01:00
|
|
|
|
|
|
|
# This could still be None as gdb.lookup_type("char[3]") generates
|
|
|
|
# "RuntimeError: No type named char[3]"
|
2016-09-06 08:54:43 +02:00
|
|
|
#self.typeCache[typeName] = typeobj
|
|
|
|
#self.typesToReport[typeName] = typeobj
|
2014-12-12 09:00:30 +01:00
|
|
|
return typeobj
|
2013-10-31 10:28:11 +01:00
|
|
|
|
2015-10-08 16:19:57 +02:00
|
|
|
def doContinue(self):
|
|
|
|
gdb.execute('continue')
|
|
|
|
|
2015-10-27 16:13:04 +01:00
|
|
|
def fetchStack(self, args):
|
2016-10-11 14:58:55 +02:00
|
|
|
def fromNativePath(string):
|
|
|
|
return string.replace('\\', '/')
|
2015-03-01 11:49:19 +02:00
|
|
|
|
2016-10-11 14:58:55 +02:00
|
|
|
extraQml = int(args.get('extraqml', '0'))
|
2015-02-11 16:05:55 +01:00
|
|
|
limit = int(args['limit'])
|
|
|
|
if limit <= 0:
|
|
|
|
limit = 10000
|
|
|
|
|
2015-10-08 16:19:57 +02:00
|
|
|
self.prepare(args)
|
2014-12-05 18:45:54 +01:00
|
|
|
self.output = []
|
|
|
|
|
|
|
|
i = 0
|
2016-10-11 14:58:55 +02:00
|
|
|
if extraQml:
|
|
|
|
frame = gdb.newest_frame()
|
|
|
|
ns = self.qtNamespace()
|
|
|
|
needle = self.qtNamespace() + 'QV4::ExecutionEngine'
|
|
|
|
pat = "%sqt_v4StackTrace(((%sQV4::ExecutionEngine *)0x%x)->currentContext)"
|
|
|
|
done = False
|
|
|
|
while i < limit and frame and not done:
|
|
|
|
block = None
|
|
|
|
try:
|
|
|
|
block = frame.block()
|
|
|
|
except:
|
|
|
|
pass
|
|
|
|
if block is not None:
|
|
|
|
for symbol in block:
|
|
|
|
if symbol.is_variable or symbol.is_argument:
|
|
|
|
value = symbol.value(frame)
|
|
|
|
typeobj = value.type
|
|
|
|
if typeobj.code == gdb.TYPE_CODE_PTR:
|
|
|
|
dereftype = typeobj.target().unqualified()
|
|
|
|
if dereftype.name == needle:
|
|
|
|
addr = toInteger(value)
|
|
|
|
expr = pat % (ns, ns, addr)
|
|
|
|
res = str(gdb.parse_and_eval(expr))
|
|
|
|
pos = res.find('"stack=[')
|
|
|
|
if pos != -1:
|
|
|
|
res = res[pos + 8:-2]
|
|
|
|
res = res.replace('\\\"', '\"')
|
|
|
|
res = res.replace('func=', 'function=')
|
|
|
|
self.put(res)
|
|
|
|
done = True
|
|
|
|
break
|
|
|
|
frame = frame.older()
|
|
|
|
i += 1
|
|
|
|
|
|
|
|
frame = gdb.newest_frame()
|
2015-01-22 12:05:00 +01:00
|
|
|
self.currentCallContext = None
|
2015-02-11 16:05:55 +01:00
|
|
|
while i < limit and frame:
|
2014-12-05 18:45:54 +01:00
|
|
|
with OutputSafer(self):
|
|
|
|
name = frame.name()
|
|
|
|
functionName = "??" if name is None else name
|
|
|
|
fileName = ""
|
|
|
|
objfile = ""
|
2015-10-08 16:19:57 +02:00
|
|
|
symtab = ""
|
2014-12-05 18:45:54 +01:00
|
|
|
pc = frame.pc()
|
|
|
|
sal = frame.find_sal()
|
|
|
|
line = -1
|
|
|
|
if sal:
|
|
|
|
line = sal.line
|
|
|
|
symtab = sal.symtab
|
|
|
|
if not symtab is None:
|
2015-03-01 11:49:19 +02:00
|
|
|
objfile = fromNativePath(symtab.objfile.filename)
|
2015-11-20 09:29:51 -06:00
|
|
|
fullname = symtab.fullname()
|
|
|
|
if fullname is None:
|
|
|
|
fileName = ""
|
|
|
|
else:
|
|
|
|
fileName = fromNativePath(fullname)
|
2015-10-08 16:19:57 +02:00
|
|
|
|
2015-10-14 13:26:22 +02:00
|
|
|
if self.nativeMixed and functionName == "qt_qmlDebugMessageAvailable":
|
2015-10-08 16:19:57 +02:00
|
|
|
interpreterStack = self.extractInterpreterStack()
|
|
|
|
#print("EXTRACTED INTEPRETER STACK: %s" % interpreterStack)
|
|
|
|
for interpreterFrame in interpreterStack.get('frames', []):
|
|
|
|
function = interpreterFrame.get('function', '')
|
|
|
|
fileName = interpreterFrame.get('file', '')
|
|
|
|
language = interpreterFrame.get('language', '')
|
|
|
|
lineNumber = interpreterFrame.get('line', 0)
|
|
|
|
context = interpreterFrame.get('context', 0)
|
|
|
|
|
|
|
|
self.put(('frame={function="%s",file="%s",'
|
|
|
|
'line="%s",language="%s",context="%s"}')
|
|
|
|
% (function, fileName, lineNumber, language, context))
|
|
|
|
|
|
|
|
if False and self.isInternalInterpreterFrame(functionName):
|
2015-01-22 12:05:00 +01:00
|
|
|
frame = frame.older()
|
2015-10-08 16:19:57 +02:00
|
|
|
self.put(('frame={address="0x%x",function="%s",'
|
|
|
|
'file="%s",line="%s",'
|
|
|
|
'module="%s",language="c",usable="0"}') %
|
|
|
|
(pc, functionName, fileName, line, objfile))
|
2015-01-22 12:05:00 +01:00
|
|
|
i += 1
|
|
|
|
frame = frame.older()
|
|
|
|
continue
|
|
|
|
|
2015-10-08 16:19:57 +02:00
|
|
|
self.put(('frame={level="%s",address="0x%x",function="%s",'
|
|
|
|
'file="%s",line="%s",module="%s",language="c"}') %
|
|
|
|
(i, pc, functionName, fileName, line, objfile))
|
2014-12-05 18:45:54 +01:00
|
|
|
|
|
|
|
frame = frame.older()
|
|
|
|
i += 1
|
2015-10-08 16:19:57 +02:00
|
|
|
safePrint('frames=[' + ','.join(self.output) + ']')
|
2014-12-05 18:45:54 +01:00
|
|
|
|
2015-02-04 16:27:46 +01:00
|
|
|
def createResolvePendingBreakpointsHookBreakpoint(self, args):
|
2015-02-04 10:48:33 +01:00
|
|
|
class Resolver(gdb.Breakpoint):
|
2015-02-04 16:27:46 +01:00
|
|
|
def __init__(self, dumper, args):
|
2015-02-04 10:48:33 +01:00
|
|
|
self.dumper = dumper
|
2015-02-04 16:27:46 +01:00
|
|
|
self.args = args
|
2015-10-08 16:19:57 +02:00
|
|
|
spec = "qt_qmlDebugConnectorOpen"
|
2015-02-04 10:48:33 +01:00
|
|
|
super(Resolver, self).\
|
|
|
|
__init__(spec, gdb.BP_BREAKPOINT, internal=True, temporary=False)
|
|
|
|
|
|
|
|
def stop(self):
|
2015-10-14 13:26:22 +02:00
|
|
|
self.dumper.resolvePendingInterpreterBreakpoint(args)
|
2015-02-04 10:48:33 +01:00
|
|
|
self.enabled = False
|
|
|
|
return False
|
|
|
|
|
2015-10-09 15:00:20 +02:00
|
|
|
self.interpreterBreakpointResolvers.append(Resolver(self, args))
|
2015-02-04 10:48:33 +01:00
|
|
|
|
2015-02-11 12:20:21 +01:00
|
|
|
def exitGdb(self, _):
|
|
|
|
gdb.execute("quit")
|
2015-02-04 10:48:33 +01:00
|
|
|
|
2016-09-28 12:04:27 +02:00
|
|
|
def reportResult(self, msg, args):
|
|
|
|
print(msg)
|
2015-03-18 16:48:57 +01:00
|
|
|
|
2015-02-11 17:51:15 +01:00
|
|
|
def profile1(self, args):
|
|
|
|
"""Internal profiling"""
|
|
|
|
import tempfile
|
|
|
|
import cProfile
|
|
|
|
tempDir = tempfile.gettempdir() + "/bbprof"
|
2015-10-08 16:19:57 +02:00
|
|
|
cProfile.run('theDumper.fetchVariables(%s)' % args, tempDir)
|
2015-02-11 17:51:15 +01:00
|
|
|
import pstats
|
|
|
|
pstats.Stats(tempDir).sort_stats('time').print_stats()
|
|
|
|
|
|
|
|
def profile2(self, args):
|
|
|
|
import timeit
|
2015-10-08 16:19:57 +02:00
|
|
|
print(timeit.repeat('theDumper.fetchVariables(%s)' % args,
|
2015-02-11 17:51:15 +01:00
|
|
|
'from __main__ import theDumper', number=10))
|
|
|
|
|
|
|
|
|
2015-02-04 10:48:33 +01:00
|
|
|
|
Debugger: Make dumpers somewhat work in command line GDB
With
python sys.path.insert(1, '/data/dev/creator/share/qtcreator/debugger/')
python from gdbbridge import *
in .gdbinit there's a new "GDB command", called "pp".
With code like
int main(int argc, char *argv[])
{
QString ss = "Hello";
QApplication app(argc, argv);
app.setObjectName(ss);
// break here
}
the 'pp' command can be used as follows:
(gdb) pp app
app =
[
<Myns::QGuiApplication> = {"Hello"}
staticMetaObject = <Myns::QMetaObject> = {""}
[parent] = <Myns::QObject *> = {"0x0"}
[children] = <Myns::QObjectList> = {"<3 items>"}
[properties] = "<>0 items>"
[methods] = "<6 items>"
[signals] = "<1 items>"
],<Myns::QApplication> = {"Hello"}
(gdb) pp app [properties],[children]
app =
[
<Myns::QGuiApplication> = {"Hello"}
staticMetaObject = <Myns::QMetaObject> = {""}
[parent] = <Myns::QObject *> = {"0x0"}
[children] = [
<Myns::QObject> = {""}
<Myns::QObject> = {""}
<Myns::QObject> = {"fusion"}
],<Myns::QObjectList> = {"<3 items>"}
[properties] = [
windowIcon = <Myns::QVariant (QIcon)> = {""}
cursorFlashTime = <Myns::QVariant (int)> = {"1000"}
doubleClickInterval = <Myns::QVariant (int)> = {"400"}
keyboardInputInterval = <Myns::QVariant (int)> = {"400"}
wheelScrollLines = <Myns::QVariant (int)> = {"3"}
globalStrut = <Myns::QVariant (QSize)> = {"(0, 0)"}
startDragTime = <Myns::QVariant (int)> = {"500"}
startDragDistance = <Myns::QVariant (int)> = {"10"}
styleSheet = <Myns::QVariant (QString)> = {""}
autoSipEnabled = <Myns::QVariant (bool)> = {"true"}
],"<10 items>"
[methods] = "<6 items>"
[signals] = "<1 items>"
],<Myns::QApplication> = {"Hello"}
(gdb) pp ss
ss =
<Myns::QString> = {"Hello"}
Change-Id: I6e4714a5cfe34c38917500d114ad9a70d20cff39
Reviewed-by: Christian Stenger <christian.stenger@digia.com>
Reviewed-by: hjk <hjk121@nokiamail.com>
2014-06-13 17:45:34 +02:00
|
|
|
class CliDumper(Dumper):
|
|
|
|
def __init__(self):
|
|
|
|
Dumper.__init__(self)
|
|
|
|
self.childrenPrefix = '['
|
|
|
|
self.chidrenSuffix = '] '
|
|
|
|
self.indent = 0
|
|
|
|
self.isCli = True
|
|
|
|
|
|
|
|
|
|
|
|
def put(self, line):
|
|
|
|
if self.output.endswith('\n'):
|
|
|
|
self.output = self.output[0:-1]
|
|
|
|
self.output += line
|
|
|
|
|
|
|
|
def putNumChild(self, numchild):
|
|
|
|
pass
|
|
|
|
|
2016-10-25 15:32:13 +02:00
|
|
|
def putOriginalAddress(self, address):
|
Debugger: Make dumpers somewhat work in command line GDB
With
python sys.path.insert(1, '/data/dev/creator/share/qtcreator/debugger/')
python from gdbbridge import *
in .gdbinit there's a new "GDB command", called "pp".
With code like
int main(int argc, char *argv[])
{
QString ss = "Hello";
QApplication app(argc, argv);
app.setObjectName(ss);
// break here
}
the 'pp' command can be used as follows:
(gdb) pp app
app =
[
<Myns::QGuiApplication> = {"Hello"}
staticMetaObject = <Myns::QMetaObject> = {""}
[parent] = <Myns::QObject *> = {"0x0"}
[children] = <Myns::QObjectList> = {"<3 items>"}
[properties] = "<>0 items>"
[methods] = "<6 items>"
[signals] = "<1 items>"
],<Myns::QApplication> = {"Hello"}
(gdb) pp app [properties],[children]
app =
[
<Myns::QGuiApplication> = {"Hello"}
staticMetaObject = <Myns::QMetaObject> = {""}
[parent] = <Myns::QObject *> = {"0x0"}
[children] = [
<Myns::QObject> = {""}
<Myns::QObject> = {""}
<Myns::QObject> = {"fusion"}
],<Myns::QObjectList> = {"<3 items>"}
[properties] = [
windowIcon = <Myns::QVariant (QIcon)> = {""}
cursorFlashTime = <Myns::QVariant (int)> = {"1000"}
doubleClickInterval = <Myns::QVariant (int)> = {"400"}
keyboardInputInterval = <Myns::QVariant (int)> = {"400"}
wheelScrollLines = <Myns::QVariant (int)> = {"3"}
globalStrut = <Myns::QVariant (QSize)> = {"(0, 0)"}
startDragTime = <Myns::QVariant (int)> = {"500"}
startDragDistance = <Myns::QVariant (int)> = {"10"}
styleSheet = <Myns::QVariant (QString)> = {""}
autoSipEnabled = <Myns::QVariant (bool)> = {"true"}
],"<10 items>"
[methods] = "<6 items>"
[signals] = "<1 items>"
],<Myns::QApplication> = {"Hello"}
(gdb) pp ss
ss =
<Myns::QString> = {"Hello"}
Change-Id: I6e4714a5cfe34c38917500d114ad9a70d20cff39
Reviewed-by: Christian Stenger <christian.stenger@digia.com>
Reviewed-by: hjk <hjk121@nokiamail.com>
2014-06-13 17:45:34 +02:00
|
|
|
pass
|
|
|
|
|
2015-10-08 16:19:57 +02:00
|
|
|
def fetchVariables(self, args):
|
2015-04-15 12:38:11 +02:00
|
|
|
args['fancy'] = 1
|
2015-10-27 15:50:41 +01:00
|
|
|
args['passexception'] = 1
|
2015-04-15 12:38:11 +02:00
|
|
|
args['autoderef'] = 1
|
2015-12-16 14:13:44 +01:00
|
|
|
args['qobjectnames'] = 1
|
2015-04-15 12:38:11 +02:00
|
|
|
name = args['varlist']
|
|
|
|
self.prepare(args)
|
Debugger: Make dumpers somewhat work in command line GDB
With
python sys.path.insert(1, '/data/dev/creator/share/qtcreator/debugger/')
python from gdbbridge import *
in .gdbinit there's a new "GDB command", called "pp".
With code like
int main(int argc, char *argv[])
{
QString ss = "Hello";
QApplication app(argc, argv);
app.setObjectName(ss);
// break here
}
the 'pp' command can be used as follows:
(gdb) pp app
app =
[
<Myns::QGuiApplication> = {"Hello"}
staticMetaObject = <Myns::QMetaObject> = {""}
[parent] = <Myns::QObject *> = {"0x0"}
[children] = <Myns::QObjectList> = {"<3 items>"}
[properties] = "<>0 items>"
[methods] = "<6 items>"
[signals] = "<1 items>"
],<Myns::QApplication> = {"Hello"}
(gdb) pp app [properties],[children]
app =
[
<Myns::QGuiApplication> = {"Hello"}
staticMetaObject = <Myns::QMetaObject> = {""}
[parent] = <Myns::QObject *> = {"0x0"}
[children] = [
<Myns::QObject> = {""}
<Myns::QObject> = {""}
<Myns::QObject> = {"fusion"}
],<Myns::QObjectList> = {"<3 items>"}
[properties] = [
windowIcon = <Myns::QVariant (QIcon)> = {""}
cursorFlashTime = <Myns::QVariant (int)> = {"1000"}
doubleClickInterval = <Myns::QVariant (int)> = {"400"}
keyboardInputInterval = <Myns::QVariant (int)> = {"400"}
wheelScrollLines = <Myns::QVariant (int)> = {"3"}
globalStrut = <Myns::QVariant (QSize)> = {"(0, 0)"}
startDragTime = <Myns::QVariant (int)> = {"500"}
startDragDistance = <Myns::QVariant (int)> = {"10"}
styleSheet = <Myns::QVariant (QString)> = {""}
autoSipEnabled = <Myns::QVariant (bool)> = {"true"}
],"<10 items>"
[methods] = "<6 items>"
[signals] = "<1 items>"
],<Myns::QApplication> = {"Hello"}
(gdb) pp ss
ss =
<Myns::QString> = {"Hello"}
Change-Id: I6e4714a5cfe34c38917500d114ad9a70d20cff39
Reviewed-by: Christian Stenger <christian.stenger@digia.com>
Reviewed-by: hjk <hjk121@nokiamail.com>
2014-06-13 17:45:34 +02:00
|
|
|
self.output = name + ' = '
|
|
|
|
frame = gdb.selected_frame()
|
|
|
|
value = frame.read_var(name)
|
|
|
|
with TopLevelItem(self, name):
|
|
|
|
self.putItem(value)
|
|
|
|
return self.output
|
|
|
|
|
2013-10-30 12:38:29 +01:00
|
|
|
# Global instance.
|
2015-09-25 08:45:20 +02:00
|
|
|
#if gdb.parameter('height') is None:
|
|
|
|
theDumper = Dumper()
|
|
|
|
#else:
|
|
|
|
# import codecs
|
|
|
|
# theDumper = CliDumper()
|
2013-10-30 12:38:29 +01:00
|
|
|
|
2015-02-11 17:51:15 +01:00
|
|
|
######################################################################
|
2013-10-30 12:38:29 +01:00
|
|
|
#
|
|
|
|
# ThreadNames Command
|
|
|
|
#
|
|
|
|
#######################################################################
|
2013-06-06 18:28:53 +02:00
|
|
|
|
|
|
|
def threadnames(arg):
|
2013-10-30 12:38:29 +01:00
|
|
|
return theDumper.threadnames(int(arg))
|
2013-05-15 15:42:55 +02:00
|
|
|
|
|
|
|
registerCommand("threadnames", threadnames)
|
|
|
|
|
2015-01-22 12:05:00 +01:00
|
|
|
#######################################################################
|
|
|
|
#
|
|
|
|
# Native Mixed
|
|
|
|
#
|
|
|
|
#######################################################################
|
|
|
|
|
2015-10-14 13:26:22 +02:00
|
|
|
class InterpreterMessageBreakpoint(gdb.Breakpoint):
|
2015-10-08 16:19:57 +02:00
|
|
|
def __init__(self):
|
2015-10-14 13:26:22 +02:00
|
|
|
spec = "qt_qmlDebugMessageAvailable"
|
|
|
|
super(InterpreterMessageBreakpoint, self).\
|
2015-10-08 16:19:57 +02:00
|
|
|
__init__(spec, gdb.BP_BREAKPOINT, internal=True)
|
|
|
|
|
|
|
|
def stop(self):
|
2015-10-09 15:00:20 +02:00
|
|
|
print("Interpreter event received.")
|
2015-10-14 13:26:22 +02:00
|
|
|
return theDumper.handleInterpreterMessage()
|
2015-10-08 16:19:57 +02:00
|
|
|
|
2016-10-25 15:32:13 +02:00
|
|
|
#InterpreterMessageBreakpoint()
|