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 <dominik.b.czarnota@gmail.com>
pull/3258/head
Matt. 4 months ago committed by GitHub
parent 0775e883e3
commit 1d374498a8
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -71,12 +71,6 @@ from pwndbg.dbg.lldb.pset import pget
from pwndbg.dbg.lldb.pset import pset from pwndbg.dbg.lldb.pset import pset
from pwndbg.dbg.lldb.repl.io import IODriver from pwndbg.dbg.lldb.repl.io import IODriver
from pwndbg.dbg.lldb.repl.io import get_io_driver 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 color_tip
from pwndbg.lib.tips import get_tip_of_the_day 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 enable_readline
from pwndbg.dbg.lldb.repl.readline import wrap_with_history 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_tip = pwndbg.config.add_param(
"show-tips", True, "whether to display the tip of the day on startup" "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)) 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 @wrap_with_history
def run( def run(
controller: Callable[..., Coroutine[Any, Any, None]], controller: Callable[..., Coroutine[Any, Any, None]],

@ -13,6 +13,7 @@ import lldb
import pwndbg import pwndbg
from pwndbg.dbg.lldb import YieldContinue from pwndbg.dbg.lldb import YieldContinue
from pwndbg.dbg.lldb import YieldSingleStep 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 IODriver
from pwndbg.dbg.lldb.repl.io import IODriverPlainText from pwndbg.dbg.lldb.repl.io import IODriverPlainText
@ -321,6 +322,18 @@ class ProcessDriver:
if fire_events: if fire_events:
self.eh.exited() 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) result = _PollResultExited(new_state)
break break

Loading…
Cancel
Save