[kvm-unit-tests PATCH v2 3/3] pretty_print_stacks: modify relative path calculation

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Don't assume we can get a relative path by cutting of certain prefixes,
since this isn't guaranteed to work.
Instead use a library function.
Also normalize paths in order to take care of symlinks.

Fixes: a9143a24 ("scripts: pretty print stack traces")
Tested-by: Thomas Huth <thuth@xxxxxxxxxx>
Signed-off-by: Nina Schoetterl-Glausch <nsg@xxxxxxxxxxxxx>
---
 scripts/pretty_print_stacks.py | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/scripts/pretty_print_stacks.py b/scripts/pretty_print_stacks.py
index 1a27f309..90026b72 100755
--- a/scripts/pretty_print_stacks.py
+++ b/scripts/pretty_print_stacks.py
@@ -4,6 +4,7 @@ import re
 import subprocess
 import sys
 import traceback
+import os
 
 config = {}
 
@@ -25,8 +26,8 @@ def pretty_print_stack(binary, line):
             addrs[i] = '%lx' % max((int(addrs[i], 16) - 1), 0)
 
     # Output like this:
-    #        0x004002be: start64 at path/to/kvm-unit-tests/x86/cstart64.S:208
-    #         (inlined by) test_ept_violation at path/to/kvm-unit-tests/x86/vmx_tests.c:1719 (discriminator 1)
+    #        0x004002be: start64 at path/to/kvm-unit-tests-repo-worktree/x86/cstart64.S:208
+    #         (inlined by) test_ept_violation at path/to/kvm-unit-tests-repo-worktree/x86/vmx_tests.c:1719 (discriminator 1)
     cmd = [config.get('ADDR2LINE', 'addr2line'), '-e', binary, '-i', '-f', '--pretty', '--address']
     cmd.extend(addrs)
 
@@ -37,12 +38,13 @@ def pretty_print_stack(binary, line):
         return
 
     for line in out.splitlines():
-        m = re.match(b'(.*) at [^ ]*/kvm-unit-tests/([^ ]*):(([0-9]+)|\?)(.*)', line)
+        m = re.match(b'(.*) at (.*):(([0-9]+)|\?)([^:]*)', line)
         if m is None:
             puts('%s\n' % line)
             return
 
         head, path, maybeline, line, tail = m.groups()
+        path = os.path.relpath(os.path.realpath(path), start=os.path.realpath(os.getcwdb()))
         puts('%s at %s:%s%s\n' % (head.decode(), path.decode(), maybeline.decode(), tail.decode()))
         if line:
             line = int(line)
-- 
2.37.2




[Index of Archives]     [KVM ARM]     [KVM ia64]     [KVM ppc]     [Virtualization Tools]     [Spice Development]     [Libvirt]     [Libvirt Users]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite Questions]     [Linux Kernel]     [Linux SCSI]     [XFree86]

  Powered by Linux