Skip to content

Commit

Permalink
bug fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
khlevin committed May 1, 2024
1 parent e40f6ca commit 222a573
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 25 deletions.
35 changes: 28 additions & 7 deletions src/chatdbg/chatdbg_gdb.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,10 @@ def _message_is_a_bad_command_error(self, message):
return message.strip().startswith("Undefined command:")

def _run_one_command(self, command):
return gdb.execute(command, to_string=True)
try:
return gdb.execute(command, to_string=True)
except Exception as e:
return str(e)

def check_debugger_state(self):
global last_error_type
Expand Down Expand Up @@ -234,16 +237,34 @@ def _initial_prompt_input(self):
input_pipe = args.find('<')
if input_pipe != -1:
input_file = args[input_pipe + 1:].strip()

try:
content = open(input_file, 'r').read()
return content
except Exception:
self.fail(f"The detected input file {input_file} could not be read.")
try:
content = open(input_file, 'r').read()
return content
except Exception:
self.fail(f"The detected input file {input_file} could not be read.")

def _prompt_stack(self):
"""
Return a simple backtrace to show the LLM where we are on the stack
in followup prompts.
"""
return None

def llm_debug(self, command: str) -> str:
"""
{
"name": "debug",
"description": "The `debug` function runs a GDB command on the stopped program and gets the response.",
"parameters": {
"type": "object",
"properties": {
"command": {
"type": "string",
"description": "The GDB command to run, possibly with arguments."
}
},
"required": [ "command" ]
}
}
"""
return command, self._run_one_command(command)
20 changes: 20 additions & 0 deletions src/chatdbg/chatdbg_lldb.py
Original file line number Diff line number Diff line change
Expand Up @@ -309,3 +309,23 @@ def _prompt_stack(self):
in followup prompts.
"""
return None

def llm_debug(self, command: str) -> str:
"""
{
"name": "debug",
"description": "The `debug` function runs an LLDB command on the stopped program and gets the response.",
"parameters": {
"type": "object",
"properties": {
"command": {
"type": "string",
"description": "The LLDB command to run, possibly with arguments."
}
},
"required": [ "command" ]
}
}
"""
return command, self._run_one_command(command)

19 changes: 1 addition & 18 deletions src/chatdbg/native_util/dbg_dialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,25 +128,8 @@ def build_prompt(self, arg, conversing):
self._prompt_history(), self._prompt_stack(), arg
)

# TODO: Factor out the name of the debugger that's embedded in the doc string...
def llm_debug(self, command: str) -> str:
"""
{
"name": "debug",
"description": "The `debug` function runs an LLDB command on the stopped program and gets the response.",
"parameters": {
"type": "object",
"properties": {
"command": {
"type": "string",
"description": "The LLDB command to run, possibly with arguments."
}
},
"required": [ "command" ]
}
}
"""
return command, self._run_one_command(command)
pass

def llm_get_code_surrounding(self, filename: str, line_number: int) -> str:
"""
Expand Down

0 comments on commit 222a573

Please sign in to comment.