This revision was automatically updated to reflect the committed changes.
Closed by commit rGb321b429416e: [lldb/Test] Add a trace method to replace 
print statements. (authored by JDevlieghere).
Herald added a project: LLDB.

Changed prior to commit:
  https://reviews.llvm.org/D80448?vs=265768&id=266056#toc

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D80448/new/

https://reviews.llvm.org/D80448

Files:
  lldb/packages/Python/lldbsuite/test/lldbtest.py
  lldb/test/API/benchmarks/stepping/TestSteppingSpeed.py
  lldb/test/API/commands/target/basic/TestTargetCommand.py
  
lldb/test/API/functionalities/breakpoint/breakpoint_conditions/TestBreakpointConditions.py
  
lldb/test/API/functionalities/breakpoint/serialize/TestBreakpointSerialization.py
  
lldb/test/API/functionalities/data-formatter/data-formatter-skip-summary/TestDataFormatterSkipSummary.py
  lldb/test/API/functionalities/load_unload/TestLoadUnload.py
  lldb/test/API/lang/c/register_variables/TestRegisterVariables.py
  lldb/test/API/lang/cpp/class_types/TestClassTypesDisassembly.py
  lldb/test/API/lang/objc/blocks/TestObjCIvarsInBlocks.py
  lldb/test/API/lang/objc/foundation/TestSymbolTable.py
  lldb/test/API/python_api/breakpoint/TestBreakpointAPI.py
  lldb/test/API/python_api/event/TestEvents.py
  lldb/test/API/python_api/frame/TestFrames.py
  lldb/test/API/python_api/frame/inlines/TestInlinedFrame.py
  lldb/test/API/python_api/function_symbol/TestDisasmAPI.py
  lldb/test/API/python_api/function_symbol/TestSymbolAPI.py
  lldb/test/API/python_api/target/TestTargetAPI.py
  lldb/test/API/python_api/thread/TestThreadAPI.py
  lldb/test/API/tools/lldb-server/TestGdbRemoteAuxvSupport.py
  lldb/test/API/tools/lldb-server/TestGdbRemoteExpeditedRegisters.py
  lldb/test/API/tools/lldb-server/TestGdbRemoteRegisterState.py
  lldb/test/API/tools/lldb-server/TestLldbGdbServer.py

