<div dir="ltr">Hi Jim,<div><br></div><div>This broke a lot of our tests on Linux. E.g., "p foo" doesn't work.</div><div><a href="http://lab.llvm.org:8011/builders/lldb-x86_64-ubuntu-14.04-cmake/builds/11803">http://lab.llvm.org:8011/builders/lldb-x86_64-ubuntu-14.04-cmake/builds/11803</a><br></div><div><br></div><div>Since the breakage is pretty severe, mind if I revert this first until the problem can be fixed?</div></div><br><div class="gmail_quote"><div dir="ltr">On Thu, Feb 25, 2016 at 5:42 PM Jim Ingham via lldb-commits <<a href="mailto:lldb-commits@lists.llvm.org">lldb-commits@lists.llvm.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Author: jingham<br>
Date: Thu Feb 25 19:37:30 2016<br>
New Revision: 261953<br>
<br>
URL: <a href="http://llvm.org/viewvc/llvm-project?rev=261953&view=rev" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project?rev=261953&view=rev</a><br>
Log:<br>
Add the "block" keyword to "thread step-in -e", and an alias that uses it: "sif <target function>" - i.e. step-into-function<br>
to allow you to step through a complex calling sequence into a particular function that may span multiple lines.  Also some<br>
test cases for this and the --step-target feature.<br>
<br>
<br>
Added:<br>
    lldb/trunk/packages/Python/lldbsuite/test/lang/c/step-target/<br>
    lldb/trunk/packages/Python/lldbsuite/test/lang/c/step-target/Makefile<br>
    lldb/trunk/packages/Python/lldbsuite/test/lang/c/step-target/TestStepTarget.py<br>
    lldb/trunk/packages/Python/lldbsuite/test/lang/c/step-target/main.c<br>
Modified:<br>
    lldb/trunk/source/Commands/CommandObjectThread.cpp<br>
    lldb/trunk/source/Interpreter/CommandInterpreter.cpp<br>
