From 33fe4361f8f8f524002b4079d8317a26b32af3a1 Mon Sep 17 00:00:00 2001 From: crazy hugsy Date: Wed, 12 Oct 2022 19:53:01 -0700 Subject: [PATCH] print warning messages when using `target remote` with gef (#899) --- gef.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/gef.py b/gef.py index 988c2f31b..0f791d8e4 100644 --- a/gef.py +++ b/gef.py @@ -356,6 +356,15 @@ def is_alive() -> bool: return False +def calling_function() -> Optional[str]: + """Return the name of the calling function""" + try: + stack_info = traceback.extract_stack()[-3] + return stack_info.name + except: + return None + + # # Decorators # @@ -10859,3 +10868,8 @@ def reset_caches(self) -> None: new_objfile_handler(None) GefTmuxSetup() + + # `target remote` commands cannot be disabled, so print a warning message instead + errmsg = "Using `target remote` with GEF does not work, use `gef-remote` instead. You've been warned." + gdb.execute(f"define target hook-remote\n pi if calling_function() != \"connect\": err(\"{errmsg}\") \nend") + gdb.execute(f"define target hook-extended-remote\n pi if calling_function() != \"connect\": err(\"{errmsg}\") \nend")