Index: lldb/test/API/tools/lldb-server/TestLldbGdbServer.py
===================================================================
--- lldb/test/API/tools/lldb-server/TestLldbGdbServer.py
+++ lldb/test/API/tools/lldb-server/TestLldbGdbServer.py
@@ -10,9 +10,6 @@
 the initial set of tests implemented.
 """
 
-from __future__ import division, print_function
-
-
 import unittest2
 import gdbremote_testcase
 import lldbgdbserverutils
@@ -1442,7 +1439,7 @@
         # Write flipped bit pattern of existing value to each register.
         (successful_writes, failed_writes) = self.flip_all_bits_in_each_register_value(
             gpr_reg_infos, endian)
-        # print("successful writes: {}, failed writes: {}".format(successful_writes, failed_writes))
+        self.trace("successful writes: {}, failed writes: {}".format(successful_writes, failed_writes))
         self.assertTrue(successful_writes > 0)
 
     # Note: as of this moment, a hefty number of the GPR writes are failing with E32 (everything except rax-rdx, rdi, rsi, rbp).
Index: lldb/test/API/tools/lldb-server/TestGdbRemoteRegisterState.py
===================================================================
--- lldb/test/API/tools/lldb-server/TestGdbRemoteRegisterState.py
+++ lldb/test/API/tools/lldb-server/TestGdbRemoteRegisterState.py
@@ -1,6 +1,3 @@
-from __future__ import print_function
-
-
 import gdbremote_testcase
 from lldbsuite.test.decorators import *
 from lldbsuite.test.lldbtest import *
@@ -50,7 +47,7 @@
             self.assertIsNotNone(threads)
             thread_id = threads[0]
             self.assertIsNotNone(thread_id)
-            # print("Running on thread: 0x{:x}".format(thread_id))
+            self.trace("Running on thread: 0x{:x}".format(thread_id))
         else:
             thread_id = None
 
@@ -64,22 +61,22 @@
         (success, state_id) = self.parse_QSaveRegisterState_response(context)
         self.assertTrue(success)
         self.assertIsNotNone(state_id)
-        # print("saved register state id: {}".format(state_id))
+        self.trace("saved register state id: {}".format(state_id))
 
         # Remember initial register values.
         initial_reg_values = self.read_register_values(
             gpr_reg_infos, endian, thread_id=thread_id)
-        # print("initial_reg_values: {}".format(initial_reg_values))
+        self.trace("initial_reg_values: {}".format(initial_reg_values))
 
         # Flip gpr register values.
         (successful_writes, failed_writes) = self.flip_all_bits_in_each_register_value(
             gpr_reg_infos, endian, thread_id=thread_id)
-        # print("successful writes: {}, failed writes: {}".format(successful_writes, failed_writes))
+        self.trace("successful writes: {}, failed writes: {}".format(successful_writes, failed_writes))
         self.assertTrue(successful_writes > 0)
 
         flipped_reg_values = self.read_register_values(
             gpr_reg_infos, endian, thread_id=thread_id)
-        # print("flipped_reg_values: {}".format(flipped_reg_values))
+        self.trace("flipped_reg_values: {}".format(flipped_reg_values))
 
         # Restore register values.
         self.reset_test_sequence()
@@ -91,7 +88,7 @@
         # Verify registers match initial register values.
         final_reg_values = self.read_register_values(
             gpr_reg_infos, endian, thread_id=thread_id)
-        # print("final_reg_values: {}".format(final_reg_values))
+        self.trace("final_reg_values: {}".format(final_reg_values))
         self.assertIsNotNone(final_reg_values)
         self.assertEqual(final_reg_values, initial_reg_values)
 
Index: lldb/test/API/tools/lldb-server/TestGdbRemoteExpeditedRegisters.py
===================================================================
--- lldb/test/API/tools/lldb-server/TestGdbRemoteExpeditedRegisters.py
+++ lldb/test/API/tools/lldb-server/TestGdbRemoteExpeditedRegisters.py
@@ -1,6 +1,3 @@
-from __future__ import print_function
-
-
 import gdbremote_testcase
 from lldbsuite.test.decorators import *
 from lldbsuite.test.lldbtest import *
@@ -59,7 +56,7 @@
 
         # Ensure the expedited registers contained it.
         self.assertTrue(reg_info["lldb_register_index"] in expedited_registers)
-        # print("{} reg_info:{}".format(generic_register_name, reg_info))
+        self.trace("{} reg_info:{}".format(generic_register_name, reg_info))
 
     def stop_notification_contains_any_registers(self):
         # Generate a stop reply, parse out expedited registers from stop
Index: lldb/test/API/tools/lldb-server/TestGdbRemoteAuxvSupport.py
===================================================================
--- lldb/test/API/tools/lldb-server/TestGdbRemoteAuxvSupport.py
+++ lldb/test/API/tools/lldb-server/TestGdbRemoteAuxvSupport.py
@@ -1,6 +1,3 @@
-from __future__ import print_function
-
-
 import gdbremote_testcase
 from lldbsuite.test.decorators import *
 from lldbsuite.test.lldbtest import *
@@ -119,7 +116,7 @@
         # Ensure auxv data is a multiple of 2*word_size (there should be two
         # unsigned long fields per auxv entry).
         self.assertEqual(len(auxv_data) % (2 * word_size), 0)
-        # print("auxv contains {} entries".format(len(auxv_data) / (2*word_size)))
+        self.trace("auxv contains {} entries".format(len(auxv_data) / (2*word_size)))
 
     @debugserver_test
     def test_auxv_data_is_correct_size_debugserver(self):
@@ -159,7 +156,7 @@
         for auxv_key in auxv_dict:
             self.assertTrue(auxv_key >= 1)
             self.assertTrue(auxv_key <= 1000)
-        # print("auxv dict: {}".format(auxv_dict))
+        self.trace("auxv dict: {}".format(auxv_dict))
 
     @debugserver_test
     def test_auxv_keys_look_valid_debugserver(self):
Index: lldb/test/API/python_api/thread/TestThreadAPI.py
===================================================================
--- lldb/test/API/python_api/thread/TestThreadAPI.py
+++ lldb/test/API/python_api/thread/TestThreadAPI.py
@@ -100,7 +100,7 @@
         self.runCmd("process status")
 
         proc_of_thread = thread.GetProcess()
-        #print("proc_of_thread:", proc_of_thread)
+        self.trace("proc_of_thread:", proc_of_thread)
         self.assertTrue(proc_of_thread.GetProcessID()
                         == process.GetProcessID())
 
Index: lldb/test/API/python_api/target/TestTargetAPI.py
===================================================================
--- lldb/test/API/python_api/target/TestTargetAPI.py
+++ lldb/test/API/python_api/target/TestTargetAPI.py
@@ -359,8 +359,8 @@
         # Now create the two breakpoints inside function 'a'.
         breakpoint1 = target.BreakpointCreateByLocation('main.c', self.line1)
         breakpoint2 = target.BreakpointCreateByLocation('main.c', self.line2)
-        #print("breakpoint1:", breakpoint1)
-        #print("breakpoint2:", breakpoint2)
+        self.trace("breakpoint1:", breakpoint1)
+        self.trace("breakpoint2:", breakpoint2)
         self.assertTrue(breakpoint1 and
                         breakpoint1.GetNumLocations() == 1,
                         VALID_BREAKPOINT)
@@ -402,8 +402,8 @@
 
         address2 = lineEntry.GetStartAddress()
 
-        #print("address1:", address1)
-        #print("address2:", address2)
+        self.trace("address1:", address1)
+        self.trace("address2:", address2)
 
         # Now call SBTarget.ResolveSymbolContextForAddress() with the addresses
         # from our line entry.
@@ -413,15 +413,15 @@
             address2, lldb.eSymbolContextEverything)
 
         self.assertTrue(context1 and context2)
-        #print("context1:", context1)
-        #print("context2:", context2)
+        self.trace("context1:", context1)
+        self.trace("context2:", context2)
 
         # Verify that the context point to the same function 'a'.
         symbol1 = context1.GetSymbol()
         symbol2 = context2.GetSymbol()
         self.assertTrue(symbol1 and symbol2)
-        #print("symbol1:", symbol1)
-        #print("symbol2:", symbol2)
+        self.trace("symbol1:", symbol1)
+        self.trace("symbol2:", symbol2)
 
         from lldbsuite.test.lldbutil import get_description
         desc1 = get_description(symbol1)
Index: lldb/test/API/python_api/function_symbol/TestSymbolAPI.py
===================================================================
--- lldb/test/API/python_api/function_symbol/TestSymbolAPI.py
+++ lldb/test/API/python_api/function_symbol/TestSymbolAPI.py
@@ -38,8 +38,8 @@
         # Now create the two breakpoints inside function 'a'.
         breakpoint1 = target.BreakpointCreateByLocation('main.c', self.line1)
         breakpoint2 = target.BreakpointCreateByLocation('main.c', self.line2)
-        #print("breakpoint1:", breakpoint1)
-        #print("breakpoint2:", breakpoint2)
+        self.trace("breakpoint1:", breakpoint1)
+        self.trace("breakpoint2:", breakpoint2)
         self.assertTrue(breakpoint1 and
                         breakpoint1.GetNumLocations() == 1,
                         VALID_BREAKPOINT)
Index: lldb/test/API/python_api/function_symbol/TestDisasmAPI.py
===================================================================
--- lldb/test/API/python_api/function_symbol/TestDisasmAPI.py
+++ lldb/test/API/python_api/function_symbol/TestDisasmAPI.py
@@ -38,8 +38,8 @@
         # Now create the two breakpoints inside function 'a'.
         breakpoint1 = target.BreakpointCreateByLocation('main.c', self.line1)
         breakpoint2 = target.BreakpointCreateByLocation('main.c', self.line2)
-        #print("breakpoint1:", breakpoint1)
-        #print("breakpoint2:", breakpoint2)
+        self.trace("breakpoint1:", breakpoint1)
+        self.trace("breakpoint2:", breakpoint2)
         self.assertTrue(breakpoint1 and
                         breakpoint1.GetNumLocations() == 1,
                         VALID_BREAKPOINT)
@@ -64,7 +64,7 @@
         self.assertTrue(lineEntry.GetLine() == self.line1)
 
         address1 = lineEntry.GetStartAddress()
-        #print("address1:", address1)
+        self.trace("address1:", address1)
 
         # Now call SBTarget.ResolveSymbolContextForAddress() with address1.
         context1 = target.ResolveSymbolContextForAddress(
@@ -103,15 +103,11 @@
             print("disassembly=>\n", disasm_output)
 
         sa1 = symbol.GetStartAddress()
-        #print("sa1:", sa1)
-        #print("sa1.GetFileAddress():", hex(sa1.GetFileAddress()))
-        #ea1 = symbol.GetEndAddress()
-        #print("ea1:", ea1)
+        self.trace("sa1:", sa1)
+        self.trace("sa1.GetFileAddress():", hex(sa1.GetFileAddress()))
         sa2 = function.GetStartAddress()
-        #print("sa2:", sa2)
-        #print("sa2.GetFileAddress():", hex(sa2.GetFileAddress()))
-        #ea2 = function.GetEndAddress()
-        #print("ea2:", ea2)
+        self.trace("sa2:", sa2)
+        self.trace("sa2.GetFileAddress():", hex(sa2.GetFileAddress()))
         self.assertTrue(sa1 and sa2 and sa1 == sa2,
                         "The two starting addresses should be the same")
 
Index: lldb/test/API/python_api/frame/inlines/TestInlinedFrame.py
===================================================================
--- lldb/test/API/python_api/frame/inlines/TestInlinedFrame.py
+++ lldb/test/API/python_api/frame/inlines/TestInlinedFrame.py
@@ -37,7 +37,7 @@
 
         # Now create a breakpoint on main.c by the name of 'inner_inline'.
         breakpoint = target.BreakpointCreateByName('inner_inline', 'a.out')
-        #print("breakpoint:", breakpoint)
+        self.trace("breakpoint:", breakpoint)
         self.assertTrue(breakpoint and
                         breakpoint.GetNumLocations() > 1,
                         VALID_BREAKPOINT)
Index: lldb/test/API/python_api/frame/TestFrames.py
===================================================================
--- lldb/test/API/python_api/frame/TestFrames.py
+++ lldb/test/API/python_api/frame/TestFrames.py
@@ -28,7 +28,7 @@
 
         # Now create a breakpoint on main.c by name 'c'.
         breakpoint = target.BreakpointCreateByName('c', 'a.out')
-        #print("breakpoint:", breakpoint)
+        self.trace("breakpoint:", breakpoint)
         self.assertTrue(breakpoint and
                         breakpoint.GetNumLocations() == 1,
                         VALID_BREAKPOINT)
@@ -131,7 +131,7 @@
 
         # Now create a breakpoint on main.c by name 'c'.
         breakpoint = target.BreakpointCreateByName('c', 'a.out')
-        #print("breakpoint:", breakpoint)
+        self.trace("breakpoint:", breakpoint)
         self.assertTrue(breakpoint and
                         breakpoint.GetNumLocations() == 1,
                         VALID_BREAKPOINT)
@@ -173,7 +173,7 @@
 
         # Now create a breakpoint on main.c by name 'c'.
         breakpoint = target.BreakpointCreateByName('c', 'a.out')
-        #print("breakpoint:", breakpoint)
+        self.trace("breakpoint:", breakpoint)
         self.assertTrue(breakpoint and
                         breakpoint.GetNumLocations() == 1,
                         VALID_BREAKPOINT)
Index: lldb/test/API/python_api/event/TestEvents.py
===================================================================
--- lldb/test/API/python_api/event/TestEvents.py
+++ lldb/test/API/python_api/event/TestEvents.py
@@ -135,7 +135,7 @@
 
         # Now create a breakpoint on main.c by name 'c'.
         breakpoint = target.BreakpointCreateByName('c', 'a.out')
-        #print("breakpoint:", breakpoint)
+        self.trace("breakpoint:", breakpoint)
         self.assertTrue(breakpoint and
                         breakpoint.GetNumLocations() == 1,
                         VALID_BREAKPOINT)
@@ -171,9 +171,9 @@
                 # Let's only try at most 3 times to retrieve any kind of event.
                 while not count > 3:
                     if listener.WaitForEvent(5, event):
-                        #print("Got a valid event:", event)
-                        #print("Event data flavor:", event.GetDataFlavor())
-                        #print("Event type:", lldbutil.state_type_to_str(event.GetType()))
+                        self.trace("Got a valid event:", event)
+                        self.trace("Event data flavor:", event.GetDataFlavor())
+                        self.trace("Event type:", lldbutil.state_type_to_str(event.GetType()))
                         listener.Clear()
                         return
                     count = count + 1
@@ -215,7 +215,7 @@
 
         # Now create a breakpoint on main.c by name 'c'.
         breakpoint = target.BreakpointCreateByName('c', 'a.out')
-        #print("breakpoint:", breakpoint)
+        self.trace("breakpoint:", breakpoint)
         self.assertTrue(breakpoint and
                         breakpoint.GetNumLocations() == 1,
                         VALID_BREAKPOINT)
@@ -256,7 +256,7 @@
         class MyListeningThread(threading.Thread):
 
             def run(self):
-                #print("Running MyListeningThread:", self)
+                self.trace("Running MyListeningThread:", self)
 
                 # Regular expression pattern for the event description.
                 pattern = re.compile("data = {.*, state = (.*)}$")
@@ -266,7 +266,7 @@
                 while True:
                     if listener.WaitForEvent(5, event):
                         desc = lldbutil.get_description(event)
-                        #print("Event description:", desc)
+                        self.trace("Event description:", desc)
                         match = pattern.search(desc)
                         if not match:
                             break
Index: lldb/test/API/python_api/breakpoint/TestBreakpointAPI.py
===================================================================
--- lldb/test/API/python_api/breakpoint/TestBreakpointAPI.py
+++ lldb/test/API/python_api/breakpoint/TestBreakpointAPI.py
@@ -25,7 +25,7 @@
 
         # Now create a breakpoint on main.c by name 'AFunction'.
         breakpoint = target.BreakpointCreateByName('AFunction', 'a.out')
-        #print("breakpoint:", breakpoint)
+        self.trace("breakpoint:", breakpoint)
         self.assertTrue(breakpoint and
                         breakpoint.GetNumLocations() == 1,
                         VALID_BREAKPOINT)
@@ -59,7 +59,7 @@
 
         # Now create a breakpoint on main.c by name 'AFunction'.
         breakpoint = target.BreakpointCreateByName('AFunction', 'a.out')
-        #print("breakpoint:", breakpoint)
+        self.trace("breakpoint:", breakpoint)
         self.assertTrue(breakpoint and
                         breakpoint.GetNumLocations() == 1,
                         VALID_BREAKPOINT)
Index: lldb/test/API/lang/objc/foundation/TestSymbolTable.py
===================================================================
--- lldb/test/API/lang/objc/foundation/TestSymbolTable.py
+++ lldb/test/API/lang/objc/foundation/TestSymbolTable.py
@@ -50,19 +50,3 @@
         module = target.FindModule(filespec)
         self.assertTrue(module, VALID_MODULE)
 
-        # Create the set of known symbols.  As we iterate through the symbol
-        # table, remove the symbol from the set if it is a known symbol.
-        expected_symbols = set(self.symbols_list)
-        for symbol in module:
-            self.assertTrue(symbol, VALID_SYMBOL)
-            #print("symbol:", symbol)
-            name = symbol.GetName()
-            if name in expected_symbols:
-                #print("Removing %s from known_symbols %s" % (name, expected_symbols))
-                expected_symbols.remove(name)
-
-        # At this point, the known_symbols set should have become an empty set.
-        # If not, raise an error.
-        #print("symbols unaccounted for:", expected_symbols)
-        self.assertTrue(len(expected_symbols) == 0,
-                        "All the known symbols are accounted for")
Index: lldb/test/API/lang/objc/blocks/TestObjCIvarsInBlocks.py
===================================================================
--- lldb/test/API/lang/objc/blocks/TestObjCIvarsInBlocks.py
+++ lldb/test/API/lang/objc/blocks/TestObjCIvarsInBlocks.py
@@ -125,7 +125,7 @@
             expr, "Successfully got a local variable in a block in a class method.")
 
         ret_value_signed = expr.GetValueAsSigned(error)
-        # print('ret_value_signed = %i' % (ret_value_signed))
+        self.trace('ret_value_signed = %i' % (ret_value_signed))
         self.assertTrue(
             ret_value_signed == 5,
             "The local variable in the block was what we expected.")
Index: lldb/test/API/lang/cpp/class_types/TestClassTypesDisassembly.py
===================================================================
--- lldb/test/API/lang/cpp/class_types/TestClassTypesDisassembly.py
+++ lldb/test/API/lang/cpp/class_types/TestClassTypesDisassembly.py
@@ -33,8 +33,8 @@
             match = frameRE.search(line)
             if match:
                 function = match.group(1)
-                #print("line:", line)
-                #print("function:", function)
+                self.trace("line:", line)
+                self.trace("function:", function)
                 self.runCmd("disassemble -n '%s'" % function)
 
     @add_test_categories(['pyapi'])
Index: lldb/test/API/lang/c/register_variables/TestRegisterVariables.py
===================================================================
--- lldb/test/API/lang/c/register_variables/TestRegisterVariables.py
+++ lldb/test/API/lang/c/register_variables/TestRegisterVariables.py
@@ -1,91 +1,11 @@
 """Check that compiler-generated register values work correctly"""
 
-from __future__ import print_function
-
 import re
 import lldb
 from lldbsuite.test.decorators import *
 from lldbsuite.test.lldbtest import *
 from lldbsuite.test import lldbutil
 
-# This method attempts to figure out if a given variable
-# is in a register.
-#
-# Return:
-#   True if the value has a readable value and is in a register
-#   False otherwise
-
-
-def is_variable_in_register(frame, var_name):
-    # Ensure we can lookup the variable.
-    var = frame.FindVariable(var_name)
-    # print("\nchecking {}...".format(var_name))
-    if var is None or not var.IsValid():
-        # print("{} cannot be found".format(var_name))
-        return False
-
-    # Check that we can get its value.  If not, this
-    # may be a variable that is just out of scope at this point.
-    value = var.GetValue()
-    # print("checking value...")
-    if value is None:
-        # print("value is invalid")
-        return False
-    # else:
-        # print("value is {}".format(value))
-
-    # We have a variable and we can get its value.  The variable is in
-    # a register if we cannot get an address for it, assuming it is
-    # not a struct pointer.  (This is an approximation - compilers can
-    # do other things with spitting up a value into multiple parts of
-    # multiple registers, but what we're verifying here is much more
-    # than it was doing before).
-    var_addr = var.GetAddress()
-    # print("checking address...")
-    if var_addr.IsValid():
-        # We have an address, it must not be in a register.
-        # print("var {} is not in a register: has a valid address {}".format(var_name, var_addr))
-        return False
-    else:
-        # We don't have an address but we can read the value.
-        # It is likely stored in a register.
-        # print("var {} is in a register (we don't have an address for it)".format(var_name))
-        return True
-
-
-def is_struct_pointer_in_register(frame, var_name, trace):
-    # Ensure we can lookup the variable.
-    var = frame.FindVariable(var_name)
-    if trace:
-        print("\nchecking {}...".format(var_name))
-
-    if var is None or not var.IsValid():
-        # print("{} cannot be found".format(var_name))
-        return False
-
-    # Check that we can get its value.  If not, this
-    # may be a variable that is just out of scope at this point.
-    value = var.GetValue()
-    # print("checking value...")
-    if value is None:
-        if trace:
-            print("value is invalid")
-        return False
-    else:
-        if trace:
-             print("value is {}".format(value))
-
-    var_loc = var.GetLocation()
-    if trace:
-        print("checking location: {}".format(var_loc))
-    if var_loc is None or var_loc.startswith("0x"):
-        # The frame var is not in a register but rather a memory location.
-        # print("frame var {} is not in a register".format(var_name))
-        return False
-    else:
-        # print("frame var {} is in a register".format(var_name))
-        return True
-
 
 def re_expr_equals(val_type, val):
     # Match ({val_type}) ${sum_digits} = {val}
@@ -136,12 +56,12 @@
         # Try some variables that should be visible
         frame = self.dbg.GetSelectedTarget().GetProcess(
         ).GetSelectedThread().GetSelectedFrame()
-        if is_variable_in_register(frame, 'a'):
+        if self.is_variable_in_register(frame, 'a'):
             register_variables_count += 1
             self.expect("expr a", VARIABLES_DISPLAYED_CORRECTLY,
                         patterns=[re_expr_equals('int', 2)])
 
-        if is_struct_pointer_in_register(frame, 'b', self.TraceOn()):
+        if self.is_struct_pointer_in_register(frame, 'b', self.TraceOn()):
             register_variables_count += 1
             self.expect("expr b->m1", VARIABLES_DISPLAYED_CORRECTLY,
                         patterns=[re_expr_equals('int', 3)])
@@ -163,12 +83,12 @@
         # Try some variables that should be visible
         frame = self.dbg.GetSelectedTarget().GetProcess(
         ).GetSelectedThread().GetSelectedFrame()
-        if is_struct_pointer_in_register(frame, 'b', self.TraceOn()):
+        if self.is_struct_pointer_in_register(frame, 'b', self.TraceOn()):
             register_variables_count += 1
             self.expect("expr b->m2", VARIABLES_DISPLAYED_CORRECTLY,
                         patterns=[re_expr_equals('int', 5)])
 
-        if is_variable_in_register(frame, 'c'):
+        if self.is_variable_in_register(frame, 'c'):
             register_variables_count += 1
             self.expect("expr c", VARIABLES_DISPLAYED_CORRECTLY,
                         patterns=[re_expr_equals('int', 5)])
@@ -190,7 +110,7 @@
         # Try some variables that should be visible
         frame = self.dbg.GetSelectedTarget().GetProcess(
         ).GetSelectedThread().GetSelectedFrame()
-        if is_variable_in_register(frame, 'f'):
+        if self.is_variable_in_register(frame, 'f'):
             register_variables_count += 1
             self.expect("expr f", VARIABLES_DISPLAYED_CORRECTLY,
                         patterns=[re_expr_equals('float', '3.1')])
@@ -199,6 +119,78 @@
         self.assertTrue(
             register_variables_count > 0,
             "expected to verify at least one variable in a register")
-        # print("executed {} expressions with values in registers".format(register_variables_count))
+        self.trace("executed {} expressions with values in registers".format(register_variables_count))
 
         self.runCmd("kill")
+
+
+    def is_variable_in_register(self, frame, var_name):
+        # Ensure we can lookup the variable.
+        var = frame.FindVariable(var_name)
+        self.trace("\nchecking {}...".format(var_name))
+        if var is None or not var.IsValid():
+            self.trace("{} cannot be found".format(var_name))
+            return False
+
+        # Check that we can get its value.  If not, this
+        # may be a variable that is just out of scope at this point.
+        value = var.GetValue()
+        self.trace("checking value...")
+        if value is None:
+            self.trace("value is invalid")
+            return False
+        else:
+            self.trace("value is {}".format(value))
+
+        # We have a variable and we can get its value.  The variable is in a
+        # register if we cannot get an address for it, assuming it is not a
+        # struct pointer.  (This is an approximation - compilers can do other
+        # things with spitting up a value into multiple parts of multiple
+        # registers, but what we're verifying here is much more than it was
+        # doing before).
+        var_addr = var.GetAddress()
+        self.trace("checking address...")
+        if var_addr.IsValid():
+            # We have an address, it must not be in a register.
+            self.trace("var {} is not in a register: has a valid address {}".format(var_name, var_addr))
+            return False
+        else:
+            # We don't have an address but we can read the value.
+            # It is likely stored in a register.
+            self.trace("var {} is in a register (we don't have an address for it)".format(var_name))
+            return True
+
+
+    def is_struct_pointer_in_register(self, frame, var_name, trace):
+        # Ensure we can lookup the variable.
+        var = frame.FindVariable(var_name)
+        if trace:
+            print("\nchecking {}...".format(var_name))
+
+        if var is None or not var.IsValid():
+            self.trace("{} cannot be found".format(var_name))
+            return False
+
+        # Check that we can get its value.  If not, this
+        # may be a variable that is just out of scope at this point.
+        value = var.GetValue()
+        self.trace("checking value...")
+        if value is None:
+            if trace:
+                print("value is invalid")
+            return False
+        else:
+            if trace:
+                print("value is {}".format(value))
+
+        var_loc = var.GetLocation()
+        if trace:
+            print("checking location: {}".format(var_loc))
+        if var_loc is None or var_loc.startswith("0x"):
+            # The frame var is not in a register but rather a memory location.
+            self.trace("frame var {} is not in a register".format(var_name))
+            return False
+        else:
+            self.trace("frame var {} is in a register".format(var_name))
+            return True
+
Index: lldb/test/API/functionalities/load_unload/TestLoadUnload.py
===================================================================
--- lldb/test/API/functionalities/load_unload/TestLoadUnload.py
+++ lldb/test/API/functionalities/load_unload/TestLoadUnload.py
@@ -267,7 +267,7 @@
         output = self.res.GetOutput()
         pattern = re.compile("Image ([0-9]+) loaded")
         for l in output.split(os.linesep):
-            #print("l:", l)
+            self.trace("l:", l)
             match = pattern.search(l)
             if match:
                 break
Index: lldb/test/API/functionalities/data-formatter/data-formatter-skip-summary/TestDataFormatterSkipSummary.py
===================================================================
--- lldb/test/API/functionalities/data-formatter/data-formatter-skip-summary/TestDataFormatterSkipSummary.py
+++ lldb/test/API/functionalities/data-formatter/data-formatter-skip-summary/TestDataFormatterSkipSummary.py
@@ -147,13 +147,13 @@
             import re
             gcc_version_output = system(
                 [[lldbutil.which(self.getCompiler()), "-v"]])[1]
-            #print("my output:", gcc_version_output)
+            self.trace("my output:", gcc_version_output)
             for line in gcc_version_output.split(os.linesep):
                 m = re.search('\(Apple Inc\. build ([0-9]+)\)', line)
-                #print("line:", line)
+                self.trace("line:", line)
                 if m:
                     gcc_build = int(m.group(1))
-                    #print("gcc build:", gcc_build)
+                    self.trace("gcc build:", gcc_build)
                     if gcc_build >= 5666:
                         # rdar://problem/9804600"
                         self.skipTest(
Index: lldb/test/API/functionalities/breakpoint/serialize/TestBreakpointSerialization.py
===================================================================
--- lldb/test/API/functionalities/breakpoint/serialize/TestBreakpointSerialization.py
+++ lldb/test/API/functionalities/breakpoint/serialize/TestBreakpointSerialization.py
@@ -118,7 +118,7 @@
             copy_text = copy_desc.GetData()
 
             # These two should be identical.
-            # print ("Source text for %d is %s."%(i, source_text))
+            self.trace("Source text for %d is %s."%(i, source_text))
             self.assertTrue (source_text == copy_text, "Source and dest breakpoints are not identical: \nsource: %s\ndest: %s"%(source_text, copy_text))
 
     def do_check_resolvers(self):
Index: lldb/test/API/functionalities/breakpoint/breakpoint_conditions/TestBreakpointConditions.py
===================================================================
--- lldb/test/API/functionalities/breakpoint/breakpoint_conditions/TestBreakpointConditions.py
+++ lldb/test/API/functionalities/breakpoint/breakpoint_conditions/TestBreakpointConditions.py
@@ -126,7 +126,7 @@
 
         # Now create a breakpoint on main.c by name 'c'.
         breakpoint = target.BreakpointCreateByName('c', 'a.out')
-        #print("breakpoint:", breakpoint)
+        self.trace("breakpoint:", breakpoint)
         self.assertTrue(breakpoint and
                         breakpoint.GetNumLocations() == 1,
                         VALID_BREAKPOINT)
@@ -194,7 +194,7 @@
 
         # Now create a breakpoint on main.c by name 'c'.
         breakpoint = target.BreakpointCreateByName('c', 'a.out')
-        #print("breakpoint:", breakpoint)
+        self.trace("breakpoint:", breakpoint)
         self.assertTrue(breakpoint and
                         breakpoint.GetNumLocations() == 1,
                         VALID_BREAKPOINT)
Index: lldb/test/API/commands/target/basic/TestTargetCommand.py
===================================================================
--- lldb/test/API/commands/target/basic/TestTargetCommand.py
+++ lldb/test/API/commands/target/basic/TestTargetCommand.py
@@ -82,7 +82,7 @@
                 if match:
                     # We will start from (index + 1) ....
                     base = int(match.group(1), 10) + 1
-                    #print("base is:", base)
+                    self.trace("base is:", base)
                     break
 
         self.runCmd("target create " + exe_a, CURRENT_EXECUTABLE_SET)
Index: lldb/test/API/benchmarks/stepping/TestSteppingSpeed.py
===================================================================
--- lldb/test/API/benchmarks/stepping/TestSteppingSpeed.py
+++ lldb/test/API/benchmarks/stepping/TestSteppingSpeed.py
@@ -22,8 +22,8 @@
         self.break_spec = '-n main'
         self.count = 50
 
-        #print("self.exe=%s" % self.exe)
-        #print("self.break_spec=%s" % self.break_spec)
+        self.trace("self.exe=%s" % self.exe)
+        self.trace("self.break_spec=%s" % self.break_spec)
 
     @benchmarks_test
     @no_debug_info_test
Index: lldb/packages/Python/lldbsuite/test/lldbtest.py
===================================================================
--- lldb/packages/Python/lldbsuite/test/lldbtest.py
+++ lldb/packages/Python/lldbsuite/test/lldbtest.py
@@ -505,6 +505,10 @@
         """Returns True if we are in trace mode (tracing detailed test execution)."""
         return traceAlways
 
+    def trace(self, *args,**kwargs):
+        with recording(self, self.TraceOn()) as sbuf:
+            print(*args, **kwargs, file=sbuf)
+
     @classmethod
     def setUpClass(cls):
         """
_______________________________________________
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits

Reply via email to