Beispiel #1
0
 def iter_helper(self, arg):
     gar_ptr = '((garray_T *){})'.format(arg)
     yield from walker_defs.Array.single_iter(
         first=True,
         start=eval_uint('{}->ga_data'.format(gar_ptr)),
         count=eval_uint('{}->ga_len'.format(gar_ptr)),
         typename=self.t,
         element_size=find_type_size(self.t))
Beispiel #2
0
 def __walker_start(self, element):
     # So the user can put '{}' in their tabpage definition.
     startptr = eval_uint(self.format_command(element, self.startptr)
                          if element is not None else self.startptr)
     # The current tab doesn't have windows stored in it, hence if we're
     # asked to walk over windows in the current tab we need to work
     # differently.
     if startptr == eval_uint('curtab'):
         startstr = 'firstwin'
     else:
         startstr = '((tabpage_T *){})->tp_firstwin'.format(startptr)
     return self.calc(startstr)
 def from_userstring(cls, args, first, last):
     cmd_parts = cls.parse_args(args, [3, 4], ';')
     if cmd_parts[-1] == 'unique':
         cmd_parts.pop()
         unique = True
     else:
         unique = False
     return cls(eval_uint(cmd_parts[-1]), cmd_parts[-2].strip(),
                cmd_parts[0], unique)
Beispiel #4
0
 def __init__(self, expr, deref, first):
     # Calculate a bunch of offsets and types for future use.
     self.mqi_q_offset = offsetof('MultiQueueItem', 'node')
     self.mq_headtail_offset = offsetof('MultiQueue', 'headtail')
     self.mqi_ptr = gdb.lookup_type('MultiQueueItem').pointer()
     self.queue_ptr = gdb.lookup_type('QUEUE').pointer()
     self.expr = expr
     self.deref = deref
     self.start = eval_uint(expr) if first else None
    def iter_def(self, inpipe):
        if not inpipe:
            self.__add_addr(eval_uint(self.start_expr), 0)
            yield from self.__iter_helper()
            return

        # Deal with each given function (and all their descendants) in turn.
        for element in inpipe:
            type(self).hypothetical_stack = []
            self.__add_addr(
                int(as_voidptr(self.eval_command(element, self.start_expr))),
                0)
            yield from self.__iter_helper()
Beispiel #6
0
    def invoke(self, arg, _):
        args = gdb.string_to_argv(arg)
        func_addr = eval_uint(''.join(args[:-1]))
        # Let possible error raise -- user needs to know something went wrong.
        func_dis, func_name, func_file = function_disassembly(func_addr)
        glob_name = args[-1]

        glob_uses = [
            self.make_info(val) for val in func_dis
            if val['asm'].split()[-1] == '<{}>'.format(glob_name)
        ]

        if glob_uses:
            print('"{}" uses "{}" in the following places'.format(
                func_name, glob_name))
            print('\n'.join(glob_uses))
Beispiel #7
0
    def invoke(self, *_):
        pos = eval_uint('$pc')
        line = gdb.find_pc_line(pos)
        if not line.symtab:
            return

        try:
            block = gdb.block_for_pc(pos)
        except RuntimeError as e:
            if e.args == ('Cannot locate object file for block.',):
                return
            raise

        if block.function is None:
            print('First found block no function', pos)
            return
        while block.function.name is None:
            if block.superblock:
                block = block.superblock
            else:
                print('No superblock at', pos)
                return
            if block.function is None:
                print('Function iterated to None in', pos)
                return

        offset = pos - block.start
        offset_str = '+{}'.format(offset) if offset else ''

        entering = self.update_fp_stack()

        if entering:
            curindent = self.indent
            self.indent += 4
            direction_string = '-->'
        else:
            self.indent -= 4
            curindent = self.indent
            direction_string = '<--'

        print_str = '{}{}{}{} {}:{}'.format(' '*curindent, direction_string,
                                            block.function.name, offset_str,
                                            line.symtab.filename, line.line)

        print(print_str)
Beispiel #8
0
    def update_fp_stack(self):
        '''Update fp stack according to if $fp was seen before.

        Return False if $fp was seen before (and hence if we think we are
        leaving a function), True otherwise.

        '''
        curfp = eval_uint('$rbp')
        if not self.fp_stack or curfp < self.fp_stack[-1]:
            self.fp_stack.append(curfp)
            return True

        # The frame pointer decreases upon entering a new function, and
        # increases otherwise.
        # Because strange things can happen with the indirected @plt functions,
        # we take all frame pointers that are below the current one off our
        # stack.
        self.fp_stack.pop()
        return False
Beispiel #9
0
 def from_userstring(cls, args, first, last):
     return cls(eval_uint(args) if first else None)
Beispiel #10
0
 def from_userstring(cls, args, first, last):
     cmd_parts = cls.parse_args(args, [2, 2] if first else [1, 1], ';')
     return cls(cmd_parts[-1],
                eval_uint(cmd_parts[0]) if first else None)
Beispiel #11
0
 def from_userstring(cls, args, first, last):
     return cls(first,
                first and not args,
                None if not args else cls.Ele('buf_T *', eval_uint(args)))