200 lines · plain
1#ifdef SWIGPYTHON2%typemap(in) (const char **symbol_name, uint32_t num_names) {3 using namespace lldb_private;4 /* Check if is a list */5 if (PythonList::Check($input)) {6 PythonList list(PyRefType::Borrowed, $input);7 $2 = list.GetSize();8 int i = 0;9 $1 = (char**)malloc(($2+1)*sizeof(char*));10 for (i = 0; i < $2; i++) {11 PythonString py_str = list.GetItemAtIndex(i).AsType<PythonString>();12 if (!py_str.IsAllocated()) {13 PyErr_SetString(PyExc_TypeError,"list must contain strings and blubby");14 free($1);15 return nullptr;16 }17 18 $1[i] = const_cast<char*>(py_str.GetString().data());19 }20 $1[i] = 0;21 } else if ($input == Py_None) {22 $1 = NULL;23 } else {24 PyErr_SetString(PyExc_TypeError,"not a list");25 return NULL;26 }27}28#endif29 30STRING_EXTENSION_LEVEL_OUTSIDE(SBTarget, lldb::eDescriptionLevelBrief)31 32%extend lldb::SBTarget {33#ifdef SWIGPYTHON34 %pythoncode %{35 # operator== is a free function, which swig does not handle, so we inject36 # our own equality operator here37 def __eq__(self, other):38 return not self.__ne__(other)39 40 class modules_access(object):41 '''A helper object that will lazily hand out lldb.SBModule objects for a target when supplied an index, or by full or partial path.'''42 def __init__(self, sbtarget):43 self.sbtarget = sbtarget44 45 def __len__(self):46 if self.sbtarget:47 return int(self.sbtarget.GetNumModules())48 return 049 50 def __getitem__(self, key):51 num_modules = self.sbtarget.GetNumModules()52 if type(key) is int:53 if -num_modules <= key < num_modules:54 key %= num_modules55 return self.sbtarget.GetModuleAtIndex(key)56 elif type(key) is str:57 if key.find('/') == -1:58 for idx in range(num_modules):59 module = self.sbtarget.GetModuleAtIndex(idx)60 if module.file.basename == key:61 return module62 else:63 for idx in range(num_modules):64 module = self.sbtarget.GetModuleAtIndex(idx)65 if module.file.fullpath == key:66 return module67 # See if the string is a UUID68 try:69 the_uuid = uuid.UUID(key)70 if the_uuid:71 for idx in range(num_modules):72 module = self.sbtarget.GetModuleAtIndex(idx)73 if module.uuid == the_uuid:74 return module75 except:76 return None77 elif type(key) is uuid.UUID:78 for idx in range(num_modules):79 module = self.sbtarget.GetModuleAtIndex(idx)80 if module.uuid == key:81 return module82 elif isinstance(key, type(re.compile(''))):83 matching_modules = []84 for idx in range(num_modules):85 module = self.sbtarget.GetModuleAtIndex(idx)86 re_match = key.search(module.file.fullpath)87 if re_match:88 matching_modules.append(module)89 return matching_modules90 else:91 print("error: unsupported item type: %s" % type(key))92 return None93 94 def get_modules_access_object(self):95 '''An accessor function that returns a modules_access() object which allows lazy module access from a lldb.SBTarget object.'''96 return self.modules_access(self)97 98 def get_modules_array(self):99 '''An accessor function that returns a list() that contains all modules in a lldb.SBTarget object.'''100 modules = []101 for idx in range(self.GetNumModules()):102 modules.append(self.GetModuleAtIndex(idx))103 return modules104 105 def module_iter(self):106 '''Returns an iterator over all modules in a lldb.SBTarget107 object.'''108 return lldb_iter(self, 'GetNumModules', 'GetModuleAtIndex')109 110 def breakpoint_iter(self):111 '''Returns an iterator over all breakpoints in a lldb.SBTarget112 object.'''113 return lldb_iter(self, 'GetNumBreakpoints', 'GetBreakpointAtIndex')114 115 class bkpts_access(object):116 '''A helper object that will lazily hand out bkpts for a target when supplied an index.'''117 def __init__(self, sbtarget):118 self.sbtarget = sbtarget119 120 def __len__(self):121 if self.sbtarget:122 return int(self.sbtarget.GetNumBreakpoints())123 return 0124 125 def __getitem__(self, key):126 if isinstance(key, int):127 count = len(self)128 if -count <= key < count:129 key %= count130 return self.sbtarget.GetBreakpointAtIndex(key)131 return None132 133 def get_bkpts_access_object(self):134 '''An accessor function that returns a bkpts_access() object which allows lazy bkpt access from a lldb.SBtarget object.'''135 return self.bkpts_access(self)136 137 def get_target_bkpts(self):138 '''An accessor function that returns a list() that contains all bkpts in a lldb.SBtarget object.'''139 bkpts = []140 for idx in range(self.GetNumBreakpoints()):141 bkpts.append(self.GetBreakpointAtIndex(idx))142 return bkpts143 144 def watchpoint_iter(self):145 '''Returns an iterator over all watchpoints in a lldb.SBTarget146 object.'''147 return lldb_iter(self, 'GetNumWatchpoints', 'GetWatchpointAtIndex')148 149 class watchpoints_access(object):150 '''A helper object that will lazily hand out watchpoints for a target when supplied an index.'''151 def __init__(self, sbtarget):152 self.sbtarget = sbtarget153 154 def __len__(self):155 if self.sbtarget:156 return int(self.sbtarget.GetNumWatchpoints())157 return 0158 159 def __getitem__(self, key):160 if isinstance(key, int):161 count = len(self)162 if -count <= key < count:163 key %= count164 return self.sbtarget.GetWatchpointAtIndex(key)165 return None166 167 def get_watchpoints_access_object(self):168 '''An accessor function that returns a watchpoints_access() object which allows lazy watchpoint access from a lldb.SBtarget object.'''169 return self.watchpoints_access(self)170 171 def get_target_watchpoints(self):172 '''An accessor function that returns a list() that contains all watchpoints in a lldb.SBtarget object.'''173 watchpoints = []174 for idx in range(self.GetNumWatchpoints()):175 watchpoints.append(self.GetWatchpointAtIndex(idx))176 return watchpoints177 178 modules = property(get_modules_array, None, doc='''A read only property that returns a list() of lldb.SBModule objects contained in this target. This list is a list all modules that the target currently is tracking (the main executable and all dependent shared libraries).''')179 module = property(get_modules_access_object, None, doc=r'''A read only property that returns an object that implements python operator overloading with the square brackets().\n target.module[<int>] allows array access to any modules.\n target.module[<str>] allows access to modules by basename, full path, or uuid string value.\n target.module[uuid.UUID()] allows module access by UUID.\n target.module[re] allows module access using a regular expression that matches the module full path.''')180 process = property(GetProcess, None, doc='''A read only property that returns an lldb object that represents the process (lldb.SBProcess) that this target owns.''')181 executable = property(GetExecutable, None, doc='''A read only property that returns an lldb object that represents the main executable module (lldb.SBModule) for this target.''')182 debugger = property(GetDebugger, None, doc='''A read only property that returns an lldb object that represents the debugger (lldb.SBDebugger) that owns this target.''')183 num_breakpoints = property(GetNumBreakpoints, None, doc='''A read only property that returns the number of breakpoints that this target has as an integer.''')184 breakpoints = property(get_target_bkpts, None, doc='''A read only property that returns a list() of lldb.SBBreakpoint objects for all breakpoints in this target.''')185 breakpoint = property(get_bkpts_access_object, None, doc='''A read only property that returns an object that can be used to access breakpoints as an array ("bkpt_12 = lldb.target.bkpt[12]").''')186 num_watchpoints = property(GetNumWatchpoints, None, doc='''A read only property that returns the number of watchpoints that this target has as an integer.''')187 watchpoints = property(get_target_watchpoints, None, doc='''A read only property that returns a list() of lldb.SBwatchpoint objects for all watchpoints in this target.''')188 watchpoint = property(get_watchpoints_access_object, None, doc='''A read only property that returns an object that can be used to access watchpoints as an array ("watchpoint_12 = lldb.target.watchpoint[12]").''')189 broadcaster = property(GetBroadcaster, None, doc='''A read only property that an lldb object that represents the broadcaster (lldb.SBBroadcaster) for this target.''')190 byte_order = property(GetByteOrder, None, doc='''A read only property that returns an lldb enumeration value (lldb.eByteOrderLittle, lldb.eByteOrderBig, lldb.eByteOrderInvalid) that represents the byte order for this target.''')191 addr_size = property(GetAddressByteSize, None, doc='''A read only property that returns the size in bytes of an address for this target.''')192 triple = property(GetTriple, None, doc='''A read only property that returns the target triple (arch-vendor-os) for this target as a string.''')193 arch_name = property(GetArchName, None, doc='''A read only property that returns the architecture name for this target as a string.''')194 data_byte_size = property(GetDataByteSize, None, doc='''A read only property that returns the size in host bytes of a byte in the data address space for this target.''')195 code_byte_size = property(GetCodeByteSize, None, doc='''A read only property that returns the size in host bytes of a byte in the code address space for this target.''')196 platform = property(GetPlatform, None, doc='''A read only property that returns the platform associated with with this target.''')197 %}198#endif199}200