Exemple #1
0
    def mstep_func(self, args):
        frame = m_frame.get_selected_frame()
        ds = m_datastore.get_stack_frame_data(frame)
        if not ds:
            return
        if m_debug.Debug: m_debug.dbg_print("retrieved ds=", ds)
        asm_path = ds['frame_func_header_info']['asm_path']
        asm_line = ds['frame_func_src_info']['asm_line']
        asm_offset = ds['frame_func_src_info']['asm_offset']

        stop = False
        short_src_file_name = None
        short_src_file_line = None
        count = 0
        while not stop:
            # before we execute msi command, we must know should we stop keep executing msi after the current msi
            # is executed. If current msi command is executed and found it should stop, then we need the source file
            # information after stop.
            stop, short_src_file_name, short_src_file_line = m_asm.look_up_next_opcode(
                asm_path, asm_line, asm_offset)
            if m_debug.Debug:
                m_debug.dbg_print("stop =", stop, "short_src_file_name=",
                                  short_src_file_name, "short_src_file_line=",
                                  short_src_file_line)
            m_util.gdb_exec("msi -internal")
            count += 1
            if m_debug.Debug:
                m_debug.dbg_print("executed %d opcodes", count)
            # retrieve the new frame data since one opcode can change to a different frame
            frame = m_frame.get_selected_frame()
            ds = m_datastore.get_stack_frame_data(frame)
            if not ds:
                gdb_print("Warning: Failed to get new stack frame to continue")
                return
            if m_debug.Debug: m_debug.dbg_print("retrieved ds=", ds)
            asm_path = ds['frame_func_header_info']['asm_path']
            asm_line = ds['frame_func_src_info']['asm_line']
            asm_offset = ds['frame_func_src_info']['asm_offset']

        gdb_print("Info: executed %d %s" %
                  (count, 'opcode' if count == 1 else 'opcodes'))
        if m_debug.Debug:
            m_debug.dbg_print("short_src_file_name = ", short_src_file_name,
                              "short_src_file_line=", short_src_file_line)

        file_full_path = None
        for source_path in m_list.maple_source_path_list:
            file_full_path = m_list.find_one_file(short_src_file_name,
                                                  source_path)
            if not file_full_path:
                continue
            else:
                break

        if not file_full_path:
            gdb_print("Warning: source file %s not found" %
                      (short_src_file_name))
        else:
            m_list.display_src_file_lines(file_full_path, short_src_file_line)
        return
Exemple #2
0
    def mlist_mir_file_func(self, offset):
        frame_change_count = m_datastore.mgdb_rdata.read_frame_change_counter()

        # stack selected frame changed by other cmds or breakpoints
        if self.frame_change_count < frame_change_count:
            frame = m_frame.get_selected_frame()
            if not frame:
                return

            ds = m_datastore.get_stack_frame_data(frame)
            if not ds:
                return

            self.frame_data = ds
            self.frame_change_count = frame_change_count

        if offset != 0:
            new_line = self.prev_mir_file_line + offset
            self.frame_data['frame_func_src_info'][
                'mirmpl_line'] = new_line if new_line > 1 else 1

        if len(self.frame_data) == 0:
            return

        self.display_mir_file_lines(self.frame_data['frame_func_header_info']['mirmpl_path'], \
                                    self.frame_data['frame_func_src_info']['mirmpl_line'],\
                                    self.frame_data['frame_func_header_info']['func_header_mirmpl_tuple'])
    def mlocal_func(self, args, from_tty):
        mode = 'local'
        s = args.split()
        if len(s) == 1 and s[0] == '-stack':
            mode = 'stack'
        elif len(s) == 1 and s[0] == '-s':
            mode = 'stack'

        frame = m_frame.get_selected_frame()
        if not frame:
            gdb_print("no valid frame found")
            return

        data = m_datastore.get_stack_frame_data(frame)
        if not data:
            gdb_print("no valid frame data found")
            return

        func_argus_locals = data['func_argus_locals']
        func_header_name = data['frame_func_header_info']['func_header_name']

        if m_debug.Debug:
            m_debug.dbg_print("func_argus_locals ======= ")
            m_debug.dbg_print("func_argus_locals=", func_argus_locals)
            m_debug.dbg_print("func_header_name=", func_header_name)

        if mode == 'local':
            self.display_locals(func_argus_locals, func_header_name)
        else:
            self.display_stack(func_argus_locals, func_header_name)

        return
Exemple #4
0
    def mstepi_update_and_display(self, frame):
        # this will update the Maple gdb runtime metadata store.
        m_datastore.mgdb_rdata.update_gdb_runtime_data()
        m_datastore.mgdb_rdata.update_frame_change_counter()

        ds = m_datastore.get_stack_frame_data(frame)
        if not ds:
            return
        if m_debug.Debug: m_debug.dbg_print("retrieved ds=", ds)

        if m_set.msettings['stack'] == 'on':
            m_util.gdb_exec('mlocal -stack')

        asm_path = ds['frame_func_header_info']['asm_path']
        asm_line = ds['frame_func_src_info']['asm_line']
        asm_offset = ds['frame_func_src_info']['asm_offset']

        gdb_print("asm file: %s%s%s" %
                  (MColors.BT_SRC, asm_path, MColors.ENDC))
        f = open(asm_path, 'r')
        f.seek(asm_offset)
        gdb_print("=> %d : %s" % (asm_line, f.readline().rstrip()))
        gdb_print("   %d : %s" % (asm_line + 1, f.readline().rstrip()))
        gdb_print("   %d : %s" % (asm_line + 2, f.readline().rstrip()))
        f.close()
        m_util.gdb_exec('display')
Exemple #5
0
def mni_display_last_opcodes():
    # to display the latest instructions will be executed after this command
    frame = m_frame.get_selected_frame()
    if not frame:
        return
    ds = m_datastore.get_stack_frame_data(frame)
    if not ds:
        return
    if m_debug.Debug: m_debug.dbg_print("retrieved ds=", ds)

    if m_set.msettings['stack'] == 'on':
        m_util.gdb_exec('mlocal -stack')

    asm_path = ds['frame_func_header_info']['asm_path']
    asm_line = ds['frame_func_src_info']['asm_line']
    asm_offset = ds['frame_func_src_info']['asm_offset']

    gdb_print("asm file: %s%s%s" % (MColors.BT_SRC, asm_path, MColors.ENDC))
    f = open(asm_path, 'r')
    f.seek(asm_offset)
    line = f.readline()
    gdb_print(str(asm_line) + " : " + line.rstrip())
    line = f.readline()
    gdb_print(str(asm_line+1) + " : " + line.rstrip())
    line = f.readline()
    gdb_print(str(asm_line+2) + " : " + line.rstrip())
    f.close()
Exemple #6
0
    def mlist_source_file_func(self, filename=None, line=0, offset=0):
        """
        params: line = 0 and offset = 0 allowed
                line = 0 and offset != 0 allowed
                line != 0 and offset = 0 allowed
                line != 0 and offset != 0 NOT allowed
        """
        if line != 0 and offset != 0:
            return

        frame_change_count = m_datastore.mgdb_rdata.read_frame_change_counter()

        # stack selected frame changed by other cmds or breakpoints
        if self.frame_change_count < frame_change_count:
            frame = m_frame.get_selected_frame()
            if not frame:
                return

            ds = m_datastore.get_stack_frame_data(frame)
            if not ds:
                return

            self.frame_data = ds
            self.frame_change_count = frame_change_count

        if filename:
            self.frame_data['frame_func_src_info'][
                'short_src_file_name'] = filename
        if line != 0:
            self.frame_data['frame_func_src_info'][
                'short_src_file_line'] = line
        if offset != 0:
            new_line = self.prev_src_file_line + offset
            self.frame_data['frame_func_src_info'][
                'short_src_file_line'] = new_line if new_line > 1 else 1

        if len(self.frame_data) == 0:
            return

        file_full_path = None
        for source_path in maple_source_path_list:
            file_full_path = find_one_file(
                self.frame_data['frame_func_src_info']['short_src_file_name'],
                source_path)
            if not file_full_path:
                continue
            else:
                break

        if not file_full_path:
            if self.frame_data['frame_func_src_info']['short_src_file_name']:
                gdb_print("Warning: Source code file " +
                          self.frame_data['frame_func_src_info']
                          ['short_src_file_name'] + " not found in any path")
            else:
                gdb_print(
                    "Warning: Source code file not found. try 'mlist -asm' instead"
                )
            return
        self.display_src_lines(
            file_full_path,
            self.frame_data['frame_func_src_info']['short_src_file_line'])
Exemple #7
0
def print_maple_frame_dync(frame, index, mbt_format):
    """
    prints one Maple backtrace frame.

    params:
      frame: a gdb.Frame object
      index: a index number of the frame.
      mbt_format: print Maple backtrace in specified format, MBT_FORMAT_SRC or MBT_FORMAT_ASM or MBT_FORMAT_MIR
    """

    data = m_datastore.get_stack_frame_data(frame)
    if not data:
        gdb_print('#%i no info' % (index))
        return

    so_path = data['frame_func_header_info']['so_path']
    asm_path = data['frame_func_header_info']['asm_path']
    mmpl_path = data['frame_func_header_info']['mmpl_path']
    func_addr_offset = data['frame_func_header_info']['func_addr_offset']
    func_name = data['frame_func_header_info']['func_name']

    src_file_short_name = data['frame_func_src_info']['short_src_file_name']
    asm_line_num = data['frame_func_src_info']['asm_line']
    mmpl_line_num = 0  #data['frame_func_src_info']['mmpl_line']
    src_file_line = data['frame_func_src_info']['short_src_file_line']

    #func_argus_locals = data['func_argus_locals']

    if src_file_short_name:
        file_full_path = None
        for source_path in m_list.maple_source_path_list:
            file_full_path = m_list.find_one_file(src_file_short_name,
                                                  source_path)
            if not file_full_path:
                continue
            else:
                break
        if not file_full_path: file_full_path = "unknown"
    else:
        file_full_path = 'unknown'

    # buffer format
    # index func_offset func_symbol (type argu=value, ...) at source-file-full-path:line_num
    args_buffer = ""
    '''
    arg_num = len(func_argus_locals['formals_name'])
    for i in range(arg_num):
        arg_value = m_info.get_maple_caller_argument_value(i, arg_num, func_argus_locals['formals_type'][i])
        if arg_value:
            if func_argus_locals['formals_type'][i] == 'a64':
                mtype = m_info.get_maple_a64_pointer_type(arg_value)
                if not mtype:
                    mtype = ""
            else:
                mtype = ""
        else:
            arg_value = '...'
            mtype = ""
        args_buffer += func_argus_locals['formals_type'][i]
        args_buffer += '<' + mtype + '>'
        args_buffer += ' '
        args_buffer += MColors.BT_ARGNAME + func_argus_locals['formals_name'][i] + MColors.ENDC
        #args_buffer += func_argus_locals['formals_name'][i]
        args_buffer += '='
        args_buffer += arg_value
        args_buffer += ', '
    if arg_num > 0:
        args_buffer = args_buffer[:-2]
    if m_debug.Debug: m_debug.dbg_print("arg_num=", arg_num, " args_buffer=", args_buffer)
    '''

    if mbt_format == MBT_FORMAT_ASM:
        buffer = '#%i %s:%s %s(%s) at %s:%s' % \
           (index, MColors.BT_ADDR + so_path.split('/')[-1] + MColors.ENDC,MColors.BT_ADDR + func_addr_offset + MColors.ENDC,\
             m_util.color_symbol(MColors.BT_FNNAME, func_name), args_buffer, MColors.BT_SRC + asm_path + MColors.ENDC, asm_line_num)
    elif mbt_format == MBT_FORMAT_SRC:
        buffer = '#%i %s:%s %s(%s) at %s:%s' % \
           (index, MColors.BT_ADDR + so_path.split('/')[-1] + MColors.ENDC, MColors.BT_ADDR + func_addr_offset + MColors.ENDC,\
            m_util.color_symbol(MColors.BT_FNNAME, func_name), args_buffer, MColors.BT_SRC + file_full_path + MColors.ENDC, src_file_line)
    else:
        buffer = '#%i %s:%s %s(%s) at %s:%s' % \
           (index, MColors.BT_ADDR + so_path.split('/')[-1] + MColors.ENDC,MColors.BT_ADDR + func_addr_offset + MColors.ENDC,\
             m_util.color_symbol(MColors.BT_FNNAME, func_name), args_buffer, MColors.BT_SRC + mmpl_path + MColors.ENDC, mmpl_line_num)
    gdb_print(buffer)