[Lldb-commits] [lldb] r202431 - Fixed the lldb_perf_clang.cpp test case to be able to run correctly.

Greg Clayton gclayton at apple.com
Thu Feb 27 13:35:50 PST 2014


Author: gclayton
Date: Thu Feb 27 15:35:49 2014
New Revision: 202431

URL: http://llvm.org/viewvc/llvm-project?rev=202431&view=rev
Log:
Fixed the lldb_perf_clang.cpp test case to be able to run correctly.

1 - There were some outdated options being passed to clang
2 - There were some bad paths being passed as options
3 - The path to the main.cpp file ("/tmp/main.cpp") was wrong when the tests were being run, now we create a temp file
4 - Added a new ActionType::eNone to do nothing (no continue, step, or kill)


Modified:
    lldb/trunk/tools/lldb-perf/common/clang/lldb_perf_clang.cpp
    lldb/trunk/tools/lldb-perf/lib/TestCase.cpp
    lldb/trunk/tools/lldb-perf/lib/TestCase.h

Modified: lldb/trunk/tools/lldb-perf/common/clang/lldb_perf_clang.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/tools/lldb-perf/common/clang/lldb_perf_clang.cpp?rev=202431&r1=202430&r2=202431&view=diff
==============================================================================
--- lldb/trunk/tools/lldb-perf/common/clang/lldb_perf_clang.cpp (original)
+++ lldb/trunk/tools/lldb-perf/common/clang/lldb_perf_clang.cpp Thu Feb 27 15:35:49 2014
@@ -84,6 +84,8 @@ public:
 	virtual void
 	TestStep (int counter, ActionWanted &next_action)
     {
+        char temp_source_path[PATH_MAX] = "/tmp/main.XXXXXX.cpp";
+
         switch (counter)
         {
             case 0:
@@ -98,6 +100,47 @@ public:
                     
                     m_time_set_bp_main();
 
+                    int fd = mkstemps(temp_source_path, 4);
+
+                    if (fd >= 0)
+                    {
+                        const char *source_content = R"(
+#include <stdio.h>
+#include <stdint.h>
+#include <vector>
+                        
+namespace {
+    struct Foo
+    {
+        int i; int j;
+    };
+    void doit (const Foo &foo)
+    {
+        printf ("doit(%i)\n", foo.i);
+    }
+}
+                        
+int main (int argc, char const *argv[], char const *envp[])
+{
+    std::vector<int> ints;
+    for (int i=0;i<10;++i)
+    ints.push_back(i);
+    printf ("hello world\n");
+    Foo foo = { 12, 13 };
+    doit (foo);
+    return 0;
+}
+)";
+                        write (fd, source_content, strlen(source_content));
+                        close(fd);
+                    }
+                    else
+                    {
+                        const char *error_cstr = strerror(errno);
+                        fprintf (stderr, "error: failed to created temporary source file: '%s' (%s)", temp_source_path, error_cstr);
+                        exit(2);
+                    }
+
                     m_time_launch_stop_main.Start();
                     const char *clang_argv[] = {
                         "-cc1",
@@ -116,10 +159,8 @@ public:
                         "-target-linker-version", "132.10.1",
                         "-v",
                         "-g",
-                        "-resource-dir", "/tmp/clang-176809/llvm-build/build/Debug/bin/../lib/clang/3.3",
                         "-O0",
                         "-fdeprecated-macro",
-                        "-fdebug-compilation-dir", "/tmp/clang-176809/llvm-build/build/Debug/bin",
                         "-ferror-limit", "19",
                         "-fmessage-length", "298",
                         "-stack-protector", "1",
@@ -127,7 +168,6 @@ public:
                         "-fblocks",
                         "-fobjc-runtime=macosx-10.8.0",
                         "-fobjc-dispatch-method=mixed",
-                        "-fobjc-default-synthesize-properties",
                         "-fencode-extended-block-signature",
                         "-fcxx-exceptions",
                         "-fexceptions",
@@ -137,18 +177,18 @@ public:
                         "-vectorize-loops",
                         "-o", "/tmp/main.o",
                         "-x", "c++",
-                        "/tmp/main.cpp",
+                        NULL,
                         NULL };
+                    clang_argv[sizeof(clang_argv)/sizeof(const char *)-2] = temp_source_path;
                     SBLaunchInfo launch_info(clang_argv);
                     Launch (launch_info);
+                    next_action.None(); // Don't continue or do anything, just wait for next event...
                 }
                 break;
             case 1:
-                puts("stop");
-                m_time_launch_stop_main.Stop();
-                m_time_total.Stop();
-            case 2:
                 {
+                    m_time_launch_stop_main.Stop();
+                    m_time_total.Stop();
                     SBFrame frame (m_thread.GetFrameAtIndex(0));
 
                     // Time the first expression evaluation
@@ -163,7 +203,7 @@ public:
                     next_action.Continue();
                 }
                 break;
-            case 3:
+            case 2:
                 {
                     SBFrame frame (m_thread.GetFrameAtIndex(21));
                     SBValue result;
@@ -171,7 +211,6 @@ public:
                     {
                         m_expr_frame_non_zero(frame);
                     }
-                    m_target.BreakpointCreateByName("DeclContext::lookup");
                     next_action.Continue();
                 }
                 break;

