示例#1
0
文件: eo_gdb.py 项目: caivega/efl-1
   def invoke (self, arg, from_tty):
      # While libeo is not reached, we step into
      while gdb.solib_name(gdb.selected_frame().pc()).find("libeo.so") == -1:
         # step by one assembly instruction, no print
         gdb.execute("stepi", False, to_string=True)

      # While we are in libeo or in an unknown function, we step into
      while (gdb.selected_frame().function() == None) or (gdb.solib_name(gdb.selected_frame().pc()).find("libeo.so") != -1):
         # step by one assembly instruction, no print
         gdb.execute("stepi", False, to_string=True)

      print "Stopped at file " + gdb.selected_frame().find_sal().symtab.filename+ " line " + str(gdb.selected_frame().find_sal().line) + " function " + str(gdb.selected_frame().function())
示例#2
0
    def invoke(self, arg, from_tty):
        # While libeo is not reached, we step into
        while gdb.solib_name(gdb.selected_frame().pc()).find("libeo.so") == -1:
            # step by one assembly instruction, no print
            gdb.execute("stepi", False, to_string=True)

        # While we are in libeo or in an unknown function, we step into
        while (gdb.selected_frame().function() == None) or (gdb.solib_name(
                gdb.selected_frame().pc()).find("libeo.so") != -1):
            # step by one assembly instruction, no print
            gdb.execute("stepi", False, to_string=True)

        print "Stopped at file " + gdb.selected_frame().find_sal(
        ).symtab.filename + " line " + str(
            gdb.selected_frame().find_sal().line) + " function " + str(
                gdb.selected_frame().function())
示例#3
0
 def stop(self):
     frame = gdb.selected_frame()
     while frame != None:
         frame = frame.older()
         prevAddr = frame.pc()
         prevLibname = gdb.solib_name(prevAddr)
         if prevLibname in self.libnames:
             return False
     return True
示例#4
0
    def describe (self, frame_num, mode, args=True):
        if self.syn_frames:
            for syn_frame in self.syn_frames:
                pout('{s} JS {jfn}%s {.48}{s}at {cn}%s{s}:{ln}%d {s}%010x{-fg}',
                     syn_frame.func_name,
                     syn_frame.filename,
                     #self.context.chewPath(syn_frame.filename) or '???',
                     syn_frame.line,
                     syn_frame.pc)

        if not self.show_me:
            return

        if self.frame.type () == gdb.DUMMY_FRAME:
            pout('{s}%2.2d <function called from gdb>{-fg}', frame_num)
        elif self.frame.type () == gdb.SIGTRAMP_FRAME:
            pout('{s}%2.2d <signal handler called>{-fg}', frame_num)
        else:
            sal = self.frame.find_sal ()
            pc = self.frame.pc ()
            name = self.frame.name ()
            if not name:
                name = "??"
            if name.startswith('mozilla::'):
                name = name[9:]

            if not name or (not sal.symtab or not sal.symtab.filename):
                lib = gdb.solib_name (pc)
                if lib:
                    # stream.write (" from " + lib)
                    pass

            if mode == MODE_TERSE:
                pout('{s}%3.3d {fn}%s{s}:{ln}%d{-fg}',
                     frame_num, name, sal.line)
            elif mode == MODE_PASTE:
                pout('{s}%3.3d {fn}%s{-fg}\n    {cn}%s{s}:{ln}%d{-fg}',
                     frame_num, name,
                     sal.symtab and sal.symtab.filename and self.context.chewPath(sal.symtab.filename) or '???',
                     sal.line)
            else:
                pout('{s}%3.3d {fn}%s {.48}{s}at {cn}%s{s}:{ln}%d {s}%010x{-fg}',
                     frame_num, name,
                     sal.symtab and sal.symtab.filename and self.context.chewPath(sal.symtab.filename) or '???',
                     sal.line, pc)
                pout.i(6)
                if args:
                    self.print_frame_args(self.block)

                if mode == MODE_FULL:
                    if not args:
                        block = self.frame.block()
                    self.print_frame_locals(self.block)
                pout.i(-6)
