From 1d374498a8a965dd4c82b4a47ac162dfa7071f19 Mon Sep 17 00:00:00 2001 From: "Matt." <4922458+mbrla0@users.noreply.github.com> Date: Tue, 19 Aug 2025 05:30:30 -0300 Subject: [PATCH] LLDB: Print process status information on exit (#3248) * LLDB: Print process status information on exit * Update pwndbg/dbg/lldb/repl/__init__.py --------- Co-authored-by: Disconnect3d --- pwndbg/dbg/lldb/repl/__init__.py | 63 ++++++++++++++++++-------------- pwndbg/dbg/lldb/repl/proc.py | 13 +++++++ 2 files changed, 49 insertions(+), 27 deletions(-) diff --git a/pwndbg/dbg/lldb/repl/__init__.py b/pwndbg/dbg/lldb/repl/__init__.py index 189b40d58..87b8a896d 100644 --- a/pwndbg/dbg/lldb/repl/__init__.py +++ b/pwndbg/dbg/lldb/repl/__init__.py @@ -71,12 +71,6 @@ from pwndbg.dbg.lldb.pset import pget from pwndbg.dbg.lldb.pset import pset from pwndbg.dbg.lldb.repl.io import IODriver from pwndbg.dbg.lldb.repl.io import get_io_driver -from pwndbg.dbg.lldb.repl.proc import EventHandler -from pwndbg.dbg.lldb.repl.proc import LaunchResultConnected -from pwndbg.dbg.lldb.repl.proc import LaunchResultEarlyExit -from pwndbg.dbg.lldb.repl.proc import LaunchResultError -from pwndbg.dbg.lldb.repl.proc import LaunchResultSuccess -from pwndbg.dbg.lldb.repl.proc import ProcessDriver from pwndbg.lib.tips import color_tip from pwndbg.lib.tips import get_tip_of_the_day @@ -90,6 +84,42 @@ else: from pwndbg.dbg.lldb.repl.readline import enable_readline from pwndbg.dbg.lldb.repl.readline import wrap_with_history + +def print_error(msg: str, *args): + """ + Print an error message in the style of the LLDB CLI. + """ + print(message.error("error:"), msg, *args) + + +def print_warn(msg: str, *args): + """ + Print a warning message in the style of the LLDB CLI. + """ + print(message.warn("warn:"), msg, *args) + + +def print_hint(msg: str, *args): + """ + Print a hint message in the style of the LLDB CLI. + """ + print(message.hint("hint:"), msg, *args) + + +def print_info(msg: str, *args): + """ + Print an information message in the style of the LLDB CLI. + """ + print(message.info("info:"), msg, *args) + + +from pwndbg.dbg.lldb.repl.proc import EventHandler +from pwndbg.dbg.lldb.repl.proc import LaunchResultConnected +from pwndbg.dbg.lldb.repl.proc import LaunchResultEarlyExit +from pwndbg.dbg.lldb.repl.proc import LaunchResultError +from pwndbg.dbg.lldb.repl.proc import LaunchResultSuccess +from pwndbg.dbg.lldb.repl.proc import ProcessDriver + show_tip = pwndbg.config.add_param( "show-tips", True, "whether to display the tip of the day on startup" ) @@ -266,27 +296,6 @@ class PwndbgController: return OneShotAwaitable(YieldExecDirect(command, True, False)) -def print_error(msg: str, *args): - """ - Print an error message in the style of the LLDB CLI. - """ - print(message.error("error:"), msg, *args) - - -def print_warn(msg: str, *args): - """ - Print a warning message in the style of the LLDB CLI. - """ - print(message.warn("warn:"), msg, *args) - - -def print_hint(msg: str, *args): - """ - Print a hint message in the style of the LLDB CLI. - """ - print(message.hint("hint:"), msg, *args) - - @wrap_with_history def run( controller: Callable[..., Coroutine[Any, Any, None]], diff --git a/pwndbg/dbg/lldb/repl/proc.py b/pwndbg/dbg/lldb/repl/proc.py index 88425d8e7..59d029ca0 100644 --- a/pwndbg/dbg/lldb/repl/proc.py +++ b/pwndbg/dbg/lldb/repl/proc.py @@ -13,6 +13,7 @@ import lldb import pwndbg from pwndbg.dbg.lldb import YieldContinue from pwndbg.dbg.lldb import YieldSingleStep +from pwndbg.dbg.lldb.repl import print_info from pwndbg.dbg.lldb.repl.io import IODriver from pwndbg.dbg.lldb.repl.io import IODriverPlainText @@ -321,6 +322,18 @@ class ProcessDriver: if fire_events: self.eh.exited() + + if new_state == lldb.eStateExited: + proc = lldb.SBProcess.GetProcessFromEvent(event) + desc = ( + "" if not proc.exit_description else f" ({proc.exit_description})" + ) + print_info(f"process exited with status {proc.exit_state}{desc}") + elif new_state == lldb.eStateCrashed: + print_info("process crashed") + elif new_state == lldb.eStateDetached: + print_info("process detached") + result = _PollResultExited(new_state) break