scripts/symbolize.py: print path of ELF files

Show which file corresponds to each ELF binary in a TA. Symbolic links
are followed, so that dynamic libraries are likely shown with their
user-friendly name (libfoo.so) rather than their UUID (<uuid>.elf) --
see commit 01b8b5ce011d ("TA dev kit: when building a shared library,
create symlink with UUID").

Signed-off-by: Jerome Forissier <jerome.forissier@linaro.org>
Reviewed-by: Joakim Bech <joakim.bech@linaro.org>
diff --git a/scripts/symbolize.py b/scripts/symbolize.py
index ac476e5..bbdd9b2 100755
--- a/scripts/symbolize.py
+++ b/scripts/symbolize.py
@@ -329,6 +329,13 @@
         self._regions = []   # [[addr, size, elf_idx, saved line], ...]
         self._elfs = {0: ["tee.elf", 0]}  # {idx: [uuid, load_addr], ...}
 
+
+    def pretty_print_path(self, path):
+        if self._strip_path:
+            return re.sub(re.escape(self._strip_path) + '/*', '', path)
+        return path
+
+
     def write(self, line):
             if self._call_stack_found:
                 match = re.search(STACK_ADDR_RE, line)
@@ -339,9 +346,7 @@
                     self._out.write(line[:pre])
                     self._out.write(addr)
                     res = self.resolve(addr)
-                    if self._strip_path:
-                        res = re.sub(re.escape(self._strip_path) + '/*', '',
-                                     res)
+                    res = self.pretty_print_path(res)
                     self._out.write(' ' + res)
                     self._out.write(line[post:])
                     return
@@ -385,7 +390,13 @@
                     for k in self._elfs:
                         e = self._elfs[k]
                         if (len(e) >= 3):
-                            self._out.write(e[2])
+                            self._out.write(e[2].strip())
+                        elf = self.get_elf(e[0])
+                        if elf:
+                            rpath = os.path.realpath(elf)
+                            path = self.pretty_print_path(rpath)
+                            self._out.write(' (' + path + ')')
+                        self._out.write('\n')
                 # Here is a good place to resolve the abort address because we
                 # have all the information we need
                 if self._saved_abort_line: