]> git.mdlowis.com Git - proto/aas.git/commitdiff
fixed up gdb view and fixed a bug in returning from functions
authorMike Lowis <mike.lowis@gentex.com>
Fri, 1 Dec 2023 20:17:13 +0000 (15:17 -0500)
committerMike Lowis <mike.lowis@gentex.com>
Fri, 1 Dec 2023 20:17:13 +0000 (15:17 -0500)
aas.rb
cerise.m
stack_dump.py

diff --git a/aas.rb b/aas.rb
index 20a5314261b292d46c307a2ab4b32a7dd48aa808..756a8898af81f7399fcbc8179fd4c1e13c9d69c0 100755 (executable)
--- a/aas.rb
+++ b/aas.rb
@@ -321,13 +321,13 @@ class Function
   end
 
   def get_local(num)
-    emit "movq      #{-8*(num)}(%rbp), %rax"
+    emit "movq      #{-8*(num+1)}(%rbp), %rax"
     emit "pushq     %rax"
   end
 
   def set_local(num)
     emit "popq      %rax"
-    emit "movq      %rax, #{-8*num}(%rbp)"
+    emit "movq      %rax, #{-8*(num+1)}(%rbp)"
   end
 
   def locals(count)
@@ -335,6 +335,7 @@ class Function
   end
 
   def ret
+    emit "movq      %rbp, %rsp"
     emit "popq      %rbp"
     if @nargs > 0 then
       emit "ret       $#{@nargs * 8}"
index 2b22b03e9c8b5060174e495fc18fb91c60f3ad52..94d3da28a8f5ca5e01a4e5a11fe5410569f1673c 100644 (file)
--- a/cerise.m
+++ b/cerise.m
@@ -3,7 +3,7 @@ sum(a,b)
     def c = 5
     if (a < b)
     {
-        set c = 1
+        set c = 42
     }
     else
     {
@@ -14,5 +14,5 @@ sum(a,b)
 
 main()
 {
-    return sum(1+1,1)
+    return sum(1+1,3)
 }
index de6c0ab9336fce2699bf0f59f09427aa18f04c70..c7dd70c22094008075a022fa1c08ea922a8b0a71 100644 (file)
@@ -1,17 +1,39 @@
 class history_window:
     def __init__(self, tui_window):
+        self.hex = [
+            '0', '1', '2', '3' ,'4', '5', '6', '7',
+            '8', '9', 'A', 'B', 'c', 'D', 'E', 'F' ]
         self.win = tui_window
+        self.win.title = 'Stack Dump'
+        gdb.events.before_prompt.connect(lambda : self.before_prompt())
+
+    def before_prompt(self):
+        self.render()
 
     def render(self):
-        height = self.win.height
-        width = self.win.width
         lines = self.get_stack()
         self.win.erase()
         for l in lines:
-            self.win.write(l)
+            self.win.write(l + "\n")
+
+    def format_byte(self,byte):
+        val   = int.from_bytes(byte, byteorder="big", signed=False)
+        upper = self.hex[ int(val / 16) ]
+        lower = self.hex[ int(val & 15) ]
+        return (upper + lower)
 
     def get_stack(self):
-        return []
+        inf = gdb.selected_inferior()
+        stack_addr = gdb.selected_frame().read_register("rsp")
+        stack = []
+        for i in range(0, 16):
+            addr  = stack_addr + (i * 8)
+            mem   = list(inf.read_memory(addr, 8)[0:7])
+            mem.reverse()
+            lbl   = '{0:02d}'.format(i)
+            val   = ''.join([self.format_byte(elem) for i,elem in enumerate(mem)])
+            stack.append(lbl + ": 0x" + val)
+        return stack
 
     def close(self):
         gdb.events.before_prompt.disconnect(self._before_prompt_listener)