| 
									
										
										
										
											2013-09-11 21:35:39 +02:00
										 |  |  | ############################################################################ | 
					
						
							|  |  |  | # | 
					
						
							| 
									
										
										
										
											2015-01-14 18:07:15 +01:00
										 |  |  | # Copyright (C) 2015 The Qt Company Ltd. | 
					
						
							|  |  |  | # Contact: http://www.qt.io/licensing | 
					
						
							| 
									
										
										
										
											2013-09-11 21:35:39 +02:00
										 |  |  | # | 
					
						
							|  |  |  | # 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 | 
					
						
							| 
									
										
										
										
											2015-01-14 18:07:15 +01:00
										 |  |  | # a written agreement between you and The Qt Company.  For licensing terms and | 
					
						
							|  |  |  | # conditions see http://www.qt.io/terms-conditions.  For further information | 
					
						
							| 
									
										
										
										
											2014-10-01 13:21:18 +02:00
										 |  |  | # use the contact form at http://www.qt.io/contact-us. | 
					
						
							| 
									
										
										
										
											2013-09-11 21:35:39 +02:00
										 |  |  | # | 
					
						
							|  |  |  | # GNU Lesser General Public License Usage | 
					
						
							|  |  |  | # Alternatively, this file may be used under the terms of the GNU Lesser | 
					
						
							| 
									
										
										
										
											2014-10-01 13:21:18 +02:00
										 |  |  | # General Public License version 2.1 or version 3 as published by the Free | 
					
						
							|  |  |  | # Software Foundation and appearing in the file LICENSE.LGPLv21 and | 
					
						
							|  |  |  | # LICENSE.LGPLv3 included in the packaging of this file.  Please review the | 
					
						
							|  |  |  | # following information to ensure the GNU Lesser General Public License | 
					
						
							|  |  |  | # requirements will be met: https://www.gnu.org/licenses/lgpl.html and | 
					
						
							|  |  |  | # http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. | 
					
						
							| 
									
										
										
										
											2013-09-11 21:35:39 +02:00
										 |  |  | # | 
					
						
							| 
									
										
										
										
											2015-01-14 18:07:15 +01:00
										 |  |  | # In addition, as a special exception, The Qt Company gives you certain additional | 
					
						
							|  |  |  | # rights.  These rights are described in The Qt Company LGPL Exception | 
					
						
							| 
									
										
										
										
											2013-09-11 21:35:39 +02:00
										 |  |  | # version 1.1, included in the file LGPL_EXCEPTION.txt in this package. | 
					
						
							|  |  |  | # | 
					
						
							|  |  |  | ############################################################################# | 
					
						
							| 
									
										
										
										
											2013-04-11 17:06:17 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | import inspect | 
					
						
							|  |  |  | import os | 
					
						
							| 
									
										
										
										
											2014-02-10 17:38:58 +01:00
										 |  |  | import platform | 
					
						
							| 
									
										
										
										
											2013-10-21 12:02:57 +02:00
										 |  |  | import re | 
					
						
							| 
									
										
										
										
											2013-05-13 16:04:00 +02:00
										 |  |  | import sys | 
					
						
							| 
									
										
										
										
											2013-10-21 12:02:57 +02:00
										 |  |  | import threading | 
					
						
							| 
									
										
										
										
											2015-01-30 12:36:04 +01:00
										 |  |  | import lldb | 
					
						
							| 
									
										
										
										
											2013-05-16 15:09:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-02-13 10:02:35 +01:00
										 |  |  | sys.path.insert(1, os.path.dirname(os.path.abspath(inspect.getfile(inspect.currentframe())))) | 
					
						
							| 
									
										
										
										
											2013-09-11 21:35:39 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | from dumper import * | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-04-11 17:06:17 +02:00
										 |  |  | ####################################################################### | 
					
						
							|  |  |  | # | 
					
						
							|  |  |  | # Helpers | 
					
						
							|  |  |  | # | 
					
						
							|  |  |  | ####################################################################### | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-06-14 15:15:09 +02:00
										 |  |  | qqWatchpointOffset = 10000 | 
					
						
							| 
									
										
										
										
											2013-05-15 15:30:42 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-04-11 17:06:17 +02:00
										 |  |  | def warn(message): | 
					
						
							| 
									
										
										
										
											2013-09-11 21:35:39 +02:00
										 |  |  |     print('\n\nWARNING="%s",\n' % message.encode("latin1").replace('"', "'")) | 
					
						
							| 
									
										
										
										
											2013-04-30 10:46:48 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | def showException(msg, exType, exValue, exTraceback): | 
					
						
							|  |  |  |     warn("**** CAUGHT EXCEPTION: %s ****" % msg) | 
					
						
							| 
									
										
										
										
											2013-05-08 16:20:03 +02:00
										 |  |  |     import traceback | 
					
						
							|  |  |  |     lines = [line for line in traceback.format_exception(exType, exValue, exTraceback)] | 
					
						
							|  |  |  |     warn('\n'.join(lines)) | 
					
						
							| 
									
										
										
										
											2013-04-30 10:46:48 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | def fileName(file): | 
					
						
							|  |  |  |     return str(file) if file.IsValid() else '' | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-04-11 17:06:17 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-05-07 16:43:20 +02:00
										 |  |  | def check(exp): | 
					
						
							|  |  |  |     if not exp: | 
					
						
							|  |  |  |         raise RuntimeError("Check failed") | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-05-13 16:39:51 +02:00
										 |  |  | Value = lldb.SBValue | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-05-08 16:20:03 +02:00
										 |  |  | def impl_SBValue__add__(self, offset): | 
					
						
							|  |  |  |     if self.GetType().IsPointerType(): | 
					
						
							| 
									
										
										
										
											2015-02-25 17:46:09 +01:00
										 |  |  |         if isinstance(offset, int) or isinstance(offset, long): | 
					
						
							| 
									
										
										
										
											2013-05-17 17:14:45 +02:00
										 |  |  |             pass | 
					
						
							|  |  |  |         else: | 
					
						
							|  |  |  |             offset = offset.GetValueAsSigned() | 
					
						
							| 
									
										
										
										
											2013-05-23 16:58:59 +02:00
										 |  |  |         itemsize = self.GetType().GetPointeeType().GetByteSize() | 
					
						
							| 
									
										
										
										
											2013-05-17 17:14:45 +02:00
										 |  |  |         address = self.GetValueAsUnsigned() + offset * itemsize | 
					
						
							| 
									
										
										
										
											2013-05-17 13:53:49 +02:00
										 |  |  |         address = address & 0xFFFFFFFFFFFFFFFF  # Force unsigned | 
					
						
							| 
									
										
										
										
											2013-11-07 14:41:31 +01:00
										 |  |  |         return self.CreateValueFromAddress(None, address, | 
					
						
							|  |  |  |                 self.GetType().GetPointeeType()).AddressOf() | 
					
						
							| 
									
										
										
										
											2013-07-02 15:43:29 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-05-13 16:39:51 +02:00
										 |  |  |     raise RuntimeError("SBValue.__add__ not implemented: %s" % self.GetType()) | 
					
						
							| 
									
										
										
										
											2013-05-08 16:20:03 +02:00
										 |  |  |     return NotImplemented | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-05-13 16:04:00 +02:00
										 |  |  | def impl_SBValue__sub__(self, other): | 
					
						
							| 
									
										
										
										
											2013-05-15 15:30:42 +02:00
										 |  |  |     if self.GetType().IsPointerType(): | 
					
						
							| 
									
										
										
										
											2013-05-17 17:14:45 +02:00
										 |  |  |         if isinstance(other, int) or isinstance(other, long): | 
					
						
							| 
									
										
										
										
											2014-04-07 12:15:07 +02:00
										 |  |  |             address = self.GetValueAsUnsigned() - other | 
					
						
							| 
									
										
										
										
											2013-05-17 17:14:45 +02:00
										 |  |  |             address = address & 0xFFFFFFFFFFFFFFFF  # Force unsigned | 
					
						
							|  |  |  |             return self.CreateValueFromAddress(None, address, self.GetType()) | 
					
						
							| 
									
										
										
										
											2013-05-15 15:30:42 +02:00
										 |  |  |         if other.GetType().IsPointerType(): | 
					
						
							| 
									
										
										
										
											2013-05-23 16:58:59 +02:00
										 |  |  |             itemsize = self.GetType().GetPointeeType().GetByteSize() | 
					
						
							|  |  |  |             return (self.GetValueAsUnsigned() - other.GetValueAsUnsigned()) / itemsize | 
					
						
							| 
									
										
										
										
											2013-05-15 15:30:42 +02:00
										 |  |  |     raise RuntimeError("SBValue.__sub__ not implemented: %s" % self.GetType()) | 
					
						
							| 
									
										
										
										
											2013-05-13 16:04:00 +02:00
										 |  |  |     return NotImplemented | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-05-13 16:39:51 +02:00
										 |  |  | def impl_SBValue__le__(self, other): | 
					
						
							|  |  |  |     if self.GetType().IsPointerType() and other.GetType().IsPointerType(): | 
					
						
							|  |  |  |         return int(self) <= int(other) | 
					
						
							|  |  |  |     raise RuntimeError("SBValue.__le__ not implemented") | 
					
						
							|  |  |  |     return NotImplemented | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | def impl_SBValue__int__(self): | 
					
						
							| 
									
										
										
										
											2013-05-17 17:14:45 +02:00
										 |  |  |     return self.GetValueAsSigned() | 
					
						
							| 
									
										
										
										
											2013-07-04 10:17:51 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | def impl_SBValue__float__(self): | 
					
						
							|  |  |  |     error = lldb.SBError() | 
					
						
							|  |  |  |     if self.GetType().GetByteSize() == 4: | 
					
						
							|  |  |  |         result = self.GetData().GetFloat(error, 0) | 
					
						
							|  |  |  |     else: | 
					
						
							|  |  |  |         result = self.GetData().GetDouble(error, 0) | 
					
						
							|  |  |  |     if error.Success(): | 
					
						
							|  |  |  |         return result | 
					
						
							|  |  |  |     return NotImplemented | 
					
						
							| 
									
										
										
										
											2013-05-13 16:39:51 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-05-17 13:53:49 +02:00
										 |  |  | def impl_SBValue__long__(self): | 
					
						
							|  |  |  |     return int(self.GetValue(), 0) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-06-10 14:50:22 +02:00
										 |  |  | def impl_SBValue__getitem__(value, index): | 
					
						
							| 
									
										
										
										
											2015-02-04 17:21:55 +01:00
										 |  |  |     if isinstance(index, int) or isinstance(index, long): | 
					
						
							| 
									
										
										
										
											2013-06-10 14:50:22 +02:00
										 |  |  |         type = value.GetType() | 
					
						
							|  |  |  |         if type.IsPointerType(): | 
					
						
							|  |  |  |             innertype = value.Dereference().GetType() | 
					
						
							|  |  |  |             address = value.GetValueAsUnsigned() + index * innertype.GetByteSize() | 
					
						
							|  |  |  |             address = address & 0xFFFFFFFFFFFFFFFF  # Force unsigned | 
					
						
							|  |  |  |             return value.CreateValueFromAddress(None, address, innertype) | 
					
						
							|  |  |  |         return value.GetChildAtIndex(index) | 
					
						
							| 
									
										
										
										
											2015-04-14 14:17:58 +02:00
										 |  |  |     item = value.GetChildMemberWithName(index) | 
					
						
							|  |  |  |     if item.IsValid(): | 
					
						
							|  |  |  |         return item | 
					
						
							|  |  |  |     raise RuntimeError("SBValue.__getitem__: No such member '%s'" % index) | 
					
						
							| 
									
										
										
										
											2013-05-13 16:39:51 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-01-10 12:42:12 +01:00
										 |  |  | def impl_SBValue__deref(value): | 
					
						
							|  |  |  |     result = value.Dereference() | 
					
						
							|  |  |  |     if result.IsValid(): | 
					
						
							|  |  |  |         return result | 
					
						
							| 
									
										
										
										
											2014-01-30 18:13:45 +01:00
										 |  |  |     exp = "*(class %s*)0x%x" % (value.GetType().GetPointeeType(), value.GetValueAsUnsigned()) | 
					
						
							|  |  |  |     return value.CreateValueFromExpression(None, exp) | 
					
						
							| 
									
										
										
										
											2014-01-10 12:42:12 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-05-08 16:20:03 +02:00
										 |  |  | lldb.SBValue.__add__ = impl_SBValue__add__ | 
					
						
							| 
									
										
										
										
											2013-05-13 16:04:00 +02:00
										 |  |  | lldb.SBValue.__sub__ = impl_SBValue__sub__ | 
					
						
							| 
									
										
										
										
											2013-05-13 16:39:51 +02:00
										 |  |  | lldb.SBValue.__le__ = impl_SBValue__le__ | 
					
						
							| 
									
										
										
										
											2013-05-08 16:20:03 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-05-13 16:39:51 +02:00
										 |  |  | lldb.SBValue.__getitem__ = impl_SBValue__getitem__ | 
					
						
							|  |  |  | lldb.SBValue.__int__ = impl_SBValue__int__ | 
					
						
							| 
									
										
										
										
											2013-07-04 10:17:51 +02:00
										 |  |  | lldb.SBValue.__float__ = impl_SBValue__float__ | 
					
						
							| 
									
										
										
										
											2013-05-08 16:20:03 +02:00
										 |  |  | lldb.SBValue.__long__ = lambda self: long(self.GetValue(), 0) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-05-13 16:39:51 +02:00
										 |  |  | lldb.SBValue.code = lambda self: self.GetTypeClass() | 
					
						
							| 
									
										
										
										
											2013-05-08 16:20:03 +02:00
										 |  |  | lldb.SBValue.cast = lambda self, typeObj: self.Cast(typeObj) | 
					
						
							| 
									
										
										
										
											2014-01-10 12:42:12 +01:00
										 |  |  | lldb.SBValue.dereference = impl_SBValue__deref | 
					
						
							| 
									
										
										
										
											2014-01-20 15:57:09 +01:00
										 |  |  | lldb.SBValue.address = property(lambda self: self.GetLoadAddress()) | 
					
						
							| 
									
										
										
										
											2013-05-08 16:20:03 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | lldb.SBType.pointer = lambda self: self.GetPointerType() | 
					
						
							| 
									
										
										
										
											2013-11-06 17:57:12 +01:00
										 |  |  | lldb.SBType.target = lambda self: self.GetPointeeType() | 
					
						
							| 
									
										
										
										
											2013-05-13 16:39:51 +02:00
										 |  |  | lldb.SBType.code = lambda self: self.GetTypeClass() | 
					
						
							| 
									
										
										
										
											2013-05-08 16:20:03 +02:00
										 |  |  | lldb.SBType.sizeof = property(lambda self: self.GetByteSize()) | 
					
						
							| 
									
										
										
										
											2013-06-24 16:49:46 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-07-05 09:22:55 +02:00
										 |  |  | lldb.SBType.unqualified = \ | 
					
						
							|  |  |  |     lambda self: self.GetUnqualifiedType() if hasattr(self, 'GetUnqualifiedType') else self | 
					
						
							| 
									
										
										
										
											2013-06-24 16:49:46 +02:00
										 |  |  | lldb.SBType.strip_typedefs = \ | 
					
						
							|  |  |  |     lambda self: self.GetCanonicalType() if hasattr(self, 'GetCanonicalType') else self | 
					
						
							| 
									
										
										
										
											2013-05-08 16:20:03 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-06-06 09:09:19 +02:00
										 |  |  | lldb.SBType.__orig__str__ = lldb.SBType.__str__ | 
					
						
							|  |  |  | lldb.SBType.__str__ = lldb.SBType.GetName | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-09-11 21:35:39 +02:00
										 |  |  | class Dumper(DumperBase): | 
					
						
							| 
									
										
										
										
											2013-04-30 10:46:48 +02:00
										 |  |  |     def __init__(self): | 
					
						
							| 
									
										
										
										
											2013-09-11 21:35:39 +02:00
										 |  |  |         DumperBase.__init__(self) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-03-19 12:08:25 +01:00
										 |  |  |         self.outputLock = threading.Lock() | 
					
						
							| 
									
										
										
										
											2013-04-30 10:46:48 +02:00
										 |  |  |         self.debugger = lldb.SBDebugger.Create() | 
					
						
							| 
									
										
										
										
											2013-05-02 14:31:35 +02:00
										 |  |  |         #self.debugger.SetLoggingCallback(loggingCallback) | 
					
						
							| 
									
										
										
										
											2015-02-04 14:15:14 +01:00
										 |  |  |         #def loggingCallback(args): | 
					
						
							|  |  |  |         #    s = args.strip() | 
					
						
							|  |  |  |         #    s = s.replace('"', "'") | 
					
						
							|  |  |  |         #    sys.stdout.write('log="%s"@\n' % s) | 
					
						
							| 
									
										
										
										
											2013-04-30 10:46:48 +02:00
										 |  |  |         #Same as: self.debugger.HandleCommand("log enable lldb dyld step") | 
					
						
							| 
									
										
										
										
											2015-02-04 14:15:14 +01:00
										 |  |  |         #self.debugger.EnableLog("lldb", ["dyld", "step", "process", "state", | 
					
						
							|  |  |  |         #    "thread", "events", | 
					
						
							| 
									
										
										
										
											2013-04-30 10:46:48 +02:00
										 |  |  |         #    "communication", "unwind", "commands"]) | 
					
						
							|  |  |  |         #self.debugger.EnableLog("lldb", ["all"]) | 
					
						
							|  |  |  |         self.debugger.Initialize() | 
					
						
							|  |  |  |         self.debugger.HandleCommand("settings set auto-confirm on") | 
					
						
							| 
									
										
										
										
											2013-11-01 14:18:10 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |         # FIXME: warn("DISABLING DEFAULT FORMATTERS") | 
					
						
							|  |  |  |         # It doesn't work at all with 179.5 and we have some bad | 
					
						
							|  |  |  |         # interactonn in 3000 | 
					
						
							|  |  |  |         # if not hasattr(lldb.SBType, 'GetCanonicalType'): # "Test" for 179.5 | 
					
						
							|  |  |  |         self.debugger.HandleCommand('type category delete gnu-libstdc++') | 
					
						
							|  |  |  |         self.debugger.HandleCommand('type category delete libcxx') | 
					
						
							|  |  |  |         #for i in range(self.debugger.GetNumCategories()): | 
					
						
							|  |  |  |         #    self.debugger.GetCategoryAtIndex(i).SetEnabled(False) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-09-11 21:35:39 +02:00
										 |  |  |         self.isLldb = True | 
					
						
							| 
									
										
										
										
											2014-01-31 13:52:47 +01:00
										 |  |  |         self.isGoodLldb = hasattr(lldb.SBValue, "SetPreferDynamicValue") | 
					
						
							| 
									
										
										
										
											2013-04-30 10:46:48 +02:00
										 |  |  |         self.process = None | 
					
						
							|  |  |  |         self.target = None | 
					
						
							|  |  |  |         self.eventState = lldb.eStateInvalid | 
					
						
							|  |  |  |         self.expandedINames = {} | 
					
						
							| 
									
										
										
										
											2013-10-31 09:17:49 +01:00
										 |  |  |         self.passExceptions = False | 
					
						
							| 
									
										
										
										
											2013-05-22 12:06:56 +02:00
										 |  |  |         self.useLldbDumpers = False | 
					
						
							| 
									
										
										
										
											2013-05-17 10:10:13 +02:00
										 |  |  |         self.autoDerefPointers = True | 
					
						
							| 
									
										
										
										
											2013-05-29 14:54:47 +02:00
										 |  |  |         self.useDynamicType = True | 
					
						
							| 
									
										
										
										
											2013-06-05 11:26:46 +02:00
										 |  |  |         self.useFancy = True | 
					
						
							| 
									
										
										
										
											2013-06-11 14:24:26 +02:00
										 |  |  |         self.formats = {} | 
					
						
							|  |  |  |         self.typeformats = {} | 
					
						
							| 
									
										
										
										
											2013-04-30 10:46:48 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |         self.currentIName = None | 
					
						
							| 
									
										
										
										
											2014-05-16 00:18:17 +02:00
										 |  |  |         self.currentValue = ReportItem() | 
					
						
							|  |  |  |         self.currentType = ReportItem() | 
					
						
							| 
									
										
										
										
											2013-05-08 16:20:03 +02:00
										 |  |  |         self.currentNumChild = None | 
					
						
							|  |  |  |         self.currentMaxNumChild = None | 
					
						
							|  |  |  |         self.currentPrintsAddress = None | 
					
						
							|  |  |  |         self.currentChildType = None | 
					
						
							| 
									
										
										
										
											2015-03-26 13:03:38 +01:00
										 |  |  |         self.currentChildNumChild = -1 | 
					
						
							| 
									
										
										
										
											2013-05-30 15:35:52 +02:00
										 |  |  |         self.currentWatchers = {} | 
					
						
							| 
									
										
										
										
											2013-04-30 10:46:48 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-05-22 14:30:36 +02:00
										 |  |  |         self.executable_ = None | 
					
						
							| 
									
										
										
										
											2013-10-01 02:30:12 +02:00
										 |  |  |         self.startMode_ = None | 
					
						
							|  |  |  |         self.processArgs_ = None | 
					
						
							|  |  |  |         self.attachPid_ = None | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-05-17 13:53:49 +02:00
										 |  |  |         self.charType_ = None | 
					
						
							|  |  |  |         self.intType_ = None | 
					
						
							| 
									
										
										
										
											2013-10-23 11:42:48 +02:00
										 |  |  |         self.int64Type_ = None | 
					
						
							| 
									
										
										
										
											2013-05-17 13:53:49 +02:00
										 |  |  |         self.sizetType_ = None | 
					
						
							|  |  |  |         self.charPtrType_ = None | 
					
						
							| 
									
										
										
										
											2013-07-02 15:43:29 +02:00
										 |  |  |         self.voidPtrType_ = None | 
					
						
							| 
									
										
										
										
											2013-05-29 15:38:49 +02:00
										 |  |  |         self.isShuttingDown_ = False | 
					
						
							| 
									
										
										
										
											2013-06-24 17:40:00 +02:00
										 |  |  |         self.isInterrupting_ = False | 
					
						
							| 
									
										
										
										
											2015-02-04 13:29:42 +01:00
										 |  |  |         self.qmlBreakpointResolvers = {} | 
					
						
							|  |  |  |         self.qmlTriggeredBreakpoint = None | 
					
						
							| 
									
										
										
										
											2013-05-17 13:53:49 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-02-13 10:02:35 +01:00
										 |  |  |         self.report('lldbversion=\"%s\"' % lldb.SBDebugger.GetVersionString()) | 
					
						
							|  |  |  |         self.reportState("enginesetupok") | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-09-11 21:35:39 +02:00
										 |  |  |     def enterSubItem(self, item): | 
					
						
							|  |  |  |         if isinstance(item.name, lldb.SBValue): | 
					
						
							|  |  |  |             # Avoid $$__synth__ suffix on Mac. | 
					
						
							|  |  |  |             value = item.name | 
					
						
							| 
									
										
										
										
											2014-01-31 13:52:47 +01:00
										 |  |  |             if self.isGoodLldb: | 
					
						
							|  |  |  |                 value.SetPreferSyntheticValue(False) | 
					
						
							| 
									
										
										
										
											2013-09-11 21:35:39 +02:00
										 |  |  |             item.name = value.GetName() | 
					
						
							|  |  |  |             if item.name is None: | 
					
						
							|  |  |  |                 self.anonNumber += 1 | 
					
						
							|  |  |  |                 item.name = "#%d" % self.anonNumber | 
					
						
							| 
									
										
										
										
											2013-12-17 11:03:16 +01:00
										 |  |  |         if not item.iname: | 
					
						
							|  |  |  |             item.iname = "%s.%s" % (self.currentIName, item.name) | 
					
						
							| 
									
										
										
										
											2013-09-11 21:35:39 +02:00
										 |  |  |         self.put('{') | 
					
						
							|  |  |  |         #if not item.name is None: | 
					
						
							|  |  |  |         if isinstance(item.name, str): | 
					
						
							|  |  |  |             if item.name == '**&': | 
					
						
							|  |  |  |                 item.name = '*' | 
					
						
							|  |  |  |             self.put('name="%s",' % item.name) | 
					
						
							|  |  |  |         item.savedIName = self.currentIName | 
					
						
							|  |  |  |         item.savedValue = self.currentValue | 
					
						
							|  |  |  |         item.savedType = self.currentType | 
					
						
							|  |  |  |         self.currentIName = item.iname | 
					
						
							| 
									
										
										
										
											2014-05-16 00:18:17 +02:00
										 |  |  |         self.currentValue = ReportItem() | 
					
						
							|  |  |  |         self.currentType = ReportItem() | 
					
						
							| 
									
										
										
										
											2013-09-11 21:35:39 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     def exitSubItem(self, item, exType, exValue, exTraceBack): | 
					
						
							|  |  |  |         if not exType is None: | 
					
						
							|  |  |  |             if self.passExceptions: | 
					
						
							|  |  |  |                 showException("SUBITEM", exType, exValue, exTraceBack) | 
					
						
							|  |  |  |             self.putNumChild(0) | 
					
						
							| 
									
										
										
										
											2015-07-20 14:23:54 +02:00
										 |  |  |             self.putSpecialValue(SpecialNotAccessibleValue) | 
					
						
							| 
									
										
										
										
											2013-09-11 21:35:39 +02:00
										 |  |  |         try: | 
					
						
							| 
									
										
										
										
											2014-05-19 10:55:33 +02:00
										 |  |  |             if self.currentType.value: | 
					
						
							|  |  |  |                 typeName = self.currentType.value | 
					
						
							|  |  |  |                 if len(typeName) > 0 and typeName != self.currentChildType: | 
					
						
							|  |  |  |                     self.put('type="%s",' % typeName) # str(type.unqualified()) ? | 
					
						
							| 
									
										
										
										
											2014-05-16 00:18:17 +02:00
										 |  |  |             if  self.currentValue.value is None: | 
					
						
							| 
									
										
										
										
											2015-07-20 14:23:54 +02:00
										 |  |  |                 self.put('value="",encoding="%d",numchild="0",' | 
					
						
							|  |  |  |                         % SpecialNotAccessibleValue) | 
					
						
							| 
									
										
										
										
											2013-09-11 21:35:39 +02:00
										 |  |  |             else: | 
					
						
							| 
									
										
										
										
											2014-05-16 00:18:17 +02:00
										 |  |  |                 if not self.currentValue.encoding is None: | 
					
						
							|  |  |  |                     self.put('valueencoded="%s",' % self.currentValue.encoding) | 
					
						
							|  |  |  |                 if self.currentValue.elided: | 
					
						
							|  |  |  |                     self.put('valueelided="%s",' % self.currentValue.elided) | 
					
						
							|  |  |  |                 self.put('value="%s",' % self.currentValue.value) | 
					
						
							| 
									
										
										
										
											2013-09-11 21:35:39 +02:00
										 |  |  |         except: | 
					
						
							|  |  |  |             pass | 
					
						
							|  |  |  |         self.put('},') | 
					
						
							|  |  |  |         self.currentIName = item.savedIName | 
					
						
							|  |  |  |         self.currentValue = item.savedValue | 
					
						
							|  |  |  |         self.currentType = item.savedType | 
					
						
							|  |  |  |         return True | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-02-04 14:15:14 +01:00
										 |  |  |     def stateName(self, s): | 
					
						
							|  |  |  |         try: | 
					
						
							|  |  |  |             # See db.StateType | 
					
						
							|  |  |  |             return ( | 
					
						
							|  |  |  |                 'invalid', | 
					
						
							|  |  |  |                 'unloaded',  # Process is object is valid, but not currently loaded | 
					
						
							|  |  |  |                 'connected', # Process is connected to remote debug services, | 
					
						
							|  |  |  |                              #  but not launched or attached to anything yet | 
					
						
							|  |  |  |                 'attaching', # Process is currently trying to attach | 
					
						
							|  |  |  |                 'launching', # Process is in the process of launching | 
					
						
							|  |  |  |                 'stopped',   # Process or thread is stopped and can be examined. | 
					
						
							|  |  |  |                 'running',   # Process or thread is running and can't be examined. | 
					
						
							|  |  |  |                 'stepping',  # Process or thread is in the process of stepping | 
					
						
							|  |  |  |                              #  and can not be examined. | 
					
						
							|  |  |  |                 'crashed',   # Process or thread has crashed and can be examined. | 
					
						
							|  |  |  |                 'detached',  # Process has been detached and can't be examined. | 
					
						
							|  |  |  |                 'exited',    # Process has exited and can't be examined. | 
					
						
							|  |  |  |                 'suspended'  # Process or thread is in a suspended state as far | 
					
						
							|  |  |  |                 )[s] | 
					
						
							|  |  |  |         except: | 
					
						
							|  |  |  |             return 'unknown(%s)' % s | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     def stopReason(self, s): | 
					
						
							|  |  |  |         try: | 
					
						
							|  |  |  |             return ( | 
					
						
							|  |  |  |                 'invalid', | 
					
						
							|  |  |  |                 'none', | 
					
						
							|  |  |  |                 'trace', | 
					
						
							|  |  |  |                 'breakpoint', | 
					
						
							|  |  |  |                 'watchpoint', | 
					
						
							|  |  |  |                 'signal', | 
					
						
							|  |  |  |                 'exception', | 
					
						
							|  |  |  |                 'exec', | 
					
						
							|  |  |  |                 'plancomplete', | 
					
						
							|  |  |  |                 'threadexiting', | 
					
						
							|  |  |  |                 'instrumentation', | 
					
						
							|  |  |  |                 )[s] | 
					
						
							|  |  |  |         except: | 
					
						
							|  |  |  |             return 'unknown(%s)' % s | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-09-11 21:35:39 +02:00
										 |  |  |     def isSimpleType(self, typeobj): | 
					
						
							|  |  |  |         typeClass = typeobj.GetTypeClass() | 
					
						
							|  |  |  |         return typeClass == lldb.eTypeClassBuiltin | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-01-20 15:03:27 +01:00
										 |  |  |     def childWithName(self, value, name): | 
					
						
							|  |  |  |         child = value.GetChildMemberWithName(name) | 
					
						
							|  |  |  |         return child if child.IsValid() else None | 
					
						
							| 
									
										
										
										
											2014-01-15 17:38:23 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-01-31 16:56:32 +01:00
										 |  |  |     def simpleValue(self, value): | 
					
						
							|  |  |  |         return str(value.value) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-09-11 21:35:39 +02:00
										 |  |  |     def childAt(self, value, index): | 
					
						
							|  |  |  |         return value.GetChildAtIndex(index) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     def fieldAt(self, type, index): | 
					
						
							|  |  |  |         return type.GetFieldAtIndex(index) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     def pointerValue(self, value): | 
					
						
							|  |  |  |         return value.GetValueAsUnsigned() | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-01-10 20:01:35 +01:00
										 |  |  |     def enumExpression(self, enumType, enumValue): | 
					
						
							|  |  |  |         ns = self.qtNamespace() | 
					
						
							|  |  |  |         return ns + "Qt::" + enumType + "(" \ | 
					
						
							|  |  |  |             + ns + "Qt::" + enumType + "::" + enumValue + ")" | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-04-03 11:23:31 +02:00
										 |  |  |     def callHelper(self, value, func, args): | 
					
						
							| 
									
										
										
										
											2013-09-11 21:35:39 +02:00
										 |  |  |         # args is a tuple. | 
					
						
							|  |  |  |         arg = ','.join(args) | 
					
						
							| 
									
										
										
										
											2014-09-22 18:00:06 +02:00
										 |  |  |         #self.warn("CALL: %s -> %s(%s)" % (value, func, arg)) | 
					
						
							| 
									
										
										
										
											2013-09-11 21:35:39 +02:00
										 |  |  |         type = value.type.name | 
					
						
							|  |  |  |         exp = "((%s*)%s)->%s(%s)" % (type, value.address, func, arg) | 
					
						
							| 
									
										
										
										
											2014-09-22 18:00:06 +02:00
										 |  |  |         #self.warn("CALL: %s" % exp) | 
					
						
							| 
									
										
										
										
											2014-01-24 17:02:23 +01:00
										 |  |  |         result = value.CreateValueFromExpression('', exp) | 
					
						
							| 
									
										
										
										
											2014-09-22 18:00:06 +02:00
										 |  |  |         #self.warn("  -> %s" % result) | 
					
						
							| 
									
										
										
										
											2013-09-11 21:35:39 +02:00
										 |  |  |         return result | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-04-30 15:52:33 +02:00
										 |  |  |     def isBadPointer(self, value): | 
					
						
							|  |  |  |         target = value.dereference() | 
					
						
							|  |  |  |         return target.GetError().Fail() | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-01-22 16:25:39 +01:00
										 |  |  |     def makeValue(self, type, *args): | 
					
						
							|  |  |  |         thread = self.currentThread() | 
					
						
							|  |  |  |         frame = thread.GetFrameAtIndex(0) | 
					
						
							|  |  |  |         inner = ','.join(args) | 
					
						
							|  |  |  |         value = frame.EvaluateExpression(type + '{' + inner + '}') | 
					
						
							| 
									
										
										
										
											2014-09-22 18:00:06 +02:00
										 |  |  |         #self.warn("  TYPE: %s" % value.type) | 
					
						
							|  |  |  |         #self.warn("  ADDR: 0x%x" % value.address) | 
					
						
							|  |  |  |         #self.warn("  VALUE: %s" % value) | 
					
						
							| 
									
										
										
										
											2014-01-22 16:25:39 +01:00
										 |  |  |         return value | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-10-23 12:51:11 +02:00
										 |  |  |     def parseAndEvaluate(self, expr): | 
					
						
							|  |  |  |         thread = self.currentThread() | 
					
						
							|  |  |  |         frame = thread.GetFrameAtIndex(0) | 
					
						
							|  |  |  |         return frame.EvaluateExpression(expr) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-09-11 21:35:39 +02:00
										 |  |  |     def checkPointer(self, p, align = 1): | 
					
						
							|  |  |  |         if not self.isNull(p): | 
					
						
							|  |  |  |             p.Dereference() | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     def isNull(self, p): | 
					
						
							|  |  |  |         return p.GetValueAsUnsigned() == 0 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     def directBaseClass(self, typeobj, index = 0): | 
					
						
							| 
									
										
										
										
											2014-03-12 15:03:20 +01:00
										 |  |  |         result = typeobj.GetDirectBaseClassAtIndex(index).GetType() | 
					
						
							| 
									
										
										
										
											2014-03-12 13:20:21 +01:00
										 |  |  |         return result if result.IsValid() else None | 
					
						
							| 
									
										
										
										
											2013-09-11 21:35:39 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-05-23 15:47:28 +02:00
										 |  |  |     def templateArgument(self, typeobj, index): | 
					
						
							| 
									
										
										
										
											2013-05-23 16:58:59 +02:00
										 |  |  |         type = typeobj.GetTemplateArgumentType(index) | 
					
						
							| 
									
										
										
										
											2013-07-03 13:32:19 +02:00
										 |  |  |         if type.IsValid(): | 
					
						
							| 
									
										
										
										
											2013-05-23 16:58:59 +02:00
										 |  |  |             return type | 
					
						
							|  |  |  |         inner = self.extractTemplateArgument(typeobj.GetName(), index) | 
					
						
							|  |  |  |         return self.lookupType(inner) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     def numericTemplateArgument(self, typeobj, index): | 
					
						
							| 
									
										
										
										
											2014-04-10 17:32:51 +02:00
										 |  |  |         # There seems no API to extract the numeric value. | 
					
						
							| 
									
										
										
										
											2013-05-23 16:58:59 +02:00
										 |  |  |         inner = self.extractTemplateArgument(typeobj.GetName(), index) | 
					
						
							| 
									
										
										
										
											2014-04-10 17:32:51 +02:00
										 |  |  |         innerType = typeobj.GetTemplateArgumentType(index) | 
					
						
							|  |  |  |         basicType = innerType.GetBasicType() | 
					
						
							|  |  |  |         value = toInteger(inner) | 
					
						
							|  |  |  |         # Clang writes 'int' and '0xfffffff' into the debug info | 
					
						
							|  |  |  |         # LLDB manages to read a value of 0xfffffff... | 
					
						
							|  |  |  |         if basicType == lldb.eBasicTypeInt and value >= 0x8000000: | 
					
						
							|  |  |  |             value -= 0x100000000 | 
					
						
							|  |  |  |         return value | 
					
						
							| 
									
										
										
										
											2013-05-23 15:47:28 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-07-03 13:32:19 +02:00
										 |  |  |     def isReferenceType(self, typeobj): | 
					
						
							|  |  |  |         return typeobj.IsReferenceType() | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     def isStructType(self, typeobj): | 
					
						
							|  |  |  |         return typeobj.GetTypeClass() in (lldb.eTypeClassStruct, lldb.eTypeClassClass) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-04-01 18:11:57 +02:00
										 |  |  |     def isWindowsTarget(self): | 
					
						
							|  |  |  |         return False | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     def isQnxTarget(self): | 
					
						
							|  |  |  |         return False | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     def isArmArchitecture(self): | 
					
						
							|  |  |  |         return False | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-01-09 13:25:17 +01:00
										 |  |  |     def qtVersionAndNamespace(self): | 
					
						
							| 
									
										
										
										
											2014-03-12 18:04:51 +01:00
										 |  |  |         for func in self.target.FindFunctions('qVersion'): | 
					
						
							|  |  |  |             name = func.GetSymbol().GetName() | 
					
						
							| 
									
										
										
										
											2014-03-19 12:16:43 +01:00
										 |  |  |             if name.endswith('()'): | 
					
						
							|  |  |  |                 name = name[:-2] | 
					
						
							| 
									
										
										
										
											2014-03-12 18:04:51 +01:00
										 |  |  |             if name.count(':') > 2: | 
					
						
							|  |  |  |                 continue | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-03-19 12:16:43 +01:00
										 |  |  |             qtNamespace = name[:name.find('qVersion')] | 
					
						
							|  |  |  |             self.qtNamespace = lambda: qtNamespace | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-04-04 15:37:55 +02:00
										 |  |  |             options = lldb.SBExpressionOptions() | 
					
						
							|  |  |  |             res = self.target.EvaluateExpression(name + '()', options) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             if not res.IsValid() or not res.GetType().IsPointerType(): | 
					
						
							|  |  |  |                 exp = '((const char*())%s)()' % name | 
					
						
							|  |  |  |                 res = self.target.EvaluateExpression(exp, options) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             if not res.IsValid() or not res.GetType().IsPointerType(): | 
					
						
							|  |  |  |                 exp = '((const char*())_Z8qVersionv)()' | 
					
						
							|  |  |  |                 res = self.target.EvaluateExpression(exp, options) | 
					
						
							| 
									
										
										
										
											2014-03-12 18:04:51 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-04-04 15:37:55 +02:00
										 |  |  |             if not res.IsValid() or not res.GetType().IsPointerType(): | 
					
						
							|  |  |  |                 continue | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             version = str(res) | 
					
						
							| 
									
										
										
										
											2014-03-12 18:04:51 +01:00
										 |  |  |             if version.count('.') != 2: | 
					
						
							|  |  |  |                 continue | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-03-19 12:16:43 +01:00
										 |  |  |             version.replace("'", '"') # Both seem possible | 
					
						
							|  |  |  |             version = version[version.find('"')+1:version.rfind('"')] | 
					
						
							| 
									
										
										
										
											2014-03-12 18:04:51 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |             (major, minor, patch) = version.split('.') | 
					
						
							|  |  |  |             qtVersion = 0x10000 * int(major) + 0x100 * int(minor) + int(patch) | 
					
						
							|  |  |  |             self.qtVersion = lambda: qtVersion | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             return (qtNamespace, qtVersion) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         return ('', 0x50200) | 
					
						
							| 
									
										
										
										
											2014-01-09 13:25:17 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |     def qtNamespace(self): | 
					
						
							| 
									
										
										
										
											2014-03-12 18:04:51 +01:00
										 |  |  |         return self.qtVersionAndNamespace()[0] | 
					
						
							| 
									
										
										
										
											2014-01-09 13:25:17 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |     def qtVersion(self): | 
					
						
							| 
									
										
										
										
											2014-01-09 16:23:17 +01:00
										 |  |  |         self.qtVersionAndNamespace() | 
					
						
							| 
									
										
										
										
											2014-03-12 18:04:51 +01:00
										 |  |  |         return self.qtVersionAndNamespace()[1] | 
					
						
							| 
									
										
										
										
											2013-06-27 10:42:32 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-07-02 15:43:29 +02:00
										 |  |  |     def intSize(self): | 
					
						
							|  |  |  |         return 4 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-04-16 17:06:57 +02:00
										 |  |  |     def ptrSize(self): | 
					
						
							|  |  |  |         return self.target.GetAddressByteSize() | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-05-17 13:53:49 +02:00
										 |  |  |     def intType(self): | 
					
						
							| 
									
										
										
										
											2015-04-16 17:06:57 +02:00
										 |  |  |         return self.target.GetBasicType(lldb.eBasicTypeInt) | 
					
						
							| 
									
										
										
										
											2013-05-17 13:53:49 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-10-23 11:42:48 +02:00
										 |  |  |     def int64Type(self): | 
					
						
							| 
									
										
										
										
											2015-04-16 17:06:57 +02:00
										 |  |  |         return self.target.GetBasicType(lldb.eBasicTypeLongLong) | 
					
						
							| 
									
										
										
										
											2013-10-23 11:42:48 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-05-17 13:53:49 +02:00
										 |  |  |     def charType(self): | 
					
						
							| 
									
										
										
										
											2015-04-16 17:06:57 +02:00
										 |  |  |         return self.target.GetBasicType(lldb.eBasicTypeChar) | 
					
						
							| 
									
										
										
										
											2013-05-17 13:53:49 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     def charPtrType(self): | 
					
						
							| 
									
										
										
										
											2015-04-16 17:06:57 +02:00
										 |  |  |         return self.target.GetBasicType(lldb.eBasicTypeChar).GetPointerType() | 
					
						
							| 
									
										
										
										
											2013-05-17 13:53:49 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     def voidPtrType(self): | 
					
						
							| 
									
										
										
										
											2015-04-16 17:06:57 +02:00
										 |  |  |         return self.target.GetBasicType(lldb.eBasicVoid).GetPointerType() | 
					
						
							| 
									
										
										
										
											2013-05-17 13:53:49 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     def sizetType(self): | 
					
						
							|  |  |  |         if self.sizetType_ is None: | 
					
						
							|  |  |  |              self.sizetType_ = self.lookupType('size_t') | 
					
						
							|  |  |  |         return self.sizetType_ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-05-17 17:14:45 +02:00
										 |  |  |     def addressOf(self, value): | 
					
						
							|  |  |  |         return int(value.GetLoadAddress()) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-07-01 17:24:56 +02:00
										 |  |  |     def extractUShort(self, address): | 
					
						
							|  |  |  |         error = lldb.SBError() | 
					
						
							|  |  |  |         return int(self.process.ReadUnsignedFromMemory(address, 2, error)) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     def extractShort(self, address): | 
					
						
							|  |  |  |         i = self.extractUInt(address) | 
					
						
							|  |  |  |         if i >= 0x8000: | 
					
						
							|  |  |  |             i -= 0x10000 | 
					
						
							|  |  |  |         return i | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-04-13 17:55:49 +02:00
										 |  |  |     def extractUInt(self, address): | 
					
						
							| 
									
										
										
										
											2015-04-02 15:55:37 +02:00
										 |  |  |         error = lldb.SBError() | 
					
						
							| 
									
										
										
										
											2015-03-26 14:22:33 +01:00
										 |  |  |         return int(self.process.ReadUnsignedFromMemory(address, 4, error)) | 
					
						
							| 
									
										
										
										
											2013-07-02 15:43:29 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-04-13 17:55:49 +02:00
										 |  |  |     def extractInt(self, address): | 
					
						
							|  |  |  |         i = self.extractUInt(address) | 
					
						
							|  |  |  |         if i >= 0x80000000: | 
					
						
							|  |  |  |             i -= 0x100000000 | 
					
						
							|  |  |  |         return i | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     def extractUInt64(self, address): | 
					
						
							| 
									
										
										
										
											2015-04-02 15:55:37 +02:00
										 |  |  |         error = lldb.SBError() | 
					
						
							| 
									
										
										
										
											2015-03-26 14:22:33 +01:00
										 |  |  |         return int(self.process.ReadUnsignedFromMemory(address, 8, error)) | 
					
						
							| 
									
										
										
										
											2013-10-23 11:42:48 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-04-13 17:55:49 +02:00
										 |  |  |     def extractInt64(self, address): | 
					
						
							|  |  |  |         i = self.extractUInt64(address) | 
					
						
							|  |  |  |         if i >= 0x8000000000000000: | 
					
						
							|  |  |  |             i -= 0x10000000000000000 | 
					
						
							|  |  |  |         return i | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-07-09 14:19:45 -07:00
										 |  |  |     def extractByte(self, address): | 
					
						
							| 
									
										
										
										
											2015-04-02 15:55:37 +02:00
										 |  |  |         error = lldb.SBError() | 
					
						
							| 
									
										
										
										
											2015-03-26 14:22:33 +01:00
										 |  |  |         return int(self.process.ReadUnsignedFromMemory(address, 1, error) & 0xFF) | 
					
						
							| 
									
										
										
										
											2013-07-09 14:19:45 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-04-30 10:46:48 +02:00
										 |  |  |     def handleCommand(self, command): | 
					
						
							|  |  |  |         result = lldb.SBCommandReturnObject() | 
					
						
							|  |  |  |         self.debugger.GetCommandInterpreter().HandleCommand(command, result) | 
					
						
							|  |  |  |         success = result.Succeeded() | 
					
						
							|  |  |  |         if success: | 
					
						
							|  |  |  |             self.report('output="%s"' % result.GetOutput()) | 
					
						
							| 
									
										
										
										
											2013-04-10 13:55:15 +02:00
										 |  |  |         else: | 
					
						
							| 
									
										
										
										
											2013-04-30 10:46:48 +02:00
										 |  |  |             self.report('error="%s"' % result.GetError()) | 
					
						
							|  |  |  |         self.reportData() | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     def put(self, stuff): | 
					
						
							|  |  |  |         sys.stdout.write(stuff) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-05-13 16:39:51 +02:00
										 |  |  |     def isMovableType(self, type): | 
					
						
							| 
									
										
										
										
											2013-10-23 16:28:02 +02:00
										 |  |  |         if type.GetTypeClass() in (lldb.eTypeClassBuiltin, lldb.eTypeClassPointer): | 
					
						
							| 
									
										
										
										
											2013-05-13 16:39:51 +02:00
										 |  |  |             return True | 
					
						
							| 
									
										
										
										
											2013-10-23 16:28:02 +02:00
										 |  |  |         return self.isKnownMovableType(self.stripNamespaceFromType(type.GetName())) | 
					
						
							| 
									
										
										
										
											2013-05-13 16:39:51 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-01-21 18:13:02 +01:00
										 |  |  |     def putPointerValue(self, value): | 
					
						
							|  |  |  |         # Use a lower priority | 
					
						
							|  |  |  |         if value is None: | 
					
						
							|  |  |  |             self.putEmptyValue(-1) | 
					
						
							|  |  |  |         else: | 
					
						
							|  |  |  |             self.putValue("0x%x" % value.Dereference()) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-10-24 13:27:10 +02:00
										 |  |  |     def putSimpleValue(self, value, encoding = None, priority = 0): | 
					
						
							|  |  |  |         self.putValue(value.GetValue(), encoding, priority) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-03-06 17:30:11 +01:00
										 |  |  |     def simpleEncoding(self, typeobj): | 
					
						
							|  |  |  |         code = typeobj.GetTypeClass() | 
					
						
							|  |  |  |         size = typeobj.sizeof | 
					
						
							|  |  |  |         if code == lldb.eTypeClassBuiltin: | 
					
						
							|  |  |  |             name = str(typeobj) | 
					
						
							|  |  |  |             if name == "float": | 
					
						
							|  |  |  |                 return Hex2EncodedFloat4 | 
					
						
							|  |  |  |             if name == "double": | 
					
						
							|  |  |  |                 return Hex2EncodedFloat8 | 
					
						
							|  |  |  |             if name.find("unsigned") >= 0: | 
					
						
							|  |  |  |                 if size == 1: | 
					
						
							|  |  |  |                     return Hex2EncodedUInt1 | 
					
						
							|  |  |  |                 if size == 2: | 
					
						
							|  |  |  |                     return Hex2EncodedUInt2 | 
					
						
							|  |  |  |                 if size == 4: | 
					
						
							|  |  |  |                     return Hex2EncodedUInt4 | 
					
						
							|  |  |  |                 if size == 8: | 
					
						
							|  |  |  |                     return Hex2EncodedUInt8 | 
					
						
							|  |  |  |             else: | 
					
						
							|  |  |  |                 if size == 1: | 
					
						
							|  |  |  |                     return Hex2EncodedInt1 | 
					
						
							|  |  |  |                 if size == 2: | 
					
						
							|  |  |  |                     return Hex2EncodedInt2 | 
					
						
							|  |  |  |                 if size == 4: | 
					
						
							|  |  |  |                     return Hex2EncodedInt4 | 
					
						
							|  |  |  |                 if size == 8: | 
					
						
							|  |  |  |                     return Hex2EncodedInt8 | 
					
						
							|  |  |  |         return None | 
					
						
							| 
									
										
										
										
											2013-05-08 16:20:03 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-06-28 14:04:05 +02:00
										 |  |  |     def createPointerValue(self, address, pointeeType): | 
					
						
							|  |  |  |         addr = int(address) & 0xFFFFFFFFFFFFFFFF | 
					
						
							| 
									
										
										
										
											2015-04-02 17:24:11 +02:00
										 |  |  |         sbaddr = lldb.SBAddress(addr, self.target) | 
					
						
							|  |  |  |         # Any type. | 
					
						
							|  |  |  |         # FIXME: This can be replaced with self.target.CreateValueFromExpression | 
					
						
							|  |  |  |         # as soon as we drop support for lldb builds not having that (~Xcode 6.1) | 
					
						
							|  |  |  |         dummy = self.target.CreateValueFromAddress('@', sbaddr, self.target.FindFirstType('char')) | 
					
						
							|  |  |  |         return dummy.CreateValueFromExpression('', '(%s*)%s' % (pointeeType, addr)) | 
					
						
							| 
									
										
										
										
											2013-06-28 14:04:05 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     def createValue(self, address, referencedType): | 
					
						
							|  |  |  |         addr = int(address) & 0xFFFFFFFFFFFFFFFF | 
					
						
							| 
									
										
										
										
											2015-04-02 17:24:11 +02:00
										 |  |  |         sbaddr = lldb.SBAddress(addr, self.target) | 
					
						
							| 
									
										
										
										
											2015-04-13 18:10:35 +02:00
										 |  |  |         return self.target.CreateValueFromAddress('@', sbaddr, referencedType) | 
					
						
							| 
									
										
										
										
											2013-06-28 14:04:05 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-05-08 16:20:03 +02:00
										 |  |  |     def childRange(self): | 
					
						
							|  |  |  |         if self.currentMaxNumChild is None: | 
					
						
							|  |  |  |             return xrange(0, self.currentNumChild) | 
					
						
							|  |  |  |         return xrange(min(self.currentMaxNumChild, self.currentNumChild)) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-01-16 14:23:53 +01:00
										 |  |  |     def canonicalTypeName(self, name): | 
					
						
							|  |  |  |         return re.sub('\\bconst\\b', '', name).replace(' ', '') | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-05-08 16:20:03 +02:00
										 |  |  |     def lookupType(self, name): | 
					
						
							| 
									
										
										
										
											2014-09-22 18:00:06 +02:00
										 |  |  |         #self.warn("LOOKUP TYPE NAME: %s" % name) | 
					
						
							| 
									
										
										
										
											2014-01-16 14:23:53 +01:00
										 |  |  |         typeobj = self.target.FindFirstType(name) | 
					
						
							|  |  |  |         if typeobj.IsValid(): | 
					
						
							|  |  |  |             return typeobj | 
					
						
							| 
									
										
										
										
											2014-12-01 12:17:56 +01:00
										 |  |  |         typeobj = self.target.FindFirstType(name + '*') | 
					
						
							|  |  |  |         if typeobj.IsValid(): | 
					
						
							|  |  |  |             return typeob.GetPointeeType() | 
					
						
							|  |  |  |         typeobj = self.target.FindFirstType(name + '&') | 
					
						
							|  |  |  |         if typeobj.IsValid(): | 
					
						
							|  |  |  |             return typeob.GetReferencedType() | 
					
						
							|  |  |  |         if name.endswith('*'): | 
					
						
							|  |  |  |             typeobj = self.target.FindFirstType(name[:-1].strip()) | 
					
						
							|  |  |  |             if typeobj.IsValid(): | 
					
						
							|  |  |  |                 return typeobj.GetPointerType() | 
					
						
							|  |  |  |         #self.warn("LOOKUP RESULT: %s" % typeobj.name) | 
					
						
							|  |  |  |         #self.warn("LOOKUP VALID: %s" % typeobj.IsValid()) | 
					
						
							|  |  |  |         needle = self.canonicalTypeName(name) | 
					
						
							|  |  |  |         #self.warn("NEEDLE: %s " % needle) | 
					
						
							|  |  |  |         for i in xrange(self.target.GetNumModules()): | 
					
						
							|  |  |  |             module = self.target.GetModuleAtIndex(i) | 
					
						
							|  |  |  |             # SBModule.GetType is new somewhere after early 300.x | 
					
						
							|  |  |  |             # So this may fail. | 
					
						
							|  |  |  |             for t in module.GetTypes(): | 
					
						
							|  |  |  |                 n = self.canonicalTypeName(t.GetName()) | 
					
						
							|  |  |  |                 if n == needle: | 
					
						
							|  |  |  |                     #self.warn("FOUND TYPE DIRECT 2: %s " % t) | 
					
						
							|  |  |  |                     return t | 
					
						
							|  |  |  |                 if n == needle + '*': | 
					
						
							|  |  |  |                     #self.warn("FOUND TYPE BY POINTER 2: %s " % t.GetPointeeType()) | 
					
						
							|  |  |  |                     return t.GetPointeeType() | 
					
						
							|  |  |  |                 if n == needle + '&': | 
					
						
							|  |  |  |                     #self.warn("FOUND TYPE BY REFERENCE 2: %s " % t) | 
					
						
							|  |  |  |                     return t.GetDereferencedType() | 
					
						
							|  |  |  |         #self.warn("NOT FOUND: %s " % needle) | 
					
						
							| 
									
										
										
										
											2014-01-16 14:23:53 +01:00
										 |  |  |         return None | 
					
						
							| 
									
										
										
										
											2013-05-08 16:20:03 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-05-07 12:34:10 +02:00
										 |  |  |     def setupInferior(self, args): | 
					
						
							| 
									
										
										
										
											2015-03-05 10:41:16 +01:00
										 |  |  |         self.reportToken(args) | 
					
						
							| 
									
										
										
										
											2013-04-30 10:46:48 +02:00
										 |  |  |         error = lldb.SBError() | 
					
						
							| 
									
										
										
										
											2013-10-01 02:30:12 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |         self.executable_ = args['executable'] | 
					
						
							| 
									
										
										
										
											2013-10-21 15:39:15 +02:00
										 |  |  |         self.startMode_ = args.get('startMode', 1) | 
					
						
							| 
									
										
										
										
											2014-02-28 13:03:21 +01:00
										 |  |  |         self.breakOnMain_ = args.get('breakOnMain', 0) | 
					
						
							| 
									
										
										
										
											2014-03-03 16:59:56 +01:00
										 |  |  |         self.useTerminal_ = args.get('useTerminal', 0) | 
					
						
							| 
									
										
										
										
											2014-02-04 13:32:17 +01:00
										 |  |  |         self.processArgs_ = args.get('processArgs', []) | 
					
						
							|  |  |  |         self.processArgs_ = map(lambda x: self.hexdecode(x), self.processArgs_) | 
					
						
							| 
									
										
										
										
											2013-10-21 15:39:15 +02:00
										 |  |  |         self.attachPid_ = args.get('attachPid', 0) | 
					
						
							| 
									
										
										
										
											2013-10-10 15:15:49 +02:00
										 |  |  |         self.sysRoot_ = args.get('sysRoot', '') | 
					
						
							| 
									
										
										
										
											2013-10-29 22:25:41 +01:00
										 |  |  |         self.remoteChannel_ = args.get('remoteChannel', '') | 
					
						
							| 
									
										
										
										
											2013-10-31 10:07:28 +01:00
										 |  |  |         self.platform_ = args.get('platform', '') | 
					
						
							| 
									
										
										
										
											2013-10-01 02:30:12 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-02-04 14:25:59 +01:00
										 |  |  |         self.ignoreStops = 0 | 
					
						
							| 
									
										
										
										
											2015-02-27 11:56:03 +01:00
										 |  |  |         self.silentStops = 0 | 
					
						
							|  |  |  |         if platform.system() == "Linux": | 
					
						
							|  |  |  |             if self.startMode_ == AttachCore: | 
					
						
							|  |  |  |                 pass | 
					
						
							|  |  |  |             else: | 
					
						
							|  |  |  |                 if self.useTerminal_: | 
					
						
							|  |  |  |                     self.ignoreStops = 2 | 
					
						
							|  |  |  |                 else: | 
					
						
							|  |  |  |                     self.silentStops = 1 | 
					
						
							| 
									
										
										
										
											2014-03-03 16:59:56 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-02-27 16:56:51 +01:00
										 |  |  |         else: | 
					
						
							|  |  |  |             if self.useTerminal_: | 
					
						
							|  |  |  |                 self.ignoreStops = 1 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-10-31 10:07:28 +01:00
										 |  |  |         if self.platform_: | 
					
						
							|  |  |  |             self.debugger.SetCurrentPlatform(self.platform_) | 
					
						
							| 
									
										
										
										
											2013-12-10 12:53:20 +01:00
										 |  |  |         # sysroot has to be set *after* the platform | 
					
						
							|  |  |  |         if self.sysRoot_: | 
					
						
							|  |  |  |             self.debugger.SetCurrentPlatformSDKRoot(self.sysRoot_) | 
					
						
							| 
									
										
										
										
											2014-02-04 18:36:32 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-02-27 11:56:03 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-02-04 18:36:32 +01:00
										 |  |  |         if os.path.isfile(self.executable_): | 
					
						
							|  |  |  |             self.target = self.debugger.CreateTarget(self.executable_, None, None, True, error) | 
					
						
							|  |  |  |         else: | 
					
						
							|  |  |  |             self.target = self.debugger.CreateTarget(None, None, None, True, error) | 
					
						
							| 
									
										
										
										
											2013-05-29 14:55:57 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-01-30 12:36:04 +01:00
										 |  |  |         if self.target.IsValid(): | 
					
						
							| 
									
										
										
										
											2015-02-02 13:48:33 +01:00
										 |  |  |             for bp in args['bkpts']: | 
					
						
							|  |  |  |                 self.insertBreakpoint(bp) | 
					
						
							| 
									
										
										
										
											2015-01-30 12:36:04 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-10-01 02:30:12 +02:00
										 |  |  |         state = "inferiorsetupok" if self.target.IsValid() else "inferiorsetupfailed" | 
					
						
							|  |  |  |         self.report('state="%s",msg="%s",exe="%s"' % (state, error, self.executable_)) | 
					
						
							| 
									
										
										
										
											2013-04-30 10:46:48 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-02-27 11:56:03 +01:00
										 |  |  |     def runEngine(self, args): | 
					
						
							|  |  |  |         self.prepare(args) | 
					
						
							| 
									
										
										
										
											2013-05-31 15:27:54 +02:00
										 |  |  |         s = threading.Thread(target=self.loop, args=[]) | 
					
						
							|  |  |  |         s.start() | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-02-27 11:56:03 +01:00
										 |  |  |     def prepare(self, args): | 
					
						
							| 
									
										
										
										
											2015-03-05 10:41:16 +01:00
										 |  |  |         self.reportToken(args) | 
					
						
							| 
									
										
										
										
											2013-04-30 10:46:48 +02:00
										 |  |  |         error = lldb.SBError() | 
					
						
							| 
									
										
										
										
											2013-05-31 15:27:54 +02:00
										 |  |  |         listener = self.debugger.GetListener() | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-10-01 02:30:12 +02:00
										 |  |  |         if self.attachPid_ > 0: | 
					
						
							|  |  |  |             attachInfo = lldb.SBAttachInfo(self.attachPid_) | 
					
						
							|  |  |  |             self.process = self.target.Attach(attachInfo, error) | 
					
						
							| 
									
										
										
										
											2013-10-31 10:07:28 +01:00
										 |  |  |             if not error.Success(): | 
					
						
							| 
									
										
										
										
											2014-03-19 12:12:24 +01:00
										 |  |  |                 self.reportState("inferiorrunfailed") | 
					
						
							| 
									
										
										
										
											2013-10-29 22:25:41 +01:00
										 |  |  |                 return | 
					
						
							|  |  |  |             self.report('pid="%s"' % self.process.GetProcessID()) | 
					
						
							| 
									
										
										
										
											2014-03-19 12:12:24 +01:00
										 |  |  |             # Even if it stops it seems that LLDB assumes it is running | 
					
						
							|  |  |  |             # and later detects that it did stop after all, so it is be | 
					
						
							|  |  |  |             # better to mirror that and wait for the spontaneous stop. | 
					
						
							|  |  |  |             self.reportState("enginerunandinferiorrunok") | 
					
						
							| 
									
										
										
										
											2014-07-01 12:30:38 +02:00
										 |  |  |         elif self.startMode_ == AttachToRemoteServer or self.startMode_ == AttachToRemoteProcess: | 
					
						
							| 
									
										
										
										
											2013-10-29 22:25:41 +01:00
										 |  |  |             self.process = self.target.ConnectRemote( | 
					
						
							| 
									
										
										
										
											2014-06-02 17:05:52 +02:00
										 |  |  |                 self.debugger.GetListener(), | 
					
						
							|  |  |  |                 self.remoteChannel_, None, error) | 
					
						
							| 
									
										
										
										
											2013-10-31 10:07:28 +01:00
										 |  |  |             if not error.Success(): | 
					
						
							| 
									
										
										
										
											2014-06-02 17:05:52 +02:00
										 |  |  |                 self.reportError(error) | 
					
						
							|  |  |  |                 self.reportState("enginerunfailed") | 
					
						
							| 
									
										
										
										
											2013-10-31 10:07:28 +01:00
										 |  |  |                 return | 
					
						
							| 
									
										
										
										
											2014-03-19 12:12:24 +01:00
										 |  |  |             # Even if it stops it seems that LLDB assumes it is running | 
					
						
							|  |  |  |             # and later detects that it did stop after all, so it is be | 
					
						
							|  |  |  |             # better to mirror that and wait for the spontaneous stop. | 
					
						
							|  |  |  |             self.reportState("enginerunandinferiorrunok") | 
					
						
							| 
									
										
										
										
											2015-02-27 11:56:03 +01:00
										 |  |  |         elif self.startMode_ == AttachCore: | 
					
						
							|  |  |  |             coreFile = args.get('coreFile', ''); | 
					
						
							|  |  |  |             self.process = self.target.LoadCore(coreFile) | 
					
						
							|  |  |  |             self.reportState("enginerunokandinferiorunrunnable") | 
					
						
							|  |  |  |             #self.reportContinuation(args) | 
					
						
							| 
									
										
										
										
											2013-10-01 02:30:12 +02:00
										 |  |  |         else: | 
					
						
							| 
									
										
										
										
											2014-02-04 13:32:17 +01:00
										 |  |  |             launchInfo = lldb.SBLaunchInfo(self.processArgs_) | 
					
						
							| 
									
										
										
										
											2013-10-01 02:30:12 +02:00
										 |  |  |             launchInfo.SetWorkingDirectory(os.getcwd()) | 
					
						
							| 
									
										
										
										
											2013-10-20 21:45:47 +02:00
										 |  |  |             environmentList = [key + "=" + value for key,value in os.environ.items()] | 
					
						
							|  |  |  |             launchInfo.SetEnvironmentEntries(environmentList, False) | 
					
						
							| 
									
										
										
										
											2014-02-28 13:03:21 +01:00
										 |  |  |             if self.breakOnMain_: | 
					
						
							|  |  |  |                 self.createBreakpointAtMain() | 
					
						
							| 
									
										
										
										
											2013-10-01 02:30:12 +02:00
										 |  |  |             self.process = self.target.Launch(launchInfo, error) | 
					
						
							| 
									
										
										
										
											2013-11-01 11:32:04 +01:00
										 |  |  |             if not error.Success(): | 
					
						
							| 
									
										
										
										
											2013-11-11 16:16:58 +01:00
										 |  |  |                 self.reportError(error) | 
					
						
							| 
									
										
										
										
											2014-03-19 12:12:24 +01:00
										 |  |  |                 self.reportState("enginerunfailed") | 
					
						
							| 
									
										
										
										
											2013-10-29 22:25:41 +01:00
										 |  |  |                 return | 
					
						
							|  |  |  |             self.report('pid="%s"' % self.process.GetProcessID()) | 
					
						
							| 
									
										
										
										
											2014-03-19 12:12:24 +01:00
										 |  |  |             self.reportState("enginerunandinferiorrunok") | 
					
						
							| 
									
										
										
										
											2013-04-30 10:46:48 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-09-22 17:55:20 +02:00
										 |  |  |     def loop(self): | 
					
						
							| 
									
										
										
										
											2013-05-31 15:27:54 +02:00
										 |  |  |         event = lldb.SBEvent() | 
					
						
							| 
									
										
										
										
											2014-09-22 17:55:20 +02:00
										 |  |  |         listener = self.debugger.GetListener() | 
					
						
							| 
									
										
										
										
											2013-05-31 15:27:54 +02:00
										 |  |  |         while True: | 
					
						
							|  |  |  |             if listener.WaitForEvent(10000000, event): | 
					
						
							|  |  |  |                 self.handleEvent(event) | 
					
						
							|  |  |  |             else: | 
					
						
							|  |  |  |                 warn('TIMEOUT') | 
					
						
							| 
									
										
										
										
											2013-05-13 16:04:00 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-05-07 08:46:51 +02:00
										 |  |  |     def describeError(self, error): | 
					
						
							| 
									
										
										
										
											2013-04-30 10:46:48 +02:00
										 |  |  |         desc = lldb.SBStream() | 
					
						
							|  |  |  |         error.GetDescription(desc) | 
					
						
							|  |  |  |         result = 'error={type="%s"' % error.GetType() | 
					
						
							|  |  |  |         result += ',code="%s"' % error.GetError() | 
					
						
							|  |  |  |         result += ',desc="%s"}' % desc.GetData() | 
					
						
							| 
									
										
										
										
											2013-05-07 08:46:51 +02:00
										 |  |  |         return result | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     def reportError(self, error): | 
					
						
							|  |  |  |         self.report(self.describeError(error)) | 
					
						
							| 
									
										
										
										
											2014-02-06 16:47:07 +01:00
										 |  |  |         if error.GetType(): | 
					
						
							|  |  |  |             self.reportStatus(error.GetCString()) | 
					
						
							| 
									
										
										
										
											2013-04-30 10:46:48 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     def currentThread(self): | 
					
						
							| 
									
										
										
										
											2014-01-29 11:43:11 +01:00
										 |  |  |         return None if self.process is None else self.process.GetSelectedThread() | 
					
						
							| 
									
										
										
										
											2013-04-30 10:46:48 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     def currentFrame(self): | 
					
						
							| 
									
										
										
										
											2014-01-29 11:43:11 +01:00
										 |  |  |         thread = self.currentThread() | 
					
						
							|  |  |  |         return None if thread is None else thread.GetSelectedFrame() | 
					
						
							| 
									
										
										
										
											2013-04-30 10:46:48 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-02-27 15:01:29 +01:00
										 |  |  |     def reportLocation(self, frame): | 
					
						
							| 
									
										
										
										
											2015-02-27 11:56:03 +01:00
										 |  |  |         if int(frame.pc) != 0xffffffffffffffff: | 
					
						
							|  |  |  |             file = fileName(frame.line_entry.file) | 
					
						
							|  |  |  |             line = frame.line_entry.line | 
					
						
							|  |  |  |             self.report('location={file="%s",line="%s",addr="%s"}' | 
					
						
							|  |  |  |                 % (file, line, frame.pc)) | 
					
						
							| 
									
										
										
										
											2013-04-30 10:46:48 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-11-11 15:27:24 +01:00
										 |  |  |     def firstStoppedThread(self): | 
					
						
							|  |  |  |         for i in xrange(0, self.process.GetNumThreads()): | 
					
						
							|  |  |  |             thread = self.process.GetThreadAtIndex(i) | 
					
						
							| 
									
										
										
										
											2013-12-02 10:37:16 +01:00
										 |  |  |             reason = thread.GetStopReason() | 
					
						
							|  |  |  |             if (reason == lldb.eStopReasonBreakpoint or | 
					
						
							|  |  |  |                     reason == lldb.eStopReasonException or | 
					
						
							|  |  |  |                     reason == lldb.eStopReasonPlanComplete or | 
					
						
							|  |  |  |                     reason == lldb.eStopReasonSignal or | 
					
						
							|  |  |  |                     reason == lldb.eStopReasonWatchpoint): | 
					
						
							| 
									
										
										
										
											2013-11-11 15:27:24 +01:00
										 |  |  |                 return thread | 
					
						
							|  |  |  |         return None | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-03-25 16:34:03 +01:00
										 |  |  |     def reportThreads(self, args): | 
					
						
							|  |  |  |         self.reportToken(args) | 
					
						
							| 
									
										
										
										
											2013-04-30 10:46:48 +02:00
										 |  |  |         result = 'threads={threads=[' | 
					
						
							| 
									
										
										
										
											2013-05-22 12:06:56 +02:00
										 |  |  |         for i in xrange(0, self.process.GetNumThreads()): | 
					
						
							| 
									
										
										
										
											2013-05-02 14:57:06 +02:00
										 |  |  |             thread = self.process.GetThreadAtIndex(i) | 
					
						
							| 
									
										
										
										
											2015-02-04 14:15:14 +01:00
										 |  |  |             if thread.is_stopped: | 
					
						
							|  |  |  |                 state = "stopped" | 
					
						
							|  |  |  |             elif thread.is_suspended: | 
					
						
							|  |  |  |                 state = "suspended" | 
					
						
							|  |  |  |             else: | 
					
						
							|  |  |  |                 state = "unknown" | 
					
						
							|  |  |  |             reason = thread.GetStopReason() | 
					
						
							| 
									
										
										
										
											2013-05-22 12:06:56 +02:00
										 |  |  |             result += '{id="%d"' % thread.GetThreadID() | 
					
						
							|  |  |  |             result += ',index="%s"' % i | 
					
						
							| 
									
										
										
										
											2013-05-29 16:59:16 +02:00
										 |  |  |             result += ',details="%s"' % thread.GetQueueName() | 
					
						
							| 
									
										
										
										
											2015-02-04 14:15:14 +01:00
										 |  |  |             result += ',stop-reason="%s"' % self.stopReason(thread.GetStopReason()) | 
					
						
							|  |  |  |             result += ',state="%s"' % state | 
					
						
							| 
									
										
										
										
											2013-05-02 14:57:06 +02:00
										 |  |  |             result += ',name="%s"' % thread.GetName() | 
					
						
							| 
									
										
										
										
											2013-04-30 10:46:48 +02:00
										 |  |  |             result += ',frame={' | 
					
						
							|  |  |  |             frame = thread.GetFrameAtIndex(0) | 
					
						
							|  |  |  |             result += 'pc="0x%x"' % frame.pc | 
					
						
							|  |  |  |             result += ',addr="0x%x"' % frame.pc | 
					
						
							|  |  |  |             result += ',fp="0x%x"' % frame.fp | 
					
						
							| 
									
										
										
										
											2013-05-29 16:59:16 +02:00
										 |  |  |             result += ',func="%s"' % frame.GetFunctionName() | 
					
						
							| 
									
										
										
										
											2013-04-30 10:46:48 +02:00
										 |  |  |             result += ',line="%s"' % frame.line_entry.line | 
					
						
							|  |  |  |             result += ',fullname="%s"' % fileName(frame.line_entry.file) | 
					
						
							|  |  |  |             result += ',file="%s"' % fileName(frame.line_entry.file) | 
					
						
							|  |  |  |             result += '}},' | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-03-25 16:34:03 +01:00
										 |  |  |         result += ']},' | 
					
						
							| 
									
										
										
										
											2013-04-30 10:46:48 +02:00
										 |  |  |         self.report(result) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-03-25 16:34:03 +01:00
										 |  |  |     def reportCurrentThread(self, args): | 
					
						
							|  |  |  |         self.reportToken(args) | 
					
						
							|  |  |  |         self.report('current-thread={id="%s"}' % self.currentThread().id) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-11-11 15:27:24 +01:00
										 |  |  |     def firstUsableFrame(self, thread): | 
					
						
							| 
									
										
										
										
											2013-07-02 15:43:29 +02:00
										 |  |  |         for i in xrange(10): | 
					
						
							| 
									
										
										
										
											2013-06-14 10:03:00 +02:00
										 |  |  |             frame = thread.GetFrameAtIndex(i) | 
					
						
							|  |  |  |             lineEntry = frame.GetLineEntry() | 
					
						
							|  |  |  |             line = lineEntry.GetLine() | 
					
						
							|  |  |  |             if line != 0: | 
					
						
							|  |  |  |                 return i | 
					
						
							|  |  |  |         return None | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-02-05 14:19:32 +01:00
										 |  |  |     def reportStack(self, args): | 
					
						
							| 
									
										
										
										
											2015-03-05 10:41:16 +01:00
										 |  |  |         self.reportToken(args) | 
					
						
							| 
									
										
										
										
											2013-11-05 16:12:31 +01:00
										 |  |  |         if not self.process: | 
					
						
							| 
									
										
										
										
											2013-04-30 10:46:48 +02:00
										 |  |  |             self.report('msg="No process"') | 
					
						
							| 
									
										
										
										
											2013-11-05 16:12:31 +01:00
										 |  |  |             return | 
					
						
							|  |  |  |         thread = self.currentThread() | 
					
						
							|  |  |  |         if not thread: | 
					
						
							|  |  |  |             self.report('msg="No thread"') | 
					
						
							|  |  |  |             return | 
					
						
							| 
									
										
										
										
											2014-02-03 13:47:26 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-03-04 11:49:27 +01:00
										 |  |  |         self.reportLocation(thread.GetFrameAtIndex(0)) # FIXME | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-02-05 14:19:32 +01:00
										 |  |  |         isNativeMixed = int(args.get('nativeMixed', 0)) | 
					
						
							| 
									
										
										
										
											2014-02-03 13:47:26 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-02-05 14:19:32 +01:00
										 |  |  |         limit = args.get('stacklimit', -1) | 
					
						
							|  |  |  |         (n, isLimited) = (limit, True) if limit > 0 else (thread.GetNumFrames(), False) | 
					
						
							| 
									
										
										
										
											2015-02-04 17:21:55 +01:00
										 |  |  |         self.currentCallContext = None | 
					
						
							| 
									
										
										
										
											2014-03-06 12:04:47 +01:00
										 |  |  |         result = 'stack={current-thread="%s"' % thread.GetThreadID() | 
					
						
							| 
									
										
										
										
											2013-11-05 16:12:31 +01:00
										 |  |  |         result += ',frames=[' | 
					
						
							|  |  |  |         for i in xrange(n): | 
					
						
							|  |  |  |             frame = thread.GetFrameAtIndex(i) | 
					
						
							| 
									
										
										
										
											2014-02-03 13:47:26 +01:00
										 |  |  |             if not frame.IsValid(): | 
					
						
							|  |  |  |                 isLimited = False | 
					
						
							|  |  |  |                 break | 
					
						
							| 
									
										
										
										
											2015-02-04 13:29:42 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-11-05 16:12:31 +01:00
										 |  |  |             lineEntry = frame.GetLineEntry() | 
					
						
							| 
									
										
										
										
											2015-02-04 13:29:42 +01:00
										 |  |  |             lineNumber = lineEntry.GetLine() | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             pc = frame.GetPC() | 
					
						
							|  |  |  |             level = frame.idx | 
					
						
							|  |  |  |             addr = frame.GetPCAddress().GetLoadAddress(self.target) | 
					
						
							|  |  |  |             functionName = frame.GetFunctionName() | 
					
						
							|  |  |  |             fullname = fileName(lineEntry.file) | 
					
						
							|  |  |  |             usable = None | 
					
						
							|  |  |  |             language = None | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-02-05 14:19:32 +01:00
										 |  |  |             if isNativeMixed: | 
					
						
							| 
									
										
										
										
											2015-02-04 13:29:42 +01:00
										 |  |  |                 if self.isReportableQmlFrame(functionName): | 
					
						
							| 
									
										
										
										
											2015-02-04 17:21:55 +01:00
										 |  |  |                     engine = frame.FindVariable("engine") | 
					
						
							|  |  |  |                     self.context = engine | 
					
						
							|  |  |  |                     h = self.extractQmlLocation(engine) | 
					
						
							|  |  |  |                     pc = 0 | 
					
						
							|  |  |  |                     functionName = h['functionName'] | 
					
						
							|  |  |  |                     fullname = h['fileName'] | 
					
						
							|  |  |  |                     lineNumber = h['lineNumber'] | 
					
						
							|  |  |  |                     addr = h['context'] | 
					
						
							|  |  |  |                     language = 'js' | 
					
						
							| 
									
										
										
										
											2015-02-04 13:29:42 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |                 elif not functionName is None: | 
					
						
							|  |  |  |                     if functionName.startswith("qt_v4"): | 
					
						
							|  |  |  |                         usable = 0 | 
					
						
							|  |  |  |                     elif functionName.find("QV4::") >= 0: | 
					
						
							|  |  |  |                         usable = 0 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             result += '{pc="0x%x"' % pc | 
					
						
							|  |  |  |             result += ',level="%d"' % level | 
					
						
							|  |  |  |             result += ',addr="0x%x"' % addr | 
					
						
							|  |  |  |             if not usable is None: | 
					
						
							|  |  |  |                 result += ',usable="%s"' % usable | 
					
						
							|  |  |  |             result += ',func="%s"' % functionName | 
					
						
							|  |  |  |             result += ',line="%d"' % lineNumber | 
					
						
							|  |  |  |             if not language is None: | 
					
						
							|  |  |  |                 result += ',language="%s"' % language | 
					
						
							|  |  |  |             result += ',fullname="%s"' % fullname | 
					
						
							|  |  |  |             result += ',file="%s"},' % fullname | 
					
						
							| 
									
										
										
										
											2014-02-03 13:47:26 +01:00
										 |  |  |         result += ']' | 
					
						
							|  |  |  |         result += ',hasmore="%d"' % isLimited | 
					
						
							|  |  |  |         result += ',limit="%d"' % limit | 
					
						
							|  |  |  |         result += '}' | 
					
						
							| 
									
										
										
										
											2013-11-05 16:12:31 +01:00
										 |  |  |         self.report(result) | 
					
						
							| 
									
										
										
										
											2015-02-24 11:33:25 +01:00
										 |  |  |         self.reportContinuation(args) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-03-05 10:41:16 +01:00
										 |  |  |     def reportToken(self, args): | 
					
						
							|  |  |  |         if "token" in args: | 
					
						
							|  |  |  |             # Unusual syntax intended, to support the double-click in left | 
					
						
							|  |  |  |             # logview pane feature. | 
					
						
							|  |  |  |             self.report('token(\"%s\")' % args["token"]) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-02-24 11:33:25 +01:00
										 |  |  |     def reportContinuation(self, args): | 
					
						
							| 
									
										
										
										
											2015-04-01 08:05:04 +02:00
										 |  |  |         if not self.isShuttingDown_ and "continuation" in args: | 
					
						
							| 
									
										
										
										
											2015-02-24 11:33:25 +01:00
										 |  |  |             self.report('continuation=\"%s\"' % args["continuation"]) | 
					
						
							| 
									
										
										
										
											2013-04-30 10:46:48 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-01-23 15:30:51 +01:00
										 |  |  |     def extractBlob(self, base, size): | 
					
						
							| 
									
										
										
										
											2013-05-22 14:30:36 +02:00
										 |  |  |         if size == 0: | 
					
						
							| 
									
										
										
										
											2014-01-23 15:30:51 +01:00
										 |  |  |             return Blob("") | 
					
						
							| 
									
										
										
										
											2013-05-17 17:14:45 +02:00
										 |  |  |         base = int(base) & 0xFFFFFFFFFFFFFFFF | 
					
						
							|  |  |  |         size = int(size) & 0xFFFFFFFF | 
					
						
							| 
									
										
										
										
											2013-05-22 14:30:36 +02:00
										 |  |  |         error = lldb.SBError() | 
					
						
							| 
									
										
										
										
											2014-01-23 15:30:51 +01:00
										 |  |  |         return Blob(self.process.ReadMemory(base, size, error)) | 
					
						
							| 
									
										
										
										
											2013-05-07 16:43:20 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-01-24 16:55:44 +01:00
										 |  |  |     def toBlob(self, value): | 
					
						
							|  |  |  |         data = value.GetData() | 
					
						
							|  |  |  |         size = int(data.GetByteSize()) | 
					
						
							|  |  |  |         buf = bytearray(struct.pack('x' * size)) | 
					
						
							|  |  |  |         error = lldb.SBError() | 
					
						
							|  |  |  |         #data.ReadRawData(error, 0, buf) | 
					
						
							|  |  |  |         for i in range(size): | 
					
						
							|  |  |  |             buf[i] = data.GetUnsignedInt8(error, i) | 
					
						
							|  |  |  |         return Blob(bytes(buf)) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-04-11 13:20:59 +02:00
										 |  |  |     def mangleName(self, typeName): | 
					
						
							|  |  |  |         return '_ZN%sE' % ''.join(map(lambda x: "%d%s" % (len(x), x), typeName.split('::'))) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     def findStaticMetaObject(self, typeName): | 
					
						
							|  |  |  |         symbolName = self.mangleName(typeName + '::staticMetaObject') | 
					
						
							|  |  |  |         return self.target.FindFirstGlobalVariable(symbolName) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-03-12 13:20:21 +01:00
										 |  |  |     def findSymbol(self, symbolName): | 
					
						
							|  |  |  |         return self.target.FindFirstGlobalVariable(symbolName) | 
					
						
							| 
									
										
										
										
											2013-07-03 13:32:19 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-05-08 16:20:03 +02:00
										 |  |  |     def stripNamespaceFromType(self, typeName): | 
					
						
							| 
									
										
										
										
											2014-09-12 13:31:12 +02:00
										 |  |  |         #type = self.stripClassTag(typeName) | 
					
						
							| 
									
										
										
										
											2013-05-08 16:20:03 +02:00
										 |  |  |         type = typeName | 
					
						
							| 
									
										
										
										
											2014-01-09 13:25:17 +01:00
										 |  |  |         ns = self.qtNamespace() | 
					
						
							|  |  |  |         if len(ns) > 0 and type.startswith(ns): | 
					
						
							|  |  |  |             type = type[len(ns):] | 
					
						
							| 
									
										
										
										
											2013-05-08 16:20:03 +02:00
										 |  |  |         pos = type.find("<") | 
					
						
							|  |  |  |         # FIXME: make it recognize  foo<A>::bar<B>::iterator? | 
					
						
							|  |  |  |         while pos != -1: | 
					
						
							|  |  |  |             pos1 = type.rfind(">", pos) | 
					
						
							|  |  |  |             type = type[0:pos] + type[pos1+1:] | 
					
						
							|  |  |  |             pos = type.find("<") | 
					
						
							| 
									
										
										
										
											2013-07-03 13:32:19 +02:00
										 |  |  |         if type.startswith("const "): | 
					
						
							|  |  |  |             type = type[6:] | 
					
						
							|  |  |  |         if type.startswith("volatile "): | 
					
						
							|  |  |  |             type = type[9:] | 
					
						
							| 
									
										
										
										
											2013-05-08 16:20:03 +02:00
										 |  |  |         return type | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     def putSubItem(self, component, value, tryDynamic=True): | 
					
						
							| 
									
										
										
										
											2013-05-13 16:39:51 +02:00
										 |  |  |         if not value.IsValid(): | 
					
						
							| 
									
										
										
										
											2015-02-24 12:38:08 +01:00
										 |  |  |             self.warn("INVALID SUBITEM: %s" % value.GetName()) | 
					
						
							| 
									
										
										
										
											2013-05-13 16:39:51 +02:00
										 |  |  |             return | 
					
						
							| 
									
										
										
										
											2013-05-08 16:20:03 +02:00
										 |  |  |         with SubItem(self, component): | 
					
						
							|  |  |  |             self.putItem(value, tryDynamic) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-06-11 14:24:26 +02:00
										 |  |  |     def putAddress(self, addr): | 
					
						
							| 
									
										
										
										
											2014-01-22 14:01:07 +01:00
										 |  |  |         #if int(addr) == 0xffffffffffffffff: | 
					
						
							|  |  |  |         #    raise RuntimeError("Illegal address") | 
					
						
							|  |  |  |         if self.currentPrintsAddress and not addr is None: | 
					
						
							|  |  |  |             self.put('addr="0x%x",' % int(addr)) | 
					
						
							| 
									
										
										
										
											2013-06-11 14:24:26 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-01-31 13:52:47 +01:00
										 |  |  |     def isFunctionType(self, typeobj): | 
					
						
							|  |  |  |         if self.isGoodLldb: | 
					
						
							|  |  |  |             return typeobj.IsFunctionType() | 
					
						
							|  |  |  |         #warn("TYPE: %s" % typeobj) | 
					
						
							|  |  |  |         return False | 
					
						
							| 
									
										
										
										
											2013-11-06 17:57:12 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-04-30 10:46:48 +02:00
										 |  |  |     def putItem(self, value, tryDynamic=True): | 
					
						
							| 
									
										
										
										
											2014-01-09 16:23:17 +01:00
										 |  |  |         typeName = value.GetType().GetUnqualifiedType().GetName() | 
					
						
							| 
									
										
										
										
											2014-01-31 13:52:47 +01:00
										 |  |  |         if self.isGoodLldb: | 
					
						
							|  |  |  |             value.SetPreferDynamicValue(tryDynamic) | 
					
						
							| 
									
										
										
										
											2013-07-03 13:32:19 +02:00
										 |  |  |         typeClass = value.GetType().GetTypeClass() | 
					
						
							| 
									
										
										
										
											2013-05-08 16:20:03 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-06-11 14:24:26 +02:00
										 |  |  |         if tryDynamic: | 
					
						
							| 
									
										
										
										
											2014-01-22 14:01:07 +01:00
										 |  |  |             self.putAddress(value.GetLoadAddress()) | 
					
						
							| 
									
										
										
										
											2013-06-11 14:24:26 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-05-22 12:06:56 +02:00
										 |  |  |         # Handle build-in LLDB visualizers if wanted. | 
					
						
							| 
									
										
										
										
											2014-01-22 14:01:07 +01:00
										 |  |  |         if False and self.useLldbDumpers and value.GetTypeSynthetic().IsValid(): | 
					
						
							| 
									
										
										
										
											2013-05-13 16:04:00 +02:00
										 |  |  |             # FIXME: print "official" summary? | 
					
						
							|  |  |  |             summary = value.GetTypeSummary() | 
					
						
							|  |  |  |             if summary.IsValid(): | 
					
						
							|  |  |  |                 warn("DATA: %s" % summary.GetData()) | 
					
						
							| 
									
										
										
										
											2014-01-31 13:52:47 +01:00
										 |  |  |             if self.isGoodLldb: | 
					
						
							|  |  |  |                 value.SetPreferSyntheticValue(False) | 
					
						
							| 
									
										
										
										
											2013-05-13 16:04:00 +02:00
										 |  |  |             provider = value.GetTypeSynthetic() | 
					
						
							|  |  |  |             data = provider.GetData() | 
					
						
							|  |  |  |             formatter = eval(data)(value, {}) | 
					
						
							|  |  |  |             formatter.update() | 
					
						
							|  |  |  |             numchild = formatter.num_children() | 
					
						
							| 
									
										
										
										
											2013-05-07 16:43:20 +02:00
										 |  |  |             self.put('iname="%s",' % self.currentIName) | 
					
						
							| 
									
										
										
										
											2013-06-04 16:15:56 +02:00
										 |  |  |             self.putType(typeName) | 
					
						
							| 
									
										
										
										
											2013-05-07 16:43:20 +02:00
										 |  |  |             self.put('numchild="%s",' % numchild) | 
					
						
							|  |  |  |             self.put('addr="0x%x",' % value.GetLoadAddress()) | 
					
						
							| 
									
										
										
										
											2013-05-13 16:04:00 +02:00
										 |  |  |             self.putItemCount(numchild) | 
					
						
							| 
									
										
										
										
											2013-05-07 16:43:20 +02:00
										 |  |  |             if self.currentIName in self.expandedINames: | 
					
						
							|  |  |  |                 with Children(self): | 
					
						
							| 
									
										
										
										
											2013-05-13 16:04:00 +02:00
										 |  |  |                     for i in xrange(numchild): | 
					
						
							|  |  |  |                         child = formatter.get_child_at_index(i) | 
					
						
							|  |  |  |                         with SubItem(self, i): | 
					
						
							|  |  |  |                             self.putItem(child) | 
					
						
							|  |  |  |             return | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-07-03 17:20:46 +02:00
										 |  |  |         # Typedefs | 
					
						
							|  |  |  |         if typeClass == lldb.eTypeClassTypedef: | 
					
						
							| 
									
										
										
										
											2013-10-30 15:07:54 +01:00
										 |  |  |             if typeName in self.qqDumpers: | 
					
						
							| 
									
										
										
										
											2013-07-03 17:20:46 +02:00
										 |  |  |                 self.putType(typeName) | 
					
						
							|  |  |  |                 self.context = value | 
					
						
							| 
									
										
										
										
											2013-10-30 15:07:54 +01:00
										 |  |  |                 self.qqDumpers[typeName](self, value) | 
					
						
							| 
									
										
										
										
											2013-07-03 17:20:46 +02:00
										 |  |  |                 return | 
					
						
							| 
									
										
										
										
											2013-07-05 09:22:55 +02:00
										 |  |  |             realType = value.GetType() | 
					
						
							|  |  |  |             if hasattr(realType, 'GetCanonicalType'): | 
					
						
							| 
									
										
										
										
											2014-01-09 18:02:09 +01:00
										 |  |  |                 baseType = realType.GetCanonicalType() | 
					
						
							| 
									
										
										
										
											2014-11-26 18:10:14 +01:00
										 |  |  |                 if baseType != realType: | 
					
						
							|  |  |  |                     baseValue = value.Cast(baseType.unqualified()) | 
					
						
							|  |  |  |                     self.putItem(baseValue) | 
					
						
							|  |  |  |                     self.putBetterType(realType) | 
					
						
							|  |  |  |                     return | 
					
						
							| 
									
										
										
										
											2013-07-03 17:20:46 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-05-22 12:06:56 +02:00
										 |  |  |         # Our turf now. | 
					
						
							| 
									
										
										
										
											2014-01-31 13:52:47 +01:00
										 |  |  |         if self.isGoodLldb: | 
					
						
							|  |  |  |             value.SetPreferSyntheticValue(False) | 
					
						
							| 
									
										
										
										
											2013-05-17 09:50:39 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-06-10 14:50:22 +02:00
										 |  |  |         # Arrays | 
					
						
							| 
									
										
										
										
											2013-07-03 13:32:19 +02:00
										 |  |  |         if typeClass == lldb.eTypeClassArray: | 
					
						
							| 
									
										
										
										
											2013-11-07 12:26:14 +01:00
										 |  |  |             self.putCStyleArray(value) | 
					
						
							| 
									
										
										
										
											2013-06-10 14:50:22 +02:00
										 |  |  |             return | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-10-24 18:46:07 +02:00
										 |  |  |         # Vectors like char __attribute__ ((vector_size (8))) | 
					
						
							|  |  |  |         if typeClass == lldb.eTypeClassVector: | 
					
						
							| 
									
										
										
										
											2013-11-07 12:26:14 +01:00
										 |  |  |             self.putCStyleArray(value) | 
					
						
							| 
									
										
										
										
											2013-10-24 18:46:07 +02:00
										 |  |  |             return | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-05-17 09:50:39 +02:00
										 |  |  |         # References | 
					
						
							|  |  |  |         if value.GetType().IsReferenceType(): | 
					
						
							| 
									
										
										
										
											2013-07-05 09:22:55 +02:00
										 |  |  |             type = value.GetType().GetDereferencedType().unqualified() | 
					
						
							| 
									
										
										
										
											2014-11-26 18:10:14 +01:00
										 |  |  |             addr = value.GetValueAsUnsigned() | 
					
						
							|  |  |  |             #warn("FROM: %s" % value) | 
					
						
							|  |  |  |             #warn("ADDR: 0x%x" % addr) | 
					
						
							|  |  |  |             #warn("TYPE: %s" % type) | 
					
						
							|  |  |  |             # Works: | 
					
						
							|  |  |  |             #item = self.currentThread().GetSelectedFrame().EvaluateExpression( | 
					
						
							|  |  |  |             #    "(%s*)0x%x" % (type, addr)).Dereference() | 
					
						
							|  |  |  |             # Works: | 
					
						
							|  |  |  |             item = value.CreateValueFromExpression(None, | 
					
						
							|  |  |  |                 "(%s*)0x%x" % (type, addr), lldb.SBExpressionOptions()).Dereference() | 
					
						
							|  |  |  |             # Does not work: | 
					
						
							|  |  |  |             #item = value.CreateValueFromAddress(None, addr, type) | 
					
						
							|  |  |  |             # Does not work: | 
					
						
							|  |  |  |             #item = value.Cast(type.GetPointerType()).Dereference() | 
					
						
							|  |  |  |             #warn("TOOO: %s" % item) | 
					
						
							|  |  |  |             self.putItem(item) | 
					
						
							|  |  |  |             self.putBetterType(value.GetTypeName()) | 
					
						
							| 
									
										
										
										
											2013-05-17 09:50:39 +02:00
										 |  |  |             return | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-05-17 10:10:13 +02:00
										 |  |  |         # Pointers | 
					
						
							| 
									
										
										
										
											2013-07-03 13:32:19 +02:00
										 |  |  |         if value.GetType().IsPointerType(): | 
					
						
							| 
									
										
										
										
											2013-11-06 17:57:12 +01:00
										 |  |  |             self.putFormattedPointer(value) | 
					
						
							|  |  |  |             return | 
					
						
							| 
									
										
										
										
											2013-05-17 10:10:13 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-04-14 12:43:04 +02:00
										 |  |  |         # Chars | 
					
						
							|  |  |  |         if typeClass == lldb.eTypeClassBuiltin: | 
					
						
							|  |  |  |             basicType = value.GetType().GetBasicType() | 
					
						
							|  |  |  |             if basicType == lldb.eBasicTypeChar: | 
					
						
							|  |  |  |                 self.putValue(value.GetValueAsUnsigned()) | 
					
						
							|  |  |  |                 self.putType(typeName) | 
					
						
							|  |  |  |                 self.putNumChild(0) | 
					
						
							|  |  |  |                 return | 
					
						
							|  |  |  |             if basicType == lldb.eBasicTypeSignedChar: | 
					
						
							|  |  |  |                 self.putValue(value.GetValueAsSigned()) | 
					
						
							|  |  |  |                 self.putType(typeName) | 
					
						
							|  |  |  |                 self.putNumChild(0) | 
					
						
							|  |  |  |                 return | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-05-13 16:04:00 +02:00
										 |  |  |         #warn("VALUE: %s" % value) | 
					
						
							| 
									
										
										
										
											2013-06-05 11:26:46 +02:00
										 |  |  |         #warn("FANCY: %s" % self.useFancy) | 
					
						
							| 
									
										
										
										
											2015-03-20 16:03:59 +01:00
										 |  |  |         if self.tryPutPrettyItem(typeName, value): | 
					
						
							|  |  |  |             return | 
					
						
							| 
									
										
										
										
											2013-05-13 16:04:00 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |         # Normal value | 
					
						
							|  |  |  |         #numchild = 1 if value.MightHaveChildren() else 0 | 
					
						
							|  |  |  |         numchild = value.GetNumChildren() | 
					
						
							| 
									
										
										
										
											2013-06-04 16:15:56 +02:00
										 |  |  |         self.putType(typeName) | 
					
						
							| 
									
										
										
										
											2014-01-29 16:14:10 +01:00
										 |  |  |         self.putEmptyValue(-1) | 
					
						
							|  |  |  |         staticMetaObject = self.extractStaticMetaObject(value.GetType()) | 
					
						
							|  |  |  |         if staticMetaObject: | 
					
						
							|  |  |  |             self.context = value | 
					
						
							|  |  |  |             self.putQObjectNameValue(value) | 
					
						
							| 
									
										
										
										
											2013-07-03 13:32:19 +02:00
										 |  |  |         else: | 
					
						
							|  |  |  |             v = value.GetValue() | 
					
						
							|  |  |  |             if v: | 
					
						
							|  |  |  |                 self.putValue(v) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-05-13 16:04:00 +02:00
										 |  |  |         self.put('numchild="%s",' % numchild) | 
					
						
							| 
									
										
										
										
											2014-01-22 14:01:07 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-05-13 16:04:00 +02:00
										 |  |  |         if self.currentIName in self.expandedINames: | 
					
						
							|  |  |  |             with Children(self): | 
					
						
							|  |  |  |                 self.putFields(value) | 
					
						
							| 
									
										
										
										
											2014-01-29 16:14:10 +01:00
										 |  |  |                 if staticMetaObject: | 
					
						
							|  |  |  |                     self.putQObjectGuts(value, staticMetaObject) | 
					
						
							| 
									
										
										
										
											2013-04-30 10:46:48 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-01-22 14:01:07 +01:00
										 |  |  |     def warn(self, msg): | 
					
						
							| 
									
										
										
										
											2014-09-22 18:00:06 +02:00
										 |  |  |         self.put('{name="%s",value="",type="",numchild="0"},' % msg) | 
					
						
							| 
									
										
										
										
											2014-01-22 14:01:07 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-04-30 10:46:48 +02:00
										 |  |  |     def putFields(self, value): | 
					
						
							| 
									
										
										
										
											2013-07-04 16:01:43 +02:00
										 |  |  |         # Suppress printing of 'name' field for arrays. | 
					
						
							|  |  |  |         if value.GetType().GetTypeClass() == lldb.eTypeClassArray: | 
					
						
							|  |  |  |             for i in xrange(value.GetNumChildren()): | 
					
						
							|  |  |  |                 child = value.GetChildAtIndex(i) | 
					
						
							| 
									
										
										
										
											2013-07-08 16:24:34 +02:00
										 |  |  |                 with UnnamedSubItem(self, str(i)): | 
					
						
							| 
									
										
										
										
											2013-07-04 16:01:43 +02:00
										 |  |  |                     self.putItem(child) | 
					
						
							|  |  |  |             return | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-04-30 10:46:48 +02:00
										 |  |  |         n = value.GetNumChildren() | 
					
						
							| 
									
										
										
										
											2013-06-20 17:18:52 +02:00
										 |  |  |         m = value.GetType().GetNumberOfDirectBaseClasses() | 
					
						
							| 
									
										
										
										
											2013-04-30 10:46:48 +02:00
										 |  |  |         if n > 10000: | 
					
						
							|  |  |  |             n = 10000 | 
					
						
							| 
									
										
										
										
											2013-06-21 13:46:56 +02:00
										 |  |  |         # seems to happen in the 'inheritance' autotest | 
					
						
							|  |  |  |         if m > n: | 
					
						
							|  |  |  |             m = n | 
					
						
							| 
									
										
										
										
											2013-06-20 17:18:52 +02:00
										 |  |  |         for i in xrange(m): | 
					
						
							|  |  |  |             child = value.GetChildAtIndex(i) | 
					
						
							|  |  |  |             with UnnamedSubItem(self, "@%d" % (i + 1)): | 
					
						
							| 
									
										
										
										
											2013-07-09 17:26:19 +02:00
										 |  |  |                 self.put('iname="%s",' % self.currentIName) | 
					
						
							| 
									
										
										
										
											2013-06-20 17:18:52 +02:00
										 |  |  |                 self.put('name="[%s]",' % child.name) | 
					
						
							|  |  |  |                 self.putItem(child) | 
					
						
							| 
									
										
										
										
											2015-05-29 08:23:52 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |         children = [value.GetChildAtIndex(i) for i in xrange(m, n)] | 
					
						
							|  |  |  |         if self.sortStructMembers: | 
					
						
							|  |  |  |             children.sort(key = lambda child: str(child.GetName())) | 
					
						
							|  |  |  |         for child in children: | 
					
						
							| 
									
										
										
										
											2014-01-30 18:13:45 +01:00
										 |  |  |             # Only needed in the QVariant4 test. | 
					
						
							| 
									
										
										
										
											2014-01-20 15:57:09 +01:00
										 |  |  |             if int(child.GetLoadAddress()) == 0xffffffffffffffff: | 
					
						
							|  |  |  |                 typeClass = child.GetType().GetTypeClass() | 
					
						
							|  |  |  |                 if typeClass != lldb.eTypeClassBuiltin: | 
					
						
							|  |  |  |                     field = value.GetType().GetFieldAtIndex(i) | 
					
						
							|  |  |  |                     addr = value.GetLoadAddress() + field.GetOffsetInBytes() | 
					
						
							| 
									
										
										
										
											2014-01-22 14:01:07 +01:00
										 |  |  |                     child = value.CreateValueFromAddress(child.GetName(), addr, child.GetType()) | 
					
						
							| 
									
										
										
										
											2013-07-05 09:22:55 +02:00
										 |  |  |             if child.IsValid():  # FIXME: Anon members? | 
					
						
							|  |  |  |                 with SubItem(self, child): | 
					
						
							|  |  |  |                     self.putItem(child) | 
					
						
							| 
									
										
										
										
											2013-04-30 10:46:48 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-04-02 15:55:37 +02:00
										 |  |  |     def reportVariables(self, args = {}): | 
					
						
							| 
									
										
										
										
											2014-03-19 12:08:25 +01:00
										 |  |  |         with self.outputLock: | 
					
						
							| 
									
										
										
										
											2015-02-02 15:05:30 +01:00
										 |  |  |             sys.stdout.write("@\n") | 
					
						
							| 
									
										
										
										
											2014-03-19 12:08:25 +01:00
										 |  |  |             self.reportVariablesHelper(args) | 
					
						
							|  |  |  |             sys.stdout.write("@\n") | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-04-02 15:55:37 +02:00
										 |  |  |     def reportVariablesHelper(self, args = {}): | 
					
						
							| 
									
										
										
										
											2014-01-29 11:43:11 +01:00
										 |  |  |         frame = self.currentFrame() | 
					
						
							|  |  |  |         if frame is None: | 
					
						
							|  |  |  |             return | 
					
						
							| 
									
										
										
										
											2015-03-26 13:03:38 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |         partialVariable = args.get("partialVariable", "") | 
					
						
							|  |  |  |         isPartial = len(partialVariable) > 0 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-05-30 15:35:52 +02:00
										 |  |  |         self.currentIName = 'local' | 
					
						
							| 
									
										
										
										
											2015-03-26 13:03:38 +01:00
										 |  |  |         self.put('all={data=[') | 
					
						
							| 
									
										
										
										
											2013-07-08 18:14:00 +02:00
										 |  |  |         self.anonNumber = 0 | 
					
						
							| 
									
										
										
										
											2013-10-25 13:35:31 +02:00
										 |  |  |         shadowed = {} | 
					
						
							| 
									
										
										
										
											2014-01-16 10:28:36 +01:00
										 |  |  |         ids = {} # Filter out duplicates entries at the same address. | 
					
						
							| 
									
										
										
										
											2014-01-29 14:41:00 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-06-08 18:07:11 +02:00
										 |  |  |         # FIXME: Implement shortcut for partial updates. | 
					
						
							|  |  |  |         #if isPartial: | 
					
						
							|  |  |  |         #    values = [frame.FindVariable(partialVariable)] | 
					
						
							|  |  |  |         #else: | 
					
						
							|  |  |  |         if True: | 
					
						
							| 
									
										
										
										
											2015-03-26 13:03:38 +01:00
										 |  |  |             values = list(frame.GetVariables(True, True, False, False)) | 
					
						
							|  |  |  |             values.reverse() # To get shadowed vars numbered backwards. | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-10-25 13:35:31 +02:00
										 |  |  |         for value in values: | 
					
						
							| 
									
										
										
										
											2014-01-16 10:28:36 +01:00
										 |  |  |             if not value.IsValid(): | 
					
						
							|  |  |  |                 continue | 
					
						
							|  |  |  |             name = value.GetName() | 
					
						
							| 
									
										
										
										
											2014-01-20 15:57:09 +01:00
										 |  |  |             id = "%s:0x%x" % (name, value.GetLoadAddress()) | 
					
						
							| 
									
										
										
										
											2014-01-16 10:28:36 +01:00
										 |  |  |             if id in ids: | 
					
						
							|  |  |  |                 continue | 
					
						
							|  |  |  |             ids[id] = True | 
					
						
							| 
									
										
										
										
											2013-11-07 18:09:43 +01:00
										 |  |  |             if name is None: | 
					
						
							| 
									
										
										
										
											2015-07-03 15:21:02 +02:00
										 |  |  |                 # This can happen for unnamed function parameters with | 
					
						
							|  |  |  |                 # default values:  void foo(int = 0) | 
					
						
							| 
									
										
										
										
											2013-11-07 18:09:43 +01:00
										 |  |  |                 continue | 
					
						
							| 
									
										
										
										
											2013-10-31 14:20:51 +01:00
										 |  |  |             if name in shadowed: | 
					
						
							| 
									
										
										
										
											2013-10-25 13:35:31 +02:00
										 |  |  |                 level = shadowed[name] | 
					
						
							|  |  |  |                 shadowed[name] = level + 1 | 
					
						
							|  |  |  |                 name += "@%s" % level | 
					
						
							|  |  |  |             else: | 
					
						
							|  |  |  |                 shadowed[name] = 1 | 
					
						
							| 
									
										
										
										
											2014-02-04 14:48:40 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |             if name == "argv" and value.GetType().GetName() == "char **": | 
					
						
							|  |  |  |                 self.putSpecialArgv(value) | 
					
						
							|  |  |  |             else: | 
					
						
							|  |  |  |                 with SubItem(self, name): | 
					
						
							|  |  |  |                     self.put('iname="%s",' % self.currentIName) | 
					
						
							|  |  |  |                     self.putItem(value) | 
					
						
							| 
									
										
										
										
											2013-05-30 15:35:52 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-02-04 19:32:24 +01:00
										 |  |  |         with SubItem(self, '[statics]'): | 
					
						
							|  |  |  |             self.put('iname="%s",' % self.currentIName) | 
					
						
							|  |  |  |             self.putEmptyValue() | 
					
						
							|  |  |  |             self.putNumChild(1) | 
					
						
							|  |  |  |             if self.isExpanded(): | 
					
						
							|  |  |  |                 with Children(self): | 
					
						
							|  |  |  |                     statics = frame.GetVariables(False, False, True, False) | 
					
						
							|  |  |  |                     if len(statics): | 
					
						
							|  |  |  |                         for i in xrange(len(statics)): | 
					
						
							|  |  |  |                             staticVar = statics[i] | 
					
						
							|  |  |  |                             typename = staticVar.GetType().GetName() | 
					
						
							|  |  |  |                             name = staticVar.GetName() | 
					
						
							|  |  |  |                             with SubItem(self, i): | 
					
						
							|  |  |  |                                 self.put('name="%s",' % name) | 
					
						
							|  |  |  |                                 self.put('iname="%s",' % self.currentIName) | 
					
						
							|  |  |  |                                 self.putItem(staticVar) | 
					
						
							|  |  |  |                     else: | 
					
						
							|  |  |  |                         with SubItem(self, "None"): | 
					
						
							|  |  |  |                             self.putEmptyValue() | 
					
						
							|  |  |  |                             self.putNumChild(0) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-03-26 13:03:38 +01:00
										 |  |  |         self.handleWatches(args) | 
					
						
							| 
									
										
										
										
											2013-05-30 15:35:52 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-03-26 13:03:38 +01:00
										 |  |  |         self.put('],partial="%d"}' % isPartial) | 
					
						
							| 
									
										
										
										
											2013-04-30 10:46:48 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-05-07 16:43:20 +02:00
										 |  |  |     def reportData(self, _ = None): | 
					
						
							| 
									
										
										
										
											2013-04-30 10:46:48 +02:00
										 |  |  |         if self.process is None: | 
					
						
							|  |  |  |             self.report('process="none"') | 
					
						
							|  |  |  |         else: | 
					
						
							|  |  |  |             state = self.process.GetState() | 
					
						
							|  |  |  |             if state == lldb.eStateStopped: | 
					
						
							|  |  |  |                 self.reportVariables() | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-05-07 12:34:10 +02:00
										 |  |  |     def reportRegisters(self, _ = None): | 
					
						
							| 
									
										
										
										
											2013-04-30 10:46:48 +02:00
										 |  |  |         if self.process is None: | 
					
						
							|  |  |  |             self.report('process="none"') | 
					
						
							|  |  |  |         else: | 
					
						
							|  |  |  |             frame = self.currentFrame() | 
					
						
							| 
									
										
										
										
											2014-01-29 11:43:11 +01:00
										 |  |  |             if frame: | 
					
						
							|  |  |  |                 result = 'registers=[' | 
					
						
							|  |  |  |                 for group in frame.GetRegisters(): | 
					
						
							|  |  |  |                     for reg in group: | 
					
						
							|  |  |  |                         result += '{name="%s"' % reg.GetName() | 
					
						
							| 
									
										
										
										
											2015-02-26 11:10:25 +01:00
										 |  |  |                         value = reg.GetValue() | 
					
						
							|  |  |  |                         if value is None: | 
					
						
							|  |  |  |                             result += ',value=""' | 
					
						
							|  |  |  |                         else: | 
					
						
							|  |  |  |                             result += ',value="%s"' % value | 
					
						
							| 
									
										
										
										
											2014-12-17 13:14:29 +01:00
										 |  |  |                         result += ',size="%s"' % reg.GetByteSize() | 
					
						
							| 
									
										
										
										
											2014-01-29 11:43:11 +01:00
										 |  |  |                         result += ',type="%s"},' % reg.GetType() | 
					
						
							|  |  |  |                 result += ']' | 
					
						
							|  |  |  |                 self.report(result) | 
					
						
							| 
									
										
										
										
											2013-04-30 10:46:48 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-08-25 13:48:55 +02:00
										 |  |  |     def setRegister(self, args): | 
					
						
							|  |  |  |         self.reportToken(args) | 
					
						
							|  |  |  |         name = args["name"] | 
					
						
							|  |  |  |         value = args["value"] | 
					
						
							|  |  |  |         result = lldb.SBCommandReturnObject() | 
					
						
							|  |  |  |         self.debugger.GetCommandInterpreter().HandleCommand( | 
					
						
							|  |  |  |             "register write %s %s" % (name, value), result) | 
					
						
							|  |  |  |         success = result.Succeeded() | 
					
						
							|  |  |  |         if success: | 
					
						
							|  |  |  |             self.report('output="%s"' % result.GetOutput()) | 
					
						
							|  |  |  |         else: | 
					
						
							|  |  |  |             self.report('error="%s"' % result.GetError()) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-04-30 10:46:48 +02:00
										 |  |  |     def report(self, stuff): | 
					
						
							| 
									
										
										
										
											2014-03-19 12:08:25 +01:00
										 |  |  |         with self.outputLock: | 
					
						
							| 
									
										
										
										
											2015-01-30 12:36:04 +01:00
										 |  |  |             sys.stdout.write("@\n" + stuff + "@\n") | 
					
						
							| 
									
										
										
										
											2013-04-30 10:46:48 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-02-06 16:47:07 +01:00
										 |  |  |     def reportStatus(self, msg): | 
					
						
							|  |  |  |         self.report('statusmessage="%s"' % msg) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-05-07 16:43:20 +02:00
										 |  |  |     def interruptInferior(self, _ = None): | 
					
						
							| 
									
										
										
										
											2013-04-30 10:46:48 +02:00
										 |  |  |         if self.process is None: | 
					
						
							| 
									
										
										
										
											2014-02-06 16:47:07 +01:00
										 |  |  |             self.reportStatus("No process to interrupt.") | 
					
						
							| 
									
										
										
										
											2013-05-31 16:51:12 +02:00
										 |  |  |             return | 
					
						
							| 
									
										
										
										
											2013-06-24 17:40:00 +02:00
										 |  |  |         self.isInterrupting_ = True | 
					
						
							| 
									
										
										
										
											2013-05-31 16:51:12 +02:00
										 |  |  |         error = self.process.Stop() | 
					
						
							|  |  |  |         self.reportError(error) | 
					
						
							| 
									
										
										
										
											2013-04-30 10:46:48 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-05-07 16:43:20 +02:00
										 |  |  |     def detachInferior(self, _ = None): | 
					
						
							| 
									
										
										
										
											2013-04-30 10:46:48 +02:00
										 |  |  |         if self.process is None: | 
					
						
							| 
									
										
										
										
											2014-02-06 16:47:07 +01:00
										 |  |  |             self.reportStatus("No process to detach from.") | 
					
						
							| 
									
										
										
										
											2013-04-30 10:46:48 +02:00
										 |  |  |         else: | 
					
						
							|  |  |  |             error = self.process.Detach() | 
					
						
							|  |  |  |             self.reportError(error) | 
					
						
							|  |  |  |             self.reportData() | 
					
						
							| 
									
										
										
										
											2013-04-10 13:55:15 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-05-07 16:43:20 +02:00
										 |  |  |     def continueInferior(self, _ = None): | 
					
						
							| 
									
										
										
										
											2013-04-30 10:46:48 +02:00
										 |  |  |         if self.process is None: | 
					
						
							| 
									
										
										
										
											2014-02-06 16:47:07 +01:00
										 |  |  |             self.reportStatus("No process to continue.") | 
					
						
							| 
									
										
										
										
											2013-04-30 10:46:48 +02:00
										 |  |  |         else: | 
					
						
							|  |  |  |             error = self.process.Continue() | 
					
						
							|  |  |  |             self.reportError(error) | 
					
						
							| 
									
										
										
										
											2014-06-02 16:45:12 +02:00
										 |  |  |             # Happens when attaching to GDBserver. | 
					
						
							|  |  |  |             if not error.Success(): | 
					
						
							|  |  |  |                 self.reportState("inferiorill") | 
					
						
							| 
									
										
										
										
											2013-04-30 10:46:48 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-06-24 17:40:00 +02:00
										 |  |  |     def quitDebugger(self, _ = None): | 
					
						
							| 
									
										
										
										
											2014-03-19 12:12:24 +01:00
										 |  |  |         self.reportState("inferiorshutdownrequested") | 
					
						
							| 
									
										
										
										
											2013-06-24 17:40:00 +02:00
										 |  |  |         self.process.Kill() | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-04-30 10:46:48 +02:00
										 |  |  |     def handleEvent(self, event): | 
					
						
							|  |  |  |         out = lldb.SBStream() | 
					
						
							|  |  |  |         event.GetDescription(out) | 
					
						
							| 
									
										
										
										
											2013-05-02 14:31:35 +02:00
										 |  |  |         #warn("EVENT: %s" % event) | 
					
						
							| 
									
										
										
										
											2015-01-23 17:54:00 +01:00
										 |  |  |         eventType = event.GetType() | 
					
						
							| 
									
										
										
										
											2013-04-30 10:46:48 +02:00
										 |  |  |         msg = lldb.SBEvent.GetCStringFromEvent(event) | 
					
						
							|  |  |  |         flavor = event.GetDataFlavor() | 
					
						
							| 
									
										
										
										
											2013-05-02 14:31:35 +02:00
										 |  |  |         state = lldb.SBProcess.GetStateFromEvent(event) | 
					
						
							| 
									
										
										
										
											2015-02-04 13:29:42 +01:00
										 |  |  |         bp = lldb.SBBreakpoint.GetBreakpointFromEvent(event) | 
					
						
							|  |  |  |         self.report('event={type="%s",data="%s",msg="%s",flavor="%s",state="%s",bp="%s"}' | 
					
						
							| 
									
										
										
										
											2015-02-04 14:15:14 +01:00
										 |  |  |             % (eventType, out.GetData(), msg, flavor, self.stateName(state), bp)) | 
					
						
							| 
									
										
										
										
											2013-05-02 14:31:35 +02:00
										 |  |  |         if state != self.eventState: | 
					
						
							|  |  |  |             self.eventState = state | 
					
						
							| 
									
										
										
										
											2013-05-22 14:30:36 +02:00
										 |  |  |             if state == lldb.eStateExited: | 
					
						
							| 
									
										
										
										
											2013-05-29 15:38:49 +02:00
										 |  |  |                 if self.isShuttingDown_: | 
					
						
							| 
									
										
										
										
											2014-03-19 12:12:24 +01:00
										 |  |  |                     self.reportState("inferiorshutdownok") | 
					
						
							| 
									
										
										
										
											2013-05-29 15:38:49 +02:00
										 |  |  |                 else: | 
					
						
							| 
									
										
										
										
											2014-03-19 12:12:24 +01:00
										 |  |  |                     self.reportState("inferiorexited") | 
					
						
							| 
									
										
										
										
											2013-05-29 15:38:49 +02:00
										 |  |  |                 self.report('exited={status="%s",desc="%s"}' | 
					
						
							| 
									
										
										
										
											2013-05-22 14:30:36 +02:00
										 |  |  |                     % (self.process.GetExitStatus(), self.process.GetExitDescription())) | 
					
						
							| 
									
										
										
										
											2013-06-24 17:40:00 +02:00
										 |  |  |             elif state == lldb.eStateStopped: | 
					
						
							| 
									
										
										
										
											2015-02-04 13:29:42 +01:00
										 |  |  |                 stoppedThread = self.firstStoppedThread() | 
					
						
							|  |  |  |                 if stoppedThread: | 
					
						
							|  |  |  |                     #self.report("STOPPED THREAD: %s" % stoppedThread) | 
					
						
							|  |  |  |                     frame = stoppedThread.GetFrameAtIndex(0) | 
					
						
							|  |  |  |                     #self.report("FRAME: %s" % frame) | 
					
						
							|  |  |  |                     function = frame.GetFunction() | 
					
						
							|  |  |  |                     #self.report("FUNCTION: %s" % function) | 
					
						
							|  |  |  |                     if function.GetName() == "qt_v4ResolvePendingBreakpointsHook": | 
					
						
							|  |  |  |                         #self.report("RESOLVER HIT") | 
					
						
							|  |  |  |                         for bp in self.qmlBreakpointResolvers: | 
					
						
							|  |  |  |                             self.qmlBreakpointResolvers[bp]() | 
					
						
							|  |  |  |                             self.target.BreakpointDelete(bp.GetID()) | 
					
						
							|  |  |  |                         self.qmlBreakpointResolvers = {} | 
					
						
							|  |  |  |                         self.process.Continue(); | 
					
						
							|  |  |  |                         return | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-06-24 17:40:00 +02:00
										 |  |  |                 if self.isInterrupting_: | 
					
						
							|  |  |  |                     self.isInterrupting_ = False | 
					
						
							| 
									
										
										
										
											2014-03-19 12:12:24 +01:00
										 |  |  |                     self.reportState("inferiorstopok") | 
					
						
							| 
									
										
										
										
											2014-03-03 16:59:56 +01:00
										 |  |  |                 elif self.ignoreStops > 0: | 
					
						
							|  |  |  |                     self.ignoreStops -= 1 | 
					
						
							|  |  |  |                     self.process.Continue() | 
					
						
							| 
									
										
										
										
											2015-02-27 11:56:03 +01:00
										 |  |  |                 elif self.silentStops > 0: | 
					
						
							|  |  |  |                     self.silentStops -= 1 | 
					
						
							| 
									
										
										
										
											2015-02-04 13:29:42 +01:00
										 |  |  |                 #elif bp and bp in self.qmlBreakpointResolvers: | 
					
						
							|  |  |  |                 #    self.report("RESOLVER HIT") | 
					
						
							|  |  |  |                 #    self.qmlBreakpointResolvers[bp]() | 
					
						
							|  |  |  |                 #    self.process.Continue(); | 
					
						
							| 
									
										
										
										
											2013-06-24 17:40:00 +02:00
										 |  |  |                 else: | 
					
						
							| 
									
										
										
										
											2014-03-19 12:12:24 +01:00
										 |  |  |                     self.reportState("stopped") | 
					
						
							| 
									
										
										
										
											2013-06-24 17:40:00 +02:00
										 |  |  |             else: | 
					
						
							| 
									
										
										
										
											2015-02-04 14:15:14 +01:00
										 |  |  |                 self.reportState(self.stateName(state)) | 
					
						
							| 
									
										
										
										
											2015-01-23 17:54:00 +01:00
										 |  |  |         if eventType == lldb.SBProcess.eBroadcastBitStateChanged: # 1 | 
					
						
							| 
									
										
										
										
											2013-06-14 10:03:00 +02:00
										 |  |  |             state = self.process.GetState() | 
					
						
							|  |  |  |             if state == lldb.eStateStopped: | 
					
						
							| 
									
										
										
										
											2013-11-11 15:27:24 +01:00
										 |  |  |                 stoppedThread = self.firstStoppedThread() | 
					
						
							|  |  |  |                 if stoppedThread: | 
					
						
							|  |  |  |                     self.process.SetSelectedThread(stoppedThread) | 
					
						
							| 
									
										
										
										
											2015-01-23 17:54:00 +01:00
										 |  |  |         elif eventType == lldb.SBProcess.eBroadcastBitInterrupt: # 2 | 
					
						
							| 
									
										
										
										
											2013-04-30 10:46:48 +02:00
										 |  |  |             pass | 
					
						
							| 
									
										
										
										
											2015-01-23 17:54:00 +01:00
										 |  |  |         elif eventType == lldb.SBProcess.eBroadcastBitSTDOUT: | 
					
						
							| 
									
										
										
										
											2013-05-29 12:14:49 +02:00
										 |  |  |             # FIXME: Size? | 
					
						
							|  |  |  |             msg = self.process.GetSTDOUT(1024) | 
					
						
							|  |  |  |             self.report('output={channel="stdout",data="%s"}' | 
					
						
							| 
									
										
										
										
											2014-01-23 15:30:51 +01:00
										 |  |  |                 % self.hexencode(msg)) | 
					
						
							| 
									
										
										
										
											2015-01-23 17:54:00 +01:00
										 |  |  |         elif eventType == lldb.SBProcess.eBroadcastBitSTDERR: | 
					
						
							| 
									
										
										
										
											2013-05-29 12:14:49 +02:00
										 |  |  |             msg = self.process.GetSTDERR(1024) | 
					
						
							| 
									
										
										
										
											2013-11-05 11:35:25 +01:00
										 |  |  |             self.report('output={channel="stderr",data="%s"}' | 
					
						
							| 
									
										
										
										
											2014-01-23 15:30:51 +01:00
										 |  |  |                 % self.hexencode(msg)) | 
					
						
							| 
									
										
										
										
											2015-01-23 17:54:00 +01:00
										 |  |  |         elif eventType == lldb.SBProcess.eBroadcastBitProfileData: | 
					
						
							| 
									
										
										
										
											2013-04-30 10:46:48 +02:00
										 |  |  |             pass | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-03-19 12:12:24 +01:00
										 |  |  |     def reportState(self, state): | 
					
						
							|  |  |  |         self.report('state="%s"' % state) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-03-05 19:06:24 +01:00
										 |  |  |     def describeBreakpoint(self, bp): | 
					
						
							| 
									
										
										
										
											2013-06-14 15:15:09 +02:00
										 |  |  |         isWatch = isinstance(bp, lldb.SBWatchpoint) | 
					
						
							|  |  |  |         if isWatch: | 
					
						
							|  |  |  |             result  = 'lldbid="%s"' % (qqWatchpointOffset + bp.GetID()) | 
					
						
							|  |  |  |         else: | 
					
						
							|  |  |  |             result  = 'lldbid="%s"' % bp.GetID() | 
					
						
							|  |  |  |         if not bp.IsValid(): | 
					
						
							|  |  |  |             return | 
					
						
							| 
									
										
										
										
											2013-04-30 10:46:48 +02:00
										 |  |  |         result += ',hitcount="%s"' % bp.GetHitCount() | 
					
						
							| 
									
										
										
										
											2013-06-14 15:15:09 +02:00
										 |  |  |         if hasattr(bp, 'GetThreadID'): | 
					
						
							|  |  |  |             result += ',threadid="%s"' % bp.GetThreadID() | 
					
						
							|  |  |  |         if hasattr(bp, 'IsOneShot'): | 
					
						
							| 
									
										
										
										
											2013-05-02 14:31:35 +02:00
										 |  |  |             result += ',oneshot="%s"' % (1 if bp.IsOneShot() else 0) | 
					
						
							| 
									
										
										
										
											2013-06-24 13:16:42 +02:00
										 |  |  |         if hasattr(bp, 'GetCondition'): | 
					
						
							|  |  |  |             cond = bp.GetCondition() | 
					
						
							| 
									
										
										
										
											2014-01-23 15:30:51 +01:00
										 |  |  |             result += ',condition="%s"' % self.hexencode("" if cond is None else cond) | 
					
						
							| 
									
										
										
										
											2013-04-30 10:46:48 +02:00
										 |  |  |         result += ',enabled="%s"' % (1 if bp.IsEnabled() else 0) | 
					
						
							|  |  |  |         result += ',valid="%s"' % (1 if bp.IsValid() else 0) | 
					
						
							|  |  |  |         result += ',ignorecount="%s"' % bp.GetIgnoreCount() | 
					
						
							|  |  |  |         result += ',locations=[' | 
					
						
							| 
									
										
										
										
											2014-03-05 19:06:24 +01:00
										 |  |  |         lineEntry = None | 
					
						
							| 
									
										
										
										
											2013-06-14 15:15:09 +02:00
										 |  |  |         if hasattr(bp, 'GetNumLocations'): | 
					
						
							|  |  |  |             for i in xrange(bp.GetNumLocations()): | 
					
						
							|  |  |  |                 loc = bp.GetLocationAtIndex(i) | 
					
						
							| 
									
										
										
										
											2014-01-29 11:43:11 +01:00
										 |  |  |                 addr = loc.GetAddress() | 
					
						
							| 
									
										
										
										
											2014-03-05 19:06:24 +01:00
										 |  |  |                 lineEntry = addr.GetLineEntry() | 
					
						
							| 
									
										
										
										
											2013-06-14 15:15:09 +02:00
										 |  |  |                 result += '{locid="%s"' % loc.GetID() | 
					
						
							|  |  |  |                 result += ',func="%s"' % addr.GetFunction().GetName() | 
					
						
							|  |  |  |                 result += ',enabled="%s"' % (1 if loc.IsEnabled() else 0) | 
					
						
							|  |  |  |                 result += ',resolved="%s"' % (1 if loc.IsResolved() else 0) | 
					
						
							|  |  |  |                 result += ',valid="%s"' % (1 if loc.IsValid() else 0) | 
					
						
							|  |  |  |                 result += ',ignorecount="%s"' % loc.GetIgnoreCount() | 
					
						
							| 
									
										
										
										
											2014-03-05 19:06:24 +01:00
										 |  |  |                 result += ',file="%s"' % lineEntry.GetFileSpec() | 
					
						
							|  |  |  |                 result += ',line="%s"' % lineEntry.GetLine() | 
					
						
							| 
									
										
										
										
											2015-03-16 11:25:19 +01:00
										 |  |  |                 result += ',addr="%s"},' % addr.GetFileAddress() | 
					
						
							| 
									
										
										
										
											2014-03-05 19:06:24 +01:00
										 |  |  |         result += ']' | 
					
						
							|  |  |  |         if lineEntry is not None: | 
					
						
							|  |  |  |             result += ',file="%s"' % lineEntry.GetFileSpec() | 
					
						
							|  |  |  |             result += ',line="%s"' % lineEntry.GetLine() | 
					
						
							| 
									
										
										
										
											2013-04-30 10:46:48 +02:00
										 |  |  |         return result | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-02-28 13:03:21 +01:00
										 |  |  |     def createBreakpointAtMain(self): | 
					
						
							|  |  |  |         return self.target.BreakpointCreateByName( | 
					
						
							|  |  |  |             "main", self.target.GetExecutable().GetFilename()) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-02-02 13:48:33 +01:00
										 |  |  |     def insertBreakpoint(self, args): | 
					
						
							| 
									
										
										
										
											2015-02-04 13:29:42 +01:00
										 |  |  |         bpType = args["type"] | 
					
						
							|  |  |  |         if bpType == BreakpointByFileAndLine: | 
					
						
							|  |  |  |             fileName = args["fileName"] | 
					
						
							|  |  |  |             if fileName.endswith(".js") or fileName.endswith(".qml"): | 
					
						
							|  |  |  |                 self.insertQmlBreakpoint(args) | 
					
						
							|  |  |  |                 return | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-02-02 13:48:33 +01:00
										 |  |  |         more = True | 
					
						
							|  |  |  |         modelId = args['modelid'] | 
					
						
							| 
									
										
										
										
											2013-05-16 17:37:41 +02:00
										 |  |  |         if bpType == BreakpointByFileAndLine: | 
					
						
							| 
									
										
										
										
											2014-03-05 19:06:24 +01:00
										 |  |  |             bp = self.target.BreakpointCreateByLocation( | 
					
						
							| 
									
										
										
										
											2015-02-04 13:29:42 +01:00
										 |  |  |                 str(args["fileName"]), int(args["lineNumber"])) | 
					
						
							| 
									
										
										
										
											2013-05-16 17:37:41 +02:00
										 |  |  |         elif bpType == BreakpointByFunction: | 
					
						
							| 
									
										
										
										
											2014-03-05 19:06:24 +01:00
										 |  |  |             bp = self.target.BreakpointCreateByName(args["function"]) | 
					
						
							| 
									
										
										
										
											2013-06-14 15:15:09 +02:00
										 |  |  |         elif bpType == BreakpointByAddress: | 
					
						
							| 
									
										
										
										
											2014-03-05 19:06:24 +01:00
										 |  |  |             bp = self.target.BreakpointCreateByAddress(args["address"]) | 
					
						
							| 
									
										
										
										
											2013-05-16 17:37:41 +02:00
										 |  |  |         elif bpType == BreakpointAtMain: | 
					
						
							| 
									
										
										
										
											2014-03-05 19:06:24 +01:00
										 |  |  |             bp = self.createBreakpointAtMain() | 
					
						
							| 
									
										
										
										
											2013-06-13 18:22:44 +02:00
										 |  |  |         elif bpType == BreakpointAtThrow: | 
					
						
							| 
									
										
										
										
											2014-03-05 19:06:24 +01:00
										 |  |  |             bp = self.target.BreakpointCreateForException( | 
					
						
							| 
									
										
										
										
											2013-06-13 18:22:44 +02:00
										 |  |  |                 lldb.eLanguageTypeC_plus_plus, False, True) | 
					
						
							|  |  |  |         elif bpType == BreakpointAtCatch: | 
					
						
							| 
									
										
										
										
											2014-03-05 19:06:24 +01:00
										 |  |  |             bp = self.target.BreakpointCreateForException( | 
					
						
							| 
									
										
										
										
											2013-06-13 18:22:44 +02:00
										 |  |  |                 lldb.eLanguageTypeC_plus_plus, True, False) | 
					
						
							| 
									
										
										
										
											2013-06-14 15:15:09 +02:00
										 |  |  |         elif bpType == WatchpointAtAddress: | 
					
						
							|  |  |  |             error = lldb.SBError() | 
					
						
							| 
									
										
										
										
											2014-03-05 19:06:24 +01:00
										 |  |  |             bp = self.target.WatchAddress(args["address"], 4, False, True, error) | 
					
						
							|  |  |  |             #warn("BPNEW: %s" % bp) | 
					
						
							| 
									
										
										
										
											2013-06-14 15:15:09 +02:00
										 |  |  |             self.reportError(error) | 
					
						
							|  |  |  |         elif bpType == WatchpointAtExpression: | 
					
						
							|  |  |  |             # FIXME: Top level-only for now. | 
					
						
							|  |  |  |             try: | 
					
						
							|  |  |  |                 frame = self.currentFrame() | 
					
						
							|  |  |  |                 value = frame.FindVariable(args["expression"]) | 
					
						
							|  |  |  |                 error = lldb.SBError() | 
					
						
							| 
									
										
										
										
											2014-03-05 19:06:24 +01:00
										 |  |  |                 bp = self.target.WatchAddress(value.GetLoadAddress(), | 
					
						
							| 
									
										
										
										
											2013-06-14 15:15:09 +02:00
										 |  |  |                     value.GetByteSize(), False, True, error) | 
					
						
							|  |  |  |             except: | 
					
						
							| 
									
										
										
										
											2015-02-02 13:48:33 +01:00
										 |  |  |                 bp = self.target.BreakpointCreateByName(None) | 
					
						
							| 
									
										
										
										
											2013-05-16 17:37:41 +02:00
										 |  |  |         else: | 
					
						
							| 
									
										
										
										
											2014-02-06 17:50:21 +01:00
										 |  |  |             # This leaves the unhandled breakpoint in a (harmless) | 
					
						
							|  |  |  |             # "pending" state. | 
					
						
							| 
									
										
										
										
											2015-02-02 13:48:33 +01:00
										 |  |  |             bp = self.target.BreakpointCreateByName(None) | 
					
						
							|  |  |  |             more = False | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         if more: | 
					
						
							|  |  |  |             bp.SetIgnoreCount(int(args["ignorecount"])) | 
					
						
							|  |  |  |             if hasattr(bp, 'SetCondition'): | 
					
						
							|  |  |  |                 bp.SetCondition(self.hexdecode(args["condition"])) | 
					
						
							| 
									
										
										
										
											2015-04-28 15:26:35 -10:00
										 |  |  |             bp.SetEnabled(bool(args["enabled"])) | 
					
						
							| 
									
										
										
										
											2015-02-02 13:48:33 +01:00
										 |  |  |             if hasattr(bp, 'SetOneShot'): | 
					
						
							| 
									
										
										
										
											2015-04-28 15:26:35 -10:00
										 |  |  |                 bp.SetOneShot(bool(args["oneshot"])) | 
					
						
							| 
									
										
										
										
											2015-02-02 13:48:33 +01:00
										 |  |  |         self.report('breakpoint-added={%s,modelid="%s"}' % (self.describeBreakpoint(bp), modelId)) | 
					
						
							| 
									
										
										
										
											2013-05-16 17:37:41 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     def changeBreakpoint(self, args): | 
					
						
							| 
									
										
										
										
											2015-02-02 13:48:33 +01:00
										 |  |  |         lldbId = int(args["lldbid"]) | 
					
						
							|  |  |  |         modelId = args['modelid'] | 
					
						
							|  |  |  |         if lldbId > qqWatchpointOffset: | 
					
						
							|  |  |  |             bp = self.target.FindWatchpointByID(lldbId) | 
					
						
							| 
									
										
										
										
											2013-06-14 15:15:09 +02:00
										 |  |  |         else: | 
					
						
							| 
									
										
										
										
											2015-02-02 13:48:33 +01:00
										 |  |  |             bp = self.target.FindBreakpointByID(lldbId) | 
					
						
							| 
									
										
										
										
											2013-06-14 15:15:09 +02:00
										 |  |  |         bp.SetIgnoreCount(int(args["ignorecount"])) | 
					
						
							| 
									
										
										
										
											2014-01-23 15:30:51 +01:00
										 |  |  |         bp.SetCondition(self.hexdecode(args["condition"])) | 
					
						
							| 
									
										
										
										
											2015-04-28 15:26:35 -10:00
										 |  |  |         bp.SetEnabled(bool(args["enabled"])) | 
					
						
							| 
									
										
										
										
											2013-06-14 15:15:09 +02:00
										 |  |  |         if hasattr(bp, 'SetOneShot'): | 
					
						
							| 
									
										
										
										
											2015-04-28 15:26:35 -10:00
										 |  |  |             bp.SetOneShot(bool(args["oneshot"])) | 
					
						
							| 
									
										
										
										
											2015-02-02 13:48:33 +01:00
										 |  |  |         self.report('breakpoint-changed={%s,modelid="%s"}' | 
					
						
							|  |  |  |               % (self.describeBreakpoint(bp), modelId)) | 
					
						
							| 
									
										
										
										
											2013-05-16 17:37:41 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     def removeBreakpoint(self, args): | 
					
						
							| 
									
										
										
										
											2015-02-02 13:48:33 +01:00
										 |  |  |         lldbId = int(args['lldbid']) | 
					
						
							|  |  |  |         modelId = args['modelid'] | 
					
						
							|  |  |  |         if lldbId > qqWatchpointOffset: | 
					
						
							|  |  |  |             res = self.target.DeleteWatchpoint(lldbId - qqWatchpointOffset) | 
					
						
							|  |  |  |         res = self.target.BreakpointDelete(lldbId) | 
					
						
							|  |  |  |         self.report('breakpoint-removed={modelid="%s"}' % modelId) | 
					
						
							| 
									
										
										
										
											2013-04-30 10:46:48 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-05-07 16:43:20 +02:00
										 |  |  |     def listModules(self, args): | 
					
						
							| 
									
										
										
										
											2013-04-30 10:46:48 +02:00
										 |  |  |         result = 'modules=[' | 
					
						
							| 
									
										
										
										
											2013-05-22 14:30:36 +02:00
										 |  |  |         for i in xrange(self.target.GetNumModules()): | 
					
						
							|  |  |  |             module = self.target.GetModuleAtIndex(i) | 
					
						
							| 
									
										
										
										
											2013-05-29 16:06:07 +02:00
										 |  |  |             result += '{file="%s"' % module.file.fullpath | 
					
						
							| 
									
										
										
										
											2013-04-30 10:46:48 +02:00
										 |  |  |             result += ',name="%s"' % module.file.basename | 
					
						
							| 
									
										
										
										
											2013-05-07 11:39:31 +02:00
										 |  |  |             result += ',addrsize="%s"' % module.addr_size | 
					
						
							|  |  |  |             result += ',triple="%s"' % module.triple | 
					
						
							|  |  |  |             #result += ',sections={' | 
					
						
							| 
									
										
										
										
											2013-04-30 10:46:48 +02:00
										 |  |  |             #for section in module.sections: | 
					
						
							|  |  |  |             #    result += '[name="%s"' % section.name | 
					
						
							|  |  |  |             #    result += ',addr="%s"' % section.addr | 
					
						
							| 
									
										
										
										
											2013-05-07 11:39:31 +02:00
										 |  |  |             #    result += ',size="%s"],' % section.size | 
					
						
							| 
									
										
										
										
											2013-04-30 10:46:48 +02:00
										 |  |  |             #result += '}' | 
					
						
							|  |  |  |             result += '},' | 
					
						
							|  |  |  |         result += ']' | 
					
						
							|  |  |  |         self.report(result) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-05-07 12:34:10 +02:00
										 |  |  |     def listSymbols(self, args): | 
					
						
							|  |  |  |         moduleName = args['module'] | 
					
						
							| 
									
										
										
										
											2013-05-07 11:39:31 +02:00
										 |  |  |         #file = lldb.SBFileSpec(moduleName) | 
					
						
							|  |  |  |         #module = self.target.FindModule(file) | 
					
						
							| 
									
										
										
										
											2013-05-22 14:30:36 +02:00
										 |  |  |         for i in xrange(self.target.GetNumModules()): | 
					
						
							|  |  |  |             module = self.target.GetModuleAtIndex(i) | 
					
						
							| 
									
										
										
										
											2013-05-29 16:24:17 +02:00
										 |  |  |             if module.file.fullpath == moduleName: | 
					
						
							| 
									
										
										
										
											2013-05-07 11:39:31 +02:00
										 |  |  |                 break | 
					
						
							|  |  |  |         result = 'symbols={module="%s"' % moduleName | 
					
						
							|  |  |  |         result += ',valid="%s"' % module.IsValid() | 
					
						
							|  |  |  |         result += ',sections="%s"' % module.GetNumSections() | 
					
						
							|  |  |  |         result += ',symbols=[' | 
					
						
							|  |  |  |         for symbol in module.symbols: | 
					
						
							|  |  |  |             startAddress = symbol.GetStartAddress().GetLoadAddress(self.target) | 
					
						
							|  |  |  |             endAddress = symbol.GetEndAddress().GetLoadAddress(self.target) | 
					
						
							|  |  |  |             result += '{type="%s"' % symbol.GetType() | 
					
						
							|  |  |  |             result += ',name="%s"' % symbol.GetName() | 
					
						
							|  |  |  |             result += ',address="0x%x"' % startAddress | 
					
						
							|  |  |  |             result += ',demangled="%s"' % symbol.GetMangledName() | 
					
						
							|  |  |  |             result += ',size="%s"' % (endAddress - startAddress) | 
					
						
							|  |  |  |             result += '},' | 
					
						
							|  |  |  |         result += ']}' | 
					
						
							|  |  |  |         self.report(result) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-05-07 12:34:10 +02:00
										 |  |  |     def executeNext(self, _ = None): | 
					
						
							| 
									
										
										
										
											2013-04-30 10:46:48 +02:00
										 |  |  |         self.currentThread().StepOver() | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-05-07 12:34:10 +02:00
										 |  |  |     def executeNextI(self, _ = None): | 
					
						
							| 
									
										
										
										
											2013-05-24 08:32:12 +02:00
										 |  |  |         self.currentThread().StepInstruction(lldb.eOnlyThisThread) | 
					
						
							| 
									
										
										
										
											2013-04-30 10:46:48 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-05-07 12:34:10 +02:00
										 |  |  |     def executeStep(self, _ = None): | 
					
						
							| 
									
										
										
										
											2013-04-30 10:46:48 +02:00
										 |  |  |         self.currentThread().StepInto() | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-05-29 15:38:49 +02:00
										 |  |  |     def shutdownInferior(self, _ = None): | 
					
						
							|  |  |  |         self.isShuttingDown_ = True | 
					
						
							| 
									
										
										
										
											2014-06-02 16:45:12 +02:00
										 |  |  |         if self.process is None: | 
					
						
							|  |  |  |             self.reportState("inferiorshutdownok") | 
					
						
							|  |  |  |         else: | 
					
						
							|  |  |  |             state = self.process.GetState() | 
					
						
							|  |  |  |             if state == lldb.eStateStopped: | 
					
						
							|  |  |  |                 self.process.Kill() | 
					
						
							|  |  |  |             self.reportState("inferiorshutdownok") | 
					
						
							| 
									
										
										
										
											2013-05-29 15:38:49 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-03-05 10:41:16 +01:00
										 |  |  |     def quit(self, args = {}): | 
					
						
							|  |  |  |         self.reportToken(args) | 
					
						
							| 
									
										
										
										
											2014-03-19 12:12:24 +01:00
										 |  |  |         self.reportState("engineshutdownok") | 
					
						
							| 
									
										
										
										
											2013-05-29 15:38:49 +02:00
										 |  |  |         self.process.Kill() | 
					
						
							| 
									
										
										
										
											2013-04-30 10:46:48 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-03-05 10:41:16 +01:00
										 |  |  |     def executeStepI(self, args = {}): | 
					
						
							|  |  |  |         self.reportToken(args) | 
					
						
							| 
									
										
										
										
											2013-05-24 08:32:12 +02:00
										 |  |  |         self.currentThread().StepInstruction(lldb.eOnlyThisThread) | 
					
						
							| 
									
										
										
										
											2013-04-30 10:46:48 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-03-05 10:41:16 +01:00
										 |  |  |     def executeStepOut(self, args = {}): | 
					
						
							|  |  |  |         self.reportToken(args) | 
					
						
							| 
									
										
										
										
											2013-05-24 08:32:12 +02:00
										 |  |  |         self.currentThread().StepOut() | 
					
						
							| 
									
										
										
										
											2013-04-30 10:46:48 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-02-06 16:47:07 +01:00
										 |  |  |     def executeRunToLocation(self, args): | 
					
						
							| 
									
										
										
										
											2015-03-05 10:41:16 +01:00
										 |  |  |         self.reportToken(args) | 
					
						
							| 
									
										
										
										
											2014-02-06 16:47:07 +01:00
										 |  |  |         addr = args.get('address', 0) | 
					
						
							|  |  |  |         if addr: | 
					
						
							| 
									
										
										
										
											2015-08-10 13:25:30 +02:00
										 |  |  |             # Does not seem to hit anything on Linux: | 
					
						
							|  |  |  |             # self.currentThread().RunToAddress(addr) | 
					
						
							|  |  |  |             bp = self.target.BreakpointCreateByAddress(addr) | 
					
						
							|  |  |  |             if bp.GetNumLocations() == 0: | 
					
						
							|  |  |  |                 self.target.BreakpointDelete(bp.GetID()) | 
					
						
							|  |  |  |                 self.reportStatus("No target location found.") | 
					
						
							|  |  |  |                 self.reportLocation(frame) | 
					
						
							|  |  |  |                 return | 
					
						
							|  |  |  |             bp.SetOneShot(True) | 
					
						
							|  |  |  |             self.process.Continue() | 
					
						
							| 
									
										
										
										
											2014-02-06 16:47:07 +01:00
										 |  |  |         else: | 
					
						
							|  |  |  |             frame = self.currentFrame() | 
					
						
							|  |  |  |             file = args['file'] | 
					
						
							|  |  |  |             line = int(args['line']) | 
					
						
							|  |  |  |             error = self.currentThread().StepOverUntil(frame, lldb.SBFileSpec(file), line) | 
					
						
							| 
									
										
										
										
											2015-08-10 13:25:30 +02:00
										 |  |  |             if error.GetType(): | 
					
						
							|  |  |  |                 self.reportState("running") | 
					
						
							|  |  |  |                 self.reportState("stopped") | 
					
						
							|  |  |  |                 self.reportError(error) | 
					
						
							|  |  |  |             else: | 
					
						
							|  |  |  |                 self.reportData() | 
					
						
							| 
									
										
										
										
											2013-04-30 10:46:48 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-02-06 15:40:23 +01:00
										 |  |  |     def executeJumpToLocation(self, args): | 
					
						
							| 
									
										
										
										
											2015-03-05 10:41:16 +01:00
										 |  |  |         self.reportToken(args) | 
					
						
							| 
									
										
										
										
											2014-02-05 17:03:51 +01:00
										 |  |  |         frame = self.currentFrame() | 
					
						
							|  |  |  |         if not frame: | 
					
						
							| 
									
										
										
										
											2014-02-06 16:47:07 +01:00
										 |  |  |             self.reportStatus("No frame available.") | 
					
						
							| 
									
										
										
										
											2014-02-05 17:03:51 +01:00
										 |  |  |             return | 
					
						
							| 
									
										
										
										
											2014-02-06 15:40:23 +01:00
										 |  |  |         addr = args.get('address', 0) | 
					
						
							|  |  |  |         if addr: | 
					
						
							|  |  |  |             bp = self.target.BreakpointCreateByAddress(addr) | 
					
						
							|  |  |  |         else: | 
					
						
							|  |  |  |             bp = self.target.BreakpointCreateByLocation( | 
					
						
							|  |  |  |                         str(args['file']), int(args['line'])) | 
					
						
							| 
									
										
										
										
											2014-02-05 17:03:51 +01:00
										 |  |  |         if bp.GetNumLocations() == 0: | 
					
						
							|  |  |  |             self.target.BreakpointDelete(bp.GetID()) | 
					
						
							| 
									
										
										
										
											2014-02-06 16:47:07 +01:00
										 |  |  |             self.reportStatus("No target location found.") | 
					
						
							| 
									
										
										
										
											2015-02-27 15:01:29 +01:00
										 |  |  |             self.reportLocation(frame) | 
					
						
							| 
									
										
										
										
											2014-02-05 17:03:51 +01:00
										 |  |  |             return | 
					
						
							|  |  |  |         loc = bp.GetLocationAtIndex(0) | 
					
						
							|  |  |  |         self.target.BreakpointDelete(bp.GetID()) | 
					
						
							| 
									
										
										
										
											2015-02-27 15:01:29 +01:00
										 |  |  |         if frame.SetPC(loc.GetLoadAddress()): | 
					
						
							|  |  |  |             self.report("Jumped.") | 
					
						
							|  |  |  |         else: | 
					
						
							|  |  |  |             self.report("Cannot jump.") | 
					
						
							|  |  |  |         self.reportLocation(frame) | 
					
						
							| 
									
										
										
										
											2013-04-30 10:46:48 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     def breakList(self): | 
					
						
							|  |  |  |         result = lldb.SBCommandReturnObject() | 
					
						
							|  |  |  |         self.debugger.GetCommandInterpreter().HandleCommand("break list", result) | 
					
						
							|  |  |  |         self.report('success="%d",output="%s",error="%s"' | 
					
						
							|  |  |  |             % (result.Succeeded(), result.GetOutput(), result.GetError())) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-05-24 10:14:11 +02:00
										 |  |  |     def activateFrame(self, args): | 
					
						
							| 
									
										
										
										
											2014-02-03 13:47:26 +01:00
										 |  |  |         thread = args['thread'] | 
					
						
							| 
									
										
										
										
											2013-05-24 10:14:11 +02:00
										 |  |  |         self.currentThread().SetSelectedFrame(args['index']) | 
					
						
							| 
									
										
										
										
											2015-02-27 16:53:48 +01:00
										 |  |  |         self.reportContinuation(args) | 
					
						
							| 
									
										
										
										
											2013-04-30 10:46:48 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-05-29 16:24:17 +02:00
										 |  |  |     def selectThread(self, args): | 
					
						
							|  |  |  |         self.process.SetSelectedThreadByID(args['id']) | 
					
						
							| 
									
										
										
										
											2013-04-30 10:46:48 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     def requestModuleSymbols(self, frame): | 
					
						
							|  |  |  |         self.handleCommand("target module list " + frame) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-03-11 16:40:07 +01:00
										 |  |  |     def createFullBacktrace(self, _ = None): | 
					
						
							|  |  |  |         command = "thread backtrace all" | 
					
						
							|  |  |  |         result = lldb.SBCommandReturnObject() | 
					
						
							|  |  |  |         self.debugger.GetCommandInterpreter().HandleCommand(command, result) | 
					
						
							|  |  |  |         self.report('full-backtrace="%s"' % self.hexencode(result.GetOutput())) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-05-07 16:43:20 +02:00
										 |  |  |     def executeDebuggerCommand(self, args): | 
					
						
							| 
									
										
										
										
											2013-04-30 10:46:48 +02:00
										 |  |  |         result = lldb.SBCommandReturnObject() | 
					
						
							| 
									
										
										
										
											2013-05-07 16:43:20 +02:00
										 |  |  |         command = args['command'] | 
					
						
							| 
									
										
										
										
											2013-04-30 10:46:48 +02:00
										 |  |  |         self.debugger.GetCommandInterpreter().HandleCommand(command, result) | 
					
						
							|  |  |  |         success = result.Succeeded() | 
					
						
							| 
									
										
										
										
											2013-05-29 15:38:49 +02:00
										 |  |  |         output = result.GetOutput() | 
					
						
							|  |  |  |         error = str(result.GetError()) | 
					
						
							| 
									
										
										
										
											2013-04-30 10:46:48 +02:00
										 |  |  |         self.report('success="%d",output="%s",error="%s"' % (success, output, error)) | 
					
						
							| 
									
										
										
										
											2013-04-10 13:55:15 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-05-07 12:34:10 +02:00
										 |  |  |     def updateData(self, args): | 
					
						
							| 
									
										
										
										
											2015-03-05 10:41:16 +01:00
										 |  |  |         self.reportToken(args) | 
					
						
							| 
									
										
										
										
											2015-02-12 11:31:02 +01:00
										 |  |  |         self.expandedINames = set(args.get('expanded', [])) | 
					
						
							|  |  |  |         self.autoDerefPointers = int(args.get('autoderef', '0')) | 
					
						
							| 
									
										
										
										
											2015-05-29 08:23:52 +02:00
										 |  |  |         self.sortStructMembers = bool(args.get("sortStructMembers", True)); | 
					
						
							| 
									
										
										
										
											2015-02-12 11:31:02 +01:00
										 |  |  |         self.useDynamicType = int(args.get('dyntype', '0')) | 
					
						
							|  |  |  |         self.useFancy = int(args.get('fancy', '0')) | 
					
						
							|  |  |  |         self.passExceptions = int(args.get('passexceptions', '0')) | 
					
						
							|  |  |  |         self.currentWatchers = args.get('watchers', {}) | 
					
						
							|  |  |  |         self.typeformats = args.get("typeformats", {}) | 
					
						
							|  |  |  |         self.formats = args.get("formats", {}) | 
					
						
							| 
									
										
										
										
											2013-05-30 15:35:52 +02:00
										 |  |  |         self.reportVariables(args) | 
					
						
							| 
									
										
										
										
											2013-04-10 15:54:04 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-05-07 12:34:10 +02:00
										 |  |  |     def disassemble(self, args): | 
					
						
							| 
									
										
										
										
											2014-03-06 12:04:47 +01:00
										 |  |  |         functionName = args.get('function', '') | 
					
						
							|  |  |  |         flavor = args.get('flavor', '') | 
					
						
							|  |  |  |         function = None | 
					
						
							|  |  |  |         if len(functionName): | 
					
						
							|  |  |  |             functions = self.target.FindFunctions(functionName).functions | 
					
						
							|  |  |  |             if len(functions): | 
					
						
							|  |  |  |                 function = functions[0] | 
					
						
							|  |  |  |         if function: | 
					
						
							|  |  |  |             base = function.GetStartAddress().GetLoadAddress(self.target) | 
					
						
							|  |  |  |             instructions = function.GetInstructions(self.target) | 
					
						
							|  |  |  |         else: | 
					
						
							|  |  |  |             base = args.get('address', 0) | 
					
						
							| 
									
										
										
										
											2015-02-04 17:21:55 +01:00
										 |  |  |             if int(base) == 0xffffffffffffffff: | 
					
						
							|  |  |  |                 warn("INVALID DISASSEMBLER BASE") | 
					
						
							|  |  |  |                 return | 
					
						
							| 
									
										
										
										
											2014-03-06 12:04:47 +01:00
										 |  |  |             addr = lldb.SBAddress(base, self.target) | 
					
						
							|  |  |  |             instructions = self.target.ReadInstructions(addr, 100) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-05-07 12:34:10 +02:00
										 |  |  |         result = 'disassembly={cookie="%s",' % args['cookie'] | 
					
						
							| 
									
										
										
										
											2013-05-07 08:46:51 +02:00
										 |  |  |         result += ',lines=[' | 
					
						
							| 
									
										
										
										
											2014-03-06 12:04:47 +01:00
										 |  |  |         for insn in instructions: | 
					
						
							| 
									
										
										
										
											2013-05-03 17:18:07 +02:00
										 |  |  |             comment = insn.GetComment(self.target) | 
					
						
							|  |  |  |             addr = insn.GetAddress().GetLoadAddress(self.target) | 
					
						
							|  |  |  |             result += '{address="%s"' % addr | 
					
						
							| 
									
										
										
										
											2013-05-13 16:04:00 +02:00
										 |  |  |             result += ',inst="%s %s"' % (insn.GetMnemonic(self.target), | 
					
						
							|  |  |  |                 insn.GetOperands(self.target)) | 
					
						
							| 
									
										
										
										
											2014-03-06 12:04:47 +01:00
										 |  |  |             result += ',func_name="%s"' % functionName | 
					
						
							| 
									
										
										
										
											2013-05-03 17:18:07 +02:00
										 |  |  |             if comment: | 
					
						
							|  |  |  |                 result += ',comment="%s"' % comment | 
					
						
							|  |  |  |             result += ',offset="%s"},' % (addr - base) | 
					
						
							|  |  |  |         self.report(result + ']') | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-03-18 16:48:57 +01:00
										 |  |  |     def loadDumpers(self, args): | 
					
						
							| 
									
										
										
										
											2015-03-05 10:41:16 +01:00
										 |  |  |         self.reportToken(args) | 
					
						
							| 
									
										
										
										
											2015-03-18 16:48:57 +01:00
										 |  |  |         self.setupDumpers() | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     def reportDumpers(self, msg): | 
					
						
							|  |  |  |         self.report(msg) | 
					
						
							| 
									
										
										
										
											2015-01-23 19:09:08 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-09-11 21:35:39 +02:00
										 |  |  |     def fetchMemory(self, args): | 
					
						
							| 
									
										
										
										
											2013-05-07 12:34:10 +02:00
										 |  |  |         address = args['address'] | 
					
						
							|  |  |  |         length = args['length'] | 
					
						
							| 
									
										
										
										
											2013-05-07 08:46:51 +02:00
										 |  |  |         error = lldb.SBError() | 
					
						
							|  |  |  |         contents = self.process.ReadMemory(address, length, error) | 
					
						
							| 
									
										
										
										
											2013-05-07 12:34:10 +02:00
										 |  |  |         result = 'memory={cookie="%s",' % args['cookie'] | 
					
						
							| 
									
										
										
										
											2013-05-07 08:46:51 +02:00
										 |  |  |         result += ',address="%s",' % address | 
					
						
							|  |  |  |         result += self.describeError(error) | 
					
						
							| 
									
										
										
										
											2014-01-23 15:30:51 +01:00
										 |  |  |         result += ',contents="%s"}' % self.hexencode(contents) | 
					
						
							| 
									
										
										
										
											2013-05-07 08:46:51 +02:00
										 |  |  |         self.report(result) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-06-11 18:55:09 +02:00
										 |  |  |     def findValueByExpression(self, exp): | 
					
						
							|  |  |  |         # FIXME: Top level-only for now. | 
					
						
							|  |  |  |         frame = self.currentFrame() | 
					
						
							|  |  |  |         value = frame.FindVariable(exp) | 
					
						
							|  |  |  |         return value | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-05-30 15:35:52 +02:00
										 |  |  |     def assignValue(self, args): | 
					
						
							| 
									
										
										
										
											2013-06-11 18:55:09 +02:00
										 |  |  |         error = lldb.SBError() | 
					
						
							| 
									
										
										
										
											2014-01-23 15:30:51 +01:00
										 |  |  |         exp = self.hexdecode(args['exp']) | 
					
						
							|  |  |  |         value = self.hexdecode(args['value']) | 
					
						
							| 
									
										
										
										
											2013-06-11 18:55:09 +02:00
										 |  |  |         lhs = self.findValueByExpression(exp) | 
					
						
							|  |  |  |         lhs.SetValueFromCString(value, error) | 
					
						
							|  |  |  |         self.reportError(error) | 
					
						
							| 
									
										
										
										
											2013-05-30 15:35:52 +02:00
										 |  |  |         self.reportVariables() | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-02-04 16:27:46 +01:00
										 |  |  |     def createResolvePendingBreakpointsHookBreakpoint(self, args): | 
					
						
							| 
									
										
										
										
											2015-02-04 13:29:42 +01:00
										 |  |  |         if self.qmlTriggeredBreakpoint is None: | 
					
						
							|  |  |  |             self.qmlTriggeredBreakpoint = \ | 
					
						
							|  |  |  |                 self.target.BreakpointCreateByName("qt_v4TriggeredBreakpointHook") | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         bp = self.target.BreakpointCreateByName("qt_v4ResolvePendingBreakpointsHook") | 
					
						
							|  |  |  |         bp.SetOneShot(True) | 
					
						
							|  |  |  |         self.qmlBreakpointResolvers[bp] = lambda: \ | 
					
						
							| 
									
										
										
										
											2015-02-04 16:27:46 +01:00
										 |  |  |             self.doInsertQmlBreakpoint(args) | 
					
						
							| 
									
										
										
										
											2013-10-17 17:08:32 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-05-29 14:55:57 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-06-04 10:44:20 +02:00
										 |  |  | # Used in dumper auto test. | 
					
						
							| 
									
										
										
										
											2015-01-23 17:54:00 +01:00
										 |  |  | class Tester(Dumper): | 
					
						
							| 
									
										
										
										
											2015-01-30 12:36:04 +01:00
										 |  |  |     def __init__(self, binary, expandedINames): | 
					
						
							| 
									
										
										
										
											2015-01-23 17:54:00 +01:00
										 |  |  |         Dumper.__init__(self) | 
					
						
							|  |  |  |         lldb.theDumper = self | 
					
						
							| 
									
										
										
										
											2013-06-04 10:44:20 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-01-30 12:36:04 +01:00
										 |  |  |         self.expandedINames = set(expandedINames) | 
					
						
							| 
									
										
										
										
											2015-01-23 17:54:00 +01:00
										 |  |  |         self.passExceptions = True | 
					
						
							| 
									
										
										
										
											2015-07-07 15:27:59 +02:00
										 |  |  |         self.sortStructMembers = True | 
					
						
							| 
									
										
										
										
											2015-01-23 17:54:00 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-03-18 16:48:57 +01:00
										 |  |  |         self.loadDumpers({}) | 
					
						
							| 
									
										
										
										
											2015-01-23 17:54:00 +01:00
										 |  |  |         error = lldb.SBError() | 
					
						
							| 
									
										
										
										
											2015-01-30 12:36:04 +01:00
										 |  |  |         self.target = self.debugger.CreateTarget(binary, None, None, True, error) | 
					
						
							| 
									
										
										
										
											2013-06-04 10:44:20 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-01-23 17:54:00 +01:00
										 |  |  |         if error.GetType(): | 
					
						
							|  |  |  |             warn("ERROR: %s" % error) | 
					
						
							|  |  |  |             return | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         s = threading.Thread(target=self.testLoop, args=[]) | 
					
						
							|  |  |  |         s.start() | 
					
						
							| 
									
										
										
										
											2015-01-30 12:36:04 +01:00
										 |  |  |         s.join(30) | 
					
						
							| 
									
										
										
										
											2013-06-04 10:44:20 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-04-14 09:06:28 +02:00
										 |  |  |     def reportDumpers(self, msg): | 
					
						
							|  |  |  |         pass | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-01-23 17:54:00 +01:00
										 |  |  |     def testLoop(self): | 
					
						
							|  |  |  |         # Disable intermediate reporting. | 
					
						
							|  |  |  |         savedReport = self.report | 
					
						
							|  |  |  |         self.report = lambda stuff: 0 | 
					
						
							| 
									
										
										
										
											2013-06-04 10:44:20 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-01-23 17:54:00 +01:00
										 |  |  |         error = lldb.SBError() | 
					
						
							|  |  |  |         launchInfo = lldb.SBLaunchInfo([]) | 
					
						
							|  |  |  |         launchInfo.SetWorkingDirectory(os.getcwd()) | 
					
						
							|  |  |  |         environmentList = [key + "=" + value for key,value in os.environ.items()] | 
					
						
							|  |  |  |         launchInfo.SetEnvironmentEntries(environmentList, False) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         self.process = self.target.Launch(launchInfo, error) | 
					
						
							|  |  |  |         if error.GetType(): | 
					
						
							|  |  |  |             warn("ERROR: %s" % error) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         event = lldb.SBEvent() | 
					
						
							|  |  |  |         listener = self.debugger.GetListener() | 
					
						
							|  |  |  |         while True: | 
					
						
							|  |  |  |             state = self.process.GetState() | 
					
						
							|  |  |  |             if listener.WaitForEvent(100, event): | 
					
						
							|  |  |  |                 #warn("EVENT: %s" % event) | 
					
						
							|  |  |  |                 state = lldb.SBProcess.GetStateFromEvent(event) | 
					
						
							| 
									
										
										
										
											2015-01-27 10:25:21 +01:00
										 |  |  |                 if state == lldb.eStateExited: # 10 | 
					
						
							| 
									
										
										
										
											2015-01-23 17:54:00 +01:00
										 |  |  |                     break | 
					
						
							| 
									
										
										
										
											2015-01-27 10:25:21 +01:00
										 |  |  |                 if state == lldb.eStateStopped: # 5 | 
					
						
							| 
									
										
										
										
											2015-04-14 09:06:28 +02:00
										 |  |  |                     stoppedThread = None | 
					
						
							|  |  |  |                     for i in xrange(0, self.process.GetNumThreads()): | 
					
						
							|  |  |  |                         thread = self.process.GetThreadAtIndex(i) | 
					
						
							|  |  |  |                         reason = thread.GetStopReason() | 
					
						
							|  |  |  |                         #warn("THREAD: %s REASON: %s" % (thread, reason)) | 
					
						
							|  |  |  |                         if (reason == lldb.eStopReasonBreakpoint or | 
					
						
							|  |  |  |                                 reason == lldb.eStopReasonException or | 
					
						
							|  |  |  |                                 reason == lldb.eStopReasonSignal): | 
					
						
							|  |  |  |                             stoppedThread = thread | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |                     if stoppedThread: | 
					
						
							|  |  |  |                         # This seems highly fragile and depending on the "No-ops" in the | 
					
						
							|  |  |  |                         # event handling above. | 
					
						
							| 
									
										
										
										
											2015-01-27 10:25:21 +01:00
										 |  |  |                         frame = stoppedThread.GetFrameAtIndex(0) | 
					
						
							| 
									
										
										
										
											2015-04-14 09:06:28 +02:00
										 |  |  |                         line = frame.line_entry.line | 
					
						
							|  |  |  |                         if line != 0: | 
					
						
							|  |  |  |                             self.report = savedReport | 
					
						
							|  |  |  |                             self.process.SetSelectedThread(stoppedThread) | 
					
						
							|  |  |  |                             self.reportVariables() | 
					
						
							|  |  |  |                             #self.reportLocation(frame) | 
					
						
							|  |  |  |                             self.report("@NS@%s@" % self.qtNamespace()) | 
					
						
							|  |  |  |                             #self.report("ENV=%s" % os.environ.items()) | 
					
						
							|  |  |  |                             #self.report("DUMPER=%s" % self.qqDumpers) | 
					
						
							|  |  |  |                             break | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-01-23 17:54:00 +01:00
										 |  |  |             else: | 
					
						
							|  |  |  |                 warn('TIMEOUT') | 
					
						
							| 
									
										
										
										
											2015-04-14 09:06:28 +02:00
										 |  |  |                 warn("Cannot determined stopped thread") | 
					
						
							| 
									
										
										
										
											2014-01-17 16:13:03 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-01-23 17:54:00 +01:00
										 |  |  |         lldb.SBDebugger.Destroy(self.debugger) |