Add type-checking to DAP requests
authorTom Tromey <tromey@adacore.com>
Thu, 11 May 2023 18:20:05 +0000 (12:20 -0600)
committerTom Tromey <tromey@adacore.com>
Mon, 12 Jun 2023 18:09:28 +0000 (12:09 -0600)
commit510586589e74f2ff27f4c563daa395a22c68501c
tree60b085e0aa026e63a65b32c3b323fec380a00711
parent5e20b4cd17c6627f93e2618f369e62228a38367e
Add type-checking to DAP requests

It occurred to me recently that gdb's DAP implementation should
probably check the types of objects coming from the client.  This
patch implements this idea by reusing Python's existing type
annotations, and supplying a decorator that verifies these at runtime.

Python doesn't make it very easy to do runtime type-checking, so the
core of the checker is written by hand.  I haven't tried to make a
fully generic runtime type checker.  Instead, this only checks the
subset that is needed by DAP.  For example, only keyword-only
functions are handled.

Furthermore, in a few spots, it wasn't convenient to spell out the
type that is accepted.  I've added a couple of comments to this effect
in breakpoint.py.

I've tried to make this code compatible with older versions of Python,
but I've only been able to try it with 3.9 and 3.10.
13 files changed:
gdb/data-directory/Makefile.in
gdb/python/lib/gdb/dap/breakpoint.py
gdb/python/lib/gdb/dap/bt.py
gdb/python/lib/gdb/dap/disassemble.py
gdb/python/lib/gdb/dap/evaluate.py
gdb/python/lib/gdb/dap/launch.py
gdb/python/lib/gdb/dap/memory.py
gdb/python/lib/gdb/dap/next.py
gdb/python/lib/gdb/dap/scopes.py
gdb/python/lib/gdb/dap/server.py
gdb/python/lib/gdb/dap/typecheck.py [new file with mode: 0644]
gdb/testsuite/gdb.dap/type_check.exp [new file with mode: 0644]
gdb/testsuite/gdb.dap/type_check.py [new file with mode: 0644]