Skip to content

Commit c360a0a

Browse files
committed
Wrap print() for emulated gdb scripts to protect ourselves.
1 parent b1e461a commit c360a0a

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

scripts/rr-gdb-script-host.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,14 @@ def strip_prefix(s: str, needle: str) -> Optional[str]:
1414

1515
return None
1616

17+
def print_wrapper(*args, **kwargs):
18+
# Don't allow the script to print to stdout and interfere
19+
# with our communication with the rr process.
20+
f = kwargs.get("file")
21+
if f is None or f == sys.stdout:
22+
kwargs["file"] = sys.stderr
23+
print(*args, **kwargs)
24+
1725
GdbNewObjfileEventCallback = Callable[[object], None]
1826

1927
class DebuggerExtensionCommand:
@@ -54,7 +62,7 @@ def set(self, cmd: str) -> str:
5462

5563
def execute_script(self, script: str):
5664
gdb_api: GdbApiRoot = GdbApiRoot(self)
57-
exec(script, {'gdb': gdb_api})
65+
exec(script, {'gdb': gdb_api, "print": print_wrapper})
5866

5967
def new_objfile(self, f: str):
6068
new_objfile: GdbNewObjfile = GdbNewObjfile(self, f)

0 commit comments

Comments
 (0)