def execCommand(command, buff_output=False): """ Thread-safe GDB command execution. """ is_mt = threading.current_thread() is threading.main_thread() lockCounter = util.AtomicInteger() output = None def _execCommand__mT(): nonlocal lockCounter nonlocal is_mt nonlocal command nonlocal buff_output nonlocal output try: output = gdb.execute(command, to_string=buff_output) except Exception as e: print(traceback.format_exc()) if not is_mt: lockCounter.decr() if not is_mt: lockCounter.incr() gdb.post_event(_execCommand__mT) while lockCounter.get() > 0: pass else: _execCommand__mT() return output
def _threadSafe(*args, **kwargs): nonlocal callback is_mt = threading.current_thread() is threading.main_thread() lockCounter = util.AtomicInteger() output = None def _exec__mT(): nonlocal callback nonlocal lockCounter nonlocal is_mt nonlocal output try: output = callback(*args, **kwargs) except Exception as e: print(traceback.format_exc()) if not is_mt: lockCounter.decr() if not is_mt: lockCounter.incr() gdb.post_event(_exec__mT) while lockCounter.get() > 0: pass else: _exec__mT() return output
def execCommand(command, buff_output=False): """ Thread-safe GDB command execution. """ is_mt = threading.current_thread() is threading.main_thread() lockCounter = util.AtomicInteger() output = None def _execCommand__mT(): nonlocal lockCounter nonlocal is_mt nonlocal command nonlocal buff_output nonlocal output try: output = gdb.execute(command, to_string=buff_output) except Exception as e: print(traceback.format_exc()) if not is_mt: lockCounter.decr() if not is_mt: lockCounter.incr() gdb.post_event(_execCommand__mT) is_warned = False start_time = time.time() while lockCounter.get() > 0: if not is_warned and time.time( ) - start_time > settings.GDB_MT_WARNING_TIME: is_warned = True print("") print( "[GDBFrontend]", "GDB main thread is bloocking. (If you are running something (like shell) in GDB shell, you must temrinate it for GDBFrontend to continue work properly.)" ) time.sleep(0.1) else: _execCommand__mT() return output
def _threadSafe(*args, **kwargs): nonlocal callback is_mt = threading.current_thread() is threading.main_thread() lockCounter = util.AtomicInteger() output = None def _exec__mT(): nonlocal callback nonlocal lockCounter nonlocal is_mt nonlocal output try: output = callback(*args, **kwargs) except Exception as e: print(traceback.format_exc()) if not is_mt: lockCounter.decr() if not is_mt: lockCounter.incr() gdb.post_event(_exec__mT) is_warned = False start_time = time.time() while lockCounter.get() > 0: if not is_warned and time.time( ) - start_time > settings.GDB_MT_WARNING_TIME: is_warned = True print("") print( "[GDBFrontend]", "GDB main thread is bloocking. (If you are running something (like shell) in GDB shell, you must terminate it for GDBFrontend to continue work properly.)" ) time.sleep(0.1) else: _exec__mT() return output
def run(request, params): if params is None: params = {} url_path = urllib.parse.urlparse(request.path) qs_params = urllib.parse.parse_qs(url_path.query) result_json = {} result_json["ok"] = True def response(): nonlocal request nonlocal params nonlocal result_json request.send_response(200) request.send_header("Content-Type", "application/json; charset=utf-8") request.end_headers() request.wfile.write(json.dumps(result_json).encode()) if qs_params["number"] is None: result_json["ok"] = False response() if qs_params["number"] is None: result_json["ok"] = False response() lockCounter = util.AtomicInteger() @api.debug.threadSafe def _setBreakpoint__mT(): api.debug.getBreakpoint(qs_params["number"][0]).enabled = ( qs_params["is_enabled"][0] == "true") _setBreakpoint__mT() response()