More cleanup on the lldb-perf code:
authorGreg Clayton <gclayton@apple.com>
Tue, 19 Mar 2013 04:41:22 +0000 (04:41 +0000)
committerGreg Clayton <gclayton@apple.com>
Tue, 19 Mar 2013 04:41:22 +0000 (04:41 +0000)
- TestCase.m_thread is now filled in with the first thread that has a valid
  stop reason. This eliminates the need for the SelectMyThread() functions.
- The first thread that stops for a reason is also set as the selected thread
  in the process in case any command line commands are run.
- Changed launch over to take a SBLaunchInfo parameter so that the launch
  function doesn't keep getting new arguments as they are needed.
- TestCase::Setup() and TestCase::Launch(SBLaunchInfo) now return bool to
  indicate success of setup and launch.
- ActionWanted::Next(SBThread) was renamed to ActionWanted::StepOver(SBThread)
- ActionWanted::Finish(SBThread) was renamed to ActionWanted::StepOut(SBThread)

llvm-svn: 177376

lldb/lldb.xcodeproj/project.pbxproj
lldb/tools/debugserver/debugserver.xcodeproj/project.pbxproj
lldb/tools/lldb-perf/README
lldb/tools/lldb-perf/darwin/formatters/main.cpp
lldb/tools/lldb-perf/darwin/sketch/main.cpp
lldb/tools/lldb-perf/lib/TestCase.cpp
lldb/tools/lldb-perf/lib/TestCase.h
lldb/tools/lldb-perf/lib/Xcode.cpp
lldb/tools/lldb-perf/lldbperf.xcodeproj/project.pbxproj

index ec10307..3ec29d8 100644 (file)
                                        "-flimit-debug-info",
                                        "-Wparentheses",
                                );
-                               SDKROOT = macosx;
                                STRIP_INSTALLED_PRODUCT = NO;
                                STRIP_STYLE = debugging;
                                WARNING_CFLAGS = "-Wreorder";
                                        "-flimit-debug-info",
                                        "-Wparentheses",
                                );
-                               SDKROOT = macosx;
                                STRIP_INSTALLED_PRODUCT = NO;
                                STRIP_STYLE = debugging;
                                WARNING_CFLAGS = "-Wreorder";
                                        "-flimit-debug-info",
                                        "-Wparentheses",
                                );
-                               SDKROOT = "";
                                STRIP_INSTALLED_PRODUCT = NO;
                                STRIP_STYLE = debugging;
                                WARNING_CFLAGS = "-Wreorder";
                                        "-flimit-debug-info",
                                        "-Wparentheses",
                                );
-                               SDKROOT = macosx;
                                STRIP_INSTALLED_PRODUCT = NO;
                                STRIP_STYLE = debugging;
                                WARNING_CFLAGS = "-Wreorder";
index a0e65aa..d5c35b1 100644 (file)
                                GCC_WARN_UNINITIALIZED_AUTOS = YES;
                                GCC_WARN_UNUSED_VARIABLE = YES;
                                ONLY_ACTIVE_ARCH = YES;
-                               SDKROOT = "";
                                STRIP_INSTALLED_PRODUCT = NO;
                                VERSIONING_SYSTEM = "apple-generic";
                                VERSION_INFO_BUILDER = "$(USER)";
                                GCC_WARN_UNINITIALIZED_AUTOS = YES;
                                GCC_WARN_UNUSED_VARIABLE = YES;
                                ONLY_ACTIVE_ARCH = YES;
-                               SDKROOT = "";
                                STRIPFLAGS = "-x";
                                STRIP_STYLE = debugging;
                                VERSIONING_SYSTEM = "apple-generic";
                                GCC_WARN_ABOUT_RETURN_TYPE = YES;
                                GCC_WARN_UNINITIALIZED_AUTOS = YES;
                                GCC_WARN_UNUSED_VARIABLE = YES;
-                               SDKROOT = "";
                                STRIPFLAGS = "-x";
                                STRIP_STYLE = debugging;
                                VERSIONING_SYSTEM = "apple-generic";
                                CURRENT_PROJECT_VERSION = 300.99.0;
                                DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
                                FRAMEWORK_SEARCH_PATHS = $SDKROOT/System/Library/PrivateFrameworks;
