This is an automated email from the ASF dual-hosted git repository.

xiaoxiang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx.git


The following commit(s) were added to refs/heads/master by this push:
     new 191dbcc4f1 gdb/debug: add debugpy to debug python code
191dbcc4f1 is described below

commit 191dbcc4f19671e3659856e37055219fcb6a4fde
Author: xuxingliang <[email protected]>
AuthorDate: Tue Oct 22 16:05:18 2024 +0800

    gdb/debug: add debugpy to debug python code
    
    Usage:
    (gdb) debugpy
    Waiting for connection at localhost:5678
    
    In VSCode, add new configuration in launch.
    {
      "name": "Python Debugger: Remote Attach",
      "type": "debugpy",
      "request": "attach",
      "connect": {
        "host": "localhost",
        "port": 5678
      }
    }
    
    and launch.
    
    Signed-off-by: xuxingliang <[email protected]>
---
 tools/gdb/nuttxgdb/debug.py | 62 +++++++++++++++++++++++++++++++++++++++++++++
 tools/gdb/requirements.txt  | 16 +++++++++---
 2 files changed, 75 insertions(+), 3 deletions(-)

diff --git a/tools/gdb/nuttxgdb/debug.py b/tools/gdb/nuttxgdb/debug.py
new file mode 100644
index 0000000000..5303bd2a16
--- /dev/null
+++ b/tools/gdb/nuttxgdb/debug.py
@@ -0,0 +1,62 @@
+############################################################################
+# tools/gdb/nuttxgdb/debug.py
+#
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements.  See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.  The
+# ASF licenses this file to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance with the
+# License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+# License for the specific language governing permissions and limitations
+# under the License.
+#
+############################################################################
+
+import argparse
+
+import gdb
+
+from . import utils
+
+
+class DebugPy(gdb.Command):
+    """Start debugpy server, so we can debug python code from IDE like 
VSCode"""
+
+    def __init__(self):
+        debugpy = utils.import_check("debugpy", errmsg="Please pip install 
debugpy")
+        if not debugpy:
+            return
+
+        self.debugpy = debugpy
+        super().__init__("debugpy", gdb.COMMAND_USER)
+
+    def invoke(self, args, from_tty):
+        debugpy = self.debugpy
+        if debugpy.is_client_connected():
+            gdb.write("debugpy is already running.\n")
+            return
+
+        parser = argparse.ArgumentParser(description=DebugPy.__doc__)
+        parser.add_argument(
+            "-p",
+            "--port",
+            default=5678,
+            type=int,
+            help="Server listening port",
+        )
+
+        try:
+            args = parser.parse_args(gdb.string_to_argv(args))
+        except SystemExit:
+            return
+
+        debugpy.listen(args.port)
+        gdb.write(f"Waiting for connection at localhost:{args.port}\n")
+        debugpy.wait_for_client()
+        gdb.write("Debugger connected.\n")
diff --git a/tools/gdb/requirements.txt b/tools/gdb/requirements.txt
index 8aacaaeab1..0aed2fa477 100644
--- a/tools/gdb/requirements.txt
+++ b/tools/gdb/requirements.txt
@@ -1,3 +1,13 @@
-matplotlib
-numpy
-pyelftools
+contourpy==1.3.0
+cycler==0.12.1
+debugpy==1.8.7
+fonttools==4.54.1
+kiwisolver==1.4.7
+matplotlib==3.9.2
+numpy==2.1.2
+packaging==24.1
+pillow==11.0.0
+pyelftools==0.31
+pyparsing==3.2.0
+python-dateutil==2.9.0.post0
+six==1.16.0

Reply via email to