From: Andrew Burgess Date: Mon, 1 Sep 2025 16:00:15 +0000 (+0100) Subject: gdb/dap: check values are available before converting to int X-Git-Tag: gdb-17-branchpoint~24 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=650400cb534ef894e9b31939594e1e79832d1030;p=thirdparty%2Fbinutils-gdb.git gdb/dap: check values are available before converting to int In VariableReference.to_object, we try to convert a gdb.Value to an int without checking if the value is actually available. This came to light in PR gdb/33345, after the x86 CET shadow stack patches were merged. If the x86 CET shadow stack register is available on the machine, but the shadow stack feature is not enabled at run time, then the register will show as "". As the register is of type 'void *', then in the DAP code we try to add a 'memoryReference' attribute with the value of the register formatted as hex. This will fail if the register is unavailable. To test this change you'll need: (a) a machine which support the shadow stack feature, and (b) to revert the changes from commit 63b862be762e1e6e7 in the file gdb.dap/scopes.exp. Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=33345 Reviewed-By: Christina Schimpe --- diff --git a/gdb/python/lib/gdb/dap/varref.py b/gdb/python/lib/gdb/dap/varref.py index 1b54fe745fa..d18197b8450 100644 --- a/gdb/python/lib/gdb/dap/varref.py +++ b/gdb/python/lib/gdb/dap/varref.py @@ -246,7 +246,11 @@ class VariableReference(BaseReference): # changed DAP to allow memory references for any of the # variable response requests, and to lift the restriction # to pointer-to-function from Variable. - if self._value.type.strip_typedefs().code == gdb.TYPE_CODE_PTR: + if ( + self._value.type.strip_typedefs().code == gdb.TYPE_CODE_PTR + and not self._value.is_optimized_out + and not self._value.is_unavailable + ): result["memoryReference"] = hex(int(self._value)) if client_bool_capability("supportsVariableType"): result["type"] = str(self._value.type)