<br>
Added: lldb/trunk/packages/Python/lldbsuite/test/lang/c/step-target/Makefile<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/lldb/trunk/packages/Python/lldbsuite/test/lang/c/step-target/Makefile?rev=261953&view=auto" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/lldb/trunk/packages/Python/lldbsuite/test/lang/c/step-target/Makefile?rev=261953&view=auto</a><br>
==============================================================================<br>
--- lldb/trunk/packages/Python/lldbsuite/test/lang/c/step-target/Makefile (added)<br>
+++ lldb/trunk/packages/Python/lldbsuite/test/lang/c/step-target/Makefile Thu Feb 25 19:37:30 2016<br>
@@ -0,0 +1,5 @@<br>
+LEVEL = ../../../make<br>
+<br>
+C_SOURCES := main.c<br>
+<br>
+include $(LEVEL)/Makefile.rules<br>
<br>
Added: lldb/trunk/packages/Python/lldbsuite/test/lang/c/step-target/TestStepTarget.py<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/lldb/trunk/packages/Python/lldbsuite/test/lang/c/step-target/TestStepTarget.py?rev=261953&view=auto" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/lldb/trunk/packages/Python/lldbsuite/test/lang/c/step-target/TestStepTarget.py?rev=261953&view=auto</a><br>
==============================================================================<br>
--- lldb/trunk/packages/Python/lldbsuite/test/lang/c/step-target/TestStepTarget.py (added)<br>
+++ lldb/trunk/packages/Python/lldbsuite/test/lang/c/step-target/TestStepTarget.py Thu Feb 25 19:37:30 2016<br>
@@ -0,0 +1,113 @@<br>
+"""Test the 'step target' feature."""<br>
+<br>
+from __future__ import print_function<br>
+<br>
+import os, time<br>
+import lldb<br>
+from lldbsuite.test.decorators import *<br>
+from lldbsuite.test.lldbtest import *<br>
+from lldbsuite.test import lldbutil<br>
+<br>
+class TestStepTarget(TestBase):<br>
+<br>
+    mydir = TestBase.compute_mydir(__file__)<br>
+<br>
+    def getCategories(self):<br>
+        return ['basic_process']<br>
+<br>
+    def setUp(self):<br>
+        # Call super's setUp().<br>
+        TestBase.setUp(self)<br>
+        # Find the line numbers that we will step to in main:<br>
+        self.main_source = "main.c"<br>
+        self.end_line = line_number(self.main_source, "All done")<br>
+<br>
+    @add_test_categories(['pyapi'])<br>
+<br>
+    def get_to_start (self):<br>
+        self.build()<br>
+        exe = os.path.join(os.getcwd(), "a.out")<br>
+<br>
+        target = self.dbg.CreateTarget(exe)<br>
+        self.assertTrue(target, VALID_TARGET)<br>
+<br>
+        self.main_source_spec = lldb.SBFileSpec (self.main_source)<br>
+<br>
+        break_in_main = target.BreakpointCreateBySourceRegex ('Break here to try targetted stepping', self.main_source_spec)<br>
+        self.assertTrue(break_in_main, VALID_BREAKPOINT)<br>
+        self.assertTrue(break_in_main.GetNumLocations() > 0,"Has locations.")<br>
+<br>
+        # Now launch the process, and do not stop at entry point.<br>
+        process = target.LaunchSimple (None, None, self.get_process_working_directory())<br>
+<br>
+        self.assertTrue(process, PROCESS_IS_VALID)<br>
+<br>
+        # The stop reason of the thread should be breakpoint.<br>
+        threads = lldbutil.get_threads_stopped_at_breakpoint (process, break_in_main)<br>
+<br>
+        if len(threads) != 1:<br>
+            self.fail ("Failed to stop at first breakpoint in main.")<br>
+<br>
+        thread = threads[0]<br>
+        return thread<br>
+<br>
+    def test_with_end_line(self):<br>
+        """Test stepping over vrs. hitting breakpoints & subsequent stepping in various forms."""<br>
+<br>
+        thread = self.get_to_start()<br>
+<br>
+        error = lldb.SBError()<br>
+        thread.StepInto("lotsOfArgs", self.end_line, error)<br>
+        frame = thread.frames[0]<br>
+<br>
+        self.assertTrue (<a href="http://frame.name" rel="noreferrer" target="_blank">frame.name</a> == "lotsOfArgs", "Stepped to lotsOfArgs.")<br>
+<br>
+    def test_with_end_line_bad_name(self):<br>
+        """Test stepping over vrs. hitting breakpoints & subsequent stepping in various forms."""<br>
+<br>
+        thread = self.get_to_start()<br>
+<br>
+        error = lldb.SBError()<br>
+        thread.StepInto("lotsOfArgssss", self.end_line, error)<br>
+        frame = thread.frames[0]<br>
+        self.assertTrue (frame.line_entry.line == self.end_line, "Stepped to the block end.")<br>
+<br>
+    def test_with_end_line_deeper(self):<br>
+        """Test stepping over vrs. hitting breakpoints & subsequent stepping in various forms."""<br>
+<br>
+        thread = self.get_to_start()<br>
+<br>
+        error = lldb.SBError()<br>
+        thread.StepInto("modifyInt", self.end_line, error)<br>
+        frame = thread.frames[0]<br>
+        self.assertTrue (<a href="http://frame.name" rel="noreferrer" target="_blank">frame.name</a> == "modifyInt", "Stepped to modifyInt.")<br>
+<br>
+    def test_with_command_and_block(self):<br>
+        """Test stepping over vrs. hitting breakpoints & subsequent stepping in various forms."""<br>
+<br>
+        thread = self.get_to_start()<br>
+<br>
+        result = lldb.SBCommandReturnObject()<br>
+        self.dbg.GetCommandInterpreter().HandleCommand('thread step-in -t "lotsOfArgs" -e block', result)<br>
+        self.assertTrue(result.Succeeded(), "thread step-in command succeeded.")<br>
+<br>
+        frame = thread.frames[0]<br>
+        self.assertTrue (<a href="http://frame.name" rel="noreferrer" target="_blank">frame.name</a> == "lotsOfArgs", "Stepped to lotsOfArgs.")<br>
+<br>
+    def test_with_command_and_block_and_bad_name(self):<br>
+        """Test stepping over vrs. hitting breakpoints & subsequent stepping in various forms."""<br>
+<br>
+        thread = self.get_to_start()<br>
+<br>
+        result = lldb.SBCommandReturnObject()<br>
+        self.dbg.GetCommandInterpreter().HandleCommand('thread step-in -t "lotsOfArgsssss" -e block', result)<br>
+        self.assertTrue(result.Succeeded(), "thread step-in command succeeded.")<br>
+<br>
+        frame = thread.frames[0]<br>
+<br>
+        self.assertTrue (<a href="http://frame.name" rel="noreferrer" target="_blank">frame.name</a> == "main", "Stepped back out to main.")<br>
+        # end_line is set to the line after the containing block.  Check that we got there:<br>
+        self.assertTrue(frame.line_entry.line == self.end_line, "Got out of the block")<br>
+<br>
+<br>
+<br>
<br>
Added: lldb/trunk/packages/Python/lldbsuite/test/lang/c/step-target/main.c<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/lldb/trunk/packages/Python/lldbsuite/test/lang/c/step-target/main.c?rev=261953&view=auto" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/lldb/trunk/packages/Python/lldbsuite/test/lang/c/step-target/main.c?rev=261953&view=auto</a><br>
==============================================================================<br>
--- lldb/trunk/packages/Python/lldbsuite/test/lang/c/step-target/main.c (added)<br>
+++ lldb/trunk/packages/Python/lldbsuite/test/lang/c/step-target/main.c Thu Feb 25 19:37:30 2016<br>
@@ -0,0 +1,40 @@<br>
+#include <stdio.h><br>
+<br>
+void<br>
+lotsOfArgs<br>
+(<br>
+  int firstArg,<br>
+  int secondArg,<br>
+  int thirdArg,<br>
+  int fourthArg<br>
+)<br>
+{<br>
+  printf ("First: %d Second: %d Third: %d Fourth: %d.\n",<br>
+          firstArg,<br>
+          secondArg,<br>
+          thirdArg,<br>
+          fourthArg);<br>
+}<br>
+<br>
+int<br>
+modifyInt(int incoming)<br>
+{<br>
+  return incoming % 2;<br>
+}<br>
+<br>
+int<br>
+main (int argc, char **argv)<br>
+{<br>
+  if (argc > 0)<br>
+    {<br>
+      int var_makes_block = argc + 1;<br>
+      printf ("Break here to try targetted stepping.\n");<br>
+      lotsOfArgs(var_makes_block,<br>
+                 modifyInt(20),<br>
+                 30,<br>
+                 modifyInt(40));<br>
+      printf ("Done calling lotsOfArgs.");<br>
+    }<br>
+  printf ("All done.\n");<br>
+  return 0;<br>
+}<br>
<br>
Modified: lldb/trunk/source/Commands/CommandObjectThread.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Commands/CommandObjectThread.cpp?rev=261953&r1=261952&r2=261953&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Commands/CommandObjectThread.cpp?rev=261953&r1=261952&r2=261953&view=diff</a><br>
==============================================================================<br>
--- lldb/trunk/source/Commands/CommandObjectThread.cpp (original)<br>
+++ lldb/trunk/source/Commands/CommandObjectThread.cpp Thu Feb 25 19:37:30 2016<br>
@@ -386,6 +386,11 @@ public:<br>
<br>
             case 'e':<br>
                 {<br>
+                    if (strcmp(option_arg, "block") == 0)<br>
+                    {<br>
+                        m_end_line_is_block_end = 1;<br>
+                        break;<br>
+                    }<br>
                     uint32_t tmp_end_line = StringConvert::ToUInt32(option_arg, UINT32_MAX, 0);<br>
                     if (tmp_end_line == UINT32_MAX)<br>
                        error.SetErrorStringWithFormat ("invalid end line number '%s'", option_arg);<br>
@@ -429,6 +434,7 @@ public:<br>
             m_class_name.clear();<br>
             m_step_count = 1;<br>
             m_end_line = LLDB_INVALID_LINE_NUMBER;<br>
+            m_end_line_is_block_end = false;<br>
         }<br>