Modified: lldb/trunk/tools/lldb-perf/lib/TestCase.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/tools/lldb-perf/lib/TestCase.cpp?rev=202431&r1=202430&r2=202431&view=diff
==============================================================================
--- lldb/trunk/tools/lldb-perf/lib/TestCase.cpp (original)
+++ lldb/trunk/tools/lldb-perf/lib/TestCase.cpp Thu Feb 27 15:35:49 2014
@@ -152,101 +152,125 @@ TestCase::Loop ()
             if (m_verbose)
                 printf("event = %s\n",SBDebugger::StateAsCString(state));
             if (SBProcess::GetRestartedFromEvent(evt))
-                continue;
-            switch (state)
             {
-            case eStateInvalid:
-            case eStateDetached:
-            case eStateCrashed:
-            case eStateUnloaded:
-                break;
-            case eStateExited:
-                return;
-            case eStateConnected:
-            case eStateAttaching:
-            case eStateLaunching:
-            case eStateRunning:
-            case eStateStepping:
-                continue;
-            case eStateStopped:
-            case eStateSuspended:
+                if (m_verbose)
                 {
-                    call_test_step = true;
-                    bool fatal = false;
-                    bool selected_thread = false;
-                    for (auto thread_index = 0; thread_index < m_process.GetNumThreads(); thread_index++)
+                    const uint32_t num_threads = m_process.GetNumThreads();
+                    for (auto thread_index = 0; thread_index < num_threads; 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)
+                        SBStream strm;
+                        strm.RedirectToFileHandle(stdout, false);
+                        frame.GetDescription(strm);
+                    }
+                    puts("restarted");
+                }
+                call_test_step = false;
+            }
+            else
+            {
+                switch (state)
+                {
+                case eStateInvalid:
+                case eStateDetached:
+                case eStateCrashed:
+                case eStateUnloaded:
+                    break;
+                case eStateExited:
+                    return;
+                case eStateConnected:
+                case eStateAttaching:
+                case eStateLaunching:
+                case eStateRunning:
+                case eStateStepping:
+                    call_test_step = false;
+                    break;
+        
+                case eStateStopped:
+                case eStateSuspended:
+                    {
+                        call_test_step = true;
+                        bool fatal = false;
+                        bool selected_thread = false;
+                        const uint32_t num_threads = m_process.GetNumThreads();
+                        for (auto thread_index = 0; thread_index < num_threads; thread_index++)
                         {
-                            case eStopReasonNone:
-                                if (m_verbose)
-                                    printf("none\n");
-                                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:
-                                if (m_verbose)
-                                    printf("thread exiting\n");
-                                break;
-                            case eStopReasonExec:
-                                if (m_verbose)
-                                    printf("exec\n");
-                                break;
-                            case eStopReasonInvalid:
-                                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;
+                            SBThread thread(m_process.GetThreadAtIndex(thread_index));
+                            SBFrame frame(thread.GetFrameAtIndex(0));
+                            SBStream strm;
+                            strm.RedirectToFileHandle(stdout, false);
+                            frame.GetDescription(strm);
+                            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)
+                            {
+                                case eStopReasonNone:
+                                    if (m_verbose)
+                                        printf("none\n");
+                                    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:
+                                    if (m_verbose)
+                                        printf("thread exiting\n");
+                                    break;
+                                case eStopReasonExec:
+                                    if (m_verbose)
+                                        printf("exec\n");
+                                    break;
+                                case eStopReasonInvalid:
+                                    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 (select_thread && !selected_thread)
+                        if (fatal)
                         {
-                            m_thread = thread;
-                            selected_thread = m_process.SetSelectedThread(thread);
+                            if (m_verbose) Xcode::RunCommand(m_debugger,"bt all",true);
+                            exit(1);
                         }
                     }
-                    if (fatal)
-                    {
-                        if (m_verbose) Xcode::RunCommand(m_debugger,"bt all",true);
-                        exit(1);
-                    }
+                    break;
                 }
-                break;
-			}
+            }
 		}
         else
         {
@@ -264,6 +288,9 @@ TestCase::Loop ()
             SBError err;
             switch (action.type)
             {
+            case ActionWanted::Type::eNone:
+                // Just exit and wait for the next event
+                break;
             case ActionWanted::Type::eContinue:
                 err = m_process.Continue();
                 break;

Modified: lldb/trunk/tools/lldb-perf/lib/TestCase.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/tools/lldb-perf/lib/TestCase.h?rev=202431&r1=202430&r2=202431&view=diff
==============================================================================
--- lldb/trunk/tools/lldb-perf/lib/TestCase.h (original)
+++ lldb/trunk/tools/lldb-perf/lib/TestCase.h Thu Feb 27 15:35:49 2014
@@ -32,6 +32,7 @@ public:
             eStepOut,
             eRelaunch,
             eCallNext,
+            eNone,
 			eKill
 		} type;
 		lldb::SBThread thread;
@@ -45,6 +46,13 @@ public:
         }
         
         void
+        None ()
+        {
+            type = Type::eNone;
+            thread = lldb::SBThread();
+        }
+
+        void
         Continue()
         {
             type = Type::eContinue;





More information about the lldb-commits mailing list