From: Tom de Vries Date: Tue, 26 Sep 2023 13:51:27 +0000 (+0200) Subject: [gdb/dap] Fix dap for python < 3.8 X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=fc21e0f029c51687c2b4ca686d0b773ad5efeff4;p=binutils-gdb.git [gdb/dap] Fix dap for python < 3.8 With any gdb.dap test and python 3.6 I run into: ... Error occurred in Python: 'code' object has no attribute 'co_posonlyargcount' ERROR: eof reading json header ... The attribute is not supported before python 3.8, which introduced the "Positional−only Parameters" concept. Fix this by using try/except AttributeError. Tested on x86_64-linux: - openSUSE Leap 15.4 with python 3.6, and - openSUSE Tumbleweed with python 3.11.5. Approved-By: Tom Tromey --- diff --git a/gdb/python/lib/gdb/dap/server.py b/gdb/python/lib/gdb/dap/server.py index d84bca5d1fc..62bf240c1e9 100644 --- a/gdb/python/lib/gdb/dap/server.py +++ b/gdb/python/lib/gdb/dap/server.py @@ -168,7 +168,11 @@ def request(name): global _commands code = func.__code__ # We don't permit requests to have positional arguments. - assert code.co_posonlyargcount == 0 + try: + assert code.co_posonlyargcount == 0 + except AttributeError: + # Attribute co_posonlyargcount is supported starting python 3.8. + pass assert code.co_argcount == 0 # A request must have a **args parameter. assert code.co_flags & inspect.CO_VARKEYWORDS