<br>
         const OptionDefinition*<br>
@@ -450,6 +456,7 @@ public:<br>
         std::string m_class_name;<br>
         uint32_t m_step_count;<br>
         uint32_t m_end_line;<br>
+        bool     m_end_line_is_block_end;<br>
     };<br>
<br>
     CommandObjectThreadStepWithTypeAndScope (CommandInterpreter &interpreter,<br>
@@ -588,6 +595,30 @@ protected:<br>
                         return false;<br>
                     }<br>
                 }<br>
+                else if (m_options.m_end_line_is_block_end)<br>
+                {<br>
+                    Error error;<br>
+                    Block *block = frame->GetSymbolContext(eSymbolContextBlock).block;<br>
+                    if (!block)<br>
+                    {<br>
+                        result.AppendErrorWithFormat("Could not find the current block.");<br>
+                        result.SetStatus(eReturnStatusFailed);<br>
+                        return false;<br>
+                    }<br>
+<br>
+                    AddressRange block_range;<br>
+                    Address pc_address = frame->GetFrameCodeAddress();<br>
+                    block->GetRangeContainingAddress(pc_address, block_range);<br>
+                    if (!block_range.GetBaseAddress().IsValid())<br>
+                    {<br>
+                        result.AppendErrorWithFormat("Could not find the current block address.");<br>
+                        result.SetStatus(eReturnStatusFailed);<br>
+                        return false;<br>
+                    }<br>
+                    lldb::addr_t pc_offset_in_block = pc_address.GetFileAddress() - block_range.GetBaseAddress().GetFileAddress();<br>
+                    lldb::addr_t range_length = block_range.GetByteSize() - pc_offset_in_block;<br>
+                    range = AddressRange(pc_address, range_length);<br>
+                }<br>
                 else<br>
                 {<br>
                     range = sc.line_entry.range;<br>
@@ -741,7 +772,9 @@ CommandObjectThreadStepWithTypeAndScope:<br>
 { LLDB_OPT_SET_1, false, "step-in-avoids-no-debug",   'a', OptionParser::eRequiredArgument, nullptr, nullptr,               0, eArgTypeBoolean,     "A boolean value that sets whether stepping into functions will step over functions with no debug information."},<br>
 { LLDB_OPT_SET_1, false, "step-out-avoids-no-debug",  'A', OptionParser::eRequiredArgument, nullptr, nullptr,               0, eArgTypeBoolean,     "A boolean value, if true stepping out of functions will continue to step out till it hits a function with debug information."},<br>
 { LLDB_OPT_SET_1, false, "count",                     'c', OptionParser::eRequiredArgument, nullptr, nullptr,               1, eArgTypeCount,     "How many times to perform the stepping operation - currently only supported for step-inst and next-inst."},<br>
-{ LLDB_OPT_SET_1, false, "end-linenumber",            'e', OptionParser::eRequiredArgument, nullptr, nullptr,               1, eArgTypeLineNum,     "The line at which to stop stepping - defaults to the next line and only supported for step-in and step-over."},<br>
+{ LLDB_OPT_SET_1, false, "end-linenumber",            'e', OptionParser::eRequiredArgument, nullptr, nullptr,               1, eArgTypeLineNum,     "The line at which to stop stepping - defaults to the next line and only supported for step-in and step-over."<br>
+                                                                                                                                              "  You can also pass the string 'block' to step to the end of the current block."<br>
+                                                                                                                                              "  This is particularly useful in conjunction with --step-target to step through a complex calling sequence."},<br>
 { LLDB_OPT_SET_1, false, "run-mode",                  'm', OptionParser::eRequiredArgument, nullptr, g_tri_running_mode, 0, eArgTypeRunMode, "Determine how to run other threads while stepping the current thread."},<br>
 { LLDB_OPT_SET_1, false, "step-over-regexp",          'r', OptionParser::eRequiredArgument, nullptr, nullptr,               0, eArgTypeRegularExpression,   "A regular expression that defines function names to not to stop at when stepping in."},<br>
 { LLDB_OPT_SET_1, false, "step-in-target",            't', OptionParser::eRequiredArgument, nullptr, nullptr,               0, eArgTypeFunctionName,   "The name of the directly called function step in should stop at when stepping into."},<br>
<br>
Modified: lldb/trunk/source/Interpreter/CommandInterpreter.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Interpreter/CommandInterpreter.cpp?rev=261953&r1=261952&r2=261953&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Interpreter/CommandInterpreter.cpp?rev=261953&r1=261952&r2=261953&view=diff</a><br>
==============================================================================<br>
--- lldb/trunk/source/Interpreter/CommandInterpreter.cpp (original)<br>
+++ lldb/trunk/source/Interpreter/CommandInterpreter.cpp Thu Feb 25 19:37:30 2016<br>
@@ -185,6 +185,9 @@ CommandInterpreter::Initialize ()<br>
<br>
     LoadCommandDictionary ();<br>
<br>
+    // An alias arguments vector to reuse - reset it before use...<br>
+    OptionArgVectorSP alias_arguments_vector_sp (new OptionArgVector);<br>
+<br>
     // Set up some initial aliases.<br>
     CommandObjectSP cmd_obj_sp = GetCommandSPExact ("quit", false);<br>
     if (cmd_obj_sp)<br>
@@ -239,6 +242,11 @@ CommandInterpreter::Initialize ()<br>
     {<br>
         AddAlias ("s", cmd_obj_sp);<br>
         AddAlias ("step", cmd_obj_sp);<br>
+<br>
+        alias_arguments_vector_sp.reset (new OptionArgVector);<br>
+        ProcessAliasOptionsArgs (cmd_obj_sp, "--end-linenumber block --step-in-target %1", alias_arguments_vector_sp);<br>
+        AddAlias ("sif", cmd_obj_sp);<br>
+        AddOrReplaceAliasOptions("sif", alias_arguments_vector_sp);<br>
     }<br>
<br>
     cmd_obj_sp = GetCommandSPExact ("thread step-over", false);<br>
@@ -329,8 +337,6 @@ CommandInterpreter::Initialize ()<br>
         AddAlias ("image", cmd_obj_sp);<br>
<br>
<br>
-    OptionArgVectorSP alias_arguments_vector_sp (new OptionArgVector);<br>
-<br>
     cmd_obj_sp = GetCommandSPExact ("expression", false);<br>
     if (cmd_obj_sp)<br>
     {<br>
<br>
<br>
_______________________________________________<br>
lldb-commits mailing list<br>
<a href="mailto:lldb-commits@lists.llvm.org" target="_blank">lldb-commits@lists.llvm.org</a><br>
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits</a><br>
</blockquote></div>