[Skiboot] [PATCH v2 1/2] mambo: Add addr2func for symbol resolution

Michael Neuling mikey at neuling.org
Wed Apr 17 11:54:28 AEST 2019


If you supply a VMLINUX_MAP/SKIBOOT_MAP/USER_MAP addr2func can guess
at your symbol name. ie

  systemsim % p pc
  0xC0000000002A68F8
  systemsim % addr2func [p pc]
  fdt_offset_ptr+0x78

Signed-off-by: Michael Neuling <mikey at neuling.org>

---
v2: Fix screwup with comment
---
 external/mambo/mambo_utils.tcl | 49 ++++++++++++++++++++++++++++++++++
 external/mambo/skiboot.tcl     | 15 +++++++++--
 2 files changed, 62 insertions(+), 2 deletions(-)

diff --git a/external/mambo/mambo_utils.tcl b/external/mambo/mambo_utils.tcl
index 12188559cf..9870999075 100644
--- a/external/mambo/mambo_utils.tcl
+++ b/external/mambo/mambo_utils.tcl
@@ -469,6 +469,55 @@ proc skisym { name } {
     return $ret
 }
 
+proc addr2func { addr } {
+    global skiboot_symbol_list
+    global linux_symbol_list
+    global user_symbol_list
+    global mconf
+
+    set prevname ""
+    set preva "0"
+
+    if { [ info exists linux_symbol_list ] && "$addr" >= 0xc000000000000000} {
+	foreach line $linux_symbol_list {
+	    lassign $line a type name
+	    if { "0x$a" > $addr } {
+		set o [format "0x%x" [expr $addr - "0x$preva"]]
+		return "$prevname+$o"
+	    }
+	    set prevname $name
+	    set preva $a
+	}
+    }
+    # Assume skiboot is less that 4MB big
+    if { [ info exists skiboot_symbol_list ] &&
+	 "$addr" >  $mconf(boot_load) && "$addr" <  [expr $mconf(boot_load) + 4194304] } {
+	set mapaddr [expr $addr - $mconf(boot_load)]
+
+	foreach line $skiboot_symbol_list {
+	    lassign $line a type name
+	    if { "0x$a" > $mapaddr } {
+		set o [format "0x%x" [expr $mapaddr - "0x$preva"]]
+		return "$prevname+$o"
+	    }
+	    set prevname $name
+	    set preva $a
+	}
+    }
+    if { [ info exists user_symbol_list ]  } {
+	foreach line $user_symbol_list {
+	    lassign $line a type name
+	    if { "0x$a" > $addr } {
+		set o [format "0x%x" [expr $addr - "0x$preva"]]
+		return "$prevname+$o"
+	    }
+	    set prevname $name
+	    set preva $a
+	}
+    }
+    return "+$addr"
+}
+
 proc current_insn { { t -1 } { c -1 } { p -1 }} {
     global target_t
     global target_c
diff --git a/external/mambo/skiboot.tcl b/external/mambo/skiboot.tcl
index c6176bdb54..8c2893df2c 100644
--- a/external/mambo/skiboot.tcl
+++ b/external/mambo/skiboot.tcl
@@ -141,19 +141,30 @@ if {![info exists of::encode_compat]} {
 if { [file exists mambo_utils.tcl] } then {
 	source mambo_utils.tcl
 
+	if { [info exists env(USER_MAP)] } {
+		global user_symbol_map user_symbol_list
+
+		set fp [open $env(USER_MAP) r]
+		set user_symbol_map [read $fp]
+	        set user_symbol_list [split $user_symbol_map "\n"]
+		close $fp
+	}
+
 	if { [info exists env(VMLINUX_MAP)] } {
-		global linux_symbol_map
+		global linux_symbol_map linux_symbol_list
 
 		set fp [open $env(VMLINUX_MAP) r]
 		set linux_symbol_map [read $fp]
+	        set linux_symbol_list [split $linux_symbol_map "\n"]
 		close $fp
 	}
 
 	if { [info exists env(SKIBOOT_MAP)] } {
-		global skiboot_symbol_map
+		global skiboot_symbol_map skiboot_symbol_list
 
 		set fp [open $env(SKIBOOT_MAP) r]
 		set skiboot_symbol_map [read $fp]
+	        set skiboot_symbol_list [split $skiboot_symbol_map "\n"]
 		close $fp
 	}
 }
-- 
2.20.1



More information about the Skiboot mailing list