aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrew Burgess <aburgess@redhat.com>2025-09-01 17:00:15 +0100
committerAndrew Burgess <aburgess@redhat.com>2025-09-04 22:18:59 +0100
commit650400cb534ef894e9b31939594e1e79832d1030 (patch)
treeb2aa8b49fd09fa44d2913855c46f423a2ce13f2e
parentb652ce7b808cd81346da587e4b4f7c3754c9d98e (diff)
downloadbinutils-650400cb534ef894e9b31939594e1e79832d1030.zip
binutils-650400cb534ef894e9b31939594e1e79832d1030.tar.gz
binutils-650400cb534ef894e9b31939594e1e79832d1030.tar.bz2
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 "<unavailable>". 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 <christina.schimpe@intel.com>
-rw-r--r--gdb/python/lib/gdb/dap/varref.py6
1 files changed, 5 insertions, 1 deletions
diff --git a/gdb/python/lib/gdb/dap/varref.py b/gdb/python/lib/gdb/dap/varref.py
index 1b54fe7..d18197b 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)