-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
BREAKING CHANGE: This commit renames some files - you will need to adjust your import paths in .gdbinit or .lldbinit (see readme for updated)
- Loading branch information
Showing
6 changed files
with
240 additions
and
172 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
import gdb | ||
from chatgdb import utils | ||
|
||
prev_command = "" | ||
COMMAND_PROMPT = "Give me a SINGLE GDB command with no explanation. Do NOT \ | ||
write any English above or below the command. Only give me the command as \ | ||
text. Here is my question: " | ||
EXPLANATION_PROMPT = "Give me an explanation for this GDB command: " | ||
|
||
|
||
class GDBCommand(gdb.Command): | ||
"""Custom GDB command - chat | ||
The chat command is used to generate GDB commands based on plain English | ||
input. | ||
""" | ||
|
||
def __init__(self): | ||
"""Initializes custom GDB command""" | ||
super(GDBCommand, self).__init__("chat", gdb.COMMAND_DATA) | ||
|
||
# creates api request on command invocation | ||
def invoke(self, arg, from_tty): | ||
"""Invokes custom GDB command and sends API request | ||
Params: | ||
arg (str): argument passed to command | ||
from_tty (bool): whether command was invoked from TTY | ||
""" | ||
global prev_command | ||
# handling if user is asking for help on how to use the commands | ||
if arg == "help": | ||
utils.chat_help() | ||
return | ||
|
||
prev_command, command = utils.chat_helper(arg, COMMAND_PROMPT) | ||
gdb.execute(command) | ||
|
||
|
||
class ExplainCommand(gdb.Command): | ||
"""Custom GDB command - explain | ||
The explain command is used to generate explanations for either the | ||
previous command or a user query | ||
""" | ||
def __init__(self): | ||
"""Initializes custom GDB command""" | ||
super(ExplainCommand, self).__init__("explain", gdb.COMMAND_DATA) | ||
|
||
# creates api request on command invocation | ||
def invoke(self, arg, from_tty): | ||
"""Invokes custom GDB command and sends API request | ||
Params: | ||
arg (str): argument passed to commands | ||
from_tty (bool): whether command was invoked from from_tty | ||
""" | ||
utils.explain_helper(prev_command, arg, EXPLANATION_PROMPT) | ||
|
||
|
||
GDBCommand() | ||
ExplainCommand() | ||
|
||
|
||
def main(): | ||
print("ChatGDB loaded successfully. Type 'chat help' for information " | ||
"on how to run the commands.") | ||
|
||
|
||
if __name__ == "__main__": | ||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import lldb | ||
from chatgdb import utils | ||
|
||
|
||
def __lldb_init_module(debugger, internal_dict): | ||
"""This function handles the initialization of the custom commands""" | ||
# lldb doesn't trigger python's main function so we print the help here | ||
print("ChatLLDB loaded successfully. Type 'chat help' for information " | ||
"on how to run the commands.") | ||
debugger.HandleCommand('command script add -f lldb.chat chat') | ||
debugger.HandleCommand('command script add -f lldb.explain explain') | ||
|
||
|
||
prev_command = "" | ||
COMMAND_PROMPT = "Give me a SINGLE LLDB command with no explanation. Do NOT \ | ||
give me a GDB command. DO NOT write any English above or below the command. \ | ||
Only give me the command as text. Here is my question: " | ||
EXPLANATION_PROMPT = "Give me an explanation for this LLDB command: " | ||
|
||
|
||
def chat(debugger, command, result, internal_dict): | ||
"""Custom LLDB command - chat | ||
The chat command is used to generate GDB commands based on plain English | ||
input. | ||
""" | ||
global prev_command | ||
# handle when user types 'chat help' | ||
if command == "help": | ||
utils.chat_help() | ||
return | ||
prev_command, command = utils.chat_helper(command, prompt=COMMAND_PROMPT) | ||
debugger.HandleCommand(command) | ||
|
||
|
||
def explain(debugger, command, result, internal_dict): | ||
"""Custom LLDB command - explain | ||
The explain command is used to generate explanations for either the | ||
previous command or a user query | ||
""" | ||
utils.explain_helper(prev_command, command, prompt=EXPLANATION_PROMPT) |
Oops, something went wrong.