def makeThreadSuspendMessage(self, thread_id, frame, stop_reason, message): """ <xml> <thread id="id" stop_reason="reason"> <frame id="id" name="functionName " file="file" line="line"> <var variable stuffff.... </frame> </thread> """ try: cmdTextList = ["<xml>"] if message: message = pydevd_vars.makeValidXmlValue(str(message)) cmdTextList.append('<thread id="%s" stop_reason="%s" message="%s">' % (thread_id, stop_reason, message)) curFrame = frame try: while curFrame: #print cmdText myId = str(id(curFrame)) #print "id is ", myId if curFrame.f_code is None: break #Iron Python sometimes does not have it! myName = curFrame.f_code.co_name #method name (if in method) or ? if global if myName is None: break #Iron Python sometimes does not have it! #print "name is ", myName filename, base = pydevd_file_utils.GetFilenameAndBase(curFrame) myFile = pydevd_file_utils.NormFileToClient(filename) #print "file is ", myFile #myFile = inspect.getsourcefile(curFrame) or inspect.getfile(frame) myLine = str(curFrame.f_lineno) #print "line is ", myLine #the variables are all gotten 'on-demand' #variables = pydevd_vars.frameVarsToXML(curFrame.f_locals) variables = '' cmdTextList.append('<frame id="%s" name="%s" ' % (myId , pydevd_vars.makeValidXmlValue(myName))) cmdTextList.append('file="%s" line="%s">"' % (quote(myFile, '/>_= \t'), myLine)) cmdTextList.append(variables) cmdTextList.append("</frame>") curFrame = curFrame.f_back except : traceback.print_exc() cmdTextList.append("</thread></xml>") cmdText = ''.join(cmdTextList) return NetCommand(CMD_THREAD_SUSPEND, 0, cmdText) except: return self.makeErrorMessage(0, GetExceptionTracebackStr())
def get_text_list_for_frame(frame): # partial copy-paste from makeThreadSuspendStr curFrame = frame cmdTextList = [] try: while curFrame: #print cmdText myId = str(id(curFrame)) #print "id is ", myId if curFrame.f_code is None: break #Iron Python sometimes does not have it! myName = curFrame.f_code.co_name #method name (if in method) or ? if global if myName is None: break #Iron Python sometimes does not have it! #print "name is ", myName filename, base = pydevd_file_utils.GetFilenameAndBase(curFrame) myFile = pydevd_file_utils.NormFileToClient(filename) if file_system_encoding.lower() != "utf-8" and hasattr( myFile, "decode"): # myFile is a byte string encoded using the file system encoding # convert it to utf8 myFile = myFile.decode(file_system_encoding).encode("utf-8") #print "file is ", myFile #myFile = inspect.getsourcefile(curFrame) or inspect.getfile(frame) myLine = str(curFrame.f_lineno) #print "line is ", myLine #the variables are all gotten 'on-demand' #variables = pydevd_vars.frameVarsToXML(curFrame.f_locals) variables = '' cmdTextList.append('<frame id="%s" name="%s" ' % (myId, pydevd_vars.makeValidXmlValue(myName))) cmdTextList.append('file="%s" line="%s">"' % (quote(myFile, '/>_= \t'), myLine)) cmdTextList.append(variables) cmdTextList.append("</frame>") curFrame = curFrame.f_back except: traceback.print_exc() return cmdTextList
def log_event(self, frame): write_log = False self_obj = None if DictContains(frame.f_locals, "self"): self_obj = frame.f_locals["self"] if isinstance(self_obj, threading.Thread) or self_obj.__class__ == ObjectWrapper: write_log = True try: if write_log: t = threadingCurrentThread() back = frame.f_back if not back: return name, back_base = pydevd_file_utils.GetFilenameAndBase(back) event_time = cur_time() - self.start_time method_name = frame.f_code.co_name if isinstance(self_obj, threading.Thread) and method_name in THREAD_METHODS: if back_base not in DONT_TRACE_THREADING or \ (method_name in INNER_METHODS and back_base in INNER_FILES): thread_id = GetThreadId(self_obj) name = self_obj.getName() real_method = frame.f_code.co_name if real_method == "_stop": # TODO: Python 2 if back_base in INNER_FILES and \ back.f_code.co_name == "_wait_for_tstate_lock": back = back.f_back.f_back real_method = "stop" elif real_method == "join": # join called in the current thread, not in self object thread_id = GetThreadId(t) name = t.getName() parent = None if real_method in ("start", "stop"): parent = GetThreadId(t) send_message("threading_event", event_time, name, thread_id, "thread", real_method, back.f_code.co_filename, back.f_lineno, back, parent=parent) # print(event_time, self_obj.getName(), thread_id, "thread", # real_method, back.f_code.co_filename, back.f_lineno) if self_obj.__class__ == ObjectWrapper: if back_base in DONT_TRACE_THREADING: # do not trace methods called from threading return _, back_back_base = pydevd_file_utils.GetFilenameAndBase(back.f_back) back = back.f_back if back_back_base in DONT_TRACE_THREADING: # back_back_base is the file, where the method was called froms return if method_name == "__init__": send_message("threading_event", event_time, t.getName(), GetThreadId(t), "lock", method_name, back.f_code.co_filename, back.f_lineno, back, lock_id=str(id(frame.f_locals["self"]))) if DictContains(frame.f_locals, "attr") and \ (frame.f_locals["attr"] in LOCK_METHODS or frame.f_locals["attr"] in QUEUE_METHODS): real_method = frame.f_locals["attr"] if method_name == "call_begin": real_method += "_begin" elif method_name == "call_end": real_method += "_end" else: return if real_method == "release_end": # do not log release end. Maybe use it later return send_message("threading_event", event_time, t.getName(), GetThreadId(t), "lock", real_method, back.f_code.co_filename, back.f_lineno, back, lock_id=str(id(self_obj))) if real_method in ("put_end", "get_end"): # fake release for queue, cause we don't call it directly send_message("threading_event", event_time, t.getName(), GetThreadId(t), "lock", "release", back.f_code.co_filename, back.f_lineno, back, lock_id=str(id(self_obj))) # print(event_time, t.getName(), GetThreadId(t), "lock", # real_method, back.f_code.co_filename, back.f_lineno) except Exception: traceback.print_exc()