[Skiboot] [PATCH 2/3] mambo_utils: add p_str <addr> [limit]

Oliver O'Halloran oohall at gmail.com
Fri Dec 2 16:38:59 AEDT 2016


Adds a helper function to mambo_utils.tcl that prints the NUL terminated
string at <addr>, and optionally limits the output to a fixed number of
characters.

Signed-off-by: Oliver O'Halloran <oohall at gmail.com>
---
 external/mambo/mambo_utils.tcl | 19 +++++++++++++++++++
 1 file changed, 19 insertions(+)

diff --git a/external/mambo/mambo_utils.tcl b/external/mambo/mambo_utils.tcl
index e1243432cdaf..879db92528a8 100644
--- a/external/mambo/mambo_utils.tcl
+++ b/external/mambo/mambo_utils.tcl
@@ -161,6 +161,25 @@ proc hexdump { location count }    {
     }
 }
 
+proc get_char { addr } {
+    return [expr [mysim memory display "$addr" 1]]
+}
+
+proc p_str { addr { limit 0 } } {
+    set addr_limit 0xfffffffffffffffff
+    if { $limit > 0 } { set addr_limit [expr $limit + $addr] }
+    set s ""
+
+    for {} { [get_char "$addr"] != 0} { incr addr 1 } {
+        # memory display returns hex values with a leading 0x
+        set c [format %c [get_char "$addr"]]
+        set s [string cat "$s" "$c"]
+        if { $addr == $addr_limit } { break }
+    }
+
+    puts "$s"
+}
+
 proc slbv {} {
     puts [mysim cpu 0 display slb valid]
 }
-- 
2.5.5



More information about the Skiboot mailing list