示例#5
0
def is_bp_in_urts():
    try:
        ip = gdb.parse_and_eval("$pc")
        solib_name = gdb.solib_name(int(str(ip).split()[0], 16))
        if(solib_name.find("libsgx_urts.so") == -1 and solib_name.find("libsgx_urts_sim.so") == -1 and solib_name.find("libsgx_aesm_service.so") == -1):
            return False
        else:
            return True
    #If exception happens, just assume it is bp in uRTS.
    except:
        return True
示例#6
0
def is_bp_in_urts():
    try:
        ip = gdb.parse_and_eval("$pc")
        solib_name = gdb.solib_name(int(str(ip).split()[0], 16))
        if(solib_name.find("libsgx_urts.so") == -1 and solib_name.find("libsgx_urts_sim.so") == -1 and solib_name.find("libsgx_aesm_service.so") == -1):
            return False
        else:
            return True
    #If exception happens, just assume it is bp in uRTS.
    except:
        return True
示例#7
0
 def invoke(self, arg_string, from_tty):
     args = arg_string.split()
     if args[0] == "whichlib":
         try:
             addr = int(args[1], 16)
             print(gdb.solib_name(addr))
         except:
             pass
     elif args[0] == "breakignorelib":
         ConditionalLibBreakpoint(args[1], args[2:])
     elif args[0] == "breakignorepc":
         ConditionalPCBreakpoint(args[1], args[2:])
示例#8
0
文件: stack.py 项目: wadoon/gdb-gui
def format_frame(frame):
    result = {}
    result["name"] = frame.function()
    result["filename"] = frame.filename()
    result["pc"] = frame.address()
    result["line"] = frame.line()
    elided = frame.elided()
    if elided is not None:
        elided = list(map(format_frame, elided))
    result["elided"] = elided
    # Not quite what we want...
    result["solib"] = gdb.solib_name(frame.address())
    return result
    def filename(self):
        """ Return the filename associated with this frame, detecting
        and returning the appropriate library name is this is a shared
        library."""

        if hasattr(self._base, "filename"):
            return self._base.filename()

        frame = self.inferior_frame()
        sal = frame.find_sal()
        if not sal.symtab or not sal.symtab.filename:
            pc = frame.pc()
            return gdb.solib_name(pc)
        else:
            return sal.symtab.filename
示例#10
0
    def filename(self):
        """ Return the filename associated with this frame, detecting
        and returning the appropriate library name is this is a shared
        library."""

        if hasattr(self._base, "filename"):
            return self._base.filename()

        frame = self.inferior_frame()
        sal = frame.find_sal()
        if not sal.symtab or not sal.symtab.filename:
            pc = frame.pc()
            return gdb.solib_name(pc)
        else:
            return sal.symtab.filename
示例#11
0
    def next(self):
        frame = next(self.frame_iter)

        args = frame.frame_args()
        if args:
            for arg in args:
                symbol = arg.symbol()
                if symbol.type.code == gdb.TYPE_CODE_PTR and symbol.type.target().name == "QV4::ExecutionContext":
                    self.execution_context = symbol.value(frame.inferior_frame())

        if self.qml_frame_found:
            return NullFrameDecorator()

        # First QML frame has PC pointing to an anonymous memory area (not
        # backed by any .so file).
        if gdb.solib_name(frame.inferior_frame().pc()) is None and self.execution_context != 0:
            self.qml_frame_found = True
            return FinalFrameDecorator(frame, self.execution_context)

        return frame
示例#12
0
 def __str__(self):
     # adjust pc according to ARM/THUMB mode
     pc = self.pc & (~1) if self.is_thumb else self.pc & (~3)
     try:
         block = gdb.block_for_pc(pc)
     except RuntimeError:
         block = None
     if block and block.is_valid() and block.function:
         func = block.function.print_name
     else:
         func = gdb.execute('info symbol ' + hex(pc), True, True).strip()
         if func.startswith('No symbol'):
             func = '??'
     for sep in ['(', '+', 'in section']:
         if sep in func:
             func = func[:func.find(sep)].strip()
             break
     lib = gdb.solib_name(pc)
     lib = os.path.basename(lib) if lib else '??'
     return 'frame {0:#08x} in function {1} ({2:#08x}) from {3}'.format(
         self.sp, func, pc, lib)
