Skip to content

Commit

Permalink
Wrap print() for emulated gdb scripts to protect ourselves.
Browse files Browse the repository at this point in the history
  • Loading branch information
khuey committed Nov 12, 2024
1 parent b1e461a commit c360a0a
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion scripts/rr-gdb-script-host.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,14 @@ def strip_prefix(s: str, needle: str) -> Optional[str]:

return None

def print_wrapper(*args, **kwargs):
# Don't allow the script to print to stdout and interfere
# with our communication with the rr process.
f = kwargs.get("file")
if f is None or f == sys.stdout:
kwargs["file"] = sys.stderr
print(*args, **kwargs)

GdbNewObjfileEventCallback = Callable[[object], None]

class DebuggerExtensionCommand:
Expand Down Expand Up @@ -54,7 +62,7 @@ def set(self, cmd: str) -> str:

def execute_script(self, script: str):
gdb_api: GdbApiRoot = GdbApiRoot(self)
exec(script, {'gdb': gdb_api})
exec(script, {'gdb': gdb_api, "print": print_wrapper})

def new_objfile(self, f: str):
new_objfile: GdbNewObjfile = GdbNewObjfile(self, f)
Expand Down

0 comments on commit c360a0a

Please sign in to comment.