diff options
author | hjk <hjk@qt.io> | 2017-03-15 09:19:12 +0100 |
---|---|---|
committer | hjk <hjk@qt.io> | 2017-03-15 11:34:58 +0000 |
commit | 68a4a3db943884c152694bfcc3c6e8f5f069c2ed (patch) | |
tree | 813bee8c7f0c95c55012c1b979ce0836086a2afd | |
parent | 802eff34850a4d0e648d87069ad5d4790c08ee86 (diff) | |
download | qt-creator-68a4a3db943884c152694bfcc3c6e8f5f069c2ed.tar.gz |
Debugger: Use gdb provided hooks to track loaded shared objects
Change-Id: I4f3cce56910e0e737febaf0ff442956b78b19c30
Reviewed-by: Christian Stenger <christian.stenger@qt.io>
-rw-r--r-- | share/qtcreator/debugger/gdbbridge.py | 111 |
1 files changed, 63 insertions, 48 deletions
diff --git a/share/qtcreator/debugger/gdbbridge.py b/share/qtcreator/debugger/gdbbridge.py index 2506ec10e3..fc21ecb212 100644 --- a/share/qtcreator/debugger/gdbbridge.py +++ b/share/qtcreator/debugger/gdbbridge.py @@ -970,58 +970,60 @@ class Dumper(DumperBase): except: return 0 + def handleNewObjectFile(self, objfile): + name = objfile.filename + if self.isWindowsTarget(): + isQtCoreObjFile = name.find('Qt5Cored.dll') >= 0 or name.find('Qt5Core.dll') >= 0 + else: + isQtCoreObjFile = name.find('/libQt5Core') >= 0 + if isQtCoreObjFile: + self.handleQtCoreLoaded(objfile) + + def handleQtCoreLoaded(self, objfile): + fd, tmppath = tempfile.mkstemp() + os.close(fd) + cmd = 'maint print msymbols %s "%s"' % (tmppath, objfile.filename) + try: + symbols = gdb.execute(cmd, to_string = True) + except: + pass + ns = '' + with open(tmppath) as f: + for line in f: + if line.find('msgHandlerGrabbed ') >= 0: + # [11] b 0x7ffff683c000 _ZN4MynsL17msgHandlerGrabbedE + # section .tbss Myns::msgHandlerGrabbed qlogging.cpp + ns = re.split('_ZN?(\d*)(\w*)L17msgHandlerGrabbedE? ', line)[2] + if len(ns): + ns += '::' + break + os.remove(tmppath) + + lenns = len(ns) + strns = ('%d%s' % (lenns - 2, ns[:lenns - 2])) if lenns else '' + + if lenns: + sym = '_ZN%s7QObject11customEventEPNS_6QEventE' % strns + else: + sym = '_ZN7QObject11customEventEP6QEvent' + self.qtCustomEventFunc = self.findSymbol(sym) + + sym += '@plt' + self.qtCustomEventPltFunc = self.findSymbol(sym) + + sym = '_ZNK%s7QObject8propertyEPKc' % strns + self.qtPropertyFunc = self.findSymbol(sym) + + # This might be wrong, but we can't do better: We found + # a libQt5Core and could not extract a namespace. + # The best guess is that there isn't any. + self.qtNamespaceToReport = ns + self.qtNamespace = lambda: ns + def qtNamespaceX(self): if not self.currentQtNamespaceGuess is None: return self.currentQtNamespaceGuess - for objfile in gdb.objfiles(): - name = objfile.filename - if self.isWindowsTarget(): - isQtCoreObjFile = name.find('Qt5Cored.dll') >= 0 or name.find('Qt5Core.dll') >= 0 - else: - isQtCoreObjFile = name.find('/libQt5Core') >= 0 - if isQtCoreObjFile: - fd, tmppath = tempfile.mkstemp() - os.close(fd) - cmd = 'maint print msymbols %s "%s"' % (tmppath, name) - try: - symbols = gdb.execute(cmd, to_string = True) - except: - pass - ns = '' - with open(tmppath) as f: - for line in f: - if line.find('msgHandlerGrabbed ') >= 0: - # [11] b 0x7ffff683c000 _ZN4MynsL17msgHandlerGrabbedE - # section .tbss Myns::msgHandlerGrabbed qlogging.cpp - ns = re.split('_ZN?(\d*)(\w*)L17msgHandlerGrabbedE? ', line)[2] - if len(ns): - ns += '::' - break - os.remove(tmppath) - - lenns = len(ns) - strns = ('%d%s' % (lenns - 2, ns[:lenns - 2])) if lenns else '' - - if lenns: - sym = '_ZN%s7QObject11customEventEPNS_6QEventE' % strns - else: - sym = '_ZN7QObject11customEventEP6QEvent' - self.qtCustomEventFunc = self.findSymbol(sym) - - sym += '@plt' - self.qtCustomEventPltFunc = self.findSymbol(sym) - - sym = '_ZNK%s7QObject8propertyEPKc' % strns - self.qtPropertyFunc = self.findSymbol(sym) - - # This might be wrong, but we can't do better: We found - # a libQt5Core and could not extract a namespace. - # The best guess is that there isn't any. - self.qtNamespaceToReport = ns - self.qtNamespace = lambda: ns - return ns - self.currentQtNamespaceGuess = '' return '' @@ -1413,4 +1415,17 @@ class InterpreterMessageBreakpoint(gdb.Breakpoint): print('Interpreter event received.') return theDumper.handleInterpreterMessage() + +####################################################################### +# +# Shared objects +# +####################################################################### + +def new_objfile_handler(event): + return theDumper.handleNewObjectFile(event.new_objfile) + +gdb.events.new_objfile.connect(new_objfile_handler) + + #InterpreterMessageBreakpoint() |