public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: Simon Farre <simon.farre.cx@gmail.com>
To: gdb-patches@sourceware.org
Cc: tom@tromey.com, Simon Farre <simon.farre.cx@gmail.com>
Subject: [PATCH v2] gdb/DAP Fix disassemble bug
Date: Tue, 27 Jun 2023 00:20:02 +0200	[thread overview]
Message-ID: <20230626222002.39842-1-simon.farre.cx@gmail.com> (raw)

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


                 reply	other threads:[~2023-06-26 22:20 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230626222002.39842-1-simon.farre.cx@gmail.com \
    --to=simon.farre.cx@gmail.com \
    --cc=gdb-patches@sourceware.org \
    --cc=tom@tromey.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).