Exemplo n.º 1
0
  def invoke(self, arg, from_tty):
    var = arg.split(' ')[0]
    m = re.match(r'^\s*\S+\b\s*(.*)',arg)
    code = m.group(1)

    # Special case recognizing _.\w+ and turning it into
    # _[\w+]
    code = re.sub(r'_\.(\w+)','(_[\'\\1\'])',code)

    # Turn the code into a function definition
    code = 'def pvf__(_,_idx=0) :\n  return ' + code

    # Compile it into the current module
#    module = imp.new_module('myfunctions')
    module = sys.modules[__name__]
    exec(code, module.__dict__)

    val = var_to_value(var)

    p = printers.StdVectorPrinter('dummy', val)
    for ch in p.children():
      ret = module.pvf__(ch[1],ch[0])
      if isinstance(ret,tuple):
        print(' '.join([str(v) for v in ret]))
      elif ret is not None:
        print(ret)
Exemplo n.º 2
0
def vec_to_keyvals(val, fields_filter=None, selector=None):
  '''Turn a vector into a list of keyvals'''
  p = printers.StdVectorPrinter('dummy', val)
  keyvals = []
  for key,val in p.children():
    if selector is not None:
      k = str(key).replace('[','').replace(']','')
      if not k in selector:
        continue
    keyvals = add_key_val(keyvals, key, val, fields_filter)
  return keyvals
Exemplo n.º 3
0
    def children(self):
        if self.value['mpPolyPolygon']['m_pimpl'].type.code in (
                gdb.TYPE_CODE_PTR, gdb.TYPE_CODE_MEMBERPTR):
            if self.value['mpPolyPolygon']['m_pimpl']:
                try:
                    vector = self.value['mpPolyPolygon'][
                        'm_pimpl'].dereference()['m_value']['maPolygons']
                    import libstdcxx.v6.printers as std
                    return std.StdVectorPrinter("std::vector",
                                                vector).children()
                except RuntimeError:
                    gdb.write(
                        "Cannot access memory at address " +
                        str(self.value['mpPolyPolygon']['m_pimpl'].address))

        return None
Exemplo n.º 4
0
  def invoke(self, arg, from_tty):
    args = shlex.split(arg)
    var,fields_filter = args[0],args[1:]
    m = re.match(r'(\w+)\[(.*?)\]',var)
    selector = None
    if m:
      var = m.group(1)
      selector = m.group(2)

    val = var_to_value(var)

    p = printers.StdVectorPrinter('dummy', val)
    keyvals = []
    for key,val in p.children():
      if selector is not None:
        k = str(key).replace('[','').replace(']','')
        if not k in selector:
          continue
      keyvals = add_key_val(keyvals, key, val, fields_filter)
    print_key_vals(keyvals)
Exemplo n.º 5
0
 def invoke(self, args, from_tty):
     val = gdb.parse_and_eval(args)
     for _, val in cxxprinters.StdVectorPrinter("", val).children():
         print(ptrvec(val))
Exemplo n.º 6
0
def ptrvec(val):
    printer = cxxprinters.StdVectorPrinter("", val).children()
    return "{" + ", ".join(str(val.dereference()) for _, val in printer) + "}"