示例#13
0
 def __str__(self):
     # adjust pc according to ARM/THUMB mode
     pc = self.pc & (~1) if self.is_thumb else self.pc & (~3)
     try:
         block = gdb.block_for_pc(pc)
     except RuntimeError:
         block = None
     if block and block.is_valid() and block.function:
         func = block.function.print_name
     else:
         func = gdb.execute('info symbol ' + hex(pc), True, True).strip()
         if func.startswith('No symbol'):
             func = '??'
     for sep in ['(', '+', 'in section']:
         if sep in func:
             func = func[: func.find(sep)].strip()
             break
     lib = gdb.solib_name(pc)
     lib = os.path.basename(lib) if lib else '??'
     return 'frame {0:#08x} in function {1} ({2:#08x}) from {3}'.format(
             self.sp, func, pc, lib)
示例#14
0
	def print_best_frame(self, tid):
		frame = gdb.newest_frame()
		i = 0

		while not frame is None:
			pc = frame.pc()
			solib = gdb.solib_name(pc)
			#if pc >= 0x400000 and pc <= 0x42b000:
			if solib is None:
				sal = frame.find_sal()
				symtab = sal.symtab
				func = frame.function()
				print("{: <4} {:<3} {:<30} {}:{}".format(
					tid, i,
					color(COL_YELLOW, func) + "()",
					symtab.filename,
					color(COL_GREEN, sal.line),
				))
				break
			frame = frame.older()
			i+=1
示例#15
0
def event_breakpoint_created_handler(bp):
    """event handler to handle breakpoint creation
       if a native breakpoint is created in Maple shared library program space,
       delete this breakpoint or disable it
    """
    if isinstance(bp, m_stepi.MapleFinishBreakpoint):
        return

    if bp.location == "maple::maple_invoke_method" or bp.location == "__inc_opcode_cnt" \
       or bp.location == "maple::InvokeInterpretMethod" or bp.location == "__inc_opcode_cnt_dyn":
        return

    if not m_inf.is_inferior_running():
        return

    try:
        result_value = gdb.parse_and_eval(bp.location)
    except:
        # breakpoint symbol not found in program space, so it is not a valid breakpoint
        return

    so_name = gdb.solib_name(int(result_value.address))
    if not so_name:  # this happens to be at very beginning before all the shared libraries are loaded
        return

    so_name = os.path.realpath(so_name)
    asm_name_1 = so_name[:-3] + '.s'
    asm_name_2 = so_name[:-3] + '.VtableImpl.s'

    asm_list = m_info.get_loaded_lib_asm_path()
    if asm_name_1 in asm_list or asm_name_2 in asm_list:
        bploc = '%s%s%s' % (MColors.BP_ADDR, bp.location, MColors.ENDC)
        # this means this breakpoint's address is in Maple Engine loaded shared library
        gdb_print("Warning: It is not allowed to set a gdb breakpoint at %s in Maple shared library %s%s%s" % \
            (bploc, MColors.BT_SRC, so_name.split('/')[-1], MColors.ENDC))
        bp.delete()
        gdb_print(
            "This gdb breakpoint at %s was deleted. Please set a Maple breakpoint with a 'mbreak' command"
            % bploc)
示例#16
0
def bt(demangle=True):
    # Find the newest frame.
    frame = gdb.selected_frame()
    while True:
        next = frame.newer()
        if not next:
            break
        frame = next

    if demangle:
        pipe = os.popen('c++filt', 'w')
    else:
        pipe = sys.stdout

    i = 0
    while frame:
        s = gdb.execute('p dumpSymbol((void*)0x%x)' % frame.pc(),
                        to_string=True)
        m = re.match(r'.*"(.*)"$', s)
        if m:
            pipe.write("#%-2d %s\n" % (i, m.group(1)))
        else:
            sal = frame.find_sal()
            lineno = ''
            if sal.symtab:
                lineno = 'at %s:%d' % (sal.symtab, sal.line)
            else:
                soname = gdb.solib_name(frame.pc())
                if soname:
                    lineno = 'from %s' % (soname)
            framename = frame.name()
            if not framename:
                framename = '??'
            pipe.write("#%-2d 0x%016x in %s () %s\n" %
                       (i, frame.pc(), framename, lineno))
        frame = frame.older()
        i += 1

    pipe.close()
