Exemple #1
0
def Main():
    cgiEnv = lib_common.ScriptEnvironment()
    pid = int(cgiEnv.GetId())

    grph = cgiEnv.GetGraph()

    proc_node = lib_uris.gUriGen.PidUri(pid)

    rem_sta = _get_remote_stack(pid)

    if rem_sta:
        call_node_prev = None

        # Typical result:
        # [
        #     ["/home/jsmith/survol/tests/SampleDirScripts/SampleSqlFile.py", 17, "<module>", "xx = sys.stdin.read(1)"],
        #     ["<string>", 1, "<module>", null],
        #     ["/tmp/tmpIcWP2j.py", 9, "<module>", "retobj = traceback.extract_stack()"]
        # ]
        for st in rem_sta:
            # == File=../essai.py line=6 module=<module>
            # == File=<string> line=1 module=<module>
            # == File=/tmp/tmpw14tgJ.py line=9 module=<module>
            logging.debug("File=%s line=%d module=%s", st[0], st[1], st[2])

            short_fil_nam = st[0]
            if short_fil_nam == "<string>":
                short_fil_nam = None
            line_number = st[1]
            module_nam = st[2]
            if module_nam == "<module>":
                module_nam = None

            # TODO: What is the full path name ?
            file_name = short_fil_nam
            func_name = module_nam

            if func_name is None:
                # Maybe an intermediate call
                if file_name is None:
                    logging.debug("Intermediate call")
                    continue
                # Maybe the main program ?
                func_name = "__main__"

            # TODO: At each stage, should add the variables defined in each function call.

            # See process_gdbstack.py
            call_node_prev = survol_symbol.AddFunctionCall(
                grph, call_node_prev, proc_node, func_name, file_name,
                line_number)

            if not call_node_prev:
                break
    else:
        logging.warning("No stack visible")

    cgiEnv.OutCgiRdf()
Exemple #2
0
def Main():
    cgiEnv = lib_common.CgiEnv()
    pid = int( cgiEnv.GetId() )

    grph = cgiEnv.GetGraph()

    procNode = lib_common.gUriGen.PidUri(pid)

    remSta = GetRemoteStack(pid)

    if remSta:
        callNodePrev = None

        # Typical result:
        # [
        #     ["/home/rchateau/survol/tests/AnotherSampleDir/SampleSqlFile.py", 17, "<module>", "xx = sys.stdin.read(1)"],
        #     ["<string>", 1, "<module>", null],
        #     ["/tmp/tmpIcWP2j.py", 9, "<module>", "retobj = traceback.extract_stack()"]
        # ]
        for st in remSta:
            # == File=../essai.py line=6 module=<module>
            # == File=<string> line=1 module=<module>
            # == File=/tmp/tmpw14tgJ.py line=9 module=<module>
            DEBUG("File=%s line=%d module=%s", st[0], st[1], st[2] )

            shortFilNam = st[0]
            if shortFilNam == "<string>":
                shortFilNam = None
            lineNumber = st[1]
            moduleNam = st[2]
            if moduleNam == "<module>":
                moduleNam = None

            # TODO: What is the full path name ?
            fileName = shortFilNam
            funcName = moduleNam

            if funcName is None:
                # Maybe an intermediate call
                if fileName is None:
                    DEBUG("Intermediate call")
                    continue
                # Maybe the main program ?
                funcName = "__main__"

            # TODO: At each stage, should add the variables defined in each function call.

            # See process_gdbstack.py
            callNodePrev = survol_symbol.AddFunctionCall( grph, callNodePrev, procNode, funcName, fileName, lineNumber )

            if not callNodePrev:
                break
    else:
        WARNING("No stack visible")


    cgiEnv.OutCgiRdf()
def Main():
    cgiEnv = lib_common.CgiEnv()
    pid = int( cgiEnv.GetId() )

    grph = cgiEnv.GetGraph()

    procNode = lib_common.gUriGen.PidUri(pid)

    remSta = GetRemoteStack(pid)

    if remSta:
        callNodePrev = None

        for st in remSta:
            # == fichier=../essai.py line=6 module=<module>
            # == fichier=<string> line=1 module=<module>
            # == fichier=/tmp/tmpw14tgJ.py line=9 module=<module>
            sys.stderr.write("== fichier=%s line=%d module=%s\n" % ( st[0], st[1], st[2] ) )

            shortFilNam = st[0]
            lineNumber = st[1]
            moduleNam = st[2]

            # TODO: What is the full path name ?
            fileName = shortFilNam
            funcName = moduleNam

            # TODO: At each stage, should add the variables defined in each function call.

            # See process_gdbstack.py
            callNodePrev = survol_symbol.AddFunctionCall( grph, callNodePrev, procNode, funcName, fileName, lineNumber )

            if not callNodePrev:
                break
    else:
        sys.stderr.write("No stack visible\n")


    cgiEnv.OutCgiRdf()
