Skip to content

Commit

Permalink
Restore compatiblity with Python 3.6 (#1051)
Browse files Browse the repository at this point in the history
## Description

Fixes #1049

Removes from `typing` imports the `Literal` member which appears on
Python 3.8.
Since it's never used anyway, it shouldn't be here in a first place.
Wonder how linting missed this 🤔

Also it seems adding target hooks overlooked the compat also. Since we
might upgrade the base versions soon, the feature is just disabled for
now
  • Loading branch information
hugsy authored Jan 20, 2024
1 parent c9a8b18 commit 219d46f
Showing 1 changed file with 27 additions and 27 deletions.
54 changes: 27 additions & 27 deletions gef.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@
from io import StringIO, TextIOWrapper
from types import ModuleType
from typing import (Any, ByteString, Callable, Dict, Generator, Iterable,
Iterator, List, Literal, NoReturn, Optional, Sequence, Set, Tuple, Type,
Iterator, List, NoReturn, Optional, Sequence, Set, Tuple, Type,
Union, TYPE_CHECKING)
from urllib.request import urlopen

Expand Down Expand Up @@ -11377,32 +11377,32 @@ def target_remote_posthook():

GefTmuxSetup()


disable_tr_overwrite_setting = "gef.disable_target_remote_overwrite"

if not gef.config[disable_tr_overwrite_setting]:
warnmsg = ("Using `target remote` with GEF should work in most cases, "
"but use `gef-remote` if you can. You can disable the "
"overwrite of the `target remote` command by toggling "
f"`{disable_tr_overwrite_setting}` in the config.")
hook = f"""
define target hookpost-{{}}
pi target_remote_posthook()
context
pi if calling_function() != "connect": warn("{warnmsg}")
end
"""

# Register a post-hook for `target remote` that initialize the remote session
gdb.execute(hook.format("remote"))
gdb.execute(hook.format("extended-remote"))
else:
errmsg = ("Using `target remote` does not work, use `gef-remote` "
f"instead. You can toggle `{disable_tr_overwrite_setting}` "
"if this is not desired.")
hook = f"""pi if calling_function() != "connect": err("{errmsg}")"""
gdb.execute(f"define target hook-remote\n{hook}\nend")
gdb.execute(f"define target hook-extended-remote\n{hook}\nend")
if GDB_VERSION > (9, 0):
disable_tr_overwrite_setting = "gef.disable_target_remote_overwrite"

if not gef.config[disable_tr_overwrite_setting]:
warnmsg = ("Using `target remote` with GEF should work in most cases, "
"but use `gef-remote` if you can. You can disable the "
"overwrite of the `target remote` command by toggling "
f"`{disable_tr_overwrite_setting}` in the config.")
hook = f"""
define target hookpost-{{}}
pi target_remote_posthook()
context
pi if calling_function() != "connect": warn("{warnmsg}")
end
"""

# Register a post-hook for `target remote` that initialize the remote session
gdb.execute(hook.format("remote"))
gdb.execute(hook.format("extended-remote"))
else:
errmsg = ("Using `target remote` does not work, use `gef-remote` "
f"instead. You can toggle `{disable_tr_overwrite_setting}` "
"if this is not desired.")
hook = f"""pi if calling_function() != "connect": err("{errmsg}")"""
gdb.execute(f"define target hook-remote\n{hook}\nend")
gdb.execute(f"define target hook-extended-remote\n{hook}\nend")

# restore saved breakpoints (if any)
bkp_fpath = pathlib.Path(gef.config["gef.autosave_breakpoints_file"]).expanduser().absolute()
Expand Down

0 comments on commit 219d46f

Please sign in to comment.