示例#17
0
    def next(self):
        frame = next(self.frame_iter)

        args = frame.frame_args()
        if args:
            for arg in args:
                symbol = arg.symbol()
                if symbol.type.code == gdb.TYPE_CODE_PTR and \
                   symbol.type.target().name == "QV4::ExecutionContext":
                    self.execution_context = symbol.value(
                        frame.inferior_frame())

        if self.qml_frame_found:
            return NullFrameDecorator()

        # First QML frame has PC pointing to an anonymous memory area (not
        # backed by any .so file).
        if gdb.solib_name(frame.inferior_frame().pc()) is None and \
           self.execution_context != 0:
            self.qml_frame_found = True
            return FinalFrameDecorator(frame, self.execution_context)

        return frame
示例#18
0
    def filter(self, frame_iter):
        for frame in frame_iter:
            address = frame.address()
            libName = gdb.solib_name(address)
            if libName == None:
                yield frame
                continue

            absoluteAddress = 0
            shared = gdb.execute("info shared", False, True)
            for line in shared.split('\n'):
                cols = line.split()
                try:
                    int(cols[0], 16)
                except:
                    continue

                # Sooo ugly but the output is fixed lenght.
                # This way we can support paths with spaces as well.
                name = line[36:]

                if name != libName:
                    continue

                libStart = int(cols[0], 16)
                absoluteAddress = address - libStart + \
                    self.getTextOffset(libName)

                break

            filename_orig = frame.filename()
            if libName != filename_orig:
                filename_orig = "%s @ %s" % (os.path.basename(libName),
                                             filename_orig)
            frame.filename = lambda: "0x%08x in %s" % (absoluteAddress,
                                                       filename_orig)
            yield frame
示例#19
0
文件: JsDbg.py 项目: cbiesinger/JsDbg
def ModuleForAddress(pointer):
    module = gdb.solib_name(pointer)
    if not module:
        # If it exists, it's in the main binary
        module = gdb.current_progspace().filename
    return JsDbgBase.FormatModule(module)
示例#20
0
def get_dync_lib_so_info(addr):
    """
    for a given Maple method address, look up the lib so file, and get informations
    about the so library and its co-responding asm file info.

    params:
      addr: address of a method in hex string with prefix '0x', i.e 0x7fff6021c308

    returns:
      1, so lib start address: int
      2, lib so file full path in string
      3, lib asm file full path in string
      4, lib mpl.mir.mpl file full path in string
    """
    a = int(addr, 0)

    buf = get_info_proc_mapping()
    start = None
    end = None
    path = None
    so_path = None
    asm_path = None
    mirmpl_path = None
    for (hexstart, hexend, path) in re.findall(proc_mapping_re, buf):
        try:
            start = int(hexstart, 16)
        except:
            start = None
        try:
            end = int(hexend, 16)
        except:
            end = None
        if not start or not end or not path:
            continue

        if a >= start and a <= end:
            if not path.rstrip().lower().endswith('.so'):
                if m_debug.Debug: m_debug.dbg_print("path does not end with .so, path = ", path)
                return None, None, None, None
            so_path = path.rstrip().replace('/./','/')
            if m_debug.Debug: m_debug.dbg_print("gdb.solib_name(addr)=", gdb.solib_name(a))
            mmpl_path = so_path[:-3] + '.mmpl'
            mmpl_path = os.path.realpath(mmpl_path)
            asm_path = so_path[:-3] + '.s'
            asm_path = os.path.realpath(asm_path)
            if os.path.exists(so_path) and os.path.exists(asm_path) and os.path.exists(mmpl_path):
                # both .so file and co-responding .s file exist in same directory
                if m_debug.Debug: m_debug.dbg_print("return lib info: start=", start, "so_path=",so_path,\
                                                    "asm_path=", asm_path, "mmpl_path=", mmpl_path)
                return start, so_path, asm_path, mmpl_path

            so_path_short_name = so_path.split('/')[-1][:-3]

            if not 'maple_lib_asm_path' in m_set.msettings:
                return None, None, None, None
            for v in m_set.msettings['maple_lib_asm_path']:
                mmpl_path = v + '/'+ so_path_short_name + '.mmpl'
                mmpl_path = os.path.realpath(mirmpl_path)
                asm_path = v + '/' + so_path_short_name + '.s'
                asm_path = os.path.realpath(asm_path)
                #asm_path = path.split('maple/out')[0] + 'maple/out/common/share/' + so_path_short_name + '.VtableImpl.s'
                if os.path.exists(so_path) and os.path.exists(asm_path) and os.path.exists(mmpl_path):
                    # .s file is in the search path list
                    if m_debug.Debug:
                        m_debug.dbg_print("return lib info: start=", start, "so_path=",so_path, \
                                          "asm_path=", asm_path, "mmpl_path", mmpl_path)
                    return start, so_path, asm_path, mmpl_path

            return None, None, None, None
    return None, None, None, None
