public inbox for gdb-cvs@sourceware.org
help / color / mirror / Atom feed
* [binutils-gdb] Fix DAP frame bug with older versions of Python
@ 2023-03-14 14:04 Tom Tromey
  0 siblings, 0 replies; only message in thread
From: Tom Tromey @ 2023-03-14 14:04 UTC (permalink / raw)
  To: gdb-cvs

https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=85c72d708e60b0da9dff4db4209e257245487d1d

commit 85c72d708e60b0da9dff4db4209e257245487d1d
Author: Tom Tromey <tromey@adacore.com>
Date:   Tue Mar 14 07:05:13 2023 -0600

    Fix DAP frame bug with older versions of Python
    
    Tom de Vries pointed out that one DAP test failed on Python 3.6
    because gdb.Frame is not hashable.
    
    This patch fixes the problem by using a list to hold the frames.  This
    is less efficient but there normally won't be that many frames.
    
    Tested-by: Tom de Vries <tdevries@suse.de>

Diff:
---
 gdb/python/lib/gdb/dap/frames.py | 33 +++++++++++++++------------------
 1 file changed, 15 insertions(+), 18 deletions(-)

diff --git a/gdb/python/lib/gdb/dap/frames.py b/gdb/python/lib/gdb/dap/frames.py
index 337bbedae0f..08209d0b361 100644
--- a/gdb/python/lib/gdb/dap/frames.py
+++ b/gdb/python/lib/gdb/dap/frames.py
@@ -18,20 +18,17 @@ import gdb
 from .startup import in_gdb_thread
 
 
-# Map from frame (thread,level) pair to frame ID numbers.  Note we
-# can't use the frame itself here as it is not hashable.
-_frame_ids = {}
-
-# Map from frame ID number back to frames.
-_id_to_frame = {}
+# A list of all the frames we've reported.  A frame's index in the
+# list is its ID.  We don't use a hash here because frames are not
+# hashable.
+_all_frames = []
 
 
 # Clear all the frame IDs.
 @in_gdb_thread
 def _clear_frame_ids(evt):
-    global _frame_ids, _id_to_frame
-    _frame_ids = {}
-    _id_to_frame = {}
+    global _all_frames
+    _all_frames = []
 
 
 # Clear the frame ID map whenever the inferior runs.
@@ -41,17 +38,17 @@ gdb.events.cont.connect(_clear_frame_ids)
 @in_gdb_thread
 def frame_id(frame):
     """Return the frame identifier for FRAME."""
-    global _frame_ids, _id_to_frame
-    pair = (gdb.selected_thread().global_num, frame.level)
-    if pair not in _frame_ids:
-        id = len(_frame_ids)
-        _frame_ids[pair] = id
-        _id_to_frame[id] = frame
-    return _frame_ids[pair]
+    global _all_frames
+    for i in range(0, len(_all_frames)):
+        if _all_frames[i] == frame:
+            return i
+    result = len(_all_frames)
+    _all_frames.append(frame)
+    return result
 
 
 @in_gdb_thread
 def frame_for_id(id):
     """Given a frame identifier ID, return the corresponding frame."""
-    global _id_to_frame
-    return _id_to_frame[id]
+    global _all_frames
+    return _all_frames[id]

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2023-03-14 14:04 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-03-14 14:04 [binutils-gdb] Fix DAP frame bug with older versions of Python Tom Tromey

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).