-                               "FRAMEWORK_SEARCH_PATHS[arch=*][sdk=iphoneos*]" = (
+                               "FRAMEWORK_SEARCH_PATHS[sdk=iphoneos*][arch=*]" = (
                                        "$(SDKROOT)/System/Library/PrivateFrameworks",
                                        "$(SDKROOT)/Developer/Library/PrivateFrameworks",
                                );
-                               "FRAMEWORK_SEARCH_PATHS[arch=*][sdk=macosx*]" = "$(SDKROOT)/System/Library/PrivateFrameworks";
+                               "FRAMEWORK_SEARCH_PATHS[sdk=macosx*][arch=*]" = "$(SDKROOT)/System/Library/PrivateFrameworks";
                                GCC_C_LANGUAGE_STANDARD = c99;
                                GCC_PREPROCESSOR_DEFINITIONS = LLDB_DEBUGSERVER_BUILDANDINTEGRATION;
                                GCC_VERSION = com.apple.compilers.llvm.clang.1_0;
                                "INSTALL_PATH[sdk=iphoneos*]" = /Developer/usr/bin/;
                                LLDB_DEBUGSERVER = 1;
                                OTHER_CFLAGS = "-Wparentheses";
-                               "OTHER_CFLAGS[arch=*][sdk=iphoneos*]" = (
+                               "OTHER_CFLAGS[sdk=iphoneos*][arch=*]" = (
                                        "-Wparentheses",
                                        "-DWITH_LOCKDOWN",
                                        "-DWITH_SPRINGBOARD",
                                        "-DOS_OBJECT_USE_OBJC=0",
                                );
-                               "OTHER_CPLUSPLUSFLAGS[arch=*][sdk=iphoneos*]" = "$(OTHER_CFLAGS)";
+                               "OTHER_CPLUSPLUSFLAGS[sdk=iphoneos*][arch=*]" = "$(OTHER_CFLAGS)";
                                OTHER_LDFLAGS = (
                                        "-sectcreate",
                                        __TEXT,
                                        __info_plist,
                                        "$(PROJECT_DIR)/resources/lldb-debugserver-Info.plist",
                                );
-                               "OTHER_LDFLAGS[arch=*][sdk=iphoneos*]" = (
+                               "OTHER_LDFLAGS[sdk=iphoneos*][arch=*]" = (
                                        "-framework",
                                        SpringBoardServices,
                                        "-llockdown",
                                COPY_PHASE_STRIP = YES;
                                CURRENT_PROJECT_VERSION = 300.99.0;
                                FRAMEWORK_SEARCH_PATHS = $SDKROOT/System/Library/PrivateFrameworks;
-                               "FRAMEWORK_SEARCH_PATHS[arch=*][sdk=iphoneos*]" = (
+                               "FRAMEWORK_SEARCH_PATHS[sdk=iphoneos*][arch=*]" = (
                                        "$(SDKROOT)/System/Library/PrivateFrameworks",
                                        "$(SDKROOT)/Developer/Library/PrivateFrameworks",
                                );
-                               "FRAMEWORK_SEARCH_PATHS[arch=*][sdk=macosx*]" = "$(SDKROOT)/System/Library/PrivateFrameworks";
+                               "FRAMEWORK_SEARCH_PATHS[sdk=macosx*][arch=*]" = "$(SDKROOT)/System/Library/PrivateFrameworks";
                                GCC_C_LANGUAGE_STANDARD = c99;
                                GCC_DYNAMIC_NO_PIC = NO;
                                GCC_OPTIMIZATION_LEVEL = 0;
                                INSTALL_PATH = /usr/bin;
                                LLDB_DEBUGSERVER = 1;
                                OTHER_CFLAGS = "-Wparentheses";
-                               "OTHER_CFLAGS[arch=*][sdk=iphoneos*]" = (
+                               "OTHER_CFLAGS[sdk=iphoneos*][arch=*]" = (
                                        "-Wparentheses",
                                        "-DWITH_LOCKDOWN",
                                        "-DWITH_SPRINGBOARD",
                                        "-DOS_OBJECT_USE_OBJC=0",
                                );
-                               "OTHER_CPLUSPLUSFLAGS[arch=*][sdk=iphoneos*]" = "$(OTHER_CFLAGS)";
+                               "OTHER_CPLUSPLUSFLAGS[sdk=iphoneos*][arch=*]" = "$(OTHER_CFLAGS)";
                                OTHER_LDFLAGS = (
                                        "-sectcreate",
                                        __TEXT,
                                        __info_plist,
                                        "$(PROJECT_DIR)/resources/lldb-debugserver-Info.plist",
                                );
-                               "OTHER_LDFLAGS[arch=*][sdk=iphoneos*]" = (
+                               "OTHER_LDFLAGS[sdk=iphoneos*][arch=*]" = (
                                        "-framework",
                                        SpringBoardServices,
                                        "-llockdown",
                                CURRENT_PROJECT_VERSION = 300.99.0;
                                DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
                                FRAMEWORK_SEARCH_PATHS = $SDKROOT/System/Library/PrivateFrameworks;
-                               "FRAMEWORK_SEARCH_PATHS[arch=*][sdk=iphoneos*]" = (
+                               "FRAMEWORK_SEARCH_PATHS[sdk=iphoneos*][arch=*]" = (
                                        "$(SDKROOT)/System/Library/PrivateFrameworks",
                                        "$(SDKROOT)/Developer/Library/PrivateFrameworks",
                                );
-                               "FRAMEWORK_SEARCH_PATHS[arch=*][sdk=macosx*]" = "$(SDKROOT)/System/Library/PrivateFrameworks";
+                               "FRAMEWORK_SEARCH_PATHS[sdk=macosx*][arch=*]" = "$(SDKROOT)/System/Library/PrivateFrameworks";
                                GCC_C_LANGUAGE_STANDARD = c99;
                                GCC_PREPROCESSOR_DEFINITIONS = LLDB_DEBUGSERVER_RELEASE;
                                GCC_VERSION = com.apple.compilers.llvm.clang.1_0;
                                INSTALL_PATH = /usr/bin;
                                LLDB_DEBUGSERVER = 1;
                                OTHER_CFLAGS = "-Wparentheses";
-                               "OTHER_CFLAGS[arch=*][sdk=iphoneos*]" = (
+                               "OTHER_CFLAGS[sdk=iphoneos*][arch=*]" = (
                                        "-Wparentheses",
                                        "-DWITH_LOCKDOWN",
                                        "-DWITH_SPRINGBOARD",
                                        "-DOS_OBJECT_USE_OBJC=0",
                                );
-                               "OTHER_CPLUSPLUSFLAGS[arch=*][sdk=iphoneos*]" = "$(OTHER_CFLAGS)";
+                               "OTHER_CPLUSPLUSFLAGS[sdk=iphoneos*][arch=*]" = "$(OTHER_CFLAGS)";
                                OTHER_LDFLAGS = (
                                        "-sectcreate",
                                        __TEXT,
                                        __info_plist,
                                        "$(PROJECT_DIR)/resources/lldb-debugserver-Info.plist",
                                );
-                               "OTHER_LDFLAGS[arch=*][sdk=iphoneos*]" = (
+                               "OTHER_LDFLAGS[sdk=iphoneos*][arch=*]" = (
                                        "-framework",
                                        SpringBoardServices,
                                        "-llockdown",
                                GCC_WARN_UNINITIALIZED_AUTOS = YES;
                                GCC_WARN_UNUSED_VARIABLE = YES;
                                ONLY_ACTIVE_ARCH = YES;
-                               SDKROOT = "";
                                STRIP_INSTALLED_PRODUCT = NO;
                                VERSIONING_SYSTEM = "apple-generic";
                                VERSION_INFO_BUILDER = "$(USER)";
                                COPY_PHASE_STRIP = YES;
                                CURRENT_PROJECT_VERSION = 300.99.0;
                                FRAMEWORK_SEARCH_PATHS = $SDKROOT/System/Library/PrivateFrameworks;
-                               "FRAMEWORK_SEARCH_PATHS[arch=*][sdk=iphoneos*]" = (
+                               "FRAMEWORK_SEARCH_PATHS[sdk=iphoneos*][arch=*]" = (
                                        "$(SDKROOT)/System/Library/PrivateFrameworks",
                                        "$(SDKROOT)/Developer/Library/PrivateFrameworks",
                                );
-                               "FRAMEWORK_SEARCH_PATHS[arch=*][sdk=macosx*]" = "$(SDKROOT)/System/Library/PrivateFrameworks";
+                               "FRAMEWORK_SEARCH_PATHS[sdk=macosx*][arch=*]" = "$(SDKROOT)/System/Library/PrivateFrameworks";
                                GCC_C_LANGUAGE_STANDARD = c99;
                                GCC_DYNAMIC_NO_PIC = NO;
                                GCC_OPTIMIZATION_LEVEL = 0;
                                INSTALL_PATH = /usr/bin;
                                LLDB_DEBUGSERVER = 1;
                                OTHER_CFLAGS = "-Wparentheses";
-                               "OTHER_CFLAGS[arch=*][sdk=iphoneos*]" = (
+                               "OTHER_CFLAGS[sdk=iphoneos*][arch=*]" = (
                                        "-Wparentheses",
                                        "-DWITH_LOCKDOWN",
                                        "-DWITH_SPRINGBOARD",
                                        "-DOS_OBJECT_USE_OBJC=0",
                                );
-                               "OTHER_CPLUSPLUSFLAGS[arch=*][sdk=iphoneos*]" = "$(OTHER_CFLAGS)";
+                               "OTHER_CPLUSPLUSFLAGS[sdk=iphoneos*][arch=*]" = "$(OTHER_CFLAGS)";
                                OTHER_LDFLAGS = (
                                        "-sectcreate",
                                        __TEXT,
                                        __info_plist,
                                        "$(PROJECT_DIR)/resources/lldb-debugserver-Info.plist",
                                );
-                               "OTHER_LDFLAGS[arch=*][sdk=iphoneos*]" = (
+                               "OTHER_LDFLAGS[sdk=iphoneos*][arch=*]" = (
                                        "-framework",
                                        SpringBoardServices,
                                        "-llockdown",
index 8e7c00b..7cec4fa 100644 (file)
@@ -1,17 +1,24 @@
  The lldb-perf infrastructure for LLDB performance testing
 ===========================================================
 
-lldb-perf is an infrastructure meant to simplify the creation of performance tests for the LLDB debugger
-It is contained in liblldbperf.a which is part of the standard opensource checkout of LLDB
-Its main concepts are:
-- Gauges: a gauge is a thing that takes a sample (e.g. it samples the time elapsed, the memory used, the energy consumed)
-- Metrics: a metric is a collection of samples that knows how to do statistics (for now, sum() and average() but can be extended as need be)
-- Measurements: a measurement is the thing that stores an action, a gauge and a metric. essentially, you define measurements as in “take the time to run this function”, “take the memory to run this block of code”, and then after you invoke it, your stats will be automagically there
-- Tests: a test is a sequence of steps and measurements
+lldb-perf is an infrastructure meant to simplify the creation of performance 
+tests for the LLDB debugger. It is contained in liblldbperf.a which is part of
+the standard opensource checkout of LLDB
 
-Tests cases should be added as targets to the lldbperf.xcodeproj project.  It is probably easiest to duplicate one of the existing targets.
+Its main concepts are:
+- Gauges: a gauge is a thing that takes a sample. Samples include elapsed time,
+  memory used, and energy consumed.
+- Metrics: a metric is a collection of samples that knows how to do statistics
+  like sum() and average(). Metrics can be extended as needed.
+- Measurements: a measurement is the thing that stores an action, a gauge and
+  a metric. You define measurements as in “take the time to run this function”,
+  “take the memory to run this block of code”, and then after you invoke it, 
+  your stats will automagically be there.
+- Tests: a test is a sequence of steps and measurements.
 
-In order to write a test based on lldb-perf, you need to subclass lldb_perf::TestCase, as in:
+Tests cases should be added as targets to the lldbperf.xcodeproj project. It 
+is probably easiest to duplicate one of the existing targets. In order to 
+write a test based on lldb-perf, you need to subclass  lldb_perf::TestCase:
 
 using namespace lldb_perf;
 
@@ -19,6 +26,7 @@ class FormattersTest : public TestCase
 {
 
 Usually, you will define measurements as variables of your test case class:
+
 private:
     // C++ formatters
     TimeMeasurement<std::function<void(SBValue)>> m_dump_std_vector_measurement;
@@ -34,107 +42,126 @@ private:
     TimeMeasurement<std::function<void(SBValue)>> m_dump_nsbundle_measurement;
     TimeMeasurement<std::function<void(SBValue)>> m_dump_nsdate_measurement;
 
-A TimeMeasurement is, obviously, a class that measures “how much time to run this block of code”. the block of code is passed as an std::function (you can construct with a lambda!) - you need however to give the prototype of your block of code. in this example, we run blocks of code that take an SBValue and return nothing. other things are possible.
+A TimeMeasurement is, obviously, a class that measures “how much time to run 
+this block of code”. The block of code is passed as an std::function which you
+can construct with a lambda! You need to give the prototype of your block of
+code. In this example, we run blocks of code that take an SBValue and return
+nothing.
+
 These blocks look like:
-        m_dump_std_vector_measurement = CreateTimeMeasurement([] (SBValue value) -> void {
-            lldb_perf::Xcode::FetchVariable (value,1,false);
-        }, "std-vector", "time to dump an std::vector");
-Here we are saying: make me a measurement named “std-vector”, whose description is “time to dump an std::vector” and that takes the time required to call lldb_perf::Xcode::FetchVariable(value,1,false)
 
-The Xcode class is a collection of utility functions that replicate common Xcode patterns (FetchVariable unsurprisingly calls API functions that Xcode could use when populating a variables view entry - the 1 means “expand 1 level of depth” and the 
-false means “do not dump the data to stdout”)
+    m_dump_std_vector_measurement = CreateTimeMeasurement([] (SBValue value) -> void {
+        lldb_perf::Xcode::FetchVariable (value,1,false);
+    }, "std-vector", "time to dump an std::vector");
+
+Here we are saying: make me a measurement named “std-vector”, whose 
+description is “time to dump an std::vector” and that takes the time required
+to call lldb_perf::Xcode::FetchVariable(value,1,false).
+
+The Xcode class is a collection of utility functions that replicate common
+Xcode patterns (FetchVariable unsurprisingly calls API functions that Xcode
+could use when populating a variables view entry - the 1 means “expand 1 level
+of depth” and the false means “do not dump the data to stdout”)
 
 A full constructor for a TestCase looks like:
-    FormattersTest () : TestCase()
-    {
-        m_dump_std_vector_measurement = CreateTimeMeasurement([] (SBValue value) -> void {
-            lldb_perf::Xcode::FetchVariable (value,1,false);
-        }, "std-vector", "time to dump an std::vector");
-        m_dump_std_list_measurement = CreateTimeMeasurement([] (SBValue value) -> void {
-            lldb_perf::Xcode::FetchVariable (value,1,false);
-        }, "std-list", "time to dump an std::list");
-        m_dump_std_map_measurement = CreateTimeMeasurement([] (SBValue value) -> void {
-            lldb_perf::Xcode::FetchVariable (value,1,false);
-        }, "std-map", "time to dump an std::map");
-        m_dump_std_string_measurement = CreateTimeMeasurement([] (SBValue value) -> void {
-            lldb_perf::Xcode::FetchVariable (value,1,false);
-        }, "std-string", "time to dump an std::string");
-        
-        m_dump_nsstring_measurement = CreateTimeMeasurement([] (SBValue value) -> void {
-            lldb_perf::Xcode::FetchVariable (value,0,false);
-        }, "ns-string", "time to dump an NSString");
-        
-        m_dump_nsarray_measurement = CreateTimeMeasurement([] (SBValue value) -> void {
-            lldb_perf::Xcode::FetchVariable (value,1,false);
-        }, "ns-array", "time to dump an NSArray");
-        
-        m_dump_nsdictionary_measurement = CreateTimeMeasurement([] (SBValue value) -> void {
-            lldb_perf::Xcode::FetchVariable (value,1,false);
-        }, "ns-dictionary", "time to dump an NSDictionary");
-        
-        m_dump_nsset_measurement = CreateTimeMeasurement([] (SBValue value) -> void {
-            lldb_perf::Xcode::FetchVariable (value,1,false);
-        }, "ns-set", "time to dump an NSSet");
-        
-        m_dump_nsbundle_measurement = CreateTimeMeasurement([] (SBValue value) -> void {
-            lldb_perf::Xcode::FetchVariable (value,1,false);
-        }, "ns-bundle", "time to dump an NSBundle");
-        
-        m_dump_nsdate_measurement = CreateTimeMeasurement([] (SBValue value) -> void {
-            lldb_perf::Xcode::FetchVariable (value,0,false);
-        }, "ns-date", "time to dump an NSDate");
-    }
+
+FormattersTest () : TestCase()
+{
+    m_dump_std_vector_measurement = CreateTimeMeasurement([] (SBValue value) -> void {
+        lldb_perf::Xcode::FetchVariable (value,1,false);
+    }, "std-vector", "time to dump an std::vector");
+    m_dump_std_list_measurement = CreateTimeMeasurement([] (SBValue value) -> void {
+        lldb_perf::Xcode::FetchVariable (value,1,false);
+    }, "std-list", "time to dump an std::list");
+    m_dump_std_map_measurement = CreateTimeMeasurement([] (SBValue value) -> void {
+        lldb_perf::Xcode::FetchVariable (value,1,false);
+    }, "std-map", "time to dump an std::map");
+    m_dump_std_string_measurement = CreateTimeMeasurement([] (SBValue value) -> void {
+        lldb_perf::Xcode::FetchVariable (value,1,false);
+    }, "std-string", "time to dump an std::string");
+    
+    m_dump_nsstring_measurement = CreateTimeMeasurement([] (SBValue value) -> void {
+        lldb_perf::Xcode::FetchVariable (value,0,false);
+    }, "ns-string", "time to dump an NSString");
+    
+    m_dump_nsarray_measurement = CreateTimeMeasurement([] (SBValue value) -> void {
+        lldb_perf::Xcode::FetchVariable (value,1,false);
+    }, "ns-array", "time to dump an NSArray");
+    
+    m_dump_nsdictionary_measurement = CreateTimeMeasurement([] (SBValue value) -> void {
+        lldb_perf::Xcode::FetchVariable (value,1,false);
+    }, "ns-dictionary", "time to dump an NSDictionary");
+    
+    m_dump_nsset_measurement = CreateTimeMeasurement([] (SBValue value) -> void {
+        lldb_perf::Xcode::FetchVariable (value,1,false);
+    }, "ns-set", "time to dump an NSSet");
+    
+    m_dump_nsbundle_measurement = CreateTimeMeasurement([] (SBValue value) -> void {
+        lldb_perf::Xcode::FetchVariable (value,1,false);
+    }, "ns-bundle", "time to dump an NSBundle");
+    
+    m_dump_nsdate_measurement = CreateTimeMeasurement([] (SBValue value) -> void {
+        lldb_perf::Xcode::FetchVariable (value,0,false);
+    }, "ns-date", "time to dump an NSDate");
+}
 
 Once your test case is constructed, Setup() is called on it:
-    virtual void
+
+    virtual bool
        Setup (int argc, const char** argv)
     {
         m_app_path.assign(argv[1]);
         m_out_path.assign(argv[2]);
         m_target = m_debugger.CreateTarget(m_app_path.c_str());
         m_target.BreakpointCreateByName("main");
-        
-        Launch (NULL,".");
+        SBLaunchInfo launch_info (argv);
+        return Launch (launch_info);
     }
-(I am considering moving Setup to the constructor, to be honest, but have not done so yet because it might also make sense to have Setup() return a bool or an Error object. stay tuned for more here!)
-In Setup() you process command-line arguments and create a target to run
+    
+Setup() returns a boolean value that indicates if setup was successful.
+In Setup() you fill out a SBLaunchInfo with any needed settings for launching
+your process like arguments, environment variables, working directory, and
+much more.
+
 The last thing you want to do in setup is call Launch():
+
        bool
-       Launch (const char** args, const char* cwd);
-This ensures your target is now alive. Make sure to have a breakpoint created :)
-Once you launched, the event loop is entered. The event loop waits for stops, and when it gets one, it calls your test case’s 
+       Launch (coSBLaunchInfo &launch_info);
+
+This ensures your target is now alive. Make sure to have a breakpoint created.
+
+Once you launched, the event loop is entered. The event loop waits for stops, 
+and when it gets one, it calls your test case’s TestStep() function:
+
     virtual void
        TestStep (int counter, ActionWanted &next_action)
 
-the counter is the step id (a monotonically increasing counter). In TestStep() you will essentially run your measurements and then return what you want the driver to do.
+the counter is the step id (a monotonically increasing counter). In TestStep()
+you will essentially run your measurements and then return what you want the
+driver to do by filling in the ActionWanted object named "next_action".
+
 Possible options are:
-- continue process          ActionWanted::Continue()
-- kill process              ActionWanted::Kill()
-- finish on a thread        ActionWanted::Finish(SBThread)
-- step-over on a thread.    ActionWanted::Next(SBThread)
-
-If you use ActionWanted::Next() or ActionWanted::Finish(), define a SelectMyThread() that gives you an SBThread. I usually use a filename as key:
-    SBThread
-       SelectMyThread (const char* file_name)
-       {
-               auto threads_count = m_process.GetNumThreads();
-               for (auto thread_num = 0; thread_num < threads_count; thread_num++)
-               {
-                       SBThread thread(m_process.GetThreadAtIndex(thread_num));
-                       auto local_file_name = thread.GetFrameAtIndex(0).GetCompileUnit().GetFileSpec().GetFilename();
-                       if (!local_file_name)
-                               continue;
-                       if (strcmp(local_file_name,file_name))
-                               continue;
-                       return thread;
-               }
-               Xcode::RunCommand(m_debugger,"bt all",true);
-               assert(false);
-       }
-you might want to use some other logic in your selection.
-For your convenience TestCase has m_debugger, m_target and m_process as member variables. There is also an m_thread, but that is for you to set if you need/want to use it!
+- continue process          next_action.Continue();
+- kill process              next_action.Kill();
+- Step-out on a thread      next_action.StepOut(SBThread)
+- step-over on a thread.    next_action.StepOver(SBThread)
+
+If you use ActionWanted::Next() or ActionWanted::Finish() you need to specify
+a thread to use. By default the TestCase class will select the first thread
+that had a stop reason other than eStopReasonNone and place it into the 
+m_thread member variable of TestCase. This means if your test case hits a
+breakpoint or steps, the thread that hit the breakpoint or finished the step
+will automatically be selected in the process (m_process) and m_thread will
+be set to this thread. If you have one or more threads that will stop with a
+reason simultaneously, you will need to find those threads manually by 
+iterating through the process list and determine what to do next.
+
+For your convenience TestCase has m_debugger, m_target and m_process as member
+variables. As state above m_thread will be filled in with the first thread 
+that has a stop reason.
 
 An example:
+
     virtual void
        TestStep (int counter, ActionWanted &next_action)
     {
@@ -148,14 +175,14 @@ An example:
             break;
         case 2:
             DoTest ();
-            next_action.Continue();
+            next_action.StepOver(m_thread);
             break;
 
 DoTest() is a function I define in my own class that calls the measurements:
     void
     DoTest ()
     {
-        SBThread thread_main(SelectMyThread("fmts_tester.mm"));
+        SBThread thread_main(m_thread);
         SBFrame frame_zero(thread_main.GetFrameAtIndex(0));
         
         m_dump_nsarray_measurement(frame_zero.FindVariable("nsarray", lldb::eDynamicCanRunTarget));
@@ -193,8 +220,11 @@ DoTest() is a function I define in my own class that calls the measurements:
         m_dump_std_string_measurement(frame_zero.FindVariable("sstr4", lldb::eDynamicCanRunTarget));
     }
 
-Essentially, you call your measurements as if they were functions, passing them arguments and all, and they will do the right thing with gathering stats.
+Essentially, you call your measurements as if they were functions, passing 
+them arguments and all, and they will do the right thing with gathering stats.
+
 The last step is usually to KILL the inferior and bail out:
+
     virtual ActionWanted
        TestStep (int counter)
     {
@@ -214,6 +244,7 @@ The last step is usually to KILL the inferior and bail out:
 
 
 At the end, you define a Results() function:
+
     void
     Results ()
     {
@@ -230,24 +261,35 @@ At the end, you define a Results() function:
         m_dump_nsbundle_measurement.Write(array);
         m_dump_nsdate_measurement.Write(array);
 
-        CFDataRef xmlData = CFPropertyListCreateData(kCFAllocatorDefault, array.get(), kCFPropertyListXMLFormat_v1_0, 0, NULL);
+        CFDataRef xmlData = CFPropertyListCreateData (kCFAllocatorDefault, 
+                                                      array.get(), 
+                                                      kCFPropertyListXMLFormat_v1_0, 
+                                                      0, 
+                                                      NULL);
         
-        CFURLRef file = CFURLCreateFromFileSystemRepresentation(NULL, (const UInt8*)m_out_path.c_str(), m_out_path.size(), FALSE);
+        CFURLRef file = CFURLCreateFromFileSystemRepresentation (NULL, 
+                                                                 (const UInt8*)m_out_path.c_str(), 
+                                                                 m_out_path.size(), 
+                                                                 FALSE);
         
         CFURLWriteDataAndPropertiesToResource(file,xmlData,NULL,NULL);
     }
 
-For now, pretty much copy this and just call Write() on all your measurements. I plan to move this higher in the hierarchy (e.g. make a TestCase::Write(filename) fairly soon).
+For now, pretty much copy this and just call Write() on all your measurements.
+I plan to move this higher in the hierarchy (e.g. make a 
+TestCase::Write(filename) fairly soon).
 
 Your main() will look like:
+
 int main(int argc, const char * argv[])
 {
     MyTest test;
-    TestCase::Run(test,argc,argv);
+    TestCase::Run (test, argc, argv);
     return 0;
 }
 
 If you are debugging your test, before Run() call
+
     test.SetVerbose(true);
 
 Feel free to send any questions and ideas for improvements.
index cc12b3e..5e0c948 100644 (file)
@@ -68,40 +68,21 @@ public:
     {
     }
     
-    virtual void
+    virtual bool
        Setup (int argc, const char** argv)
     {
         m_app_path.assign(argv[1]);
         m_out_path.assign(argv[2]);
         m_target = m_debugger.CreateTarget(m_app_path.c_str());
         m_target.BreakpointCreateByName("main");
-        
-        Launch (NULL,".");
+        SBLaunchInfo launch_info(argv);
+        return Launch (launch_info);
     }
     
-    SBThread
-       SelectMyThread (const char* file_name)
-       {
-               auto threads_count = m_process.GetNumThreads();
-               for (auto thread_num = 0; thread_num < threads_count; thread_num++)
-               {
-                       SBThread thread(m_process.GetThreadAtIndex(thread_num));
-                       auto local_file_name = thread.GetFrameAtIndex(0).GetCompileUnit().GetFileSpec().GetFilename();
-                       if (!local_file_name)
-                               continue;
-                       if (strcmp(local_file_name,file_name))
-                               continue;
-                       return thread;
-               }
-               Xcode::RunCommand(m_debugger,"bt all",true);
-               assert(false);
-       }
-    
     void
     DoTest ()
     {
-        SBThread thread_main(SelectMyThread("fmts_tester.mm"));
-        SBFrame frame_zero(thread_main.GetFrameAtIndex(0));
+        SBFrame frame_zero(m_thread.GetFrameAtIndex(0));
         
         m_dump_nsarray_measurement(frame_zero.FindVariable("nsarray", lldb::eDynamicCanRunTarget));
         m_dump_nsarray_measurement(frame_zero.FindVariable("nsmutablearray", lldb::eDynamicCanRunTarget));
index ef1a08f..dba3b4d 100644 (file)
@@ -54,9 +54,10 @@ public:
     {
     }
     
-    virtual void
+    virtual bool
        Setup (int argc, const char** argv)
     {
+        SetVerbose(true);
         m_app_path.assign(argv[1]);
         m_doc_path.assign(argv[2]);
         m_out_path.assign(argv[3]);
@@ -67,11 +68,11 @@ public:
         const char* persist_skip = "YES";
         const char* empty = nullptr;
         const char* args[] = {file_arg,persist_arg,persist_skip,empty};
+        SBLaunchInfo launch_info (args);
         m_file_line_bp_measurement(m_target, "SKTDocument.m",245);
         m_file_line_bp_measurement(m_target, "SKTDocument.m",283);
         m_file_line_bp_measurement(m_target, "SKTText.m",326);
-        
-        Launch (args,".");
+        return Launch (launch_info);
     }
     
     void
@@ -98,12 +99,11 @@ public:
         case 1:
             {
                 DoTest ();
-                SBThread thread(SelectMyThread("SKTDocument.m"));
-                m_run_expr_measurement(thread.GetFrameAtIndex(0),"properties");
-                m_run_expr_measurement(thread.GetFrameAtIndex(0),"[properties description]");
-                m_run_expr_measurement(thread.GetFrameAtIndex(0),"typeName");
-                m_run_expr_measurement(thread.GetFrameAtIndex(0),"data");
-                m_run_expr_measurement(thread.GetFrameAtIndex(0),"[data description]");
+                m_run_expr_measurement(m_thread.GetFrameAtIndex(0),"properties");
+                m_run_expr_measurement(m_thread.GetFrameAtIndex(0),"[properties description]");
+                m_run_expr_measurement(m_thread.GetFrameAtIndex(0),"typeName");
+                m_run_expr_measurement(m_thread.GetFrameAtIndex(0),"data");
+                m_run_expr_measurement(m_thread.GetFrameAtIndex(0),"[data description]");
                 next_action.Continue();
             }
             break;
@@ -118,52 +118,49 @@ public:
         case 3:
             {
                 DoTest ();
-                next_action.Next(SelectMyThread ("SKTText.m"));
+                next_action.StepOver(m_thread);
             }
             break;
 
         case 4:
             {
                 DoTest ();
-                SBThread thread(SelectMyThread("SKTText.m"));
-                m_run_expr_measurement(thread.GetFrameAtIndex(0),"layoutManager");
-                m_run_expr_measurement(thread.GetFrameAtIndex(0),"contents");
-                next_action.Next(thread);
+                m_run_expr_measurement(m_thread.GetFrameAtIndex(0),"layoutManager");
+                m_run_expr_measurement(m_thread.GetFrameAtIndex(0),"contents");
+                next_action.StepOver(m_thread);
             }
             break;
         
         case 5:
             {
                 DoTest ();
-                next_action.Next(SelectMyThread ("SKTText.m"));
+                next_action.StepOver(m_thread);
             }
             break;
 
         case 6:
             {
                 DoTest ();
-                next_action.Next(SelectMyThread ("SKTText.m"));
+                next_action.StepOver(m_thread);
             }
             break;
 
         case 7:
             {
                 DoTest ();
-                SBThread thread(SelectMyThread("SKTText.m"));
-                m_run_expr_measurement(thread.GetFrameAtIndex(0),"@\"an NSString\"");
-                m_run_expr_measurement(thread.GetFrameAtIndex(0),"[(id)@\"an NSString\" description]");
-                m_run_expr_measurement(thread.GetFrameAtIndex(0),"@[@1,@2,@3]");
-                next_action.Finish(thread);
+                m_run_expr_measurement(m_thread.GetFrameAtIndex(0),"@\"an NSString\"");
+                m_run_expr_measurement(m_thread.GetFrameAtIndex(0),"[(id)@\"an NSString\" description]");
+                m_run_expr_measurement(m_thread.GetFrameAtIndex(0),"@[@1,@2,@3]");
+                next_action.StepOut(m_thread);
             }
             break;
 
         case 8:
             {
                 DoTest ();
-                SBThread thread(SelectMyThread("SKTGraphicView.m"));
-                m_run_expr_measurement(thread.GetFrameAtIndex(0),"[graphics description]");
-                m_run_expr_measurement(thread.GetFrameAtIndex(0),"[selectionIndexes description]");
-                m_run_expr_measurement(thread.GetFrameAtIndex(0),"(BOOL)NSIntersectsRect(rect, graphicDrawingBounds)");
+                m_run_expr_measurement(m_thread.GetFrameAtIndex(0),"[graphics description]");
+                m_run_expr_measurement(m_thread.GetFrameAtIndex(0),"[selectionIndexes description]");
+                m_run_expr_measurement(m_thread.GetFrameAtIndex(0),"(BOOL)NSIntersectsRect(rect, graphicDrawingBounds)");
                 next_action.Kill();
             }
             break;
@@ -200,23 +197,6 @@ private:
     Measurement<lldb_perf::TimeGauge, std::function<void(SBProcess,int)>> m_fetch_vars_measurement;
     Measurement<lldb_perf::TimeGauge, std::function<void(SBFrame,const char*)>> m_run_expr_measurement;
     
-    SBThread
-       SelectMyThread (const char* file_name)
-       {
-               auto threads_count = m_process.GetNumThreads();
-               for (auto thread_num = 0; thread_num < threads_count; thread_num++)
-               {
-                       SBThread thread(m_process.GetThreadAtIndex(thread_num));
-                       auto local_file_name = thread.GetFrameAtIndex(0).GetCompileUnit().GetFileSpec().GetFilename();
-                       if (!local_file_name)
-                               continue;
-                       if (strcmp(local_file_name,file_name))
-                               continue;
-                       return thread;
-               }
-               Xcode::RunCommand(m_debugger,"bt all",true);
-               assert(false);
-       }
     std::string m_app_path;
     std::string m_doc_path;
     std::string m_out_path;
index ca825d9..ac8a4c4 100644 (file)
 using namespace lldb_perf;
 
 TestCase::TestCase () :
-m_debugger(),
-m_target(),
-m_process(),
-m_thread(),
-m_listener(),
-m_verbose(false)
+    m_debugger(),
+    m_target(),
+    m_process(),
+    m_thread(),
+    m_listener(),
+    m_verbose(false)
 {
     SBDebugger::Initialize();
        SBHostOS::ThreadCreated ("<lldb-tester.app.main>");
@@ -25,16 +25,25 @@ m_verbose(false)
        m_listener = m_debugger.GetListener();
 }
 
-void
+bool
 TestCase::Setup (int argc, const char** argv)
-{}
+{
+    return false;
+}
 
 bool
-TestCase::Launch (const char** args, const char* cwd)
+TestCase::Launch (lldb::SBLaunchInfo &launch_info)
 {
-       m_process = m_target.LaunchSimple(args,NULL,cwd);
-       m_process.GetBroadcaster().AddListener(m_listener, SBProcess::eBroadcastBitStateChanged | SBProcess::eBroadcastBitInterrupt);
-       return m_process.IsValid ();
+    lldb::SBError error;
+       m_process = m_target.Launch (launch_info, error);
+    if (!error.Success())
+        fprintf (stderr, "error: %s\n", error.GetCString());
+    if (m_process.IsValid())
+    {
+        m_process.GetBroadcaster().AddListener(m_listener, SBProcess::eBroadcastBitStateChanged | SBProcess::eBroadcastBitInterrupt);
+        return true;
+    }
+    return false;
 }
 
 void
@@ -81,10 +90,12 @@ TestCase::Loop ()
                        case eStateSuspended:
                        {
                                bool fatal = false;
+                bool selected_thread = false;
                                for (auto thread_index = 0; thread_index < m_process.GetNumThreads(); thread_index++)
                                {
                                        SBThread thread(m_process.GetThreadAtIndex(thread_index));
                                        SBFrame frame(thread.GetFrameAtIndex(0));
+                    bool select_thread = false;
                                        StopReason stop_reason = thread.GetStopReason();
                                        if (m_verbose) printf("tid = 0x%llx pc = 0x%llx ",thread.GetThreadID(),frame.GetPC());
                                        switch (stop_reason)
@@ -94,10 +105,12 @@ TestCase::Loop ()
                             break;
                             
                                        case eStopReasonTrace:
+                            select_thread = true;
                             if (m_verbose) printf("trace\n");
                             break;
                             
                                        case eStopReasonPlanComplete:
+                            select_thread = true;
                             if (m_verbose) printf("plan complete\n");
                             break;
                                        case eStopReasonThreadExiting:
@@ -110,19 +123,28 @@ TestCase::Loop ()
                             if (m_verbose) printf("invalid\n");
                             break;
                                        case eStopReasonException:
+                            select_thread = true;
                             if (m_verbose) printf("exception\n");
                             fatal = true;
                             break;
                                        case eStopReasonBreakpoint:
+                            select_thread = true;
                             if (m_verbose) printf("breakpoint id = %lld.%lld\n",thread.GetStopReasonDataAtIndex(0),thread.GetStopReasonDataAtIndex(1));
                             break;
                                        case eStopReasonWatchpoint:
+                            select_thread = true;
                             if (m_verbose) printf("watchpoint id = %lld\n",thread.GetStopReasonDataAtIndex(0));
                             break;
                                        case eStopReasonSignal:
+                            select_thread = true;
                             if (m_verbose) printf("signal %d\n",(int)thread.GetStopReasonDataAtIndex(0));
                             break;
                                        }
+                    if (select_thread && !selected_thread)
+                    {
+                        m_thread = thread;
+                        selected_thread = m_process.SetSelectedThread(thread);
+                    }
                                }
                                if (fatal)
                                {
@@ -134,12 +156,13 @@ TestCase::Loop ()
                 ActionWanted action;
                                TestStep(step, action);
                                step++;
+                SBError err;
                                switch (action.type)
                                {
                                        case ActionWanted::Type::eContinue:
-                                               m_debugger.HandleCommand("continue");
+                        err = m_process.Continue();
                                                break;
-                    case ActionWanted::Type::eFinish:
+                    case ActionWanted::Type::eStepOut:
                         if (action.thread.IsValid() == false)
                         {
                             if (m_verbose) Xcode::RunCommand(m_debugger,"bt all",true);
@@ -147,7 +170,7 @@ TestCase::Loop ()
                             exit(501);
                         }
                         m_process.SetSelectedThread(action.thread);
-                        m_debugger.HandleCommand("finish");
+                        action.thread.StepOut();
                                                break;
                                        case ActionWanted::Type::eNext:
                         if (action.thread.IsValid() == false)
@@ -157,7 +180,7 @@ TestCase::Loop ()
                             exit(500);
                         }
                         m_process.SetSelectedThread(action.thread);
-                        m_debugger.HandleCommand("next");
+                        action.thread.StepOver();
                                                break;
                                        case ActionWanted::Type::eKill:
                                                if (m_verbose) printf("I want to die\n");
@@ -173,7 +196,9 @@ TestCase::Loop ()
 void
 TestCase::Run (TestCase& test, int argc, const char** argv)
 {
-    test.Setup(argc, argv);
-    test.Loop();
-    test.Results();
+    if (test.Setup(argc, argv))
+    {
+        test.Loop();
+        test.Results();
+    }
 }
index a46dc5a..69d8002 100644 (file)
@@ -25,7 +25,7 @@ public:
                {
                        eNext,
                        eContinue,
-            eFinish,
+            eStepOut,
                        eKill
                } type;
                lldb::SBThread thread;
@@ -44,16 +44,16 @@ public:
         }
         
         void
-        Next (lldb::SBThread t)
+        StepOver (lldb::SBThread t)
         {
             type = Type::eNext;
             thread = t;
         }
 
         void
-        Finish (lldb::SBThread t)
+        StepOut (lldb::SBThread t)
         {
-            type = Type::eFinish;
+            type = Type::eStepOut;
             thread = t;
         }
         
@@ -69,14 +69,14 @@ public:
     ~TestCase ()
     {}
     
-       virtual void
+       virtual bool
        Setup (int argc, const char** argv);
     
        virtual void
        TestStep (int counter, ActionWanted &next_action) = 0;
        
        bool
-       Launch (const char** args, const char* cwd);
+       Launch (lldb::SBLaunchInfo &launch_info);
        
        void
        Loop();
index e0b2a79..6d42118 100644 (file)
@@ -26,7 +26,7 @@ Xcode::FetchVariable (SBValue value, uint32_t expand, bool verbose)
        auto type_3 = value.GetType();
        auto type_name_2 = value.GetTypeName();
        if (verbose)
-               printf("%s %s = %llu %s\n",value.GetTypeName(),value.GetName(),num_value,summary);
+               printf("%s %s = 0x%llx (%llu) %s\n",value.GetTypeName(),value.GetName(),num_value, num_value,summary);
        if (expand > 0)
        {
                auto count = value.GetNumChildren();
index dfb32ac..566a428 100644 (file)
                                GCC_WARN_UNDECLARED_SELECTOR = YES;
                                GCC_WARN_UNINITIALIZED_AUTOS = YES;
                                GCC_WARN_UNUSED_VARIABLE = YES;
-                               MACOSX_DEPLOYMENT_TARGET = 10.9;
+                               MACOSX_DEPLOYMENT_TARGET = 10.7;
                                ONLY_ACTIVE_ARCH = YES;
-                               SDKROOT = macosx;
                        };
                        name = Debug;
                };
                                GCC_WARN_UNDECLARED_SELECTOR = YES;
                                GCC_WARN_UNINITIALIZED_AUTOS = YES;
                                GCC_WARN_UNUSED_VARIABLE = YES;
-                               MACOSX_DEPLOYMENT_TARGET = 10.9;
-                               SDKROOT = macosx;
+                               MACOSX_DEPLOYMENT_TARGET = 10.7;
                        };
                        name = Release;
                };