示例#21
0
    def invoke(self, arg, from_tty):
        parser = argparse.ArgumentParser(fromfile_prefix_chars='@')
        parser.add_argument(
            "--include-symbols",
            action="store_true",
            help=
            "include symbol section like one generated by google-pprof in raw profile mode"
        )
        parser.add_argument(
            "--core-maps-from-info-files",
            action="store_true",
            help=
            "build objects map from the command 'info files' output. This is the default beaviour"
        )
        parser.add_argument(
            "--core-maps-from-info-proc-mapping",
            action="store_true",
            help="build objects map from the command 'info proc mapping' output"
        )
        parser.add_argument("--core-maps-from-file",
                            action="store",
                            help="read objects map from the specified file")
        parser.add_argument("--core-maps-from-command",
                            action="store",
                            help="read objects map from the specified command")
        parser.add_argument("--output",
                            action="store",
                            help="output profile file")
        parser.add_argument(
            "threads",
            nargs=argparse.REMAINDER,
            help="threads to focus on. All threads will be included by default"
        )
        opts = parser.parse_args(gdb.string_to_argv(arg))

        inferior = gdb.selected_inferior()
        if not inferior:
            return

        selected_thread = gdb.selected_thread()
        selected_frame = gdb.selected_frame()
        if not selected_frame:
            return

        dump = None
        if opts.output:
            dump = self.ProfileDump(opts.output, opts.include_symbols,
                                    selected_frame.architecture())
        else:
            dump = self.StdoutDump()

        core_maps = None
        core_binary = self.ExeFromInfoProc()
        if opts.core_maps_from_info_proc_mapping:
            core_maps = self.MapsFromInfoProcMappingCommand()
        if opts.core_maps_from_file:
            core_maps = self.MapsFromFile(opts.core_maps_from_file)
        if opts.core_maps_from_command:
            core_maps = self.MapsFromCommand(opts.core_maps_from_command)
        if not core_maps or opts.core_maps_from_info_files:
            core_maps = self.MapsAndExeFromInfoFilesCommand()
            core_binary = core_maps

        if opts.threads:
            threads = self.ThreadsToFocusOn(opts.threads, inferior)
        else:
            threads = inferior.threads()
        for thread in threads:
            lwpid = thread.ptid[1]
            if not lwpid:
                lwpid = thread.ptid[2]
            dump.add_thread(thread.num, lwpid, thread.name)
            thread.switch()
            frame = gdb.newest_frame()
            while None != frame:
                addr = frame.pc()
                fun = frame.function()
                symbol_name = ''
                if fun:
                    sal = frame.find_sal()
                    if sal:
                        symbol_name = '{} at {}:{}'.format(
                            fun.print_name, sal.symtab.filename, sal.line)
                    else:
                        symbol_name = '{} at {}:{}'.format(
                            fun.print_name, fun.symtab.filename, fun.line)
                else:
                    symbol_info = gdb.execute(
                        "info symbol 0x{:x}".format(addr), False, True)
                    if symbol_info:
                        match = re.match(
                            '(\S+)\s+[+]\s+([0-9A-Fa-f]+)\s+in\s+section\s+([.]\S+)\s+of\s+([/].+)',
                            symbol_info)
                        if match:
                            symbol_name = '{} at {}:??'.format(
                                match.group(1), match.group(4))
                        else:
                            symbol_name = '?? at {}:??'.format(
                                gdb.solib_name(addr))

                dump.add_frame(addr, symbol_name, frame.type())
                frame = frame.older()

        selected_thread.switch()
        selected_frame.select()

        self.__write_list_of_mapped_objects(dump, core_maps, core_binary,
                                            inferior)