Skip to content

Commit

Permalink
refactor(gdb): refactor gdb Debugger to be a gdb command (lvgl#7140)
Browse files Browse the repository at this point in the history
  • Loading branch information
W-Mai authored Oct 24, 2024
1 parent 7f690a2 commit a8d2cc0
Show file tree
Hide file tree
Showing 3 changed files with 81 additions and 3 deletions.
15 changes: 15 additions & 0 deletions docs/details/debugging/gdb_plugin.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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.
9 changes: 9 additions & 0 deletions scripts/gdb/lvglgdb/__init__.py
Original file line number Diff line number Diff line change
@@ -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)
60 changes: 57 additions & 3 deletions scripts/gdb/lvglgdb/debugger.py
Original file line number Diff line number Diff line change
@@ -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:
Expand All @@ -13,7 +60,14 @@ def connect_to_pycharm(self):
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")

0 comments on commit a8d2cc0

Please sign in to comment.