rupprecht created this revision.
Herald added a project: All.
rupprecht requested review of this revision.
Herald added a project: LLDB.
Herald added a subscriber: lldb-commits.

This test more exhaustively tests all the different shortcuts that 
`_regexp-break` provides.

I have a follow up to propose to generically support more flags, and I want to 
make sure the existing functionality is well tested. However, these tests 
should be useful regardless of whether we want to expand the syntax here.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D141174

Files:
  lldb/packages/Python/lldbsuite/test/lldbutil.py
  
lldb/test/API/functionalities/breakpoint/breakpoint_command/TestRegexpBreakCommand.py

Index: lldb/test/API/functionalities/breakpoint/breakpoint_command/TestRegexpBreakCommand.py
===================================================================
--- lldb/test/API/functionalities/breakpoint/breakpoint_command/TestRegexpBreakCommand.py
+++ lldb/test/API/functionalities/breakpoint/breakpoint_command/TestRegexpBreakCommand.py
@@ -12,11 +12,6 @@
 
 class RegexpBreakCommandTestCase(TestBase):
 
-    def test(self):
-        """Test _regexp-break command."""
-        self.build()
-        self.regexp_break_command()
-
     def setUp(self):
         # Call super's setUp().
         TestBase.setUp(self)
@@ -25,14 +20,15 @@
         self.line = line_number(
             self.source, '// Set break point at this line.')
 
-    def regexp_break_command(self):
-        """Test the super consie "b" command, which is analias for _regexp-break."""
+    def test_regexp_break_command(self):
+        """Test the super concise "b" command, which is an alias for _regexp-break."""
+        self.build()
         exe = self.getBuildArtifact("a.out")
         self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET)
 
+        # <linenum>
         break_results = lldbutil.run_break_set_command(
-            self, "b %d" %
-            self.line)
+            self, "b %d" % self.line)
         lldbutil.check_breakpoint_result(
             self,
             break_results,
@@ -40,6 +36,7 @@
             line_number=self.line,
             num_locations=1)
 
+        # <filename>:<linenum>
         break_results = lldbutil.run_break_set_command(
             self, "b %s:%d" % (self.source, self.line))
         lldbutil.check_breakpoint_result(
@@ -49,6 +46,71 @@
             line_number=self.line,
             num_locations=1)
 
+        # <filename>:<linenum>:<colnum>
+        self.assertIn('column', break_results)
+        col = break_results['column']
+        break_results = lldbutil.run_break_set_command(
+            self, "b %s:%d:%d" % (self.source, self.line, col))
+        lldbutil.check_breakpoint_result(
+            self,
+            break_results,
+            file_name='main.c',
+            line_number=self.line,
+            column_number=col,
+            num_locations=1)
+
+        # <name>
+        break_results = lldbutil.run_break_set_command(
+            self, "b main")
+        lldbutil.check_breakpoint_result(
+            self,
+            break_results,
+            file_name='main.c',
+            symbol_name='main',
+            num_locations=1)
+
+        # 0x<address>
+        self.assertIn('address', break_results)
+        main_address = break_results['address']
+        break_results = lldbutil.run_break_set_command(
+            self, "b %s" % main_address)
+        lldbutil.check_breakpoint_result(
+            self,
+            break_results,
+            address=main_address,
+            num_locations=1)
+
+        # <module>`<name>
+        break_results = lldbutil.run_break_set_command(
+            self, "b a.out`main")
+        lldbutil.check_breakpoint_result(
+            self,
+            break_results,
+            module_name='a.out',
+            file_name='main.c',
+            symbol_name='main',
+            num_locations=1)
+
+        # &<name>
+        break_results = lldbutil.run_break_set_command(
+            self, "b &main")
+        lldbutil.check_breakpoint_result(
+            self,
+            break_results,
+            file_name='main.c',
+            symbol_name='main',
+            num_locations=1)
+
+        # /<source-regex>/
+        break_results = lldbutil.run_break_set_command(
+            self, "b /Set b[a-z]+k poi[mn]t at this linx*e/")
+        lldbutil.check_breakpoint_result(
+            self,
+            break_results,
+            file_name='main.c',
+            line_number=self.line,
+            num_locations=1)
+
         # Check breakpoint with full file path.
         full_path = os.path.join(self.getSourceDir(), self.source)
         break_results = lldbutil.run_break_set_command(
Index: lldb/packages/Python/lldbsuite/test/lldbutil.py
===================================================================
--- lldb/packages/Python/lldbsuite/test/lldbutil.py
+++ lldb/packages/Python/lldbsuite/test/lldbutil.py
@@ -492,7 +492,7 @@
 
     return get_bpno_from_match(break_results)
 
-def run_break_set_command(test, command):
+def run_break_set_command(test, command, error=False, error_msg=None):
     """Run the command passed in - it must be some break set variant - and analyze the result.
     Returns a dictionary of information gleaned from the command-line results.
     Will assert if the breakpoint setting fails altogether.
@@ -514,9 +514,17 @@
     patterns = [
         r"^Breakpoint (?P<bpno>[0-9]+): (?P<num_locations>[0-9]+) locations\.$",
         r"^Breakpoint (?P<bpno>[0-9]+): (?P<num_locations>no) locations \(pending\)\.",
+        r"^Breakpoint (?P<bpno>[0-9]+): address = (?P<address>0x[0-9a-fA-F]+)$",
         r"^Breakpoint (?P<bpno>[0-9]+): where = (?P<module>.*)`(?P<symbol>[+\-]{0,1}[^+]+)( \+ (?P<offset>[0-9]+)){0,1}( \[inlined\] (?P<inline_symbol>.*)){0,1} at (?P<file>[^:]+):(?P<line_no>[0-9]+)(?P<column>(:[0-9]+)?), address = (?P<address>0x[0-9a-fA-F]+)$",
         r"^Breakpoint (?P<bpno>[0-9]+): where = (?P<module>.*)`(?P<symbol>.*)( \+ (?P<offset>[0-9]+)){0,1}, address = (?P<address>0x[0-9a-fA-F]+)$"]
-    match_object = test.match(command, patterns)
+    match_object = test.match(command, patterns, error=error, matching=not error)
+
+    if error:
+        test.assertFalse(test.res.Succeeded(),"Command '%s' is expected to fail!" % command)
+        if error_msg:
+            test.assertIn(error_msg, test.res.GetError())
+        return
+
     break_results = match_object.groupdict()
 
     # We always insert the breakpoint number, setting it to -1 if we couldn't find it
@@ -544,6 +552,15 @@
     if 'line_no' in break_results:
         break_results['line_no'] = int(break_results['line_no'])
 
+
+    if 'column' in break_results:
+        if break_results['column']:
+            # The 'column' regex match group matches (:[0-9]+), strip off the ':' prefix.
+            break_results['column'] = int(break_results['column'][1:])
+        else:
+            # The matching group was empty; delete it to not be confusing.
+            del break_results['column']
+
     return break_results
 
 
@@ -557,6 +574,7 @@
         file_name=None,
         line_number=-1,
         column_number=0,
+        address=None,
         symbol_name=None,
         symbol_match_exact=True,
         module_name=None,
@@ -642,6 +660,16 @@
             (out_module_name,
              module_name))
 
+    if address:
+        out_address = 0
+        if 'address' in break_results:
+            out_address = break_results['address']
+
+        test.assertTrue(
+            address == out_address,
+            "Breakpoint address %s doesn't match resultant address %s." %
+            (address, out_address))
+
 def check_breakpoint(
             test,
             bpno,
_______________________________________________
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits

Reply via email to