106c3fb27SDimitry Andric #ifdef SWIGPYTHON
206c3fb27SDimitry Andric %typemap(in) (const char **symbol_name, uint32_t num_names) {
306c3fb27SDimitry Andric   using namespace lldb_private;
406c3fb27SDimitry Andric   /* Check if is a list  */
506c3fb27SDimitry Andric   if (PythonList::Check($input)) {
606c3fb27SDimitry Andric     PythonList list(PyRefType::Borrowed, $input);
706c3fb27SDimitry Andric     $2 = list.GetSize();
806c3fb27SDimitry Andric     int i = 0;
906c3fb27SDimitry Andric     $1 = (char**)malloc(($2+1)*sizeof(char*));
1006c3fb27SDimitry Andric     for (i = 0; i < $2; i++) {
1106c3fb27SDimitry Andric       PythonString py_str = list.GetItemAtIndex(i).AsType<PythonString>();
1206c3fb27SDimitry Andric       if (!py_str.IsAllocated()) {
1306c3fb27SDimitry Andric         PyErr_SetString(PyExc_TypeError,"list must contain strings and blubby");
1406c3fb27SDimitry Andric         free($1);
1506c3fb27SDimitry Andric         return nullptr;
1606c3fb27SDimitry Andric       }
1706c3fb27SDimitry Andric 
1806c3fb27SDimitry Andric       $1[i] = const_cast<char*>(py_str.GetString().data());
1906c3fb27SDimitry Andric     }
2006c3fb27SDimitry Andric     $1[i] = 0;
2106c3fb27SDimitry Andric   } else if ($input == Py_None) {
2206c3fb27SDimitry Andric     $1 =  NULL;
2306c3fb27SDimitry Andric   } else {
2406c3fb27SDimitry Andric     PyErr_SetString(PyExc_TypeError,"not a list");
2506c3fb27SDimitry Andric     return NULL;
2606c3fb27SDimitry Andric   }
2706c3fb27SDimitry Andric }
2806c3fb27SDimitry Andric #endif
2906c3fb27SDimitry Andric 
3006c3fb27SDimitry Andric STRING_EXTENSION_LEVEL_OUTSIDE(SBTarget, lldb::eDescriptionLevelBrief)
3106c3fb27SDimitry Andric 
3206c3fb27SDimitry Andric %extend lldb::SBTarget {
3306c3fb27SDimitry Andric #ifdef SWIGPYTHON
3406c3fb27SDimitry Andric     %pythoncode %{
35*5f757f3fSDimitry Andric         # operator== is a free function, which swig does not handle, so we inject
36*5f757f3fSDimitry Andric         # our own equality operator here
37*5f757f3fSDimitry Andric         def __eq__(self, other):
38*5f757f3fSDimitry Andric             return not self.__ne__(other)
39*5f757f3fSDimitry Andric 
4006c3fb27SDimitry Andric         class modules_access(object):
4106c3fb27SDimitry Andric             '''A helper object that will lazily hand out lldb.SBModule objects for a target when supplied an index, or by full or partial path.'''
4206c3fb27SDimitry Andric             def __init__(self, sbtarget):
4306c3fb27SDimitry Andric                 self.sbtarget = sbtarget
4406c3fb27SDimitry Andric 
4506c3fb27SDimitry Andric             def __len__(self):
4606c3fb27SDimitry Andric                 if self.sbtarget:
4706c3fb27SDimitry Andric                     return int(self.sbtarget.GetNumModules())
4806c3fb27SDimitry Andric                 return 0
4906c3fb27SDimitry Andric 
5006c3fb27SDimitry Andric             def __getitem__(self, key):
5106c3fb27SDimitry Andric                 num_modules = self.sbtarget.GetNumModules()
5206c3fb27SDimitry Andric                 if type(key) is int:
5306c3fb27SDimitry Andric                     if -num_modules <= key < num_modules:
5406c3fb27SDimitry Andric                         key %= num_modules
5506c3fb27SDimitry Andric                         return self.sbtarget.GetModuleAtIndex(key)
5606c3fb27SDimitry Andric                 elif type(key) is str:
5706c3fb27SDimitry Andric                     if key.find('/') == -1:
5806c3fb27SDimitry Andric                         for idx in range(num_modules):
5906c3fb27SDimitry Andric                             module = self.sbtarget.GetModuleAtIndex(idx)
6006c3fb27SDimitry Andric                             if module.file.basename == key:
6106c3fb27SDimitry Andric                                 return module
6206c3fb27SDimitry Andric                     else:
6306c3fb27SDimitry Andric                         for idx in range(num_modules):
6406c3fb27SDimitry Andric                             module = self.sbtarget.GetModuleAtIndex(idx)
6506c3fb27SDimitry Andric                             if module.file.fullpath == key:
6606c3fb27SDimitry Andric                                 return module
6706c3fb27SDimitry Andric                     # See if the string is a UUID
6806c3fb27SDimitry Andric                     try:
6906c3fb27SDimitry Andric                         the_uuid = uuid.UUID(key)
7006c3fb27SDimitry Andric                         if the_uuid:
7106c3fb27SDimitry Andric                             for idx in range(num_modules):
7206c3fb27SDimitry Andric                                 module = self.sbtarget.GetModuleAtIndex(idx)
7306c3fb27SDimitry Andric                                 if module.uuid == the_uuid:
7406c3fb27SDimitry Andric                                     return module
7506c3fb27SDimitry Andric                     except:
7606c3fb27SDimitry Andric                         return None
7706c3fb27SDimitry Andric                 elif type(key) is uuid.UUID:
7806c3fb27SDimitry Andric                     for idx in range(num_modules):
7906c3fb27SDimitry Andric                         module = self.sbtarget.GetModuleAtIndex(idx)
8006c3fb27SDimitry Andric                         if module.uuid == key:
8106c3fb27SDimitry Andric                             return module
8206c3fb27SDimitry Andric                 elif type(key) is re.SRE_Pattern:
8306c3fb27SDimitry Andric                     matching_modules = []
8406c3fb27SDimitry Andric                     for idx in range(num_modules):
8506c3fb27SDimitry Andric                         module = self.sbtarget.GetModuleAtIndex(idx)
8606c3fb27SDimitry Andric                         re_match = key.search(module.path.fullpath)
8706c3fb27SDimitry Andric                         if re_match:
8806c3fb27SDimitry Andric                             matching_modules.append(module)
8906c3fb27SDimitry Andric                     return matching_modules
9006c3fb27SDimitry Andric                 else:
9106c3fb27SDimitry Andric                     print("error: unsupported item type: %s" % type(key))
9206c3fb27SDimitry Andric                 return None
9306c3fb27SDimitry Andric 
9406c3fb27SDimitry Andric         def get_modules_access_object(self):
9506c3fb27SDimitry Andric             '''An accessor function that returns a modules_access() object which allows lazy module access from a lldb.SBTarget object.'''
9606c3fb27SDimitry Andric             return self.modules_access(self)
9706c3fb27SDimitry Andric 
9806c3fb27SDimitry Andric         def get_modules_array(self):
9906c3fb27SDimitry Andric             '''An accessor function that returns a list() that contains all modules in a lldb.SBTarget object.'''
10006c3fb27SDimitry Andric             modules = []
10106c3fb27SDimitry Andric             for idx in range(self.GetNumModules()):
10206c3fb27SDimitry Andric                 modules.append(self.GetModuleAtIndex(idx))
10306c3fb27SDimitry Andric             return modules
10406c3fb27SDimitry Andric 
10506c3fb27SDimitry Andric         def module_iter(self):
10606c3fb27SDimitry Andric             '''Returns an iterator over all modules in a lldb.SBTarget
10706c3fb27SDimitry Andric             object.'''
10806c3fb27SDimitry Andric             return lldb_iter(self, 'GetNumModules', 'GetModuleAtIndex')
10906c3fb27SDimitry Andric 
11006c3fb27SDimitry Andric         def breakpoint_iter(self):
11106c3fb27SDimitry Andric             '''Returns an iterator over all breakpoints in a lldb.SBTarget
11206c3fb27SDimitry Andric             object.'''
11306c3fb27SDimitry Andric             return lldb_iter(self, 'GetNumBreakpoints', 'GetBreakpointAtIndex')
11406c3fb27SDimitry Andric 
11506c3fb27SDimitry Andric         class bkpts_access(object):
11606c3fb27SDimitry Andric             '''A helper object that will lazily hand out bkpts for a target when supplied an index.'''
11706c3fb27SDimitry Andric             def __init__(self, sbtarget):
11806c3fb27SDimitry Andric                 self.sbtarget = sbtarget
11906c3fb27SDimitry Andric 
12006c3fb27SDimitry Andric             def __len__(self):
12106c3fb27SDimitry Andric                 if self.sbtarget:
12206c3fb27SDimitry Andric                     return int(self.sbtarget.GetNumBreakpoints())
12306c3fb27SDimitry Andric                 return 0
12406c3fb27SDimitry Andric 
12506c3fb27SDimitry Andric             def __getitem__(self, key):
12606c3fb27SDimitry Andric                 if isinstance(key, int):
12706c3fb27SDimitry Andric                     count = len(self)
12806c3fb27SDimitry Andric                     if -count <= key < count:
12906c3fb27SDimitry Andric                         key %= count
13006c3fb27SDimitry Andric                         return self.sbtarget.GetBreakpointAtIndex(key)
13106c3fb27SDimitry Andric                 return None
13206c3fb27SDimitry Andric 
13306c3fb27SDimitry Andric         def get_bkpts_access_object(self):
13406c3fb27SDimitry Andric             '''An accessor function that returns a bkpts_access() object which allows lazy bkpt access from a lldb.SBtarget object.'''
13506c3fb27SDimitry Andric             return self.bkpts_access(self)
13606c3fb27SDimitry Andric 
13706c3fb27SDimitry Andric         def get_target_bkpts(self):
13806c3fb27SDimitry Andric             '''An accessor function that returns a list() that contains all bkpts in a lldb.SBtarget object.'''
13906c3fb27SDimitry Andric             bkpts = []
14006c3fb27SDimitry Andric             for idx in range(self.GetNumBreakpoints()):
14106c3fb27SDimitry Andric                 bkpts.append(self.GetBreakpointAtIndex(idx))
14206c3fb27SDimitry Andric             return bkpts
14306c3fb27SDimitry Andric 
14406c3fb27SDimitry Andric         def watchpoint_iter(self):
14506c3fb27SDimitry Andric             '''Returns an iterator over all watchpoints in a lldb.SBTarget
14606c3fb27SDimitry Andric             object.'''
14706c3fb27SDimitry Andric             return lldb_iter(self, 'GetNumWatchpoints', 'GetWatchpointAtIndex')
14806c3fb27SDimitry Andric 
14906c3fb27SDimitry Andric         class watchpoints_access(object):
15006c3fb27SDimitry Andric             '''A helper object that will lazily hand out watchpoints for a target when supplied an index.'''
15106c3fb27SDimitry Andric             def __init__(self, sbtarget):
15206c3fb27SDimitry Andric                 self.sbtarget = sbtarget
15306c3fb27SDimitry Andric 
15406c3fb27SDimitry Andric             def __len__(self):
15506c3fb27SDimitry Andric                 if self.sbtarget:
15606c3fb27SDimitry Andric                     return int(self.sbtarget.GetNumWatchpoints())
15706c3fb27SDimitry Andric                 return 0
15806c3fb27SDimitry Andric 
15906c3fb27SDimitry Andric             def __getitem__(self, key):
16006c3fb27SDimitry Andric                 if isinstance(key, int):
16106c3fb27SDimitry Andric                     count = len(self)
16206c3fb27SDimitry Andric                     if -count <= key < count:
16306c3fb27SDimitry Andric                         key %= count
16406c3fb27SDimitry Andric                         return self.sbtarget.GetWatchpointAtIndex(key)
16506c3fb27SDimitry Andric                 return None
16606c3fb27SDimitry Andric 
16706c3fb27SDimitry Andric         def get_watchpoints_access_object(self):
16806c3fb27SDimitry Andric             '''An accessor function that returns a watchpoints_access() object which allows lazy watchpoint access from a lldb.SBtarget object.'''
16906c3fb27SDimitry Andric             return self.watchpoints_access(self)
17006c3fb27SDimitry Andric 
17106c3fb27SDimitry Andric         def get_target_watchpoints(self):
17206c3fb27SDimitry Andric             '''An accessor function that returns a list() that contains all watchpoints in a lldb.SBtarget object.'''
17306c3fb27SDimitry Andric             watchpoints = []
17406c3fb27SDimitry Andric             for idx in range(self.GetNumWatchpoints()):
17506c3fb27SDimitry Andric                 bkpts.append(self.GetWatchpointAtIndex(idx))
17606c3fb27SDimitry Andric             return watchpoints
17706c3fb27SDimitry Andric 
17806c3fb27SDimitry Andric         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).''')
17906c3fb27SDimitry Andric         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.''')
18006c3fb27SDimitry Andric         process = property(GetProcess, None, doc='''A read only property that returns an lldb object that represents the process (lldb.SBProcess) that this target owns.''')
18106c3fb27SDimitry Andric         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.''')
18206c3fb27SDimitry Andric         debugger = property(GetDebugger, None, doc='''A read only property that returns an lldb object that represents the debugger (lldb.SBDebugger) that owns this target.''')
18306c3fb27SDimitry Andric         num_breakpoints = property(GetNumBreakpoints, None, doc='''A read only property that returns the number of breakpoints that this target has as an integer.''')
18406c3fb27SDimitry Andric         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.''')
18506c3fb27SDimitry Andric         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]").''')
18606c3fb27SDimitry Andric         num_watchpoints = property(GetNumWatchpoints, None, doc='''A read only property that returns the number of watchpoints that this target has as an integer.''')
18706c3fb27SDimitry Andric         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.''')
18806c3fb27SDimitry Andric         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]").''')
18906c3fb27SDimitry Andric         broadcaster = property(GetBroadcaster, None, doc='''A read only property that an lldb object that represents the broadcaster (lldb.SBBroadcaster) for this target.''')
19006c3fb27SDimitry Andric         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.''')
19106c3fb27SDimitry Andric         addr_size = property(GetAddressByteSize, None, doc='''A read only property that returns the size in bytes of an address for this target.''')
19206c3fb27SDimitry Andric         triple = property(GetTriple, None, doc='''A read only property that returns the target triple (arch-vendor-os) for this target as a string.''')
19306c3fb27SDimitry Andric         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.''')
19406c3fb27SDimitry Andric         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.''')
19506c3fb27SDimitry Andric         platform = property(GetPlatform, None, doc='''A read only property that returns the platform associated with with this target.''')
19606c3fb27SDimitry Andric     %}
19706c3fb27SDimitry Andric #endif
19806c3fb27SDimitry Andric }
199