Tests: Disable 'stdbuf' when TAP autotime is disabled
[lttng-tools.git] / tests / utils / parse-callstack.py
index da0bab626e5d736b9a29c4a8c11c5fa28567e196..029100b6184de3e4c61d83841e65180ef724888b 100755 (executable)
@@ -1,19 +1,9 @@
-#! /usr/bin/python3
-
-# Copyright (C) - 2017 Francis Deslauriers <francis.deslauriers@efficios.com>
+#!/usr/bin/env python3
 #
-# This library is free software; you can redistribute it and/or modify it
-# under the terms of the GNU Lesser General Public License as published by the
-# Free Software Foundation; version 2.1 of the License.
+# Copyright (C) 2017 Francis Deslauriers <francis.deslauriers@efficios.com>
 #
-# This library is distributed in the hope that it will be useful, but WITHOUT
-# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
-# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License
-# for more details.
+# SPDX-License-Identifier: LGPL-2.1-only
 #
-# You should have received a copy of the GNU Lesser General Public License
-# along with this library; if not, write to the Free Software Foundation,
-# Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301 USA
 
 import sys
 import bisect
@@ -34,14 +24,25 @@ def addr2line(executable, addr):
     # Expand inlined functions
     cmd += ['--addresses', addr]
 
-    addr2line_output = subprocess.getoutput(' '.join(cmd))
+    status = subprocess.run(cmd, stdout=subprocess.PIPE, check=True)
+
+    addr2line_output = status.stdout.decode("utf-8").splitlines()
+    # addr2line's output is made of 3-tuples:
+    #   - address
+    #   - function name
+    #   - source location
+    if len(addr2line_output) % 3 != 0:
+        raise Exception('Unexpected addr2line output:\n\t{}'.format('\n\t'.join(addr2line_output)))
 
-    # Omit the last 2 lines as the caller of main can not be determine
-    fcts = [addr2line_output.split()[-2]]
+    function_names = []
+    for address_line_number in range(0, len(addr2line_output), 3):
+        function_name = addr2line_output[address_line_number + 1]
 
-    fcts = [ f for f in fcts if '??' not in f]
+        # Filter-out unresolved functions
+        if "??" not in function_name:
+            function_names.append(addr2line_output[address_line_number + 1])
 
-    return fcts
+    return function_names
 
 def extract_user_func_names(executable, raw_callstack):
     """
This page took 0.024356 seconds and 4 git commands to generate.