Add GDB scheduler-locking control to the Debugger-agnostic API (#2409)

* Add GDB scheduler-locking control to the Debugger-agnostic API

* Add back uses of scheduler-locking where they'd been removed
pull/2414/head
Matt. 1 year ago committed by GitHub
parent 0172a834ba
commit 3db6ba4eed
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -16,7 +16,11 @@ def __call_pthread_self() -> int:
if pwndbg.dbg.selected_inferior().symbol_address_from_name("pthread_self") is None:
return 0
try:
return int(pwndbg.dbg.selected_frame().evaluate_expression("(void *)pthread_self()"))
return int(
pwndbg.dbg.selected_frame().evaluate_expression(
"(void *)pthread_self()", lock_scheduler=True
)
)
except pwndbg.dbg_mod.Error:
return 0

@ -154,10 +154,17 @@ class Registers:
class Frame:
def evaluate_expression(self, expression: str) -> Value:
def evaluate_expression(self, expression: str, lock_scheduler: bool = False) -> Value:
"""
Evaluate the given expression in the context of this frame, and
return a `Value`.
# `lock_scheduler`
Additionally, callers of this function might specify that they want to
enable scheduler locking during the evaluation of this expression. This
is a GDB-only option, and is intended for cases in which the result
would be incorrect without it enabled, when running in GDB. Other
debuggers should ignore this parameter.
"""
raise NotImplementedError()

@ -2,6 +2,7 @@ from __future__ import annotations
import re
import signal
from contextlib import nullcontext
from typing import Any
from typing import Generator
from typing import List
@ -86,10 +87,12 @@ class GDBFrame(pwndbg.dbg_mod.Frame):
self.inner = inner
@override
def evaluate_expression(self, expression: str) -> pwndbg.dbg_mod.Value:
from pwndbg.gdblib.scheduler import lock_scheduler
def evaluate_expression(
self, expression: str, lock_scheduler: bool = False
) -> pwndbg.dbg_mod.Value:
from pwndbg.gdblib.scheduler import lock_scheduler as do_lock_scheduler
with lock_scheduler():
with do_lock_scheduler() if lock_scheduler else nullcontext():
with selection(self.inner, lambda: gdb.selected_frame(), lambda f: f.select()):
try:
value = parse_and_eval(expression, global_context=False)

@ -97,7 +97,9 @@ class LLDBFrame(pwndbg.dbg_mod.Frame):
self.proc = proc
@override
def evaluate_expression(self, expression: str) -> pwndbg.dbg_mod.Value:
def evaluate_expression(
self, expression: str, lock_scheduler: bool = False
) -> pwndbg.dbg_mod.Value:
value = self.inner.EvaluateExpression(expression)
opt_out = _is_optimized_out(value)

Loading…
Cancel
Save