예제 #1
0
 def detach(self):
     if not self.is_attached:
         return
     self.is_attached = False
     if self.running:
         info("Detach %s" % self)
         ptrace_detach(self.pid)
     self.debugger.deleteProcess(process=self)
예제 #2
0
 def detach(self):
     if not self.is_attached:
         return
     self.is_attached = False
     if self.running:
         info("Detach %s" % self)
         ptrace_detach(self.pid)
     self.debugger.deleteProcess(process=self)
예제 #3
0
 def detach(self):
     if not self.is_attached:
         return
     self.is_attached = False
     if self.running:
         if self.was_attached:
             info("Detach %s" % self)
             ptrace_detach(self.pid)
         elif self.is_stopped:
             info("Continue process %s execution" % self.pid)
             self.cont()
     self.debugger.deleteProcess(process=self)
예제 #4
0
 def detach(self):
     if not self.is_attached:
         return
     self.is_attached = False
     if self.running:
         if self.was_attached:
             info("Detach %s" % self)
             ptrace_detach(self.pid)
         elif self.is_stopped:
             info("Continue process %s execution" % self.pid)
             self.cont()
     self.debugger.deleteProcess(process=self)
예제 #5
0
    def __capturecore(self):
        ptrace_detach(self.pid, signal.SIGSTOP) #detach and leave stopped so gcore can attach
        #TODO: put process in a queue to be core dumped later

        #Relying on kernel to create a core file does not work well in a container
        #Use gcore to capture core its a little slower but reliable
        dst = os.path.join(self.service.cores_dir, "core")
        with open(os.devnull, 'w') as devnull:
            try:
                subprocess.call(["gcore", "-o", dst, str(self.pid)], stdout=devnull, stderr=devnull)
            except:
                pass

        os.kill(self.pid, signal.SIGKILL)
        # Wait to cleanup zombie
        os.waitpid(self.pid, 0)
        self.service.cores.append("core." + str(self.pid))
예제 #6
0
    def __handle_event(self, pid, status):
        if os.WCOREDUMP(status):
            logger.warning("Core dump created for %s" % (self.pid))

        if os.WIFEXITED(status):
            self.service.instances.pop(self.pid, None)
            self.log_event(0)
            self.__spawn()

        elif os.WIFSIGNALED(status):
            self.service.instances.pop(self.pid, None)
            sig = os.WTERMSIG(status)
            self.log_event(sig)
            self.__spawn()

        elif os.WIFSTOPPED(status):
            self.coverage.capture(self.pid)
            sig = os.WSTOPSIG(status)

            #Don't log breakpoints
            if sig == signal.SIGTRAP:
                self.exitbp.desinstall(set_ip = True)
                ptrace_cont(self.pid, 0)
                return

            self.log_event(sig)
            if sig == signal.SIGPIPE:
                ptrace_detach(self.pid)
                os.waitpid(self.pid, 0) #Clean up Zombie
                self.running = False

            elif sig == signal.SIGSEGV:
                self.__capturecore()
                self.__spawn()
            else:
                ptrace_cont(self.pid, sig)
예제 #7
0
 def detach(self):
     if self.attached:
         ptrace_detach(self.pid)
         self.attached = False
예제 #8
0
 def _ptrace_detach(self, tracer):
     """This cleans up a single process object without trying to delete it from a
     debugger.
     """
     ptrace_detach(self.pid) #bug piptrace doesn't detach when detach is called
     tracer.read_mem_file.close() #bug piptrace does not close file handles
예제 #9
0
 def detach(self, signum=0):
     return ptrace_detach(self.pid, signum)