diff --git a/docs/details/debugging/gdb_plugin.rst b/docs/details/debugging/gdb_plugin.rst index 0e222ff29..6af5b2dc2 100644 --- a/docs/details/debugging/gdb_plugin.rst +++ b/docs/details/debugging/gdb_plugin.rst @@ -73,3 +73,18 @@ Example: 32 = {num = 90, ptr = 0x5a, color = {blue = 90 'Z', green = 0 '\000', red = 0 '\000'}} 158 = {num = 32767, ptr = 0x7fff, color = {blue = 255 '\377', green = 127 '\177', red = 0 '\000'}} (gdb) + +Connect to Debugger +------------------- + +This command provides the ability to connect and debug GDB Python Script using IDE. + +Connect to ``PyCharm`` / ``VSCode`` / ``Eclipse(not support yet)`` + +``debugger -t pycharm`` + +``debugger -t vscode`` + +``debugger -t eclipse`` + +How to use it specifically, search ``pydevd_pycharm`` / ``debugpy`` for details. diff --git a/scripts/gdb/lvglgdb/__init__.py b/scripts/gdb/lvglgdb/__init__.py index e81a0da1f..7e1d9e17e 100644 --- a/scripts/gdb/lvglgdb/__init__.py +++ b/scripts/gdb/lvglgdb/__init__.py @@ -1,7 +1,16 @@ from .lvgl import * from .value import * +from .debugger import * +# Debugger +Debugger() + +# Dumps DumpObj() + +# Infos InfoStyle() InfoDrawUnit() + +# Set instance set_lvgl_instance(None) diff --git a/scripts/gdb/lvglgdb/debugger.py b/scripts/gdb/lvglgdb/debugger.py index 9a5bb1af4..235ecdcdd 100644 --- a/scripts/gdb/lvglgdb/debugger.py +++ b/scripts/gdb/lvglgdb/debugger.py @@ -1,7 +1,54 @@ -class Debugger(object): +import argparse + +import gdb + + +class Debugger(gdb.Command): + """Start debugpy server or connect to a debug server, so we can debug python code from IDE like PyCharm/VSCode""" + def __init__(self, host="localhost", port=11451): self.__host = host self.__port = port + super().__init__("debugger", gdb.COMMAND_USER) + + def invoke(self, args, from_tty): + parser = argparse.ArgumentParser(description=Debugger.__doc__) + parser.add_argument( + "--host", + type=str, + help="Server listening host", + ) + parser.add_argument( + "-p", + "--port", + type=int, + help="Server listening port", + ) + parser.add_argument( + "-t", + "--type", + choices=["pycharm", "vscode", "eclipse"], + help="Debugger type", + required=True, + ) + + try: + args = parser.parse_args(gdb.string_to_argv(args)) + except SystemExit: + return + + if args.host: + self.__host = args.host + + if args.port: + self.__port = args.port + + if args.type == "pycharm": + self.connect_to_pycharm() + elif args.type == "vscode": + self.connect_to_vscode() + elif args.type == "eclipse": + self.connect_to_eclipse() def connect_to_pycharm(self): try: @@ -13,7 +60,14 @@ class Debugger(object): pydevd_pycharm.settrace(self.__host, port=self.__port, stdoutToServer=True, stderrToServer=True) def connect_to_vscode(self): - raise NotImplementedError() + try: + import debugpy + except ImportError: + print("debugpy module not found. Please install it using pip.") + return + + debugpy.listen((self.__host, self.__port)) + debugpy.wait_for_client() def connect_to_eclipse(self): - raise NotImplementedError() + print("Eclipse is not implemented yet")