public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: Hannes Domani <ssbssa@yahoo.de>
To: gdb-patches@sourceware.org
Subject: [PATCH 21/22] Implement memory TUI window
Date: Sat,  6 Mar 2021 18:44:49 +0100	[thread overview]
Message-ID: <20210306174450.21718-2-ssbssa@yahoo.de> (raw)
In-Reply-To: <20210306174450.21718-1-ssbssa@yahoo.de>

---
 gdb/python/lib/gdb/command/tui_windows.py | 57 +++++++++++++++++++++++
 1 file changed, 57 insertions(+)

diff --git a/gdb/python/lib/gdb/command/tui_windows.py b/gdb/python/lib/gdb/command/tui_windows.py
index 92a7a2b2f01..45ba9502878 100644
--- a/gdb/python/lib/gdb/command/tui_windows.py
+++ b/gdb/python/lib/gdb/command/tui_windows.py
@@ -712,10 +712,65 @@ class FramesWindow(TextWindow):
             var_change_handler()
 
 
+class MemoryWindow(TextWindow):
+    def __init__(self, win):
+        super(MemoryWindow, self).__init__(win, "memory")
+        self.pointer = 0
+
+    def refill(self):
+        if not self.win.is_valid():
+            return
+        self.lines = []
+        pointer = self.pointer
+        try:
+            mem = gdb.selected_inferior().read_memory(pointer, 16 * self.win.height)
+            ptr_hex_count = int(gdb.lookup_type("void").pointer().sizeof) * 2
+            ofs = 0
+            for h in range(self.win.height):
+                l = "0x%0*x  " % (ptr_hex_count, pointer + ofs)
+                l += " ".join(["%02x%02x" % (ord(mem[ofs + i]), ord(mem[ofs + i + 1])) for i in range(0, 16, 2)])
+                l += "  "
+                l += "".join([self.printable(mem[ofs + i]) for i in range(16)])
+                self.lines.append(l)
+                ofs += 16
+        except:
+            self.lines = [str(sys.exc_info()[1])]
+        self.redraw()
+
+    def vscroll(self, num):
+        self.pointer += num * 16
+        if self.pointer < 0:
+            self.pointer = 0
+        self.refill()
+
+    def printable(self, c):
+        o = ord(c)
+        if o < 0x20 or o >= 0x7f:
+            return "."
+        return c
+
+class MemoryCommand(gdb.Command):
+    """Set start pointer for memory window."""
+
+    def __init__(self):
+        super(MemoryCommand, self).__init__("memory", gdb.COMMAND_TUI, gdb.COMPLETE_EXPRESSION)
+
+    def invoke(self, arg, from_tty):
+        self.dont_repeat()
+        global custom_windows
+        if 'memory' not in custom_windows or not custom_windows['memory'].win.is_valid():
+            gdb.execute("layout memory")
+        memory_window = custom_windows['memory']
+        memory_window.pointer = long(gdb.parse_and_eval(arg))
+
+MemoryCommand()
+
+
 gdb.register_window_type("locals", LocalsWindow)
 gdb.register_window_type("display", DisplayWindow)
 gdb.register_window_type("threads", ThreadsWindow)
 gdb.register_window_type("frames", FramesWindow)
+gdb.register_window_type("memory", MemoryWindow)
 
 
 class CustomCommandWindow(TextWindow):
@@ -778,6 +833,7 @@ gdb.execute("tui new-layout locals-frames {-horizontal src 2 {locals 2 frames 1}
 gdb.execute("tui new-layout display-frames {-horizontal src 2 {display 2 frames 1} 1} 2 status 0 cmd 1")
 gdb.execute("tui new-layout locals-display-frames {-horizontal src 2 {locals 2 display 2 frames 1} 1} 3 status 0 cmd 1")
 gdb.execute("tui new-layout threads-locals-frames-display {-horizontal src 3 {threads 1 locals 2} 1 {frames 1 display 2} 1} 3 status 0 cmd 1")
+gdb.execute("tui new-layout memory memory 1 src 2 status 0 cmd 1")
 gdb.execute("tui new-layout all {-horizontal {{-horizontal asm 1 regs 1} 1 src 2} 3 {threads 1 locals 2} 1 {frames 1 display 2} 1} 3 status 0 cmd 1")
 
 gdb.execute("alias ll = layout locals")
@@ -790,4 +846,5 @@ gdb.execute("alias llf = layout locals-frames")
 gdb.execute("alias ldf = layout display-frames")
 gdb.execute("alias lldf = layout locals-display-frames")
 gdb.execute("alias ltlfd = layout threads-locals-frames-display")
+gdb.execute("alias lm = layout memory")
 gdb.execute("alias la = layout all")
-- 
2.30.1


  reply	other threads:[~2021-03-06 17:45 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <20210306174450.21718-1-ssbssa.ref@yahoo.de>
2021-03-06 17:44 ` [PATCH 20/22] Use method children instead of to_string in pretty printers Hannes Domani
2021-03-06 17:44   ` Hannes Domani [this message]
2021-03-06 17:44   ` [PATCH 22/22] Copy variable value to clipboard on middle-click Hannes Domani
2021-03-11 21:55   ` [PATCH 20/22] Use method children instead of to_string in pretty printers Tom Tromey

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=20210306174450.21718-2-ssbssa@yahoo.de \
    --to=ssbssa@yahoo.de \
    --cc=gdb-patches@sourceware.org \
    /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).