Exemple #4
0
def CallParse(execName, grph, procNode, callNodePrev, lin):
    # TODO: See the content of the parenthesis. Can it be the arguments?

    funcName = None
    fileName = None

    # #5  0xb6f8007c in QApplication::exec () from /usr/lib/qt3/lib/libqt-mt.so.3
    mtch_call_lib = re.match(
        r"^#[0-9]+ +0x[0-9a-f]+ in ([^ ]+) \([^)]*\) from (.*)$", lin)
    if mtch_call_lib:
        funcName = mtch_call_lib.group(1)
        fileName = mtch_call_lib.group(2)
    else:
        # #8  0x0804ebe9 in QGList::~QGList$delete ()
        mtch_call_lib = re.match(
            r"^#[0-9]+ +0x[0-9a-f]+ in ([^ ]+) \([^)]*\)$", lin)
        if mtch_call_lib:
            funcName = mtch_call_lib.group(1)
            fileName = execName

    # TODO: Should add the address or the line number as last parameter.
    return survol_symbol.AddFunctionCall(grph, callNodePrev, procNode,
                                         funcName, fileName)
def Main():
    cgiEnv = lib_common.ScriptEnvironment()
    try:
        the_pid = int(cgiEnv.GetId())
    except Exception:
        lib_common.ErrorMessageHtml("Must provide a pid")

    # If cannot be the current pid, otherwise it will block.
    if the_pid == os.getpid():
        lib_common.ErrorMessageHtml("Cannot debug current process")

    if not lib_util.isPlatformWindows:
        lib_common.ErrorMessageHtml("This works only on Windows platforms")

    grph = cgiEnv.GetGraph()

    # Starts a second session
    cdb_fil = lib_util.TmpFile("CdbCommand", "cdb")
    cdb_fd = open(cdb_fil.Name, "w")
    cdb_fd.write("lm\n")  # List loaded modules
    cdb_fd.write("k\n")   # Display stack backtrace.
    cdb_fd.write("qd\n")  # Quit and detach.
    cdb_fd.close()

    cdb_cmd = "cdb -p " + str(the_pid) + " -cf " + cdb_fil.Name

    proc_node = lib_uris.gUriGen.PidUri(the_pid)
    call_node_prev = None

    modules_map = {}

    logging.debug("Starting cdb_cmd=%s", cdb_cmd)
    try:
        cdb_pipe = lib_common.SubProcPOpen(cdb_cmd)
    except WindowsError as exc:
        lib_common.ErrorMessageHtml("cdb not available: Caught:%s" % str(exc))

    logging.debug("Started cdb_cmd=%s", cdb_cmd)

    cdb_output, cdb_err = cdb_pipe.communicate()

    # Without decode, "TypeError: Type str does not support the buffer API"
    cdb_str = cdb_output.decode("utf-8")

    call_depth = 0

    for dot_line in cdb_str.split('\n'):
        err_match = re.match(".*parameter is incorrect.*", dot_line)
        if err_match:
            lib_common.ErrorMessageHtml("CDB:"+dot_line)

        # 76590000 766a0000   kernel32   (export symbols)       C:\Windows\syswow64\kernel32.dll
        match_lm = re.match(r"[0-9a-fA-F]+ [0-9a-fA-F]+ +([^ ]*) +\(export symbols\) +(.*)", dot_line )
        if match_lm:
            module_name = match_lm.group(1)
            dll_name_raw = match_lm.group(2).strip()
            dll_name = lib_util.standardized_file_path(dll_name_raw)
            logging.debug("module_name=%s dll_name=%s", module_name, dll_name)
            modules_map[module_name] = dll_name
            continue

        # 295cfb0c 00000000 ntdll!RtlInitializeExceptionChain+0x36
        # Another format, maybe because of a 64 bits machine.
        # 00000000`02edff90 00000000`00000000 ntdll!RtlUserThreadStart+0x21
        match_k = re.match("[`0-9a-fA-F]+ [`0-9a-fA-F]+ ([^!]*)!([^+]*)", dot_line)
        if match_k:
            module_name = match_k.group(1)
            try:
                dll_name = modules_map[module_name]
            except KeyError:
                dll_name = module_name
            func_name = match_k.group(2).strip()
            logging.debug("module_name=%s dll_name=%s func_name=%s", module_name, dll_name, func_name)

            dll_name = CDB.TestIfKnownDll(dll_name)

            call_node_prev = survol_symbol.AddFunctionCall(grph, call_node_prev, proc_node, func_name, dll_name)
            grph.add((call_node_prev, lib_properties.MakeProp("Call_depth"), lib_util.NodeLiteral(call_depth)))
            call_depth += 1
            continue

        logging.debug("dot_line=%s", dot_line)

    logging.debug("Parsed cdb result")

    call_node_prev = survol_symbol.AddFunctionCall(grph, call_node_prev, proc_node, None, None)

    CIM_Process.AddInfo(grph, proc_node, [the_pid])

    # http://msdn.microsoft.com/en-us/library/windows/hardware/ff539058(v=vs.85).aspx
    #
    # This section describes how to perform basic debugging tasks using
    # the Microsoft Console Debugger (CDB) and Microsoft NT Symbolic Debugger (NTSD).
    # CDB and NTSD are identical in every way, except that NTSD spawns
    # a new text window when it is started, whereas CDB inherits
    # the Command Prompt window from which it was invoked.
    # The instructions in this section are given for CDB,
    # but they work equally well for NTSD. For a discussion
    # of when to use CDB or NTSD, see Debugging Environments.

    cgiEnv.OutCgiRdf("LAYOUT_SPLINE")