From: Waldemar Kozaczuk <jwkozac...@gmail.com>
Committer: Waldemar Kozaczuk <jwkozac...@gmail.com>
Branch: master

trace.py: add option to show multiline backtrace

The format of backtrace output from trace.py is not very
human friendly so this patch adds new option - '-l', '--multiline'.

New output:

0xffff8000021e5040 >/tests/tst-tcp  1         0.174132344 tcp_state            
tp=0xffffa00001dcd800, CLOSED -> CLOSED
  tcpcb::set_state(int)
  tcp_attach
  tcp_usr_attach
  socreate
  socreate(int, int, int)
  sys_socket
  linux_socket
  socket
  0x1000000e83b1
  0x200000700f1b
  0x1000000e859f

0xffff8000021e5040 >/tests/tst-tcp  1         0.174145515 tcp_state            
tp=0xffffa00001dcd800, CLOSED -> LISTEN
  tcpcb::set_state(int)
  tcp_usr_listen
  sys_listen
  listen
  0x1000000e842c

vs the regular one:

0xffff8000021e5040 >/tests/tst-tcp  1         0.174132344 tcp_state            
tp=0xffffa00001dcd800, CLOSED -> CLOSED   [tcpcb::set_state(int), tcp_attac h, 
tcp_usr_attach, socreate, socreate(int, int, int), sys_socket, linux_socket, 
socket, 0x1000000e83b1, 0x200000700f1b, 0x1000000e859f]
0xffff8000021e5040 >/tests/tst-tcp  1         0.174145515 tcp_state            
tp=0xffffa00001dcd800, CLOSED -> LISTEN   [tcpcb::set_state(int), tcp_usr_l 
isten, sys_listen, listen, 0x1000000e842c]

Signed-off-by: Waldemar Kozaczuk <jwkozac...@gmail.com>

---
diff --git a/scripts/loader.py b/scripts/loader.py
--- a/scripts/loader.py
+++ b/scripts/loader.py
@@ -1309,7 +1309,7 @@ def make_symbolic(addr):
 
 def dump_trace(out_func):
     indents = defaultdict(int)
-    bt_formatter = BacktraceFormatter(symbol_resolver, symbol_formatter)
+    bt_formatter = BacktraceFormatter(symbol_resolver, symbol_formatter, True)
 
     def lookup_tp(name):
         return gdb.lookup_global_symbol(name).value().dereference()
diff --git a/scripts/osv/trace.py b/scripts/osv/trace.py
--- a/scripts/osv/trace.py
+++ b/scripts/osv/trace.py
@@ -22,25 +22,29 @@ def format_time(time):
     return "%12.9f" % nanos_to_seconds(time)
 
 class BacktraceFormatter:
-    def __init__(self, resolver, formatter):
+    def __init__(self, resolver, formatter, multiline):
         self.resolver = resolver
         self.formatter = formatter
+        self.multiline = multiline
 
     def __call__(self, backtrace):
         if not backtrace:
             return ''
 
         frames = list(debug.resolve_all(self.resolver, (x - 1 for x in 
backtrace if x)))
 
-        while frames[0].name and frames[0].name.startswith("tracepoint"):
+        while frames[0].name and (frames[0].name.startswith("tracepoint") or 
frames[0].filename.endswith("trace.hh")):
             frames.pop(0)
 
-        return '   [' + ', '.join(map(self.formatter, frames)) + ']'
+        if self.multiline:
+            return '\n  ' + '\n  '.join(map(self.formatter, frames)) + '\n'
+        else:
+            return '   [' + ', '.join(map(self.formatter, frames)) + ']'
 
 def simple_symbol_formatter(src_addr):
     return '0x%x' % src_addr.addr
 
-default_backtrace_formatter = BacktraceFormatter(debug.DummyResolver(), 
simple_symbol_formatter)
+default_backtrace_formatter = BacktraceFormatter(debug.DummyResolver(), 
simple_symbol_formatter, False)
 
 class TimeRange(object):
     """
diff --git a/scripts/trace.py b/scripts/trace.py
--- a/scripts/trace.py
+++ b/scripts/trace.py
@@ -102,7 +102,7 @@ def get_backtrace_formatter(args):
     if not args.backtrace:
         return lambda backtrace: ''
 
-    return trace.BacktraceFormatter(symbol_resolver(args), 
src_addr_formatter(args))
+    return trace.BacktraceFormatter(symbol_resolver(args), 
src_addr_formatter(args), True if args.multiline else False)
 
 def list_trace(args):
     def data_formatter(sample):
@@ -667,6 +667,7 @@ def add_trace_listing_options(parser):
     add_symbol_resolution_options(parser)
     parser.add_argument("-b", "--backtrace", action="store_true", help="show 
backtrace")
     parser.add_argument("--no-header", action="store_true", help="do not show 
the header")
+    parser.add_argument("-l", "--multiline", action="store_true", help="show 
backtrace in multiple lines")
 
 def convert_dump(args):
     if os.path.isfile(args.dumpfile):

-- 
You received this message because you are subscribed to the Google Groups "OSv 
Development" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to osv-dev+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/osv-dev/0000000000007aeb8005e507ffd3%40google.com.

Reply via email to