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
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
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()
def mfinish_func(self, args): frame = m_frame.get_newest_frame() if not frame: return silent_finish() frame = m_frame.get_selected_frame() if m_debug.Debug: m_debug.dbg_print("frame.name()=", frame.name()) m_util.gdb_exec("msi") m_util.gdb_exec("mlist") m_datastore.mgdb_rdata.update_frame_change_counter()
def mdown_func(self, args, from_tty): steps = 1 s = str(args).split() if len(s) is 1: try: steps = int(s[0]) except: pass elif len(s) > 1: self.usage() return selected_frame = m_frame.get_selected_frame() newest_frame = m_frame.get_newest_frame() if not selected_frame or not newest_frame: gdb_print('Unable to locate Maple frame') return # walk through from innermost frame to selected frame # to get the level number from newest frame to selected frame. index = 0 frame = newest_frame while frame != selected_frame and frame: frame = m_frame.get_next_older_frame(frame) index += 1 if not frame: gdb_print('No valid frames found') return prev_maple_frame = frame prev_maple_frame_index = index while frame and steps > 0: frame = m_frame.get_next_newer_frame(frame) if frame: m_util.gdb_exec_to_null('down-silently') index -= 1 else: frame = prev_maple_frame m_util.gdb_exec_to_null('up-silently ' + str(index - prev_maple_frame_index)) index = prev_maple_frame_index break if m_frame.is_maple_frame(frame): prev_maple_frame = frame prev_maple_frame_index = index steps -= 1 print_maple_frame(frame, index, MBT_FORMAT_SRC) m_datastore.mgdb_rdata.update_frame_change_counter()
def display_symbol_detail(symbol_name, symbol_asm_path): if m_debug.Debug: m_debug.dbg_print("symbol_asm_path=", symbol_asm_path, "symbol_name=", symbol_name) if not symbol_name or not symbol_asm_path: return frame = m_frame.get_selected_frame() if not frame: return is_dync = False if m_frame.is_maple_frame_dync(frame): is_dync = True data = m_datastore.mgdb_rdata.get_one_label_mirbin_info_cache( symbol_asm_path, symbol_name) if is_dync == True: d = m_asm.lookup_src_file_info_dync(symbol_asm_path, symbol_name, "0000") else: d = m_asm.lookup_src_file_info(symbol_asm_path, data[0], data[1], data[2], "0000") if not d: return short_src_file_name, short_src_file_line = m_asm.lookup_next_src_file_info(symbol_asm_path,\ d["asm_line"], d['asm_offset']) 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 gdb_print("assembly file : " + symbol_asm_path) if not file_full_path: gdb_print("source : unknown") else: gdb_print("source : " + file_full_path) if is_dync == True: return else: gdb_print("demangled name: " + m_symbol.get_demangled_maple_symbol( m_util.color_symbol(MColors.SP_SNAME, symbol_name[:-12])))
def mbt_func(self, args, from_tty): s = str(args) mbt_format = MBT_FORMAT_SRC full = False if s == "-full" or s == "full": full = True elif s == "-asm": mbt_format = MBT_FORMAT_ASM elif s == "-mir": mbt_format = MBT_FORMAT_MIR selected_frame = m_frame.get_selected_frame() newest_frame = m_frame.get_newest_frame() if not selected_frame or not newest_frame: gdb_print('Unable to locate Maple frame') return # walk through from innermost frame to selected frame index = 0 frame = newest_frame while frame != selected_frame and frame: frame = m_frame.get_next_older_frame(frame) index += 1 if not frame: gdb_print('No valid frames found') return start_level = index gdb_print('Maple Traceback (most recent call first):') while frame: if m_frame.is_maple_frame(frame): print_maple_frame(frame, index, mbt_format) elif full: print_gdb_frame(frame, index) index += 1 frame = m_frame.get_next_older_frame(frame) if frame: m_util.gdb_exec_to_null('up-silently') # move frame back to the original stack level m_util.gdb_exec_to_null('down-silently ' + str(index - start_level - 1))
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'])
def mstepi_common_dync(self, threadno, count): msi_bp_dync_exist, msi_bp_dync_id = is_msi_bp_dync_existed() if not msi_bp_dync_exist: # there is no msi bp exist, so just create a new msi breakpoint self.init_gdb_breakpoint(threadno, count, False, True) else: if msi_bp_dync_id != self.msi_bp_dync_id: # if existing msi bp id does not match to self.msi_bp_id gdb_print( "There are one or more breakpints already created at __inc_opcode_cnt_dyn\n" "In order to use mstepi command, please delete those breakpoints first\n" ) return None else: # the existing msi bp id matches to self.msi_bp_id, it was created # by mstepi command previously. if self.msi_bp_dync_id.enabled is False: enable_msi_bp_dync() self.mbp_dync_object.set_bp_attr('thread', threadno) self.mbp_dync_object.set_bp_attr('count', count) assert count > 0 if self.mbp_dync_object.ignore_count != count - 1: self.mbp_dync_object.ignore_count = count - 1 hitcnt = self.mbp_dync_object.hit_count # It is important to perform a continue command here for the msi breakpoint # to be reached. m_util.gdb_exec("continue") """ if the msi breakpoint's count reaches to 1, it will return True to cause gdb stop at msi breakpoint by previous 'continue' command. Once gdb stops here, a gdb 'finish' command shall be called. However, 'finish' command must NOT be called inside of msi breakpoint stop() logic """ frame = None if self.mbp_dync_object.hit_count - hitcnt == count: """ if gdb stops here, it must have hit one breakpoint. However. the breakpoint it hits may not be the msi breakpoint, it could be another breakpoint the user set up. In this case, we check if it is a Maple frame. If it is, then the breakpoint is ours. Otherwise just stop here and return because it hit a user's other stop. """ frame = m_frame.get_selected_frame() if not frame: return None if not m_frame.is_maple_frame(frame): if m_set.msettings['opcode'] == 'on': m_util.gdb_exec("finish") else: silent_finish() # now get the new selected frame frame = m_frame.get_selected_frame() if not frame: return None # 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() # always disable msi breakpoint after msi is excuted disable_msi_bp_dync() return frame