diff mbox series

[kvm-unit-tests,v2,2/3] pretty_print_stacks: support unknown line numbers

Message ID 20230404185048.2824384-3-nsg@linux.ibm.com (mailing list archive)
State New, archived
Headers show
Series Improve stack pretty printing | expand

Commit Message

Nina Schoetterl-Glausch April 4, 2023, 6:50 p.m. UTC
Handle the case where addr2line cannot determine a line number.
Skip printing lines for this frame in this case.

Fixes: a9143a24 ("scripts: pretty print stack traces")
Tested-by: Thomas Huth <thuth@redhat.com>
Signed-off-by: Nina Schoetterl-Glausch <nsg@linux.ibm.com>
---
 scripts/pretty_print_stacks.py | 27 ++++++++++++++-------------
 1 file changed, 14 insertions(+), 13 deletions(-)
diff mbox series

Patch

diff --git a/scripts/pretty_print_stacks.py b/scripts/pretty_print_stacks.py
index ba6f0825..1a27f309 100755
--- a/scripts/pretty_print_stacks.py
+++ b/scripts/pretty_print_stacks.py
@@ -37,23 +37,24 @@  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 [^ ]*/kvm-unit-tests/([^ ]*):(([0-9]+)|\?)(.*)', line)
         if m is None:
             puts('%s\n' % line)
             return
 
-        head, path, line, tail = m.groups()
-        line = int(line)
-        puts('%s at %s:%d%s\n' % (head.decode(), path.decode(), line, tail.decode()))
-        try:
-            lines = open(path).readlines()
-        except IOError:
-            continue
-        if line > 1:
-            puts('        %s\n' % lines[line - 2].rstrip())
-        puts('      > %s\n' % lines[line - 1].rstrip())
-        if line < len(lines):
-            puts('        %s\n' % lines[line].rstrip())
+        head, path, maybeline, line, tail = m.groups()
+        puts('%s at %s:%s%s\n' % (head.decode(), path.decode(), maybeline.decode(), tail.decode()))
+        if line:
+            line = int(line)
+            try:
+                lines = open(path).readlines()
+            except IOError:
+                continue
+            if line > 1:
+                puts('        %s\n' % lines[line - 2].rstrip())
+            puts('      > %s\n' % lines[line - 1].rstrip())
+            if line < len(lines):
+                puts('        %s\n' % lines[line].rstrip())
 
 def main():
     if len(sys.argv) != 2: