Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

print warning messages when using target remote with gef #899

Merged
merged 1 commit into from
Oct 13, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
16 changes: 15 additions & 1 deletion gef.py
Original file line number Diff line number Diff line change
Expand Up @@ -355,6 +355,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
#
Expand Down Expand Up @@ -10689,7 +10698,7 @@ def __setup_remote(self) -> bool:

def remote_objfile_event_handler(self, evt: "gdb.NewObjFileEvent") -> None:
dbg(f"[remote] in remote_objfile_handler({evt.new_objfile.filename if evt else 'None'}))")
if not evt:
if not evt or not evt.new_objfile.filename:
return
if not evt.new_objfile.filename.startswith("target:") and not evt.new_objfile.filename.startswith("/"):
warn(f"[remote] skipping '{evt.new_objfile.filename}'")
Expand Down Expand Up @@ -10856,3 +10865,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")