Skip to content

Commit

Permalink
Added exit msgs (#54)
Browse files Browse the repository at this point in the history
* added exit msgs

* rearrange

* Update src/chatdbg/util/exit_message.py

Co-authored-by: Nicolas van Kempen <[email protected]>

* import

* fixed lldb

* fix

* nick is picky

---------

Co-authored-by: Kyla Levin <[email protected]>
Co-authored-by: Nicolas van Kempen <[email protected]>
  • Loading branch information
3 people authored Dec 10, 2024
1 parent 4bb4897 commit 55a4f26
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 2 deletions.
6 changes: 5 additions & 1 deletion src/chatdbg/chatdbg_gdb.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import os
import atexit
from typing import List, Optional, Union


import gdb

from chatdbg.native_util import clangd_lsp_integration
Expand All @@ -14,6 +14,7 @@
)
from chatdbg.util.config import chatdbg_config
from chatdbg.native_util.safety import command_is_safe
from chatdbg.util.exit_message import chatdbg_was_called, print_exit_message

# The file produced by the panic handler if the Rust program is using the chatdbg crate.
RUST_PANIC_LOG_FILENAME = "panic_log.txt"
Expand All @@ -25,6 +26,8 @@

last_error_type = ""

atexit.register(print_exit_message)


def stop_handler(event):
"""Sets last error type so we can report it later."""
Expand Down Expand Up @@ -105,6 +108,7 @@ def invoke(self, command, from_tty):
class GDBDialog(DBGDialog):

def __init__(self, prompt) -> None:
chatdbg_was_called()
super().__init__(prompt)

def _message_is_a_bad_command_error(self, message):
Expand Down
4 changes: 4 additions & 0 deletions src/chatdbg/chatdbg_lldb.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,18 @@
_SkippedFramesEntry,
)
from chatdbg.util.config import chatdbg_config
from chatdbg.util.exit_message import chatdbg_was_called, print_exit_message
from chatdbg.native_util.safety import command_is_safe


# The file produced by the panic handler if the Rust program is using the chatdbg crate.
RUST_PANIC_LOG_FILENAME = "panic_log.txt"
PROMPT = "(ChatDBG lldb) "


def __lldb_init_module(debugger: lldb.SBDebugger, internal_dict: dict) -> None:
debugger.HandleCommand(f"settings set prompt '{PROMPT}'")
debugger.SetDestroyCallback(print_exit_message)
chatdbg_config.format = "md"


Expand Down Expand Up @@ -76,6 +79,7 @@ class LLDBDialog(DBGDialog):

def __init__(self, prompt, debugger) -> None:
super().__init__(prompt)
chatdbg_was_called()
self._debugger = debugger

def _message_is_a_bad_command_error(self, message):
Expand Down
5 changes: 4 additions & 1 deletion src/chatdbg/chatdbg_pdb.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
from chatdbg.util.config import chatdbg_config
from chatdbg.util.log import ChatDBGLog
from chatdbg.util.history import CommandHistory
from chatdbg.util.exit_message import chatdbg_was_called, print_exit_message


def load_ipython_extension(ipython):
Expand Down Expand Up @@ -78,6 +79,7 @@ def __init__(self, *args, **kwargs):
self._chat_prefix = " "
self._text_width = 120
self._assistant = None
atexit.register(print_exit_message)
atexit.register(lambda: self._close_assistant())

self._history = CommandHistory(self.prompt)
Expand Down Expand Up @@ -287,7 +289,7 @@ def _getval(self, arg):
try:
if chatdbg_config.unsafe:
return super._getval(arg)
else:
else:
return sandbox_eval(arg, self.curframe.f_globals, self.curframe_locals)
except NameError as e:
self.error(f"NameError: {e}")
Expand Down Expand Up @@ -576,6 +578,7 @@ def do_chat(self, arg):
"""chat
Send a chat message.
"""
chatdbg_was_called()
self.was_chat_or_renew = True

full_prompt = self._build_prompt(arg, self._assistant != None)
Expand Down
17 changes: 17 additions & 0 deletions src/chatdbg/util/exit_message.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
from typing import Any

_chatdbg_was_called = False


def chatdbg_was_called() -> None:
global _chatdbg_was_called
_chatdbg_was_called = True


def print_exit_message(*args: Any, **kwargs: Any) -> None:
global _chatdbg_was_called
if _chatdbg_was_called:
print("Thank you for using ChatDBG!")
print(
"Share your success stories here: github.com/plasma-umass/ChatDBG/issues/53"
)

0 comments on commit 55a4f26

Please sign in to comment.