public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
* [PATCH v2] gdb/DAP Fix disassemble bug
@ 2023-06-26 22:20 Simon Farre
  0 siblings, 0 replies; only message in thread
From: Simon Farre @ 2023-06-26 22:20 UTC (permalink / raw)
  To: gdb-patches; +Cc: tom, Simon Farre

v2.
Since GDB's current design apparently isn't well suited to backwards
disassembly, I've changed the patch to just return "invalid values"
prior to "current pc".

Though one approach would be to use dwarf's line number
program info to get "logical breakpoint locations" and disassemble from
these as "sources of known truth". This would require that parts of my
"next expression patch", that also works with DAP's "next statement"
request gets accepted, so that the line number program stuff can be used)

v1.
Fixes disassembleRequest

The field instructionOffset can be negative. Previous patch made it so
that sometimes the request got calculated to 0 instructions, when it
meant to retrieve disasm for -50 to 0 (current position).
---
 gdb/python/lib/gdb/dap/disassemble.py | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)

diff --git a/gdb/python/lib/gdb/dap/disassemble.py b/gdb/python/lib/gdb/dap/disassemble.py
index bc091eb2c89..c82b2ffcff1 100644
--- a/gdb/python/lib/gdb/dap/disassemble.py
+++ b/gdb/python/lib/gdb/dap/disassemble.py
@@ -27,8 +27,12 @@ def _disassemble(pc, skip_insns, count):
         # Maybe there was no frame.
         arch = gdb.selected_inferior().architecture()
     result = []
-    total_count = skip_insns + count
-    for elt in arch.disassemble(pc, count=total_count)[skip_insns:]:
+    if skip_insns < 0:
+        for i in range(0, -skip_insns):
+            result.append({"address": 0, "instruction": "unknown"})
+        skip_insns = 0
+
+    for elt in arch.disassemble(pc, count=count + skip_insns)[skip_insns:]:
         result.append(
             {
                 "address": hex(elt["addr"]),
@@ -50,7 +54,7 @@ def disassemble(
     instructionCount: int,
     **extra
 ):
-    pc = int(memoryReference, 0) + offset
+    pc = int(memoryReference, 0)
     return send_gdb_with_response(
         lambda: _disassemble(pc, instructionOffset, instructionCount)
     )
-- 
2.41.0


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

only message in thread, other threads:[~2023-06-26 22:20 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-06-26 22:20 [PATCH v2] gdb/DAP Fix disassemble bug Simon Farre

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).