예제 #1
0
 def _fThreadExceptionHandler(oCdbWrapper, oException, oExceptionThread):
   # Wait for the exception thread to terminate and then clean up.
   oExceptionThread.join();
   oCdbProcess = getattr(oCdbWrapper, "oCdbProcess", None);
   if not oCdbProcess:
     oCdbWrapper.bCdbRunning = False;
     return;
   if oCdbProcess.poll() is not None:
     oCdbWrapper.bCdbRunning = False;
     return;
   oCdbWrapper.bCdbWasTerminatedOnPurpose = True;
   # cdb is still running: try to terminate cdb the normal way.
   try:
     oCdbProcess.terminate();
   except:
     pass;
   else:
     oCdbWrapper.bCdbRunning = False;
     return;
   if oCdbProcess.poll() is not None:
     oCdbWrapper.bCdbRunning = False;
     return;
   # cdb is still running: try to terminate cdb the hard way.
   oKillException = None;
   try:
     fKillProcessesUntilTheyAreDead([oCdbProcess.pid]);
   except Exception, oException:
     oKillException = oException;
예제 #2
0
 def _fThreadExceptionHandler(oCdbWrapper, oException, oExceptionThread):
     # Wait for the exception thread to terminate and then clean up.
     oExceptionThread.join()
     oCdbProcess = getattr(oCdbWrapper, "oCdbProcess", None)
     if not oCdbProcess:
         oCdbWrapper.bCdbRunning = False
         return
     if oCdbProcess.poll() is not None:
         oCdbWrapper.bCdbRunning = False
         return
     oCdbWrapper.bCdbWasTerminatedOnPurpose = True
     # cdb is still running: try to terminate cdb the normal way.
     try:
         oCdbProcess.terminate()
     except:
         pass
     else:
         oCdbWrapper.bCdbRunning = False
         return
     if oCdbProcess.poll() is not None:
         oCdbWrapper.bCdbRunning = False
         return
     # cdb is still running: try to terminate cdb the hard way.
     oKillException = None
     try:
         fKillProcessesUntilTheyAreDead([oCdbProcess.pid])
     except Exception, oException:
         oKillException = oException
def cCdbWrapper_fCdbCleanupThread(oCdbWrapper):
    # wait for debugger thread to terminate.
    oCdbWrapper.oCdbStdInOutThread.join()
    # wait for stderr thread to terminate.
    oCdbWrapper.oCdbStdErrThread.join()
    # Terminate the cdb process in case it somehow is still running.
    oCdbWrapper.oCdbProcess.terminate()
    # Make sure all stdio pipes are closed.
    oCdbWrapper.oCdbProcess.stdout.close()
    oCdbWrapper.oCdbProcess.stderr.close()
    oCdbWrapper.oCdbProcess.stdin.close()
    # Wait for the cdb process to terminate
    uExitCode = oCdbWrapper.oCdbProcess.wait()
    # Destroy the subprocess object to make even more sure all stdio pipes are closed.
    del oCdbWrapper.oCdbProcess
    # Determine if the debugger was terminated or if the application terminated. If not, an exception is thrown later, as
    # the debugger was not expected to stop, which is an unexpected error.
    bTerminationWasExpected = oCdbWrapper.bCdbWasTerminatedOnPurpose or len(
        oCdbWrapper.auProcessIds) == 0
    # It was originally assumed that waiting for the cdb process to terminate would mean all process being debugged would
    # also be terminated. However, it turns out that if the application terminates, cdb.exe reports that the last process
    # is terminated while that last process is still busy terminating; the process still exists according to the OS.
    if oCdbWrapper.uLastProcessId:
        fKillProcessesUntilTheyAreDead([oCdbWrapper.uLastProcessId])
    # There have also been cases where processes associated with an application were still running after this point in
    # the code. I have been unable to determine how this could happen but in an attempt to fix this, all process ids that
    # should be terminated are killed until they are confirmed they have terminated:
    if oCdbWrapper.auProcessIds:
        fKillProcessesUntilTheyAreDead(oCdbWrapper.auProcessIds)
    if not bTerminationWasExpected:
        oCdbWrapper.oBugReport = cBugReport_CdbTerminatedUnexpectedly(
            oCdbWrapper, uExitCode)
    oCdbWrapper.fFinishedCallback and oCdbWrapper.fFinishedCallback(
        oCdbWrapper.oBugReport)
def cCdbWrapper_fCdbCleanupThread(oCdbWrapper):
  # wait for debugger thread to terminate.
  oCdbWrapper.oCdbDebuggerThread.join();
  # wait for stderr thread to terminate.
  oCdbWrapper.oCdbStdErrThread.join();
  # Terminate the cdb process in case it somehow is still running.
  oCdbWrapper.oCdbProcess.terminate();
  # Make sure all stdio pipes are closed.
  oCdbWrapper.oCdbProcess.stdout.close();
  oCdbWrapper.oCdbProcess.stderr.close();
  oCdbWrapper.oCdbProcess.stdin.close();
  # Wait for the cdb process to terminate
  oCdbWrapper.oCdbProcess.wait();
  # Destroy the subprocess object to make even more sure all stdio pipes are closed.
  del oCdbWrapper.oCdbProcess;
  # Determine if the debugger was terminated or if the application terminated. If not, an exception is thrown later, as
  # the debugger was not expected to stop, which is an unexpected error.
  bTerminationWasExpected = oCdbWrapper.bCdbWasTerminatedOnPurpose or len(oCdbWrapper.auProcessIds) == 0;
  # It was originally assumed that waiting for the cdb process to terminate would mean all process being debugged would
  # also be terminated. However, it turns out that if the application terminates, cdb.exe reports that the last process
  # is terminated while that last process is still busy terminating; the process still exists according to the OS.
  if oCdbWrapper.uLastProcessId:
    fKillProcessesUntilTheyAreDead([oCdbWrapper.uLastProcessId]);
  # There have also been cases where processes associated with an application were still running after this point in
  # the code. I have been unable to determine how this could happen but in an attempt to fix this, all process ids that
  # should be terminated are killed until they are confirmed they have terminated:
  if oCdbWrapper.auProcessIds:
    fKillProcessesUntilTheyAreDead(oCdbWrapper.auProcessIds);
  assert bTerminationWasExpected, \
      "Cdb terminated unexpectedly! StdIO:\r\n%s\r\nStdErr:\r\n%s" % (
        "\r\n".join(["\r\n".join(asCdbStdIO) for asCdbStdIO in oCdbWrapper.aasCdbStdIO]),
        "\r\n".join(oCdbWrapper.asCdbStdErr)
      );
  oCdbWrapper.fFinishedCallback and oCdbWrapper.fFinishedCallback(oCdbWrapper.oErrorReport);
예제 #5
0
 def _fThreadExceptionHandler(oCdbWrapper, oException, oExceptionThread):
     # Wait for the exception thread to terminate and then clean up.
     oExceptionThread.join()
     if oCdbWrapper.bCdbRunning:
         oCdbWrapper.bCdbWasTerminatedOnPurpose = True
         oCdbProcess = getattr(oCdbWrapper, "oCdbProcess", None)
         if oCdbProcess:
             fKillProcessesUntilTheyAreDead([oCdbProcess.pid])
예제 #6
0
 def _fThreadExceptionHandler(oCdbWrapper, oException, oExceptionThread):
   # Wait for the exception thread to terminate and then clean up.
   oExceptionThread.join();
   if oCdbWrapper.bCdbRunning:
     oCdbWrapper.bCdbWasTerminatedOnPurpose = True;
     oCdbProcess = getattr(oCdbWrapper, "oCdbProcess", None);
     if oCdbProcess:
       fKillProcessesUntilTheyAreDead([oCdbProcess.pid]);
예제 #7
0
 def _fThreadWrapper(oCdbWrapper, fActivity):
   try:
     # If there is not exception callback, do not handle exceptions:
     if not oCdbWrapper.fInternalExceptionCallback:
       return fActivity(oCdbWrapper);
     else:
       # If there is an exception callback, handle exceptions and pass them to the callback:
       try:
         fActivity(oCdbWrapper);
       except Exception, oException:
         cException, oException, oTraceBack = sys.exc_info();
         oCdbWrapper.fInternalExceptionCallback(oException, oTraceBack);
   finally:
     oCdbProcess = getattr(oCdbWrapper, "oCdbProcess", None);
     if not oCdbProcess:
       oCdbWrapper.bCdbRunning = False;
       return;
     if oCdbProcess.poll() is not None:
       oCdbWrapper.bCdbRunning = False;
       return;
     oCdbWrapper.bCdbWasTerminatedOnPurpose = True;
     # cdb is still running: try to terminate cdb the normal way.
     try:
       oCdbProcess.terminate();
     except:
       pass;
     else:
       oCdbWrapper.bCdbRunning = False;
       return;
     if oCdbProcess.poll() is not None:
       oCdbWrapper.bCdbRunning = False;
       return;
     # cdb is still running: try to terminate cdb the hard way.
     fKillProcessesUntilTheyAreDead([oCdbProcess.pid]);
     # Make sure cdb finally died.
     assert oCdbProcess.poll() is not None, \
         "cdb did not die after killing it repeatedly";
     oCdbWrapper.bCdbRunning = False;
예제 #8
0
파일: Tests.py 프로젝트: tmm08a/EdgeDbg
from fauStartEdgeAndReturnProcessIds import fauStartEdgeAndReturnProcessIds
from Kill import fKillProcessesUntilTheyAreDead

print "* Starting Edge and returning process ids..."
auProcessIds = fauStartEdgeAndReturnProcessIds()
print repr(auProcessIds)
print "* Kill all Edge process ids..."
fKillProcessesUntilTheyAreDead(auProcessIds=auProcessIds)
예제 #9
0
from fauStartEdgeAndReturnProcessIds import fauStartEdgeAndReturnProcessIds
from Kill import fKillProcessesUntilTheyAreDead

print "* Killing any running instances of Edge..."
fKillProcessesUntilTheyAreDead(asBinaryNames=[
    "ApplicationFrameHost.exe",
    "browser_broker.exe",
    "MicrosoftEdge.exe",
    "MicrosoftEdgeCP.exe",
    "RuntimeBroker.exe",
])
print "* Starting Edge and returning process ids..."
auProcessIds = fauStartEdgeAndReturnProcessIds()
print repr(auProcessIds)
print "* Kill all Edge process ids..."
fKillProcessesUntilTheyAreDead(auProcessIds=auProcessIds)