From gclayton at apple.com Mon Jan 17 00:17:42 2011 From: gclayton at apple.com (Greg Clayton) Date: Mon, 17 Jan 2011 06:17:42 -0000 Subject: [Lldb-commits] [lldb] r123617 - /lldb/trunk/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.cpp Message-ID: <20110117061742.D8D172A6C12C@llvm.org> Author: gclayton Date: Mon Jan 17 00:17:42 2011 New Revision: 123617 URL: http://llvm.org/viewvc/llvm-project?rev=123617&view=rev Log: Another fix for the objective C runtime object checker to not use NULL when it isn't defined. Modified: lldb/trunk/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.cpp Modified: lldb/trunk/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.cpp?rev=123617&r1=123616&r2=123617&view=diff ============================================================================== --- lldb/trunk/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.cpp (original) +++ lldb/trunk/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.cpp Mon Jan 17 00:17:42 2011 @@ -156,7 +156,7 @@ " if ($__lldb_arg_obj == (void *)0) \n" " return; // nil is ok \n" " void **$isa_ptr = (void **)$__lldb_arg_obj; \n" - " if (*$isa_ptr == NULL || !gdb_class_getClass(*$isa_ptr)) \n" + " if (*$isa_ptr == (void *)0 || !gdb_class_getClass(*$isa_ptr)) \n" " *((volatile int *)0) = 'ocgc'; \n" "} \n", name); From scallanan at apple.com Mon Jan 17 14:50:38 2011 From: scallanan at apple.com (Sean Callanan) Date: Mon, 17 Jan 2011 20:50:38 -0000 Subject: [Lldb-commits] [lldb] r123671 - /lldb/trunk/source/Symbol/ClangASTContext.cpp Message-ID: <20110117205038.866C02A6C12C@llvm.org> Author: spyffe Date: Mon Jan 17 14:50:38 2011 New Revision: 123671 URL: http://llvm.org/viewvc/llvm-project?rev=123671&view=rev Log: Fixed a bug which would trigger an assert() in LLDB; we were setting a forward-declared Objective-C class type as being completed using an ExternalSemaSource, but this is neither legal nor necessary. Modified: lldb/trunk/source/Symbol/ClangASTContext.cpp Modified: lldb/trunk/source/Symbol/ClangASTContext.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Symbol/ClangASTContext.cpp?rev=123671&r1=123670&r2=123671&view=diff ============================================================================== --- lldb/trunk/source/Symbol/ClangASTContext.cpp (original) +++ lldb/trunk/source/Symbol/ClangASTContext.cpp Mon Jan 17 14:50:38 2011 @@ -1083,8 +1083,8 @@ if (class_interface_decl) { - if (has_extern) - class_interface_decl->setExternallyCompleted(); + //if (has_extern) + // class_interface_decl->setExternallyCompleted(); class_interface_decl->setHasExternalLexicalStorage (has_extern); //class_interface_decl->setHasExternalVisibleStorage (has_extern); return true; From gclayton at apple.com Mon Jan 17 14:59:07 2011 From: gclayton at apple.com (Greg Clayton) Date: Mon, 17 Jan 2011 20:59:07 -0000 Subject: [Lldb-commits] [lldb] r123672 - /lldb/trunk/source/Symbol/ClangASTContext.cpp Message-ID: <20110117205907.6509C2A6C12C@llvm.org> Author: gclayton Date: Mon Jan 17 14:59:07 2011 New Revision: 123672 URL: http://llvm.org/viewvc/llvm-project?rev=123672&view=rev Log: Removed commented out code since it was incorrect code to begin with and we don't want anyone thinking they should put it back in. Modified: lldb/trunk/source/Symbol/ClangASTContext.cpp Modified: lldb/trunk/source/Symbol/ClangASTContext.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Symbol/ClangASTContext.cpp?rev=123672&r1=123671&r2=123672&view=diff ============================================================================== --- lldb/trunk/source/Symbol/ClangASTContext.cpp (original) +++ lldb/trunk/source/Symbol/ClangASTContext.cpp Mon Jan 17 14:59:07 2011 @@ -1083,8 +1083,6 @@ if (class_interface_decl) { - //if (has_extern) - // class_interface_decl->setExternallyCompleted(); class_interface_decl->setHasExternalLexicalStorage (has_extern); //class_interface_decl->setHasExternalVisibleStorage (has_extern); return true; From gclayton at apple.com Mon Jan 17 15:03:33 2011 From: gclayton at apple.com (Greg Clayton) Date: Mon, 17 Jan 2011 21:03:33 -0000 Subject: [Lldb-commits] [lldb] r123673 - in /lldb/trunk/source/Plugins/Process/Utility: RegisterContextLLDB.cpp RegisterContextLLDB.h UnwindLLDB.cpp Message-ID: <20110117210333.601482A6C12C@llvm.org> Author: gclayton Date: Mon Jan 17 15:03:33 2011 New Revision: 123673 URL: http://llvm.org/viewvc/llvm-project?rev=123673&view=rev Log: Avoid infinite loops in stack backtraces and renamed: bool RegisterContextLLDB::GetPC (addr_t& pc); to: bool RegisterContextLLDB::ReadPC (addr_t& pc); To avoid confusion with the GetPC() function that is part of the lldb_private::RegisterContext: uint64_t RegisterContext::GetPC (uint64_t fail_value); Bad things could happen if the two got intermixed and the wrong one got called. Fixed inifinite loop detection by watching for two frames where the RegisterContextLLDB::CursorSP contains the same start_pc and cfa. Modified: lldb/trunk/source/Plugins/Process/Utility/RegisterContextLLDB.cpp lldb/trunk/source/Plugins/Process/Utility/RegisterContextLLDB.h lldb/trunk/source/Plugins/Process/Utility/UnwindLLDB.cpp Modified: lldb/trunk/source/Plugins/Process/Utility/RegisterContextLLDB.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Process/Utility/RegisterContextLLDB.cpp?rev=123673&r1=123672&r2=123673&view=diff ============================================================================== --- lldb/trunk/source/Plugins/Process/Utility/RegisterContextLLDB.cpp (original) +++ lldb/trunk/source/Plugins/Process/Utility/RegisterContextLLDB.cpp Mon Jan 17 15:03:33 2011 @@ -1246,7 +1246,7 @@ return false; if (!m_start_pc.IsValid()) { - return GetPC (start_pc); + return ReadPC (start_pc); } start_pc = m_start_pc.GetLoadAddress (&m_thread.GetProcess().GetTarget()); return true; @@ -1255,7 +1255,7 @@ // Retrieve the current pc value for THIS frame, as saved by the NEXT frame. bool -RegisterContextLLDB::GetPC (addr_t& pc) +RegisterContextLLDB::ReadPC (addr_t& pc) { if (!IsValid()) return false; Modified: lldb/trunk/source/Plugins/Process/Utility/RegisterContextLLDB.h URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Process/Utility/RegisterContextLLDB.h?rev=123673&r1=123672&r2=123673&view=diff ============================================================================== --- lldb/trunk/source/Plugins/Process/Utility/RegisterContextLLDB.h (original) +++ lldb/trunk/source/Plugins/Process/Utility/RegisterContextLLDB.h Mon Jan 17 15:03:33 2011 @@ -72,7 +72,7 @@ GetStartPC (lldb::addr_t& start_pc); bool - GetPC (lldb::addr_t& start_pc); + ReadPC (lldb::addr_t& start_pc); private: Modified: lldb/trunk/source/Plugins/Process/Utility/UnwindLLDB.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Process/Utility/UnwindLLDB.cpp?rev=123673&r1=123672&r2=123673&view=diff ============================================================================== --- lldb/trunk/source/Plugins/Process/Utility/UnwindLLDB.cpp (original) +++ lldb/trunk/source/Plugins/Process/Utility/UnwindLLDB.cpp Mon Jan 17 15:03:33 2011 @@ -76,7 +76,7 @@ if (!first_register_ctx_ap->GetCFA (first_cursor_sp->cfa)) return false; - if (!first_register_ctx_ap->GetPC (first_cursor_sp->start_pc)) + if (!first_register_ctx_ap->ReadPC (first_cursor_sp->start_pc)) return false; // Everything checks out, so release the auto pointer value and let the @@ -132,7 +132,7 @@ } return false; } - if (!register_ctx_ap->GetPC (cursor_sp->start_pc)) + if (!register_ctx_ap->ReadPC (cursor_sp->start_pc)) { if (log) { @@ -141,6 +141,15 @@ } return false; } + if (!m_frames.empty()) + { + if ((m_frames.back()->start_pc == cursor_sp->start_pc) && + (m_frames.back()->cfa == cursor_sp->cfa)) + { + // Infinite loop where the current cursor is the same as the previous one... + return false; + } + } RegisterContextSP register_ctx_sp(register_ctx_ap.release()); cursor_sp->reg_ctx = register_ctx_sp; m_frames.push_back (cursor_sp); From ctice at apple.com Mon Jan 17 15:55:19 2011 From: ctice at apple.com (Caroline Tice) Date: Mon, 17 Jan 2011 21:55:19 -0000 Subject: [Lldb-commits] [lldb] r123674 - in /lldb/trunk/source: Core/Debugger.cpp Interpreter/ScriptInterpreterPython.cpp Message-ID: <20110117215520.0AACA2A6C12C@llvm.org> Author: ctice Date: Mon Jan 17 15:55:19 2011 New Revision: 123674 URL: http://llvm.org/viewvc/llvm-project?rev=123674&view=rev Log: Replace Mutex guarding python interpreter access with Predicate, allowing timeouts & informing the user when the lock is unavailable. Fixed problem where Debugger::Terminate was clearing the debugger list even when the global ref count was greater than zero. Modified: lldb/trunk/source/Core/Debugger.cpp lldb/trunk/source/Interpreter/ScriptInterpreterPython.cpp Modified: lldb/trunk/source/Core/Debugger.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Core/Debugger.cpp?rev=123674&r1=123673&r2=123674&view=diff ============================================================================== --- lldb/trunk/source/Core/Debugger.cpp (original) +++ lldb/trunk/source/Core/Debugger.cpp Mon Jan 17 15:55:19 2011 @@ -94,11 +94,12 @@ UserSettingsControllerSP &usc = GetSettingsController(); UserSettingsController::FinalizeSettingsController (usc); usc.reset(); + + // Clear our master list of debugger objects + Mutex::Locker locker (GetDebuggerListMutex ()); + GetDebuggerList().clear(); } } - // Clear our master list of debugger objects - Mutex::Locker locker (GetDebuggerListMutex ()); - GetDebuggerList().clear(); } DebuggerSP Modified: lldb/trunk/source/Interpreter/ScriptInterpreterPython.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Interpreter/ScriptInterpreterPython.cpp?rev=123674&r1=123673&r2=123674&view=diff ============================================================================== --- lldb/trunk/source/Interpreter/ScriptInterpreterPython.cpp (original) +++ lldb/trunk/source/Interpreter/ScriptInterpreterPython.cpp Mon Jan 17 15:55:19 2011 @@ -171,11 +171,43 @@ return fflush (stream) || prev_fail ? EOF : 0; } -static Mutex & -GetPythonMutex () +static Predicate & +PythonMutexPredicate () { - static Mutex g_python_mutex (Mutex::eMutexTypeRecursive); - return g_python_mutex; + static lldb_private::Predicate g_interpreter_is_running (LLDB_INVALID_THREAD_ID); + return g_interpreter_is_running; +} + +static bool +CurrentThreadHasPythonLock () +{ + TimeValue timeout; + + timeout = TimeValue::Now(); // Don't wait any time. + + return PythonMutexPredicate().WaitForValueEqualTo (Host::GetCurrentThreadID(), &timeout, NULL); +} + +static bool +GetPythonLock (uint32_t seconds_to_wait) +{ + + TimeValue timeout; + + if (seconds_to_wait != UINT32_MAX) + { + timeout = TimeValue::Now(); + timeout.OffsetWithSeconds (seconds_to_wait); + } + + return PythonMutexPredicate().WaitForValueEqualToAndSetValueTo (LLDB_INVALID_THREAD_ID, + Host::GetCurrentThreadID(), &timeout, NULL); +} + +static void +ReleasePythonLock () +{ + PythonMutexPredicate().SetValue (LLDB_INVALID_THREAD_ID, eBroadcastAlways); } ScriptInterpreterPython::ScriptInterpreterPython (CommandInterpreter &interpreter) : @@ -191,8 +223,33 @@ m_pty_slave_is_open (false), m_valid_session (true) { - Mutex::Locker locker (GetPythonMutex()); + bool safe_to_run = false; + bool need_to_release_lock = true; + int interval = 5; // Number of seconds to try getting the Python lock before timing out. + + // We don't dare exit this function without finishing setting up the script interpreter, so we must wait until + // we can get the Python lock. + + if (CurrentThreadHasPythonLock()) + { + safe_to_run = true; + need_to_release_lock = false; + } + + while (!safe_to_run) + { + safe_to_run = GetPythonLock (interval); + if (!safe_to_run) + { + FILE *tmp_fh = (m_dbg_stdout ? m_dbg_stdout : stdout); + fprintf (tmp_fh, + "Python interpreter is locked on another thread; " + "please release interpreter in order to continue.\n"); + interval = interval * 2; + } + } + m_dictionary_name.append("_dict"); StreamString run_string; run_string.Printf ("%s = dict()", m_dictionary_name.c_str()); @@ -234,6 +291,9 @@ { m_new_sysout = PyFile_FromFile (m_dbg_stdout, (char *) "", (char *) "w", _check_and_flush); } + + if (need_to_release_lock) + ReleasePythonLock(); } ScriptInterpreterPython::~ScriptInterpreterPython () @@ -252,8 +312,16 @@ if (m_new_sysout) { - Mutex::Locker locker(GetPythonMutex()); - Py_DECREF (m_new_sysout); + FILE *tmp_fh = (m_dbg_stdout ? m_dbg_stdout : stdout); + if (!CurrentThreadHasPythonLock ()) + { + while (!GetPythonLock (1)) + fprintf (tmp_fh, "Python interpreter locked on another thread; waiting to acquire lock...\n"); + Py_DECREF (m_new_sysout); + ReleasePythonLock (); + } + else + Py_DECREF (m_new_sysout); } } @@ -264,11 +332,23 @@ return; m_dbg_stdout = fh; - Mutex::Locker locker (GetPythonMutex()); - EnterSession (); - m_new_sysout = PyFile_FromFile (m_dbg_stdout, (char *) "", (char *) "w", _check_and_flush); - LeaveSession (); + FILE *tmp_fh = (m_dbg_stdout ? m_dbg_stdout : stdout); + if (!CurrentThreadHasPythonLock ()) + { + while (!GetPythonLock (1)) + fprintf (tmp_fh, "Python interpreter locked on another thread; waiting to acquire lock...\n"); + EnterSession (); + m_new_sysout = PyFile_FromFile (m_dbg_stdout, (char *) "", (char *) "w", _check_and_flush); + LeaveSession (); + ReleasePythonLock (); + } + else + { + EnterSession (); + m_new_sysout = PyFile_FromFile (m_dbg_stdout, (char *) "", (char *) "w", _check_and_flush); + LeaveSession (); + } } void @@ -288,7 +368,12 @@ m_session_is_active = true; - Mutex::Locker locker (GetPythonMutex()); + StreamString run_string; + + run_string.Printf ("run_one_line (%s, 'lldb.debugger_unique_id = %d')", m_dictionary_name.c_str(), + GetCommandInterpreter().GetDebugger().GetID()); + PyRun_SimpleString (run_string.GetData()); + PyObject *sysmod = PyImport_AddModule ("sys"); PyObject *sysdict = PyModule_GetDict (sysmod); @@ -301,9 +386,9 @@ if (PyErr_Occurred()) PyErr_Clear (); - StreamString run_string; if (!m_pty_slave_is_open) { + run_string.Clear(); run_string.Printf ("run_one_line (%s, \"new_stdin = open('%s', 'r')\")", m_dictionary_name.c_str(), m_pty_slave_name.c_str()); PyRun_SimpleString (run_string.GetData()); @@ -322,9 +407,7 @@ if (!m_valid_session) return false; - EnterSession (); - Mutex::Locker locker (GetPythonMutex()); // We want to call run_one_line, passing in the dictionary and the command string. We cannot do this through // PyRun_SimpleString here because the command string may contain escaped characters, and putting it inside @@ -332,6 +415,18 @@ // method to pass the command string directly down to Python. + bool need_to_release_lock = true; + + if (CurrentThreadHasPythonLock()) + need_to_release_lock = false; + else if (!GetPythonLock (1)) + { + fprintf ((m_dbg_stdout ? m_dbg_stdout : stdout), + "Python interpreter is currently locked by another thread; unable to process command.\n"); + return false; + } + + EnterSession (); bool success = false; if (command) @@ -417,6 +512,9 @@ LeaveSession (); + if (need_to_release_lock) + ReleasePythonLock(); + if (success) return true; @@ -427,6 +525,10 @@ } LeaveSession (); + + if (need_to_release_lock) + ReleasePythonLock (); + if (result) result->AppendError ("empty command passed to python\n"); return false; @@ -478,6 +580,18 @@ script_interpreter->m_termios_valid = ::tcgetattr (input_fd, &script_interpreter->m_termios) == 0; + if (!CurrentThreadHasPythonLock()) + { + while (!GetPythonLock(1)) + { + ::fprintf (out_fh, "Python interpreter locked on another thread; waiting to acquire lock...\n"); + } + script_interpreter->EnterSession (); + ReleasePythonLock(); + } + else + script_interpreter->EnterSession (); + char error_str[1024]; if (script_interpreter->m_embedded_python_pty.OpenFirstAvailableMaster (O_RDWR|O_NOCTTY, error_str, sizeof(error_str))) @@ -508,8 +622,6 @@ log->Printf ("ScriptInterpreterPython::InputReaderCallback, Activate, failed to open master pty "); reader.SetIsDone (true); } - script_interpreter->EnterSession (); - } break; @@ -518,7 +630,17 @@ break; case eInputReaderReactivate: - script_interpreter->EnterSession (); + if (!CurrentThreadHasPythonLock()) + { + while (!GetPythonLock(1)) + { + // Wait until lock is acquired. + } + script_interpreter->EnterSession (); + ReleasePythonLock(); + } + else + script_interpreter->EnterSession (); break; case eInputReaderInterrupt: @@ -618,9 +740,19 @@ ScriptInterpreter::ReturnType return_type, void *ret_value) { - EnterSession (); - Mutex::Locker locker (GetPythonMutex()); + bool need_to_release_lock = true; + + if (CurrentThreadHasPythonLock()) + need_to_release_lock = false; + else if (!GetPythonLock (1)) + { + fprintf ((m_dbg_stdout ? m_dbg_stdout : stdout), + "Python interpreter is currently locked by another thread; unable to process command.\n"); + return false; + } + + EnterSession (); PyObject *py_return = NULL; PyObject *mainmod = PyImport_AddModule ("__main__"); @@ -786,15 +918,27 @@ LeaveSession (); + if (need_to_release_lock) + ReleasePythonLock(); + return ret_success; } bool ScriptInterpreterPython::ExecuteMultipleLines (const char *in_string) { - EnterSession (); + FILE *tmp_fh = (m_dbg_stdout ? m_dbg_stdout : stdout); + bool need_to_release_lock = true; + + if (CurrentThreadHasPythonLock()) + need_to_release_lock = false; + else + { + while (!GetPythonLock (1)) + fprintf (tmp_fh, "Python interpreter locked on another thread; waiting to acquire lock...\n"); + } - Mutex::Locker locker (GetPythonMutex()); + EnterSession (); bool success = false; PyObject *py_return = NULL; @@ -867,6 +1011,9 @@ LeaveSession (); + if (need_to_release_lock) + ReleasePythonLock(); + return success; } @@ -1156,12 +1303,28 @@ if (sb_bp_loc.IsValid() || sb_frame.IsValid()) { - python_interpreter->EnterSession (); - Mutex::Locker locker (GetPythonMutex()); - bool ret_val = LLDBSWIGPythonBreakpointCallbackFunction(python_function_name, - python_interpreter->m_dictionary_name.c_str(), - sb_frame, sb_bp_loc); - python_interpreter->LeaveSession (); + bool ret_val = true; + FILE *tmp_fh = (python_interpreter->m_dbg_stdout ? python_interpreter->m_dbg_stdout : stdout); + if (CurrentThreadHasPythonLock()) + { + python_interpreter->EnterSession (); + ret_val = LLDBSWIGPythonBreakpointCallbackFunction(python_function_name, + python_interpreter->m_dictionary_name.c_str(), + sb_frame, sb_bp_loc); + python_interpreter->LeaveSession (); + } + else + { + while (!GetPythonLock (1)) + fprintf (tmp_fh, + "Python interpreter locked on another thread; waiting to acquire lock...\n"); + python_interpreter->EnterSession (); + ret_val = LLDBSWIGPythonBreakpointCallbackFunction(python_function_name, + python_interpreter->m_dictionary_name.c_str(), + sb_frame, sb_bp_loc); + python_interpreter->LeaveSession (); + ReleasePythonLock (); + } return ret_val; } } @@ -1175,8 +1338,6 @@ { ScriptInterpreterPython *script_interpreter = (ScriptInterpreterPython *) baton; - script_interpreter->EnterSession (); - LogSP log (lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_SCRIPT)); if (log) @@ -1184,12 +1345,31 @@ char error_str[1024]; const char *pty_slave_name = script_interpreter->m_embedded_python_pty.GetSlaveName (error_str, sizeof (error_str)); - if (pty_slave_name != NULL) - { - Mutex::Locker locker (GetPythonMutex()); + bool need_to_release_lock = true; + bool safe_to_run = false; + if (CurrentThreadHasPythonLock()) + { + safe_to_run = true; + need_to_release_lock = false; + } + else + { + int interval = 1; + safe_to_run = GetPythonLock (interval); + while (!safe_to_run) + { + interval = interval * 2; + safe_to_run = GetPythonLock (interval); + } + } + + if (pty_slave_name != NULL && safe_to_run) + { StreamString run_string; + script_interpreter->EnterSession (); + run_string.Printf ("run_one_line (%s, 'save_stderr = sys.stderr')", script_interpreter->m_dictionary_name.c_str()); PyRun_SimpleString (run_string.GetData()); run_string.Clear (); @@ -1221,8 +1401,18 @@ run_string.Printf ("run_one_line (%s, 'sys.stderr = save_stderr')", script_interpreter->m_dictionary_name.c_str()); PyRun_SimpleString (run_string.GetData()); run_string.Clear(); + + script_interpreter->LeaveSession (); + } + if (!safe_to_run) + fprintf ((script_interpreter->m_dbg_stdout ? script_interpreter->m_dbg_stdout : stdout), + "Python interpreter locked on another thread; unable to acquire lock.\n"); + + if (need_to_release_lock) + ReleasePythonLock (); + if (script_interpreter->m_embedded_thread_input_reader_sp) script_interpreter->m_embedded_thread_input_reader_sp->SetIsDone (true); @@ -1241,8 +1431,6 @@ script_interpreter->m_embedded_thread_input_reader_sp.reset(); debugger.PopInputReader (reader_sp); - script_interpreter->LeaveSession (); - return NULL; } From johnny.chen at apple.com Mon Jan 17 16:35:39 2011 From: johnny.chen at apple.com (Johnny Chen) Date: Mon, 17 Jan 2011 22:35:39 -0000 Subject: [Lldb-commits] [lldb] r123683 - /lldb/trunk/test/abbreviation_tests/TestAbbreviations.py Message-ID: <20110117223539.336872A6C12C@llvm.org> Author: johnny Date: Mon Jan 17 16:35:39 2011 New Revision: 123683 URL: http://llvm.org/viewvc/llvm-project?rev=123683&view=rev Log: Terminate the current process being debugged. The test framework was relying on detecting either "run" or "process launch" command to automatically kill the inferior. Modified: lldb/trunk/test/abbreviation_tests/TestAbbreviations.py Modified: lldb/trunk/test/abbreviation_tests/TestAbbreviations.py URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/abbreviation_tests/TestAbbreviations.py?rev=123683&r1=123682&r2=123683&view=diff ============================================================================== --- lldb/trunk/test/abbreviation_tests/TestAbbreviations.py (original) +++ lldb/trunk/test/abbreviation_tests/TestAbbreviations.py Mon Jan 17 16:35:39 2011 @@ -146,7 +146,10 @@ '/usr/lib/libSystem.B.dylib', '/usr/lib/system/libmathCommon.A.dylib']) - + # Terminate the current process being debugged. + # The test framework was relying on detecting either "run" or + # "process launch" command to automatically kill the inferior. + self.runCmd("process kill") if __name__ == '__main__': From jingham at apple.com Mon Jan 17 17:06:54 2011 From: jingham at apple.com (Jim Ingham) Date: Mon, 17 Jan 2011 23:06:54 -0000 Subject: [Lldb-commits] [lldb] r123693 - in /lldb/trunk: include/lldb/ include/lldb/Target/ source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/ Message-ID: <20110117230654.A29622A6C12C@llvm.org> Author: jingham Date: Mon Jan 17 17:06:54 2011 New Revision: 123693 URL: http://llvm.org/viewvc/llvm-project?rev=123693&view=rev Log: Add a method on the ObjC Language Runtime that returns the runtime version. Modified: lldb/trunk/include/lldb/Target/ObjCLanguageRuntime.h lldb/trunk/include/lldb/lldb-enumerations.h lldb/trunk/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntime.cpp lldb/trunk/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntime.h lldb/trunk/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV1.cpp lldb/trunk/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV1.h lldb/trunk/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.cpp lldb/trunk/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.h Modified: lldb/trunk/include/lldb/Target/ObjCLanguageRuntime.h URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Target/ObjCLanguageRuntime.h?rev=123693&r1=123692&r2=123693&view=diff ============================================================================== --- lldb/trunk/include/lldb/Target/ObjCLanguageRuntime.h (original) +++ lldb/trunk/include/lldb/Target/ObjCLanguageRuntime.h Mon Jan 17 17:06:54 2011 @@ -58,6 +58,12 @@ virtual ClangUtilityFunction * CreateObjectChecker (const char *) = 0; + virtual lldb::ObjCRuntimeVersions + GetRuntimeVersion () + { + return lldb::eObjC_VersionUnknown; + } + protected: //------------------------------------------------------------------ // Classes that inherit from ObjCLanguageRuntime can see and modify these Modified: lldb/trunk/include/lldb/lldb-enumerations.h URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/lldb-enumerations.h?rev=123693&r1=123692&r2=123693&view=diff ============================================================================== --- lldb/trunk/include/lldb/lldb-enumerations.h (original) +++ lldb/trunk/include/lldb/lldb-enumerations.h Mon Jan 17 17:06:54 2011 @@ -633,6 +633,12 @@ eExecutionTimedOut } ExecutionResults; +typedef enum ObjCRuntimeVersions { + eObjC_VersionUnknown = 0, + eAppleObjC_V1 = 1, + eAppleObjC_V2 = 2 +} ObjCRuntimeVersions; + } // namespace lldb Modified: lldb/trunk/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntime.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntime.cpp?rev=123693&r1=123692&r2=123693&view=diff ============================================================================== --- lldb/trunk/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntime.cpp (original) +++ lldb/trunk/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntime.cpp Mon Jan 17 17:06:54 2011 @@ -240,7 +240,7 @@ //------------------------------------------------------------------ // Static Functions //------------------------------------------------------------------ -enum AppleObjCRuntime::RuntimeVersions +enum lldb::ObjCRuntimeVersions AppleObjCRuntime::GetObjCVersion (Process *process, ModuleSP &objc_module_sp) { ModuleList &images = process->GetTarget().GetImages(); @@ -253,21 +253,21 @@ objc_module_sp = module_sp; ObjectFile *ofile = module_sp->GetObjectFile(); if (!ofile) - return eObjC_VersionUnknown; + return lldb::eObjC_VersionUnknown; SectionList *sections = ofile->GetSectionList(); if (!sections) - return eObjC_VersionUnknown; + return lldb::eObjC_VersionUnknown; SectionSP v1_telltale_section_sp = sections->FindSectionByName(ConstString ("__OBJC")); if (v1_telltale_section_sp) { - return eObjC_V1; + return lldb::eAppleObjC_V1; } - return eObjC_V2; + return lldb::eAppleObjC_V2; } } - return eObjC_VersionUnknown; + return lldb::eObjC_VersionUnknown; } //------------------------------------------------------------------ Modified: lldb/trunk/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntime.h URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntime.h?rev=123693&r1=123692&r2=123693&view=diff ============================================================================== --- lldb/trunk/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntime.h (original) +++ lldb/trunk/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntime.h Mon Jan 17 17:06:54 2011 @@ -27,12 +27,6 @@ public lldb_private::ObjCLanguageRuntime { public: - - enum RuntimeVersions { - eObjC_VersionUnknown = 0, - eObjC_V1 = 1, - eObjC_V2 = 2 - }; ~AppleObjCRuntime() { } @@ -73,7 +67,7 @@ static bool AppleIsModuleObjCLibrary (const lldb::ModuleSP &module_sp); - static enum AppleObjCRuntime::RuntimeVersions + static enum lldb::ObjCRuntimeVersions GetObjCVersion (Process *process, ModuleSP &objc_module_sp); //------------------------------------------------------------------ Modified: lldb/trunk/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV1.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV1.cpp?rev=123693&r1=123692&r2=123693&view=diff ============================================================================== --- lldb/trunk/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV1.cpp (original) +++ lldb/trunk/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV1.cpp Mon Jan 17 17:06:54 2011 @@ -59,7 +59,7 @@ { ModuleSP objc_module_sp; - if (AppleObjCRuntime::GetObjCVersion (process, objc_module_sp) == AppleObjCRuntime::eObjC_V1) + if (AppleObjCRuntime::GetObjCVersion (process, objc_module_sp) == lldb::eAppleObjC_V1) return new AppleObjCRuntimeV1 (process); else return NULL; Modified: lldb/trunk/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV1.h URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV1.h?rev=123693&r1=123692&r2=123693&view=diff ============================================================================== --- lldb/trunk/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV1.h (original) +++ lldb/trunk/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV1.h Mon Jan 17 17:06:54 2011 @@ -64,6 +64,11 @@ virtual void SetExceptionBreakpoints (); + virtual lldb::ObjCRuntimeVersions + GetRuntimeVersion () + { + return lldb::eAppleObjC_V1; + } protected: private: Modified: lldb/trunk/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.cpp?rev=123693&r1=123692&r2=123693&view=diff ============================================================================== --- lldb/trunk/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.cpp (original) +++ lldb/trunk/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.cpp Mon Jan 17 17:06:54 2011 @@ -65,7 +65,7 @@ { ModuleSP objc_module_sp; - if (AppleObjCRuntime::GetObjCVersion (process, objc_module_sp) == AppleObjCRuntime::eObjC_V2) + if (AppleObjCRuntime::GetObjCVersion (process, objc_module_sp) == lldb::eAppleObjC_V2) return new AppleObjCRuntimeV2 (process, objc_module_sp); else return NULL; Modified: lldb/trunk/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.h URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.h?rev=123693&r1=123692&r2=123693&view=diff ============================================================================== --- lldb/trunk/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.h (original) +++ lldb/trunk/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.h Mon Jan 17 17:06:54 2011 @@ -64,6 +64,12 @@ virtual void SetExceptionBreakpoints (); + + virtual lldb::ObjCRuntimeVersions + GetRuntimeVersion () + { + return lldb::eAppleObjC_V2; + } protected: From scallanan at apple.com Mon Jan 17 17:42:46 2011 From: scallanan at apple.com (Sean Callanan) Date: Mon, 17 Jan 2011 23:42:46 -0000 Subject: [Lldb-commits] [lldb] r123694 - in /lldb/trunk: include/lldb/Expression/ClangExpressionDeclMap.h include/lldb/Expression/ClangExpressionParser.h include/lldb/Expression/IRForTarget.h source/Expression/ClangExpressionDeclMap.cpp source/Expression/ClangExpressionParser.cpp source/Expression/ClangFunction.cpp source/Expression/ClangUserExpression.cpp source/Expression/ClangUtilityFunction.cpp source/Expression/IRForTarget.cpp Message-ID: <20110117234246.C94482A6C12C@llvm.org> Author: spyffe Date: Mon Jan 17 17:42:46 2011 New Revision: 123694 URL: http://llvm.org/viewvc/llvm-project?rev=123694&view=rev Log: Added support for the fragile ivars provided by Apple's Objective-C 2.0 runtime. They are enabled if the Objective-C runtime has the proper version. Modified: lldb/trunk/include/lldb/Expression/ClangExpressionDeclMap.h lldb/trunk/include/lldb/Expression/ClangExpressionParser.h lldb/trunk/include/lldb/Expression/IRForTarget.h lldb/trunk/source/Expression/ClangExpressionDeclMap.cpp lldb/trunk/source/Expression/ClangExpressionParser.cpp lldb/trunk/source/Expression/ClangFunction.cpp lldb/trunk/source/Expression/ClangUserExpression.cpp lldb/trunk/source/Expression/ClangUtilityFunction.cpp lldb/trunk/source/Expression/IRForTarget.cpp Modified: lldb/trunk/include/lldb/Expression/ClangExpressionDeclMap.h URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Expression/ClangExpressionDeclMap.h?rev=123694&r1=123693&r2=123694&view=diff ============================================================================== --- lldb/trunk/include/lldb/Expression/ClangExpressionDeclMap.h (original) +++ lldb/trunk/include/lldb/Expression/ClangExpressionDeclMap.h Mon Jan 17 17:42:46 2011 @@ -290,6 +290,23 @@ uint64_t &ptr); //------------------------------------------------------------------ + /// [Used by IRForTarget] Get the address of a symbol given nothing + /// but its name. + /// + /// @param[in] name + /// The name of the symbol. + /// + /// @param[out] ptr + /// The absolute address of the function in the target. + /// + /// @return + /// True if the address could be retrieved; false otherwise. + //------------------------------------------------------------------ + bool + GetSymbolAddress (const ConstString &name, + uint64_t &ptr); + + //------------------------------------------------------------------ /// [Used by CommandObjectExpression] Materialize the entire struct /// at a given address, which should be aligned as specified by /// GetStructInfo(). Modified: lldb/trunk/include/lldb/Expression/ClangExpressionParser.h URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Expression/ClangExpressionParser.h?rev=123694&r1=123693&r2=123694&view=diff ============================================================================== --- lldb/trunk/include/lldb/Expression/ClangExpressionParser.h (original) +++ lldb/trunk/include/lldb/Expression/ClangExpressionParser.h Mon Jan 17 17:42:46 2011 @@ -25,6 +25,7 @@ namespace lldb_private { +class Process; class RecordingMemoryManager; //---------------------------------------------------------------------- @@ -49,10 +50,15 @@ /// The LLVM-friendly target triple for use in initializing the /// compiler. /// + /// @param[in process + /// If non-NULL, the process to customize the expression for + /// (e.g., by tuning Objective-C runtime support). May be NULL. + /// /// @param[in] expr /// The expression to be parsed. //------------------------------------------------------------------ ClangExpressionParser (const char *target_triple, + Process *process, ClangExpression &expr); //------------------------------------------------------------------ Modified: lldb/trunk/include/lldb/Expression/IRForTarget.h URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Expression/IRForTarget.h?rev=123694&r1=123693&r2=123694&view=diff ============================================================================== --- lldb/trunk/include/lldb/Expression/IRForTarget.h (original) +++ lldb/trunk/include/lldb/Expression/IRForTarget.h Mon Jan 17 17:42:46 2011 @@ -322,12 +322,9 @@ /// @param[in] llvm_module /// The module currently being processed. /// - /// @param[in] V + /// @param[in] value /// The variable. /// - /// @param[in] Store - /// True if the access is a store. - /// /// @return /// True on success; false otherwise //------------------------------------------------------------------ @@ -336,6 +333,22 @@ llvm::Value *value); //------------------------------------------------------------------ + /// Handle a single externally-defined symbol + /// + /// @param[in] llvm_module + /// The module currently being processed. + /// + /// @param[in] symbol + /// The symbol. + /// + /// @return + /// True on success; false otherwise + //------------------------------------------------------------------ + bool + HandleSymbol (llvm::Module &llvm_module, + llvm::Value *symbol); + + //------------------------------------------------------------------ /// Handle all the arguments to a function call /// /// @param[in] llvm_module Modified: lldb/trunk/source/Expression/ClangExpressionDeclMap.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Expression/ClangExpressionDeclMap.cpp?rev=123694&r1=123693&r2=123694&view=diff ============================================================================== --- lldb/trunk/source/Expression/ClangExpressionDeclMap.cpp (original) +++ lldb/trunk/source/Expression/ClangExpressionDeclMap.cpp Mon Jan 17 17:42:46 2011 @@ -452,6 +452,36 @@ return true; } +bool +ClangExpressionDeclMap::GetSymbolAddress +( + const ConstString &name, + uint64_t &ptr +) +{ + assert (m_parser_vars.get()); + + // Back out in all cases where we're not fully initialized + if (m_parser_vars->m_exe_ctx->target == NULL) + return false; + + SymbolContextList sc_list; + + m_parser_vars->m_exe_ctx->target->GetImages().FindSymbolsWithNameAndType(name, lldb::eSymbolTypeAny, sc_list); + + if (!sc_list.GetSize()) + return false; + + SymbolContext sym_ctx; + sc_list.GetContextAtIndex(0, sym_ctx); + + const Address *sym_address = &sym_ctx.symbol->GetAddressRangeRef().GetBaseAddress(); + + ptr = sym_address->GetLoadAddress (m_parser_vars->m_exe_ctx->target); + + return true; +} + // Interface for CommandObjectExpression bool Modified: lldb/trunk/source/Expression/ClangExpressionParser.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Expression/ClangExpressionParser.cpp?rev=123694&r1=123693&r2=123694&view=diff ============================================================================== --- lldb/trunk/source/Expression/ClangExpressionParser.cpp (original) +++ lldb/trunk/source/Expression/ClangExpressionParser.cpp Mon Jan 17 17:42:46 2011 @@ -21,6 +21,7 @@ #include "lldb/Expression/IRToDWARF.h" #include "lldb/Expression/RecordingMemoryManager.h" #include "lldb/Target/ExecutionContext.h" +#include "lldb/Target/ObjCLanguageRuntime.h" #include "lldb/Target/Process.h" #include "lldb/Target/Target.h" @@ -177,6 +178,7 @@ //===----------------------------------------------------------------------===// ClangExpressionParser::ClangExpressionParser(const char *target_triple, + Process *process, ClangExpression &expr) : m_expr(expr), m_target_triple (), @@ -211,10 +213,18 @@ // Setup objective C m_compiler->getLangOpts().ObjC1 = true; m_compiler->getLangOpts().ObjC2 = true; - // We need to enable the fragile ABI for things target triples that - // support it. -// m_compiler->getLangOpts().ObjCNonFragileABI = true; // NOT i386 -// m_compiler->getLangOpts().ObjCNonFragileABI2 = true; // NOT i386 + + if (process) + { + if (process->GetObjCLanguageRuntime()) + { + if (process->GetObjCLanguageRuntime()->GetRuntimeVersion() == lldb::eAppleObjC_V2) + { + m_compiler->getLangOpts().ObjCNonFragileABI = true; // NOT i386 + m_compiler->getLangOpts().ObjCNonFragileABI2 = true; // NOT i386 + } + } + } m_compiler->getLangOpts().ThreadsafeStatics = false; m_compiler->getLangOpts().AccessControl = false; // Debuggers get universal access Modified: lldb/trunk/source/Expression/ClangFunction.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Expression/ClangFunction.cpp?rev=123694&r1=123693&r2=123694&view=diff ============================================================================== --- lldb/trunk/source/Expression/ClangFunction.cpp (original) +++ lldb/trunk/source/Expression/ClangFunction.cpp Mon Jan 17 17:42:46 2011 @@ -214,7 +214,7 @@ // Okay, now compile this expression - m_parser.reset(new ClangExpressionParser(m_target_triple.c_str(), *this)); + m_parser.reset(new ClangExpressionParser(m_target_triple.c_str(), NULL, *this)); num_errors = m_parser->Parse (errors); Modified: lldb/trunk/source/Expression/ClangUserExpression.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Expression/ClangUserExpression.cpp?rev=123694&r1=123693&r2=123694&view=diff ============================================================================== --- lldb/trunk/source/Expression/ClangUserExpression.cpp (original) +++ lldb/trunk/source/Expression/ClangUserExpression.cpp Mon Jan 17 17:42:46 2011 @@ -253,7 +253,7 @@ m_expr_decl_map->WillParse(exe_ctx); - ClangExpressionParser parser(target_triple.GetCString(), *this); + ClangExpressionParser parser(target_triple.GetCString(), exe_ctx.process, *this); unsigned num_errors = parser.Parse (error_stream); Modified: lldb/trunk/source/Expression/ClangUtilityFunction.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Expression/ClangUtilityFunction.cpp?rev=123694&r1=123693&r2=123694&view=diff ============================================================================== --- lldb/trunk/source/Expression/ClangUtilityFunction.cpp (original) +++ lldb/trunk/source/Expression/ClangUtilityFunction.cpp Mon Jan 17 17:42:46 2011 @@ -105,7 +105,7 @@ m_expr_decl_map->WillParse(exe_ctx); - ClangExpressionParser parser(target_triple.GetCString(), *this); + ClangExpressionParser parser(target_triple.GetCString(), exe_ctx.process, *this); unsigned num_errors = parser.Parse (error_stream); Modified: lldb/trunk/source/Expression/IRForTarget.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Expression/IRForTarget.cpp?rev=123694&r1=123693&r2=123694&view=diff ============================================================================== --- lldb/trunk/source/Expression/IRForTarget.cpp (original) +++ lldb/trunk/source/Expression/IRForTarget.cpp Mon Jan 17 17:42:46 2011 @@ -1070,6 +1070,44 @@ } bool +IRForTarget::HandleSymbol (Module &llvm_module, + Value *symbol) +{ + lldb::LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_EXPRESSIONS)); + + lldb_private::ConstString name(symbol->getName().str().c_str()); + + uint64_t symbol_addr; + + if (!m_decl_map->GetSymbolAddress (name, symbol_addr)) + { + if (log) + log->Printf ("Symbol \"%s\" had no address", name.GetCString()); + + return false; + } + + if (log) + log->Printf("Found \"%s\" at 0x%llx", name.GetCString(), symbol_addr); + + const Type *symbol_type = symbol->getType(); + + const IntegerType *intptr_ty = Type::getIntNTy(llvm_module.getContext(), + (llvm_module.getPointerSize() == Module::Pointer64) ? 64 : 32); + + Constant *symbol_addr_int = ConstantInt::get(intptr_ty, symbol_addr, false); + + Value *symbol_addr_ptr = ConstantExpr::getIntToPtr(symbol_addr_int, symbol_type); + + if (log) + log->Printf("Replacing %s with %s", PrintValue(symbol).c_str(), PrintValue(symbol_addr_ptr).c_str()); + + symbol->replaceAllUsesWith(symbol_addr_ptr); + + return true; +} + +bool IRForTarget::MaybeHandleCallArguments (Module &llvm_module, CallInst *Old) { lldb::LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_EXPRESSIONS)); @@ -1250,9 +1288,16 @@ (*global).getName().str().c_str(), DeclForGlobalValue(llvm_module, global)); - if (DeclForGlobalValue(llvm_module, global) && - !MaybeHandleVariable (llvm_module, global)) - return false; + if ((*global).getName().str().find("OBJC_IVAR") == 0) + { + if (!HandleSymbol(llvm_module, global)) + return false; + } + else if (DeclForGlobalValue(llvm_module, global)) + { + if (!MaybeHandleVariable (llvm_module, global)) + return false; + } } return true; From scallanan at apple.com Mon Jan 17 19:03:44 2011 From: scallanan at apple.com (Sean Callanan) Date: Tue, 18 Jan 2011 01:03:44 -0000 Subject: [Lldb-commits] [lldb] r123710 - /lldb/trunk/source/Symbol/ClangASTContext.cpp Message-ID: <20110118010344.65AC92A6C12C@llvm.org> Author: spyffe Date: Mon Jan 17 19:03:44 2011 New Revision: 123710 URL: http://llvm.org/viewvc/llvm-project?rev=123710&view=rev Log: Quick fixes to set access specifiers for Typedefs and Enums inside classes. Modified: lldb/trunk/source/Symbol/ClangASTContext.cpp Modified: lldb/trunk/source/Symbol/ClangASTContext.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Symbol/ClangASTContext.cpp?rev=123710&r1=123709&r2=123710&view=diff ============================================================================== --- lldb/trunk/source/Symbol/ClangASTContext.cpp (original) +++ lldb/trunk/source/Symbol/ClangASTContext.cpp Mon Jan 17 19:03:44 2011 @@ -3734,10 +3734,15 @@ false, // IsScoped false, // IsScopedUsingClassTag false); // IsFixed + + if (enum_decl) { // TODO: check if we should be setting the promotion type too? enum_decl->setIntegerType(QualType::getFromOpaquePtr (integer_qual_type)); + + enum_decl->setAccess(AS_public); // TODO respect what's in the debug info + return ast->getTagDeclType(enum_decl).getAsOpaquePtr(); } return NULL; @@ -4216,6 +4221,8 @@ SourceLocation(), name ? &identifier_table->get(name) : NULL, // Identifier ast->CreateTypeSourceInfo(qual_type)); + + decl->setAccess(AS_public); // TODO respect proper access specifier // Get a uniqued QualType for the typedef decl type return ast->getTypedefType (decl).getAsOpaquePtr(); From jingham at apple.com Mon Jan 17 19:58:07 2011 From: jingham at apple.com (Jim Ingham) Date: Tue, 18 Jan 2011 01:58:07 -0000 Subject: [Lldb-commits] [lldb] r123716 - in /lldb/trunk: include/lldb/Target/ThreadPlanCallFunction.h source/Target/ThreadPlanCallFunction.cpp Message-ID: <20110118015807.1F9452A6C12C@llvm.org> Author: jingham Date: Mon Jan 17 19:58:06 2011 New Revision: 123716 URL: http://llvm.org/viewvc/llvm-project?rev=123716&view=rev Log: In ThreadPlanCallFunction, do the Takedown right when the thread plan gets popped. When the function call is discarded (e.g. when it crashes and discard_on_error is true) the plan gets discarded. You need to make sure that the stack gets restored right then, and not wait till you start again and the thread plan stack is cleared. Modified: lldb/trunk/include/lldb/Target/ThreadPlanCallFunction.h lldb/trunk/source/Target/ThreadPlanCallFunction.cpp Modified: lldb/trunk/include/lldb/Target/ThreadPlanCallFunction.h URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Target/ThreadPlanCallFunction.h?rev=123716&r1=123715&r2=123716&view=diff ============================================================================== --- lldb/trunk/include/lldb/Target/ThreadPlanCallFunction.h (original) +++ lldb/trunk/include/lldb/Target/ThreadPlanCallFunction.h Mon Jan 17 19:58:06 2011 @@ -69,6 +69,9 @@ { return true; } + + virtual void + WillPop (); protected: private: Modified: lldb/trunk/source/Target/ThreadPlanCallFunction.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Target/ThreadPlanCallFunction.cpp?rev=123716&r1=123715&r2=123716&view=diff ============================================================================== --- lldb/trunk/source/Target/ThreadPlanCallFunction.cpp (original) +++ lldb/trunk/source/Target/ThreadPlanCallFunction.cpp Mon Jan 17 19:58:06 2011 @@ -129,6 +129,13 @@ } void +ThreadPlanCallFunction::WillPop () +{ + if (m_valid && !IsPlanComplete()) + DoTakedown(); +} + +void ThreadPlanCallFunction::GetDescription (Stream *s, lldb::DescriptionLevel level) { if (level == lldb::eDescriptionLevelBrief) From gclayton at apple.com Tue Jan 18 13:36:39 2011 From: gclayton at apple.com (Greg Clayton) Date: Tue, 18 Jan 2011 19:36:39 -0000 Subject: [Lldb-commits] [lldb] r123762 - in /lldb/trunk: source/Expression/ source/Plugins/Process/gdb-remote/ source/Target/ source/Utility/ tools/debugserver/source/ tools/debugserver/source/MacOSX/ tools/debugserver/source/MacOSX/i386/ tools/debugserver/source/MacOSX/x86_64/ Message-ID: <20110118193639.8541F2A6C12C@llvm.org> Author: gclayton Date: Tue Jan 18 13:36:39 2011 New Revision: 123762 URL: http://llvm.org/viewvc/llvm-project?rev=123762&view=rev Log: Thread safety changes in debugserver and also in the process GDB remote plugin. I added support for asking if the GDB remote server supports thread suffixes for packets that should be thread specific (register read/write packets) because the way the GDB remote protocol does it right now is to have a notion of a current thread for register and memory reads/writes (set via the "$Hg%x" packet) and a current thread for running ("$Hc%x"). Now we ask the remote GDB server if it supports adding the thread ID to the register packets and we enable that feature in LLDB if supported. This stops us from having to send a bunch of packets that update the current thread ID to some value which is prone to error, or extra packets. Modified: lldb/trunk/source/Expression/ClangUserExpression.cpp lldb/trunk/source/Expression/ClangUtilityFunction.cpp lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.cpp lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.h lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteRegisterContext.cpp lldb/trunk/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp lldb/trunk/source/Target/ThreadList.cpp lldb/trunk/source/Utility/StringExtractor.h lldb/trunk/tools/debugserver/source/DNBThreadResumeActions.h lldb/trunk/tools/debugserver/source/MacOSX/MachProcess.cpp lldb/trunk/tools/debugserver/source/MacOSX/MachProcess.h lldb/trunk/tools/debugserver/source/MacOSX/MachThread.cpp lldb/trunk/tools/debugserver/source/MacOSX/MachThread.h lldb/trunk/tools/debugserver/source/MacOSX/i386/DNBArchImplI386.cpp lldb/trunk/tools/debugserver/source/MacOSX/x86_64/DNBArchImplX86_64.cpp lldb/trunk/tools/debugserver/source/RNBRemote.cpp lldb/trunk/tools/debugserver/source/RNBRemote.h Modified: lldb/trunk/source/Expression/ClangUserExpression.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Expression/ClangUserExpression.cpp?rev=123762&r1=123761&r2=123762&view=diff ============================================================================== --- lldb/trunk/source/Expression/ClangUserExpression.cpp (original) +++ lldb/trunk/source/Expression/ClangUserExpression.cpp Tue Jan 18 13:36:39 2011 @@ -20,6 +20,7 @@ #include "lldb/Core/ConstString.h" #include "lldb/Core/Log.h" +#include "lldb/Core/StreamFile.h" #include "lldb/Core/StreamString.h" #include "lldb/Core/ValueObjectConstResult.h" #include "lldb/Expression/ASTResultSynthesizer.h" @@ -365,6 +366,12 @@ error_stream.Printf("Couldn't materialize struct: %s\n", materialize_error.AsCString()); return false; } + +#if 0 + // jingham: look here + StreamFile logfile ("/tmp/exprs.txt", "a"); + logfile.Printf("0x%16.16llx: thread = 0x%4.4x, expr = '%s'\n", m_jit_addr, exe_ctx.thread ? exe_ctx.thread->GetID() : -1, m_expr_text.c_str()); +#endif if (log) { Modified: lldb/trunk/source/Expression/ClangUtilityFunction.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Expression/ClangUtilityFunction.cpp?rev=123762&r1=123761&r2=123762&view=diff ============================================================================== --- lldb/trunk/source/Expression/ClangUtilityFunction.cpp (original) +++ lldb/trunk/source/Expression/ClangUtilityFunction.cpp Tue Jan 18 13:36:39 2011 @@ -17,6 +17,7 @@ #include "lldb/Core/ConstString.h" #include "lldb/Core/Stream.h" +#include "lldb/Core/StreamFile.h" #include "lldb/Expression/ClangExpressionDeclMap.h" #include "lldb/Expression/ClangExpressionParser.h" #include "lldb/Expression/ClangUtilityFunction.h" @@ -124,6 +125,15 @@ Error jit_error = parser.MakeJIT (m_jit_begin, m_jit_end, exe_ctx); +#if 0 + // jingham: look here + StreamFile logfile ("/tmp/exprs.txt", "a"); + logfile.Printf ("0x%16.16llx: func = %s, source =\n%s\n", + m_jit_begin, + m_function_name.c_str(), + m_function_text.c_str()); +#endif + m_expr_decl_map->DidParse(); m_expr_decl_map.reset(); Modified: lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.cpp?rev=123762&r1=123761&r2=123762&view=diff ============================================================================== --- lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.cpp (original) +++ lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.cpp Tue Jan 18 13:36:39 2011 @@ -34,6 +34,7 @@ GDBRemoteCommunication::GDBRemoteCommunication() : Communication("gdb-remote.packets"), m_send_acks (true), + m_thread_suffix_supported (false), m_rx_packet_listener ("gdbremote.rx_packet"), m_sequence_mutex (Mutex::eMutexTypeRecursive), m_is_running (false), Modified: lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.h URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.h?rev=123762&r1=123761&r2=123762&view=diff ============================================================================== --- lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.h (original) +++ lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.h Tue Jan 18 13:36:39 2011 @@ -100,6 +100,18 @@ } bool + GetThreadSuffixSupported () const + { + return m_thread_suffix_supported; + } + + void + SetThreadSuffixSupported (bool enabled) + { + m_thread_suffix_supported = enabled; + } + + bool SendAsyncSignal (int signo); bool @@ -244,7 +256,8 @@ //------------------------------------------------------------------ // Classes that inherit from GDBRemoteCommunication can see and modify these //------------------------------------------------------------------ - bool m_send_acks; + bool m_send_acks:1, + m_thread_suffix_supported:1; lldb_private::Listener m_rx_packet_listener; lldb_private::Mutex m_sequence_mutex; // Restrict access to sending/receiving packets to a single thread at a time lldb_private::Predicate m_is_running; Modified: lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteRegisterContext.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteRegisterContext.cpp?rev=123762&r1=123761&r2=123762&view=diff ============================================================================== --- lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteRegisterContext.cpp (original) +++ lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteRegisterContext.cpp Tue Jan 18 13:36:39 2011 @@ -217,15 +217,19 @@ Mutex::Locker locker; if (gdb_comm.GetSequenceMutex (locker)) { - if (GetGDBProcess().SetCurrentGDBRemoteThread(m_thread.GetID())) + const bool thread_suffix_supported = gdb_comm.GetThreadSuffixSupported(); + if (thread_suffix_supported || GetGDBProcess().SetCurrentGDBRemoteThread(m_thread.GetID())) { - char packet[32]; + char packet[64]; StringExtractorGDBRemote response; - int packet_len; + int packet_len = 0; if (m_read_all_at_once) { // Get all registers in one packet - packet_len = ::snprintf (packet, sizeof(packet), "g"); + if (thread_suffix_supported) + packet_len = ::snprintf (packet, sizeof(packet), "g;thread:%4.4x;", m_thread.GetID()); + else + packet_len = ::snprintf (packet, sizeof(packet), "g"); assert (packet_len < (sizeof(packet) - 1)); if (gdb_comm.SendPacketAndWaitForResponse(packet, response, 1, false)) { @@ -237,7 +241,10 @@ else { // Get each register individually - packet_len = ::snprintf (packet, sizeof(packet), "p%x", reg); + if (thread_suffix_supported) + packet_len = ::snprintf (packet, sizeof(packet), "p%x;thread:%4.4x;", reg, m_thread.GetID()); + else + packet_len = ::snprintf (packet, sizeof(packet), "p%x", reg); assert (packet_len < (sizeof(packet) - 1)); if (gdb_comm.SendPacketAndWaitForResponse(packet, response, 1, false)) PrivateSetRegisterValue (reg, response); @@ -319,7 +326,8 @@ Mutex::Locker locker; if (gdb_comm.GetSequenceMutex (locker)) { - if (GetGDBProcess().SetCurrentGDBRemoteThread(m_thread.GetID())) + const bool thread_suffix_supported = gdb_comm.GetThreadSuffixSupported(); + if (thread_suffix_supported || GetGDBProcess().SetCurrentGDBRemoteThread(m_thread.GetID())) { uint32_t offset, end_offset; StreamString packet; @@ -336,6 +344,9 @@ eByteOrderHost, eByteOrderHost); + if (thread_suffix_supported) + packet.Printf (";thread:%4.4x;", m_thread.GetID()); + // Invalidate all register values InvalidateIfNeeded (true); @@ -361,6 +372,9 @@ eByteOrderHost, eByteOrderHost); + if (thread_suffix_supported) + packet.Printf (";thread:%4.4x;", m_thread.GetID()); + // Invalidate just this register m_reg_valid[reg] = false; if (gdb_comm.SendPacketAndWaitForResponse(packet.GetString().c_str(), @@ -391,16 +405,31 @@ Mutex::Locker locker; if (gdb_comm.GetSequenceMutex (locker)) { - if (GetGDBProcess().SetCurrentGDBRemoteThread(m_thread.GetID())) + char packet[32]; + const bool thread_suffix_supported = gdb_comm.GetThreadSuffixSupported(); + if (thread_suffix_supported || GetGDBProcess().SetCurrentGDBRemoteThread(m_thread.GetID())) { - if (gdb_comm.SendPacketAndWaitForResponse("g", response, 1, false)) + int packet_len = 0; + if (thread_suffix_supported) + packet_len = ::snprintf (packet, sizeof(packet), "g;thread:%4.4x", m_thread.GetID()); + else + packet_len = ::snprintf (packet, sizeof(packet), "g"); + assert (packet_len < (sizeof(packet) - 1)); + + if (gdb_comm.SendPacketAndWaitForResponse(packet, packet_len, response, 1, false)) { if (response.IsErrorPacket()) return false; - + response.GetStringRef().insert(0, 1, 'G'); - data_sp.reset (new DataBufferHeap(response.GetStringRef().c_str(), - response.GetStringRef().size())); + if (thread_suffix_supported) + { + char thread_id_cstr[64]; + ::snprintf (thread_id_cstr, sizeof(thread_id_cstr), ";thread:%4.4x;", m_thread.GetID()); + response.GetStringRef().append (thread_id_cstr); + } + data_sp.reset (new DataBufferHeap (response.GetStringRef().c_str(), + response.GetStringRef().size())); return true; } } @@ -419,7 +448,8 @@ Mutex::Locker locker; if (gdb_comm.GetSequenceMutex (locker)) { - if (GetGDBProcess().SetCurrentGDBRemoteThread(m_thread.GetID())) + const bool thread_suffix_supported = gdb_comm.GetThreadSuffixSupported(); + if (thread_suffix_supported || GetGDBProcess().SetCurrentGDBRemoteThread(m_thread.GetID())) { if (gdb_comm.SendPacketAndWaitForResponse((const char *)data_sp->GetBytes(), data_sp->GetByteSize(), Modified: lldb/trunk/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp?rev=123762&r1=123761&r2=123762&view=diff ============================================================================== --- lldb/trunk/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp (original) +++ lldb/trunk/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp Tue Jan 18 13:36:39 2011 @@ -554,6 +554,13 @@ if (response.IsOKPacket()) m_gdb_comm.SetAckMode (false); } + + if (m_gdb_comm.SendPacketAndWaitForResponse("QThreadSuffixSupported", response, 1, false)) + { + if (response.IsOKPacket()) + m_gdb_comm.SetThreadSuffixSupported (true); + } + } return error; } @@ -2021,7 +2028,7 @@ return true; char packet[32]; - const int packet_len = ::snprintf (packet, sizeof(packet), "Hg%x", tid); + const int packet_len = ::snprintf (packet, sizeof(packet), "Hc%x", tid); assert (packet_len + 1 < sizeof(packet)); StringExtractorGDBRemote response; if (m_gdb_comm.SendPacketAndWaitForResponse(packet, packet_len, response, 2, false)) Modified: lldb/trunk/source/Target/ThreadList.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Target/ThreadList.cpp?rev=123762&r1=123761&r2=123762&view=diff ============================================================================== --- lldb/trunk/source/Target/ThreadList.cpp (original) +++ lldb/trunk/source/Target/ThreadList.cpp Tue Jan 18 13:36:39 2011 @@ -340,6 +340,7 @@ void ThreadList::Clear() { + Mutex::Locker locker(m_threads_mutex); m_stop_id = 0; m_threads.clear(); m_selected_tid = LLDB_INVALID_THREAD_ID; @@ -504,6 +505,7 @@ void ThreadList::DidResume () { + Mutex::Locker locker(m_threads_mutex); collection::iterator pos, end = m_threads.end(); for (pos = m_threads.begin(); pos != end; ++pos) { Modified: lldb/trunk/source/Utility/StringExtractor.h URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Utility/StringExtractor.h?rev=123762&r1=123761&r2=123762&view=diff ============================================================================== --- lldb/trunk/source/Utility/StringExtractor.h (original) +++ lldb/trunk/source/Utility/StringExtractor.h Tue Jan 18 13:36:39 2011 @@ -113,6 +113,14 @@ size_t GetHexByteString (std::string &str); + const char * + Peek () + { + if (m_index < m_packet.size()) + return m_packet.c_str() + m_index; + return NULL; + } + protected: //------------------------------------------------------------------ // For StringExtractor only Modified: lldb/trunk/tools/debugserver/source/DNBThreadResumeActions.h URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/tools/debugserver/source/DNBThreadResumeActions.h?rev=123762&r1=123761&r2=123762&view=diff ============================================================================== --- lldb/trunk/tools/debugserver/source/DNBThreadResumeActions.h (original) +++ lldb/trunk/tools/debugserver/source/DNBThreadResumeActions.h Tue Jan 18 13:36:39 2011 @@ -85,6 +85,13 @@ { return m_actions.size(); } + + void + Clear() + { + m_actions.clear(); + m_signal_handled.clear(); + } protected: std::vector m_actions; Modified: lldb/trunk/tools/debugserver/source/MacOSX/MachProcess.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/tools/debugserver/source/MacOSX/MachProcess.cpp?rev=123762&r1=123761&r2=123762&view=diff ============================================================================== --- lldb/trunk/tools/debugserver/source/MacOSX/MachProcess.cpp (original) +++ lldb/trunk/tools/debugserver/source/MacOSX/MachProcess.cpp Tue Jan 18 13:36:39 2011 @@ -101,6 +101,7 @@ m_stdio_thread (0), m_stdio_mutex (PTHREAD_MUTEX_RECURSIVE), m_stdout_data (), + m_thread_actions (), m_thread_list (), m_exception_messages (), m_exception_messages_mutex (PTHREAD_MUTEX_RECURSIVE), @@ -314,7 +315,8 @@ if (CanResume(state)) { - PrivateResume(thread_actions); + m_thread_actions = thread_actions; + PrivateResume(); return true; } else if (state == eStateRunning) @@ -337,7 +339,8 @@ DNBError err; err.SetErrorToErrno(); DNBLogThreadedIf(LOG_PROCESS, "MachProcess::Kill() DoSIGSTOP() ::ptrace (PT_KILL, pid=%u, 0, 0) => 0x%8.8x (%s)", err.Error(), err.AsString()); - PrivateResume (DNBThreadResumeActions (eStateRunning, 0)); + m_thread_actions = DNBThreadResumeActions (eStateRunning, 0); + PrivateResume (); return true; } @@ -392,7 +395,8 @@ // No threads were stopped with a SIGSTOP, we need to run and halt the // process with a signal DNBLogThreadedIf(LOG_PROCESS, "MachProcess::DoSIGSTOP() state = %s -- resuming process", DNBStateAsString (state)); - PrivateResume (DNBThreadResumeActions (eStateRunning, 0)); + m_thread_actions = DNBThreadResumeActions (eStateRunning, 0); + PrivateResume (); // Reset the event that says we were indeed running m_events.ResetEvents(eEventProcessRunningStateChanged); @@ -428,20 +432,19 @@ DNBLogThreadedIf(LOG_PROCESS, "MachProcess::Detach() DoSIGSTOP() returned %s", DNBStateAsString(state)); { - DNBThreadResumeActions thread_actions; + m_thread_actions.Clear(); DNBThreadResumeAction thread_action; thread_action.tid = m_thread_list.ThreadIDAtIndex (thread_idx); thread_action.state = eStateRunning; thread_action.signal = -1; thread_action.addr = INVALID_NUB_ADDRESS; - thread_actions.Append (thread_action); - - thread_actions.SetDefaultThreadActionIfNeeded (eStateRunning, 0); + m_thread_actions.Append (thread_action); + m_thread_actions.SetDefaultThreadActionIfNeeded (eStateRunning, 0); PTHREAD_MUTEX_LOCKER (locker, m_exception_messages_mutex); - ReplyToAllExceptions (thread_actions); + ReplyToAllExceptions (); } @@ -597,7 +600,7 @@ void -MachProcess::ReplyToAllExceptions (const DNBThreadResumeActions& thread_actions) +MachProcess::ReplyToAllExceptions () { PTHREAD_MUTEX_LOCKER(locker, m_exception_messages_mutex); if (m_exception_messages.empty() == false) @@ -610,13 +613,13 @@ DNBLogThreadedIf(LOG_EXCEPTIONS, "Replying to exception %d...", std::distance(begin, pos)); int thread_reply_signal = 0; - const DNBThreadResumeAction *action = thread_actions.GetActionForThread (pos->state.thread_port, false); + const DNBThreadResumeAction *action = m_thread_actions.GetActionForThread (pos->state.thread_port, false); if (action) { thread_reply_signal = action->signal; if (thread_reply_signal) - thread_actions.SetSignalHandledForThread (pos->state.thread_port); + m_thread_actions.SetSignalHandledForThread (pos->state.thread_port); } DNBError err (pos->Reply(this, thread_reply_signal)); @@ -630,20 +633,20 @@ } } void -MachProcess::PrivateResume (const DNBThreadResumeActions& thread_actions) +MachProcess::PrivateResume () { PTHREAD_MUTEX_LOCKER (locker, m_exception_messages_mutex); - ReplyToAllExceptions (thread_actions); + ReplyToAllExceptions (); // bool stepOverBreakInstruction = step; // Let the thread prepare to resume and see if any threads want us to // step over a breakpoint instruction (ProcessWillResume will modify // the value of stepOverBreakInstruction). - m_thread_list.ProcessWillResume (this, thread_actions); + m_thread_list.ProcessWillResume (this, m_thread_actions); // Set our state accordingly - if (thread_actions.NumActionsWithState(eStateStepping)) + if (m_thread_actions.NumActionsWithState(eStateStepping)) SetState (eStateStepping); else SetState (eStateRunning); @@ -1100,7 +1103,7 @@ else { // Resume without checking our current state. - PrivateResume (DNBThreadResumeActions (eStateRunning, 0)); + PrivateResume (); } } else Modified: lldb/trunk/tools/debugserver/source/MacOSX/MachProcess.h URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/tools/debugserver/source/MacOSX/MachProcess.h?rev=123762&r1=123761&r2=123762&view=diff ============================================================================== --- lldb/trunk/tools/debugserver/source/MacOSX/MachProcess.h (original) +++ lldb/trunk/tools/debugserver/source/MacOSX/MachProcess.h Tue Jan 18 13:36:39 2011 @@ -17,6 +17,7 @@ #include "DNBDefs.h" #include "DNBBreakpoint.h" #include "DNBError.h" +#include "DNBThreadResumeActions.h" //#include "MachDYLD.h" #include "MachException.h" #include "MachVMMemory.h" @@ -219,8 +220,8 @@ eMachProcessFlagsUsingSBS = (1 << 1) }; void Clear (); - void ReplyToAllExceptions (const DNBThreadResumeActions& thread_actions); - void PrivateResume (const DNBThreadResumeActions& thread_actions); + void ReplyToAllExceptions (); + void PrivateResume (); nub_size_t RemoveTrapsFromBuffer (nub_addr_t addr, nub_size_t size, uint8_t *buf) const; uint32_t Flags () const { return m_flags; } @@ -239,6 +240,7 @@ pthread_t m_stdio_thread; // Thread ID for the thread that watches for child process stdio PThreadMutex m_stdio_mutex; // Multithreaded protection for stdio std::string m_stdout_data; + DNBThreadResumeActions m_thread_actions; // The thread actions for the current MachProcess::Resume() call MachException::Message::collection m_exception_messages; // A collection of exception messages caught when listening to the exception port PThreadMutex m_exception_messages_mutex; // Multithreaded protection for m_exception_messages Modified: lldb/trunk/tools/debugserver/source/MacOSX/MachThread.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/tools/debugserver/source/MacOSX/MachThread.cpp?rev=123762&r1=123761&r2=123762&view=diff ============================================================================== --- lldb/trunk/tools/debugserver/source/MacOSX/MachThread.cpp (original) +++ lldb/trunk/tools/debugserver/source/MacOSX/MachThread.cpp Tue Jan 18 13:36:39 2011 @@ -339,6 +339,12 @@ m_stop_exception.Clear(); } +nub_break_t +MachThread::CurrentBreakpoint() +{ + return m_process->Breakpoints().FindIDByAddress(GetPC()); +} + bool MachThread::ShouldStop(bool &step_more) { @@ -394,14 +400,18 @@ bool MachThread::IsStepping() { +#if ENABLE_AUTO_STEPPING_OVER_BP // Return true if this thread is currently being stepped. // MachThread::ThreadWillResume currently determines this by looking if we // have been asked to single step, or if we are at a breakpoint instruction // and have been asked to resume. In the latter case we need to disable the // breakpoint we are at, single step, re-enable and continue. nub_state_t state = GetState(); - return (state == eStateStepping) || - (state == eStateRunning && NUB_BREAK_ID_IS_VALID(CurrentBreakpoint())); + return ((state == eStateStepping) || + (state == eStateRunning && NUB_BREAK_ID_IS_VALID(CurrentBreakpoint()))); +#else + return GetState() == eStateStepping; +#endif } @@ -430,6 +440,7 @@ // Update the basic information for a thread MachThread::GetBasicInfo(m_tid, &m_basicInfo); +#if ENABLE_AUTO_STEPPING_OVER_BP // See if we were at a breakpoint when we last resumed that we disabled, // re-enable it. nub_break_t breakID = CurrentBreakpoint(); @@ -469,10 +480,12 @@ SetState(eStateStopped); } } - - - SetCurrentBreakpoint(INVALID_NUB_BREAK_ID); - +#else + if (m_basicInfo.suspend_count > 0) + SetState(eStateSuspended); + else + SetState(eStateStopped); +#endif return true; } @@ -496,30 +509,27 @@ if (!handled) { handled = true; - nub_addr_t pc = GetPC(); - nub_break_t breakID = m_process->Breakpoints().FindIDByAddress(pc); - SetCurrentBreakpoint(breakID); - switch (exc.exc_type) - { - case EXC_BAD_ACCESS: - break; - case EXC_BAD_INSTRUCTION: - break; - case EXC_ARITHMETIC: - break; - case EXC_EMULATION: - break; - case EXC_SOFTWARE: - break; - case EXC_BREAKPOINT: - break; - case EXC_SYSCALL: - break; - case EXC_MACH_SYSCALL: - break; - case EXC_RPC_ALERT: - break; - } +// switch (exc.exc_type) +// { +// case EXC_BAD_ACCESS: +// break; +// case EXC_BAD_INSTRUCTION: +// break; +// case EXC_ARITHMETIC: +// break; +// case EXC_EMULATION: +// break; +// case EXC_SOFTWARE: +// break; +// case EXC_BREAKPOINT: +// break; +// case EXC_SYSCALL: +// break; +// case EXC_MACH_SYSCALL: +// break; +// case EXC_RPC_ALERT: +// break; +// } } return handled; } @@ -658,27 +668,6 @@ return false; } - -void -MachThread::NotifyBreakpointChanged (const DNBBreakpoint *bp) -{ - nub_break_t breakID = bp->GetID(); - if (bp->IsEnabled()) - { - if (bp->Address() == GetPC()) - { - SetCurrentBreakpoint(breakID); - } - } - else - { - if (CurrentBreakpoint() == breakID) - { - SetCurrentBreakpoint(INVALID_NUB_BREAK_ID); - } - } -} - bool MachThread::GetIdentifierInfo () { Modified: lldb/trunk/tools/debugserver/source/MacOSX/MachThread.h URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/tools/debugserver/source/MacOSX/MachThread.h?rev=123762&r1=123761&r2=123762&view=diff ============================================================================== --- lldb/trunk/tools/debugserver/source/MacOSX/MachThread.h (original) +++ lldb/trunk/tools/debugserver/source/MacOSX/MachThread.h Tue Jan 18 13:36:39 2011 @@ -60,8 +60,7 @@ bool SetPC(uint64_t value); // Set program counter uint64_t GetSP(uint64_t failValue = INVALID_NUB_ADDRESS); // Get stack pointer - nub_break_t CurrentBreakpoint() const { return m_breakID; } - void SetCurrentBreakpoint(nub_break_t breakID) { m_breakID = breakID; } + nub_break_t CurrentBreakpoint(); uint32_t EnableHardwareBreakpoint (const DNBBreakpoint *breakpoint); uint32_t EnableHardwareWatchpoint (const DNBBreakpoint *watchpoint); bool DisableHardwareBreakpoint (const DNBBreakpoint *breakpoint); @@ -88,7 +87,9 @@ bool SetRegisterValue ( uint32_t reg_set_idx, uint32_t reg_idx, const DNBRegisterValue *reg_value ); nub_size_t GetRegisterContext (void *buf, nub_size_t buf_len); nub_size_t SetRegisterContext (const void *buf, nub_size_t buf_len); - void NotifyBreakpointChanged (const DNBBreakpoint *bp); + void NotifyBreakpointChanged (const DNBBreakpoint *bp) + { + } bool IsUserReady(); struct thread_basic_info * Modified: lldb/trunk/tools/debugserver/source/MacOSX/i386/DNBArchImplI386.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/tools/debugserver/source/MacOSX/i386/DNBArchImplI386.cpp?rev=123762&r1=123761&r2=123762&view=diff ============================================================================== --- lldb/trunk/tools/debugserver/source/MacOSX/i386/DNBArchImplI386.cpp (original) +++ lldb/trunk/tools/debugserver/source/MacOSX/i386/DNBArchImplI386.cpp Tue Jan 18 13:36:39 2011 @@ -428,8 +428,6 @@ // Write the new PC back out SetGPRState (); } - - m_thread->SetCurrentBreakpoint(breakID); } return true; } Modified: lldb/trunk/tools/debugserver/source/MacOSX/x86_64/DNBArchImplX86_64.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/tools/debugserver/source/MacOSX/x86_64/DNBArchImplX86_64.cpp?rev=123762&r1=123761&r2=123762&view=diff ============================================================================== --- lldb/trunk/tools/debugserver/source/MacOSX/x86_64/DNBArchImplX86_64.cpp (original) +++ lldb/trunk/tools/debugserver/source/MacOSX/x86_64/DNBArchImplX86_64.cpp Tue Jan 18 13:36:39 2011 @@ -355,8 +355,6 @@ // Write the new PC back out SetGPRState (); } - - m_thread->SetCurrentBreakpoint(breakID); } return true; } Modified: lldb/trunk/tools/debugserver/source/RNBRemote.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/tools/debugserver/source/RNBRemote.cpp?rev=123762&r1=123761&r2=123762&view=diff ============================================================================== --- lldb/trunk/tools/debugserver/source/RNBRemote.cpp (original) +++ lldb/trunk/tools/debugserver/source/RNBRemote.cpp Tue Jan 18 13:36:39 2011 @@ -76,6 +76,7 @@ m_max_payload_size(DEFAULT_GDB_REMOTE_PROTOCOL_BUFSIZE - 4), m_extended_mode(false), m_noack_mode(false), + m_thread_suffix_supported (false), m_use_native_regs (use_native_regs) { DNBLogThreadedIf (LOG_RNB_REMOTE, "%s", __PRETTY_FUNCTION__); @@ -170,12 +171,13 @@ t.push_back (Packet (query_step_packet_supported, &RNBRemote::HandlePacket_qStepPacketSupported,NULL, "qStepPacketSupported", "Replys with OK if the 's' packet is supported.")); t.push_back (Packet (query_host_info, &RNBRemote::HandlePacket_qHostInfo, NULL, "qHostInfo", "Replies with multiple 'key:value;' tuples appended to each other.")); // t.push_back (Packet (query_symbol_lookup, &RNBRemote::HandlePacket_UNIMPLEMENTED, NULL, "qSymbol", "Notify that host debugger is ready to do symbol lookups")); - t.push_back (Packet (start_noack_mode, &RNBRemote::HandlePacket_Q , NULL, "QStartNoAckMode", "Request that " DEBUGSERVER_PROGRAM_NAME " stop acking remote protocol packets")); - t.push_back (Packet (set_logging_mode, &RNBRemote::HandlePacket_Q , NULL, "QSetLogging:", "Request that the " DEBUGSERVER_PROGRAM_NAME " set its logging mode bits")); - t.push_back (Packet (set_max_packet_size, &RNBRemote::HandlePacket_Q , NULL, "QSetMaxPacketSize:", "Tell " DEBUGSERVER_PROGRAM_NAME " the max sized packet gdb can handle")); - t.push_back (Packet (set_max_payload_size, &RNBRemote::HandlePacket_Q , NULL, "QSetMaxPayloadSize:", "Tell " DEBUGSERVER_PROGRAM_NAME " the max sized payload gdb can handle")); - t.push_back (Packet (set_environment_variable, &RNBRemote::HandlePacket_Q , NULL, "QEnvironment:", "Add an environment variable to the inferior's environment")); - t.push_back (Packet (set_disable_aslr, &RNBRemote::HandlePacket_Q , NULL, "QSetDisableASLR:", "Set wether to disable ASLR when launching the process with the set argv ('A') packet")); + t.push_back (Packet (start_noack_mode, &RNBRemote::HandlePacket_QStartNoAckMode , NULL, "QStartNoAckMode", "Request that " DEBUGSERVER_PROGRAM_NAME " stop acking remote protocol packets")); + t.push_back (Packet (prefix_reg_packets_with_tid, &RNBRemote::HandlePacket_QThreadSuffixSupported , NULL, "QThreadSuffixSupported", "Check if thread specifc packets (register packets 'g', 'G', 'p', and 'P') support having the thread ID appended to the end of the command")); + t.push_back (Packet (set_logging_mode, &RNBRemote::HandlePacket_QSetLogging , NULL, "QSetLogging:", "Check if register packets ('g', 'G', 'p', and 'P' support having the thread ID prefix")); + t.push_back (Packet (set_max_packet_size, &RNBRemote::HandlePacket_QSetMaxPacketSize , NULL, "QSetMaxPacketSize:", "Tell " DEBUGSERVER_PROGRAM_NAME " the max sized packet gdb can handle")); + t.push_back (Packet (set_max_payload_size, &RNBRemote::HandlePacket_QSetMaxPayloadSize , NULL, "QSetMaxPayloadSize:", "Tell " DEBUGSERVER_PROGRAM_NAME " the max sized payload gdb can handle")); + t.push_back (Packet (set_environment_variable, &RNBRemote::HandlePacket_QEnvironment , NULL, "QEnvironment:", "Add an environment variable to the inferior's environment")); + t.push_back (Packet (set_disable_aslr, &RNBRemote::HandlePacket_QSetDisableASLR , NULL, "QSetDisableASLR:", "Set wether to disable ASLR when launching the process with the set argv ('A') packet")); // t.push_back (Packet (pass_signals_to_inferior, &RNBRemote::HandlePacket_UNIMPLEMENTED, NULL, "QPassSignals:", "Specify which signals are passed to the inferior")); t.push_back (Packet (allocate_memory, &RNBRemote::HandlePacket_AllocateMemory, NULL, "_M", "Allocate memory in the inferior process.")); t.push_back (Packet (deallocate_memory, &RNBRemote::HandlePacket_DeallocateMemory, NULL, "_m", "Deallocate memory in the inferior process.")); @@ -1702,104 +1704,105 @@ return rnb_success; } - +rnb_err_t +RNBRemote::HandlePacket_QThreadSuffixSupported (const char *p) +{ + m_thread_suffix_supported = true; + return SendPacket ("OK"); +} rnb_err_t -RNBRemote::HandlePacket_Q (const char *p) +RNBRemote::HandlePacket_QStartNoAckMode (const char *p) { - if (p == NULL || strlen (p) <= 1) - { - return HandlePacket_ILLFORMED ("No subtype specified in Q packet"); - } + // Send the OK packet first so the correct checksum is appended... + rnb_err_t result = SendPacket ("OK"); + m_noack_mode = true; + return result; +} - /* Switch to no-ack protocol mode after the "OK" packet is sent - and the ack for that comes back from gdb. */ - if (strcmp (p, "QStartNoAckMode") == 0) - { - rnb_err_t result = SendPacket ("OK"); - m_noack_mode = true; - return result; - } +rnb_err_t +RNBRemote::HandlePacket_QSetLogging (const char *p) +{ + p += sizeof ("QSetLogging:") - 1; + rnb_err_t result = set_logging (p); + if (result == rnb_success) + return SendPacket ("OK"); + else + return SendPacket ("E35"); +} - if (strncmp (p, "QSetLogging:", sizeof ("QSetLogging:") - 1) == 0) +rnb_err_t +RNBRemote::HandlePacket_QSetDisableASLR (const char *p) +{ + extern int g_disable_aslr; + p += sizeof ("QSetDisableASLR:") - 1; + switch (*p) { - p += sizeof ("QSetLogging:") - 1; - rnb_err_t result = set_logging (p); - if (result == rnb_success) - return SendPacket ("OK"); - else - return SendPacket ("E35"); + case '0': g_disable_aslr = 0; break; + case '1': g_disable_aslr = 1; break; + default: + return SendPacket ("E56"); } + return SendPacket ("OK"); +} - if (strncmp (p, "QSetDisableASLR:", sizeof ("QSetDisableASLR:") - 1) == 0) - { - extern int g_disable_aslr; - p += sizeof ("QSetDisableASLR:") - 1; - switch (*p) - { - case '0': g_disable_aslr = 0; break; - case '1': g_disable_aslr = 1; break; - default: - return SendPacket ("E56"); - } - return SendPacket ("OK"); - } +rnb_err_t +RNBRemote::HandlePacket_QSetMaxPayloadSize (const char *p) +{ /* The number of characters in a packet payload that gdb is prepared to accept. The packet-start char, packet-end char, 2 checksum chars and terminating null character are not included in this size. */ - if (strncmp (p, "QSetMaxPayloadSize:", sizeof ("QSetMaxPayloadSize:") - 1) == 0) + p += sizeof ("QSetMaxPayloadSize:") - 1; + errno = 0; + uint32_t size = strtoul (p, NULL, 16); + if (errno != 0 && size == 0) { - p += sizeof ("QSetMaxPayloadSize:") - 1; - errno = 0; - uint32_t size = strtoul (p, NULL, 16); - if (errno != 0 && size == 0) - { - return HandlePacket_ILLFORMED ("Invalid length in QSetMaxPayloadSize packet"); - } - m_max_payload_size = size; - return SendPacket ("OK"); + return HandlePacket_ILLFORMED ("Invalid length in QSetMaxPayloadSize packet"); } + m_max_payload_size = size; + return SendPacket ("OK"); +} +rnb_err_t +RNBRemote::HandlePacket_QSetMaxPacketSize (const char *p) +{ /* This tells us the largest packet that gdb can handle. i.e. the size of gdb's packet-reading buffer. QSetMaxPayloadSize is preferred because it is less ambiguous. */ - - if (strncmp (p, "QSetMaxPacketSize:", sizeof ("QSetMaxPacketSize:") - 1) == 0) + p += sizeof ("QSetMaxPacketSize:") - 1; + errno = 0; + uint32_t size = strtoul (p, NULL, 16); + if (errno != 0 && size == 0) { - p += sizeof ("QSetMaxPacketSize:") - 1; - errno = 0; - uint32_t size = strtoul (p, NULL, 16); - if (errno != 0 && size == 0) - { - return HandlePacket_ILLFORMED ("Invalid length in QSetMaxPacketSize packet"); - } - m_max_payload_size = size - 5; - return SendPacket ("OK"); + return HandlePacket_ILLFORMED ("Invalid length in QSetMaxPacketSize packet"); } + m_max_payload_size = size - 5; + return SendPacket ("OK"); +} + + + +rnb_err_t +RNBRemote::HandlePacket_QEnvironment (const char *p) +{ /* This sets the environment for the target program. The packet is of the form: QEnvironment:VARIABLE=VALUE */ - if (strncmp (p, "QEnvironment:", sizeof ("QEnvironment:") - 1) == 0) - { - DNBLogThreadedIf (LOG_RNB_REMOTE, "%8u RNBRemote::%s Handling QEnvironment: \"%s\"", - (uint32_t)m_comm.Timer().ElapsedMicroSeconds(true), __FUNCTION__, p); + DNBLogThreadedIf (LOG_RNB_REMOTE, "%8u RNBRemote::%s Handling QEnvironment: \"%s\"", + (uint32_t)m_comm.Timer().ElapsedMicroSeconds(true), __FUNCTION__, p); - p += sizeof ("QEnvironment:") - 1; - RNBContext& ctx = Context(); - - ctx.PushEnvironment (p); - return SendPacket ("OK"); - } + p += sizeof ("QEnvironment:") - 1; + RNBContext& ctx = Context(); - // Unrecognized Q packet - return SendPacket (""); + ctx.PushEnvironment (p); + return SendPacket ("OK"); } void @@ -2245,7 +2248,9 @@ InitializeRegisters (); nub_process_t pid = m_ctx.ProcessID (); - nub_thread_t tid = GetCurrentThread(); + nub_thread_t tid = ExtractThreadIDFromThreadSuffix (p + 1); + if (tid == INVALID_NUB_THREAD) + return HandlePacket_ILLFORMED ("No thread specified in p packet"); if (m_use_native_regs) { @@ -2291,7 +2296,9 @@ packet.SetFilePos(1); // Skip the 'G' nub_process_t pid = m_ctx.ProcessID(); - nub_thread_t tid = GetCurrentThread(); + nub_thread_t tid = ExtractThreadIDFromThreadSuffix (p); + if (tid == INVALID_NUB_THREAD) + return HandlePacket_ILLFORMED ("No thread specified in p packet"); if (m_use_native_regs) { @@ -2870,6 +2877,30 @@ return HandlePacket_UNIMPLEMENTED(p); } +// Extract the thread number from the thread suffix that might be appended to +// thread specific packets. This will only be enabled if m_thread_suffix_supported +// is true. +nub_thread_t +RNBRemote::ExtractThreadIDFromThreadSuffix (const char *p) +{ + if (m_thread_suffix_supported) + { + nub_thread_t tid = INVALID_NUB_THREAD; + if (p) + { + const char *tid_cstr = strstr (p, "thread:"); + if (tid_cstr) + { + tid_cstr += strlen ("thread:"); + tid = strtoul(tid_cstr, NULL, 16); + } + DNBLogThreadedIf (LOG_RNB_PACKETS, "RNBRemote::ExtractThreadIDFromThreadSuffix(%s) got thread 0x%4.4x", p, tid); + } + } + return GetCurrentThread(); + +} + /* `p XX' print the contents of register X */ @@ -2889,12 +2920,17 @@ } nub_process_t pid = m_ctx.ProcessID(); errno = 0; - uint32_t reg = strtoul (p + 1, NULL, 16); + char *tid_cstr = NULL; + uint32_t reg = strtoul (p + 1, &tid_cstr, 16); if (errno != 0 && reg == 0) { - return HandlePacket_ILLFORMED ("Could not parse thread number in p packet"); + return HandlePacket_ILLFORMED ("Could not parse register number in p packet"); } + nub_thread_t tid = ExtractThreadIDFromThreadSuffix (tid_cstr); + if (tid == INVALID_NUB_THREAD) + return HandlePacket_ILLFORMED ("No thread specified in p packet"); + const register_map_entry_t *reg_entry; if (reg < g_num_reg_entries) @@ -2925,7 +2961,6 @@ } else { - nub_thread_t tid = GetCurrentThread(); register_value_in_hex_fixed_width (ostrm, pid, tid, reg_entry); } return SendPacket (ostrm.str()); @@ -2985,8 +3020,9 @@ reg_value.info = reg_entry->nub_info; packet.GetHexBytes (reg_value.value.v_sint8, reg_entry->gdb_size, 0xcc); - nub_thread_t tid; - tid = GetCurrentThread (); + nub_thread_t tid = ExtractThreadIDFromThreadSuffix (p); + if (tid == INVALID_NUB_THREAD) + return HandlePacket_ILLFORMED ("No thread specified in p packet"); if (!DNBThreadSetRegisterValueByID (pid, tid, reg_entry->nub_info.set, reg_entry->nub_info.reg, ®_value)) { Modified: lldb/trunk/tools/debugserver/source/RNBRemote.h URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/tools/debugserver/source/RNBRemote.h?rev=123762&r1=123761&r2=123762&view=diff ============================================================================== --- lldb/trunk/tools/debugserver/source/RNBRemote.h (original) +++ lldb/trunk/tools/debugserver/source/RNBRemote.h Tue Jan 18 13:36:39 2011 @@ -93,6 +93,7 @@ query_host_info, // 'qHostInfo' pass_signals_to_inferior, // 'QPassSignals' start_noack_mode, // 'QStartNoAckMode' + prefix_reg_packets_with_tid, // 'QPrefixRegisterPacketsWithThreadID set_logging_mode, // 'QSetLogging:' set_max_packet_size, // 'QSetMaxPacketSize:' set_max_payload_size, // 'QSetMaxPayloadSize:' @@ -156,7 +157,14 @@ rnb_err_t HandlePacket_qThreadExtraInfo (const char *p); rnb_err_t HandlePacket_qThreadStopInfo (const char *p); rnb_err_t HandlePacket_qHostInfo (const char *p); - rnb_err_t HandlePacket_Q (const char *p); + rnb_err_t HandlePacket_QStartNoAckMode (const char *p); + rnb_err_t HandlePacket_QThreadSuffixSupported (const char *p); + rnb_err_t HandlePacket_QSetLogging (const char *p); + rnb_err_t HandlePacket_QSetDisableASLR (const char *p); + rnb_err_t HandlePacket_QSetMaxPayloadSize (const char *p); + rnb_err_t HandlePacket_QSetMaxPacketSize (const char *p); + rnb_err_t HandlePacket_QEnvironment (const char *p); + rnb_err_t HandlePacket_QPrefixRegisterPacketsWithThreadID (const char *p); rnb_err_t HandlePacket_last_signal (const char *p); rnb_err_t HandlePacket_m (const char *p); rnb_err_t HandlePacket_M (const char *p); @@ -237,6 +245,9 @@ void CreatePacketTable (); rnb_err_t GetPacketPayload (std::string &); + nub_thread_t + ExtractThreadIDFromThreadSuffix (const char *p); + // gdb can send multiple Z/z packets for the same address and // these calls must be ref counted. struct Breakpoint @@ -286,7 +297,13 @@ uint32_t m_max_payload_size; // the maximum sized payload we should send to gdb bool m_extended_mode:1, // are we in extended mode? m_noack_mode:1, // are we in no-ack mode? - m_use_native_regs:1; // Use native registers by querying DNB layer for register definitions? + m_noack_mode_just_enabled:1, // Did we just enable this and need to compute one more checksum? + m_use_native_regs:1, // Use native registers by querying DNB layer for register definitions? + m_thread_suffix_supported:1; // Set to true if the 'p', 'P', 'g', and 'G' packets should be prefixed with the thread ID and colon: + // "$pRR;thread:TTTT;" instead of "$pRR" + // "$PRR=VVVVVVVV;thread:TTTT;" instead of "$PRR=VVVVVVVV" + // "$g;thread:TTTT" instead of "$g" + // "$GVVVVVVVVVVVVVV;thread:TTTT;#00 instead of "$GVVVVVVVVVVVVVV" }; /* We translate the /usr/include/mach/exception_types.h exception types From wilsons at start.ca Tue Jan 18 15:11:40 2011 From: wilsons at start.ca (Stephen Wilson) Date: Tue, 18 Jan 2011 16:11:40 -0500 Subject: [Lldb-commits] [PATCH 0/4] simple/trivial fixes Message-ID: <1295385104-5442-1-git-send-email-wilsons@start.ca> Another small patch series containing a few simple cleanups. From wilsons at start.ca Tue Jan 18 15:11:41 2011 From: wilsons at start.ca (Stephen Wilson) Date: Tue, 18 Jan 2011 16:11:41 -0500 Subject: [Lldb-commits] [PATCH 1/4] Add a missing 'return'. In-Reply-To: <1295385104-5442-1-git-send-email-wilsons@start.ca> References: <1295385104-5442-1-git-send-email-wilsons@start.ca> Message-ID: <1295385104-5442-2-git-send-email-wilsons@start.ca> --- source/API/SBThread.cpp | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-) diff --git a/source/API/SBThread.cpp b/source/API/SBThread.cpp index e99a812..67ca2ff 100644 --- a/source/API/SBThread.cpp +++ b/source/API/SBThread.cpp @@ -588,7 +588,7 @@ bool SBThread::IsSuspended() { if (m_opaque_sp) - m_opaque_sp->GetResumeState () == eStateSuspended; + return m_opaque_sp->GetResumeState () == eStateSuspended; return false; } -- 1.7.3.5 From wilsons at start.ca Tue Jan 18 15:11:42 2011 From: wilsons at start.ca (Stephen Wilson) Date: Tue, 18 Jan 2011 16:11:42 -0500 Subject: [Lldb-commits] [PATCH 2/4] Display proper value in log message. In-Reply-To: <1295385104-5442-1-git-send-email-wilsons@start.ca> References: <1295385104-5442-1-git-send-email-wilsons@start.ca> Message-ID: <1295385104-5442-3-git-send-email-wilsons@start.ca> --- source/Target/ThreadPlanStepRange.cpp | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-) diff --git a/source/Target/ThreadPlanStepRange.cpp b/source/Target/ThreadPlanStepRange.cpp index a1b958e..7646dc3 100644 --- a/source/Target/ThreadPlanStepRange.cpp +++ b/source/Target/ThreadPlanStepRange.cpp @@ -88,7 +88,7 @@ ThreadPlanStepRange::ShouldReportStop (Event *event_ptr) const Vote vote = IsPlanComplete() ? eVoteYes : eVoteNo; if (log) - log->Printf ("ThreadPlanStepRange::ShouldReportStop() returning vote %i\n", eVoteYes); + log->Printf ("ThreadPlanStepRange::ShouldReportStop() returning vote %i\n", vote); return vote; } -- 1.7.3.5 From wilsons at start.ca Tue Jan 18 15:11:43 2011 From: wilsons at start.ca (Stephen Wilson) Date: Tue, 18 Jan 2011 16:11:43 -0500 Subject: [Lldb-commits] [PATCH 3/4] Use generic CPU types instead of Mach-O types when computing ArchSpec endianness. In-Reply-To: <1295385104-5442-1-git-send-email-wilsons@start.ca> References: <1295385104-5442-1-git-send-email-wilsons@start.ca> Message-ID: <1295385104-5442-4-git-send-email-wilsons@start.ca> --- source/Core/ArchSpec.cpp | 12 ++++++------ 1 files changed, 6 insertions(+), 6 deletions(-) diff --git a/source/Core/ArchSpec.cpp b/source/Core/ArchSpec.cpp index 006aa70..b09c751 100644 --- a/source/Core/ArchSpec.cpp +++ b/source/Core/ArchSpec.cpp @@ -1807,15 +1807,15 @@ ArchSpec::SetCPUSubtype (uint32_t subtype) ByteOrder ArchSpec::GetDefaultEndian () const { - switch (m_cpu) + switch (GetGenericCPUType()) { - case llvm::MachO::CPUTypePowerPC: - case llvm::MachO::CPUTypePowerPC64: + case eCPU_ppc: + case eCPU_ppc64: return eByteOrderBig; - case llvm::MachO::CPUTypeARM: - case llvm::MachO::CPUTypeI386: - case llvm::MachO::CPUTypeX86_64: + case eCPU_arm: + case eCPU_i386: + case eCPU_x86_64: return eByteOrderLittle; default: -- 1.7.3.5 From wilsons at start.ca Tue Jan 18 15:11:44 2011 From: wilsons at start.ca (Stephen Wilson) Date: Tue, 18 Jan 2011 16:11:44 -0500 Subject: [Lldb-commits] [PATCH 4/4] Remove trailing commas from lldb-enumerations. In-Reply-To: <1295385104-5442-1-git-send-email-wilsons@start.ca> References: <1295385104-5442-1-git-send-email-wilsons@start.ca> Message-ID: <1295385104-5442-5-git-send-email-wilsons@start.ca> --- include/lldb/lldb-enumerations.h | 8 ++++---- 1 files changed, 4 insertions(+), 4 deletions(-) diff --git a/include/lldb/lldb-enumerations.h b/include/lldb/lldb-enumerations.h index ba59460..1601af4 100644 --- a/include/lldb/lldb-enumerations.h +++ b/include/lldb/lldb-enumerations.h @@ -173,7 +173,7 @@ typedef enum Format eFormatVectorOfFloat32, eFormatVectorOfFloat64, eFormatVectorOfUInt128, - eFormatComplexInteger, // Integer complex type + eFormatComplexInteger // Integer complex type } Format; @@ -318,7 +318,7 @@ typedef enum ValueType eValueTypeVariableLocal = 4, // function local variables eValueTypeRegister = 5, // stack frame register value eValueTypeRegisterSet = 6, // A collection of stack frame register values - eValueTypeConstResult = 7, // constant result variables + eValueTypeConstResult = 7 // constant result variables } ValueType; //---------------------------------------------------------------------- @@ -430,7 +430,7 @@ typedef enum FunctionNameType eFunctionNameTypeBase = (1u << 3), // The function name only, no namespaces or arguments and no class // methods or selectors will be searched. eFunctionNameTypeMethod = (1u << 4), // Find function by method name (C++) with no namespace or arguments - eFunctionNameTypeSelector = (1u << 5), // Find function by selector name (ObjC) names + eFunctionNameTypeSelector = (1u << 5) // Find function by selector name (ObjC) names } FunctionNameType; @@ -602,7 +602,7 @@ typedef enum SortOrder { eSortOrderNone, eSortOrderByAddress, - eSortOrderByName, + eSortOrderByName } SortOrder; -- 1.7.3.5 From gclayton at apple.com Tue Jan 18 15:43:22 2011 From: gclayton at apple.com (Greg Clayton) Date: Tue, 18 Jan 2011 21:43:22 -0000 Subject: [Lldb-commits] [lldb] r123779 - /lldb/trunk/source/API/SBThread.cpp Message-ID: <20110118214322.F32302A6C12C@llvm.org> Author: gclayton Date: Tue Jan 18 15:43:22 2011 New Revision: 123779 URL: http://llvm.org/viewvc/llvm-project?rev=123779&view=rev Log: Fixed missing return value (patch from Stephen Wilson). Modified: lldb/trunk/source/API/SBThread.cpp Modified: lldb/trunk/source/API/SBThread.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/API/SBThread.cpp?rev=123779&r1=123778&r2=123779&view=diff ============================================================================== --- lldb/trunk/source/API/SBThread.cpp (original) +++ lldb/trunk/source/API/SBThread.cpp Tue Jan 18 15:43:22 2011 @@ -588,7 +588,7 @@ SBThread::IsSuspended() { if (m_opaque_sp) - m_opaque_sp->GetResumeState () == eStateSuspended; + return m_opaque_sp->GetResumeState () == eStateSuspended; return false; } From gclayton at apple.com Tue Jan 18 15:44:45 2011 From: gclayton at apple.com (Greg Clayton) Date: Tue, 18 Jan 2011 21:44:45 -0000 Subject: [Lldb-commits] [lldb] r123780 - /lldb/trunk/source/Target/ThreadPlanStepRange.cpp Message-ID: <20110118214445.C37022A6C12C@llvm.org> Author: gclayton Date: Tue Jan 18 15:44:45 2011 New Revision: 123780 URL: http://llvm.org/viewvc/llvm-project?rev=123780&view=rev Log: Fixed incorrect logging printf (patch from Stephen Wilson). Modified: lldb/trunk/source/Target/ThreadPlanStepRange.cpp Modified: lldb/trunk/source/Target/ThreadPlanStepRange.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Target/ThreadPlanStepRange.cpp?rev=123780&r1=123779&r2=123780&view=diff ============================================================================== --- lldb/trunk/source/Target/ThreadPlanStepRange.cpp (original) +++ lldb/trunk/source/Target/ThreadPlanStepRange.cpp Tue Jan 18 15:44:45 2011 @@ -88,7 +88,7 @@ const Vote vote = IsPlanComplete() ? eVoteYes : eVoteNo; if (log) - log->Printf ("ThreadPlanStepRange::ShouldReportStop() returning vote %i\n", eVoteYes); + log->Printf ("ThreadPlanStepRange::ShouldReportStop() returning vote %i\n", vote); return vote; } From gclayton at apple.com Tue Jan 18 15:47:52 2011 From: gclayton at apple.com (Greg Clayton) Date: Tue, 18 Jan 2011 21:47:52 -0000 Subject: [Lldb-commits] [lldb] r123781 - /lldb/trunk/source/Core/ArchSpec.cpp Message-ID: <20110118214752.A58452A6C12C@llvm.org> Author: gclayton Date: Tue Jan 18 15:47:52 2011 New Revision: 123781 URL: http://llvm.org/viewvc/llvm-project?rev=123781&view=rev Log: Use generic CPU types instead of hard coding to mach-o when getting default byte order (patch from Stephen Wilson). Modified: lldb/trunk/source/Core/ArchSpec.cpp Modified: lldb/trunk/source/Core/ArchSpec.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Core/ArchSpec.cpp?rev=123781&r1=123780&r2=123781&view=diff ============================================================================== --- lldb/trunk/source/Core/ArchSpec.cpp (original) +++ lldb/trunk/source/Core/ArchSpec.cpp Tue Jan 18 15:47:52 2011 @@ -1807,15 +1807,15 @@ ByteOrder ArchSpec::GetDefaultEndian () const { - switch (m_cpu) + switch (GetGenericCPUType ()) { - case llvm::MachO::CPUTypePowerPC: - case llvm::MachO::CPUTypePowerPC64: + case eCPU_ppc: + case eCPU_ppc64: return eByteOrderBig; - case llvm::MachO::CPUTypeARM: - case llvm::MachO::CPUTypeI386: - case llvm::MachO::CPUTypeX86_64: + case eCPU_arm: + case eCPU_i386: + case eCPU_x86_64: return eByteOrderLittle; default: From gclayton at apple.com Tue Jan 18 15:49:11 2011 From: gclayton at apple.com (Greg Clayton) Date: Tue, 18 Jan 2011 21:49:11 -0000 Subject: [Lldb-commits] [lldb] r123782 - /lldb/trunk/include/lldb/lldb-enumerations.h Message-ID: <20110118214911.474602A6C12C@llvm.org> Author: gclayton Date: Tue Jan 18 15:49:11 2011 New Revision: 123782 URL: http://llvm.org/viewvc/llvm-project?rev=123782&view=rev Log: Remove trailing commas from lldb enumerations (patch from Stephen Wilson). Modified: lldb/trunk/include/lldb/lldb-enumerations.h Modified: lldb/trunk/include/lldb/lldb-enumerations.h URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/lldb-enumerations.h?rev=123782&r1=123781&r2=123782&view=diff ============================================================================== --- lldb/trunk/include/lldb/lldb-enumerations.h (original) +++ lldb/trunk/include/lldb/lldb-enumerations.h Tue Jan 18 15:49:11 2011 @@ -156,7 +156,7 @@ eFormatHex, eFormatFloat, eFormatOctal, - eFormatOSType, // OS character codes encoded into an integer 'PICT' 'text' etc... + eFormatOSType, // OS character codes encoded into an integer 'PICT' 'text' etc... eFormatUnicode16, eFormatUnicode32, eFormatUnsigned, @@ -173,7 +173,7 @@ eFormatVectorOfFloat32, eFormatVectorOfFloat64, eFormatVectorOfUInt128, - eFormatComplexInteger, // Integer complex type + eFormatComplexInteger // Integer complex type } Format; @@ -318,7 +318,7 @@ eValueTypeVariableLocal = 4, // function local variables eValueTypeRegister = 5, // stack frame register value eValueTypeRegisterSet = 6, // A collection of stack frame register values - eValueTypeConstResult = 7, // constant result variables + eValueTypeConstResult = 7 // constant result variables } ValueType; //---------------------------------------------------------------------- @@ -430,7 +430,7 @@ eFunctionNameTypeBase = (1u << 3), // The function name only, no namespaces or arguments and no class // methods or selectors will be searched. eFunctionNameTypeMethod = (1u << 4), // Find function by method name (C++) with no namespace or arguments - eFunctionNameTypeSelector = (1u << 5), // Find function by selector name (ObjC) names + eFunctionNameTypeSelector = (1u << 5) // Find function by selector name (ObjC) names } FunctionNameType; @@ -602,7 +602,7 @@ { eSortOrderNone, eSortOrderByAddress, - eSortOrderByName, + eSortOrderByName } SortOrder; From gclayton at apple.com Tue Jan 18 15:52:44 2011 From: gclayton at apple.com (Greg Clayton) Date: Tue, 18 Jan 2011 13:52:44 -0800 Subject: [Lldb-commits] [PATCH 0/4] simple/trivial fixes In-Reply-To: <1295385104-5442-1-git-send-email-wilsons@start.ca> References: <1295385104-5442-1-git-send-email-wilsons@start.ca> Message-ID: <6D4163BC-7569-4F53-93F8-FF674AE658CC@apple.com> All patches have been checked in. Thanks for the patches! On Jan 18, 2011, at 1:11 PM, Stephen Wilson wrote: > Another small patch series containing a few simple cleanups. > > _______________________________________________ > lldb-commits mailing list > lldb-commits at cs.uiuc.edu > http://lists.cs.uiuc.edu/mailman/listinfo/lldb-commits From jingham at apple.com Tue Jan 18 16:20:08 2011 From: jingham at apple.com (Jim Ingham) Date: Tue, 18 Jan 2011 22:20:08 -0000 Subject: [Lldb-commits] [lldb] r123784 - in /lldb/trunk/source/Expression: ClangFunction.cpp ClangUserExpression.cpp Message-ID: <20110118222008.602D02A6C12C@llvm.org> Author: jingham Date: Tue Jan 18 16:20:08 2011 New Revision: 123784 URL: http://llvm.org/viewvc/llvm-project?rev=123784&view=rev Log: Make a few log messages come out in "log enable lldb step" as well as "log enable lldb expression". Modified: lldb/trunk/source/Expression/ClangFunction.cpp lldb/trunk/source/Expression/ClangUserExpression.cpp Modified: lldb/trunk/source/Expression/ClangFunction.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Expression/ClangFunction.cpp?rev=123784&r1=123783&r2=123784&view=diff ============================================================================== --- lldb/trunk/source/Expression/ClangFunction.cpp (original) +++ lldb/trunk/source/Expression/ClangFunction.cpp Tue Jan 18 16:20:08 2011 @@ -208,7 +208,7 @@ m_wrapper_function_text.append (args_list_buffer); m_wrapper_function_text.append (");\n}\n"); - lldb::LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_STEP)); + lldb::LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_EXPRESSIONS)); if (log) log->Printf ("Expression: \n\n%s\n\n", m_wrapper_function_text.c_str()); Modified: lldb/trunk/source/Expression/ClangUserExpression.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Expression/ClangUserExpression.cpp?rev=123784&r1=123783&r2=123784&view=diff ============================================================================== --- lldb/trunk/source/Expression/ClangUserExpression.cpp (original) +++ lldb/trunk/source/Expression/ClangUserExpression.cpp Tue Jan 18 16:20:08 2011 @@ -472,7 +472,9 @@ ClangUserExpression::ClangUserExpressionSP &shared_ptr_to_me, lldb::ClangExpressionVariableSP &result) { - lldb::LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_EXPRESSIONS)); + // The expression log is quite verbose, and if you're just tracking the execution of the + // expression, it's quite convenient to have these logs come out with the STEP log as well. + lldb::LogSP log(lldb_private::GetLogIfAnyCategoriesSet (LIBLLDB_LOG_EXPRESSIONS | LIBLLDB_LOG_STEP)); if (m_dwarf_opcodes.get()) { @@ -570,7 +572,7 @@ const char *expr_prefix, lldb::ValueObjectSP &result_valobj_sp) { - lldb::LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_EXPRESSIONS)); + lldb::LogSP log(lldb_private::GetLogIfAnyCategoriesSet (LIBLLDB_LOG_EXPRESSIONS | LIBLLDB_LOG_STEP)); Error error; lldb::ExecutionResults execution_results = lldb::eExecutionSetupError; From wilsons at start.ca Tue Jan 18 16:39:06 2011 From: wilsons at start.ca (Stephen Wilson) Date: Tue, 18 Jan 2011 17:39:06 -0500 Subject: [Lldb-commits] [PATCH 0/9] linux: bugfixes, register and unwind support. Message-ID: <1295390355-8700-1-git-send-email-wilsons@start.ca> This patch series provides a few important bug fixes to the linux process and dynamic loader plugins. Two new features are implemented as well: improved support for reading registers and the use of LLDB's unwinder. With these patches "basic" debugging scenarios are working on Linux x86_64. For the most part setting break points, step over/step thru, back traces, frame variable inspection, and disassemble all appear to work well. Although there is still more to do, it is exciting to see LLDB working this well on Linux! Take care, -- steve From wilsons at start.ca Tue Jan 18 16:39:07 2011 From: wilsons at start.ca (Stephen Wilson) Date: Tue, 18 Jan 2011 17:39:07 -0500 Subject: [Lldb-commits] [PATCH 1/9] Load dependent modules in the Linux dynamic loader. In-Reply-To: <1295390355-8700-1-git-send-email-wilsons@start.ca> References: <1295390355-8700-1-git-send-email-wilsons@start.ca> Message-ID: <1295390355-8700-2-git-send-email-wilsons@start.ca> This fixes a bug where the dynamic loader rendezvous was not updating its internal state when first initialized. diff --git a/source/Plugins/DynamicLoader/Linux-DYLD/DYLDRendezvous.cpp b/source/Plugins/DynamicLoader/Linux-DYLD/DYLDRendezvous.cpp index 8b4795d..f10aedb 100644 --- a/source/Plugins/DynamicLoader/Linux-DYLD/DYLDRendezvous.cpp +++ b/source/Plugins/DynamicLoader/Linux-DYLD/DYLDRendezvous.cpp @@ -117,6 +117,12 @@ DYLDRendezvous::UpdateSOEntries() if (m_current.map_addr == 0) return false; + // When the previous and current states are consistent this is the first + // time we have been asked to update. Just take a snapshot of the currently + // loaded modules. + if (m_previous.state == eConsistent && m_current.state == eConsistent) + return TakeSnapshot(m_soentries); + // If we are about to add or remove a shared object clear out the current // state and take a snapshot of the currently loaded images. if (m_current.state == eAdd || m_current.state == eDelete) @@ -127,6 +133,7 @@ DYLDRendezvous::UpdateSOEntries() m_removed_soentries.clear(); return TakeSnapshot(m_soentries); } + assert(m_current.state == eConsistent); // Otherwise check the previous state to determine what to expect and update // accordingly. -- 1.7.3.5 From wilsons at start.ca Tue Jan 18 16:39:08 2011 From: wilsons at start.ca (Stephen Wilson) Date: Tue, 18 Jan 2011 17:39:08 -0500 Subject: [Lldb-commits] [PATCH 2/9] Only enqueue valid ProcessLinux messages. In-Reply-To: <1295390355-8700-1-git-send-email-wilsons@start.ca> References: <1295390355-8700-1-git-send-email-wilsons@start.ca> Message-ID: <1295390355-8700-3-git-send-email-wilsons@start.ca> diff --git a/source/Plugins/Process/Linux/ProcessLinux.cpp b/source/Plugins/Process/Linux/ProcessLinux.cpp index d7fe1da..0e8774f 100644 --- a/source/Plugins/Process/Linux/ProcessLinux.cpp +++ b/source/Plugins/Process/Linux/ProcessLinux.cpp @@ -244,7 +244,6 @@ void ProcessLinux::SendMessage(const ProcessMessage &message) { Mutex::Locker lock(m_message_mutex); - m_message_queue.push(message); switch (message.GetKind()) { @@ -252,6 +251,9 @@ ProcessLinux::SendMessage(const ProcessMessage &message) SetPrivateState(eStateStopped); break; + case ProcessMessage::eInvalidMessage: + return; + case ProcessMessage::eExitMessage: SetExitStatus(message.GetExitStatus(), NULL); break; @@ -260,6 +262,8 @@ ProcessLinux::SendMessage(const ProcessMessage &message) SetExitStatus(-1, NULL); break; } + + m_message_queue.push(message); } void -- 1.7.3.5 From wilsons at start.ca Tue Jan 18 16:39:09 2011 From: wilsons at start.ca (Stephen Wilson) Date: Tue, 18 Jan 2011 17:39:09 -0500 Subject: [Lldb-commits] [PATCH 3/9] Timeout if we fail to receive a state change event when destroying an inferior. In-Reply-To: <1295390355-8700-1-git-send-email-wilsons@start.ca> References: <1295390355-8700-1-git-send-email-wilsons@start.ca> Message-ID: <1295390355-8700-4-git-send-email-wilsons@start.ca> diff --git a/source/Plugins/Process/Linux/ProcessLinux.cpp b/source/Plugins/Process/Linux/ProcessLinux.cpp index 0e8774f..ecf8479 100644 --- a/source/Plugins/Process/Linux/ProcessLinux.cpp +++ b/source/Plugins/Process/Linux/ProcessLinux.cpp @@ -223,20 +223,28 @@ ProcessLinux::DoDestroy() return error; } - // Wait for the event to arrive. This guaranteed to be an exit event. + // Wait for the event to arrive. This is guaranteed to be an exit event. StateType state; EventSP event; do { - state = WaitForStateChangedEventsPrivate(NULL, event); - } while (state != eStateExited); + TimeValue timeout_time; + timeout_time = TimeValue::Now(); + timeout_time.OffsetWithSeconds(2); + state = WaitForStateChangedEventsPrivate(&timeout_time, event); + } while (state != eStateExited && state != eStateInvalid); + + // Check if we timed out waiting for the exit event to arrive. + if (state == eStateInvalid) + error.SetErrorString("ProcessLinux::DoDestroy timed out."); // Restart standard event handling and send the process the final kill, // driving it out of limbo. ResumePrivateStateThread(); } - if (kill(m_monitor->GetPID(), SIGKILL)) + if (kill(m_monitor->GetPID(), SIGKILL) && error.Success()) error.SetErrorToErrno(); + return error; } -- 1.7.3.5 From wilsons at start.ca Tue Jan 18 16:39:10 2011 From: wilsons at start.ca (Stephen Wilson) Date: Tue, 18 Jan 2011 17:39:10 -0500 Subject: [Lldb-commits] [PATCH 4/9] Support the reading of registers en masse via the linux ProcessMonitor. In-Reply-To: <1295390355-8700-1-git-send-email-wilsons@start.ca> References: <1295390355-8700-1-git-send-email-wilsons@start.ca> Message-ID: <1295390355-8700-5-git-send-email-wilsons@start.ca> diff --git a/source/Plugins/Process/Linux/ProcessMonitor.cpp b/source/Plugins/Process/Linux/ProcessMonitor.cpp index f21cb00..8fe7451 100644 --- a/source/Plugins/Process/Linux/ProcessMonitor.cpp +++ b/source/Plugins/Process/Linux/ProcessMonitor.cpp @@ -260,6 +260,58 @@ WriteRegOperation::Execute(ProcessMonitor *monitor) } //------------------------------------------------------------------------------ +/// @class ReadGPROperation +/// @brief Implements ProcessMonitor::ReadGPR. +class ReadGPROperation : public Operation +{ +public: + ReadGPROperation(void *buf, bool &result) + : m_buf(buf), m_result(result) + { } + + void Execute(ProcessMonitor *monitor); + +private: + void *m_buf; + bool &m_result; +}; + +void +ReadGPROperation::Execute(ProcessMonitor *monitor) +{ + if (ptrace(PTRACE_GETREGS, monitor->GetPID(), NULL, m_buf) < 0) + m_result = false; + else + m_result = true; +} + +//------------------------------------------------------------------------------ +/// @class ReadFPROperation +/// @brief Implements ProcessMonitor::ReadFPR. +class ReadFPROperation : public Operation +{ +public: + ReadFPROperation(void *buf, bool &result) + : m_buf(buf), m_result(result) + { } + + void Execute(ProcessMonitor *monitor); + +private: + void *m_buf; + bool &m_result; +}; + +void +ReadFPROperation::Execute(ProcessMonitor *monitor) +{ + if (ptrace(PTRACE_GETFPREGS, monitor->GetPID(), NULL, m_buf) < 0) + m_result = false; + else + m_result = true; +} + +//------------------------------------------------------------------------------ /// @class ResumeOperation /// @brief Implements ProcessMonitor::Resume. class ResumeOperation : public Operation @@ -876,6 +928,24 @@ ProcessMonitor::WriteRegisterValue(unsigned offset, const Scalar &value) } bool +ProcessMonitor::ReadGPR(void *buf) +{ + bool result; + ReadGPROperation op(buf, result); + DoOperation(&op); + return result; +} + +bool +ProcessMonitor::ReadFPR(void *buf) +{ + bool result; + ReadFPROperation op(buf, result); + DoOperation(&op); + return result; +} + +bool ProcessMonitor::Resume(lldb::tid_t tid) { bool result; diff --git a/source/Plugins/Process/Linux/ProcessMonitor.h b/source/Plugins/Process/Linux/ProcessMonitor.h index 431fab7..86aad23 100644 --- a/source/Plugins/Process/Linux/ProcessMonitor.h +++ b/source/Plugins/Process/Linux/ProcessMonitor.h @@ -108,6 +108,14 @@ public: bool WriteRegisterValue(unsigned offset, const lldb_private::Scalar &value); + /// Reads all general purpose registers into the specified buffer. + bool + ReadGPR(void *buf); + + /// Reads all floating point registers into the specified buffer. + bool + ReadFPR(void *buf); + /// Writes a siginfo_t structure corresponding to the given thread ID to the /// memory region pointed to by @p siginfo. bool -- 1.7.3.5 From wilsons at start.ca Tue Jan 18 16:39:11 2011 From: wilsons at start.ca (Stephen Wilson) Date: Tue, 18 Jan 2011 17:39:11 -0500 Subject: [Lldb-commits] [PATCH 5/9] Implement RegisterContextLinux_x86_64::ReadRegisterBytes. In-Reply-To: <1295390355-8700-1-git-send-email-wilsons@start.ca> References: <1295390355-8700-1-git-send-email-wilsons@start.ca> Message-ID: <1295390355-8700-6-git-send-email-wilsons@start.ca> Also, this patch adds a few delimiters to the register enumeration to enable efficient testing of register set inclusion. diff --git a/source/Plugins/Process/Linux/RegisterContextLinux_x86_64.cpp b/source/Plugins/Process/Linux/RegisterContextLinux_x86_64.cpp index 27cd6c6..4dddce8 100644 --- a/source/Plugins/Process/Linux/RegisterContextLinux_x86_64.cpp +++ b/source/Plugins/Process/Linux/RegisterContextLinux_x86_64.cpp @@ -11,6 +11,7 @@ #include #include +#include "lldb/Core/DataExtractor.h" #include "lldb/Core/Scalar.h" #include "lldb/Target/Thread.h" @@ -24,7 +25,8 @@ using namespace lldb; // Internal codes for all x86_64 registers. enum { - gpr_rax = 0, + k_first_gpr, + gpr_rax = k_first_gpr, gpr_rbx, gpr_rcx, gpr_rdx, @@ -48,11 +50,10 @@ enum gpr_ss, gpr_ds, gpr_es, + k_last_gpr = gpr_es, - // Number of GPR's. - k_num_gpr_registers, - - fpu_fcw = k_num_gpr_registers, + k_first_fpr, + fpu_fcw = k_first_fpr, fpu_fsw, fpu_ftw, fpu_fop, @@ -86,12 +87,11 @@ enum fpu_xmm13, fpu_xmm14, fpu_xmm15, + k_last_fpr = fpu_xmm15, - // Total number of registers. k_num_registers, - - // Number of FPR's. - k_num_fpu_registers = k_num_registers - k_num_gpr_registers + k_num_gpr_registers = k_last_gpr - k_first_gpr + 1, + k_num_fpu_registers = k_last_fpr - k_first_fpr + 1 }; // Number of register sets provided by this context. @@ -401,6 +401,22 @@ static unsigned GetRegOffset(unsigned reg) return g_register_infos[reg].byte_offset; } +static unsigned GetRegSize(unsigned reg) +{ + assert(reg < k_num_registers && "Invalid register number."); + return g_register_infos[reg].byte_size; +} + +static bool IsGPR(unsigned reg) +{ + return reg <= k_last_gpr; // GPR's come first. +} + +static bool IsFPR(unsigned reg) +{ + return (k_first_fpr <= reg && reg <= k_last_fpr); +} + RegisterContextLinux_x86_64::RegisterContextLinux_x86_64(Thread &thread, uint32_t concrete_frame_idx) : RegisterContextLinux(thread, concrete_frame_idx) @@ -470,7 +486,23 @@ bool RegisterContextLinux_x86_64::ReadRegisterBytes(uint32_t reg, DataExtractor &data) { - return false; + uint8_t *buf = reinterpret_cast(&user); + bool status; + + if (IsGPR(reg)) + status = ReadGPR(); + else if (IsFPR(reg)) + status = ReadFPR(); + else + { + assert(false && "invalid register number"); + status = false; + } + + if (status) + data.SetData(buf + GetRegOffset(reg), GetRegSize(reg), eByteOrderHost); + + return status; } bool @@ -660,3 +692,17 @@ RegisterContextLinux_x86_64::HardwareSingleStep(bool enable) { return GetMonitor().SingleStep(GetThreadID()); } + +bool +RegisterContextLinux_x86_64::ReadGPR() +{ + ProcessMonitor &monitor = GetMonitor(); + return monitor.ReadGPR(&user.regs); +} + +bool +RegisterContextLinux_x86_64::ReadFPR() +{ + ProcessMonitor &monitor = GetMonitor(); + return monitor.ReadFPR(&user.i387); +} diff --git a/source/Plugins/Process/Linux/RegisterContextLinux_x86_64.h b/source/Plugins/Process/Linux/RegisterContextLinux_x86_64.h index 876d685..08d2cbd 100644 --- a/source/Plugins/Process/Linux/RegisterContextLinux_x86_64.h +++ b/source/Plugins/Process/Linux/RegisterContextLinux_x86_64.h @@ -153,6 +153,9 @@ private: UserArea user; ProcessMonitor &GetMonitor(); + + bool ReadGPR(); + bool ReadFPR(); }; #endif // #ifndef liblldb_RegisterContextLinux_x86_64_H_ -- 1.7.3.5 From wilsons at start.ca Tue Jan 18 16:39:12 2011 From: wilsons at start.ca (Stephen Wilson) Date: Tue, 18 Jan 2011 17:39:12 -0500 Subject: [Lldb-commits] [PATCH 6/9] Fix implementation of LinuxThread::HardwareSingleStep. In-Reply-To: <1295390355-8700-1-git-send-email-wilsons@start.ca> References: <1295390355-8700-1-git-send-email-wilsons@start.ca> Message-ID: <1295390355-8700-7-git-send-email-wilsons@start.ca> Previous version simply resumed the associated thread to single step over a single instruction which is not the intended semantics for this method. Set the appropriate bit in the rflags register instead. diff --git a/source/Plugins/Process/Linux/RegisterContextLinux_x86_64.cpp b/source/Plugins/Process/Linux/RegisterContextLinux_x86_64.cpp index 4dddce8..e16a3de 100644 --- a/source/Plugins/Process/Linux/RegisterContextLinux_x86_64.cpp +++ b/source/Plugins/Process/Linux/RegisterContextLinux_x86_64.cpp @@ -690,7 +690,28 @@ RegisterContextLinux_x86_64::ConvertRegisterKindToRegisterNumber(uint32_t kind, bool RegisterContextLinux_x86_64::HardwareSingleStep(bool enable) { - return GetMonitor().SingleStep(GetThreadID()); + enum { TRACE_BIT = 0x100 }; + uint64_t rflags; + + if ((rflags = ReadRegisterAsUnsigned(gpr_rflags, -1UL)) == -1UL) + return false; + + if (enable) + { + if (rflags & TRACE_BIT) + return true; + + rflags |= TRACE_BIT; + } + else + { + if (!(rflags & TRACE_BIT)) + return false; + + rflags &= ~TRACE_BIT; + } + + return WriteRegisterFromUnsigned(gpr_rflags, rflags); } bool -- 1.7.3.5 From wilsons at start.ca Tue Jan 18 16:39:13 2011 From: wilsons at start.ca (Stephen Wilson) Date: Tue, 18 Jan 2011 17:39:13 -0500 Subject: [Lldb-commits] [PATCH 7/9] Do not enable hardware stepping when resuming a step-enabled thread. In-Reply-To: <1295390355-8700-1-git-send-email-wilsons@start.ca> References: <1295390355-8700-1-git-send-email-wilsons@start.ca> Message-ID: <1295390355-8700-8-git-send-email-wilsons@start.ca> The previous implementation of HardwareSingleStep wrongly resumed the thread and single-stepped over the next instruction. Use the proper call to ProcessMonitor. diff --git a/source/Plugins/Process/Linux/LinuxThread.cpp b/source/Plugins/Process/Linux/LinuxThread.cpp index de1ca51..b7b2df1 100644 --- a/source/Plugins/Process/Linux/LinuxThread.cpp +++ b/source/Plugins/Process/Linux/LinuxThread.cpp @@ -153,7 +153,7 @@ LinuxThread::Resume() case lldb::eStateStepping: SetState(resume_state); - status = GetRegisterContext()->HardwareSingleStep(true); + status = monitor.SingleStep(GetID()); break; } -- 1.7.3.5 From wilsons at start.ca Tue Jan 18 16:39:14 2011 From: wilsons at start.ca (Stephen Wilson) Date: Tue, 18 Jan 2011 17:39:14 -0500 Subject: [Lldb-commits] [PATCH 8/9] Make LinuxThread use the LLDB unwinder. In-Reply-To: <1295390355-8700-1-git-send-email-wilsons@start.ca> References: <1295390355-8700-1-git-send-email-wilsons@start.ca> Message-ID: <1295390355-8700-9-git-send-email-wilsons@start.ca> diff --git a/source/Plugins/Process/Linux/LinuxThread.cpp b/source/Plugins/Process/Linux/LinuxThread.cpp index b7b2df1..5c278d4 100644 --- a/source/Plugins/Process/Linux/LinuxThread.cpp +++ b/source/Plugins/Process/Linux/LinuxThread.cpp @@ -7,9 +7,9 @@ // //===----------------------------------------------------------------------===// +// C Includes #include -// C Includes // C++ Includes // Other libraries and framework includes #include "lldb/Target/Process.h" @@ -20,6 +20,7 @@ #include "ProcessLinux.h" #include "ProcessMonitor.h" #include "RegisterContextLinux_x86_64.h" +#include "UnwindLLDB.h" using namespace lldb_private; @@ -91,17 +92,19 @@ LinuxThread::RestoreSaveFrameZero(const RegisterCheckpoint &checkpoint) } lldb::RegisterContextSP -LinuxThread::CreateRegisterContextForFrame (lldb_private::StackFrame *frame) +LinuxThread::CreateRegisterContextForFrame(lldb_private::StackFrame *frame) { lldb::RegisterContextSP reg_ctx_sp; uint32_t concrete_frame_idx = 0; + if (frame) concrete_frame_idx = frame->GetConcreteFrameIndex(); if (concrete_frame_idx == 0) reg_ctx_sp = GetRegisterContext(); else - reg_ctx_sp.reset (new RegisterContextLinux_x86_64(*this, frame->GetConcreteFrameIndex())); + reg_ctx_sp = GetUnwinder()->CreateRegisterContextForFrame(frame); + return reg_ctx_sp; } @@ -118,6 +121,9 @@ LinuxThread::GetPrivateStopReason() Unwind * LinuxThread::GetUnwinder() { + if (m_unwinder_ap.get() == NULL) + m_unwinder_ap.reset(new UnwindLLDB(*this)); + return m_unwinder_ap.get(); } @@ -125,6 +131,11 @@ bool LinuxThread::WillResume(lldb::StateType resume_state) { SetResumeState(resume_state); + + ClearStackFrames(); + if (m_unwinder_ap.get()) + m_unwinder_ap->Clear(); + return Thread::WillResume(resume_state); } diff --git a/source/Plugins/Process/Linux/Makefile b/source/Plugins/Process/Linux/Makefile index 0454e6d..d2260f5 100644 --- a/source/Plugins/Process/Linux/Makefile +++ b/source/Plugins/Process/Linux/Makefile @@ -11,4 +11,7 @@ LLDB_LEVEL := ../../../.. LIBRARYNAME := lldbPluginProcessLinux BUILD_ARCHIVE = 1 +# Extend the include path so we may locate UnwindLLDB.h +CPPFLAGS += -I $(LLDB_LEVEL)/source/Plugins/Utility + include $(LLDB_LEVEL)/Makefile -- 1.7.3.5 From wilsons at start.ca Tue Jan 18 16:39:15 2011 From: wilsons at start.ca (Stephen Wilson) Date: Tue, 18 Jan 2011 17:39:15 -0500 Subject: [Lldb-commits] [PATCH 9/9] Delay sync with the parent thread in ProcessLinux/ProcessMonitor. In-Reply-To: <1295390355-8700-1-git-send-email-wilsons@start.ca> References: <1295390355-8700-1-git-send-email-wilsons@start.ca> Message-ID: <1295390355-8700-10-git-send-email-wilsons@start.ca> This patch removes a potential race condition between a process monitor thread and its parent waiting to interrogate the success/failure of the launch. diff --git a/source/Plugins/Process/Linux/ProcessMonitor.cpp b/source/Plugins/Process/Linux/ProcessMonitor.cpp index 8fe7451..2c93638 100644 --- a/source/Plugins/Process/Linux/ProcessMonitor.cpp +++ b/source/Plugins/Process/Linux/ProcessMonitor.cpp @@ -607,7 +607,7 @@ ProcessMonitor::OperationThread(void *arg) if (!Launch(args)) return NULL; - ServeOperation(args->m_monitor); + ServeOperation(args); return NULL; } @@ -716,8 +716,6 @@ ProcessMonitor::Launch(LaunchArgs *args) process.SendMessage(ProcessMessage::Trace(pid)); FINISH: - // Sync with our parent thread now that the launch operation is complete. - sem_post(&args->m_semaphore); return args->m_error.Success(); } @@ -819,15 +817,20 @@ ProcessMonitor::MonitorSIGTRAP(ProcessMonitor *monitor, lldb::pid_t pid) } void -ProcessMonitor::ServeOperation(ProcessMonitor *monitor) +ProcessMonitor::ServeOperation(LaunchArgs *args) { int status; pollfd fdset; + ProcessMonitor *monitor = args->m_monitor; fdset.fd = monitor->m_server_fd; fdset.events = POLLIN | POLLPRI; fdset.revents = 0; + // We are finised with the arguments and are ready to go. Sync with the + // parent thread and start serving operations on the inferior. + sem_post(&args->m_semaphore); + for (;;) { if ((status = poll(&fdset, 1, -1)) < 0) diff --git a/source/Plugins/Process/Linux/ProcessMonitor.h b/source/Plugins/Process/Linux/ProcessMonitor.h index 86aad23..c016019 100644 --- a/source/Plugins/Process/Linux/ProcessMonitor.h +++ b/source/Plugins/Process/Linux/ProcessMonitor.h @@ -197,7 +197,7 @@ private: EnableIPC(); static void - ServeOperation(ProcessMonitor *monitor); + ServeOperation(LaunchArgs *args); static bool DupDescriptor(const char *path, int fd, int flags); -- 1.7.3.5 From scallanan at apple.com Tue Jan 18 17:32:06 2011 From: scallanan at apple.com (Sean Callanan) Date: Tue, 18 Jan 2011 23:32:06 -0000 Subject: [Lldb-commits] [lldb] r123787 - in /lldb/trunk: llvm.zip scripts/build-llvm.pl source/Core/FileSpec.cpp source/Expression/ClangASTSource.cpp source/Expression/ClangExpressionParser.cpp source/Symbol/ClangASTContext.cpp source/Symbol/ClangASTType.cpp Message-ID: <20110118233206.1BEC82A6C12C@llvm.org> Author: spyffe Date: Tue Jan 18 17:32:05 2011 New Revision: 123787 URL: http://llvm.org/viewvc/llvm-project?rev=123787&view=rev Log: Updated to revision 123723 of LLVM, to bring in support for minimal type import functionality. Modified: lldb/trunk/llvm.zip lldb/trunk/scripts/build-llvm.pl lldb/trunk/source/Core/FileSpec.cpp lldb/trunk/source/Expression/ClangASTSource.cpp lldb/trunk/source/Expression/ClangExpressionParser.cpp lldb/trunk/source/Symbol/ClangASTContext.cpp lldb/trunk/source/Symbol/ClangASTType.cpp Modified: lldb/trunk/llvm.zip URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/llvm.zip?rev=123787&r1=123786&r2=123787&view=diff ============================================================================== Binary files - no diff available. Modified: lldb/trunk/scripts/build-llvm.pl URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/scripts/build-llvm.pl?rev=123787&r1=123786&r2=123787&view=diff ============================================================================== --- lldb/trunk/scripts/build-llvm.pl (original) +++ lldb/trunk/scripts/build-llvm.pl Tue Jan 18 17:32:05 2011 @@ -25,7 +25,7 @@ our $llvm_configuration = $ENV{LLVM_CONFIGURATION}; -our $llvm_revision = "121655"; +our $llvm_revision = "123723"; our $llvm_source_dir = "$ENV{SRCROOT}"; our $cc = "$ENV{DEVELOPER_BIN_DIR}/gcc-4.2"; our $cxx = "$ENV{DEVELOPER_BIN_DIR}/g++-4.2"; @@ -74,7 +74,6 @@ "$llvm_configuration/lib/libLLVMScalarOpts.a", "$llvm_configuration/lib/libLLVMSelectionDAG.a", "$llvm_configuration/lib/libLLVMSupport.a", - "$llvm_configuration/lib/libLLVMSystem.a", "$llvm_configuration/lib/libLLVMTarget.a", "$llvm_configuration/lib/libLLVMTransformUtils.a", "$llvm_configuration/lib/libLLVMX86AsmParser.a", @@ -82,7 +81,6 @@ "$llvm_configuration/lib/libLLVMX86CodeGen.a", "$llvm_configuration/lib/libLLVMX86Disassembler.a", "$llvm_configuration/lib/libLLVMX86Info.a", - "$llvm_configuration/lib/libclangChecker.a" ); if (-l $llvm_dstroot) Modified: lldb/trunk/source/Core/FileSpec.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Core/FileSpec.cpp?rev=123787&r1=123786&r2=123787&view=diff ============================================================================== --- lldb/trunk/source/Core/FileSpec.cpp (original) +++ lldb/trunk/source/Core/FileSpec.cpp Tue Jan 18 17:32:05 2011 @@ -499,7 +499,9 @@ { const std::string file_str (m_filename.AsCString()); llvm::sys::Path path = llvm::sys::Program::FindProgramByName (file_str); - llvm::StringRef dir_ref = path.getDirname(); + const std::string &path_str = path.str(); + llvm::StringRef dir_ref = llvm::sys::path::parent_path(path_str); + //llvm::StringRef dir_ref = path.getDirname(); if (! dir_ref.empty()) { // FindProgramByName returns "." if it can't find the file. Modified: lldb/trunk/source/Expression/ClangASTSource.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Expression/ClangASTSource.cpp?rev=123787&r1=123786&r2=123787&view=diff ============================================================================== --- lldb/trunk/source/Expression/ClangASTSource.cpp (original) +++ lldb/trunk/source/Expression/ClangASTSource.cpp Tue Jan 18 17:32:05 2011 @@ -225,16 +225,14 @@ clang::NamedDecl * NameSearchContext::AddGenericFunDecl() { + FunctionProtoType::ExtProtoInfo proto_info; + + proto_info.Variadic = true; + QualType generic_function_type(m_ast_source.m_ast_context.getFunctionType (m_ast_source.m_ast_context.getSizeType(), // result - NULL, // argument types - 0, // number of arguments - true, // variadic? - 0, // type qualifiers - false, // has exception specification? - false, // has any exception specification? - 0, // number of exceptions - NULL, // exceptions - FunctionType::ExtInfo())); // defaults for noreturn, regparm, calling convention + NULL, // argument types + 0, // number of arguments + proto_info)); return AddFunDecl(generic_function_type.getAsOpaquePtr()); } Modified: lldb/trunk/source/Expression/ClangExpressionParser.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Expression/ClangExpressionParser.cpp?rev=123787&r1=123786&r2=123787&view=diff ============================================================================== --- lldb/trunk/source/Expression/ClangExpressionParser.cpp (original) +++ lldb/trunk/source/Expression/ClangExpressionParser.cpp Tue Jan 18 17:32:05 2011 @@ -30,7 +30,6 @@ #include "clang/Basic/FileManager.h" #include "clang/Basic/TargetInfo.h" #include "clang/Basic/Version.h" -#include "clang/Checker/FrontendActions.h" #include "clang/CodeGen/CodeGenAction.h" #include "clang/CodeGen/ModuleBuilder.h" #include "clang/Driver/CC1Options.h" @@ -47,6 +46,7 @@ #include "clang/Parse/ParseAST.h" #include "clang/Rewrite/FrontendActions.h" #include "clang/Sema/SemaConsumer.h" +#include "clang/StaticAnalyzer/FrontendActions.h" #include "llvm/ADT/StringRef.h" #include "llvm/ExecutionEngine/ExecutionEngine.h" @@ -153,7 +153,7 @@ case RewriteMacros: return new RewriteMacrosAction(); case RewriteObjC: return new RewriteObjCAction(); case RewriteTest: return new RewriteTestAction(); - case RunAnalysis: return new AnalysisAction(); + //case RunAnalysis: return new AnalysisAction(); case RunPreprocessorOnly: return new PreprocessOnlyAction(); } } Modified: lldb/trunk/source/Symbol/ClangASTContext.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Symbol/ClangASTContext.cpp?rev=123787&r1=123786&r2=123787&view=diff ============================================================================== --- lldb/trunk/source/Symbol/ClangASTContext.cpp (original) +++ lldb/trunk/source/Symbol/ClangASTContext.cpp Tue Jan 18 17:32:05 2011 @@ -912,7 +912,8 @@ FileSystemOptions file_system_options; FileManager file_manager (file_system_options); ASTImporter importer(*dst_ast, file_manager, - *src_ast, file_manager); + *src_ast, file_manager, + false); QualType src (QualType::getFromOpaquePtr(clang_type)); QualType dst (importer.Import(src)); @@ -929,7 +930,8 @@ FileSystemOptions file_system_options; FileManager file_manager (file_system_options); ASTImporter importer(*dst_ast, file_manager, - *src_ast, file_manager); + *src_ast, file_manager, + false); return importer.Import(source_decl); } @@ -1629,7 +1631,8 @@ is_virtual, base_of_class, ConvertAccessTypeToAccessSpecifier (access), - getASTContext()->CreateTypeSourceInfo (QualType::getFromOpaquePtr(base_class_type))); + getASTContext()->CreateTypeSourceInfo (QualType::getFromOpaquePtr(base_class_type)), + SourceLocation()); return NULL; } @@ -2278,6 +2281,7 @@ case clang::BuiltinType::Bool: case clang::BuiltinType::Char_U: case clang::BuiltinType::UChar: + case clang::BuiltinType::WChar_U: case clang::BuiltinType::Char16: case clang::BuiltinType::Char32: case clang::BuiltinType::UShort: @@ -2287,7 +2291,7 @@ case clang::BuiltinType::UInt128: case clang::BuiltinType::Char_S: case clang::BuiltinType::SChar: - case clang::BuiltinType::WChar: + case clang::BuiltinType::WChar_S: case clang::BuiltinType::Short: case clang::BuiltinType::Int: case clang::BuiltinType::Long: @@ -3562,16 +3566,18 @@ qual_type_args.push_back (QualType::getFromOpaquePtr(args[i])); // TODO: Detect calling convention in DWARF? + FunctionProtoType::ExtProtoInfo proto_info; + proto_info.Variadic = is_variadic; + proto_info.HasExceptionSpec = false; + proto_info.HasAnyExceptionSpec = false; + proto_info.TypeQuals = type_quals; + proto_info.NumExceptions = 0; + proto_info.Exceptions = NULL; + return ast->getFunctionType(QualType::getFromOpaquePtr(result_type), qual_type_args.empty() ? NULL : &qual_type_args.front(), qual_type_args.size(), - is_variadic, - type_quals, - false, // hasExceptionSpec - false, // hasAnyExceptionSpec, - 0, // NumExs - 0, // const QualType *ExArray - FunctionType::ExtInfo ()).getAsOpaquePtr(); // NoReturn); + proto_info).getAsOpaquePtr(); // NoReturn); } ParmVarDecl * Modified: lldb/trunk/source/Symbol/ClangASTType.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Symbol/ClangASTType.cpp?rev=123787&r1=123786&r2=123787&view=diff ============================================================================== --- lldb/trunk/source/Symbol/ClangASTType.cpp (original) +++ lldb/trunk/source/Symbol/ClangASTType.cpp Tue Jan 18 17:32:05 2011 @@ -140,7 +140,7 @@ case clang::BuiltinType::Bool: case clang::BuiltinType::Char_S: case clang::BuiltinType::SChar: - case clang::BuiltinType::WChar: + case clang::BuiltinType::WChar_S: case clang::BuiltinType::Char16: case clang::BuiltinType::Char32: case clang::BuiltinType::Short: @@ -151,6 +151,7 @@ case clang::BuiltinType::Char_U: case clang::BuiltinType::UChar: + case clang::BuiltinType::WChar_U: case clang::BuiltinType::UShort: case clang::BuiltinType::UInt: case clang::BuiltinType::ULong: @@ -249,9 +250,10 @@ case clang::BuiltinType::Bool: return lldb::eFormatBoolean; case clang::BuiltinType::Char_S: case clang::BuiltinType::SChar: + case clang::BuiltinType::WChar_S: case clang::BuiltinType::Char_U: case clang::BuiltinType::UChar: - case clang::BuiltinType::WChar: return lldb::eFormatChar; + case clang::BuiltinType::WChar_U: return lldb::eFormatChar; case clang::BuiltinType::Char16: return lldb::eFormatUnicode16; case clang::BuiltinType::Char32: return lldb::eFormatUnicode32; case clang::BuiltinType::UShort: return lldb::eFormatUnsigned; From gclayton at apple.com Tue Jan 18 18:10:02 2011 From: gclayton at apple.com (Greg Clayton) Date: Tue, 18 Jan 2011 16:10:02 -0800 Subject: [Lldb-commits] [PATCH 0/9] linux: bugfixes, register and unwind support. In-Reply-To: <1295390355-8700-1-git-send-email-wilsons@start.ca> References: <1295390355-8700-1-git-send-email-wilsons@start.ca> Message-ID: <96FBD483-8B8A-4776-B658-5742F0F51B78@apple.com> All patches look good! Nice progress on the linux plug-in. I hope the abstracted LLDB unwinder works well for linux, that is how we tried to design it. Greg On Jan 18, 2011, at 2:39 PM, Stephen Wilson wrote: > This patch series provides a few important bug fixes to the linux process and > dynamic loader plugins. Two new features are implemented as well: improved > support for reading registers and the use of LLDB's unwinder. > > With these patches "basic" debugging scenarios are working on Linux x86_64. For > the most part setting break points, step over/step thru, back traces, frame > variable inspection, and disassemble all appear to work well. > > Although there is still more to do, it is exciting to see LLDB working this well > on Linux! > > > Take care, > > -- > steve > > _______________________________________________ > lldb-commits mailing list > lldb-commits at cs.uiuc.edu > http://lists.cs.uiuc.edu/mailman/listinfo/lldb-commits From johnny.chen at apple.com Tue Jan 18 18:31:52 2011 From: johnny.chen at apple.com (Johnny Chen) Date: Wed, 19 Jan 2011 00:31:52 -0000 Subject: [Lldb-commits] [lldb] r123792 - /lldb/trunk/test/objc-stepping/TestObjCStepping.py Message-ID: <20110119003152.70B4D2A6C12C@llvm.org> Author: johnny Date: Tue Jan 18 18:31:52 2011 New Revision: 123792 URL: http://llvm.org/viewvc/llvm-project?rev=123792&view=rev Log: Decorated two new expected failures: rdar://problem/8875425 Found mySource->isa local variable assertion failed Modified: lldb/trunk/test/objc-stepping/TestObjCStepping.py Modified: lldb/trunk/test/objc-stepping/TestObjCStepping.py URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/objc-stepping/TestObjCStepping.py?rev=123792&r1=123791&r2=123792&view=diff ============================================================================== --- lldb/trunk/test/objc-stepping/TestObjCStepping.py (original) +++ lldb/trunk/test/objc-stepping/TestObjCStepping.py Tue Jan 18 18:31:52 2011 @@ -9,6 +9,8 @@ mydir = "objc-stepping" + # rdar://problem/8875425 Found mySource->isa local variable assertion failed + @unittest2.expectedFailure @unittest2.skipUnless(sys.platform.startswith("darwin"), "requires Darwin") @python_api_test def test_with_dsym_and_python_api(self): @@ -16,6 +18,8 @@ self.buildDsym() self.objc_stepping() + # rdar://problem/8875425 Found mySource->isa local variable assertion failed + @unittest2.expectedFailure @python_api_test def test_with_dwarf_and_python_api(self): """Test stepping through ObjC method dispatch in various forms.""" From wilsons at start.ca Tue Jan 18 19:28:39 2011 From: wilsons at start.ca (Stephen Wilson) Date: Wed, 19 Jan 2011 01:28:39 -0000 Subject: [Lldb-commits] [lldb] r123794 - /lldb/trunk/source/Plugins/DynamicLoader/Linux-DYLD/DYLDRendezvous.cpp Message-ID: <20110119012839.DD9112A6C12C@llvm.org> Author: wilsons Date: Tue Jan 18 19:28:39 2011 New Revision: 123794 URL: http://llvm.org/viewvc/llvm-project?rev=123794&view=rev Log: Load dependent modules in the Linux dynamic loader. This fixes a bug where the dynamic loader rendezvous was not updating its internal state when first initialized. Modified: lldb/trunk/source/Plugins/DynamicLoader/Linux-DYLD/DYLDRendezvous.cpp Modified: lldb/trunk/source/Plugins/DynamicLoader/Linux-DYLD/DYLDRendezvous.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/DynamicLoader/Linux-DYLD/DYLDRendezvous.cpp?rev=123794&r1=123793&r2=123794&view=diff ============================================================================== --- lldb/trunk/source/Plugins/DynamicLoader/Linux-DYLD/DYLDRendezvous.cpp (original) +++ lldb/trunk/source/Plugins/DynamicLoader/Linux-DYLD/DYLDRendezvous.cpp Tue Jan 18 19:28:39 2011 @@ -117,6 +117,12 @@ if (m_current.map_addr == 0) return false; + // When the previous and current states are consistent this is the first + // time we have been asked to update. Just take a snapshot of the currently + // loaded modules. + if (m_previous.state == eConsistent && m_current.state == eConsistent) + return TakeSnapshot(m_soentries); + // If we are about to add or remove a shared object clear out the current // state and take a snapshot of the currently loaded images. if (m_current.state == eAdd || m_current.state == eDelete) @@ -127,6 +133,7 @@ m_removed_soentries.clear(); return TakeSnapshot(m_soentries); } + assert(m_current.state == eConsistent); // Otherwise check the previous state to determine what to expect and update // accordingly. From wilsons at start.ca Tue Jan 18 19:29:39 2011 From: wilsons at start.ca (Stephen Wilson) Date: Wed, 19 Jan 2011 01:29:39 -0000 Subject: [Lldb-commits] [lldb] r123795 - /lldb/trunk/source/Plugins/Process/Linux/ProcessLinux.cpp Message-ID: <20110119012939.7C6662A6C12C@llvm.org> Author: wilsons Date: Tue Jan 18 19:29:39 2011 New Revision: 123795 URL: http://llvm.org/viewvc/llvm-project?rev=123795&view=rev Log: Only enqueue valid ProcessLinux messages. Modified: lldb/trunk/source/Plugins/Process/Linux/ProcessLinux.cpp Modified: lldb/trunk/source/Plugins/Process/Linux/ProcessLinux.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Process/Linux/ProcessLinux.cpp?rev=123795&r1=123794&r2=123795&view=diff ============================================================================== --- lldb/trunk/source/Plugins/Process/Linux/ProcessLinux.cpp (original) +++ lldb/trunk/source/Plugins/Process/Linux/ProcessLinux.cpp Tue Jan 18 19:29:39 2011 @@ -244,7 +244,6 @@ ProcessLinux::SendMessage(const ProcessMessage &message) { Mutex::Locker lock(m_message_mutex); - m_message_queue.push(message); switch (message.GetKind()) { @@ -252,6 +251,9 @@ SetPrivateState(eStateStopped); break; + case ProcessMessage::eInvalidMessage: + return; + case ProcessMessage::eExitMessage: SetExitStatus(message.GetExitStatus(), NULL); break; @@ -260,6 +262,8 @@ SetExitStatus(-1, NULL); break; } + + m_message_queue.push(message); } void From wilsons at start.ca Tue Jan 18 19:30:44 2011 From: wilsons at start.ca (Stephen Wilson) Date: Wed, 19 Jan 2011 01:30:44 -0000 Subject: [Lldb-commits] [lldb] r123796 - /lldb/trunk/source/Plugins/Process/Linux/ProcessLinux.cpp Message-ID: <20110119013044.E65C52A6C12C@llvm.org> Author: wilsons Date: Tue Jan 18 19:30:44 2011 New Revision: 123796 URL: http://llvm.org/viewvc/llvm-project?rev=123796&view=rev Log: Timeout if we fail to receive a state change event when destroying an inferior. Modified: lldb/trunk/source/Plugins/Process/Linux/ProcessLinux.cpp Modified: lldb/trunk/source/Plugins/Process/Linux/ProcessLinux.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Process/Linux/ProcessLinux.cpp?rev=123796&r1=123795&r2=123796&view=diff ============================================================================== --- lldb/trunk/source/Plugins/Process/Linux/ProcessLinux.cpp (original) +++ lldb/trunk/source/Plugins/Process/Linux/ProcessLinux.cpp Tue Jan 18 19:30:44 2011 @@ -223,20 +223,28 @@ return error; } - // Wait for the event to arrive. This guaranteed to be an exit event. + // Wait for the event to arrive. This is guaranteed to be an exit event. StateType state; EventSP event; do { - state = WaitForStateChangedEventsPrivate(NULL, event); - } while (state != eStateExited); + TimeValue timeout_time; + timeout_time = TimeValue::Now(); + timeout_time.OffsetWithSeconds(2); + state = WaitForStateChangedEventsPrivate(&timeout_time, event); + } while (state != eStateExited && state != eStateInvalid); + + // Check if we timed out waiting for the exit event to arrive. + if (state == eStateInvalid) + error.SetErrorString("ProcessLinux::DoDestroy timed out."); // Restart standard event handling and send the process the final kill, // driving it out of limbo. ResumePrivateStateThread(); } - if (kill(m_monitor->GetPID(), SIGKILL)) + if (kill(m_monitor->GetPID(), SIGKILL) && error.Success()) error.SetErrorToErrno(); + return error; } From wilsons at start.ca Tue Jan 18 19:31:38 2011 From: wilsons at start.ca (Stephen Wilson) Date: Wed, 19 Jan 2011 01:31:38 -0000 Subject: [Lldb-commits] [lldb] r123797 - in /lldb/trunk/source/Plugins/Process/Linux: ProcessMonitor.cpp ProcessMonitor.h Message-ID: <20110119013138.701A52A6C12C@llvm.org> Author: wilsons Date: Tue Jan 18 19:31:38 2011 New Revision: 123797 URL: http://llvm.org/viewvc/llvm-project?rev=123797&view=rev Log: Support the reading of registers en masse via the linux ProcessMonitor. Modified: lldb/trunk/source/Plugins/Process/Linux/ProcessMonitor.cpp lldb/trunk/source/Plugins/Process/Linux/ProcessMonitor.h Modified: lldb/trunk/source/Plugins/Process/Linux/ProcessMonitor.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Process/Linux/ProcessMonitor.cpp?rev=123797&r1=123796&r2=123797&view=diff ============================================================================== --- lldb/trunk/source/Plugins/Process/Linux/ProcessMonitor.cpp (original) +++ lldb/trunk/source/Plugins/Process/Linux/ProcessMonitor.cpp Tue Jan 18 19:31:38 2011 @@ -260,6 +260,58 @@ } //------------------------------------------------------------------------------ +/// @class ReadGPROperation +/// @brief Implements ProcessMonitor::ReadGPR. +class ReadGPROperation : public Operation +{ +public: + ReadGPROperation(void *buf, bool &result) + : m_buf(buf), m_result(result) + { } + + void Execute(ProcessMonitor *monitor); + +private: + void *m_buf; + bool &m_result; +}; + +void +ReadGPROperation::Execute(ProcessMonitor *monitor) +{ + if (ptrace(PTRACE_GETREGS, monitor->GetPID(), NULL, m_buf) < 0) + m_result = false; + else + m_result = true; +} + +//------------------------------------------------------------------------------ +/// @class ReadFPROperation +/// @brief Implements ProcessMonitor::ReadFPR. +class ReadFPROperation : public Operation +{ +public: + ReadFPROperation(void *buf, bool &result) + : m_buf(buf), m_result(result) + { } + + void Execute(ProcessMonitor *monitor); + +private: + void *m_buf; + bool &m_result; +}; + +void +ReadFPROperation::Execute(ProcessMonitor *monitor) +{ + if (ptrace(PTRACE_GETFPREGS, monitor->GetPID(), NULL, m_buf) < 0) + m_result = false; + else + m_result = true; +} + +//------------------------------------------------------------------------------ /// @class ResumeOperation /// @brief Implements ProcessMonitor::Resume. class ResumeOperation : public Operation @@ -876,6 +928,24 @@ } bool +ProcessMonitor::ReadGPR(void *buf) +{ + bool result; + ReadGPROperation op(buf, result); + DoOperation(&op); + return result; +} + +bool +ProcessMonitor::ReadFPR(void *buf) +{ + bool result; + ReadFPROperation op(buf, result); + DoOperation(&op); + return result; +} + +bool ProcessMonitor::Resume(lldb::tid_t tid) { bool result; Modified: lldb/trunk/source/Plugins/Process/Linux/ProcessMonitor.h URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Process/Linux/ProcessMonitor.h?rev=123797&r1=123796&r2=123797&view=diff ============================================================================== --- lldb/trunk/source/Plugins/Process/Linux/ProcessMonitor.h (original) +++ lldb/trunk/source/Plugins/Process/Linux/ProcessMonitor.h Tue Jan 18 19:31:38 2011 @@ -108,6 +108,14 @@ bool WriteRegisterValue(unsigned offset, const lldb_private::Scalar &value); + /// Reads all general purpose registers into the specified buffer. + bool + ReadGPR(void *buf); + + /// Reads all floating point registers into the specified buffer. + bool + ReadFPR(void *buf); + /// Writes a siginfo_t structure corresponding to the given thread ID to the /// memory region pointed to by @p siginfo. bool From wilsons at start.ca Tue Jan 18 19:32:28 2011 From: wilsons at start.ca (Stephen Wilson) Date: Wed, 19 Jan 2011 01:32:28 -0000 Subject: [Lldb-commits] [lldb] r123798 - in /lldb/trunk/source/Plugins/Process/Linux: RegisterContextLinux_x86_64.cpp RegisterContextLinux_x86_64.h Message-ID: <20110119013228.7F59E2A6C12C@llvm.org> Author: wilsons Date: Tue Jan 18 19:32:28 2011 New Revision: 123798 URL: http://llvm.org/viewvc/llvm-project?rev=123798&view=rev Log: Implement RegisterContextLinux_x86_64::ReadRegisterBytes. Also, this patch adds a few delimiters to the register enumeration to enable efficient testing of register set inclusion. Modified: lldb/trunk/source/Plugins/Process/Linux/RegisterContextLinux_x86_64.cpp lldb/trunk/source/Plugins/Process/Linux/RegisterContextLinux_x86_64.h Modified: lldb/trunk/source/Plugins/Process/Linux/RegisterContextLinux_x86_64.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Process/Linux/RegisterContextLinux_x86_64.cpp?rev=123798&r1=123797&r2=123798&view=diff ============================================================================== --- lldb/trunk/source/Plugins/Process/Linux/RegisterContextLinux_x86_64.cpp (original) +++ lldb/trunk/source/Plugins/Process/Linux/RegisterContextLinux_x86_64.cpp Tue Jan 18 19:32:28 2011 @@ -11,6 +11,7 @@ #include #include +#include "lldb/Core/DataExtractor.h" #include "lldb/Core/Scalar.h" #include "lldb/Target/Thread.h" @@ -24,7 +25,8 @@ // Internal codes for all x86_64 registers. enum { - gpr_rax = 0, + k_first_gpr, + gpr_rax = k_first_gpr, gpr_rbx, gpr_rcx, gpr_rdx, @@ -48,11 +50,10 @@ gpr_ss, gpr_ds, gpr_es, + k_last_gpr = gpr_es, - // Number of GPR's. - k_num_gpr_registers, - - fpu_fcw = k_num_gpr_registers, + k_first_fpr, + fpu_fcw = k_first_fpr, fpu_fsw, fpu_ftw, fpu_fop, @@ -86,12 +87,11 @@ fpu_xmm13, fpu_xmm14, fpu_xmm15, + k_last_fpr = fpu_xmm15, - // Total number of registers. k_num_registers, - - // Number of FPR's. - k_num_fpu_registers = k_num_registers - k_num_gpr_registers + k_num_gpr_registers = k_last_gpr - k_first_gpr + 1, + k_num_fpu_registers = k_last_fpr - k_first_fpr + 1 }; // Number of register sets provided by this context. @@ -401,6 +401,22 @@ return g_register_infos[reg].byte_offset; } +static unsigned GetRegSize(unsigned reg) +{ + assert(reg < k_num_registers && "Invalid register number."); + return g_register_infos[reg].byte_size; +} + +static bool IsGPR(unsigned reg) +{ + return reg <= k_last_gpr; // GPR's come first. +} + +static bool IsFPR(unsigned reg) +{ + return (k_first_fpr <= reg && reg <= k_last_fpr); +} + RegisterContextLinux_x86_64::RegisterContextLinux_x86_64(Thread &thread, uint32_t concrete_frame_idx) : RegisterContextLinux(thread, concrete_frame_idx) @@ -470,7 +486,23 @@ RegisterContextLinux_x86_64::ReadRegisterBytes(uint32_t reg, DataExtractor &data) { - return false; + uint8_t *buf = reinterpret_cast(&user); + bool status; + + if (IsGPR(reg)) + status = ReadGPR(); + else if (IsFPR(reg)) + status = ReadFPR(); + else + { + assert(false && "invalid register number"); + status = false; + } + + if (status) + data.SetData(buf + GetRegOffset(reg), GetRegSize(reg), eByteOrderHost); + + return status; } bool @@ -660,3 +692,17 @@ { return GetMonitor().SingleStep(GetThreadID()); } + +bool +RegisterContextLinux_x86_64::ReadGPR() +{ + ProcessMonitor &monitor = GetMonitor(); + return monitor.ReadGPR(&user.regs); +} + +bool +RegisterContextLinux_x86_64::ReadFPR() +{ + ProcessMonitor &monitor = GetMonitor(); + return monitor.ReadFPR(&user.i387); +} Modified: lldb/trunk/source/Plugins/Process/Linux/RegisterContextLinux_x86_64.h URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Process/Linux/RegisterContextLinux_x86_64.h?rev=123798&r1=123797&r2=123798&view=diff ============================================================================== --- lldb/trunk/source/Plugins/Process/Linux/RegisterContextLinux_x86_64.h (original) +++ lldb/trunk/source/Plugins/Process/Linux/RegisterContextLinux_x86_64.h Tue Jan 18 19:32:28 2011 @@ -153,6 +153,9 @@ UserArea user; ProcessMonitor &GetMonitor(); + + bool ReadGPR(); + bool ReadFPR(); }; #endif // #ifndef liblldb_RegisterContextLinux_x86_64_H_ From wilsons at start.ca Tue Jan 18 19:33:33 2011 From: wilsons at start.ca (Stephen Wilson) Date: Wed, 19 Jan 2011 01:33:33 -0000 Subject: [Lldb-commits] [lldb] r123799 - /lldb/trunk/source/Plugins/Process/Linux/RegisterContextLinux_x86_64.cpp Message-ID: <20110119013333.B53A12A6C12C@llvm.org> Author: wilsons Date: Tue Jan 18 19:33:33 2011 New Revision: 123799 URL: http://llvm.org/viewvc/llvm-project?rev=123799&view=rev Log: Fix implementation of LinuxThread::HardwareSingleStep. Previous version simply resumed the associated thread to single step over a single instruction which is not the intended semantics for this method. Set the appropriate bit in the rflags register instead. Modified: lldb/trunk/source/Plugins/Process/Linux/RegisterContextLinux_x86_64.cpp Modified: lldb/trunk/source/Plugins/Process/Linux/RegisterContextLinux_x86_64.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Process/Linux/RegisterContextLinux_x86_64.cpp?rev=123799&r1=123798&r2=123799&view=diff ============================================================================== --- lldb/trunk/source/Plugins/Process/Linux/RegisterContextLinux_x86_64.cpp (original) +++ lldb/trunk/source/Plugins/Process/Linux/RegisterContextLinux_x86_64.cpp Tue Jan 18 19:33:33 2011 @@ -690,7 +690,28 @@ bool RegisterContextLinux_x86_64::HardwareSingleStep(bool enable) { - return GetMonitor().SingleStep(GetThreadID()); + enum { TRACE_BIT = 0x100 }; + uint64_t rflags; + + if ((rflags = ReadRegisterAsUnsigned(gpr_rflags, -1UL)) == -1UL) + return false; + + if (enable) + { + if (rflags & TRACE_BIT) + return true; + + rflags |= TRACE_BIT; + } + else + { + if (!(rflags & TRACE_BIT)) + return false; + + rflags &= ~TRACE_BIT; + } + + return WriteRegisterFromUnsigned(gpr_rflags, rflags); } bool From wilsons at start.ca Tue Jan 18 19:35:00 2011 From: wilsons at start.ca (Stephen Wilson) Date: Wed, 19 Jan 2011 01:35:00 -0000 Subject: [Lldb-commits] [lldb] r123800 - /lldb/trunk/source/Plugins/Process/Linux/LinuxThread.cpp Message-ID: <20110119013500.492792A6C12C@llvm.org> Author: wilsons Date: Tue Jan 18 19:35:00 2011 New Revision: 123800 URL: http://llvm.org/viewvc/llvm-project?rev=123800&view=rev Log: Do not enable hardware stepping when resuming a step-enabled thread. The previous implementation of HardwareSingleStep wrongly resumed the thread and single-stepped over the next instruction. Use the proper call to ProcessMonitor. Modified: lldb/trunk/source/Plugins/Process/Linux/LinuxThread.cpp Modified: lldb/trunk/source/Plugins/Process/Linux/LinuxThread.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Process/Linux/LinuxThread.cpp?rev=123800&r1=123799&r2=123800&view=diff ============================================================================== --- lldb/trunk/source/Plugins/Process/Linux/LinuxThread.cpp (original) +++ lldb/trunk/source/Plugins/Process/Linux/LinuxThread.cpp Tue Jan 18 19:35:00 2011 @@ -153,7 +153,7 @@ case lldb::eStateStepping: SetState(resume_state); - status = GetRegisterContext()->HardwareSingleStep(true); + status = monitor.SingleStep(GetID()); break; } From wilsons at start.ca Tue Jan 18 19:36:10 2011 From: wilsons at start.ca (Stephen Wilson) Date: Wed, 19 Jan 2011 01:36:10 -0000 Subject: [Lldb-commits] [lldb] r123801 - in /lldb/trunk/source/Plugins/Process/Linux: LinuxThread.cpp Makefile Message-ID: <20110119013610.654352A6C12C@llvm.org> Author: wilsons Date: Tue Jan 18 19:36:10 2011 New Revision: 123801 URL: http://llvm.org/viewvc/llvm-project?rev=123801&view=rev Log: Make LinuxThread use the LLDB unwinder. Modified: lldb/trunk/source/Plugins/Process/Linux/LinuxThread.cpp lldb/trunk/source/Plugins/Process/Linux/Makefile Modified: lldb/trunk/source/Plugins/Process/Linux/LinuxThread.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Process/Linux/LinuxThread.cpp?rev=123801&r1=123800&r2=123801&view=diff ============================================================================== --- lldb/trunk/source/Plugins/Process/Linux/LinuxThread.cpp (original) +++ lldb/trunk/source/Plugins/Process/Linux/LinuxThread.cpp Tue Jan 18 19:36:10 2011 @@ -7,9 +7,9 @@ // //===----------------------------------------------------------------------===// +// C Includes #include -// C Includes // C++ Includes // Other libraries and framework includes #include "lldb/Target/Process.h" @@ -20,6 +20,7 @@ #include "ProcessLinux.h" #include "ProcessMonitor.h" #include "RegisterContextLinux_x86_64.h" +#include "UnwindLLDB.h" using namespace lldb_private; @@ -91,17 +92,19 @@ } lldb::RegisterContextSP -LinuxThread::CreateRegisterContextForFrame (lldb_private::StackFrame *frame) +LinuxThread::CreateRegisterContextForFrame(lldb_private::StackFrame *frame) { lldb::RegisterContextSP reg_ctx_sp; uint32_t concrete_frame_idx = 0; + if (frame) concrete_frame_idx = frame->GetConcreteFrameIndex(); if (concrete_frame_idx == 0) reg_ctx_sp = GetRegisterContext(); else - reg_ctx_sp.reset (new RegisterContextLinux_x86_64(*this, frame->GetConcreteFrameIndex())); + reg_ctx_sp = GetUnwinder()->CreateRegisterContextForFrame(frame); + return reg_ctx_sp; } @@ -118,6 +121,9 @@ Unwind * LinuxThread::GetUnwinder() { + if (m_unwinder_ap.get() == NULL) + m_unwinder_ap.reset(new UnwindLLDB(*this)); + return m_unwinder_ap.get(); } @@ -125,6 +131,11 @@ LinuxThread::WillResume(lldb::StateType resume_state) { SetResumeState(resume_state); + + ClearStackFrames(); + if (m_unwinder_ap.get()) + m_unwinder_ap->Clear(); + return Thread::WillResume(resume_state); } Modified: lldb/trunk/source/Plugins/Process/Linux/Makefile URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Process/Linux/Makefile?rev=123801&r1=123800&r2=123801&view=diff ============================================================================== --- lldb/trunk/source/Plugins/Process/Linux/Makefile (original) +++ lldb/trunk/source/Plugins/Process/Linux/Makefile Tue Jan 18 19:36:10 2011 @@ -11,4 +11,7 @@ LIBRARYNAME := lldbPluginProcessLinux BUILD_ARCHIVE = 1 +# Extend the include path so we may locate UnwindLLDB.h +CPPFLAGS += -I $(LLDB_LEVEL)/source/Plugins/Utility + include $(LLDB_LEVEL)/Makefile From wilsons at start.ca Tue Jan 18 19:37:06 2011 From: wilsons at start.ca (Stephen Wilson) Date: Wed, 19 Jan 2011 01:37:06 -0000 Subject: [Lldb-commits] [lldb] r123803 - in /lldb/trunk/source/Plugins/Process/Linux: ProcessMonitor.cpp ProcessMonitor.h Message-ID: <20110119013706.A2B0D2A6C12C@llvm.org> Author: wilsons Date: Tue Jan 18 19:37:06 2011 New Revision: 123803 URL: http://llvm.org/viewvc/llvm-project?rev=123803&view=rev Log: Delay sync with the parent thread in ProcessLinux/ProcessMonitor. This patch removes a potential race condition between a process monitor thread and its parent waiting to interrogate the success/failure of the launch. Modified: lldb/trunk/source/Plugins/Process/Linux/ProcessMonitor.cpp lldb/trunk/source/Plugins/Process/Linux/ProcessMonitor.h Modified: lldb/trunk/source/Plugins/Process/Linux/ProcessMonitor.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Process/Linux/ProcessMonitor.cpp?rev=123803&r1=123802&r2=123803&view=diff ============================================================================== --- lldb/trunk/source/Plugins/Process/Linux/ProcessMonitor.cpp (original) +++ lldb/trunk/source/Plugins/Process/Linux/ProcessMonitor.cpp Tue Jan 18 19:37:06 2011 @@ -607,7 +607,7 @@ if (!Launch(args)) return NULL; - ServeOperation(args->m_monitor); + ServeOperation(args); return NULL; } @@ -716,8 +716,6 @@ process.SendMessage(ProcessMessage::Trace(pid)); FINISH: - // Sync with our parent thread now that the launch operation is complete. - sem_post(&args->m_semaphore); return args->m_error.Success(); } @@ -819,15 +817,20 @@ } void -ProcessMonitor::ServeOperation(ProcessMonitor *monitor) +ProcessMonitor::ServeOperation(LaunchArgs *args) { int status; pollfd fdset; + ProcessMonitor *monitor = args->m_monitor; fdset.fd = monitor->m_server_fd; fdset.events = POLLIN | POLLPRI; fdset.revents = 0; + // We are finised with the arguments and are ready to go. Sync with the + // parent thread and start serving operations on the inferior. + sem_post(&args->m_semaphore); + for (;;) { if ((status = poll(&fdset, 1, -1)) < 0) Modified: lldb/trunk/source/Plugins/Process/Linux/ProcessMonitor.h URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Process/Linux/ProcessMonitor.h?rev=123803&r1=123802&r2=123803&view=diff ============================================================================== --- lldb/trunk/source/Plugins/Process/Linux/ProcessMonitor.h (original) +++ lldb/trunk/source/Plugins/Process/Linux/ProcessMonitor.h Tue Jan 18 19:37:06 2011 @@ -197,7 +197,7 @@ EnableIPC(); static void - ServeOperation(ProcessMonitor *monitor); + ServeOperation(LaunchArgs *args); static bool DupDescriptor(const char *path, int fd, int flags); From johnny.chen at apple.com Tue Jan 18 20:02:09 2011 From: johnny.chen at apple.com (Johnny Chen) Date: Wed, 19 Jan 2011 02:02:09 -0000 Subject: [Lldb-commits] [lldb] r123806 - /lldb/trunk/test/lldbtest.py Message-ID: <20110119020209.2314A2A6C12C@llvm.org> Author: johnny Date: Tue Jan 18 20:02:08 2011 New Revision: 123806 URL: http://llvm.org/viewvc/llvm-project?rev=123806&view=rev Log: The test suite was unnecessarily doing a time.sleep() after performing the "process launch" or "run" interpreter command. Let's do the sleep only if the process launch failed. This saves about 135 seconds from the whole test suite run time. Modified: lldb/trunk/test/lldbtest.py Modified: lldb/trunk/test/lldbtest.py URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/lldbtest.py?rev=123806&r1=123805&r2=123806&view=diff ============================================================================== --- lldb/trunk/test/lldbtest.py (original) +++ lldb/trunk/test/lldbtest.py Tue Jan 18 20:02:08 2011 @@ -701,13 +701,11 @@ print >> sbuf, "runCmd failed!" print >> sbuf, self.res.GetError() - if running: - # For process launch, wait some time before possible next try. - time.sleep(self.timeWaitNextLaunch) - if self.res.Succeeded(): break elif running: + # For process launch, wait some time before possible next try. + time.sleep(self.timeWaitNextLaunch) with recording(self, True) as sbuf: print >> sbuf, "Command '" + cmd + "' failed!" From johnny.chen at apple.com Tue Jan 18 20:10:40 2011 From: johnny.chen at apple.com (Johnny Chen) Date: Wed, 19 Jan 2011 02:10:40 -0000 Subject: [Lldb-commits] [lldb] r123807 - in /lldb/trunk/test: README-TestSuite dotest.py Message-ID: <20110119021040.C9E442A6C12C@llvm.org> Author: johnny Date: Tue Jan 18 20:10:40 2011 New Revision: 123807 URL: http://llvm.org/viewvc/llvm-project?rev=123807&view=rev Log: Added special logic to faciliate profiling the test suite run with the cProfile.py module. On my MBP running SnowLeopard: $ DOTEST_PROFILE=YES DOTEST_SCRIPT_DIR=/Volumes/data/lldb/svn/trunk/test /System/Library/Frameworks/Python.framework/Versions/Current/lib/python2.6/cProfile.py -o my.profile ./dotest.py -v -w 2> ~/Developer/Log/lldbtest.log After that, I used the pstats.py module to browse the statistics recorded in the my.profile file. Modified: lldb/trunk/test/README-TestSuite lldb/trunk/test/dotest.py Modified: lldb/trunk/test/README-TestSuite URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/README-TestSuite?rev=123807&r1=123806&r2=123807&view=diff ============================================================================== --- lldb/trunk/test/README-TestSuite (original) +++ lldb/trunk/test/README-TestSuite Tue Jan 18 20:10:40 2011 @@ -90,3 +90,12 @@ suite become more reliable, we don't expect to be using 'dotest.pl' anymore. Note: dotest.pl has been moved to the attic directory. + +o Profiling dotest.py runs + + I used the following command line thingy to do the profiling on a SnowLeopard + machine: + +$ DOTEST_PROFILE=YES DOTEST_SCRIPT_DIR=/Volumes/data/lldb/svn/trunk/test /System/Library/Frameworks/Python.framework/Versions/Current/lib/python2.6/cProfile.py -o my.profile ./dotest.py -v -w 2> ~/Developer/Log/lldbtest.log + + After that, I used the pstats.py module to browse the statistics. Modified: lldb/trunk/test/dotest.py URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/dotest.py?rev=123807&r1=123806&r2=123807&view=diff ============================================================================== --- lldb/trunk/test/dotest.py (original) +++ lldb/trunk/test/dotest.py Tue Jan 18 20:10:40 2011 @@ -439,7 +439,10 @@ global testdirs # Get the directory containing the current script. - scriptPath = sys.path[0] + if "DOTEST_PROFILE" in os.environ and "DOTEST_SCRIPT_DIR" in os.environ: + scriptPath = os.environ["DOTEST_SCRIPT_DIR"] + else: + scriptPath = sys.path[0] if not scriptPath.endswith('test'): print "This script expects to reside in lldb's test directory." sys.exit(-1) From gclayton at apple.com Wed Jan 19 01:54:15 2011 From: gclayton at apple.com (Greg Clayton) Date: Wed, 19 Jan 2011 07:54:15 -0000 Subject: [Lldb-commits] [lldb] r123815 - in /lldb/trunk: source/Expression/ClangUserExpression.cpp tools/debugserver/source/DNBBreakpoint.cpp tools/debugserver/source/MacOSX/MachProcess.cpp tools/debugserver/source/MacOSX/MachProcess.h tools/debugserver/source/MacOSX/MachThread.cpp tools/debugserver/source/MacOSX/MachThreadList.cpp tools/debugserver/source/MacOSX/MachThreadList.h tools/debugserver/source/MacOSX/x86_64/DNBArchImplX86_64.cpp tools/debugserver/source/RNBRemote.cpp Message-ID: <20110119075415.9371A2A6C12C@llvm.org> Author: gclayton Date: Wed Jan 19 01:54:15 2011 New Revision: 123815 URL: http://llvm.org/viewvc/llvm-project?rev=123815&view=rev Log: Took the timeout for a ClangUserExpression down from a 10 second timeout to 500 ms. Make MachThreadList more threadsafe. Added code to make sure the thread register state was properly flushed for x86_64. Fixed an missing return code for the current thread in the new thread suffix code. Improved debugserver logging. Modified: lldb/trunk/source/Expression/ClangUserExpression.cpp lldb/trunk/tools/debugserver/source/DNBBreakpoint.cpp lldb/trunk/tools/debugserver/source/MacOSX/MachProcess.cpp lldb/trunk/tools/debugserver/source/MacOSX/MachProcess.h lldb/trunk/tools/debugserver/source/MacOSX/MachThread.cpp lldb/trunk/tools/debugserver/source/MacOSX/MachThreadList.cpp lldb/trunk/tools/debugserver/source/MacOSX/MachThreadList.h lldb/trunk/tools/debugserver/source/MacOSX/x86_64/DNBArchImplX86_64.cpp lldb/trunk/tools/debugserver/source/RNBRemote.cpp Modified: lldb/trunk/source/Expression/ClangUserExpression.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Expression/ClangUserExpression.cpp?rev=123815&r1=123814&r2=123815&view=diff ============================================================================== --- lldb/trunk/source/Expression/ClangUserExpression.cpp (original) +++ lldb/trunk/source/Expression/ClangUserExpression.cpp Wed Jan 19 01:54:15 2011 @@ -512,7 +512,7 @@ call_plan_sp->SetPrivate(true); - uint32_t single_thread_timeout_usec = 10000000; + uint32_t single_thread_timeout_usec = 500000; if (log) log->Printf("-- [ClangUserExpression::Execute] Execution of expression begins --"); Modified: lldb/trunk/tools/debugserver/source/DNBBreakpoint.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/tools/debugserver/source/DNBBreakpoint.cpp?rev=123815&r1=123814&r2=123815&view=diff ============================================================================== --- lldb/trunk/tools/debugserver/source/DNBBreakpoint.cpp (original) +++ lldb/trunk/tools/debugserver/source/DNBBreakpoint.cpp Wed Jan 19 01:54:15 2011 @@ -148,10 +148,10 @@ DNBBreakpoint *bp = FindByAddress (addr); if (bp) { - DNBLogThreadedIf(LOG_BREAKPOINTS, "DNBBreakpointList::%s ( addr = 0x%8.8llx ) => %u", __FUNCTION__, (uint64_t)addr, bp->GetID()); + DNBLogThreadedIf(LOG_BREAKPOINTS, "DNBBreakpointList::%s ( addr = 0x%16.16llx ) => %u", __FUNCTION__, (uint64_t)addr, bp->GetID()); return bp->GetID(); } - DNBLogThreadedIf(LOG_BREAKPOINTS, "DNBBreakpointList::%s ( addr = 0x%8.8llx ) => NONE", __FUNCTION__, (uint64_t)addr); + DNBLogThreadedIf(LOG_BREAKPOINTS, "DNBBreakpointList::%s ( addr = 0x%16.16llx ) => NONE", __FUNCTION__, (uint64_t)addr); return INVALID_NUB_BREAK_ID; } Modified: lldb/trunk/tools/debugserver/source/MacOSX/MachProcess.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/tools/debugserver/source/MacOSX/MachProcess.cpp?rev=123815&r1=123814&r2=123815&view=diff ============================================================================== --- lldb/trunk/tools/debugserver/source/MacOSX/MachProcess.cpp (original) +++ lldb/trunk/tools/debugserver/source/MacOSX/MachProcess.cpp Wed Jan 19 01:54:15 2011 @@ -170,12 +170,6 @@ return m_thread_list.ThreadIDAtIndex(thread_idx); } -uint32_t -MachProcess::GetThreadIndexFromThreadID (nub_thread_t tid) -{ - return m_thread_list.GetThreadIndexByID(tid); -} - nub_thread_t MachProcess::GetCurrentThread () { @@ -207,12 +201,12 @@ } const DNBRegisterSetInfo * -MachProcess::GetRegisterSetInfo(nub_thread_t tid, nub_size_t *num_reg_sets ) const +MachProcess::GetRegisterSetInfo (nub_thread_t tid, nub_size_t *num_reg_sets) const { - MachThread *thread = m_thread_list.GetThreadByID (tid); - if (thread) + MachThreadSP thread_sp (m_thread_list.GetThreadByID (tid)); + if (thread_sp) { - DNBArchProtocol *arch = thread->GetArchProtocol(); + DNBArchProtocol *arch = thread_sp->GetArchProtocol(); if (arch) return arch->GetRegisterSetInfo (num_reg_sets); } Modified: lldb/trunk/tools/debugserver/source/MacOSX/MachProcess.h URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/tools/debugserver/source/MacOSX/MachProcess.h?rev=123815&r1=123814&r2=123815&view=diff ============================================================================== --- lldb/trunk/tools/debugserver/source/MacOSX/MachProcess.h (original) +++ lldb/trunk/tools/debugserver/source/MacOSX/MachProcess.h Wed Jan 19 01:54:15 2011 @@ -139,7 +139,6 @@ nub_state_t ThreadGetState (nub_thread_t tid); nub_size_t GetNumThreads () const; nub_thread_t GetThreadAtIndex (nub_size_t thread_idx) const; - uint32_t GetThreadIndexFromThreadID (nub_thread_t tid); nub_thread_t GetCurrentThread (); nub_thread_t SetCurrentThread (nub_thread_t tid); MachThreadList & GetThreadList() { return m_thread_list; } Modified: lldb/trunk/tools/debugserver/source/MacOSX/MachThread.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/tools/debugserver/source/MacOSX/MachThread.cpp?rev=123815&r1=123814&r2=123815&view=diff ============================================================================== --- lldb/trunk/tools/debugserver/source/MacOSX/MachThread.cpp (original) +++ lldb/trunk/tools/debugserver/source/MacOSX/MachThread.cpp Wed Jan 19 01:54:15 2011 @@ -297,14 +297,14 @@ default: thread_run_state = "???"; break; } - DNBLogThreaded("thread[%u] %4.4x (%u): pc: 0x%8.8llx sp: 0x%8.8llx breakID: %d user: %d.%06.6d system: %d.%06.6d cpu: %d policy: %d run_state: %d (%s) flags: %d suspend_count: %d (current %d) sleep_time: %d", + DNBLogThreaded("[%3u] #%3u tid: 0x%4.4x, pc: 0x%16.16llx, sp: 0x%16.16llx, breakID: %3d, user: %d.%06.6d, system: %d.%06.6d, cpu: %2d, policy: %2d, run_state: %2d (%s), flags: %2d, suspend_count: %2d (current %2d), sleep_time: %d", index, - m_tid, m_seq_id, + m_tid, GetPC(INVALID_NUB_ADDRESS), GetSP(INVALID_NUB_ADDRESS), m_breakID, - m_basicInfo.user_time.seconds, m_basicInfo.user_time.microseconds, + m_basicInfo.user_time.seconds, m_basicInfo.user_time.microseconds, m_basicInfo.system_time.seconds, m_basicInfo.system_time.microseconds, m_basicInfo.cpu_usage, m_basicInfo.policy, Modified: lldb/trunk/tools/debugserver/source/MacOSX/MachThreadList.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/tools/debugserver/source/MacOSX/MachThreadList.cpp?rev=123815&r1=123814&r2=123815&view=diff ============================================================================== --- lldb/trunk/tools/debugserver/source/MacOSX/MachThreadList.cpp (original) +++ lldb/trunk/tools/debugserver/source/MacOSX/MachThreadList.cpp Wed Jan 19 01:54:15 2011 @@ -29,47 +29,33 @@ { } -// Not thread safe, must lock m_threads_mutex prior to using this function. -uint32_t -MachThreadList::GetThreadIndexByID(thread_t tid) const -{ - uint32_t idx = 0; - const uint32_t num_threads = m_threads.size(); - for (idx = 0; idx < num_threads; ++idx) - { - if (m_threads[idx]->ThreadID() == tid) - return idx; - } - return ~((uint32_t)0); -} - nub_state_t MachThreadList::GetState(thread_t tid) { - uint32_t idx = GetThreadIndexByID(tid); - if (idx < m_threads.size()) - return m_threads[idx]->GetState(); + MachThreadSP thread_sp (GetThreadByID (tid)); + if (thread_sp) + return thread_sp->GetState(); return eStateInvalid; } const char * MachThreadList::GetName (thread_t tid) { - uint32_t idx = GetThreadIndexByID(tid); - if (idx < m_threads.size()) - return m_threads[idx]->GetName(); + MachThreadSP thread_sp (GetThreadByID (tid)); + if (thread_sp) + return thread_sp->GetName(); return NULL; } nub_thread_t MachThreadList::SetCurrentThread(thread_t tid) { - uint32_t idx = GetThreadIndexByID(tid); - if (idx < m_threads.size()) - m_current_thread = m_threads[idx]; - - if (m_current_thread.get()) - return m_current_thread->ThreadID(); + MachThreadSP thread_sp (GetThreadByID (tid)); + if (thread_sp) + { + m_current_thread = thread_sp; + return tid; + } return INVALID_NUB_THREAD; } @@ -77,9 +63,9 @@ bool MachThreadList::GetThreadStoppedReason(nub_thread_t tid, struct DNBThreadStopInfo *stop_info) const { - uint32_t idx = GetThreadIndexByID(tid); - if (idx < m_threads.size()) - return m_threads[idx]->GetStopException().GetStopInfo(stop_info); + MachThreadSP thread_sp (GetThreadByID (tid)); + if (thread_sp) + return thread_sp->GetStopException().GetStopInfo(stop_info); return false; } @@ -91,37 +77,45 @@ } void -MachThreadList::DumpThreadStoppedReason(nub_thread_t tid) const +MachThreadList::DumpThreadStoppedReason (nub_thread_t tid) const { - uint32_t idx = GetThreadIndexByID(tid); - if (idx < m_threads.size()) - m_threads[idx]->GetStopException().DumpStopReason(); + MachThreadSP thread_sp (GetThreadByID (tid)); + if (thread_sp) + thread_sp->GetStopException().DumpStopReason(); } const char * -MachThreadList::GetThreadInfo(nub_thread_t tid) const +MachThreadList::GetThreadInfo (nub_thread_t tid) const { - uint32_t idx = GetThreadIndexByID(tid); - if (idx < m_threads.size()) - return m_threads[idx]->GetBasicInfoAsString(); + MachThreadSP thread_sp (GetThreadByID (tid)); + if (thread_sp) + return thread_sp->GetBasicInfoAsString(); return NULL; } -MachThread * +MachThreadSP MachThreadList::GetThreadByID (nub_thread_t tid) const { - uint32_t idx = GetThreadIndexByID(tid); - if (idx < m_threads.size()) - return m_threads[idx].get(); - return NULL; + PTHREAD_MUTEX_LOCKER (locker, m_threads_mutex); + MachThreadSP thread_sp; + const size_t num_threads = m_threads.size(); + for (size_t idx = 0; idx < num_threads; ++idx) + { + if (m_threads[idx]->ThreadID() == tid) + { + thread_sp = m_threads[idx]; + break; + } + } + return thread_sp; } bool MachThreadList::GetRegisterValue ( nub_thread_t tid, uint32_t reg_set_idx, uint32_t reg_idx, DNBRegisterValue *reg_value ) const { - uint32_t idx = GetThreadIndexByID(tid); - if (idx < m_threads.size()) - return m_threads[idx]->GetRegisterValue(reg_set_idx, reg_idx, reg_value); + MachThreadSP thread_sp (GetThreadByID (tid)); + if (thread_sp) + return thread_sp->GetRegisterValue(reg_set_idx, reg_idx, reg_value); return false; } @@ -129,9 +123,9 @@ bool MachThreadList::SetRegisterValue ( nub_thread_t tid, uint32_t reg_set_idx, uint32_t reg_idx, const DNBRegisterValue *reg_value ) const { - uint32_t idx = GetThreadIndexByID(tid); - if (idx < m_threads.size()) - return m_threads[idx]->SetRegisterValue(reg_set_idx, reg_idx, reg_value); + MachThreadSP thread_sp (GetThreadByID (tid)); + if (thread_sp) + return thread_sp->SetRegisterValue(reg_set_idx, reg_idx, reg_value); return false; } @@ -139,30 +133,32 @@ nub_size_t MachThreadList::GetRegisterContext (nub_thread_t tid, void *buf, size_t buf_len) { - uint32_t idx = GetThreadIndexByID(tid); - if (idx < m_threads.size()) - return m_threads[idx]->GetRegisterContext (buf, buf_len); + MachThreadSP thread_sp (GetThreadByID (tid)); + if (thread_sp) + return thread_sp->GetRegisterContext (buf, buf_len); return 0; } nub_size_t MachThreadList::SetRegisterContext (nub_thread_t tid, const void *buf, size_t buf_len) { - uint32_t idx = GetThreadIndexByID(tid); - if (idx < m_threads.size()) - return m_threads[idx]->SetRegisterContext (buf, buf_len); + MachThreadSP thread_sp (GetThreadByID (tid)); + if (thread_sp) + return thread_sp->SetRegisterContext (buf, buf_len); return 0; } nub_size_t -MachThreadList::NumThreads() const +MachThreadList::NumThreads () const { + PTHREAD_MUTEX_LOCKER (locker, m_threads_mutex); return m_threads.size(); } nub_thread_t -MachThreadList::ThreadIDAtIndex(nub_size_t idx) const +MachThreadList::ThreadIDAtIndex (nub_size_t idx) const { + PTHREAD_MUTEX_LOCKER (locker, m_threads_mutex); if (idx < m_threads.size()) return m_threads[idx]->ThreadID(); return INVALID_NUB_THREAD; @@ -171,42 +167,29 @@ nub_thread_t MachThreadList::CurrentThreadID ( ) { - MachThreadSP threadSP; - CurrentThread(threadSP); - if (threadSP.get()) - return threadSP->ThreadID(); + MachThreadSP thread_sp; + CurrentThread(thread_sp); + if (thread_sp.get()) + return thread_sp->ThreadID(); return INVALID_NUB_THREAD; } bool MachThreadList::NotifyException(MachException::Data& exc) { - uint32_t idx = GetThreadIndexByID(exc.thread_port); - if (idx < m_threads.size()) + MachThreadSP thread_sp (GetThreadByID (exc.thread_port)); + if (thread_sp) { - m_threads[idx]->NotifyException(exc); + thread_sp->NotifyException(exc); return true; } return false; } -/* -MachThreadList::const_iterator -MachThreadList::FindThreadByID(thread_t tid) const -{ - const_iterator pos; - const_iterator end = m_threads.end(); - for (pos = m_threads.begin(); pos != end; ++pos) - { - if (pos->ThreadID() == tid) - return pos; - } - return NULL; -} -*/ void MachThreadList::Clear() { + PTHREAD_MUTEX_LOCKER (locker, m_threads_mutex); m_threads.clear(); } @@ -249,29 +232,28 @@ if (err.Error() == KERN_SUCCESS && thread_list_count > 0) { MachThreadList::collection currThreads; - const size_t numOldThreads = m_threads.size(); size_t idx; // Iterator through the current thread list and see which threads // we already have in our list (keep them), which ones we don't // (add them), and which ones are not around anymore (remove them). for (idx = 0; idx < thread_list_count; ++idx) { - uint32_t existing_idx = 0; - if (numOldThreads > 0) - existing_idx = GetThreadIndexByID(thread_list[idx]); - if (existing_idx < numOldThreads) + const thread_t tid = thread_list[idx]; + + MachThreadSP thread_sp (GetThreadByID (tid)); + if (thread_sp) { // Keep the existing thread class - currThreads.push_back(m_threads[existing_idx]); + currThreads.push_back(thread_sp); } else { // We don't have this thread, lets add it. - MachThreadSP threadSP(new MachThread(process, thread_list[idx])); + thread_sp.reset(new MachThread(process, tid)); // Make sure the thread is ready to be displayed and shown to users // before we add this thread to our list... - if (threadSP->IsUserReady()) - currThreads.push_back(threadSP); + if (thread_sp->IsUserReady()) + currThreads.push_back(thread_sp); } } @@ -290,7 +272,7 @@ void -MachThreadList::CurrentThread(MachThreadSP& threadSP) +MachThreadList::CurrentThread (MachThreadSP& thread_sp) { // locker will keep a mutex locked until it goes out of scope PTHREAD_MUTEX_LOCKER (locker, m_threads_mutex); @@ -299,49 +281,25 @@ // Figure out which thread is going to be our current thread. // This is currently done by finding the first thread in the list // that has a valid exception. - const size_t num_threads = m_threads.size(); - size_t idx; - for (idx = 0; idx < num_threads; ++idx) + const uint32_t num_threads = m_threads.size(); + for (uint32_t idx = 0; idx < num_threads; ++idx) { - MachThread *thread = m_threads[idx].get(); - if (thread->GetStopException().IsValid()) + if (m_threads[idx]->GetStopException().IsValid()) { m_current_thread = m_threads[idx]; break; } } } - threadSP = m_current_thread; -} - -void -MachThreadList::GetRegisterState(int flavor, bool force) -{ - uint32_t idx = 0; - const uint32_t num_threads = m_threads.size(); - for (idx = 0; idx < num_threads; ++idx) - { - m_threads[idx]->GetRegisterState(flavor, force); - } -} - -void -MachThreadList::SetRegisterState(int flavor) -{ - uint32_t idx = 0; - const uint32_t num_threads = m_threads.size(); - for (idx = 0; idx < num_threads; ++idx) - { - m_threads[idx]->SetRegisterState(flavor); - } + thread_sp = m_current_thread; } void MachThreadList::Dump() const { - uint32_t idx = 0; + PTHREAD_MUTEX_LOCKER (locker, m_threads_mutex); const uint32_t num_threads = m_threads.size(); - for (idx = 0; idx < num_threads; ++idx) + for (uint32_t idx = 0; idx < num_threads; ++idx) { m_threads[idx]->Dump(idx); } @@ -351,10 +309,9 @@ void MachThreadList::ProcessWillResume(MachProcess *process, const DNBThreadResumeActions &thread_actions) { - uint32_t idx = 0; + PTHREAD_MUTEX_LOCKER (locker, m_threads_mutex); const uint32_t num_threads = m_threads.size(); - - for (idx = 0; idx < num_threads; ++idx) + for (uint32_t idx = 0; idx < num_threads; ++idx) { MachThread *thread = m_threads[idx].get(); @@ -368,10 +325,10 @@ uint32_t MachThreadList::ProcessDidStop(MachProcess *process) { + PTHREAD_MUTEX_LOCKER (locker, m_threads_mutex); // Update our thread list const uint32_t num_threads = UpdateThreadList(process, true); - uint32_t idx = 0; - for (idx = 0; idx < num_threads; ++idx) + for (uint32_t idx = 0; idx < num_threads; ++idx) { m_threads[idx]->ThreadDidStop(); } @@ -392,10 +349,10 @@ bool MachThreadList::ShouldStop(bool &step_more) { + PTHREAD_MUTEX_LOCKER (locker, m_threads_mutex); uint32_t should_stop = false; const uint32_t num_threads = m_threads.size(); - uint32_t idx = 0; - for (idx = 0; !should_stop && idx < num_threads; ++idx) + for (uint32_t idx = 0; !should_stop && idx < num_threads; ++idx) { should_stop = m_threads[idx]->ShouldStop(step_more); } @@ -406,9 +363,9 @@ void MachThreadList::NotifyBreakpointChanged (const DNBBreakpoint *bp) { - uint32_t idx = 0; + PTHREAD_MUTEX_LOCKER (locker, m_threads_mutex); const uint32_t num_threads = m_threads.size(); - for (idx = 0; idx < num_threads; ++idx) + for (uint32_t idx = 0; idx < num_threads; ++idx) { m_threads[idx]->NotifyBreakpointChanged(bp); } @@ -420,9 +377,9 @@ { if (bp != NULL) { - uint32_t idx = GetThreadIndexByID(bp->ThreadID()); - if (idx < m_threads.size()) - return m_threads[idx]->EnableHardwareBreakpoint(bp); + MachThreadSP thread_sp (GetThreadByID (bp->ThreadID())); + if (thread_sp) + return thread_sp->EnableHardwareBreakpoint(bp); } return INVALID_NUB_HW_INDEX; } @@ -432,9 +389,9 @@ { if (bp != NULL) { - uint32_t idx = GetThreadIndexByID(bp->ThreadID()); - if (idx < m_threads.size()) - return m_threads[idx]->DisableHardwareBreakpoint(bp); + MachThreadSP thread_sp (GetThreadByID (bp->ThreadID())); + if (thread_sp) + return thread_sp->DisableHardwareBreakpoint(bp); } return false; } @@ -444,9 +401,9 @@ { if (wp != NULL) { - uint32_t idx = GetThreadIndexByID(wp->ThreadID()); - if (idx < m_threads.size()) - return m_threads[idx]->EnableHardwareWatchpoint(wp); + MachThreadSP thread_sp (GetThreadByID (wp->ThreadID())); + if (thread_sp) + return thread_sp->EnableHardwareWatchpoint(wp); } return INVALID_NUB_HW_INDEX; } @@ -456,9 +413,9 @@ { if (wp != NULL) { - uint32_t idx = GetThreadIndexByID(wp->ThreadID()); - if (idx < m_threads.size()) - return m_threads[idx]->DisableHardwareWatchpoint(wp); + MachThreadSP thread_sp (GetThreadByID (wp->ThreadID())); + if (thread_sp) + return thread_sp->DisableHardwareWatchpoint(wp); } return false; } @@ -466,10 +423,10 @@ uint32_t MachThreadList::GetThreadIndexForThreadStoppedWithSignal (const int signo) const { + PTHREAD_MUTEX_LOCKER (locker, m_threads_mutex); uint32_t should_stop = false; const uint32_t num_threads = m_threads.size(); - uint32_t idx = 0; - for (idx = 0; !should_stop && idx < num_threads; ++idx) + for (uint32_t idx = 0; !should_stop && idx < num_threads; ++idx) { if (m_threads[idx]->GetStopException().SoftSignal () == signo) return idx; Modified: lldb/trunk/tools/debugserver/source/MacOSX/MachThreadList.h URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/tools/debugserver/source/MacOSX/MachThreadList.h?rev=123815&r1=123814&r2=123815&view=diff ============================================================================== --- lldb/trunk/tools/debugserver/source/MacOSX/MachThreadList.h (original) +++ lldb/trunk/tools/debugserver/source/MacOSX/MachThreadList.h Wed Jan 19 01:54:15 2011 @@ -26,8 +26,6 @@ void Clear (); void Dump () const; - void GetRegisterState (int flavor, bool force); - void SetRegisterState (int flavor); bool GetRegisterValue (nub_thread_t tid, uint32_t reg_set_idx, uint32_t reg_idx, DNBRegisterValue *reg_value) const; bool SetRegisterValue (nub_thread_t tid, uint32_t reg_set_idx, uint32_t reg_idx, const DNBRegisterValue *reg_value) const; nub_size_t GetRegisterContext (nub_thread_t tid, void *buf, size_t buf_len); @@ -46,7 +44,6 @@ nub_size_t NumThreads () const; nub_thread_t ThreadIDAtIndex (nub_size_t idx) const; nub_thread_t CurrentThreadID (); - uint32_t GetThreadIndexByID (thread_t tid) const; void CurrentThread (MachThreadSP& threadSP); void NotifyBreakpointChanged (const DNBBreakpoint *bp); uint32_t EnableHardwareBreakpoint (const DNBBreakpoint *bp) const; @@ -55,7 +52,7 @@ bool DisableHardwareWatchpoint (const DNBBreakpoint *wp) const; uint32_t GetThreadIndexForThreadStoppedWithSignal (const int signo) const; - MachThread * GetThreadByID (nub_thread_t tid) const; + MachThreadSP GetThreadByID (nub_thread_t tid) const; protected: typedef std::vector collection; @@ -66,7 +63,7 @@ // const_iterator FindThreadByID (thread_t tid) const; collection m_threads; - PThreadMutex m_threads_mutex; + mutable PThreadMutex m_threads_mutex; MachThreadSP m_current_thread; }; Modified: lldb/trunk/tools/debugserver/source/MacOSX/x86_64/DNBArchImplX86_64.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/tools/debugserver/source/MacOSX/x86_64/DNBArchImplX86_64.cpp?rev=123815&r1=123814&r2=123815&view=diff ============================================================================== --- lldb/trunk/tools/debugserver/source/MacOSX/x86_64/DNBArchImplX86_64.cpp (original) +++ lldb/trunk/tools/debugserver/source/MacOSX/x86_64/DNBArchImplX86_64.cpp Wed Jan 19 01:54:15 2011 @@ -19,6 +19,7 @@ #include "DNBLog.h" #include "MachThread.h" #include "MachProcess.h" +#include uint64_t DNBArchImplX86_64::GetPC(uint64_t failValue) @@ -59,6 +60,9 @@ { if (force || m_state.GetError(e_regSetGPR, Read)) { + kern_return_t kret = ::thread_abort_safely(m_thread->ThreadID()); + DNBLogThreaded("thread = 0x%4.4x calling thread_abort_safely (tid) => %u (GetGPRState() for stop_count = %u)", m_thread->ThreadID(), kret, m_thread->Process()->StopCount()); + #if DEBUG_GPR_VALUES m_state.context.gpr.__rax = ('a' << 8) + 'x'; m_state.context.gpr.__rbx = ('b' << 8) + 'x'; @@ -247,6 +251,9 @@ kern_return_t DNBArchImplX86_64::SetGPRState() { + kern_return_t kret = ::thread_abort_safely(m_thread->ThreadID()); + DNBLogThreaded("thread = 0x%4.4x calling thread_abort_safely (tid) => %u (SetGPRState() for stop_count = %u)", m_thread->ThreadID(), kret, m_thread->Process()->StopCount()); + m_state.SetError(e_regSetGPR, Write, ::thread_set_state(m_thread->ThreadID(), x86_THREAD_STATE64, (thread_state_t)&m_state.context.gpr, x86_THREAD_STATE64_COUNT)); DNBLogThreadedIf (LOG_THREAD, "::thread_set_state (0x%4.4x, %u, &gpr, %u) => 0x%8.8x" "\n\trax = %16.16llx rbx = %16.16llx rcx = %16.16llx rdx = %16.16llx" Modified: lldb/trunk/tools/debugserver/source/RNBRemote.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/tools/debugserver/source/RNBRemote.cpp?rev=123815&r1=123814&r2=123815&view=diff ============================================================================== --- lldb/trunk/tools/debugserver/source/RNBRemote.cpp (original) +++ lldb/trunk/tools/debugserver/source/RNBRemote.cpp Wed Jan 19 01:54:15 2011 @@ -2894,8 +2894,8 @@ tid_cstr += strlen ("thread:"); tid = strtoul(tid_cstr, NULL, 16); } - DNBLogThreadedIf (LOG_RNB_PACKETS, "RNBRemote::ExtractThreadIDFromThreadSuffix(%s) got thread 0x%4.4x", p, tid); } + return tid; } return GetCurrentThread(); From jingham at apple.com Wed Jan 19 03:45:44 2011 From: jingham at apple.com (Jim Ingham) Date: Wed, 19 Jan 2011 09:45:44 -0000 Subject: [Lldb-commits] [lldb] r123816 - in /lldb/trunk/include/lldb/Target: ThreadPlanCallFunction.h ThreadPlanCallUserExpression.h Message-ID: <20110119094544.C4B642A6C12E@llvm.org> Author: jingham Date: Wed Jan 19 03:45:44 2011 New Revision: 123816 URL: http://llvm.org/viewvc/llvm-project?rev=123816&view=rev Log: ThreadPlanCallUserExpression's WillPop needs to call it's parent's WillPop. Modified: lldb/trunk/include/lldb/Target/ThreadPlanCallFunction.h lldb/trunk/include/lldb/Target/ThreadPlanCallUserExpression.h Modified: lldb/trunk/include/lldb/Target/ThreadPlanCallFunction.h URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Target/ThreadPlanCallFunction.h?rev=123816&r1=123815&r2=123816&view=diff ============================================================================== --- lldb/trunk/include/lldb/Target/ThreadPlanCallFunction.h (original) +++ lldb/trunk/include/lldb/Target/ThreadPlanCallFunction.h Wed Jan 19 03:45:44 2011 @@ -70,6 +70,9 @@ return true; } + // Classes that derive from ClangFunction, and implement + // their own WillPop methods should call this so that the + // thread state gets restored if the plan gets discarded. virtual void WillPop (); Modified: lldb/trunk/include/lldb/Target/ThreadPlanCallUserExpression.h URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Target/ThreadPlanCallUserExpression.h?rev=123816&r1=123815&r2=123816&view=diff ============================================================================== --- lldb/trunk/include/lldb/Target/ThreadPlanCallUserExpression.h (original) +++ lldb/trunk/include/lldb/Target/ThreadPlanCallUserExpression.h Wed Jan 19 03:45:44 2011 @@ -43,6 +43,7 @@ virtual void WillPop () { + ThreadPlanCallFunction::WillPop(); if (m_user_expression_sp) m_user_expression_sp.reset(); } From johnny.chen at apple.com Wed Jan 19 12:18:47 2011 From: johnny.chen at apple.com (Johnny Chen) Date: Wed, 19 Jan 2011 18:18:47 -0000 Subject: [Lldb-commits] [lldb] r123840 - /lldb/trunk/test/lldbtest.py Message-ID: <20110119181847.E51BF2A6C12E@llvm.org> Author: johnny Date: Wed Jan 19 12:18:47 2011 New Revision: 123840 URL: http://llvm.org/viewvc/llvm-project?rev=123840&view=rev Log: Fix a typo in the comment. Modified: lldb/trunk/test/lldbtest.py Modified: lldb/trunk/test/lldbtest.py URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/lldbtest.py?rev=123840&r1=123839&r2=123840&view=diff ============================================================================== --- lldb/trunk/test/lldbtest.py (original) +++ lldb/trunk/test/lldbtest.py Wed Jan 19 12:18:47 2011 @@ -106,7 +106,7 @@ import lldb # See also dotest.parseOptionsAndInitTestdirs(), where the environment variables -# LLDB_COMMAND_TRACE and LLDB_NO_CLEANUP are set from '-t' and '-r dir' options. +# LLDB_COMMAND_TRACE and LLDB_DO_CLEANUP are set from '-t' and '-r dir' options. # By default, traceAlways is False. if "LLDB_COMMAND_TRACE" in os.environ and os.environ["LLDB_COMMAND_TRACE"]=="YES": From scallanan at apple.com Wed Jan 19 12:49:56 2011 From: scallanan at apple.com (Sean Callanan) Date: Wed, 19 Jan 2011 18:49:56 -0000 Subject: [Lldb-commits] [lldb] r123841 - /lldb/trunk/llvm.zip Message-ID: <20110119184956.B8AD32A6C12E@llvm.org> Author: spyffe Date: Wed Jan 19 12:49:56 2011 New Revision: 123841 URL: http://llvm.org/viewvc/llvm-project?rev=123841&view=rev Log: Updated llvm.zip; the old one had debug symbols, making it way too big. Modified: lldb/trunk/llvm.zip Modified: lldb/trunk/llvm.zip URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/llvm.zip?rev=123841&r1=123840&r2=123841&view=diff ============================================================================== Binary files - no diff available. From johnny.chen at apple.com Wed Jan 19 13:31:46 2011 From: johnny.chen at apple.com (Johnny Chen) Date: Wed, 19 Jan 2011 19:31:46 -0000 Subject: [Lldb-commits] [lldb] r123843 - /lldb/trunk/test/dotest.py Message-ID: <20110119193146.CAA7D2A6C12E@llvm.org> Author: johnny Date: Wed Jan 19 13:31:46 2011 New Revision: 123843 URL: http://llvm.org/viewvc/llvm-project?rev=123843&view=rev Log: Print out the command line used to invoke the test suite so I don't get confused since different options can affect the run time. Modified: lldb/trunk/test/dotest.py Modified: lldb/trunk/test/dotest.py URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/dotest.py?rev=123843&r1=123842&r2=123843&view=diff ============================================================================== --- lldb/trunk/test/dotest.py (original) +++ lldb/trunk/test/dotest.py Wed Jan 19 13:31:46 2011 @@ -607,6 +607,12 @@ if not res.Succeeded(): raise Exception('log enable failed (check GDB_REMOTE_LOG env variable.') +def getMyCommandLine(): + import subprocess + ps = subprocess.Popen(['ps', '-o', "command=CMD", str(os.getpid())], stdout=subprocess.PIPE).communicate()[0] + lines = ps.split('\n') + cmd_line = lines[1] + return cmd_line # ======================================== # # # @@ -679,7 +685,9 @@ timestamp = datetime.datetime.now().strftime("%Y-%m-%d-%H_%M_%S") sdir_name = timestamp os.environ["LLDB_SESSION_DIRNAME"] = sdir_name + sys.stderr.write("\nSession logs for test failures/errors will go into directory '%s'\n" % sdir_name) +sys.stderr.write("Command invoked: %s\n" % getMyCommandLine()) # # Invoke the default TextTestRunner to run the test suite, possibly iterating From johnny.chen at apple.com Wed Jan 19 13:48:29 2011 From: johnny.chen at apple.com (Johnny Chen) Date: Wed, 19 Jan 2011 19:48:29 -0000 Subject: [Lldb-commits] [lldb] r123844 - /lldb/trunk/test/README-TestSuite Message-ID: <20110119194829.3CB3D2A6C12E@llvm.org> Author: johnny Date: Wed Jan 19 13:48:29 2011 New Revision: 123844 URL: http://llvm.org/viewvc/llvm-project?rev=123844&view=rev Log: Add the cmdline to invoke the Python profile reporting module. Modified: lldb/trunk/test/README-TestSuite Modified: lldb/trunk/test/README-TestSuite URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/README-TestSuite?rev=123844&r1=123843&r2=123844&view=diff ============================================================================== --- lldb/trunk/test/README-TestSuite (original) +++ lldb/trunk/test/README-TestSuite Wed Jan 19 13:48:29 2011 @@ -98,4 +98,6 @@ $ DOTEST_PROFILE=YES DOTEST_SCRIPT_DIR=/Volumes/data/lldb/svn/trunk/test /System/Library/Frameworks/Python.framework/Versions/Current/lib/python2.6/cProfile.py -o my.profile ./dotest.py -v -w 2> ~/Developer/Log/lldbtest.log - After that, I used the pstats.py module to browse the statistics. + After that, I used the pstats.py module to browse the statistics: + +$ python /System/Library/Frameworks/Python.framework/Versions/Current/lib/python2.6/pstats.py my.profile From gclayton at apple.com Wed Jan 19 17:00:49 2011 From: gclayton at apple.com (Greg Clayton) Date: Wed, 19 Jan 2011 23:00:49 -0000 Subject: [Lldb-commits] [lldb] r123855 - in /lldb/trunk: include/lldb/ include/lldb/Core/ include/lldb/Expression/ include/lldb/Target/ source/Expression/ Message-ID: <20110119230050.174F12A6C12E@llvm.org> Author: gclayton Date: Wed Jan 19 17:00:49 2011 New Revision: 123855 URL: http://llvm.org/viewvc/llvm-project?rev=123855&view=rev Log: Make expressions clean up their JIT'ed code allocation. Modified: lldb/trunk/include/lldb/Core/ClangForward.h lldb/trunk/include/lldb/Expression/ClangExpression.h lldb/trunk/include/lldb/Expression/ClangExpressionParser.h lldb/trunk/include/lldb/Expression/ClangFunction.h lldb/trunk/include/lldb/Expression/ClangUserExpression.h lldb/trunk/include/lldb/Expression/ClangUtilityFunction.h lldb/trunk/include/lldb/Expression/RecordingMemoryManager.h lldb/trunk/include/lldb/Target/ThreadPlanCallUserExpression.h lldb/trunk/include/lldb/lldb-forward.h lldb/trunk/source/Expression/ClangExpressionParser.cpp lldb/trunk/source/Expression/ClangFunction.cpp lldb/trunk/source/Expression/ClangUserExpression.cpp lldb/trunk/source/Expression/ClangUtilityFunction.cpp Modified: lldb/trunk/include/lldb/Core/ClangForward.h URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Core/ClangForward.h?rev=123855&r1=123854&r2=123855&view=diff ============================================================================== --- lldb/trunk/include/lldb/Core/ClangForward.h (original) +++ lldb/trunk/include/lldb/Core/ClangForward.h Wed Jan 19 17:00:49 2011 @@ -118,5 +118,10 @@ struct PrintingPolicy; } +namespace llvm +{ + class ExecutionEngine; +} + #endif // #if defined(__cplusplus) #endif // liblldb_ClangForward_h_ Modified: lldb/trunk/include/lldb/Expression/ClangExpression.h URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Expression/ClangExpression.h?rev=123855&r1=123854&r2=123855&view=diff ============================================================================== --- lldb/trunk/include/lldb/Expression/ClangExpression.h (original) +++ lldb/trunk/include/lldb/Expression/ClangExpression.h Wed Jan 19 17:00:49 2011 @@ -23,7 +23,7 @@ #include "lldb/lldb-forward.h" #include "lldb/lldb-private.h" #include "lldb/Core/ClangForward.h" -#include "llvm/ExecutionEngine/JITMemoryManager.h" +#include "lldb/Target/Process.h" namespace lldb_private { @@ -41,11 +41,20 @@ class ClangExpression { public: + ClangExpression () : + m_jit_process_sp(), + m_jit_alloc (LLDB_INVALID_ADDRESS), + m_jit_start_addr (LLDB_INVALID_ADDRESS), + m_jit_end_addr (LLDB_INVALID_ADDRESS) + { + } + //------------------------------------------------------------------ /// Destructor //------------------------------------------------------------------ virtual ~ClangExpression () { + DeallocateJITFunction (); } //------------------------------------------------------------------ @@ -112,6 +121,38 @@ //------------------------------------------------------------------ virtual bool NeedsVariableResolution () = 0; + + void + DeallocateJITFunction () + { + if (m_jit_process_sp && m_jit_alloc != LLDB_INVALID_ADDRESS) + { + m_jit_process_sp->DeallocateMemory (m_jit_alloc); + // If this process is ever used for anything else, we can not clear it + // here. For now it is only used in order to deallocate any code if + // m_jit_alloc is a valid address. + m_jit_process_sp.reset(); + m_jit_alloc = LLDB_INVALID_ADDRESS; + } + } + + //------------------------------------------------------------------ + /// Return the address of the function's JIT-compiled code, or + /// LLDB_INVALID_ADDRESS if the function is not JIT compiled + //------------------------------------------------------------------ + lldb::addr_t + StartAddress () + { + return m_jit_start_addr; + } + +protected: + + lldb::ProcessSP m_jit_process_sp; + lldb::addr_t m_jit_alloc; ///< The address of the block containing JITted code. LLDB_INVALID_ADDRESS if invalid. + lldb::addr_t m_jit_start_addr; ///< The address of the JITted function within the JIT allocation. LLDB_INVALID_ADDRESS if invalid. + lldb::addr_t m_jit_end_addr; ///< The address of the JITted function within the JIT allocation. LLDB_INVALID_ADDRESS if invalid. + }; } // namespace lldb_private Modified: lldb/trunk/include/lldb/Expression/ClangExpressionParser.h URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Expression/ClangExpressionParser.h?rev=123855&r1=123854&r2=123855&view=diff ============================================================================== --- lldb/trunk/include/lldb/Expression/ClangExpressionParser.h (original) +++ lldb/trunk/include/lldb/Expression/ClangExpressionParser.h Wed Jan 19 17:00:49 2011 @@ -17,15 +17,9 @@ #include #include -namespace llvm -{ - class ExecutionEngine; -} - namespace lldb_private { -class Process; class RecordingMemoryManager; //---------------------------------------------------------------------- @@ -96,6 +90,10 @@ //------------------------------------------------------------------ /// JIT-compile the IR for an already-parsed expression. /// + /// @param[out] func_allocation_addr + /// The address which can be used to deallocate the code for this + /// JIT'ed function + /// /// @param[out] func_addr /// The address to which the function has been written. /// @@ -117,7 +115,8 @@ /// Test with Success(). //------------------------------------------------------------------ Error - MakeJIT (lldb::addr_t &func_addr, + MakeJIT (lldb::addr_t &func_allocation_addr, + lldb::addr_t &func_addr, lldb::addr_t &func_end, ExecutionContext &exe_ctx, lldb::ClangExpressionVariableSP *const_result = NULL); @@ -136,7 +135,9 @@ /// The error generated. If .Success() is true, disassembly succeeded. //------------------------------------------------------------------ Error - DisassembleFunction (Stream &stream, ExecutionContext &exc_context); + DisassembleFunction (Stream &stream, + ExecutionContext &exe_ctx, + RecordingMemoryManager *jit_memory_manager); private: //---------------------------------------------------------------------- @@ -187,7 +188,6 @@ std::auto_ptr m_selector_table; ///< Selector table for Objective-C methods std::auto_ptr m_ast_context; ///< The AST context used to hold types and names for the parser std::auto_ptr m_code_generator; ///< [owned by the Execution Engine] The Clang object that generates IR - RecordingMemoryManager *m_jit_mm; ///< The memory manager for the LLVM JIT std::auto_ptr m_execution_engine; ///< The LLVM JIT std::vector m_jitted_functions; ///< A vector of all functions that have been JITted into machine code (just one, if ParseExpression() was called) }; Modified: lldb/trunk/include/lldb/Expression/ClangFunction.h URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Expression/ClangFunction.h?rev=123855&r1=123854&r2=123855&view=diff ============================================================================== --- lldb/trunk/include/lldb/Expression/ClangFunction.h (original) +++ lldb/trunk/include/lldb/Expression/ClangFunction.h Wed Jan 19 17:00:49 2011 @@ -477,7 +477,7 @@ bool discard_on_error = true) { return ClangFunction::GetThreadPlanToCallFunction (exe_ctx, - m_wrapper_function_addr, + m_jit_start_addr, args_addr_ref, errors, stop_others, @@ -618,7 +618,6 @@ std::string m_wrapper_function_name; ///< The name of the wrapper function. std::string m_wrapper_function_text; ///< The contents of the wrapper function. std::string m_wrapper_struct_name; ///< The name of the struct that contains the target function address, arguments, and result. - lldb::addr_t m_wrapper_function_addr; ///< The address of the wrapper function. std::list m_wrapper_args_addrs; ///< The addresses of the arguments to the wrapper function. bool m_struct_valid; ///< True if the ASTStructExtractor has populated the variables below. Modified: lldb/trunk/include/lldb/Expression/ClangUserExpression.h URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Expression/ClangUserExpression.h?rev=123855&r1=123854&r2=123855&view=diff ============================================================================== --- lldb/trunk/include/lldb/Expression/ClangUserExpression.h (original) +++ lldb/trunk/include/lldb/Expression/ClangUserExpression.h Wed Jan 19 17:00:49 2011 @@ -291,7 +291,6 @@ std::auto_ptr m_expr_decl_map; ///< The map to use when parsing and materializing the expression. std::auto_ptr m_local_variables; ///< The local expression variables, if the expression is DWARF. std::auto_ptr m_dwarf_opcodes; ///< The DWARF opcodes for the expression. May be NULL. - lldb::addr_t m_jit_addr; ///< The address of the JITted code. LLDB_INVALID_ADDRESS if invalid. bool m_cplusplus; ///< True if the expression is compiled as a C++ member function (true if it was parsed when exe_ctx was in a C++ method). bool m_objectivec; ///< True if the expression is compiled as an Objective-C method (true if it was parsed when exe_ctx was in an Objective-C method). Modified: lldb/trunk/include/lldb/Expression/ClangUtilityFunction.h URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Expression/ClangUtilityFunction.h?rev=123855&r1=123854&r2=123855&view=diff ============================================================================== --- lldb/trunk/include/lldb/Expression/ClangUtilityFunction.h (original) +++ lldb/trunk/include/lldb/Expression/ClangUtilityFunction.h Wed Jan 19 17:00:49 2011 @@ -88,18 +88,9 @@ { // nothing is both >= LLDB_INVALID_ADDRESS and < LLDB_INVALID_ADDRESS, // so this always returns false if the function is not JIT compiled yet - return (address >= m_jit_begin && address < m_jit_end); + return (address >= m_jit_start_addr && address < m_jit_end_addr); } - //------------------------------------------------------------------ - /// Return the address of the function's JIT-compiled code, or - /// LLDB_INVALID_ADDRESS if the function is not JIT compiled - //------------------------------------------------------------------ - lldb::addr_t - StartAddress () - { - return m_jit_begin; - } //------------------------------------------------------------------ /// Return the string that the parser should parse. Must be a full @@ -191,9 +182,6 @@ std::string m_function_text; ///< The text of the function. Must be a well-formed translation unit. std::string m_function_name; ///< The name of the function. - - lldb::addr_t m_jit_begin; ///< The address of the JITted code. LLDB_INVALID_ADDRESS if invalid. - lldb::addr_t m_jit_end; ///< The end of the JITted code. LLDB_INVALID_ADDRESS if invalid. }; } // namespace lldb_private Modified: lldb/trunk/include/lldb/Expression/RecordingMemoryManager.h URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Expression/RecordingMemoryManager.h?rev=123855&r1=123854&r2=123855&view=diff ============================================================================== --- lldb/trunk/include/lldb/Expression/RecordingMemoryManager.h (original) +++ lldb/trunk/include/lldb/Expression/RecordingMemoryManager.h Wed Jan 19 17:00:49 2011 @@ -52,11 +52,6 @@ //---------------------------------------------------------------------- class RecordingMemoryManager : public llvm::JITMemoryManager { -friend Error ClangExpressionParser::MakeJIT (uint64_t &, - uint64_t&, - ExecutionContext &, - lldb::ClangExpressionVariableSP *); - public: //------------------------------------------------------------------ /// Constructor @@ -329,6 +324,8 @@ AddToLocalToRemoteMap (lldb::addr_t lstart, size_t size, lldb::addr_t rstart); std::vector m_address_map; ///< The base address of the remote allocation + + friend class ClangExpressionParser; }; } // namespace lldb_private Modified: lldb/trunk/include/lldb/Target/ThreadPlanCallUserExpression.h URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Target/ThreadPlanCallUserExpression.h?rev=123855&r1=123854&r2=123855&view=diff ============================================================================== --- lldb/trunk/include/lldb/Target/ThreadPlanCallUserExpression.h (original) +++ lldb/trunk/include/lldb/Target/ThreadPlanCallUserExpression.h Wed Jan 19 17:00:49 2011 @@ -26,13 +26,13 @@ { public: ThreadPlanCallUserExpression (Thread &thread, - Address &function, - lldb::addr_t arg, - bool stop_other_threads, - bool discard_on_error, - lldb::addr_t *this_arg, - lldb::addr_t *cmd_arg, - ClangUserExpression::ClangUserExpressionSP &user_expression_sp); + Address &function, + lldb::addr_t arg, + bool stop_other_threads, + bool discard_on_error, + lldb::addr_t *this_arg, + lldb::addr_t *cmd_arg, + ClangUserExpression::ClangUserExpressionSP &user_expression_sp); virtual ~ThreadPlanCallUserExpression (); @@ -50,9 +50,9 @@ protected: private: - ClangUserExpression::ClangUserExpressionSP m_user_expression_sp; // This is currently just used to ensure the - // User expression the initiated this ThreadPlan - // lives as long as the thread plan does. + ClangUserExpression::ClangUserExpressionSP m_user_expression_sp; // This is currently just used to ensure the + // User expression the initiated this ThreadPlan + // lives as long as the thread plan does. DISALLOW_COPY_AND_ASSIGN (ThreadPlanCallUserExpression); }; Modified: lldb/trunk/include/lldb/lldb-forward.h URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/lldb-forward.h?rev=123855&r1=123854&r2=123855&view=diff ============================================================================== --- lldb/trunk/include/lldb/lldb-forward.h (original) +++ lldb/trunk/include/lldb/lldb-forward.h Wed Jan 19 17:00:49 2011 @@ -45,6 +45,7 @@ class ClangNamespaceDecl; class ClangExpression; class ClangExpressionDeclMap; +class ClangExpressionParser; class ClangExpressionVariable; class ClangExpressionVariableList; class ClangExpressionVariableList; Modified: lldb/trunk/source/Expression/ClangExpressionParser.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Expression/ClangExpressionParser.cpp?rev=123855&r1=123854&r2=123855&view=diff ============================================================================== --- lldb/trunk/source/Expression/ClangExpressionParser.cpp (original) +++ lldb/trunk/source/Expression/ClangExpressionParser.cpp Wed Jan 19 17:00:49 2011 @@ -425,11 +425,15 @@ } Error -ClangExpressionParser::MakeJIT (lldb::addr_t &func_addr, +ClangExpressionParser::MakeJIT (lldb::addr_t &func_allocation_addr, + lldb::addr_t &func_addr, lldb::addr_t &func_end, ExecutionContext &exe_ctx, lldb::ClangExpressionVariableSP *const_result) { + func_allocation_addr = LLDB_INVALID_ADDRESS; + func_addr = LLDB_INVALID_ADDRESS; + func_end = LLDB_INVALID_ADDRESS; lldb::LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_EXPRESSIONS)); Error err; @@ -488,7 +492,9 @@ } } - m_jit_mm = new RecordingMemoryManager(); + // llvm will own this pointer when llvm::ExecutionEngine::createJIT is called + // below so we don't need to free it. + RecordingMemoryManager *jit_memory_manager = new RecordingMemoryManager(); std::string error_string; @@ -496,7 +502,7 @@ m_execution_engine.reset(llvm::ExecutionEngine::createJIT (module, &error_string, - m_jit_mm, + jit_memory_manager, CodeGenOpt::Less, true, CodeModel::Small)); @@ -544,25 +550,27 @@ size_t alloc_size = 0; - std::map::iterator fun_pos = m_jit_mm->m_functions.begin(); - std::map::iterator fun_end = m_jit_mm->m_functions.end(); + std::map::iterator fun_pos = jit_memory_manager->m_functions.begin(); + std::map::iterator fun_end = jit_memory_manager->m_functions.end(); for (; fun_pos != fun_end; ++fun_pos) alloc_size += (*fun_pos).second - (*fun_pos).first; Error alloc_error; - lldb::addr_t target_addr = exc_context.process->AllocateMemory (alloc_size, lldb::ePermissionsReadable|lldb::ePermissionsExecutable, alloc_error); + func_allocation_addr = exc_context.process->AllocateMemory (alloc_size, + lldb::ePermissionsReadable|lldb::ePermissionsExecutable, + alloc_error); - if (target_addr == LLDB_INVALID_ADDRESS) + if (func_allocation_addr == LLDB_INVALID_ADDRESS) { err.SetErrorToGenericError(); err.SetErrorStringWithFormat("Couldn't allocate memory for the JITted function: %s", alloc_error.AsCString("unknown error")); return err; } - lldb::addr_t cursor = target_addr; + lldb::addr_t cursor = func_allocation_addr; - for (fun_pos = m_jit_mm->m_functions.begin(); fun_pos != fun_end; fun_pos++) + for (fun_pos = jit_memory_manager->m_functions.begin(); fun_pos != fun_end; fun_pos++) { lldb::addr_t lstart = (lldb::addr_t) (*fun_pos).first; lldb::addr_t lend = (lldb::addr_t) (*fun_pos).second; @@ -577,7 +585,7 @@ return err; } - m_jit_mm->AddToLocalToRemoteMap (lstart, size, cursor); + jit_memory_manager->AddToLocalToRemoteMap (lstart, size, cursor); cursor += size; } @@ -585,11 +593,11 @@ for (pos = m_jitted_functions.begin(); pos != end; pos++) { - (*pos).m_remote_addr = m_jit_mm->GetRemoteAddressForLocal ((*pos).m_local_addr); + (*pos).m_remote_addr = jit_memory_manager->GetRemoteAddressForLocal ((*pos).m_local_addr); if (!(*pos).m_name.compare(function_name.c_str())) { - func_end = m_jit_mm->GetRemoteRangeForLocal ((*pos).m_local_addr).second; + func_end = jit_memory_manager->GetRemoteRangeForLocal ((*pos).m_local_addr).second; func_addr = (*pos).m_remote_addr; } } @@ -600,7 +608,7 @@ StreamString disassembly_stream; - Error err = DisassembleFunction(disassembly_stream, exe_ctx); + Error err = DisassembleFunction(disassembly_stream, exe_ctx, jit_memory_manager); if (!err.Success()) { @@ -617,7 +625,7 @@ } Error -ClangExpressionParser::DisassembleFunction (Stream &stream, ExecutionContext &exe_ctx) +ClangExpressionParser::DisassembleFunction (Stream &stream, ExecutionContext &exe_ctx, RecordingMemoryManager *jit_memory_manager) { lldb::LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_EXPRESSIONS)); @@ -653,7 +661,7 @@ std::pair func_range; - func_range = m_jit_mm->GetRemoteRangeForLocal(func_local_addr); + func_range = jit_memory_manager->GetRemoteRangeForLocal(func_local_addr); if (func_range.first == 0 && func_range.second == 0) { Modified: lldb/trunk/source/Expression/ClangFunction.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Expression/ClangFunction.cpp?rev=123855&r1=123854&r2=123855&view=diff ============================================================================== --- lldb/trunk/source/Expression/ClangFunction.cpp (original) +++ lldb/trunk/source/Expression/ClangFunction.cpp Wed Jan 19 17:00:49 2011 @@ -61,7 +61,6 @@ m_clang_ast_context (ast_context), m_wrapper_function_name ("__lldb_caller_function"), m_wrapper_struct_name ("__lldb_caller_struct"), - m_wrapper_function_addr (), m_wrapper_args_addrs (), m_arg_values (arg_value_list), m_compiled (false), @@ -83,7 +82,6 @@ m_clang_ast_context (ast_context), m_wrapper_function_name ("__lldb_function_caller"), m_wrapper_struct_name ("__lldb_caller_struct"), - m_wrapper_function_addr (), m_wrapper_args_addrs (), m_arg_values (arg_value_list), m_compiled (false), @@ -240,12 +238,12 @@ if (m_JITted) return true; - lldb::addr_t wrapper_function_end; - - Error jit_error = m_parser->MakeJIT(m_wrapper_function_addr, wrapper_function_end, exe_ctx); + Error jit_error (m_parser->MakeJIT (m_jit_alloc, m_jit_start_addr, m_jit_end_addr, exe_ctx)); if (!jit_error.Success()) return false; + if (exe_ctx.process && m_jit_alloc != LLDB_INVALID_ADDRESS) + m_jit_process_sp = exe_ctx.process->GetSP(); return true; } @@ -360,7 +358,7 @@ lldb::LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_STEP)); if (log) - log->Printf ("Call Address: 0x%llx Struct Address: 0x%llx.\n", m_wrapper_function_addr, args_addr_ref); + log->Printf ("Call Address: 0x%llx Struct Address: 0x%llx.\n", m_jit_start_addr, args_addr_ref); return true; } @@ -524,8 +522,14 @@ return lldb::eExecutionSetupError; } - return_value = ClangFunction::ExecuteFunction(exe_ctx, m_wrapper_function_addr, args_addr, stop_others, - try_all_threads, discard_on_error, single_thread_timeout_usec, errors); + return_value = ClangFunction::ExecuteFunction (exe_ctx, + m_jit_start_addr, + args_addr, + stop_others, + try_all_threads, + discard_on_error, + single_thread_timeout_usec, + errors); if (args_addr_ptr != NULL) *args_addr_ptr = args_addr; Modified: lldb/trunk/source/Expression/ClangUserExpression.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Expression/ClangUserExpression.cpp?rev=123855&r1=123854&r2=123855&view=diff ============================================================================== --- lldb/trunk/source/Expression/ClangUserExpression.cpp (original) +++ lldb/trunk/source/Expression/ClangUserExpression.cpp Wed Jan 19 17:00:49 2011 @@ -41,15 +41,15 @@ ClangUserExpression::ClangUserExpression (const char *expr, const char *expr_prefix) : - m_expr_text(expr), - m_expr_prefix(expr_prefix ? expr_prefix : ""), - m_transformed_text(), - m_jit_addr(LLDB_INVALID_ADDRESS), - m_cplusplus(false), - m_objectivec(false), - m_needs_object_ptr(false), - m_const_object(false), - m_desired_type(NULL, NULL) + ClangExpression (), + m_expr_text (expr), + m_expr_prefix (expr_prefix ? expr_prefix : ""), + m_transformed_text (), + m_cplusplus (false), + m_objectivec (false), + m_needs_object_ptr (false), + m_const_object (false), + m_desired_type (NULL, NULL) { } @@ -295,14 +295,14 @@ m_dwarf_opcodes.reset(); - lldb::addr_t jit_end; - - Error jit_error = parser.MakeJIT (m_jit_addr, jit_end, exe_ctx, const_result); + Error jit_error = parser.MakeJIT (m_jit_alloc, m_jit_start_addr, m_jit_end_addr, exe_ctx, const_result); m_expr_decl_map->DidParse(); if (jit_error.Success()) { + if (exe_ctx.process && m_jit_alloc != LLDB_INVALID_ADDRESS) + m_jit_process_sp = exe_ctx.process->GetSP(); return true; } else @@ -321,7 +321,7 @@ { lldb::LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_EXPRESSIONS)); - if (m_jit_addr != LLDB_INVALID_ADDRESS) + if (m_jit_start_addr != LLDB_INVALID_ADDRESS) { Error materialize_error; @@ -370,14 +370,14 @@ #if 0 // jingham: look here StreamFile logfile ("/tmp/exprs.txt", "a"); - logfile.Printf("0x%16.16llx: thread = 0x%4.4x, expr = '%s'\n", m_jit_addr, exe_ctx.thread ? exe_ctx.thread->GetID() : -1, m_expr_text.c_str()); + logfile.Printf("0x%16.16llx: thread = 0x%4.4x, expr = '%s'\n", m_jit_start_addr, exe_ctx.thread ? exe_ctx.thread->GetID() : -1, m_expr_text.c_str()); #endif if (log) { log->Printf("-- [ClangUserExpression::PrepareToExecuteJITExpression] Materializing for execution --"); - log->Printf(" Function address : 0x%llx", (uint64_t)m_jit_addr); + log->Printf(" Function address : 0x%llx", (uint64_t)m_jit_start_addr); if (m_needs_object_ptr) log->Printf(" Object pointer : 0x%llx", (uint64_t)object_ptr); @@ -420,7 +420,7 @@ // forcing unwind_on_error to be true here, in practical terms that can't happen. return ClangFunction::GetThreadPlanToCallFunction (exe_ctx, - m_jit_addr, + m_jit_start_addr, struct_address, error_stream, true, @@ -484,7 +484,7 @@ return lldb::eExecutionSetupError; } - else if (m_jit_addr != LLDB_INVALID_ADDRESS) + else if (m_jit_start_addr != LLDB_INVALID_ADDRESS) { lldb::addr_t struct_address; @@ -497,7 +497,7 @@ const bool stop_others = true; const bool try_all_threads = true; - Address wrapper_address (NULL, m_jit_addr); + Address wrapper_address (NULL, m_jit_start_addr); lldb::ThreadPlanSP call_plan_sp(new ThreadPlanCallUserExpression (*(exe_ctx.thread), wrapper_address, struct_address, Modified: lldb/trunk/source/Expression/ClangUtilityFunction.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Expression/ClangUtilityFunction.cpp?rev=123855&r1=123854&r2=123855&view=diff ============================================================================== --- lldb/trunk/source/Expression/ClangUtilityFunction.cpp (original) +++ lldb/trunk/source/Expression/ClangUtilityFunction.cpp Wed Jan 19 17:00:49 2011 @@ -38,10 +38,9 @@ //------------------------------------------------------------------ ClangUtilityFunction::ClangUtilityFunction (const char *text, const char *name) : - m_function_text(text), - m_function_name(name), - m_jit_begin(LLDB_INVALID_ADDRESS), - m_jit_end(LLDB_INVALID_ADDRESS) + ClangExpression (), + m_function_text (text), + m_function_name (name) { } @@ -65,7 +64,7 @@ ClangUtilityFunction::Install (Stream &error_stream, ExecutionContext &exe_ctx) { - if (m_jit_begin != LLDB_INVALID_ADDRESS) + if (m_jit_start_addr != LLDB_INVALID_ADDRESS) { error_stream.PutCString("error: already installed\n"); return false; @@ -123,13 +122,16 @@ // JIT the output of the parser // - Error jit_error = parser.MakeJIT (m_jit_begin, m_jit_end, exe_ctx); + Error jit_error = parser.MakeJIT (m_jit_alloc, m_jit_start_addr, m_jit_end_addr, exe_ctx); + + if (exe_ctx.process && m_jit_start_addr != LLDB_INVALID_ADDRESS) + m_jit_process_sp = exe_ctx.process->GetSP(); #if 0 // jingham: look here StreamFile logfile ("/tmp/exprs.txt", "a"); logfile.Printf ("0x%16.16llx: func = %s, source =\n%s\n", - m_jit_begin, + m_jit_start_addr, m_function_name.c_str(), m_function_text.c_str()); #endif From jingham at apple.com Wed Jan 19 20:03:18 2011 From: jingham at apple.com (Jim Ingham) Date: Thu, 20 Jan 2011 02:03:18 -0000 Subject: [Lldb-commits] [lldb] r123869 - in /lldb/trunk: include/lldb/Target/ lldb.xcodeproj/ source/Plugins/Process/Linux/ source/Plugins/Process/MacOSX-User/source/ source/Plugins/Process/gdb-remote/ source/Target/ Message-ID: <20110120020318.A4DE02A6C12E@llvm.org> Author: jingham Date: Wed Jan 19 20:03:18 2011 New Revision: 123869 URL: http://llvm.org/viewvc/llvm-project?rev=123869&view=rev Log: Back up both the register AND the stop state when calling functions. Set the thread state to "bland" before calling functions so they don't inherit the pending signals and die. Modified: lldb/trunk/include/lldb/Target/StopInfo.h lldb/trunk/include/lldb/Target/Thread.h lldb/trunk/include/lldb/Target/ThreadPlan.h lldb/trunk/include/lldb/Target/ThreadPlanCallFunction.h lldb/trunk/lldb.xcodeproj/project.pbxproj lldb/trunk/source/Plugins/Process/Linux/LinuxThread.h lldb/trunk/source/Plugins/Process/MacOSX-User/source/ThreadMacOSX.h lldb/trunk/source/Plugins/Process/gdb-remote/ThreadGDBRemote.cpp lldb/trunk/source/Plugins/Process/gdb-remote/ThreadGDBRemote.h lldb/trunk/source/Target/Process.cpp lldb/trunk/source/Target/StopInfo.cpp lldb/trunk/source/Target/Thread.cpp lldb/trunk/source/Target/ThreadPlanCallFunction.cpp lldb/trunk/source/Target/UnixSignals.cpp Modified: lldb/trunk/include/lldb/Target/StopInfo.h URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Target/StopInfo.h?rev=123869&r1=123868&r2=123869&view=diff ============================================================================== --- lldb/trunk/include/lldb/Target/StopInfo.h (original) +++ lldb/trunk/include/lldb/Target/StopInfo.h Wed Jan 19 20:03:18 2011 @@ -119,9 +119,16 @@ // Classes that inherit from StackID can see and modify these //------------------------------------------------------------------ Thread & m_thread; // The thread corresponding to the stop reason. - const uint32_t m_stop_id; // The process stop ID for which this stop info is valid + uint32_t m_stop_id; // The process stop ID for which this stop info is valid uint64_t m_value; // A generic value that can be used for things pertaining to this stop info private: + friend class Thread; + + // MakeStopInfoValid is necessary to allow saved stop infos to resurrect themselves as valid. It should + // only need to be called by Thread::RestoreThreadStateFromCheckpoint. + void + MakeStopInfoValid (); + DISALLOW_COPY_AND_ASSIGN (StopInfo); }; Modified: lldb/trunk/include/lldb/Target/Thread.h URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Target/Thread.h?rev=123869&r1=123868&r2=123869&view=diff ============================================================================== --- lldb/trunk/include/lldb/Target/Thread.h (original) +++ lldb/trunk/include/lldb/Target/Thread.h Wed Jan 19 20:03:18 2011 @@ -115,6 +115,8 @@ DISALLOW_COPY_AND_ASSIGN (SettingsController); }; + // TODO: You shouldn't just checkpoint the register state alone, so this should get + // moved to protected. To do that ThreadStateCheckpoint needs to be returned as a token... class RegisterCheckpoint { public: @@ -135,6 +137,23 @@ { } + const RegisterCheckpoint& + operator= (const RegisterCheckpoint &rhs) + { + if (this != &rhs) + { + this->m_stack_id = rhs.m_stack_id; + this->m_data_sp = rhs.m_data_sp; + } + return *this; + } + + RegisterCheckpoint (const RegisterCheckpoint &rhs) : + m_stack_id (rhs.m_stack_id), + m_data_sp (rhs.m_data_sp) + { + } + const StackID & GetStackID() { @@ -164,6 +183,13 @@ lldb::DataBufferSP m_data_sp; }; + struct ThreadStateCheckpoint + { + uint32_t orig_stop_id; // Dunno if I need this yet but it is an interesting bit of data. + lldb::StopInfoSP stop_info_sp; // You have to restore the stop info or you might continue with the wrong signals. + RegisterCheckpoint register_backup; // You need to restore the registers, of course... + }; + void UpdateInstanceName (); @@ -261,6 +287,11 @@ lldb::StopInfoSP GetStopInfo (); + // This sets the stop reason to a "blank" stop reason, so you can call functions on the thread + // without having the called function run with whatever stop reason you stopped with. + void + SetStopInfoToNothing(); + bool ThreadStoppedForAReason (); @@ -309,12 +340,6 @@ virtual lldb::RegisterContextSP GetRegisterContext () = 0; - virtual bool - SaveFrameZeroState (RegisterCheckpoint &checkpoint) = 0; - - virtual bool - RestoreSaveFrameZero (const RegisterCheckpoint &checkpoint) = 0; - virtual lldb::RegisterContextSP CreateRegisterContextForFrame (StackFrame *frame) = 0; @@ -609,6 +634,12 @@ void DumpThreadPlans (Stream *s) const; + virtual bool + CheckpointThreadState (ThreadStateCheckpoint &saved_state); + + virtual bool + RestoreThreadStateFromCheckpoint (ThreadStateCheckpoint &saved_state); + void EnableTracer (bool value, bool single_step); @@ -678,22 +709,35 @@ ThreadPlan *GetPreviousPlan (ThreadPlan *plan); + // When you implement this method, make sure you don't overwrite the m_actual_stop_info if it claims to be + // valid. The stop info may be a "checkpointed and restored" stop info, so if it is still around it is right + // even if you have not calculated this yourself, or if it disagrees with what you might have calculated. virtual lldb::StopInfoSP GetPrivateStopReason () = 0; typedef std::vector plan_stack; + void + SetStopInfo (const lldb::StopInfoSP &stop_info_sp); + + virtual bool + SaveFrameZeroState (RegisterCheckpoint &checkpoint) = 0; + + virtual bool + RestoreSaveFrameZero (const RegisterCheckpoint &checkpoint) = 0; + virtual lldb_private::Unwind * GetUnwinder () = 0; StackFrameList & GetStackFrameList (); - - void - SetStopInfo (lldb::StopInfoSP stop_info_sp) + + struct ThreadState { - m_actual_stop_info_sp = stop_info_sp; - } + uint32_t orig_stop_id; + lldb::StopInfoSP stop_info_sp; + RegisterCheckpoint register_backup; + }; //------------------------------------------------------------------ // Classes that inherit from Process can see and modify these @@ -713,10 +757,14 @@ lldb::StateType m_resume_state; ///< The state that indicates what this thread should do when the process is resumed. std::auto_ptr m_unwinder_ap; bool m_destroy_called; // This is used internally to make sure derived Thread classes call DestroyThread. + uint32_t m_thread_stop_reason_stop_id; // This is the stop id for which the StopInfo is valid. Can use this so you know that + // the thread's m_actual_stop_info_sp is current and you don't have to fetch it again + private: //------------------------------------------------------------------ // For Thread only //------------------------------------------------------------------ + DISALLOW_COPY_AND_ASSIGN (Thread); }; Modified: lldb/trunk/include/lldb/Target/ThreadPlan.h URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Target/ThreadPlan.h?rev=123869&r1=123868&r2=123869&view=diff ============================================================================== --- lldb/trunk/include/lldb/Target/ThreadPlan.h (original) +++ lldb/trunk/include/lldb/Target/ThreadPlan.h Wed Jan 19 20:03:18 2011 @@ -66,9 +66,21 @@ // its job, but it doesn't want that sub-plan to be the one that sets the StopInfo, then call SetPrivate on the // sub-plan when you create it, and the Thread will pass over that plan in reporting the reason for the stop. // -// When the plan is moved from the plan stack to the completed plan stack its DidPop method is called. You should -// undo anything that affects target state in this method so the target state is clear for new plans. -// But be sure to leave whatever state might be needed to correctly fill the StopInfo. +// Discarded plans: +// +// Your plan may also get discarded, i.e. moved from the plan stack to the "discarded plan stack". This can +// happen, for instance, if the plan is calling a function and the function call crashes and you want +// to unwind the attempt to call. So don't assume that your plan will always successfully stop. Which leads to: +// +// Cleaning up after your plans: +// +// When the plan is moved from the plan stack its WillPop method is always called, no matter why. Once it is +// moved off the plan stack it is done, and won't get a chance to run again. So you should +// undo anything that affects target state in this method. But be sure to leave the plan able to correctly +// fill the StopInfo, however. +// N.B. Don't wait to do clean up target state till the destructor, since that will usually get called when +// the target resumes, and you want to leave the target state correct for new plans in the time between when +// your plan gets unshipped and the next resume. // // Over the lifetime of the plan, various methods of the ThreadPlan are then called in response to changes of state in // the process we are debugging as follows: Modified: lldb/trunk/include/lldb/Target/ThreadPlanCallFunction.h URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Target/ThreadPlanCallFunction.h?rev=123869&r1=123868&r2=123869&view=diff ============================================================================== --- lldb/trunk/include/lldb/Target/ThreadPlanCallFunction.h (original) +++ lldb/trunk/include/lldb/Target/ThreadPlanCallFunction.h Wed Jan 19 20:03:18 2011 @@ -103,6 +103,7 @@ lldb::ThreadPlanSP m_subplan_sp; LanguageRuntime *m_cxx_language_runtime; LanguageRuntime *m_objc_language_runtime; + Thread::ThreadStateCheckpoint m_stored_thread_state; DISALLOW_COPY_AND_ASSIGN (ThreadPlanCallFunction); }; Modified: lldb/trunk/lldb.xcodeproj/project.pbxproj URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/lldb.xcodeproj/project.pbxproj?rev=123869&r1=123868&r2=123869&view=diff ============================================================================== --- lldb/trunk/lldb.xcodeproj/project.pbxproj (original) +++ lldb/trunk/lldb.xcodeproj/project.pbxproj Wed Jan 19 20:03:18 2011 @@ -2370,7 +2370,6 @@ isa = PBXProject; buildConfigurationList = 1DEB91EF08733DB70010E9CD /* Build configuration list for PBXProject "lldb" */; compatibilityVersion = "Xcode 3.1"; - developmentRegion = English; hasScannedForEncodings = 1; knownRegions = ( en, Modified: lldb/trunk/source/Plugins/Process/Linux/LinuxThread.h URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Process/Linux/LinuxThread.h?rev=123869&r1=123868&r2=123869&view=diff ============================================================================== --- lldb/trunk/source/Plugins/Process/Linux/LinuxThread.h (original) +++ lldb/trunk/source/Plugins/Process/Linux/LinuxThread.h Wed Jan 19 20:03:18 2011 @@ -43,12 +43,6 @@ virtual lldb::RegisterContextSP GetRegisterContext(); - virtual bool - SaveFrameZeroState(RegisterCheckpoint &checkpoint); - - virtual bool - RestoreSaveFrameZero(const RegisterCheckpoint &checkpoint); - virtual lldb::RegisterContextSP CreateRegisterContextForFrame (lldb_private::StackFrame *frame); @@ -61,6 +55,13 @@ void TraceNotify(); void ExitNotify(); +protected: + virtual bool + SaveFrameZeroState(RegisterCheckpoint &checkpoint); + + virtual bool + RestoreSaveFrameZero(const RegisterCheckpoint &checkpoint); + private: RegisterContextLinux * Modified: lldb/trunk/source/Plugins/Process/MacOSX-User/source/ThreadMacOSX.h URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Process/MacOSX-User/source/ThreadMacOSX.h?rev=123869&r1=123868&r2=123869&view=diff ============================================================================== --- lldb/trunk/source/Plugins/Process/MacOSX-User/source/ThreadMacOSX.h (original) +++ lldb/trunk/source/Plugins/Process/MacOSX-User/source/ThreadMacOSX.h Wed Jan 19 20:03:18 2011 @@ -45,12 +45,6 @@ virtual lldb::RegisterContextSP CreateRegisterContextForFrame (lldb_private::StackFrame *frame); - virtual bool - SaveFrameZeroState (RegisterCheckpoint &checkpoint); - - virtual bool - RestoreSaveFrameZero (const RegisterCheckpoint &checkpoint); - virtual void ClearStackFrames (); @@ -124,6 +118,12 @@ GetPrivateStopReason (); protected: + virtual bool + SaveFrameZeroState (RegisterCheckpoint &checkpoint); + + virtual bool + RestoreSaveFrameZero (const RegisterCheckpoint &checkpoint); + bool GetIdentifierInfo (); Modified: lldb/trunk/source/Plugins/Process/gdb-remote/ThreadGDBRemote.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Process/gdb-remote/ThreadGDBRemote.cpp?rev=123869&r1=123868&r2=123869&view=diff ============================================================================== --- lldb/trunk/source/Plugins/Process/gdb-remote/ThreadGDBRemote.cpp (original) +++ lldb/trunk/source/Plugins/Process/gdb-remote/ThreadGDBRemote.cpp Wed Jan 19 20:03:18 2011 @@ -37,8 +37,7 @@ Thread(process, tid), m_thread_name (), m_dispatch_queue_name (), - m_thread_dispatch_qaddr (LLDB_INVALID_ADDRESS), - m_thread_stop_reason_stop_id (0) + m_thread_dispatch_qaddr (LLDB_INVALID_ADDRESS) { // ProcessGDBRemoteLog::LogIf(GDBR_LOG_THREAD | GDBR_LOG_VERBOSE, "ThreadGDBRemote::ThreadGDBRemote ( pid = %i, tid = 0x%4.4x, )", m_process.GetID(), GetID()); ProcessGDBRemoteLog::LogIf(GDBR_LOG_THREAD, "%p: ThreadGDBRemote::ThreadGDBRemote (pid = %i, tid = 0x%4.4x)", this, m_process.GetID(), GetID()); Modified: lldb/trunk/source/Plugins/Process/gdb-remote/ThreadGDBRemote.h URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Process/gdb-remote/ThreadGDBRemote.h?rev=123869&r1=123868&r2=123869&view=diff ============================================================================== --- lldb/trunk/source/Plugins/Process/gdb-remote/ThreadGDBRemote.h (original) +++ lldb/trunk/source/Plugins/Process/gdb-remote/ThreadGDBRemote.h Wed Jan 19 20:03:18 2011 @@ -47,12 +47,6 @@ virtual lldb::RegisterContextSP CreateRegisterContextForFrame (lldb_private::StackFrame *frame); - virtual bool - SaveFrameZeroState (RegisterCheckpoint &checkpoint); - - virtual bool - RestoreSaveFrameZero (const RegisterCheckpoint &checkpoint); - virtual void ClearStackFrames (); @@ -81,12 +75,6 @@ GetBasicInfoAsString (); void - SetStopInfo (const lldb::StopInfoSP &stop_info) - { - m_actual_stop_info_sp = stop_info; - } - - void SetName (const char *name) { if (name && name[0]) @@ -111,6 +99,12 @@ friend class ProcessGDBRemote; + virtual bool + SaveFrameZeroState (RegisterCheckpoint &checkpoint); + + virtual bool + RestoreSaveFrameZero (const RegisterCheckpoint &checkpoint); + void PrivateSetRegisterValue (uint32_t reg, StringExtractor &response); @@ -121,7 +115,6 @@ std::string m_thread_name; std::string m_dispatch_queue_name; lldb::addr_t m_thread_dispatch_qaddr; - uint32_t m_thread_stop_reason_stop_id; //------------------------------------------------------------------ // Member variables. //------------------------------------------------------------------ Modified: lldb/trunk/source/Target/Process.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Target/Process.cpp?rev=123869&r1=123868&r2=123869&view=diff ============================================================================== --- lldb/trunk/source/Target/Process.cpp (original) +++ lldb/trunk/source/Target/Process.cpp Wed Jan 19 20:03:18 2011 @@ -2567,6 +2567,12 @@ { ExecutionResults return_value = eExecutionSetupError; + if (thread_plan_sp.get() == NULL) + { + errors.Printf("RunThreadPlan called with empty thread plan."); + return lldb::eExecutionSetupError; + } + // Save this value for restoration of the execution context after we run uint32_t tid = exe_ctx.thread->GetIndexID(); @@ -2592,6 +2598,14 @@ Listener listener("ClangFunction temporary listener"); exe_ctx.process->HijackProcessEvents(&listener); + lldb::LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_STEP)); + if (log) + { + StreamString s; + thread_plan_sp->GetDescription(&s, lldb::eDescriptionLevelVerbose); + log->Printf ("Resuming thread 0x%x to run thread plan \"%s\".", tid, s.GetData()); + } + Error resume_error = exe_ctx.process->Resume (); if (!resume_error.Success()) { @@ -2616,7 +2630,6 @@ timeout_ptr = &real_timeout; } - lldb::LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_STEP)); while (1) { lldb::EventSP event_sp; Modified: lldb/trunk/source/Target/StopInfo.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Target/StopInfo.cpp?rev=123869&r1=123868&r2=123869&view=diff ============================================================================== --- lldb/trunk/source/Target/StopInfo.cpp (original) +++ lldb/trunk/source/Target/StopInfo.cpp Wed Jan 19 20:03:18 2011 @@ -41,6 +41,12 @@ return m_thread.GetProcess().GetStopID() == m_stop_id; } +void +StopInfo::MakeStopInfoValid () +{ + m_stop_id = m_thread.GetProcess().GetStopID(); +} + //---------------------------------------------------------------------- // StopInfoBreakpoint //---------------------------------------------------------------------- Modified: lldb/trunk/source/Target/Thread.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Target/Thread.cpp?rev=123869&r1=123868&r2=123869&view=diff ============================================================================== --- lldb/trunk/source/Target/Thread.cpp (original) +++ lldb/trunk/source/Target/Thread.cpp Wed Jan 19 20:03:18 2011 @@ -55,7 +55,8 @@ m_resume_signal (LLDB_INVALID_SIGNAL_NUMBER), m_resume_state (eStateRunning), m_unwinder_ap (), - m_destroy_called (false) + m_destroy_called (false), + m_thread_stop_reason_stop_id (0) { LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_OBJECT)); @@ -95,12 +96,48 @@ return GetPrivateStopReason (); } +void +Thread::SetStopInfo (const lldb::StopInfoSP &stop_info_sp) +{ + m_actual_stop_info_sp = stop_info_sp; + m_thread_stop_reason_stop_id = GetProcess().GetStopID(); +} + +void +Thread::SetStopInfoToNothing() +{ + // Note, we can't just NULL out the private reason, or the native thread implementation will try to + // go calculate it again. For now, just set it to a Unix Signal with an invalid signal number. + SetStopInfo (StopInfo::CreateStopReasonWithSignal (*this, LLDB_INVALID_SIGNAL_NUMBER)); +} + bool Thread::ThreadStoppedForAReason (void) { return GetPrivateStopReason () != NULL; } +bool +Thread::CheckpointThreadState (ThreadStateCheckpoint &saved_state) +{ + if (!SaveFrameZeroState(saved_state.register_backup)) + return false; + + saved_state.stop_info_sp = GetStopInfo(); + saved_state.orig_stop_id = GetProcess().GetStopID(); + + return true; +} + +bool +Thread::RestoreThreadStateFromCheckpoint (ThreadStateCheckpoint &saved_state) +{ + RestoreSaveFrameZero(saved_state.register_backup); + saved_state.stop_info_sp->MakeStopInfoValid(); + SetStopInfo(saved_state.stop_info_sp); + return true; +} + StateType Thread::GetState() const { Modified: lldb/trunk/source/Target/ThreadPlanCallFunction.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Target/ThreadPlanCallFunction.cpp?rev=123869&r1=123868&r2=123869&view=diff ============================================================================== --- lldb/trunk/source/Target/ThreadPlanCallFunction.cpp (original) +++ lldb/trunk/source/Target/ThreadPlanCallFunction.cpp Wed Jan 19 20:03:18 2011 @@ -59,6 +59,8 @@ if (!abi) return; + LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_STEP)); + SetBreakpoints(); lldb::addr_t spBelowRedZone = thread.GetRegisterContext()->GetSP() - abi->GetRedZoneSize(); @@ -76,9 +78,16 @@ m_start_addr = context.symbol->GetValue(); lldb::addr_t StartLoadAddr = m_start_addr.GetLoadAddress(&target); - if (!thread.SaveFrameZeroState(m_register_backup)) + // Checkpoint the thread state so we can restore it later. + if (!thread.CheckpointThreadState (m_stored_thread_state)) + { + if (log) + log->Printf ("Setting up ThreadPlanCallFunction, failed to checkpoint thread state."); return; - + } + // Now set the thread state to "no reason" so we don't run with whatever signal was outstanding... + thread.SetStopInfoToNothing(); + m_function_addr = function; lldb::addr_t FunctionLoadAddr = m_function_addr.GetLoadAddress(&target); @@ -91,8 +100,6 @@ cmd_arg)) return; - LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_STEP)); - if (log) { RegisterContext *reg_ctx = m_thread.GetRegisterContext().get(); @@ -115,24 +122,24 @@ ThreadPlanCallFunction::~ThreadPlanCallFunction () { - if (m_valid && !IsPlanComplete()) DoTakedown(); } void ThreadPlanCallFunction::DoTakedown () { - m_thread.RestoreSaveFrameZero(m_register_backup); - m_thread.ClearStackFrames(); - SetPlanComplete(); - ClearBreakpoints(); + if (m_valid && !IsPlanComplete()) + { + m_thread.RestoreThreadStateFromCheckpoint(m_stored_thread_state); + SetPlanComplete(); + ClearBreakpoints(); + } } void ThreadPlanCallFunction::WillPop () { - if (m_valid && !IsPlanComplete()) - DoTakedown(); + DoTakedown(); } void @@ -278,6 +285,7 @@ m_subplan_sp.reset(new ThreadPlanRunToAddress(m_thread, m_start_addr, m_stop_other_threads)); m_thread.QueueThreadPlan(m_subplan_sp, false); + m_subplan_sp->SetPrivate (true); #endif } Modified: lldb/trunk/source/Target/UnixSignals.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Target/UnixSignals.cpp?rev=123869&r1=123868&r2=123869&view=diff ============================================================================== --- lldb/trunk/source/Target/UnixSignals.cpp (original) +++ lldb/trunk/source/Target/UnixSignals.cpp Wed Jan 19 20:03:18 2011 @@ -66,7 +66,7 @@ AddSignal (3, "SIGQUIT", "QUIT", false, true, true, "quit"); AddSignal (4, "SIGILL", "ILL", false, true, true, "illegal instruction"); AddSignal (5, "SIGTRAP", "TRAP", true, true, true, "trace trap (not reset when caught)"); - AddSignal (6, "SIGABRT", "ABRT", true, true, true, "abort()"); + AddSignal (6, "SIGABRT", "ABRT", false, true, true, "abort()"); AddSignal (7, "SIGEMT", "EMT", false, true, true, "pollable event"); AddSignal (8, "SIGFPE", "FPE", false, true, true, "floating point exception"); AddSignal (9, "SIGKILL", "KILL", false, true, true, "kill"); From gclayton at apple.com Wed Jan 19 22:18:48 2011 From: gclayton at apple.com (Greg Clayton) Date: Thu, 20 Jan 2011 04:18:48 -0000 Subject: [Lldb-commits] [lldb] r123881 - in /lldb/trunk: lldb.xcodeproj/project.pbxproj source/Symbol/ClangASTContext.cpp Message-ID: <20110120041848.EDE8B2A6C12E@llvm.org> Author: gclayton Date: Wed Jan 19 22:18:48 2011 New Revision: 123881 URL: http://llvm.org/viewvc/llvm-project?rev=123881&view=rev Log: Fixed the auto completion of objective C types with the new ExternalASTSource changes that recently happened. Modified: lldb/trunk/lldb.xcodeproj/project.pbxproj lldb/trunk/source/Symbol/ClangASTContext.cpp Modified: lldb/trunk/lldb.xcodeproj/project.pbxproj URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/lldb.xcodeproj/project.pbxproj?rev=123881&r1=123880&r2=123881&view=diff ============================================================================== --- lldb/trunk/lldb.xcodeproj/project.pbxproj (original) +++ lldb/trunk/lldb.xcodeproj/project.pbxproj Wed Jan 19 22:18:48 2011 @@ -2370,6 +2370,7 @@ isa = PBXProject; buildConfigurationList = 1DEB91EF08733DB70010E9CD /* Build configuration list for PBXProject "lldb" */; compatibilityVersion = "Xcode 3.1"; + developmentRegion = English; hasScannedForEncodings = 1; knownRegions = ( en, Modified: lldb/trunk/source/Symbol/ClangASTContext.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Symbol/ClangASTContext.cpp?rev=123881&r1=123880&r2=123881&view=diff ============================================================================== --- lldb/trunk/source/Symbol/ClangASTContext.cpp (original) +++ lldb/trunk/source/Symbol/ClangASTContext.cpp Wed Jan 19 22:18:48 2011 @@ -118,8 +118,9 @@ external_ast_source->CompleteType (class_interface_decl); is_forward_decl = class_interface_decl->isForwardDecl(); } + return is_forward_decl == false; } - return is_forward_decl; + return true; } } break; @@ -1056,7 +1057,7 @@ if (cxx_record_decl) { cxx_record_decl->setHasExternalLexicalStorage (has_extern); - //cxx_record_decl->setHasExternalVisibleStorage (has_extern); + cxx_record_decl->setHasExternalVisibleStorage (has_extern); return true; } } @@ -1068,7 +1069,7 @@ if (enum_decl) { enum_decl->setHasExternalLexicalStorage (has_extern); - //enum_decl->setHasExternalVisibleStorage (has_extern); + enum_decl->setHasExternalVisibleStorage (has_extern); return true; } } @@ -1086,7 +1087,7 @@ if (class_interface_decl) { class_interface_decl->setHasExternalLexicalStorage (has_extern); - //class_interface_decl->setHasExternalVisibleStorage (has_extern); + class_interface_decl->setHasExternalVisibleStorage (has_extern); return true; } } @@ -1459,7 +1460,16 @@ cxx_method_decl->setParams (params, num_params); cxx_record_decl->addDecl (cxx_method_decl); - + +// printf ("decl->isPolymorphic() = %i\n", cxx_record_decl->isPolymorphic()); +// printf ("decl->isAggregate() = %i\n", cxx_record_decl->isAggregate()); +// printf ("decl->isPOD() = %i\n", cxx_record_decl->isPOD()); +// printf ("decl->isEmpty() = %i\n", cxx_record_decl->isEmpty()); +// printf ("decl->isAbstract() = %i\n", cxx_record_decl->isAbstract()); +// printf ("decl->hasTrivialConstructor() = %i\n", cxx_record_decl->hasTrivialConstructor()); +// printf ("decl->hasTrivialCopyConstructor() = %i\n", cxx_record_decl->hasTrivialCopyConstructor()); +// printf ("decl->hasTrivialCopyAssignment() = %i\n", cxx_record_decl->hasTrivialCopyAssignment()); +// printf ("decl->hasTrivialDestructor() = %i\n", cxx_record_decl->hasTrivialDestructor()); return cxx_method_decl; } @@ -2120,7 +2130,7 @@ case clang::Type::Complex: return 0; case clang::Type::Record: - if (ClangASTContext::GetCompleteType (ast, clang_type)) + if (GetCompleteQualType (ast, qual_type)) { const RecordType *record_type = cast(qual_type.getTypePtr()); const RecordDecl *record_decl = record_type->getDecl(); @@ -2163,6 +2173,7 @@ case clang::Type::ObjCObject: case clang::Type::ObjCInterface: + if (GetCompleteQualType (ast, qual_type)) { ObjCObjectType *objc_class_type = dyn_cast(qual_type.getTypePtr()); assert (objc_class_type); @@ -2427,7 +2438,7 @@ break; case clang::Type::Record: - if (ClangASTContext::GetCompleteType (ast, parent_clang_type)) + if (GetCompleteQualType (ast, parent_qual_type)) { const RecordType *record_type = cast(parent_qual_type.getTypePtr()); const RecordDecl *record_decl = record_type->getDecl(); @@ -2517,6 +2528,7 @@ case clang::Type::ObjCObject: case clang::Type::ObjCInterface: + if (GetCompleteQualType (ast, parent_qual_type)) { ObjCObjectType *objc_class_type = dyn_cast(parent_qual_type.getTypePtr()); assert (objc_class_type); @@ -2958,7 +2970,7 @@ switch (type_class) { case clang::Type::Record: - if (ClangASTContext::GetCompleteType (ast, clang_type)) + if (GetCompleteQualType (ast, qual_type)) { const RecordType *record_type = cast(qual_type.getTypePtr()); const RecordDecl *record_decl = record_type->getDecl(); @@ -3047,6 +3059,7 @@ case clang::Type::ObjCObject: case clang::Type::ObjCInterface: + if (GetCompleteQualType (ast, qual_type)) { StringRef name_sref(name); ObjCObjectType *objc_class_type = dyn_cast(qual_type.getTypePtr()); @@ -3238,7 +3251,7 @@ switch (type_class) { case clang::Type::Record: - if (ClangASTContext::GetCompleteType (ast, clang_type)) + if (GetCompleteQualType (ast, qual_type)) { const RecordType *record_type = cast(qual_type.getTypePtr()); const RecordDecl *record_decl = record_type->getDecl(); @@ -3282,6 +3295,7 @@ case clang::Type::ObjCObject: case clang::Type::ObjCInterface: + if (GetCompleteQualType (ast, qual_type)) { StringRef name_sref(name); ObjCObjectType *objc_class_type = dyn_cast(qual_type.getTypePtr()); @@ -4354,8 +4368,7 @@ if (clang_type == NULL) return false; - clang::QualType qual_type(clang::QualType::getFromOpaquePtr(clang_type)); - return GetCompleteQualType (ast, qual_type); + return GetCompleteQualType (ast, clang::QualType::getFromOpaquePtr(clang_type)); } From gclayton at apple.com Thu Jan 20 00:08:59 2011 From: gclayton at apple.com (Greg Clayton) Date: Thu, 20 Jan 2011 06:08:59 -0000 Subject: [Lldb-commits] [lldb] r123889 - in /lldb/trunk: include/lldb/Symbol/Symtab.h source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDebugMap.cpp source/Symbol/Symtab.cpp Message-ID: <20110120060859.423F62A6C12E@llvm.org> Author: gclayton Date: Thu Jan 20 00:08:59 2011 New Revision: 123889 URL: http://llvm.org/viewvc/llvm-project?rev=123889&view=rev Log: Made the DWARF + debug map symbol file parser be much more efficient when it isn't going to actually be used as the symbol file plug-in by looking only for suitable N_OSO symbols and avoiding sorting function (N_FUN) and global/static (N_GSYM/N_STSYM) symbols when there are no suitable N_OSO objects. Modified: lldb/trunk/include/lldb/Symbol/Symtab.h lldb/trunk/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDebugMap.cpp lldb/trunk/source/Symbol/Symtab.cpp Modified: lldb/trunk/include/lldb/Symbol/Symtab.h URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Symbol/Symtab.h?rev=123889&r1=123888&r2=123889&view=diff ============================================================================== --- lldb/trunk/include/lldb/Symbol/Symtab.h (original) +++ lldb/trunk/include/lldb/Symbol/Symtab.h Thu Jan 20 00:08:59 2011 @@ -55,6 +55,7 @@ Symbol * FindSymbolWithType (lldb::SymbolType symbol_type, Debug symbol_debug_type, Visibility symbol_visibility, uint32_t &start_idx); // const Symbol * FindSymbolWithType (lldb::SymbolType symbol_type, Debug symbol_debug_type, Visibility symbol_visibility, uint32_t &start_idx) const; uint32_t AppendSymbolIndexesWithType (lldb::SymbolType symbol_type, std::vector& indexes, uint32_t start_idx = 0, uint32_t end_index = UINT32_MAX) const; + uint32_t AppendSymbolIndexesWithTypeAndFlagsValue (lldb::SymbolType symbol_type, uint32_t flags_value, std::vector& indexes, uint32_t start_idx = 0, uint32_t end_index = UINT32_MAX) const; uint32_t AppendSymbolIndexesWithType (lldb::SymbolType symbol_type, Debug symbol_debug_type, Visibility symbol_visibility, std::vector& matches, uint32_t start_idx = 0, uint32_t end_index = UINT32_MAX) const; uint32_t AppendSymbolIndexesWithName (const ConstString& symbol_name, std::vector& matches); uint32_t AppendSymbolIndexesWithName (const ConstString& symbol_name, Debug symbol_debug_type, Visibility symbol_visibility, std::vector& matches); Modified: lldb/trunk/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDebugMap.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDebugMap.cpp?rev=123889&r1=123888&r2=123889&view=diff ============================================================================== --- lldb/trunk/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDebugMap.cpp (original) +++ lldb/trunk/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDebugMap.cpp Thu Jan 20 00:08:59 2011 @@ -103,18 +103,29 @@ Symtab* symtab = m_obj_file->GetSymtab(); if (symtab) { - //StreamFile s(0, 4, eByteOrderHost, stdout); std::vector oso_indexes; - const uint32_t oso_index_count = symtab->AppendSymbolIndexesWithType(eSymbolTypeObjectFile, oso_indexes); +// StreamFile s(stdout); +// symtab->Dump(&s, NULL, eSortOrderNone); - symtab->AppendSymbolIndexesWithType (eSymbolTypeCode, Symtab::eDebugYes, Symtab::eVisibilityAny, m_func_indexes); - symtab->AppendSymbolIndexesWithType (eSymbolTypeData, Symtab::eDebugYes, Symtab::eVisibilityAny, m_glob_indexes); + // When a mach-o symbol is encoded, the n_type field is encoded in bits + // 23:16, and the n_desc field is encoded in bits 15:0. + // + // To find all N_OSO entries that are part of the DWARF + debug map + // we find only object file symbols with the flags value as follows: + // bits 23:16 == 0x66 (N_OSO) + // bits 15: 0 == 0x0001 (specifies this is a debug map object file) + const uint32_t k_oso_symbol_flags_value = 0x660001u; - symtab->SortSymbolIndexesByValue(m_func_indexes, true); - symtab->SortSymbolIndexesByValue(m_glob_indexes, true); + const uint32_t oso_index_count = symtab->AppendSymbolIndexesWithTypeAndFlagsValue(eSymbolTypeObjectFile, k_oso_symbol_flags_value, oso_indexes); if (oso_index_count > 0) { + symtab->AppendSymbolIndexesWithType (eSymbolTypeCode, Symtab::eDebugYes, Symtab::eVisibilityAny, m_func_indexes); + symtab->AppendSymbolIndexesWithType (eSymbolTypeData, Symtab::eDebugYes, Symtab::eVisibilityAny, m_glob_indexes); + + symtab->SortSymbolIndexesByValue(m_func_indexes, true); + symtab->SortSymbolIndexesByValue(m_glob_indexes, true); + m_compile_unit_infos.resize(oso_index_count); // s.Printf("%s N_OSO symbols:\n", __PRETTY_FUNCTION__); // symtab->Dump(&s, oso_indexes); Modified: lldb/trunk/source/Symbol/Symtab.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Symbol/Symtab.cpp?rev=123889&r1=123888&r2=123889&view=diff ============================================================================== --- lldb/trunk/source/Symbol/Symtab.cpp (original) +++ lldb/trunk/source/Symbol/Symtab.cpp Thu Jan 20 00:08:59 2011 @@ -332,6 +332,24 @@ } uint32_t +Symtab::AppendSymbolIndexesWithTypeAndFlagsValue (SymbolType symbol_type, uint32_t flags_value, std::vector& indexes, uint32_t start_idx, uint32_t end_index) const +{ + Mutex::Locker locker (m_mutex); + + uint32_t prev_size = indexes.size(); + + const uint32_t count = std::min (m_symbols.size(), end_index); + + for (uint32_t i = start_idx; i < count; ++i) + { + if ((symbol_type == eSymbolTypeAny || m_symbols[i].GetType() == symbol_type) && m_symbols[i].GetFlags() == flags_value) + indexes.push_back(i); + } + + return indexes.size() - prev_size; +} + +uint32_t Symtab::AppendSymbolIndexesWithType (SymbolType symbol_type, Debug symbol_debug_type, Visibility symbol_visibility, std::vector& indexes, uint32_t start_idx, uint32_t end_index) const { Mutex::Locker locker (m_mutex); From gclayton at apple.com Thu Jan 20 01:53:46 2011 From: gclayton at apple.com (Greg Clayton) Date: Thu, 20 Jan 2011 07:53:46 -0000 Subject: [Lldb-commits] [lldb] r123903 - in /lldb/trunk/source/Plugins/Process/gdb-remote: GDBRemoteCommunication.cpp GDBRemoteCommunication.h Message-ID: <20110120075346.2167D2A6C12E@llvm.org> Author: gclayton Date: Thu Jan 20 01:53:45 2011 New Revision: 123903 URL: http://llvm.org/viewvc/llvm-project?rev=123903&view=rev Log: Fixed the async packets (packets that need to be sent to the GDB server while the inferior is running) to be fast. The previous code would always cause the sender to timeout, yet still return success due to the way we were waiting for a value (incorrect value) to change. Now the ProcessGDBRemote plug-in has a public and private "is running" predicate. This allows things that need to send async packets to interrupt and wait for the private "is running" state to be flipped to false, and then resume quickly with no timeout. Modified: lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.cpp lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.h Modified: lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.cpp?rev=123903&r1=123902&r2=123903&view=diff ============================================================================== --- lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.cpp (original) +++ lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.cpp Thu Jan 20 01:53:45 2011 @@ -37,7 +37,8 @@ m_thread_suffix_supported (false), m_rx_packet_listener ("gdbremote.rx_packet"), m_sequence_mutex (Mutex::eMutexTypeRecursive), - m_is_running (false), + m_public_is_running (false), + m_private_is_running (false), m_async_mutex (Mutex::eMutexTypeRecursive), m_async_packet_predicate (false), m_async_packet (), @@ -206,7 +207,8 @@ state = eStateInvalid; BroadcastEvent(eBroadcastBitRunPacketSent, NULL); - m_is_running.SetValue (true, eBroadcastNever); + m_public_is_running.SetValue (true, eBroadcastNever); + m_private_is_running.SetValue (true, eBroadcastNever); while (state == eStateRunning) { @@ -229,6 +231,11 @@ { case 'T': case 'S': + // Privately notify any internal threads that we have stopped + // in case we wanted to interrupt our process, yet we might + // send a packet and continue without returning control to the + // user. + m_private_is_running.SetValue (false, eBroadcastAlways); if (m_async_signal != -1) { if (async_log) @@ -272,11 +279,14 @@ if (async_log) async_log->Printf ("async: error: failed to resume with %s", Host::GetSignalAsCString (async_signal)); - state = eStateInvalid; + state = eStateExited; break; } else + { + m_private_is_running.SetValue (true, eBroadcastNever); continue; + } } } else if (m_async_packet_predicate.GetValue()) @@ -307,11 +317,15 @@ // Continue again if (SendPacket("c", 1) == 0) { - state = eStateInvalid; + // Failed to send the continue packet + state = eStateExited; break; } else + { + m_private_is_running.SetValue (true, eBroadcastNever); continue; + } } // Stop with signal and thread info state = eStateStopped; @@ -358,7 +372,8 @@ if (log) log->Printf ("GDBRemoteCommunication::%s () => %s", __FUNCTION__, StateAsCString(state)); response.SetFilePos(0); - m_is_running.SetValue (false, eBroadcastAlways); + m_private_is_running.SetValue (false, eBroadcastAlways); + m_public_is_running.SetValue (false, eBroadcastAlways); return state; } @@ -470,7 +485,7 @@ if (Write (&ctrl_c, 1, status, NULL) > 0) { if (seconds_to_wait_for_stop) - m_is_running.WaitForValueEqualTo (false, &timeout, timed_out); + m_private_is_running.WaitForValueEqualTo (false, &timeout, timed_out); return true; } } @@ -481,6 +496,7 @@ size_t GDBRemoteCommunication::WaitForPacket (StringExtractorGDBRemote &response, uint32_t timeout_seconds) { + Mutex::Locker locker(m_sequence_mutex); TimeValue timeout_time; timeout_time = TimeValue::Now(); timeout_time.OffsetWithSeconds (timeout_seconds); Modified: lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.h URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.h?rev=123903&r1=123902&r2=123903&view=diff ============================================================================== --- lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.h (original) +++ lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.h Thu Jan 20 01:53:45 2011 @@ -215,7 +215,7 @@ bool IsRunning() const { - return m_is_running.GetValue(); + return m_public_is_running.GetValue(); } bool @@ -260,7 +260,8 @@ m_thread_suffix_supported:1; lldb_private::Listener m_rx_packet_listener; lldb_private::Mutex m_sequence_mutex; // Restrict access to sending/receiving packets to a single thread at a time - lldb_private::Predicate m_is_running; + lldb_private::Predicate m_public_is_running; + lldb_private::Predicate m_private_is_running; // If we need to send a packet while the target is running, the m_async_XXX // member variables take care of making this happen. From johnny.chen at apple.com Thu Jan 20 11:40:51 2011 From: johnny.chen at apple.com (Johnny Chen) Date: Thu, 20 Jan 2011 17:40:51 -0000 Subject: [Lldb-commits] [lldb] r123924 - /lldb/trunk/test/objc-stepping/TestObjCStepping.py Message-ID: <20110120174051.EEA472A6C12C@llvm.org> Author: johnny Date: Thu Jan 20 11:40:51 2011 New Revision: 123924 URL: http://llvm.org/viewvc/llvm-project?rev=123924&view=rev Log: Remove the expectedFailure decorators. The bug: rdar://problem/8875425 Found mySource->isa local variable assertion failed has been fixed. Modified: lldb/trunk/test/objc-stepping/TestObjCStepping.py Modified: lldb/trunk/test/objc-stepping/TestObjCStepping.py URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/objc-stepping/TestObjCStepping.py?rev=123924&r1=123923&r2=123924&view=diff ============================================================================== --- lldb/trunk/test/objc-stepping/TestObjCStepping.py (original) +++ lldb/trunk/test/objc-stepping/TestObjCStepping.py Thu Jan 20 11:40:51 2011 @@ -9,8 +9,6 @@ mydir = "objc-stepping" - # rdar://problem/8875425 Found mySource->isa local variable assertion failed - @unittest2.expectedFailure @unittest2.skipUnless(sys.platform.startswith("darwin"), "requires Darwin") @python_api_test def test_with_dsym_and_python_api(self): @@ -18,8 +16,6 @@ self.buildDsym() self.objc_stepping() - # rdar://problem/8875425 Found mySource->isa local variable assertion failed - @unittest2.expectedFailure @python_api_test def test_with_dwarf_and_python_api(self): """Test stepping through ObjC method dispatch in various forms.""" From gclayton at apple.com Thu Jan 20 13:27:18 2011 From: gclayton at apple.com (Greg Clayton) Date: Thu, 20 Jan 2011 19:27:18 -0000 Subject: [Lldb-commits] [lldb] r123938 - in /lldb/trunk: include/lldb/Target/StackFrame.h source/Commands/CommandObjectFrame.cpp source/Target/StackFrame.cpp source/Target/Target.cpp Message-ID: <20110120192718.977A12A6C12E@llvm.org> Author: gclayton Date: Thu Jan 20 13:27:18 2011 New Revision: 123938 URL: http://llvm.org/viewvc/llvm-project?rev=123938&view=rev Log: Added the ability to StackFrame::GetValueForVariableExpressionPath(...) to avoid fragile ivars if requested. This was done by changing the previous second parameter to an options bitfield that can be populated by logical OR'ing the new StackFrame::ExpressionPathOption enum values together: typedef enum ExpressionPathOption { eExpressionPathOptionCheckPtrVsMember = (1u << 0), eExpressionPathOptionsNoFragileObjcIvar = (1u << 1), }; So the old function was: lldb::ValueObjectSP StackFrame::GetValueForVariableExpressionPath (const char *var_expr, bool check_ptr_vs_member, Error &error); But it is now: lldb::ValueObjectSP StackFrame::GetValueForVariableExpressionPath (const char *var_expr, uint32_t options, Error &error); This allows the expression parser in Target::EvaluateExpression(...) to avoid using simple frame variable expression paths when evaluating something that might be a fragile ivar. Modified: lldb/trunk/include/lldb/Target/StackFrame.h lldb/trunk/source/Commands/CommandObjectFrame.cpp lldb/trunk/source/Target/StackFrame.cpp lldb/trunk/source/Target/Target.cpp Modified: lldb/trunk/include/lldb/Target/StackFrame.h URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Target/StackFrame.h?rev=123938&r1=123937&r2=123938&view=diff ============================================================================== --- lldb/trunk/include/lldb/Target/StackFrame.h (original) +++ lldb/trunk/include/lldb/Target/StackFrame.h Thu Jan 20 13:27:18 2011 @@ -30,6 +30,11 @@ public ExecutionContextScope { public: + typedef enum ExpressionPathOption + { + eExpressionPathOptionCheckPtrVsMember = (1u << 0), + eExpressionPathOptionsNoFragileObjcIvar = (1u << 1) + }; //------------------------------------------------------------------ // Constructors and Destructors //------------------------------------------------------------------ @@ -96,8 +101,9 @@ VariableList * GetVariableList (bool get_file_globals); + // See ExpressionPathOption enumeration for "options" values lldb::ValueObjectSP - GetValueForVariableExpressionPath (const char *var_expr, bool check_ptr_vs_member, Error &error); + GetValueForVariableExpressionPath (const char *var_expr, uint32_t options, Error &error); bool HasDebugInformation (); Modified: lldb/trunk/source/Commands/CommandObjectFrame.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Commands/CommandObjectFrame.cpp?rev=123938&r1=123937&r2=123938&view=diff ============================================================================== --- lldb/trunk/source/Commands/CommandObjectFrame.cpp (original) +++ lldb/trunk/source/Commands/CommandObjectFrame.cpp Thu Jan 20 13:27:18 2011 @@ -588,8 +588,8 @@ else { Error error; - const bool check_ptr_vs_member = true; - valobj_sp = exe_ctx.frame->GetValueForVariableExpressionPath (name_cstr, check_ptr_vs_member, error); + const uint32_t expr_path_options = StackFrame::eExpressionPathOptionCheckPtrVsMember; + valobj_sp = exe_ctx.frame->GetValueForVariableExpressionPath (name_cstr, expr_path_options, error); if (valobj_sp) { if (m_options.show_decl && var_sp->GetDeclaration ().GetFile()) Modified: lldb/trunk/source/Target/StackFrame.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Target/StackFrame.cpp?rev=123938&r1=123937&r2=123938&view=diff ============================================================================== --- lldb/trunk/source/Target/StackFrame.cpp (original) +++ lldb/trunk/source/Target/StackFrame.cpp Thu Jan 20 13:27:18 2011 @@ -480,11 +480,13 @@ } ValueObjectSP -StackFrame::GetValueForVariableExpressionPath (const char *var_expr_cstr, bool check_ptr_vs_member, Error &error) +StackFrame::GetValueForVariableExpressionPath (const char *var_expr_cstr, uint32_t options, Error &error) { if (var_expr_cstr && var_expr_cstr[0]) { + const bool check_ptr_vs_member = (options & eExpressionPathOptionCheckPtrVsMember) != 0; + const bool no_fragile_ivar = (options & eExpressionPathOptionsNoFragileObjcIvar) != 0; error.Clear(); bool deref = false; bool address_of = false; @@ -536,6 +538,20 @@ if (var_path.size() >= 2 && var_path[1] != '>') return ValueObjectSP(); + if (no_fragile_ivar) + { + // Make sure we aren't trying to deref an objective + // C ivar if this is not allowed + const uint32_t pointer_type_flags = ClangASTContext::GetTypeInfo (valobj_sp->GetClangType(), NULL, NULL); + if ((pointer_type_flags & ClangASTContext::eTypeIsObjC) && + (pointer_type_flags & ClangASTContext::eTypeIsPointer)) + { + // This was an objective C object pointer and + // it was requested we skip any fragile ivars + // so return nothing here + return ValueObjectSP(); + } + } var_path.erase (0, 1); // Remove the '-' // Fall through case '.': Modified: lldb/trunk/source/Target/Target.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Target/Target.cpp?rev=123938&r1=123937&r2=123938&view=diff ============================================================================== --- lldb/trunk/source/Target/Target.cpp (original) +++ lldb/trunk/source/Target/Target.cpp Thu Jan 20 13:27:18 2011 @@ -923,8 +923,9 @@ { frame->CalculateExecutionContext(exe_ctx); Error error; - const bool check_ptr_vs_member = true; - result_valobj_sp = frame->GetValueForVariableExpressionPath (expr_cstr, check_ptr_vs_member, error); + const uint32_t expr_path_options = StackFrame::eExpressionPathOptionCheckPtrVsMember | + StackFrame::eExpressionPathOptionsNoFragileObjcIvar; + result_valobj_sp = frame->GetValueForVariableExpressionPath (expr_cstr, expr_path_options, error); } else if (m_process_sp) { From gclayton at apple.com Thu Jan 20 19:59:01 2011 From: gclayton at apple.com (Greg Clayton) Date: Fri, 21 Jan 2011 01:59:01 -0000 Subject: [Lldb-commits] [lldb] r123957 - in /lldb/trunk: include/lldb/API/SBType.h include/lldb/Core/ValueObject.h include/lldb/Core/ValueObjectChild.h include/lldb/Symbol/ClangASTContext.h include/lldb/Symbol/Type.h source/API/SBType.cpp source/Core/ValueObject.cpp source/Core/ValueObjectChild.cpp source/Symbol/ClangASTContext.cpp source/Symbol/Type.cpp Message-ID: <20110121015901.35D0D2A6C12C@llvm.org> Author: gclayton Date: Thu Jan 20 19:59:00 2011 New Revision: 123957 URL: http://llvm.org/viewvc/llvm-project?rev=123957&view=rev Log: Fixed up the SBValue::GetExpressionPath() to be more correct under more circumstances. Modified: lldb/trunk/include/lldb/API/SBType.h lldb/trunk/include/lldb/Core/ValueObject.h lldb/trunk/include/lldb/Core/ValueObjectChild.h lldb/trunk/include/lldb/Symbol/ClangASTContext.h lldb/trunk/include/lldb/Symbol/Type.h lldb/trunk/source/API/SBType.cpp lldb/trunk/source/Core/ValueObject.cpp lldb/trunk/source/Core/ValueObjectChild.cpp lldb/trunk/source/Symbol/ClangASTContext.cpp lldb/trunk/source/Symbol/Type.cpp Modified: lldb/trunk/include/lldb/API/SBType.h URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/API/SBType.h?rev=123957&r1=123956&r2=123957&view=diff ============================================================================== --- lldb/trunk/include/lldb/API/SBType.h (original) +++ lldb/trunk/include/lldb/API/SBType.h Thu Jan 20 19:59:00 2011 @@ -128,6 +128,7 @@ uint32_t m_bit_size; uint32_t m_bit_offset; bool m_is_base_class; + bool m_is_deref_of_paremt; }; Modified: lldb/trunk/include/lldb/Core/ValueObject.h URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Core/ValueObject.h?rev=123957&r1=123956&r2=123957&view=diff ============================================================================== --- lldb/trunk/include/lldb/Core/ValueObject.h (original) +++ lldb/trunk/include/lldb/Core/ValueObject.h Thu Jan 20 19:59:00 2011 @@ -86,6 +86,15 @@ { return false; } + + virtual bool + IsDereferenceOfParent () + { + return false; + } + + virtual bool + GetBaseClassPath (Stream &s); virtual void GetExpressionPath (Stream &s, bool qualify_cxx_base_classes); @@ -276,7 +285,10 @@ { return m_parent; } - + + ValueObject * + GetNonBaseClassParent(); + void SetPointersPointToLoadAddrs (bool b) { @@ -312,7 +324,8 @@ m_value_did_change:1, m_children_count_valid:1, m_old_value_valid:1, - m_pointers_point_to_load_addrs:1; + m_pointers_point_to_load_addrs:1, + m_is_deref_of_parent:1; friend class CommandObjectExpression; friend class ClangExpressionVariable; Modified: lldb/trunk/include/lldb/Core/ValueObjectChild.h URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Core/ValueObjectChild.h?rev=123957&r1=123956&r2=123957&view=diff ============================================================================== --- lldb/trunk/include/lldb/Core/ValueObjectChild.h (original) +++ lldb/trunk/include/lldb/Core/ValueObjectChild.h Thu Jan 20 19:59:00 2011 @@ -32,7 +32,8 @@ int32_t byte_offset, uint32_t bitfield_bit_size, uint32_t bitfield_bit_offset, - bool is_base_class); + bool is_base_class, + bool is_deref_of_parent); virtual ~ValueObjectChild(); @@ -94,6 +95,12 @@ return m_is_base_class; } + virtual bool + IsDereferenceOfParent () + { + return m_is_deref_of_parent; + } + protected: clang::ASTContext *m_clang_ast; // The clang AST that the clang type comes from void *m_clang_type; // The type of the child in question within the parent (m_parent_sp) @@ -103,6 +110,7 @@ uint8_t m_bitfield_bit_size; uint8_t m_bitfield_bit_offset; bool m_is_base_class; + bool m_is_deref_of_parent; // // void Modified: lldb/trunk/include/lldb/Symbol/ClangASTContext.h URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Symbol/ClangASTContext.h?rev=123957&r1=123956&r2=123957&view=diff ============================================================================== --- lldb/trunk/include/lldb/Symbol/ClangASTContext.h (original) +++ lldb/trunk/include/lldb/Symbol/ClangASTContext.h Thu Jan 20 19:59:00 2011 @@ -393,8 +393,9 @@ int32_t &child_byte_offset, uint32_t &child_bitfield_bit_size, uint32_t &child_bitfield_bit_offset, - bool &child_is_base_class); - + bool &child_is_base_class, + bool &child_is_deref_of_parent); + static lldb::clang_type_t GetChildClangTypeAtIndex (clang::ASTContext *ast, const char *parent_name, @@ -407,7 +408,8 @@ int32_t &child_byte_offset, uint32_t &child_bitfield_bit_size, uint32_t &child_bitfield_bit_offset, - bool &child_is_base_class); + bool &child_is_base_class, + bool &child_is_deref_of_parent); // Lookup a child given a name. This function will match base class names // and member member names in "clang_type" only, not descendants. Modified: lldb/trunk/include/lldb/Symbol/Type.h URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Symbol/Type.h?rev=123957&r1=123956&r2=123957&view=diff ============================================================================== --- lldb/trunk/include/lldb/Symbol/Type.h (original) +++ lldb/trunk/include/lldb/Symbol/Type.h Thu Jan 20 19:59:00 2011 @@ -202,18 +202,6 @@ ClangASTContext & GetClangASTContext (); - lldb::clang_type_t - GetChildClangTypeAtIndex (const char *parent_name, - uint32_t idx, - bool transparent_pointers, - bool omit_empty_base_classes, - ConstString& name, - uint32_t &child_byte_size, - int32_t &child_byte_offset, - uint32_t &child_bitfield_bit_size, - uint32_t &child_bitfield_bit_offset, - bool &child_is_base_class); - static int Compare(const Type &a, const Type &b); Modified: lldb/trunk/source/API/SBType.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/API/SBType.cpp?rev=123957&r1=123956&r2=123957&view=diff ============================================================================== --- lldb/trunk/source/API/SBType.cpp (original) +++ lldb/trunk/source/API/SBType.cpp Thu Jan 20 19:59:00 2011 @@ -113,6 +113,7 @@ uint32_t child_bitfield_bit_size = 0; uint32_t child_bitfield_bit_offset = 0; bool child_is_base_class = false; + bool child_is_deref_of_parent = false; if (IsValid ()) { @@ -128,7 +129,8 @@ child_byte_offset, child_bitfield_bit_size, child_bitfield_bit_offset, - child_is_base_class); + child_is_base_class, + child_is_deref_of_parent); } @@ -142,6 +144,7 @@ member.m_bit_size = child_bitfield_bit_size; member.m_bit_offset = child_bitfield_bit_offset; member.m_is_base_class = child_is_base_class; + member.m_is_deref_of_paremt = child_is_deref_of_parent; } else { Modified: lldb/trunk/source/Core/ValueObject.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Core/ValueObject.cpp?rev=123957&r1=123956&r2=123957&view=diff ============================================================================== --- lldb/trunk/source/Core/ValueObject.cpp (original) +++ lldb/trunk/source/Core/ValueObject.cpp Thu Jan 20 19:59:00 2011 @@ -64,7 +64,8 @@ m_value_did_change (false), m_children_count_valid (false), m_old_value_valid (false), - m_pointers_point_to_load_addrs (false) + m_pointers_point_to_load_addrs (false), + m_is_deref_of_parent (false) { } @@ -367,6 +368,8 @@ uint32_t child_bitfield_bit_size = 0; uint32_t child_bitfield_bit_offset = 0; bool child_is_base_class = false; + bool child_is_deref_of_parent = false; + const bool transparent_pointers = synthetic_array_member == false; clang::ASTContext *clang_ast = GetClangAST(); clang_type_t clang_type = GetClangType(); @@ -382,7 +385,8 @@ child_byte_offset, child_bitfield_bit_size, child_bitfield_bit_offset, - child_is_base_class); + child_is_base_class, + child_is_deref_of_parent); if (child_clang_type && child_byte_size) { if (synthetic_index) @@ -400,7 +404,8 @@ child_byte_offset, child_bitfield_bit_size, child_bitfield_bit_offset, - child_is_base_class)); + child_is_base_class, + child_is_deref_of_parent)); if (m_pointers_point_to_load_addrs) valobj_sp->SetPointersPointToLoadAddrs (m_pointers_point_to_load_addrs); } @@ -931,47 +936,90 @@ return true; } +bool +ValueObject::GetBaseClassPath (Stream &s) +{ + if (IsBaseClass()) + { + bool parent_had_base_class = m_parent && m_parent->GetBaseClassPath (s); + clang_type_t clang_type = GetClangType(); + std::string cxx_class_name; + bool this_had_base_class = ClangASTContext::GetCXXClassName (clang_type, cxx_class_name); + if (this_had_base_class) + { + if (parent_had_base_class) + s.PutCString("::"); + s.PutCString(cxx_class_name.c_str()); + } + return parent_had_base_class || this_had_base_class; + } + return false; +} + + +ValueObject * +ValueObject::GetNonBaseClassParent() +{ + if (m_parent) + { + if (m_parent->IsBaseClass()) + return m_parent->GetNonBaseClassParent(); + else + return m_parent; + } + return NULL; +} void ValueObject::GetExpressionPath (Stream &s, bool qualify_cxx_base_classes) { + const bool is_deref_of_parent = IsDereferenceOfParent (); + + if (is_deref_of_parent) + s.PutCString("*("); + if (m_parent) - { m_parent->GetExpressionPath (s, qualify_cxx_base_classes); - clang_type_t parent_clang_type = m_parent->GetClangType(); - if (parent_clang_type) + + if (!IsBaseClass()) + { + if (!is_deref_of_parent) { - if (ClangASTContext::IsPointerType(parent_clang_type)) + ValueObject *non_base_class_parent = GetNonBaseClassParent(); + if (non_base_class_parent) { - s.PutCString("->"); + clang_type_t non_base_class_parent_clang_type = non_base_class_parent->GetClangType(); + if (non_base_class_parent_clang_type) + { + const uint32_t non_base_class_parent_type_info = ClangASTContext::GetTypeInfo (non_base_class_parent_clang_type, NULL, NULL); + + if (non_base_class_parent_type_info & ClangASTContext::eTypeIsPointer) + { + s.PutCString("->"); + } + else if ((non_base_class_parent_type_info & ClangASTContext::eTypeHasChildren) && + !(non_base_class_parent_type_info & ClangASTContext::eTypeIsArray)) + { + s.PutChar('.'); + } + } } - else if (ClangASTContext::IsAggregateType (parent_clang_type)) + + const char *name = GetName().GetCString(); + if (name) { - if (ClangASTContext::IsArrayType (parent_clang_type) == false && - m_parent->IsBaseClass() == false) - s.PutChar('.'); + if (qualify_cxx_base_classes) + { + if (GetBaseClassPath (s)) + s.PutCString("::"); + } + s.PutCString(name); } } } - if (IsBaseClass()) - { - if (qualify_cxx_base_classes) - { - clang_type_t clang_type = GetClangType(); - std::string cxx_class_name; - if (ClangASTContext::GetCXXClassName (clang_type, cxx_class_name)) - { - s << cxx_class_name.c_str() << "::"; - } - } - } - else - { - const char *name = GetName().GetCString(); - if (name) - s.PutCString(name); - } + if (is_deref_of_parent) + s.PutChar(')'); } void @@ -1012,7 +1060,7 @@ s.Indent(); // Always show the type for the top level items. - if (show_types || curr_depth == 0) + if (show_types || (curr_depth == 0 && !flat_output)) s.Printf("(%s) ", valobj->GetTypeName().AsCString("")); @@ -1223,6 +1271,7 @@ uint32_t child_bitfield_bit_size = 0; uint32_t child_bitfield_bit_offset = 0; bool child_is_base_class = false; + bool child_is_deref_of_parent = false; const bool transparent_pointers = false; clang::ASTContext *clang_ast = GetClangAST(); clang_type_t clang_type = GetClangType(); @@ -1238,7 +1287,8 @@ child_byte_offset, child_bitfield_bit_size, child_bitfield_bit_offset, - child_is_base_class); + child_is_base_class, + child_is_deref_of_parent); if (child_clang_type && child_byte_size) { ConstString child_name; @@ -1253,7 +1303,8 @@ child_byte_offset, child_bitfield_bit_size, child_bitfield_bit_offset, - child_is_base_class)); + child_is_base_class, + child_is_deref_of_parent)); } } Modified: lldb/trunk/source/Core/ValueObjectChild.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Core/ValueObjectChild.cpp?rev=123957&r1=123956&r2=123957&view=diff ============================================================================== --- lldb/trunk/source/Core/ValueObjectChild.cpp (original) +++ lldb/trunk/source/Core/ValueObjectChild.cpp Thu Jan 20 19:59:00 2011 @@ -34,7 +34,8 @@ int32_t byte_offset, uint32_t bitfield_bit_size, uint32_t bitfield_bit_offset, - bool is_base_class + bool is_base_class, + bool is_deref_of_parent ) : ValueObject (parent), m_clang_ast (clang_ast), @@ -43,7 +44,8 @@ m_byte_offset (byte_offset), m_bitfield_bit_size (bitfield_bit_size), m_bitfield_bit_offset (bitfield_bit_offset), - m_is_base_class (is_base_class) + m_is_base_class (is_base_class), + m_is_deref_of_parent (is_deref_of_parent) { m_name = name; } Modified: lldb/trunk/source/Symbol/ClangASTContext.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Symbol/ClangASTContext.cpp?rev=123957&r1=123956&r2=123957&view=diff ============================================================================== --- lldb/trunk/source/Symbol/ClangASTContext.cpp (original) +++ lldb/trunk/source/Symbol/ClangASTContext.cpp Thu Jan 20 19:59:00 2011 @@ -2373,7 +2373,8 @@ int32_t &child_byte_offset, uint32_t &child_bitfield_bit_size, uint32_t &child_bitfield_bit_offset, - bool &child_is_base_class + bool &child_is_base_class, + bool &child_is_deref_of_parent ) { if (parent_clang_type) @@ -2389,7 +2390,8 @@ child_byte_offset, child_bitfield_bit_size, child_bitfield_bit_offset, - child_is_base_class); + child_is_base_class, + child_is_deref_of_parent); return NULL; } @@ -2407,7 +2409,8 @@ int32_t &child_byte_offset, uint32_t &child_bitfield_bit_size, uint32_t &child_bitfield_bit_offset, - bool &child_is_base_class + bool &child_is_base_class, + bool &child_is_deref_of_parent ) { if (parent_clang_type == NULL) @@ -2612,6 +2615,8 @@ if (transparent_pointers && ClangASTContext::IsAggregateType (pointee_type.getAsOpaquePtr())) { + child_is_deref_of_parent = false; + bool tmp_child_is_deref_of_parent = false; return GetChildClangTypeAtIndex (ast, parent_name, pointer_type->getPointeeType().getAsOpaquePtr(), @@ -2623,10 +2628,12 @@ child_byte_offset, child_bitfield_bit_size, child_bitfield_bit_offset, - child_is_base_class); + child_is_base_class, + tmp_child_is_deref_of_parent); } else { + child_is_deref_of_parent = true; if (parent_name) { child_name.assign(1, '*'); @@ -2681,6 +2688,8 @@ if (transparent_pointers && ClangASTContext::IsAggregateType (pointee_type.getAsOpaquePtr())) { + child_is_deref_of_parent = false; + bool tmp_child_is_deref_of_parent = false; return GetChildClangTypeAtIndex (ast, parent_name, pointer_type->getPointeeType().getAsOpaquePtr(), @@ -2692,10 +2701,13 @@ child_byte_offset, child_bitfield_bit_size, child_bitfield_bit_offset, - child_is_base_class); + child_is_base_class, + tmp_child_is_deref_of_parent); } else { + child_is_deref_of_parent = true; + if (parent_name) { child_name.assign(1, '*'); @@ -2723,6 +2735,8 @@ clang_type_t pointee_clang_type = pointee_type.getAsOpaquePtr(); if (transparent_pointers && ClangASTContext::IsAggregateType (pointee_clang_type)) { + child_is_deref_of_parent = false; + bool tmp_child_is_deref_of_parent = false; return GetChildClangTypeAtIndex (ast, parent_name, pointee_clang_type, @@ -2734,7 +2748,8 @@ child_byte_offset, child_bitfield_bit_size, child_bitfield_bit_offset, - child_is_base_class); + child_is_base_class, + tmp_child_is_deref_of_parent); } else { @@ -2769,7 +2784,8 @@ child_byte_offset, child_bitfield_bit_size, child_bitfield_bit_offset, - child_is_base_class); + child_is_base_class, + child_is_deref_of_parent); break; default: Modified: lldb/trunk/source/Symbol/Type.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Symbol/Type.cpp?rev=123957&r1=123956&r2=123957&view=diff ============================================================================== --- lldb/trunk/source/Symbol/Type.cpp (original) +++ lldb/trunk/source/Symbol/Type.cpp Thu Jan 20 19:59:00 2011 @@ -559,50 +559,6 @@ } return m_clang_type != NULL; } - -clang_type_t -lldb_private::Type::GetChildClangTypeAtIndex -( - const char *parent_name, - uint32_t idx, - bool transparent_pointers, - bool omit_empty_base_classes, - ConstString& name, - uint32_t &child_byte_size, - int32_t &child_byte_offset, - uint32_t &child_bitfield_bit_size, - uint32_t &child_bitfield_bit_offset, - bool &child_is_base_class -) -{ - clang_type_t child_qual_type = NULL; - - if (GetClangType()) - { - std::string name_str; - child_qual_type = GetClangASTContext().GetChildClangTypeAtIndex (parent_name, - m_clang_type, - idx, - transparent_pointers, - omit_empty_base_classes, - name_str, - child_byte_size, - child_byte_offset, - child_bitfield_bit_size, - child_bitfield_bit_offset, - child_is_base_class); - - if (child_qual_type) - { - if (!name_str.empty()) - name.SetCString(name_str.c_str()); - else - name.Clear(); - } - } - return child_qual_type; -} - uint32_t lldb_private::Type::GetEncodingMask () { From gclayton at apple.com Fri Jan 21 00:11:59 2011 From: gclayton at apple.com (Greg Clayton) Date: Fri, 21 Jan 2011 06:11:59 -0000 Subject: [Lldb-commits] [lldb] r123970 - in /lldb/trunk: include/lldb/API/ include/lldb/Target/ source/API/ source/Commands/ source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/ source/Target/ Message-ID: <20110121061159.4D1D22A6C12C@llvm.org> Author: gclayton Date: Fri Jan 21 00:11:58 2011 New Revision: 123970 URL: http://llvm.org/viewvc/llvm-project?rev=123970&view=rev Log: Added support for stepping out of a frame. If you have 10 stack frames, and you select frame #3, you can then do a step out and be able to go directly to the frame above frame #3! Added StepOverUntil and StepOutOfFrame to the SBThread API to allow more powerful stepping. Modified: lldb/trunk/include/lldb/API/SBError.h lldb/trunk/include/lldb/API/SBFrame.h lldb/trunk/include/lldb/API/SBThread.h lldb/trunk/include/lldb/Target/Thread.h lldb/trunk/include/lldb/Target/ThreadPlanStepOut.h lldb/trunk/include/lldb/Target/ThreadPlanStepUntil.h lldb/trunk/source/API/SBFrame.cpp lldb/trunk/source/API/SBThread.cpp lldb/trunk/source/Commands/CommandObjectThread.cpp lldb/trunk/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleThreadPlanStepThroughObjCTrampoline.cpp lldb/trunk/source/Target/Thread.cpp lldb/trunk/source/Target/ThreadPlanStepInRange.cpp lldb/trunk/source/Target/ThreadPlanStepInstruction.cpp lldb/trunk/source/Target/ThreadPlanStepOut.cpp lldb/trunk/source/Target/ThreadPlanStepOverRange.cpp lldb/trunk/source/Target/ThreadPlanStepUntil.cpp Modified: lldb/trunk/include/lldb/API/SBError.h URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/API/SBError.h?rev=123970&r1=123969&r2=123970&view=diff ============================================================================== --- lldb/trunk/include/lldb/API/SBError.h (original) +++ lldb/trunk/include/lldb/API/SBError.h Fri Jan 21 00:11:58 2011 @@ -72,17 +72,18 @@ GetDescription (lldb::SBStream &description) const; protected: + +#ifndef SWIG friend class SBArguments; friend class SBDebugger; friend class SBCommunication; friend class SBHostOS; friend class SBInputReader; friend class SBProcess; + friend class SBThread; friend class SBTarget; friend class SBValue; -#ifndef SWIG - lldb_private::Error * get(); Modified: lldb/trunk/include/lldb/API/SBFrame.h URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/API/SBFrame.h?rev=123970&r1=123969&r2=123970&view=diff ============================================================================== --- lldb/trunk/include/lldb/API/SBFrame.h (original) +++ lldb/trunk/include/lldb/API/SBFrame.h Fri Jan 21 00:11:58 2011 @@ -146,6 +146,9 @@ lldb_private::StackFrame * get() const; + const lldb::StackFrameSP & + get_sp() const; + #endif Modified: lldb/trunk/include/lldb/API/SBThread.h URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/API/SBThread.h?rev=123970&r1=123969&r2=123970&view=diff ============================================================================== --- lldb/trunk/include/lldb/API/SBThread.h (original) +++ lldb/trunk/include/lldb/API/SBThread.h Fri Jan 21 00:11:58 2011 @@ -85,8 +85,16 @@ StepOut (); void + StepOutOfFrame (lldb::SBFrame &frame); + + void StepInstruction(bool step_over); + SBError + StepOverUntil (lldb::SBFrame &frame, + lldb::SBFileSpec &file_spec, + uint32_t line); + void RunToAddress (lldb::addr_t addr); Modified: lldb/trunk/include/lldb/Target/Thread.h URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Target/Thread.h?rev=123970&r1=123969&r2=123970&view=diff ============================================================================== --- lldb/trunk/include/lldb/Target/Thread.h (original) +++ lldb/trunk/include/lldb/Target/Thread.h Fri Jan 21 00:11:58 2011 @@ -481,8 +481,9 @@ SymbolContext *addr_context, bool first_insn, bool stop_other_threads, - lldb::Vote stop_vote = lldb::eVoteYes, - lldb::Vote run_vote = lldb::eVoteNoOpinion); + lldb::Vote stop_vote, // = lldb::eVoteYes, + lldb::Vote run_vote, // = lldb::eVoteNoOpinion); + uint32_t frame_idx); //------------------------------------------------------------------ /// Gets the plan used to step through the code that steps from a function @@ -527,9 +528,10 @@ virtual ThreadPlan * QueueThreadPlanForStepUntil (bool abort_other_plans, - lldb::addr_t *address_list, - size_t num_addresses, - bool stop_others); + lldb::addr_t *address_list, + size_t num_addresses, + bool stop_others, + uint32_t frame_idx); virtual ThreadPlan * QueueThreadPlanForCallFunction (bool abort_other_plans, Modified: lldb/trunk/include/lldb/Target/ThreadPlanStepOut.h URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Target/ThreadPlanStepOut.h?rev=123970&r1=123969&r2=123970&view=diff ============================================================================== --- lldb/trunk/include/lldb/Target/ThreadPlanStepOut.h (original) +++ lldb/trunk/include/lldb/Target/ThreadPlanStepOut.h Fri Jan 21 00:11:58 2011 @@ -40,13 +40,14 @@ bool first_insn, bool stop_others, lldb::Vote stop_vote, - lldb::Vote run_vote); + lldb::Vote run_vote, + uint32_t frame_idx); protected: private: SymbolContext *m_step_from_context; lldb::addr_t m_step_from_insn; - uint64_t m_stack_depth; + uint32_t m_stack_depth; lldb::break_id_t m_return_bp_id; lldb::addr_t m_return_addr; bool m_first_insn; @@ -58,7 +59,8 @@ bool first_insn, bool stop_others, lldb::Vote stop_vote, - lldb::Vote run_vote); + lldb::Vote run_vote, + uint32_t frame_idx); // Need an appropriate marker for the current stack so we can tell step out // from step in. Modified: lldb/trunk/include/lldb/Target/ThreadPlanStepUntil.h URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Target/ThreadPlanStepUntil.h?rev=123970&r1=123969&r2=123970&view=diff ============================================================================== --- lldb/trunk/include/lldb/Target/ThreadPlanStepUntil.h (original) +++ lldb/trunk/include/lldb/Target/ThreadPlanStepUntil.h Fri Jan 21 00:11:58 2011 @@ -45,7 +45,8 @@ ThreadPlanStepUntil (Thread &thread, lldb::addr_t *address_list, size_t num_addresses, - bool stop_others); + bool stop_others, + uint32_t frame_idx = 0); void AnalyzeStop(void); private: @@ -67,9 +68,10 @@ friend ThreadPlan * Thread::QueueThreadPlanForStepUntil (bool abort_other_plans, - lldb::addr_t *address_list, - size_t num_addresses, - bool stop_others); + lldb::addr_t *address_list, + size_t num_addresses, + bool stop_others, + uint32_t frame_idx); // Need an appropriate marker for the current stack so we can tell step out // from step in. Modified: lldb/trunk/source/API/SBFrame.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/API/SBFrame.cpp?rev=123970&r1=123969&r2=123970&view=diff ============================================================================== --- lldb/trunk/source/API/SBFrame.cpp (original) +++ lldb/trunk/source/API/SBFrame.cpp Fri Jan 21 00:11:58 2011 @@ -511,6 +511,11 @@ return m_opaque_sp.get(); } +const lldb::StackFrameSP & +SBFrame::get_sp() const +{ + return m_opaque_sp; +} SBThread SBFrame::GetThread () const Modified: lldb/trunk/source/API/SBThread.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/API/SBThread.cpp?rev=123970&r1=123969&r2=123970&view=diff ============================================================================== --- lldb/trunk/source/API/SBThread.cpp (original) +++ lldb/trunk/source/API/SBThread.cpp Fri Jan 21 00:11:58 2011 @@ -492,8 +492,53 @@ bool abort_other_plans = true; bool stop_other_threads = true; - m_opaque_sp->QueueThreadPlanForStepOut (abort_other_plans, NULL, false, stop_other_threads, eVoteYes, eVoteNoOpinion); + m_opaque_sp->QueueThreadPlanForStepOut (abort_other_plans, + NULL, + false, + stop_other_threads, + eVoteYes, + eVoteNoOpinion, + 0); + + Process &process = m_opaque_sp->GetProcess(); + process.GetThreadList().SetSelectedThreadByID (m_opaque_sp->GetID()); + Error error (process.Resume()); + if (error.Success()) + { + // If we are doing synchronous mode, then wait for the + // process to stop yet again! + if (process.GetTarget().GetDebugger().GetAsyncExecution () == false) + process.WaitForProcessToStop (NULL); + } + } +} + +void +SBThread::StepOutOfFrame (lldb::SBFrame &sb_frame) +{ + LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); + if (log) + { + SBStream frame_desc_strm; + sb_frame.GetDescription (frame_desc_strm); + log->Printf ("SBThread(%p)::StepOutOfFrame (frame = SBFrame(%p): %s)", m_opaque_sp.get(), sb_frame.get(), frame_desc_strm.GetData()); + } + + if (m_opaque_sp) + { + Mutex::Locker api_locker (m_opaque_sp->GetProcess().GetTarget().GetAPIMutex()); + bool abort_other_plans = true; + bool stop_other_threads = true; + + m_opaque_sp->QueueThreadPlanForStepOut (abort_other_plans, + NULL, + false, + stop_other_threads, + eVoteYes, + eVoteNoOpinion, + sb_frame->GetFrameIndex()); + Process &process = m_opaque_sp->GetProcess(); process.GetThreadList().SetSelectedThreadByID (m_opaque_sp->GetID()); Error error (process.Resume()); @@ -559,9 +604,141 @@ process.WaitForProcessToStop (NULL); } } +} + +SBError +SBThread::StepOverUntil (lldb::SBFrame &sb_frame, + lldb::SBFileSpec &sb_file_spec, + uint32_t line) +{ + SBError sb_error; + LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); + char path[PATH_MAX]; + if (log) + { + SBStream frame_desc_strm; + sb_frame.GetDescription (frame_desc_strm); + sb_file_spec->GetPath (path, sizeof(path)); + log->Printf ("SBThread(%p)::StepOverUntil (frame = SBFrame(%p): %s, file+line = %s:%u)", + m_opaque_sp.get(), + sb_frame.get(), + frame_desc_strm.GetData(), + path, line); + } + + if (m_opaque_sp) + { + Mutex::Locker api_locker (m_opaque_sp->GetProcess().GetTarget().GetAPIMutex()); + + if (line == 0) + { + sb_error.SetErrorString("invalid line argument"); + return sb_error; + } + + StackFrameSP frame_sp; + if (sb_frame.IsValid()) + frame_sp = sb_frame.get_sp(); + else + { + frame_sp = m_opaque_sp->GetSelectedFrame (); + if (!frame_sp) + frame_sp = m_opaque_sp->GetStackFrameAtIndex (0); + } + + SymbolContext frame_sc; + if (!frame_sp) + { + sb_error.SetErrorString("no valid frames in thread to step"); + return sb_error; + } + + // If we have a frame, get its line + frame_sc = frame_sp->GetSymbolContext (eSymbolContextCompUnit | + eSymbolContextFunction | + eSymbolContextLineEntry | + eSymbolContextSymbol ); + + if (frame_sc.comp_unit == NULL) + { + sb_error.SetErrorStringWithFormat("frame %u doesn't have debug information", frame_sp->GetFrameIndex()); + return sb_error; + } + + FileSpec step_file_spec; + if (sb_file_spec.IsValid()) + { + // The file spec passed in was valid, so use it + step_file_spec = sb_file_spec.ref(); + } + else + { + if (frame_sc.line_entry.IsValid()) + step_file_spec = frame_sc.line_entry.file; + else + { + sb_error.SetErrorString("invalid file argument or no file for frame"); + return sb_error; + } + } + + std::vector step_over_until_addrs; + const bool abort_other_plans = true; + const bool stop_other_threads = true; + const bool check_inlines = true; + const bool exact = false; + + SymbolContextList sc_list; + const uint32_t num_matches = frame_sc.comp_unit->ResolveSymbolContext (step_file_spec, line, check_inlines, exact, eSymbolContextLineEntry, sc_list); + if (num_matches > 0) + { + SymbolContext sc; + for (uint32_t i=0; iGetProcess().GetTarget()); + if (step_addr != LLDB_INVALID_ADDRESS) + { + step_over_until_addrs.push_back(step_addr); + } + } + } + } + + if (step_over_until_addrs.empty()) + { + step_file_spec.GetPath (path, sizeof(path)); + sb_error.SetErrorStringWithFormat("No line entries for %s:u", path, line); + } + else + { + m_opaque_sp->QueueThreadPlanForStepUntil (abort_other_plans, + &step_over_until_addrs[0], + step_over_until_addrs.size(), + stop_other_threads, + frame_sp->GetFrameIndex()); + + m_opaque_sp->GetProcess().GetThreadList().SetSelectedThreadByID (m_opaque_sp->GetID()); + sb_error.ref() = m_opaque_sp->GetProcess().Resume(); + if (sb_error->Success()) + { + // If we are doing synchronous mode, then wait for the + // process to stop yet again! + if (m_opaque_sp->GetProcess().GetTarget().GetDebugger().GetAsyncExecution () == false) + m_opaque_sp->GetProcess().WaitForProcessToStop (NULL); + } + } + } + else + { + sb_error.SetErrorString("this SBThread object is invalid"); + } + return sb_error; } + bool SBThread::Suspend() { @@ -606,10 +783,10 @@ LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); if (log) { - SBStream sstr; - process.GetDescription (sstr); + SBStream frame_desc_strm; + process.GetDescription (frame_desc_strm); log->Printf ("SBThread(%p)::GetProcess () => SBProcess(%p): %s", m_opaque_sp.get(), - process.get(), sstr.GetData()); + process.get(), frame_desc_strm.GetData()); } return process; @@ -647,10 +824,10 @@ if (log) { - SBStream sstr; - sb_frame.GetDescription (sstr); + SBStream frame_desc_strm; + sb_frame.GetDescription (frame_desc_strm); log->Printf ("SBThread(%p)::GetFrameAtIndex (idx=%d) => SBFrame(%p): %s", - m_opaque_sp.get(), idx, sb_frame.get(), sstr.GetData()); + m_opaque_sp.get(), idx, sb_frame.get(), frame_desc_strm.GetData()); } return sb_frame; @@ -670,10 +847,10 @@ if (log) { - SBStream sstr; - sb_frame.GetDescription (sstr); + SBStream frame_desc_strm; + sb_frame.GetDescription (frame_desc_strm); log->Printf ("SBThread(%p)::GetSelectedFrame () => SBFrame(%p): %s", - m_opaque_sp.get(), sb_frame.get(), sstr.GetData()); + m_opaque_sp.get(), sb_frame.get(), frame_desc_strm.GetData()); } return sb_frame; @@ -698,10 +875,10 @@ if (log) { - SBStream sstr; - sb_frame.GetDescription (sstr); + SBStream frame_desc_strm; + sb_frame.GetDescription (frame_desc_strm); log->Printf ("SBThread(%p)::SetSelectedFrame (idx=%u) => SBFrame(%p): %s", - m_opaque_sp.get(), idx, sb_frame.get(), sstr.GetData()); + m_opaque_sp.get(), idx, sb_frame.get(), frame_desc_strm.GetData()); } return sb_frame; } Modified: lldb/trunk/source/Commands/CommandObjectThread.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Commands/CommandObjectThread.cpp?rev=123970&r1=123969&r2=123970&view=diff ============================================================================== --- lldb/trunk/source/Commands/CommandObjectThread.cpp (original) +++ lldb/trunk/source/Commands/CommandObjectThread.cpp Fri Jan 21 00:11:58 2011 @@ -729,7 +729,13 @@ { ThreadPlan *new_plan; - new_plan = thread->QueueThreadPlanForStepOut (abort_other_plans, NULL, false, bool_stop_other_threads, eVoteYes, eVoteNoOpinion); + new_plan = thread->QueueThreadPlanForStepOut (abort_other_plans, + NULL, + false, + bool_stop_other_threads, + eVoteYes, + eVoteNoOpinion, + thread->GetSelectedFrameIndex()); // FIXME: This will keep the step plan on the thread stack when we hit a breakpoint while stepping over. // Maybe there should be a parameter to control this. new_plan->SetOkayToDiscard(false); @@ -1208,7 +1214,7 @@ index_ptr++; } - new_plan = thread->QueueThreadPlanForStepUntil (abort_other_plans, &address_list.front(), address_list.size(), m_options.m_stop_others); + new_plan = thread->QueueThreadPlanForStepUntil (abort_other_plans, &address_list.front(), address_list.size(), m_options.m_stop_others, thread->GetSelectedFrameIndex ()); new_plan->SetOkayToDiscard(false); } else Modified: lldb/trunk/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleThreadPlanStepThroughObjCTrampoline.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleThreadPlanStepThroughObjCTrampoline.cpp?rev=123970&r1=123969&r2=123970&view=diff ============================================================================== --- lldb/trunk/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleThreadPlanStepThroughObjCTrampoline.cpp (original) +++ lldb/trunk/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleThreadPlanStepThroughObjCTrampoline.cpp Fri Jan 21 00:11:58 2011 @@ -129,7 +129,13 @@ log->Printf ("Implementation lookup returned msgForward function: 0x%llx, stopping.", target_addr); SymbolContext sc = m_thread.GetStackFrameAtIndex(0)->GetSymbolContext(eSymbolContextEverything); - m_run_to_sp.reset(new ThreadPlanStepOut(m_thread, &sc, true, m_stop_others, eVoteNoOpinion, eVoteNoOpinion)); + m_run_to_sp.reset(new ThreadPlanStepOut (m_thread, + &sc, + true, + m_stop_others, + eVoteNoOpinion, + eVoteNoOpinion, + 0)); m_thread.QueueThreadPlan(m_run_to_sp, false); m_run_to_sp->SetPrivate(true); return false; Modified: lldb/trunk/source/Target/Thread.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Target/Thread.cpp?rev=123970&r1=123969&r2=123970&view=diff ============================================================================== --- lldb/trunk/source/Target/Thread.cpp (original) +++ lldb/trunk/source/Target/Thread.cpp Fri Jan 21 00:11:58 2011 @@ -661,7 +661,12 @@ } ThreadPlan * -Thread::QueueThreadPlanForStepSingleInstruction (bool step_over, bool abort_other_plans, bool stop_other_threads) +Thread::QueueThreadPlanForStepSingleInstruction +( + bool step_over, + bool abort_other_plans, + bool stop_other_threads +) { ThreadPlanSP thread_plan_sp (new ThreadPlanStepInstruction (*this, step_over, stop_other_threads, eVoteNoOpinion, eVoteNoOpinion)); QueueThreadPlan (thread_plan_sp, abort_other_plans); @@ -706,10 +711,24 @@ } ThreadPlan * -Thread::QueueThreadPlanForStepOut (bool abort_other_plans, SymbolContext *addr_context, bool first_insn, - bool stop_other_threads, Vote stop_vote, Vote run_vote) +Thread::QueueThreadPlanForStepOut +( + bool abort_other_plans, + SymbolContext *addr_context, + bool first_insn, + bool stop_other_threads, + Vote stop_vote, + Vote run_vote, + uint32_t frame_idx +) { - ThreadPlanSP thread_plan_sp (new ThreadPlanStepOut (*this, addr_context, first_insn, stop_other_threads, stop_vote, run_vote)); + ThreadPlanSP thread_plan_sp (new ThreadPlanStepOut (*this, + addr_context, + first_insn, + stop_other_threads, + stop_vote, + run_vote, + frame_idx)); QueueThreadPlan (thread_plan_sp, abort_other_plans); return thread_plan_sp.get(); } @@ -761,11 +780,12 @@ ThreadPlan * Thread::QueueThreadPlanForStepUntil (bool abort_other_plans, - lldb::addr_t *address_list, - size_t num_addresses, - bool stop_other_threads) + lldb::addr_t *address_list, + size_t num_addresses, + bool stop_other_threads, + uint32_t frame_idx) { - ThreadPlanSP thread_plan_sp (new ThreadPlanStepUntil (*this, address_list, num_addresses, stop_other_threads)); + ThreadPlanSP thread_plan_sp (new ThreadPlanStepUntil (*this, address_list, num_addresses, stop_other_threads, frame_idx)); QueueThreadPlan (thread_plan_sp, abort_other_plans); return thread_plan_sp.get(); Modified: lldb/trunk/source/Target/ThreadPlanStepInRange.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Target/ThreadPlanStepInRange.cpp?rev=123970&r1=123969&r2=123970&view=diff ============================================================================== --- lldb/trunk/source/Target/ThreadPlanStepInRange.cpp (original) +++ lldb/trunk/source/Target/ThreadPlanStepInRange.cpp Fri Jan 21 00:11:58 2011 @@ -270,9 +270,13 @@ if (should_step_out) { // FIXME: Make sure the ThreadPlanForStepOut does the right thing with inlined functions. - return current_plan->GetThread().QueueThreadPlanForStepOut (false, NULL, true, + return current_plan->GetThread().QueueThreadPlanForStepOut (false, + NULL, + true, current_plan->StopOthers(), - eVoteNo, eVoteNoOpinion); + eVoteNo, + eVoteNoOpinion, + 0); // Frame index } return NULL; Modified: lldb/trunk/source/Target/ThreadPlanStepInstruction.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Target/ThreadPlanStepInstruction.cpp?rev=123970&r1=123969&r2=123970&view=diff ============================================================================== --- lldb/trunk/source/Target/ThreadPlanStepInstruction.cpp (original) +++ lldb/trunk/source/Target/ThreadPlanStepInstruction.cpp Fri Jan 21 00:11:58 2011 @@ -129,7 +129,7 @@ s.Address (return_addr, m_thread.GetProcess().GetAddressByteSize()); log->Printf("%s.", s.GetData()); } - m_thread.QueueThreadPlanForStepOut(false, NULL, true, m_stop_other_threads, eVoteNo, eVoteNoOpinion); + m_thread.QueueThreadPlanForStepOut(false, NULL, true, m_stop_other_threads, eVoteNo, eVoteNoOpinion, 0); return false; } else Modified: lldb/trunk/source/Target/ThreadPlanStepOut.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Target/ThreadPlanStepOut.cpp?rev=123970&r1=123969&r2=123970&view=diff ============================================================================== --- lldb/trunk/source/Target/ThreadPlanStepOut.cpp (original) +++ lldb/trunk/source/Target/ThreadPlanStepOut.cpp Fri Jan 21 00:11:58 2011 @@ -35,7 +35,8 @@ bool first_insn, bool stop_others, Vote stop_vote, - Vote run_vote + Vote run_vote, + uint32_t frame_idx ) : ThreadPlan (ThreadPlan::eKindStepOut, "Step out", thread, stop_vote, run_vote), m_step_from_context (context), @@ -50,24 +51,20 @@ // Find the return address and set a breakpoint there: // FIXME - can we do this more securely if we know first_insn? - StackFrame *return_frame = m_thread.GetStackFrameAtIndex(1).get(); - if (return_frame) + StackFrameSP return_frame_sp (m_thread.GetStackFrameAtIndex(frame_idx + 1)); + if (return_frame_sp) { // TODO: check for inlined frames and do the right thing... - m_return_addr = return_frame->GetRegisterContext()->GetPC(); + m_return_addr = return_frame_sp->GetRegisterContext()->GetPC(); Breakpoint *return_bp = m_thread.GetProcess().GetTarget().CreateBreakpoint (m_return_addr, true).get(); if (return_bp != NULL) { return_bp->SetThreadID(m_thread.GetID()); m_return_bp_id = return_bp->GetID(); } - else - { - m_return_bp_id = LLDB_INVALID_BREAK_ID; - } } - m_stack_depth = m_thread.GetStackFrameCount(); + m_stack_depth = m_thread.GetStackFrameCount() - frame_idx; } ThreadPlanStepOut::~ThreadPlanStepOut () @@ -116,6 +113,10 @@ BreakpointSiteSP site_sp (m_thread.GetProcess().GetBreakpointSiteList().FindByID (stop_info_sp->GetValue())); if (site_sp && site_sp->IsBreakpointAtThisSite (m_return_bp_id)) { + const uint32_t num_frames = m_thread.GetStackFrameCount(); + if (m_stack_depth > num_frames); + SetPlanComplete(); + // If there was only one owner, then we're done. But if we also hit some // user breakpoint on our way out, we should mark ourselves as done, but // also not claim to explain the stop, since it is more important to report @@ -124,7 +125,6 @@ if (site_sp->GetNumberOfOwners() == 1) return true; - SetPlanComplete(); } return false; } @@ -143,9 +143,7 @@ bool ThreadPlanStepOut::ShouldStop (Event *event_ptr) { - if (IsPlanComplete() - || m_thread.GetRegisterContext()->GetPC() == m_return_addr - || m_stack_depth > m_thread.GetStackFrameCount()) + if (IsPlanComplete() || m_stack_depth > m_thread.GetStackFrameCount()) { SetPlanComplete(); return true; Modified: lldb/trunk/source/Target/ThreadPlanStepOverRange.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Target/ThreadPlanStepOverRange.cpp?rev=123970&r1=123969&r2=123970&view=diff ============================================================================== --- lldb/trunk/source/Target/ThreadPlanStepOverRange.cpp (original) +++ lldb/trunk/source/Target/ThreadPlanStepOverRange.cpp Fri Jan 21 00:11:58 2011 @@ -104,7 +104,13 @@ } else if (FrameIsYounger()) { - new_plan = m_thread.QueueThreadPlanForStepOut (false, NULL, true, stop_others, lldb::eVoteNo, lldb::eVoteNoOpinion); + new_plan = m_thread.QueueThreadPlanForStepOut (false, + NULL, + true, + stop_others, + lldb::eVoteNo, + lldb::eVoteNoOpinion, + 0); } else if (!InSymbol()) { Modified: lldb/trunk/source/Target/ThreadPlanStepUntil.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Target/ThreadPlanStepUntil.cpp?rev=123970&r1=123969&r2=123970&view=diff ============================================================================== --- lldb/trunk/source/Target/ThreadPlanStepUntil.cpp (original) +++ lldb/trunk/source/Target/ThreadPlanStepUntil.cpp Fri Jan 21 00:11:58 2011 @@ -37,7 +37,8 @@ Thread &thread, lldb::addr_t *address_list, size_t num_addresses, - bool stop_others + bool stop_others, + uint32_t frame_idx ) : ThreadPlan (ThreadPlan::eKindStepUntil, "Step until", thread, eVoteNoOpinion, eVoteNoOpinion), m_stack_depth (0), @@ -56,40 +57,43 @@ // Stash away our "until" addresses: Target &target = m_thread.GetProcess().GetTarget(); - m_step_from_insn = m_thread.GetRegisterContext()->GetPC(0); - lldb::user_id_t thread_id = m_thread.GetID(); - - // Find the return address and set a breakpoint there: - // FIXME - can we do this more securely if we know first_insn? - - StackFrame *return_frame = m_thread.GetStackFrameAtIndex(1).get(); - // TODO: add inline functionality - m_return_addr = return_frame->GetRegisterContext()->GetPC(); - Breakpoint *return_bp = target.CreateBreakpoint (m_return_addr, true).get(); - if (return_bp != NULL) - { - return_bp->SetThreadID(thread_id); - m_return_bp_id = return_bp->GetID(); - } - else + StackFrameSP frame_sp (m_thread.GetStackFrameAtIndex (frame_idx)); + if (frame_sp) { - m_return_bp_id = LLDB_INVALID_BREAK_ID; - } + m_step_from_insn = frame_sp->GetStackID().GetPC(); + lldb::user_id_t thread_id = m_thread.GetID(); - m_stack_depth = m_thread.GetStackFrameCount(); + // Find the return address and set a breakpoint there: + // FIXME - can we do this more securely if we know first_insn? - // Now set breakpoints on all our return addresses: - for (int i = 0; i < num_addresses; i++) - { - Breakpoint *until_bp = target.CreateBreakpoint (address_list[i], true).get(); - if (until_bp != NULL) + StackFrameSP return_frame_sp (m_thread.GetStackFrameAtIndex(frame_idx + 1)); + if (return_frame_sp) { - until_bp->SetThreadID(thread_id); - m_until_points[address_list[i]] = until_bp->GetID(); + // TODO: add inline functionality + m_return_addr = return_frame_sp->GetStackID().GetPC(); + Breakpoint *return_bp = target.CreateBreakpoint (m_return_addr, true).get(); + if (return_bp != NULL) + { + return_bp->SetThreadID(thread_id); + m_return_bp_id = return_bp->GetID(); + } } - else + + m_stack_depth = m_thread.GetStackFrameCount() - frame_idx; + + // Now set breakpoints on all our return addresses: + for (int i = 0; i < num_addresses; i++) { - m_until_points[address_list[i]] = LLDB_INVALID_BREAK_ID; + Breakpoint *until_bp = target.CreateBreakpoint (address_list[i], true).get(); + if (until_bp != NULL) + { + until_bp->SetThreadID(thread_id); + m_until_points[address_list[i]] = until_bp->GetID(); + } + else + { + m_until_points[address_list[i]] = LLDB_INVALID_BREAK_ID; + } } } } From johnny.chen at apple.com Fri Jan 21 12:23:17 2011 From: johnny.chen at apple.com (Johnny Chen) Date: Fri, 21 Jan 2011 18:23:17 -0000 Subject: [Lldb-commits] [lldb] r123984 - in /lldb/trunk/test/stepping: ./ Makefile TestThreadStepping.py main.c Message-ID: <20110121182317.1915B2A6C12C@llvm.org> Author: johnny Date: Fri Jan 21 12:23:16 2011 New Revision: 123984 URL: http://llvm.org/viewvc/llvm-project?rev=123984&view=rev Log: Add test cases for the scenario of selecting a frame index while stopped, and then doing a thread step-out. This should lead us to the caller frame of the frame we just selected. Added: lldb/trunk/test/stepping/ lldb/trunk/test/stepping/Makefile lldb/trunk/test/stepping/TestThreadStepping.py lldb/trunk/test/stepping/main.c Added: lldb/trunk/test/stepping/Makefile URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/stepping/Makefile?rev=123984&view=auto ============================================================================== --- lldb/trunk/test/stepping/Makefile (added) +++ lldb/trunk/test/stepping/Makefile Fri Jan 21 12:23:16 2011 @@ -0,0 +1,5 @@ +LEVEL = ../make + +C_SOURCES := main.c + +include $(LEVEL)/Makefile.rules Added: lldb/trunk/test/stepping/TestThreadStepping.py URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/stepping/TestThreadStepping.py?rev=123984&view=auto ============================================================================== --- lldb/trunk/test/stepping/TestThreadStepping.py (added) +++ lldb/trunk/test/stepping/TestThreadStepping.py Fri Jan 21 12:23:16 2011 @@ -0,0 +1,95 @@ +""" +Test thread stepping features in combination with frame select. +""" + +import os, time +import re +import unittest2 +import lldb, lldbutil +from lldbtest import * + +class ThreadSteppingTestCase(TestBase): + + mydir = "stepping" + + @unittest2.skipUnless(sys.platform.startswith("darwin"), "requires Darwin") + def test_step_out_with_dsym_and_run_command(self): + """Exercise thread step-out and frame select followed by thread step-out.""" + self.buildDwarf() + self.thread_step_out() + + def test_step_out_with_dwarf_and_run_command(self): + """Exercise thread step-out and frame select followed by thread step-out.""" + self.buildDwarf() + self.thread_step_out() + + def setUp(self): + # Call super's setUp(). + TestBase.setUp(self) + # Find the line number to of function 'c'. + self.line1 = line_number('main.c', '// Find the line number of function "c" here.') + self.line2 = line_number('main.c', '// frame select 2, thread step-out while stopped at "c(1)"') + self.line3 = line_number('main.c', '// thread step-out while stopped at "c(2)"') + self.line4 = line_number('main.c', '// frame select 1, thread step-out while stopped at "c(3)"') + + def thread_step_out(self): + """Exercise thread step-out and frame select followed by thread step-out.""" + exe = os.path.join(os.getcwd(), "a.out") + self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET) + + # Create a breakpoint inside function 'c'. + self.expect("breakpoint set -f main.c -l %d" % self.line1, BREAKPOINT_CREATED, + startstr = "Breakpoint created: 1: file ='main.c', line = %d, locations = 1" % + self.line1) + + # Now run the program. + self.runCmd("run", RUN_SUCCEEDED) + + # The process should be stopped at this point. + self.expect("process status", PROCESS_STOPPED, + patterns = ['Process .* stopped']) + + # The frame #0 should correspond to main.c:32, the executable statement + # in function name 'c'. And frame #3 should point to main.c:37. + self.expect("thread backtrace", STOPPED_DUE_TO_BREAKPOINT, + substrs = ["stop reason = breakpoint"], + patterns = ["frame #0.*main.c:%d" % self.line1, + "frame #3.*main.c:%d" % self.line2]) + + # We want to move the pc to frame #3. This can be accomplished by + # 'frame select 2', followed by 'thread step-out'. + self.runCmd("frame select 2") + self.runCmd("thread step-out") + self.expect("thread backtrace", STEP_OUT_SUCCEEDED, + substrs = ["stop reason = step out"], + patterns = ["frame #0.*main.c:%d" % self.line2]) + + # Let's move on to a single step-out case. + self.runCmd("process continue") + + # The process should be stopped at this point. + self.expect("process status", PROCESS_STOPPED, + patterns = ['Process .* stopped']) + self.runCmd("thread step-out") + self.expect("thread backtrace", STEP_OUT_SUCCEEDED, + substrs = ["stop reason = step out"], + patterns = ["frame #0.*main.c:%d" % self.line3]) + + # Do another frame selct, followed by thread step-out. + self.runCmd("process continue") + + # The process should be stopped at this point. + self.expect("process status", PROCESS_STOPPED, + patterns = ['Process .* stopped']) + self.runCmd("frame select 1") + self.runCmd("thread step-out") + self.expect("thread backtrace", STEP_OUT_SUCCEEDED, + substrs = ["stop reason = step out"], + patterns = ["frame #0.*main.c:%d" % self.line4]) + + +if __name__ == '__main__': + import atexit + lldb.SBDebugger.Initialize() + atexit.register(lambda: lldb.SBDebugger.Terminate()) + unittest2.main() Added: lldb/trunk/test/stepping/main.c URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/stepping/main.c?rev=123984&view=auto ============================================================================== --- lldb/trunk/test/stepping/main.c (added) +++ lldb/trunk/test/stepping/main.c Fri Jan 21 12:23:16 2011 @@ -0,0 +1,48 @@ +//===-- main.c --------------------------------------------------*- C++ -*-===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +#include + +int a(int); +int b(int); +int c(int); + +int a(int val) +{ + if (val <= 1) + return b(val); + else if (val >= 3) + return c(val); + + return val; +} + +int b(int val) +{ + int rc = c(val); // thread step-out while stopped at "c(2)" + return rc; +} + +int c(int val) +{ + return val + 3; // Find the line number of function "c" here. +} + +int main (int argc, char const *argv[]) +{ + int A1 = a(1); // frame select 2, thread step-out while stopped at "c(1)" + printf("a(1) returns %d\n", A1); + + int B2 = b(2); + printf("b(2) returns %d\n", B2); + + int A3 = a(3); // frame select 1, thread step-out while stopped at "c(3)" + printf("a(3) returns %d\n", A3); + + return 0; +} From gclayton at apple.com Fri Jan 21 16:02:52 2011 From: gclayton at apple.com (Greg Clayton) Date: Fri, 21 Jan 2011 22:02:52 -0000 Subject: [Lldb-commits] [lldb] r123998 - in /lldb/trunk: lldb.xcodeproj/project.pbxproj source/Plugins/Process/Utility/EmulateInstruction.cpp source/Plugins/Process/Utility/EmulateInstruction.h source/Plugins/Process/Utility/EmulateInstructionARM.cpp source/Plugins/Process/Utility/EmulateInstructionARM.h Message-ID: <20110121220252.877522A6C12C@llvm.org> Author: gclayton Date: Fri Jan 21 16:02:52 2011 New Revision: 123998 URL: http://llvm.org/viewvc/llvm-project?rev=123998&view=rev Log: Added the start of opcode emulation for ARM instructions. This class is designed to be fed 4 callbacks: read/write memory, and read/write registers. After this, you can tell the object to read an instruction. This will cause the class to read the PC, and read and instruction. Then you can emulate the instruction by calling EvaluateInstruction. This will cause the class to figure out exactly what an opcode does, and call the read/write mem/regs functions with actual values which allows one to emulate an instruction without running a process, or it allows one to watch the context information (the memory write is a pushing register 3 onto the stack at offset 12) so it can be used for generating call frame information. This way, in the future, we will have one class that can be used to emulate instructions and generate our unwind info from assembly. Added: lldb/trunk/source/Plugins/Process/Utility/EmulateInstruction.cpp lldb/trunk/source/Plugins/Process/Utility/EmulateInstruction.h lldb/trunk/source/Plugins/Process/Utility/EmulateInstructionARM.cpp lldb/trunk/source/Plugins/Process/Utility/EmulateInstructionARM.h Modified: lldb/trunk/lldb.xcodeproj/project.pbxproj Modified: lldb/trunk/lldb.xcodeproj/project.pbxproj URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/lldb.xcodeproj/project.pbxproj?rev=123998&r1=123997&r2=123998&view=diff ============================================================================== --- lldb/trunk/lldb.xcodeproj/project.pbxproj (original) +++ lldb/trunk/lldb.xcodeproj/project.pbxproj Fri Jan 21 16:02:52 2011 @@ -15,6 +15,10 @@ 2618D7921240116900F2B8FE /* SectionLoadList.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 2618D7911240116900F2B8FE /* SectionLoadList.cpp */; }; 2618D9EB12406FE600F2B8FE /* NameToDIE.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 2618D9EA12406FE600F2B8FE /* NameToDIE.cpp */; }; 261B5A5411C3F2AD00AABD0A /* SharingPtr.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 261B5A5211C3F2AD00AABD0A /* SharingPtr.cpp */; }; + 2621C9CD12EA009300711A30 /* EmulateInstructionARM.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 2621C9CB12EA009300711A30 /* EmulateInstructionARM.cpp */; }; + 2621C9CE12EA009300711A30 /* EmulateInstruction.h in Headers */ = {isa = PBXBuildFile; fileRef = 2621C9CC12EA009300711A30 /* EmulateInstruction.h */; }; + 2621C9D012EA066500711A30 /* EmulateInstructionARM.h in Headers */ = {isa = PBXBuildFile; fileRef = 2621C9CF12EA066500711A30 /* EmulateInstructionARM.h */; }; + 2621CA0B12EA107700711A30 /* EmulateInstruction.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 2621CA0A12EA107700711A30 /* EmulateInstruction.cpp */; }; 262CFC7711A4510000946C6C /* debugserver in Resources */ = {isa = PBXBuildFile; fileRef = 26CE05A0115C31E50022F371 /* debugserver */; }; 2635DA87127D0D0400675BC1 /* SharingPtr.h in Headers */ = {isa = PBXBuildFile; fileRef = 261B5A5311C3F2AD00AABD0A /* SharingPtr.h */; settings = {ATTRIBUTES = (Public, ); }; }; 26368A3C126B697600E8659F /* darwin-debug.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 26368A3B126B697600E8659F /* darwin-debug.cpp */; }; @@ -540,6 +544,10 @@ 261B5A5311C3F2AD00AABD0A /* SharingPtr.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = SharingPtr.h; path = include/lldb/Utility/SharingPtr.h; sourceTree = ""; }; 261E18CC1148966100BADCD3 /* GDBRemoteRegisterContext.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = GDBRemoteRegisterContext.h; path = "source/Plugins/Process/gdb-remote/GDBRemoteRegisterContext.h"; sourceTree = ""; }; 261E18CD1148966100BADCD3 /* GDBRemoteRegisterContext.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = GDBRemoteRegisterContext.cpp; path = "source/Plugins/Process/gdb-remote/GDBRemoteRegisterContext.cpp"; sourceTree = ""; }; + 2621C9CB12EA009300711A30 /* EmulateInstructionARM.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = EmulateInstructionARM.cpp; path = Utility/EmulateInstructionARM.cpp; sourceTree = ""; }; + 2621C9CC12EA009300711A30 /* EmulateInstruction.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = EmulateInstruction.h; path = Utility/EmulateInstruction.h; sourceTree = ""; }; + 2621C9CF12EA066500711A30 /* EmulateInstructionARM.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = EmulateInstructionARM.h; path = Utility/EmulateInstructionARM.h; sourceTree = ""; }; + 2621CA0A12EA107700711A30 /* EmulateInstruction.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = EmulateInstruction.cpp; path = Utility/EmulateInstruction.cpp; sourceTree = ""; }; 263664921140A4930075843B /* Debugger.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = Debugger.cpp; path = source/Core/Debugger.cpp; sourceTree = ""; }; 263664941140A4C10075843B /* Debugger.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = Debugger.h; path = include/lldb/Core/Debugger.h; sourceTree = ""; }; 26368A3B126B697600E8659F /* darwin-debug.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = "darwin-debug.cpp"; path = "tools/darwin-debug/darwin-debug.cpp"; sourceTree = ""; }; @@ -1601,6 +1609,10 @@ 26B4666E11A2080F00CF6220 /* Utility */ = { isa = PBXGroup; children = ( + 2621C9CC12EA009300711A30 /* EmulateInstruction.h */, + 2621CA0A12EA107700711A30 /* EmulateInstruction.cpp */, + 2621C9CF12EA066500711A30 /* EmulateInstructionARM.h */, + 2621C9CB12EA009300711A30 /* EmulateInstructionARM.cpp */, AF68D32F1255A110002FF25B /* UnwindLLDB.cpp */, AF68D3301255A110002FF25B /* UnwindLLDB.h */, AF68D2541255416E002FF25B /* RegisterContextLLDB.cpp */, @@ -2299,6 +2311,8 @@ 266A42D8128E40040090CF7C /* ClangNamespaceDecl.h in Headers */, 26E6902F129C6BD500DDECD9 /* ClangExternalASTSourceCallbacks.h in Headers */, 4C7CF7E41295E10E00B4FBB5 /* ThreadPlanCallUserExpression.h in Headers */, + 2621C9CE12EA009300711A30 /* EmulateInstruction.h in Headers */, + 2621C9D012EA066500711A30 /* EmulateInstructionARM.h in Headers */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -2800,6 +2814,8 @@ 26E69031129C6BEF00DDECD9 /* ClangExternalASTSourceCallbacks.cpp in Sources */, 4C7CF7E61295E12B00B4FBB5 /* ThreadPlanCallUserExpression.cpp in Sources */, B296983712C2FB98002D92C3 /* CommandObjectVersion.cpp in Sources */, + 2621C9CD12EA009300711A30 /* EmulateInstructionARM.cpp in Sources */, + 2621CA0B12EA107700711A30 /* EmulateInstruction.cpp in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; Added: lldb/trunk/source/Plugins/Process/Utility/EmulateInstruction.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Process/Utility/EmulateInstruction.cpp?rev=123998&view=auto ============================================================================== --- lldb/trunk/source/Plugins/Process/Utility/EmulateInstruction.cpp (added) +++ lldb/trunk/source/Plugins/Process/Utility/EmulateInstruction.cpp Fri Jan 21 16:02:52 2011 @@ -0,0 +1,98 @@ +//===-- EmulateInstruction.h ------------------------------------*- C++ -*-===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +#include "EmulateInstruction.h" + +#include "lldb/Core/DataExtractor.h" +#include "lldb/Core/StreamString.h" +using namespace lldb; +using namespace lldb_private; + + +EmulateInstruction::EmulateInstruction +( + lldb::ByteOrder byte_order, + uint32_t addr_byte_size, + void *baton, + ReadMemory read_mem_callback, + WriteMemory write_mem_callback, + ReadRegister read_reg_callback, + WriteRegister write_reg_callback +) : + m_byte_order (lldb::eByteOrderHost), + m_addr_byte_size (sizeof (void *)), + m_baton (baton), + m_read_mem_callback (read_mem_callback), + m_write_mem_callback (write_mem_callback), + m_read_reg_callback (read_reg_callback), + m_write_reg_callback (write_reg_callback), + m_inst_pc (LLDB_INVALID_ADDRESS) +{ + ::bzero (&m_inst, sizeof (m_inst)); +} + +uint64_t +EmulateInstruction::ReadRegisterUnsigned (uint32_t reg_kind, uint32_t reg_num, uint64_t fail_value, bool *success_ptr) +{ + uint64_t uval64 = 0; + bool success = m_read_reg_callback (m_baton, reg_kind, reg_num, uval64); + if (success_ptr) + *success_ptr = success; + if (!success) + uval64 = fail_value; + return uval64; +} + +bool +EmulateInstruction::WriteRegisterUnsigned (const Context &context, uint32_t reg_kind, uint32_t reg_num, uint64_t reg_value) +{ + return m_write_reg_callback (m_baton, context, reg_kind, reg_num, reg_value); +} + +uint64_t +EmulateInstruction::ReadMemoryUnsigned (const Context &context, lldb::addr_t addr, size_t byte_size, uint64_t fail_value, bool *success_ptr) +{ + uint64_t uval64 = 0; + bool success = false; + if (byte_size <= 8) + { + uint8_t buf[sizeof(uint64_t)]; + size_t bytes_read = m_read_mem_callback (m_baton, context, addr, buf, byte_size); + if (bytes_read == byte_size) + { + uint32_t offset = 0; + DataExtractor data (buf, byte_size, m_byte_order, m_addr_byte_size); + uval64 = data.GetMaxU64 (&offset, byte_size); + success = true; + } + } + + if (success_ptr) + *success_ptr = success; + + if (!success) + uval64 = fail_value; + return uval64; +} + + +bool +EmulateInstruction::WriteMemoryUnsigned (const Context &context, + lldb::addr_t addr, + uint64_t uval, + size_t uval_byte_size) +{ + StreamString strm(Stream::eBinary, GetAddressByteSize(), GetByteOrder()); + strm.PutMaxHex64 (uval, uval_byte_size); + + size_t bytes_written = m_write_mem_callback (m_baton, context, addr, strm.GetData(), uval_byte_size); + if (bytes_written == uval_byte_size) + return true; + return false; +} Added: lldb/trunk/source/Plugins/Process/Utility/EmulateInstruction.h URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Process/Utility/EmulateInstruction.h?rev=123998&view=auto ============================================================================== --- lldb/trunk/source/Plugins/Process/Utility/EmulateInstruction.h (added) +++ lldb/trunk/source/Plugins/Process/Utility/EmulateInstruction.h Fri Jan 21 16:02:52 2011 @@ -0,0 +1,234 @@ +//===-- EmulateInstruction.h ------------------------------------*- C++ -*-===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +#ifndef lldb_EmulateInstruction_h_ +#define lldb_EmulateInstruction_h_ + +#include "lldb/lldb-include.h" + +namespace lldb_private { + +class EmulateInstruction +{ +public: + enum ContextType + { + eContextInvalid = 0, + eContextReadOpcode, + eContextImmediate, + eContextPushRegisterOnStack, + eContextAdjustStackPointer, + eContextRegisterPlusOffset, + }; + + struct Context + { + ContextType type; + lldb::addr_t arg0; + lldb::addr_t arg1; + lldb::addr_t arg2; + }; + + union Opcode + { + uint8_t inst8; + uint16_t inst16; + uint32_t inst32; + uint64_t inst64; + union inst + { + uint8_t bytes[16]; + uint8_t length; + }; + }; + + enum OpcodeType + { + eOpcode8, + eOpcode16, + eOpcode32, + eOpcode64, + eOpcodeBytes, + }; + + struct Instruction + { + OpcodeType opcode_type; + Opcode opcode; + }; + + typedef size_t (*ReadMemory) (void *baton, + const Context &context, + lldb::addr_t addr, + void *dst, + size_t length); + + typedef size_t (*WriteMemory) (void *baton, + const Context &context, + lldb::addr_t addr, + const void *dst, + size_t length); + + typedef bool (*ReadRegister) (void *baton, + uint32_t reg_kind, + uint32_t reg_num, + uint64_t ®_value); + + typedef bool (*WriteRegister) (void *baton, + const Context &context, + uint32_t reg_kind, + uint32_t reg_num, + uint64_t reg_value); + + EmulateInstruction (lldb::ByteOrder byte_order, + uint32_t addr_byte_size, + void *baton, + ReadMemory read_mem_callback, + WriteMemory write_mem_callback, + ReadRegister read_reg_callback, + WriteRegister write_reg_callback); + + virtual ~EmulateInstruction() + { + } + + virtual bool + ReadInstruction () = 0; + + virtual bool + EvaluateInstruction () = 0; + + // Create a mask that starts at bit zero and includes "bit" + static uint64_t + MaskUpToBit (const uint64_t bit) + { + return (1ull << (bit + 1ull)) - 1ull; + } + + static bool + BitIsSet (const uint64_t value, const uint64_t bit) + { + return (value & (1ull << bit)) != 0; + } + + static bool + BitIsClear (const uint64_t value, const uint64_t bit) + { + return (value & (1ull << bit)) == 0; + } + + static int64_t + SignedBits (const uint64_t value, const uint64_t msbit, const uint64_t lsbit) + { + uint64_t result = UnsignedBits (value, msbit, lsbit); + if (BitIsSet(value, msbit)) + { + // Sign extend + result |= ~MaskUpToBit (msbit - lsbit); + } + return result; + } + + static uint64_t + UnsignedBits (const uint64_t value, const uint64_t msbit, const uint64_t lsbit) + { + uint64_t result = value >> lsbit; + result &= MaskUpToBit (msbit - lsbit); + return result; + } + + uint64_t + ReadRegisterUnsigned (uint32_t reg_kind, + uint32_t reg_num, + uint64_t fail_value, + bool *success_ptr); + + bool + WriteRegisterUnsigned (const Context &context, + uint32_t reg_kind, + uint32_t reg_num, + uint64_t reg_value); + + uint64_t + ReadMemoryUnsigned (const Context &context, + lldb::addr_t addr, + size_t byte_size, + uint64_t fail_value, + bool *success_ptr); + + bool + WriteMemoryUnsigned (const Context &context, + lldb::addr_t addr, + uint64_t uval, + size_t uval_byte_size); + + static uint32_t + BitCount (uint64_t value) + { + uint32_t set_bit_count = 0; + while (value) + { + if (value & 1) + ++set_bit_count; + value >>= 1; + } + return set_bit_count; + } + + uint32_t + GetAddressByteSize () const + { + return m_addr_byte_size; + } + + lldb::ByteOrder + GetByteOrder () const + { + return m_byte_order; + } + + uint64_t + OpcodeAsUnsigned (bool *success_ptr) + { + if (success_ptr) + *success_ptr = true; + switch (m_inst.opcode_type) + { + eOpcode8: return m_inst.opcode.inst8; + eOpcode16: return m_inst.opcode.inst16; + eOpcode32: return m_inst.opcode.inst32; + eOpcode64: return m_inst.opcode.inst64; + eOpcodeBytes: + break; + } + if (success_ptr) + *success_ptr = false; + return 0; + } + +protected: + lldb::ByteOrder m_byte_order; + uint32_t m_addr_byte_size; + void * m_baton; + ReadMemory m_read_mem_callback; + WriteMemory m_write_mem_callback; + ReadRegister m_read_reg_callback; + WriteRegister m_write_reg_callback; + + lldb::addr_t m_inst_pc; + Instruction m_inst; + //------------------------------------------------------------------ + // For EmulateInstruction only + //------------------------------------------------------------------ + DISALLOW_COPY_AND_ASSIGN (EmulateInstruction); +}; + +} // namespace lldb_private + +#endif // lldb_EmulateInstruction_h_ Added: lldb/trunk/source/Plugins/Process/Utility/EmulateInstructionARM.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Process/Utility/EmulateInstructionARM.cpp?rev=123998&view=auto ============================================================================== --- lldb/trunk/source/Plugins/Process/Utility/EmulateInstructionARM.cpp (added) +++ lldb/trunk/source/Plugins/Process/Utility/EmulateInstructionARM.cpp Fri Jan 21 16:02:52 2011 @@ -0,0 +1,299 @@ +//===-- EmulateInstructionARM.cpp -------------------------------*- C++ -*-===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +#include "EmulateInstructionARM.h" + +using namespace lldb; +using namespace lldb_private; + +// ARM constants used during decoding +#define REG_RD 0 +#define LDM_REGLIST 1 +#define PC_REG 15 +#define PC_REGLIST_BIT 0x8000 + +// ARM conditions +#define COND_EQ 0x0 +#define COND_NE 0x1 +#define COND_CS 0x2 +#define COND_HS 0x2 +#define COND_CC 0x3 +#define COND_LO 0x3 +#define COND_MI 0x4 +#define COND_PL 0x5 +#define COND_VS 0x6 +#define COND_VC 0x7 +#define COND_HI 0x8 +#define COND_LS 0x9 +#define COND_GE 0xA +#define COND_LT 0xB +#define COND_GT 0xC +#define COND_LE 0xD +#define COND_AL 0xE +#define COND_UNCOND 0xF + + +#define MASK_CPSR_MODE_MASK (0x0000001fu) +#define MASK_CPSR_T (1u << 5) +#define MASK_CPSR_F (1u << 6) +#define MASK_CPSR_I (1u << 7) +#define MASK_CPSR_A (1u << 8) +#define MASK_CPSR_E (1u << 9) +#define MASK_CPSR_GE_MASK (0x000f0000u) +#define MASK_CPSR_J (1u << 24) +#define MASK_CPSR_Q (1u << 27) +#define MASK_CPSR_V (1u << 28) +#define MASK_CPSR_C (1u << 29) +#define MASK_CPSR_Z (1u << 30) +#define MASK_CPSR_N (1u << 31) + + +#define ARMv4 (1u << 0) +#define ARMv4T (1u << 1) +#define ARMv5T (1u << 2) +#define ARMv5TE (1u << 3) +#define ARMv5TEJ (1u << 4) +#define ARMv6 (1u << 5) +#define ARMv6K (1u << 6) +#define ARMv6T2 (1u << 7) +#define ARMv7 (1u << 8) +#define ARMv8 (1u << 8) +#define ARMvAll (0xffffffffu) + +typedef bool (*EmulateCallback) (EmulateInstructionARM *emulator); + + +typedef enum ARMEncoding +{ + eEncodingA1, + eEncodingA2, + eEncodingA3, + eEncodingA4, + eEncodingA5, + eEncodingT1, + eEncodingT2, + eEncodingT3, + eEncodingT4, + eEncodingT5, +} ARMEncoding; + + +typedef struct ARMOpcode +{ + uint32_t mask; + uint32_t value; + uint32_t variants; + ARMEncoding encoding; + const char *name; + EmulateCallback callback; +}; + +static bool +EmulateARMPushEncodingA1 (EmulateInstructionARM *emulator) +{ +#if 0 + // ARM pseudo code... + if (ConditionPassed()) + { + EncodingSpecificOperations(); + NullCheckIfThumbEE(13); + address = SP - 4*BitCount(registers); + + for (i = 0 to 14) + { + if (registers == ???1???) + { + if i == 13 && i != LowestSetBit(registers) // Only possible for encoding A1 + MemA[address,4] = bits(32) UNKNOWN; + else + MemA[address,4] = R[i]; + address = address + 4; + } + } + + if (registers<15> == ???1???) // Only possible for encoding A1 or A2 + MemA[address,4] = PCStoreValue(); + + SP = SP - 4*BitCount(registers); + } +#endif + + bool success = false; + const uint32_t opcode = emulator->OpcodeAsUnsigned (&success); + if (!success) + return false; + + if (emulator->ConditionPassed()) + { + const uint32_t addr_byte_size = emulator->GetAddressByteSize(); + const addr_t sp = emulator->ReadRegisterUnsigned (eRegisterKindGeneric, LLDB_REGNUM_GENERIC_SP, 0, &success); + if (!success) + return false; + const uint32_t registers = EmulateInstruction::UnsignedBits (opcode, 15, 0); + addr_t sp_offset = addr_byte_size * EmulateInstruction::BitCount (registers); + addr_t addr = sp - sp_offset; + uint32_t i; + + EmulateInstruction::Context context = { EmulateInstruction::eContextPushRegisterOnStack, eRegisterKindDWARF, 0, 0 }; + for (i=0; i<15; ++i) + { + if (EmulateInstruction::BitIsSet (registers, 1u << i)) + { + context.arg1 = dwarf_r0 + i; // arg1 in the context is the DWARF register number + context.arg2 = addr - sp; // arg2 in the context is the stack pointer offset + uint32_t reg_value = emulator->ReadRegisterUnsigned(eRegisterKindDWARF, context.arg1, 0, &success); + if (!success) + return false; + if (!emulator->WriteMemoryUnsigned (context, addr, reg_value, addr_byte_size)) + return false; + addr += addr_byte_size; + } + } + + if (EmulateInstruction::BitIsSet (registers, 1u << 15)) + { + context.arg1 = dwarf_pc; // arg1 in the context is the DWARF register number + context.arg2 = addr - sp; // arg2 in the context is the stack pointer offset + const uint32_t pc = emulator->ReadRegisterUnsigned(eRegisterKindGeneric, LLDB_REGNUM_GENERIC_PC, 0, &success); + if (!success) + return false; + if (!emulator->WriteMemoryUnsigned (context, addr, pc + 8, addr_byte_size)) + return false; + } + + context.type = EmulateInstruction::eContextAdjustStackPointer; + context.arg0 = eRegisterKindGeneric; + context.arg1 = LLDB_REGNUM_GENERIC_SP; + context.arg2 = sp_offset; + + if (!emulator->WriteRegisterUnsigned (context, eRegisterKindGeneric, LLDB_REGNUM_GENERIC_SP, sp - sp_offset)) + return false; + } + return true; +} + +static ARMOpcode g_arm_opcodes[] = +{ + { 0x0fff0000, 0x092d0000, ARMvAll, eEncodingA1, "PUSH ", EmulateARMPushEncodingA1 } +}; + +static const size_t k_num_arm_opcodes = sizeof(g_arm_opcodes)/sizeof(ARMOpcode); + +bool +EmulateInstructionARM::ReadInstruction () +{ + bool success = false; + m_inst_cpsr = ReadRegisterUnsigned (eRegisterKindGeneric, LLDB_REGNUM_GENERIC_FLAGS, 0, &success); + if (success) + { + addr_t pc = ReadRegisterUnsigned (eRegisterKindGeneric, LLDB_REGNUM_GENERIC_PC, LLDB_INVALID_ADDRESS, &success); + if (success) + { + Context read_inst_context = {eContextReadOpcode, 0, 0}; + if (m_inst_cpsr & MASK_CPSR_T) + { + m_inst_mode = eModeThumb; + uint32_t thumb_opcode = ReadMemoryUnsigned(read_inst_context, pc, 2, 0, &success); + + if (success) + { + if ((m_inst.opcode.inst16 & 0xe000) != 0xe000 || ((m_inst.opcode.inst16 & 0x1800u) == 0)) + { + m_inst.opcode_type = eOpcode16; + m_inst.opcode.inst16 = thumb_opcode; + } + else + { + m_inst.opcode_type = eOpcode32; + m_inst.opcode.inst32 = (thumb_opcode << 16) | ReadMemoryUnsigned(read_inst_context, pc + 2, 2, 0, &success); + } + } + } + else + { + m_inst_mode = eModeARM; + m_inst.opcode_type = eOpcode32; + m_inst.opcode.inst32 = ReadMemoryUnsigned(read_inst_context, pc, 4, 0, &success); + } + } + } + if (!success) + { + m_inst_mode = eModeInvalid; + m_inst_pc = LLDB_INVALID_ADDRESS; + } + return success; +} + +uint32_t +EmulateInstructionARM::CurrentCond () +{ + switch (m_inst_mode) + { + default: + case eModeInvalid: + break; + + case eModeARM: + return UnsignedBits(m_inst.opcode.inst32, 31, 28); + + case eModeThumb: + return 0x0000000Eu; // Return always for now, we need to handl IT instructions later + } + return UINT32_MAX; // Return invalid value +} +bool +EmulateInstructionARM::ConditionPassed () +{ + if (m_inst_cpsr == 0) + return false; + + const uint32_t cond = CurrentCond (); + + if (cond == UINT32_MAX) + return false; + + bool result = false; + switch (UnsignedBits(cond, 3, 1)) + { + case 0: result = (m_inst_cpsr & MASK_CPSR_Z) != 0; break; + case 1: result = (m_inst_cpsr & MASK_CPSR_C) != 0; break; + case 2: result = (m_inst_cpsr & MASK_CPSR_N) != 0; break; + case 3: result = (m_inst_cpsr & MASK_CPSR_V) != 0; break; + case 4: result = ((m_inst_cpsr & MASK_CPSR_C) != 0) && ((m_inst_cpsr & MASK_CPSR_Z) == 0); break; + case 5: + { + bool n = (m_inst_cpsr & MASK_CPSR_N); + bool v = (m_inst_cpsr & MASK_CPSR_V); + result = n == v; + } + break; + case 6: + { + bool n = (m_inst_cpsr & MASK_CPSR_N); + bool v = (m_inst_cpsr & MASK_CPSR_V); + result = n == v && ((m_inst_cpsr & MASK_CPSR_Z) == 0); + } + break; + case 7: + result = true; + break; + } + + if (cond & 1) + result = !result; + return result; +} + + +bool +EmulateInstructionARM::EvaluateInstruction () +{ + return false; +} Added: lldb/trunk/source/Plugins/Process/Utility/EmulateInstructionARM.h URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Process/Utility/EmulateInstructionARM.h?rev=123998&view=auto ============================================================================== --- lldb/trunk/source/Plugins/Process/Utility/EmulateInstructionARM.h (added) +++ lldb/trunk/source/Plugins/Process/Utility/EmulateInstructionARM.h Fri Jan 21 16:02:52 2011 @@ -0,0 +1,65 @@ +//===-- lldb_EmulateInstructionARM.h ------------------------------------*- C++ -*-===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +#ifndef lldb_EmulateInstructionARM_h_ +#define lldb_EmulateInstructionARM_h_ + +#include "EmulateInstruction.h" +#include "ARM_DWARF_Registers.h" + +namespace lldb_private { + +class EmulateInstructionARM : public EmulateInstruction +{ +public: + enum Mode + { + eModeInvalid, + eModeARM, + eModeThumb + }; + + EmulateInstructionARM (void *baton, + ReadMemory read_mem_callback, + WriteMemory write_mem_callback, + ReadRegister read_reg_callback, + WriteRegister write_reg_callback) : + EmulateInstruction (lldb::eByteOrderLittle, // Byte order for ARM + 4, // Address size in byte + baton, + read_mem_callback, + write_mem_callback, + read_reg_callback, + write_reg_callback), + m_inst_mode (eModeInvalid) + { + } + + virtual bool + ReadInstruction (); + + virtual bool + EvaluateInstruction (); + + bool + ConditionPassed (); + + uint32_t + CurrentCond (); + +protected: + + Mode m_inst_mode; + uint32_t m_inst_cpsr; + +}; + +} // namespace lldb_private + +#endif // lldb_EmulateInstructionARM_h_ From jingham at apple.com Fri Jan 21 16:13:26 2011 From: jingham at apple.com (Jim Ingham) Date: Fri, 21 Jan 2011 22:13:26 -0000 Subject: [Lldb-commits] [lldb] r124000 - /lldb/trunk/source/Commands/CommandObjectBreakpointCommand.cpp Message-ID: <20110121221326.170E82A6C12D@llvm.org> Author: jingham Date: Fri Jan 21 16:13:25 2011 New Revision: 124000 URL: http://llvm.org/viewvc/llvm-project?rev=124000&view=rev Log: The code to check whether the number of arguments was 0 was not necessary, VerifyBreakpointIDs will turn an empty argument into the last specified breakpoint. Modified: lldb/trunk/source/Commands/CommandObjectBreakpointCommand.cpp Modified: lldb/trunk/source/Commands/CommandObjectBreakpointCommand.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Commands/CommandObjectBreakpointCommand.cpp?rev=124000&r1=123999&r2=124000&view=diff ============================================================================== --- lldb/trunk/source/Commands/CommandObjectBreakpointCommand.cpp (original) +++ lldb/trunk/source/Commands/CommandObjectBreakpointCommand.cpp Fri Jan 21 16:13:25 2011 @@ -282,13 +282,6 @@ return false; } - if (command.GetArgumentCount() == 0) - { - result.AppendError ("No breakpoint specified to which to add the commands"); - result.SetStatus (eReturnStatusFailed); - return false; - } - BreakpointIDList valid_bp_ids; CommandObjectMultiwordBreakpoint::VerifyBreakpointIDs (command, target, result, &valid_bp_ids); From scallanan at apple.com Fri Jan 21 16:30:25 2011 From: scallanan at apple.com (Sean Callanan) Date: Fri, 21 Jan 2011 22:30:25 -0000 Subject: [Lldb-commits] [lldb] r124001 - /lldb/trunk/source/Expression/IRForTarget.cpp Message-ID: <20110121223025.36D562A6C12C@llvm.org> Author: spyffe Date: Fri Jan 21 16:30:25 2011 New Revision: 124001 URL: http://llvm.org/viewvc/llvm-project?rev=124001&view=rev Log: Added a safeguard to ensure that the user does not create variables that override persistent result variables. Modified: lldb/trunk/source/Expression/IRForTarget.cpp Modified: lldb/trunk/source/Expression/IRForTarget.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Expression/IRForTarget.cpp?rev=124001&r1=124000&r2=124001&view=diff ============================================================================== --- lldb/trunk/source/Expression/IRForTarget.cpp (original) +++ lldb/trunk/source/Expression/IRForTarget.cpp Fri Jan 21 16:30:25 2011 @@ -901,9 +901,23 @@ Instruction &inst = *ii; if (AllocaInst *alloc = dyn_cast(&inst)) - if (alloc->getName().startswith("$") && - !alloc->getName().startswith("$__lldb")) + { + llvm::StringRef alloc_name = alloc->getName(); + + if (alloc_name.startswith("$") && + !alloc_name.startswith("$__lldb")) + { + if (alloc_name.find_first_of("0123456789") == 1) + { + if (log) + log->Printf("Rejecting a numeric persistent variable."); + + return false; + } + pvar_allocs.push_back(alloc); + } + } } InstrIterator iter; From johnny.chen at apple.com Fri Jan 21 16:47:25 2011 From: johnny.chen at apple.com (Johnny Chen) Date: Fri, 21 Jan 2011 22:47:25 -0000 Subject: [Lldb-commits] [lldb] r124003 - /lldb/trunk/source/Plugins/Process/Utility/EmulateInstructionARM.cpp Message-ID: <20110121224725.CA5CE2A6C12C@llvm.org> Author: johnny Date: Fri Jan 21 16:47:25 2011 New Revision: 124003 URL: http://llvm.org/viewvc/llvm-project?rev=124003&view=rev Log: Untabify the file. Modified: lldb/trunk/source/Plugins/Process/Utility/EmulateInstructionARM.cpp Modified: lldb/trunk/source/Plugins/Process/Utility/EmulateInstructionARM.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Process/Utility/EmulateInstructionARM.cpp?rev=124003&r1=124002&r2=124003&view=diff ============================================================================== --- lldb/trunk/source/Plugins/Process/Utility/EmulateInstructionARM.cpp (original) +++ lldb/trunk/source/Plugins/Process/Utility/EmulateInstructionARM.cpp Fri Jan 21 16:47:25 2011 @@ -39,7 +39,7 @@ #define COND_UNCOND 0xF -#define MASK_CPSR_MODE_MASK (0x0000001fu) +#define MASK_CPSR_MODE_MASK (0x0000001fu) #define MASK_CPSR_T (1u << 5) #define MASK_CPSR_F (1u << 6) #define MASK_CPSR_I (1u << 7) @@ -54,16 +54,16 @@ #define MASK_CPSR_N (1u << 31) -#define ARMv4 (1u << 0) +#define ARMv4 (1u << 0) #define ARMv4T (1u << 1) #define ARMv5T (1u << 2) #define ARMv5TE (1u << 3) #define ARMv5TEJ (1u << 4) -#define ARMv6 (1u << 5) +#define ARMv6 (1u << 5) #define ARMv6K (1u << 6) #define ARMv6T2 (1u << 7) -#define ARMv7 (1u << 8) -#define ARMv8 (1u << 8) +#define ARMv7 (1u << 8) +#define ARMv8 (1u << 8) #define ARMvAll (0xffffffffu) typedef bool (*EmulateCallback) (EmulateInstructionARM *emulator); From jingham at apple.com Fri Jan 21 18:28:04 2011 From: jingham at apple.com (Jim Ingham) Date: Sat, 22 Jan 2011 00:28:04 -0000 Subject: [Lldb-commits] [lldb] r124008 - /lldb/trunk/source/Breakpoint/BreakpointOptions.cpp Message-ID: <20110122002804.3C6892A6C12C@llvm.org> Author: jingham Date: Fri Jan 21 18:28:04 2011 New Revision: 124008 URL: http://llvm.org/viewvc/llvm-project?rev=124008&view=rev Log: Add missing {} so we don't print the Baton address for the brief breakpoint listing. Modified: lldb/trunk/source/Breakpoint/BreakpointOptions.cpp Modified: lldb/trunk/source/Breakpoint/BreakpointOptions.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Breakpoint/BreakpointOptions.cpp?rev=124008&r1=124007&r2=124008&view=diff ============================================================================== --- lldb/trunk/source/Breakpoint/BreakpointOptions.cpp (original) +++ lldb/trunk/source/Breakpoint/BreakpointOptions.cpp Fri Jan 21 18:28:04 2011 @@ -312,8 +312,10 @@ if (m_callback_baton_sp.get()) { if (level != eDescriptionLevelBrief) + { s->EOL(); - m_callback_baton_sp->GetDescription (s, level); + m_callback_baton_sp->GetDescription (s, level); + } } if (m_condition_ap.get()) { From johnny.chen at apple.com Fri Jan 21 18:47:08 2011 From: johnny.chen at apple.com (Johnny Chen) Date: Sat, 22 Jan 2011 00:47:08 -0000 Subject: [Lldb-commits] [lldb] r124009 - /lldb/trunk/source/Plugins/Process/Utility/EmulateInstructionARM.cpp Message-ID: <20110122004708.3F8362A6C12C@llvm.org> Author: johnny Date: Fri Jan 21 18:47:08 2011 New Revision: 124009 URL: http://llvm.org/viewvc/llvm-project?rev=124009&view=rev Log: Pass along (ARMEncoding)encoding as the callback data, which allows us to abstract the EmulateCallback routine without too much duplication. Add an entry for emulating ARM PUSH with encoding A2. Modified: lldb/trunk/source/Plugins/Process/Utility/EmulateInstructionARM.cpp Modified: lldb/trunk/source/Plugins/Process/Utility/EmulateInstructionARM.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Process/Utility/EmulateInstructionARM.cpp?rev=124009&r1=124008&r2=124009&view=diff ============================================================================== --- lldb/trunk/source/Plugins/Process/Utility/EmulateInstructionARM.cpp (original) +++ lldb/trunk/source/Plugins/Process/Utility/EmulateInstructionARM.cpp Fri Jan 21 18:47:08 2011 @@ -66,9 +66,6 @@ #define ARMv8 (1u << 8) #define ARMvAll (0xffffffffu) -typedef bool (*EmulateCallback) (EmulateInstructionARM *emulator); - - typedef enum ARMEncoding { eEncodingA1, @@ -83,7 +80,9 @@ eEncodingT5, } ARMEncoding; - +// Pass along (ARMEncoding)encoding as the callback data. +typedef bool (*EmulateCallback) (EmulateInstructionARM *emulator, ARMEncoding encoding); + typedef struct ARMOpcode { uint32_t mask; @@ -95,7 +94,7 @@ }; static bool -EmulateARMPushEncodingA1 (EmulateInstructionARM *emulator) +EmulateARMPushEncoding (EmulateInstructionARM *emulator, ARMEncoding encoding) { #if 0 // ARM pseudo code... @@ -135,7 +134,19 @@ const addr_t sp = emulator->ReadRegisterUnsigned (eRegisterKindGeneric, LLDB_REGNUM_GENERIC_SP, 0, &success); if (!success) return false; - const uint32_t registers = EmulateInstruction::UnsignedBits (opcode, 15, 0); + uint32_t registers = 0; + switch (encoding) { + case eEncodingA1: + registers = EmulateInstruction::UnsignedBits (opcode, 15, 0); + break; + case eEncodingA2: + const uint32_t Rt = EmulateInstruction::UnsignedBits (opcode, 15, 12); + // if t == 13 then UNPREDICTABLE + if (Rt == dwarf_sp) + return false; + registers = (1u << Rt); + break; + } addr_t sp_offset = addr_byte_size * EmulateInstruction::BitCount (registers); addr_t addr = sp - sp_offset; uint32_t i; @@ -159,7 +170,7 @@ if (EmulateInstruction::BitIsSet (registers, 1u << 15)) { context.arg1 = dwarf_pc; // arg1 in the context is the DWARF register number - context.arg2 = addr - sp; // arg2 in the context is the stack pointer offset + context.arg2 = addr - sp; // arg2 in the context is the stack pointer offset const uint32_t pc = emulator->ReadRegisterUnsigned(eRegisterKindGeneric, LLDB_REGNUM_GENERIC_PC, 0, &success); if (!success) return false; @@ -180,7 +191,8 @@ static ARMOpcode g_arm_opcodes[] = { - { 0x0fff0000, 0x092d0000, ARMvAll, eEncodingA1, "PUSH ", EmulateARMPushEncodingA1 } + { 0x0fff0000, 0x092d0000, ARMvAll, eEncodingA1, "PUSH ", EmulateARMPushEncoding }, + { 0x0fff0fff, 0x052d0004, ARMvAll, eEncodingA2, "PUSH ", EmulateARMPushEncoding } }; static const size_t k_num_arm_opcodes = sizeof(g_arm_opcodes)/sizeof(ARMOpcode); From johnny.chen at apple.com Fri Jan 21 18:59:07 2011 From: johnny.chen at apple.com (Johnny Chen) Date: Sat, 22 Jan 2011 00:59:07 -0000 Subject: [Lldb-commits] [lldb] r124010 - /lldb/trunk/source/Plugins/Process/Utility/EmulateInstructionARM.cpp Message-ID: <20110122005907.764A12A6C12C@llvm.org> Author: johnny Date: Fri Jan 21 18:59:07 2011 New Revision: 124010 URL: http://llvm.org/viewvc/llvm-project?rev=124010&view=rev Log: Add more descriptions to the g_arm_opcodes table entries. Modified: lldb/trunk/source/Plugins/Process/Utility/EmulateInstructionARM.cpp Modified: lldb/trunk/source/Plugins/Process/Utility/EmulateInstructionARM.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Process/Utility/EmulateInstructionARM.cpp?rev=124010&r1=124009&r2=124010&view=diff ============================================================================== --- lldb/trunk/source/Plugins/Process/Utility/EmulateInstructionARM.cpp (original) +++ lldb/trunk/source/Plugins/Process/Utility/EmulateInstructionARM.cpp Fri Jan 21 18:59:07 2011 @@ -89,8 +89,8 @@ uint32_t value; uint32_t variants; ARMEncoding encoding; - const char *name; EmulateCallback callback; + const char *name; }; static bool @@ -191,8 +191,10 @@ static ARMOpcode g_arm_opcodes[] = { - { 0x0fff0000, 0x092d0000, ARMvAll, eEncodingA1, "PUSH ", EmulateARMPushEncoding }, - { 0x0fff0fff, 0x052d0004, ARMvAll, eEncodingA2, "PUSH ", EmulateARMPushEncoding } + { 0x0fff0000, 0x092d0000, ARMvAll, eEncodingA1, EmulateARMPushEncoding, + "PUSH ; contains more than one register" }, + { 0x0fff0fff, 0x052d0004, ARMvAll, eEncodingA2, EmulateARMPushEncoding, + "PUSH ; contains one register, " } }; static const size_t k_num_arm_opcodes = sizeof(g_arm_opcodes)/sizeof(ARMOpcode); From ctice at apple.com Fri Jan 21 19:02:07 2011 From: ctice at apple.com (Caroline Tice) Date: Sat, 22 Jan 2011 01:02:07 -0000 Subject: [Lldb-commits] [lldb] r124011 - in /lldb/trunk: include/lldb/API/SBDebugger.h include/lldb/Core/Debugger.h source/API/SBDebugger.cpp source/Core/Debugger.cpp Message-ID: <20110122010207.619702A6C12C@llvm.org> Author: ctice Date: Fri Jan 21 19:02:07 2011 New Revision: 124011 URL: http://llvm.org/viewvc/llvm-project?rev=124011&view=rev Log: Add API and implementation for SBDebugger::Destroy and Debugger::Destroy. Modified: lldb/trunk/include/lldb/API/SBDebugger.h lldb/trunk/include/lldb/Core/Debugger.h lldb/trunk/source/API/SBDebugger.cpp lldb/trunk/source/Core/Debugger.cpp Modified: lldb/trunk/include/lldb/API/SBDebugger.h URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/API/SBDebugger.h?rev=124011&r1=124010&r2=124011&view=diff ============================================================================== --- lldb/trunk/include/lldb/API/SBDebugger.h (original) +++ lldb/trunk/include/lldb/API/SBDebugger.h Fri Jan 21 19:02:07 2011 @@ -25,9 +25,12 @@ static void Terminate(); - static SBDebugger + static lldb::SBDebugger Create(); + static void + Destroy (lldb::SBDebugger &debugger); + SBDebugger(); SBDebugger(const lldb::SBDebugger &rhs); Modified: lldb/trunk/include/lldb/Core/Debugger.h URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Core/Debugger.h?rev=124011&r1=124010&r2=124011&view=diff ============================================================================== --- lldb/trunk/include/lldb/Core/Debugger.h (original) +++ lldb/trunk/include/lldb/Core/Debugger.h Fri Jan 21 19:02:07 2011 @@ -259,6 +259,9 @@ static void Terminate (); + + static void + Destroy (lldb::DebuggerSP &debugger_sp); ~Debugger (); Modified: lldb/trunk/source/API/SBDebugger.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/API/SBDebugger.cpp?rev=124011&r1=124010&r2=124011&view=diff ============================================================================== --- lldb/trunk/source/API/SBDebugger.cpp (original) +++ lldb/trunk/source/API/SBDebugger.cpp Fri Jan 21 19:02:07 2011 @@ -83,6 +83,24 @@ return debugger; } +void +SBDebugger::Destroy (SBDebugger &debugger) +{ + LogSP log (lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); + + if (log) + { + SBStream sstr; + debugger.GetDescription (sstr); + log->Printf ("SBDebugger::Destroy () => SBDebugger(%p): %s", debugger.m_opaque_sp.get(), sstr.GetData()); + } + + Debugger::Destroy (debugger.m_opaque_sp); + + if (debugger.m_opaque_sp.get() != NULL) + debugger.m_opaque_sp.reset(); +} + SBDebugger::SBDebugger () : m_opaque_sp () { Modified: lldb/trunk/source/Core/Debugger.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Core/Debugger.cpp?rev=124011&r1=124010&r2=124011&view=diff ============================================================================== --- lldb/trunk/source/Core/Debugger.cpp (original) +++ lldb/trunk/source/Core/Debugger.cpp Fri Jan 21 19:02:07 2011 @@ -114,6 +114,26 @@ return debugger_sp; } +void +Debugger::Destroy (lldb::DebuggerSP &debugger_sp) +{ + if (debugger_sp.get() == NULL) + return; + + Mutex::Locker locker (GetDebuggerListMutex ()); + DebuggerList &debugger_list = GetDebuggerList (); + DebuggerList::iterator pos, end = debugger_list.end(); + for (pos = debugger_list.begin (); pos != end; ++pos) + { + if ((*pos).get() == debugger_sp.get()) + { + debugger_list.erase (pos); + return; + } + } + +} + lldb::DebuggerSP Debugger::GetSP () { From jingham at apple.com Fri Jan 21 19:22:51 2011 From: jingham at apple.com (Jim Ingham) Date: Sat, 22 Jan 2011 01:22:51 -0000 Subject: [Lldb-commits] [lldb] r124012 - /lldb/trunk/tools/debugserver/source/MacOSX/MachTask.cpp Message-ID: <20110122012251.F39162A6C12C@llvm.org> Author: jingham Date: Fri Jan 21 19:22:51 2011 New Revision: 124012 URL: http://llvm.org/viewvc/llvm-project?rev=124012&view=rev Log: Add a (currently disabled) bear trap where instead of deallocating pages, we remove all permissions. Modified: lldb/trunk/tools/debugserver/source/MacOSX/MachTask.cpp Modified: lldb/trunk/tools/debugserver/source/MacOSX/MachTask.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/tools/debugserver/source/MacOSX/MachTask.cpp?rev=124012&r1=124011&r2=124012&view=diff ============================================================================== --- lldb/trunk/tools/debugserver/source/MacOSX/MachTask.cpp (original) +++ lldb/trunk/tools/debugserver/source/MacOSX/MachTask.cpp Fri Jan 21 19:22:51 2011 @@ -626,7 +626,7 @@ if (err.Error() == KERN_SUCCESS) { // Set the protections: - vm_prot_t mach_prot = 0; + vm_prot_t mach_prot = VM_PROT_NONE; if (permissions & eMemoryPermissionsReadable) mach_prot |= VM_PROT_READ; if (permissions & eMemoryPermissionsWritable) @@ -663,7 +663,14 @@ if ((*pos).first == addr) { m_allocations.erase(pos); - return ::mach_vm_deallocate (task, (*pos).first, (*pos).second) == KERN_SUCCESS; +#define ALWAYS_ZOMBIE_ALLOCATIONS 0 + if (ALWAYS_ZOMBIE_ALLOCATIONS || getenv ("DEBUGSERVER_ZOMBIE_ALLOCATIONS")) + { + ::mach_vm_protect (task, (*pos).first, (*pos).second, 0, VM_PROT_NONE); + return true; + } + else + return ::mach_vm_deallocate (task, (*pos).first, (*pos).second) == KERN_SUCCESS; } } From jingham at apple.com Fri Jan 21 19:24:30 2011 From: jingham at apple.com (Jim Ingham) Date: Sat, 22 Jan 2011 01:24:30 -0000 Subject: [Lldb-commits] [lldb] r124013 - /lldb/trunk/source/Core/Log.cpp Message-ID: <20110122012430.534122A6C12C@llvm.org> Author: jingham Date: Fri Jan 21 19:24:30 2011 New Revision: 124013 URL: http://llvm.org/viewvc/llvm-project?rev=124013&view=rev Log: Make "log enable -v" work. We were only checking the log's stream's verbosity, not the log's verbosity... Modified: lldb/trunk/source/Core/Log.cpp Modified: lldb/trunk/source/Core/Log.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Core/Log.cpp?rev=124013&r1=124012&r2=124013&view=diff ============================================================================== --- lldb/trunk/source/Core/Log.cpp (original) +++ lldb/trunk/source/Core/Log.cpp Fri Jan 21 19:24:30 2011 @@ -442,6 +442,10 @@ bool Log::GetVerbose() const { + // FIXME: This has to be centralized between the stream and the log... + if (m_options.Test(LLDB_LOG_OPTION_VERBOSE)) + return true; + if (m_stream_sp) return m_stream_sp->GetVerbose(); return false; From jingham at apple.com Fri Jan 21 19:25:40 2011 From: jingham at apple.com (Jim Ingham) Date: Sat, 22 Jan 2011 01:25:40 -0000 Subject: [Lldb-commits] [lldb] r124014 - in /lldb/trunk/source/Expression: ASTResultSynthesizer.cpp IRDynamicChecks.cpp IRToDWARF.cpp Message-ID: <20110122012540.ECF242A6C12C@llvm.org> Author: jingham Date: Fri Jan 21 19:25:40 2011 New Revision: 124014 URL: http://llvm.org/viewvc/llvm-project?rev=124014&view=rev Log: Move some of the more noisy "log enable lldb expression" output to the verbose output. Modified: lldb/trunk/source/Expression/ASTResultSynthesizer.cpp lldb/trunk/source/Expression/IRDynamicChecks.cpp lldb/trunk/source/Expression/IRToDWARF.cpp Modified: lldb/trunk/source/Expression/ASTResultSynthesizer.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Expression/ASTResultSynthesizer.cpp?rev=124014&r1=124013&r2=124014&view=diff ============================================================================== --- lldb/trunk/source/Expression/ASTResultSynthesizer.cpp (original) +++ lldb/trunk/source/Expression/ASTResultSynthesizer.cpp Fri Jan 21 19:25:40 2011 @@ -133,7 +133,7 @@ if (!function_decl) return false; - if (log) + if (log && log->GetVerbose()) { std::string s; raw_string_ostream os(s); @@ -150,8 +150,8 @@ bool ret = SynthesizeBodyResult (compound_stmt, function_decl); - - if (log) + + if (log && log->GetVerbose()) { std::string s; raw_string_ostream os(s); @@ -160,7 +160,7 @@ os.flush(); - log->Printf("Transformed function AST:\n%s", s.c_str()); + log->Printf ("Transformed function AST:\n%s", s.c_str()); } return ret; @@ -179,7 +179,7 @@ if (!MethodDecl) return false; - if (log) + if (log && log->GetVerbose()) { std::string s; raw_string_ostream os(s); Modified: lldb/trunk/source/Expression/IRDynamicChecks.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Expression/IRDynamicChecks.cpp?rev=124014&r1=124013&r2=124014&view=diff ============================================================================== --- lldb/trunk/source/Expression/IRDynamicChecks.cpp (original) +++ lldb/trunk/source/Expression/IRDynamicChecks.cpp Fri Jan 21 19:25:40 2011 @@ -487,8 +487,8 @@ if (!ooc.Instrument()) return false; - - if (log) + + if (log && log->GetVerbose()) { std::string s; raw_string_ostream oss(s); @@ -497,7 +497,7 @@ oss.flush(); - log->Printf("Module after dynamic checks: \n%s", s.c_str()); + log->Printf ("Module after dynamic checks: \n%s", s.c_str()); } return true; Modified: lldb/trunk/source/Expression/IRToDWARF.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Expression/IRToDWARF.cpp?rev=124014&r1=124013&r2=124014&view=diff ============================================================================== --- lldb/trunk/source/Expression/IRToDWARF.cpp (original) +++ lldb/trunk/source/Expression/IRToDWARF.cpp Fri Jan 21 19:25:40 2011 @@ -187,8 +187,8 @@ if (!runOnBasicBlock(function->getEntryBlock(), relocator)) return false; - - if (log) + + if (log && log->GetVerbose()) { std::string s; raw_string_ostream oss(s); @@ -197,7 +197,7 @@ oss.flush(); - log->Printf("Module being translated to DWARF: \n%s", s.c_str()); + log->Printf ("Module being translated to DWARF: \n%s", s.c_str()); } // TEMPORARY: Fail in order to force execution in the target. From jingham at apple.com Fri Jan 21 19:27:23 2011 From: jingham at apple.com (Jim Ingham) Date: Sat, 22 Jan 2011 01:27:23 -0000 Subject: [Lldb-commits] [lldb] r124015 - /lldb/trunk/source/Target/ThreadPlanCallFunction.cpp Message-ID: <20110122012723.A60F72A6C12C@llvm.org> Author: jingham Date: Fri Jan 21 19:27:23 2011 New Revision: 124015 URL: http://llvm.org/viewvc/llvm-project?rev=124015&view=rev Log: Centralize the register reporting (might want to move this function to Thread). Make sure DoTakedown gets called only once by adding a dedicated m_takedown_done bool. Add a little more useful logging. Modified: lldb/trunk/source/Target/ThreadPlanCallFunction.cpp Modified: lldb/trunk/source/Target/ThreadPlanCallFunction.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Target/ThreadPlanCallFunction.cpp?rev=124015&r1=124014&r2=124015&view=diff ============================================================================== --- lldb/trunk/source/Target/ThreadPlanCallFunction.cpp (original) +++ lldb/trunk/source/Target/ThreadPlanCallFunction.cpp Fri Jan 21 19:27:23 2011 @@ -48,7 +48,8 @@ m_arg_addr (arg), m_args (NULL), m_process (thread.GetProcess()), - m_thread (thread) + m_thread (thread), + m_takedown_done (false) { SetOkayToDiscard (discard_on_error); @@ -79,6 +80,9 @@ lldb::addr_t StartLoadAddr = m_start_addr.GetLoadAddress(&target); // Checkpoint the thread state so we can restore it later. + if (log && log->GetVerbose()) + ReportRegisterState ("About to checkpoint thread before function call. Original register state was:"); + if (!thread.CheckpointThreadState (m_stored_thread_state)) { if (log) @@ -100,12 +104,25 @@ cmd_arg)) return; + ReportRegisterState ("Function call was set up. Register state was:"); + + m_valid = true; +} + +ThreadPlanCallFunction::~ThreadPlanCallFunction () +{ +} + +void +ThreadPlanCallFunction::ReportRegisterState (const char *message) +{ + LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_STEP)); if (log) { RegisterContext *reg_ctx = m_thread.GetRegisterContext().get(); - - log->PutCString("Function call was set up. Register state was:"); - + + log->PutCString(message); + for (uint32_t register_index = 0, num_registers = reg_ctx->GetRegisterCount(); register_index < num_registers; ++register_index) @@ -116,23 +133,27 @@ log->Printf(" %s = 0x%llx", register_name, register_value); } } - - m_valid = true; -} - -ThreadPlanCallFunction::~ThreadPlanCallFunction () -{ - DoTakedown(); } void ThreadPlanCallFunction::DoTakedown () { - if (m_valid && !IsPlanComplete()) + LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_STEP)); + if (!m_takedown_done) { + if (log) + log->Printf ("DoTakedown called for thread 0x%4.4x, m_valid: %d complete: %d.\n", m_thread.GetID(), m_valid, IsPlanComplete()); + m_takedown_done = true; m_thread.RestoreThreadStateFromCheckpoint(m_stored_thread_state); SetPlanComplete(); ClearBreakpoints(); + if (log && log->GetVerbose()) + ReportRegisterState ("Restoring thread state after function call. Restored register state:"); + } + else + { + if (log) + log->Printf ("DoTakedown called as no-op for thread 0x%4.4x, m_valid: %d complete: %d.\n", m_thread.GetID(), m_valid, IsPlanComplete()); } } @@ -224,24 +245,7 @@ { if (PlanExplainsStop()) { - LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_STEP)); - - if (log) - { - RegisterContext *reg_ctx = m_thread.GetRegisterContext().get(); - - log->PutCString("Function completed. Register state was:"); - - for (uint32_t register_index = 0, num_registers = reg_ctx->GetRegisterCount(); - register_index < num_registers; - ++register_index) - { - const char *register_name = reg_ctx->GetRegisterName(register_index); - uint64_t register_value = reg_ctx->ReadRegisterAsUnsigned(register_index, LLDB_INVALID_ADDRESS); - - log->Printf(" %s = 0x%llx", register_name, register_value); - } - } + ReportRegisterState ("Function completed. Register state was:"); DoTakedown(); From jingham at apple.com Fri Jan 21 19:28:29 2011 From: jingham at apple.com (Jim Ingham) Date: Sat, 22 Jan 2011 01:28:29 -0000 Subject: [Lldb-commits] [lldb] r124016 - /lldb/trunk/include/lldb/Target/ThreadPlanCallFunction.h Message-ID: <20110122012829.5B2242A6C12C@llvm.org> Author: jingham Date: Fri Jan 21 19:28:29 2011 New Revision: 124016 URL: http://llvm.org/viewvc/llvm-project?rev=124016&view=rev Log: Centralize the register reporting (might want to move this function to Thread). Modified: lldb/trunk/include/lldb/Target/ThreadPlanCallFunction.h Modified: lldb/trunk/include/lldb/Target/ThreadPlanCallFunction.h URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Target/ThreadPlanCallFunction.h?rev=124016&r1=124015&r2=124016&view=diff ============================================================================== --- lldb/trunk/include/lldb/Target/ThreadPlanCallFunction.h (original) +++ lldb/trunk/include/lldb/Target/ThreadPlanCallFunction.h Fri Jan 21 19:28:29 2011 @@ -77,6 +77,7 @@ WillPop (); protected: + void ReportRegisterState (const char *message); private: void DoTakedown (); @@ -104,6 +105,7 @@ LanguageRuntime *m_cxx_language_runtime; LanguageRuntime *m_objc_language_runtime; Thread::ThreadStateCheckpoint m_stored_thread_state; + bool m_takedown_done; // We want to ensure we only do the takedown once. This ensures that. DISALLOW_COPY_AND_ASSIGN (ThreadPlanCallFunction); }; From jingham at apple.com Fri Jan 21 19:30:53 2011 From: jingham at apple.com (Jim Ingham) Date: Sat, 22 Jan 2011 01:30:53 -0000 Subject: [Lldb-commits] [lldb] r124017 - /lldb/trunk/source/Target/Process.cpp Message-ID: <20110122013053.607D82A6C12C@llvm.org> Author: jingham Date: Fri Jan 21 19:30:53 2011 New Revision: 124017 URL: http://llvm.org/viewvc/llvm-project?rev=124017&view=rev Log: Add more logging. Try to handle the case where "Halt" fails. This is kind of a losing game in the end, if we can't halt the target, it is not clear what we can do but keep trying... Modified: lldb/trunk/source/Target/Process.cpp Modified: lldb/trunk/source/Target/Process.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Target/Process.cpp?rev=124017&r1=124016&r2=124017&view=diff ============================================================================== --- lldb/trunk/source/Target/Process.cpp (original) +++ lldb/trunk/source/Target/Process.cpp Fri Jan 21 19:30:53 2011 @@ -2651,7 +2651,9 @@ single_thread_timeout_usec); } - if (exe_ctx.process->Halt().Success()) + Error halt_error = exe_ctx.process->Halt(); + + if (halt_error.Success()) { timeout_ptr = NULL; if (log) @@ -2698,6 +2700,22 @@ } } } + else + { + + if (log) + log->Printf ("Halt failed: \"%s\", I'm just going to wait a little longer and see if the world gets nicer to me.", + halt_error.AsCString()); + + if (single_thread_timeout_usec != 0) + { + real_timeout = TimeValue::Now(); + real_timeout.OffsetWithMicroSeconds(single_thread_timeout_usec); + timeout_ptr = &real_timeout; + } + continue; + } + } stop_state = Process::ProcessEventData::GetStateFromEvent(event_sp.get()); @@ -2722,7 +2740,13 @@ if (log) { StreamString s; - event_sp->Dump (&s); + if (event_sp) + event_sp->Dump (&s); + else + { + log->Printf ("Stop event that interrupted us is NULL."); + } + StreamString ts; const char *event_explanation; @@ -2764,7 +2788,7 @@ continue; } - ts.Printf("<"); + ts.Printf("<0x%4.4x ", thread->GetID()); RegisterContext *register_context = thread->GetRegisterContext().get(); if (register_context) @@ -2785,8 +2809,26 @@ event_explanation = ts.GetData(); } while (0); - if (log) - log->Printf("Execution interrupted: %s %s", s.GetData(), event_explanation); + // See if any of the threads that stopped think we ought to stop. Otherwise continue on. + if (!GetThreadList().ShouldStop(event_sp.get())) + { + if (log) + log->Printf("Execution interrupted, but nobody wanted to stop, so we continued: %s %s", + s.GetData(), event_explanation); + if (single_thread_timeout_usec != 0) + { + real_timeout = TimeValue::Now(); + real_timeout.OffsetWithMicroSeconds(single_thread_timeout_usec); + timeout_ptr = &real_timeout; + } + + continue; + } + else + { + if (log) + log->Printf("Execution interrupted: %s %s", s.GetData(), event_explanation); + } } if (discard_on_error && thread_plan_sp) From jingham at apple.com Fri Jan 21 19:33:44 2011 From: jingham at apple.com (Jim Ingham) Date: Sat, 22 Jan 2011 01:33:44 -0000 Subject: [Lldb-commits] [lldb] r124018 - in /lldb/trunk: include/lldb/Target/Process.h source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp source/Plugins/Process/gdb-remote/ProcessGDBRemote.h source/Target/ThreadList.cpp Message-ID: <20110122013344.EB8952A6C12C@llvm.org> Author: jingham Date: Fri Jan 21 19:33:44 2011 New Revision: 124018 URL: http://llvm.org/viewvc/llvm-project?rev=124018&view=rev Log: Added an interface for noticing new thread creation. At this point, I only turn it on when we are requesting a single thread to run. May seem like a silly thing to do, but the kernel on MacOS X will inject new threads into a program willy-nilly, and I would like to keep them from running if I can. Modified: lldb/trunk/include/lldb/Target/Process.h lldb/trunk/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp lldb/trunk/source/Plugins/Process/gdb-remote/ProcessGDBRemote.h lldb/trunk/source/Target/ThreadList.cpp Modified: lldb/trunk/include/lldb/Target/Process.h URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Target/Process.h?rev=124018&r1=124017&r2=124018&view=diff ============================================================================== --- lldb/trunk/include/lldb/Target/Process.h (original) +++ lldb/trunk/include/lldb/Target/Process.h Fri Jan 21 19:33:44 2011 @@ -1753,6 +1753,18 @@ m_dynamic_checkers_ap.reset(dynamic_checkers); } + virtual bool + StartNoticingNewThreads() + { + return true; + } + + virtual bool + StopNoticingNewThreads() + { + return true; + } + //------------------------------------------------------------------ // lldb::ExecutionContextScope pure virtual functions //------------------------------------------------------------------ Modified: lldb/trunk/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp?rev=124018&r1=124017&r2=124018&view=diff ============================================================================== --- lldb/trunk/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp (original) +++ lldb/trunk/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp Fri Jan 21 19:33:44 2011 @@ -119,7 +119,8 @@ m_packet_timeout (1), m_max_memory_size (512), m_waiting_for_attach (false), - m_local_debugserver (true) + m_local_debugserver (true), + m_thread_observation_bps() { } @@ -2279,3 +2280,91 @@ } } + +bool +ProcessGDBRemote::NewThreadNotifyBreakpointHit (void *baton, + lldb_private::StoppointCallbackContext *context, + lldb::user_id_t break_id, + lldb::user_id_t break_loc_id) +{ + // I don't think I have to do anything here, just make sure I notice the new thread when it starts to + // run so I can stop it if that's what I want to do. + LogSP log (lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_STEP)); + if (log) + log->Printf("Hit New Thread Notification breakpoint."); + return false; +} + + +bool +ProcessGDBRemote::StartNoticingNewThreads() +{ + static const char *bp_names[] = + { + "start_wqthread", + "_pthread_start", + NULL + }; + + LogSP log (lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_STEP)); + size_t num_bps = m_thread_observation_bps.size(); + if (num_bps != 0) + { + for (int i = 0; i < num_bps; i++) + { + lldb::BreakpointSP break_sp = m_target.GetBreakpointByID(m_thread_observation_bps[i]); + if (break_sp) + { + if (log) + log->Printf("Enabled noticing new thread breakpoint."); + break_sp->SetEnabled(true); + } + } + } + else + { + for (int i = 0; bp_names[i] != NULL; i++) + { + Breakpoint *breakpoint = m_target.CreateBreakpoint (NULL, bp_names[i], eFunctionNameTypeFull, true).get(); + if (breakpoint) + { + if (log) + log->Printf("Successfully created new thread notification breakpoint at \"%s\".", bp_names[i]); + m_thread_observation_bps.push_back(breakpoint->GetID()); + breakpoint->SetCallback (ProcessGDBRemote::NewThreadNotifyBreakpointHit, this, true); + } + else + { + if (log) + log->Printf("Failed to create new thread notification breakpoint."); + return false; + } + } + } + + return true; +} + +bool +ProcessGDBRemote::StopNoticingNewThreads() +{ + size_t num_bps = m_thread_observation_bps.size(); + if (num_bps != 0) + { + for (int i = 0; i < num_bps; i++) + { + LogSP log (lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_STEP)); + + lldb::BreakpointSP break_sp = m_target.GetBreakpointByID(m_thread_observation_bps[i]); + if (break_sp) + { + if (log) + log->Printf ("Disabling new thread notification breakpoint."); + break_sp->SetEnabled(false); + } + } + } + return true; +} + + Modified: lldb/trunk/source/Plugins/Process/gdb-remote/ProcessGDBRemote.h URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Process/gdb-remote/ProcessGDBRemote.h?rev=124018&r1=124017&r2=124018&view=diff ============================================================================== --- lldb/trunk/source/Plugins/Process/gdb-remote/ProcessGDBRemote.h (original) +++ lldb/trunk/source/Plugins/Process/gdb-remote/ProcessGDBRemote.h Fri Jan 21 19:33:44 2011 @@ -216,6 +216,12 @@ virtual lldb_private::DynamicLoader * GetDynamicLoader (); + + virtual bool + StartNoticingNewThreads(); + + virtual bool + StopNoticingNewThreads(); protected: friend class ThreadGDBRemote; @@ -336,6 +342,7 @@ size_t m_max_memory_size; // The maximum number of bytes to read/write when reading and writing memory bool m_waiting_for_attach; bool m_local_debugserver; // Is the debugserver process we are talking to local or on another machine. + std::vector m_thread_observation_bps; void ResetGDBRemoteState (); @@ -379,6 +386,12 @@ //------------------------------------------------------------------ // For ProcessGDBRemote only //------------------------------------------------------------------ + static bool + NewThreadNotifyBreakpointHit (void *baton, + lldb_private::StoppointCallbackContext *context, + lldb::user_id_t break_id, + lldb::user_id_t break_loc_id); + DISALLOW_COPY_AND_ASSIGN (ProcessGDBRemote); }; Modified: lldb/trunk/source/Target/ThreadList.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Target/ThreadList.cpp?rev=124018&r1=124017&r2=124018&view=diff ============================================================================== --- lldb/trunk/source/Target/ThreadList.cpp (original) +++ lldb/trunk/source/Target/ThreadList.cpp Fri Jan 21 19:33:44 2011 @@ -352,6 +352,10 @@ Mutex::Locker locker(m_threads_mutex); m_process->UpdateThreadListIfNeeded(); + + LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_STEP)); + if (log) + log->Printf ("Turning off notification of new threads while single stepping a thread."); collection::iterator pos, end = m_threads.end(); for (pos = m_threads.begin(); pos != end; ++pos) @@ -403,6 +407,20 @@ } } + if (wants_solo_run) + { + LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_STEP)); + if (log) + log->Printf ("Turning on notification of new threads while single stepping a thread."); + m_process->StartNoticingNewThreads(); + } + else + { + LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_STEP)); + if (log) + log->Printf ("Turning off notification of new threads while single stepping a thread."); + m_process->StopNoticingNewThreads(); + } // Give all the threads that are likely to run a last chance to set up their state before we // negotiate who is actually going to get a chance to run... From gclayton at apple.com Sat Jan 22 01:12:45 2011 From: gclayton at apple.com (Greg Clayton) Date: Sat, 22 Jan 2011 07:12:45 -0000 Subject: [Lldb-commits] [lldb] r124024 - in /lldb/trunk: source/Plugins/Process/gdb-remote/GDBRemoteCommunication.cpp source/Plugins/Process/gdb-remote/GDBRemoteCommunication.h source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp source/Symbol/ClangASTContext.cpp source/Symbol/ClangASTType.cpp source/Target/Process.cpp tools/debugserver/source/RNBRemote.cpp Message-ID: <20110122071245.9633C2A6C12C@llvm.org> Author: gclayton Date: Sat Jan 22 01:12:45 2011 New Revision: 124024 URL: http://llvm.org/viewvc/llvm-project?rev=124024&view=rev Log: Sped up the shutdown time on MacOSX by quite a bit by making sure any threads that we spawn let us know when they are going away and that we don't timeout waiting for a message from threads that have gone away. We also now don't expect the "k" packet (kill) to send a response. This greatly speeds up debugger shutdown performance. The test suite now runs quite a bit faster. Added a fix to the variable display code that fixes the display of base classes. We were assuming the virtual or normal base class offsets were being given in bit sizes, but they were being given as character sizes, so we needed to multiply the offset by 8. This wasn't affecting the expression parser, but it was affecting the correct display of C++ class base classes and all of their children. Modified: lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.cpp lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.h lldb/trunk/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp lldb/trunk/source/Symbol/ClangASTContext.cpp lldb/trunk/source/Symbol/ClangASTType.cpp lldb/trunk/source/Target/Process.cpp lldb/trunk/tools/debugserver/source/RNBRemote.cpp Modified: lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.cpp?rev=124024&r1=124023&r2=124024&view=diff ============================================================================== --- lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.cpp (original) +++ lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.cpp Sat Jan 22 01:12:45 2011 @@ -87,15 +87,24 @@ } size_t -GDBRemoteCommunication::SendAck (char ack_char) +GDBRemoteCommunication::SendAck () { - Mutex::Locker locker(m_sequence_mutex); - ProcessGDBRemoteLog::LogIf (GDBR_LOG_PACKETS, "send packet: %c", ack_char); + ProcessGDBRemoteLog::LogIf (GDBR_LOG_PACKETS, "send packet: +"); ConnectionStatus status = eConnectionStatusSuccess; + char ack_char = '+'; return Write (&ack_char, 1, status, NULL) == 1; } size_t +GDBRemoteCommunication::SendNack () +{ + ProcessGDBRemoteLog::LogIf (GDBR_LOG_PACKETS, "send packet: -"); + ConnectionStatus status = eConnectionStatusSuccess; + char nack_char = '-'; + return Write (&nack_char, 1, status, NULL) == 1; +} + +size_t GDBRemoteCommunication::SendPacketAndWaitForResponse ( const char *payload, @@ -141,7 +150,8 @@ m_async_packet_predicate.SetValue (true, eBroadcastNever); bool timed_out = false; - if (SendInterrupt(locker, 1, &timed_out)) + bool sent_interrupt = false; + if (SendInterrupt(locker, 1, sent_interrupt, timed_out)) { if (m_async_packet_predicate.WaitForValueEqualTo (false, &timeout_time, &timed_out)) { @@ -443,8 +453,9 @@ { m_async_signal = signo; bool timed_out = false; + bool sent_interrupt = false; Mutex::Locker locker; - if (SendInterrupt (locker, 1, &timed_out)) + if (SendInterrupt (locker, 1, sent_interrupt, timed_out)) return true; m_async_signal = -1; return false; @@ -461,10 +472,16 @@ // (gdb remote protocol requires this), and do what we need to do, then resume. bool -GDBRemoteCommunication::SendInterrupt (Mutex::Locker& locker, uint32_t seconds_to_wait_for_stop, bool *timed_out) +GDBRemoteCommunication::SendInterrupt +( + Mutex::Locker& locker, + uint32_t seconds_to_wait_for_stop, + bool &sent_interrupt, + bool &timed_out +) { - if (timed_out) - *timed_out = false; + sent_interrupt = false; + timed_out = false; if (IsConnected() && IsRunning()) { @@ -484,8 +501,9 @@ ProcessGDBRemoteLog::LogIf (GDBR_LOG_PACKETS, "send packet: \\x03"); if (Write (&ctrl_c, 1, status, NULL) > 0) { + sent_interrupt = true; if (seconds_to_wait_for_stop) - m_private_is_running.WaitForValueEqualTo (false, &timeout, timed_out); + m_private_is_running.WaitForValueEqualTo (false, &timeout, &timed_out); return true; } } @@ -553,9 +571,9 @@ checksum_error = packet_checksum != actual_checksum; // Send the ack or nack if needed if (checksum_error || !success) - SendAck('-'); + SendNack(); else - SendAck('+'); + SendAck(); } } else Modified: lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.h URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.h?rev=124024&r1=124023&r2=124024&view=diff ============================================================================== --- lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.h (original) +++ lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.h Sat Jan 22 01:12:45 2011 @@ -87,7 +87,11 @@ GetAck (uint32_t timeout_seconds); size_t - SendAck (char ack_char); + SendAck (); + + size_t + SendNack (); + char CalculcateChecksum (const char *payload, @@ -117,7 +121,8 @@ bool SendInterrupt (lldb_private::Mutex::Locker &locker, uint32_t seconds_to_wait_for_stop, - bool *timed_out = NULL); + bool &sent_interrupt, + bool &timed_out); bool GetSequenceMutex(lldb_private::Mutex::Locker& locker); Modified: lldb/trunk/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp?rev=124024&r1=124023&r2=124024&view=diff ============================================================================== --- lldb/trunk/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp (original) +++ lldb/trunk/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp Sat Jan 22 01:12:45 2011 @@ -541,7 +541,7 @@ if (m_gdb_comm.StartReadThread(&error)) { // Send an initial ack - m_gdb_comm.SendAck('+'); + m_gdb_comm.SendAck(); if (m_debugserver_pid != LLDB_INVALID_PROCESS_ID) m_debugserver_thread = Host::StartMonitoringChildProcess (MonitorDebugserverProcess, @@ -1141,24 +1141,16 @@ ProcessGDBRemote::DoHalt (bool &caused_stop) { Error error; - - if (m_gdb_comm.IsRunning()) - { - caused_stop = true; - bool timed_out = false; - Mutex::Locker locker; - if (!m_gdb_comm.SendInterrupt (locker, 2, &timed_out)) - { - if (timed_out) - error.SetErrorString("timed out sending interrupt packet"); - else - error.SetErrorString("unknown error sending interrupt packet"); - } - } - else + bool timed_out = false; + Mutex::Locker locker; + + if (!m_gdb_comm.SendInterrupt (locker, 2, caused_stop, timed_out)) { - caused_stop = false; + if (timed_out) + error.SetErrorString("timed out sending interrupt packet"); + else + error.SetErrorString("unknown error sending interrupt packet"); } return error; @@ -1172,11 +1164,12 @@ if (m_gdb_comm.IsRunning()) { bool timed_out = false; + bool sent_interrupt = false; Mutex::Locker locker; PausePrivateStateThread(); m_thread_list.DiscardThreadPlans(); m_debugserver_pid = LLDB_INVALID_PROCESS_ID; - if (!m_gdb_comm.SendInterrupt (locker, 2, &timed_out)) + if (!m_gdb_comm.SendInterrupt (locker, 2, sent_interrupt, timed_out)) { if (timed_out) error.SetErrorString("timed out sending interrupt packet"); @@ -1238,22 +1231,10 @@ log->Printf ("ProcessGDBRemote::DoDestroy()"); // Interrupt if our inferior is running... - Mutex::Locker locker; - m_gdb_comm.SendInterrupt (locker, 1); - DisableAllBreakpointSites (); - SetExitStatus(-1, "process killed"); - - StringExtractorGDBRemote response; - if (m_gdb_comm.SendPacketAndWaitForResponse("k", response, 1, false)) + if (m_gdb_comm.IsConnected()) { - log = ProcessGDBRemoteLog::GetLogIfAllCategoriesSet(GDBR_LOG_PROCESS); - if (log) - { - if (response.IsOKPacket()) - log->Printf ("ProcessGDBRemote::DoDestroy() kill was successful"); - else - log->Printf ("ProcessGDBRemote::DoDestroy() kill failed: %s", response.GetStringRef().c_str()); - } + // Don't get a response when killing our + m_gdb_comm.SendPacket ("k", 1); } StopAsyncThread (); Modified: lldb/trunk/source/Symbol/ClangASTContext.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Symbol/ClangASTContext.cpp?rev=124024&r1=124023&r2=124024&view=diff ============================================================================== --- lldb/trunk/source/Symbol/ClangASTContext.cpp (original) +++ lldb/trunk/source/Symbol/ClangASTContext.cpp Sat Jan 22 01:12:45 2011 @@ -2475,9 +2475,9 @@ if (base_class->isVirtual()) - bit_offset = record_layout.getVBaseClassOffset(base_class_decl).getQuantity(); + bit_offset = record_layout.getVBaseClassOffset(base_class_decl).getQuantity() * 8; else - bit_offset = record_layout.getBaseClassOffset(base_class_decl).getQuantity(); + bit_offset = record_layout.getBaseClassOffset(base_class_decl).getQuantity() * 8; // Base classes should be a multiple of 8 bits in size assert (bit_offset % 8 == 0); Modified: lldb/trunk/source/Symbol/ClangASTType.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Symbol/ClangASTType.cpp?rev=124024&r1=124023&r2=124024&view=diff ============================================================================== --- lldb/trunk/source/Symbol/ClangASTType.cpp (original) +++ lldb/trunk/source/Symbol/ClangASTType.cpp Sat Jan 22 01:12:45 2011 @@ -392,9 +392,9 @@ continue; if (base_class->isVirtual()) - field_bit_offset = record_layout.getVBaseClassOffset(base_class_decl).getQuantity(); + field_bit_offset = record_layout.getVBaseClassOffset(base_class_decl).getQuantity() * 8; else - field_bit_offset = record_layout.getBaseClassOffset(base_class_decl).getQuantity(); + field_bit_offset = record_layout.getBaseClassOffset(base_class_decl).getQuantity() * 8; field_byte_offset = field_bit_offset / 8; assert (field_bit_offset % 8 == 0); if (child_idx == 0) Modified: lldb/trunk/source/Target/Process.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Target/Process.cpp?rev=124024&r1=124023&r2=124024&view=diff ============================================================================== --- lldb/trunk/source/Target/Process.cpp (original) +++ lldb/trunk/source/Target/Process.cpp Sat Jan 22 01:12:45 2011 @@ -407,7 +407,6 @@ event_sp)) state = Process::ProcessEventData::GetStateFromEvent(event_sp.get()); - log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_PROCESS); if (log) log->Printf ("Process::%s (timeout = %p, event_sp) => %s", __FUNCTION__, @@ -427,7 +426,6 @@ Event *event_ptr; event_ptr = m_listener.PeekAtNextEventForBroadcasterWithType (this, eBroadcastBitStateChanged); - log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_PROCESS); if (log) { if (event_ptr) @@ -463,7 +461,6 @@ // This is a bit of a hack, but when we wait here we could very well return // to the command-line, and that could disable the log, which would render the // log we got above invalid. - log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_PROCESS); if (log) log->Printf ("Process::%s (timeout = %p, event_sp) => %s", __FUNCTION__, timeout, StateAsCString(state)); return state; @@ -2140,7 +2137,6 @@ break; } - log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_PROCESS); if (log) log->Printf ("Process::%s (arg = %p, pid = %i) got a control event: %d", __FUNCTION__, this, GetID(), event_sp->GetType()); @@ -2160,7 +2156,6 @@ internal_state == eStateExited || internal_state == eStateDetached ) { - log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_PROCESS); if (log) log->Printf ("Process::%s (arg = %p, pid = %i) about to exit with internal state %s...", __FUNCTION__, this, GetID(), StateAsCString(internal_state)); @@ -2169,10 +2164,11 @@ } // Verify log is still enabled before attempting to write to it... - log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_PROCESS); if (log) log->Printf ("Process::%s (arg = %p, pid = %i) thread exiting...", __FUNCTION__, this, GetID()); + m_private_state_control_wait.SetValue (true, eBroadcastAlways); + m_private_state_thread = LLDB_INVALID_HOST_THREAD; return NULL; } Modified: lldb/trunk/tools/debugserver/source/RNBRemote.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/tools/debugserver/source/RNBRemote.cpp?rev=124024&r1=124023&r2=124024&view=diff ============================================================================== --- lldb/trunk/tools/debugserver/source/RNBRemote.cpp (original) +++ lldb/trunk/tools/debugserver/source/RNBRemote.cpp Sat Jan 22 01:12:45 2011 @@ -3123,11 +3123,10 @@ rnb_err_t RNBRemote::HandlePacket_k (const char *p) { - if (!m_ctx.HasValidProcessID()) - return SendPacket ("E26"); - if (!DNBProcessKill (m_ctx.ProcessID())) - return SendPacket ("E27"); - return SendPacket ("OK"); + // No response to should be sent to the kill packet + if (m_ctx.HasValidProcessID()) + DNBProcessKill (m_ctx.ProcessID()); + return rnb_success; } rnb_err_t From gclayton at apple.com Sat Jan 22 11:43:17 2011 From: gclayton at apple.com (Greg Clayton) Date: Sat, 22 Jan 2011 17:43:17 -0000 Subject: [Lldb-commits] [lldb] r124038 - /lldb/trunk/source/Target/Process.cpp Message-ID: <20110122174317.CB9682A6C12C@llvm.org> Author: gclayton Date: Sat Jan 22 11:43:17 2011 New Revision: 124038 URL: http://llvm.org/viewvc/llvm-project?rev=124038&view=rev Log: Avoid the race condition Stephen Wilson was worried about in revision 123465 by making a local copy. We need to be able to have the private state thread let the lldb_private::Process class that it has exited, otherwise we end up with a timeout when the process destructor or DoDestroy is called where the private state thread has already exited and then StopPrivateStateThread() will wait for the thread which has already existed to respond to it. Modified: lldb/trunk/source/Target/Process.cpp Modified: lldb/trunk/source/Target/Process.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Target/Process.cpp?rev=124038&r1=124037&r2=124038&view=diff ============================================================================== --- lldb/trunk/source/Target/Process.cpp (original) +++ lldb/trunk/source/Target/Process.cpp Sat Jan 22 11:43:17 2011 @@ -2037,10 +2037,13 @@ signal == eBroadcastInternalStateControlResume); if (log) - log->Printf ("Process::%s ( ) - signal: %d", __FUNCTION__, signal); + log->Printf ("Process::%s (signal = %d)", __FUNCTION__, signal); - // Signal the private state thread - if (m_private_state_thread != LLDB_INVALID_HOST_THREAD) + // Signal the private state thread. First we should copy this is case the + // thread starts exiting since the private state thread will NULL this out + // when it exits + const lldb::thread_t private_state_thread = m_private_state_thread; + if (private_state_thread != LLDB_INVALID_HOST_THREAD) { TimeValue timeout_time; bool timed_out; @@ -2055,10 +2058,10 @@ if (signal == eBroadcastInternalStateControlStop) { if (timed_out) - Host::ThreadCancel (m_private_state_thread, NULL); + Host::ThreadCancel (private_state_thread, NULL); thread_result_t result = NULL; - Host::ThreadJoin (m_private_state_thread, &result, NULL); + Host::ThreadJoin (private_state_thread, &result, NULL); m_private_state_thread = LLDB_INVALID_HOST_THREAD; } } From gclayton at apple.com Sat Jan 22 17:43:18 2011 From: gclayton at apple.com (Greg Clayton) Date: Sat, 22 Jan 2011 23:43:18 -0000 Subject: [Lldb-commits] [lldb] r124049 - in /lldb/trunk: include/lldb/Target/ source/API/ source/Plugins/Process/gdb-remote/ source/Target/ tools/debugserver/source/ tools/debugserver/source/MacOSX/ Message-ID: <20110122234319.1C42F2A6C12C@llvm.org> Author: gclayton Date: Sat Jan 22 17:43:18 2011 New Revision: 124049 URL: http://llvm.org/viewvc/llvm-project?rev=124049&view=rev Log: Fixed an issue in "SBError SBProcess::Destroy ()" where it wasn't properly checking the validity of the shared pointer prior to using it. Fixed the GDB remote plug-in to once again watch for a reply from the "k" packet, and fixed the logic to make sure the thread requesting the kill and the async thread play nice (and very quickly) by synchronizing the packet sending and reply. I also tweaked some of the shut down packet ("k" kill, "D" detach, and the halt packet) to make sure they do the right thing. Fixed "StateType Process::WaitForProcessStopPrivate (...)" to correctly pass the timeout along to WaitForStateChangedEventsPrivate() and made the function behave correctly with respect to timing out. Added separate STDIN, STDOUT, and STDERR support to debugserver. Also added the start of being able to set the working directory for the inferior process. Modified: lldb/trunk/include/lldb/Target/Process.h lldb/trunk/source/API/SBProcess.cpp lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.cpp lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.h lldb/trunk/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp lldb/trunk/source/Plugins/Process/gdb-remote/ProcessGDBRemote.h lldb/trunk/source/Target/Process.cpp lldb/trunk/tools/debugserver/source/DNB.cpp lldb/trunk/tools/debugserver/source/DNB.h lldb/trunk/tools/debugserver/source/MacOSX/MachProcess.cpp lldb/trunk/tools/debugserver/source/MacOSX/MachProcess.h lldb/trunk/tools/debugserver/source/RNBContext.cpp lldb/trunk/tools/debugserver/source/RNBContext.h lldb/trunk/tools/debugserver/source/RNBRemote.cpp lldb/trunk/tools/debugserver/source/debugserver.cpp Modified: lldb/trunk/include/lldb/Target/Process.h URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Target/Process.h?rev=124049&r1=124048&r2=124049&view=diff ============================================================================== --- lldb/trunk/include/lldb/Target/Process.h (original) +++ lldb/trunk/include/lldb/Target/Process.h Sat Jan 22 17:43:18 2011 @@ -1260,7 +1260,7 @@ /// /// @see lldb::StateType //------------------------------------------------------------------ - virtual void + virtual bool SetExitStatus (int exit_status, const char *cstr); //------------------------------------------------------------------ Modified: lldb/trunk/source/API/SBProcess.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/API/SBProcess.cpp?rev=124049&r1=124048&r2=124049&view=diff ============================================================================== --- lldb/trunk/source/API/SBProcess.cpp (original) +++ lldb/trunk/source/API/SBProcess.cpp Sat Jan 22 17:43:18 2011 @@ -421,11 +421,12 @@ SBError SBProcess::Destroy () { - Mutex::Locker api_locker (m_opaque_sp->GetTarget().GetAPIMutex()); - SBError sb_error; if (m_opaque_sp) + { + Mutex::Locker api_locker (m_opaque_sp->GetTarget().GetAPIMutex()); sb_error.SetError(m_opaque_sp->Destroy()); + } else sb_error.SetErrorString ("SBProcess is invalid"); @@ -434,7 +435,10 @@ { SBStream sstr; sb_error.GetDescription (sstr); - log->Printf ("SBProcess(%p)::Destroy () => SBError (%p): %s", m_opaque_sp.get(), sb_error.get(), sstr.GetData()); + log->Printf ("SBProcess(%p)::Destroy () => SBError (%p): %s", + m_opaque_sp.get(), + sb_error.get(), + sstr.GetData()); } return sb_error; Modified: lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.cpp?rev=124049&r1=124048&r2=124049&view=diff ============================================================================== --- lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.cpp (original) +++ lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.cpp Sat Jan 22 17:43:18 2011 @@ -511,6 +511,18 @@ return false; } +bool +GDBRemoteCommunication::WaitForNotRunning (const TimeValue *timeout_ptr) +{ + return m_public_is_running.WaitForValueEqualTo (false, timeout_ptr, NULL); +} + +bool +GDBRemoteCommunication::WaitForNotRunningPrivate (const TimeValue *timeout_ptr) +{ + return m_private_is_running.WaitForValueEqualTo (false, timeout_ptr, NULL); +} + size_t GDBRemoteCommunication::WaitForPacket (StringExtractorGDBRemote &response, uint32_t timeout_seconds) { @@ -522,14 +534,14 @@ } size_t -GDBRemoteCommunication::WaitForPacket (StringExtractorGDBRemote &response, TimeValue* timeout_time_ptr) +GDBRemoteCommunication::WaitForPacket (StringExtractorGDBRemote &response, const TimeValue* timeout_time_ptr) { Mutex::Locker locker(m_sequence_mutex); return WaitForPacketNoLock (response, timeout_time_ptr); } size_t -GDBRemoteCommunication::WaitForPacketNoLock (StringExtractorGDBRemote &response, TimeValue* timeout_time_ptr) +GDBRemoteCommunication::WaitForPacketNoLock (StringExtractorGDBRemote &response, const TimeValue* timeout_time_ptr) { bool checksum_error = false; response.Clear (); Modified: lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.h URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.h?rev=124049&r1=124048&r2=124049&view=diff ============================================================================== --- lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.h (original) +++ lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.h Sat Jan 22 17:43:18 2011 @@ -81,7 +81,7 @@ // wait indefinitely. size_t WaitForPacket (StringExtractorGDBRemote &response, - lldb_private::TimeValue* timeout); + const lldb_private::TimeValue* timeout); char GetAck (uint32_t timeout_seconds); @@ -222,7 +222,10 @@ { return m_public_is_running.GetValue(); } - + + bool + WaitForNotRunning (const lldb_private::TimeValue *timeout_ptr); + bool GetHostInfo (uint32_t timeout_seconds); @@ -256,7 +259,10 @@ size_t WaitForPacketNoLock (StringExtractorGDBRemote &response, - lldb_private::TimeValue* timeout_time_ptr); + const lldb_private::TimeValue* timeout_ptr); + + bool + WaitForNotRunningPrivate (const lldb_private::TimeValue *timeout_ptr); //------------------------------------------------------------------ // Classes that inherit from GDBRemoteCommunication can see and modify these Modified: lldb/trunk/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp?rev=124049&r1=124048&r2=124049&view=diff ============================================================================== --- lldb/trunk/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp (original) +++ lldb/trunk/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp Sat Jan 22 17:43:18 2011 @@ -1157,7 +1157,13 @@ } Error -ProcessGDBRemote::WillDetach () +ProcessGDBRemote::InterruptIfRunning +( + bool discard_thread_plans, + bool catch_stop_event, + bool resume_private_state_thread, + EventSP &stop_event_sp +) { Error error; @@ -1166,30 +1172,54 @@ bool timed_out = false; bool sent_interrupt = false; Mutex::Locker locker; - PausePrivateStateThread(); - m_thread_list.DiscardThreadPlans(); - m_debugserver_pid = LLDB_INVALID_PROCESS_ID; - if (!m_gdb_comm.SendInterrupt (locker, 2, sent_interrupt, timed_out)) + + if (catch_stop_event) + PausePrivateStateThread(); + + if (discard_thread_plans) + m_thread_list.DiscardThreadPlans(); + + //m_debugserver_pid = LLDB_INVALID_PROCESS_ID; + if (!m_gdb_comm.SendInterrupt (locker, 1, sent_interrupt, timed_out)) { if (timed_out) error.SetErrorString("timed out sending interrupt packet"); else error.SetErrorString("unknown error sending interrupt packet"); - ResumePrivateStateThread(); + if (catch_stop_event) + ResumePrivateStateThread(); + return error; + } + + + if (catch_stop_event) + { + TimeValue timeout_time; + timeout_time = TimeValue::Now(); + timeout_time.OffsetWithSeconds(1); + StateType state = WaitForProcessStopPrivate (&timeout_time, stop_event_sp); + + if (state == eStateInvalid) + error.SetErrorString("unable to verify target stopped"); } - TimeValue timeout_time; - timeout_time = TimeValue::Now(); - timeout_time.OffsetWithSeconds(2); - - EventSP event_sp; - StateType state = WaitForStateChangedEventsPrivate (&timeout_time, event_sp); - if (state != eStateStopped) - error.SetErrorString("unable to stop target"); + + if (catch_stop_event && resume_private_state_thread) + ResumePrivateStateThread(); } return error; } Error +ProcessGDBRemote::WillDetach () +{ + bool discard_thread_plans = true; + bool catch_stop_event = true; + bool resume_private_state_thread = false; // DoDetach will resume the thread + EventSP event_sp; + return InterruptIfRunning (discard_thread_plans, catch_stop_event, resume_private_state_thread, event_sp); +} + +Error ProcessGDBRemote::DoDetach() { Error error; @@ -1223,6 +1253,16 @@ } Error +ProcessGDBRemote::WillDestroy () +{ + bool discard_thread_plans = true; + bool catch_stop_event = true; + bool resume_private_state_thread = true; + EventSP event_sp; + return InterruptIfRunning (discard_thread_plans, catch_stop_event, resume_private_state_thread, event_sp); +} + +Error ProcessGDBRemote::DoDestroy () { Error error; @@ -1233,10 +1273,40 @@ // Interrupt if our inferior is running... if (m_gdb_comm.IsConnected()) { - // Don't get a response when killing our - m_gdb_comm.SendPacket ("k", 1); - } + m_continue_packet.Clear(); + m_continue_packet.Printf("k"); + Listener listener ("gdb-remote.kill-packet-sent"); + if (listener.StartListeningForEvents (&m_gdb_comm, GDBRemoteCommunication::eBroadcastBitRunPacketSent)) + { + EventSP event_sp; + TimeValue timeout; + timeout = TimeValue::Now(); + timeout.OffsetWithSeconds (1); + m_async_broadcaster.BroadcastEvent (eBroadcastBitAsyncContinue, new EventDataBytes (m_continue_packet.GetData(), m_continue_packet.GetSize())); + // Wait for the async thread to send the "k" packet + if (listener.WaitForEvent (&timeout, event_sp)) + { + if (log) + log->Printf ("ProcessGDBRemote::DoDestroy() got confirmation the \"k\" packet was sent"); + } + else + { + if (log) + log->Printf ("ProcessGDBRemote::DoDestroy() timed out waiting for \"k\" packet to be sent"); + error.SetErrorString("Resume timed out."); + } + + // Wait for the async thread to exit which will indicate we stopped. + // Hopefully the stop will be a process exited state since we are + // asking the process to go away. + if (!m_gdb_comm.WaitForNotRunning (&timeout)) + { + if (log) + log->Printf ("ProcessGDBRemote::DoDestroy() timed out waiting for \"k\" stop reply packet"); + } + } + } StopAsyncThread (); m_gdb_comm.StopReadThread(); KillDebugserverProcess (); @@ -1851,14 +1921,14 @@ log->Printf("%s arguments:\n%s", debugserver_args.GetArgumentAtIndex(0), strm.GetData()); } - error.SetError(::posix_spawnp (&m_debugserver_pid, - debugserver_path, - file_actions_err.Success() ? &file_actions : NULL, - &attr, - debugserver_args.GetArgumentVector(), - (char * const*)inferior_envp), - eErrorTypePOSIX); - + error.SetError (::posix_spawnp (&m_debugserver_pid, + debugserver_path, + file_actions_err.Success() ? &file_actions : NULL, + &attr, + debugserver_args.GetArgumentVector(), + (char * const*)inferior_envp), + eErrorTypePOSIX); + ::posix_spawnattr_destroy (&attr); @@ -1907,7 +1977,11 @@ // debugserver that we are tracking... ProcessGDBRemote *process = (ProcessGDBRemote *)callback_baton; - + + LogSP log (ProcessGDBRemoteLog::GetLogIfAllCategoriesSet(GDBR_LOG_PROCESS)); + if (log) + log->Printf ("ProcessGDBRemote::MonitorDebugserverProcess (baton=%p, pid=%i, signo=%i (0x%x), exit_status=%i)", callback_baton, debugserver_pid, signo, signo, exit_status); + if (process) { // Sleep for a half a second to make sure our inferior process has Modified: lldb/trunk/source/Plugins/Process/gdb-remote/ProcessGDBRemote.h URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Process/gdb-remote/ProcessGDBRemote.h?rev=124049&r1=124048&r2=124049&view=diff ============================================================================== --- lldb/trunk/source/Plugins/Process/gdb-remote/ProcessGDBRemote.h (original) +++ lldb/trunk/source/Plugins/Process/gdb-remote/ProcessGDBRemote.h Sat Jan 22 17:43:18 2011 @@ -149,6 +149,9 @@ DoSignal (int signal); virtual lldb_private::Error + WillDestroy (); + + virtual lldb_private::Error DoDestroy (); virtual void @@ -382,6 +385,12 @@ const char *bytes, size_t bytes_len); + lldb_private::Error + InterruptIfRunning (bool discard_thread_plans, + bool catch_stop_event, + bool resume_private_state_thread, + lldb::EventSP &stop_event_sp); + private: //------------------------------------------------------------------ // For ProcessGDBRemote only Modified: lldb/trunk/source/Target/Process.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Target/Process.cpp?rev=124049&r1=124048&r2=124049&view=diff ============================================================================== --- lldb/trunk/source/Target/Process.cpp (original) +++ lldb/trunk/source/Target/Process.cpp Sat Jan 22 17:43:18 2011 @@ -452,17 +452,22 @@ log->Printf ("Process::%s (timeout = %p, event_sp)...", __FUNCTION__, timeout); StateType state = eStateInvalid; - if (m_private_state_listener.WaitForEventForBroadcasterWithType(timeout, - &m_private_state_broadcaster, - eBroadcastBitStateChanged, - event_sp)) + if (m_private_state_listener.WaitForEventForBroadcasterWithType (timeout, + &m_private_state_broadcaster, + eBroadcastBitStateChanged, + event_sp)) state = Process::ProcessEventData::GetStateFromEvent(event_sp.get()); // This is a bit of a hack, but when we wait here we could very well return // to the command-line, and that could disable the log, which would render the // log we got above invalid. if (log) - log->Printf ("Process::%s (timeout = %p, event_sp) => %s", __FUNCTION__, timeout, StateAsCString(state)); + { + if (state == eStateInvalid) + log->Printf ("Process::%s (timeout = %p, event_sp) => TIMEOUT", __FUNCTION__, timeout); + else + log->Printf ("Process::%s (timeout = %p, event_sp) => %s", __FUNCTION__, timeout, StateAsCString(state)); + } return state; } @@ -547,21 +552,23 @@ return NULL; } -void +bool Process::SetExitStatus (int status, const char *cstr) { - if (m_private_state.GetValue() != eStateExited) - { - m_exit_status = status; - if (cstr) - m_exit_string = cstr; - else - m_exit_string.clear(); + // We were already in the exited state + if (m_private_state.GetValue() == eStateExited) + return false; + + m_exit_status = status; + if (cstr) + m_exit_string = cstr; + else + m_exit_string.clear(); - DidExit (); + DidExit (); - SetPrivateState (eStateExited); - } + SetPrivateState (eStateExited); + return true; } // This static callback can be used to watch for local child processes on @@ -1425,11 +1432,17 @@ // call DidLaunch: while (1) { - // FIXME: Might want to put a timeout in here: - state = WaitForStateChangedEventsPrivate (NULL, event_sp); - if (state == eStateStopped || state == eStateCrashed || state == eStateExited) + event_sp.reset(); + state = WaitForStateChangedEventsPrivate (timeout, event_sp); + + if (StateIsStoppedState(state)) break; - else + + // If state is invalid, then we timed out + if (state == eStateInvalid) + break; + + if (event_sp) HandlePrivateEvent (event_sp); } return state; @@ -1744,7 +1757,7 @@ // Wait for 2 seconds for the process to stop. TimeValue timeout_time; timeout_time = TimeValue::Now(); - timeout_time.OffsetWithSeconds(2); + timeout_time.OffsetWithSeconds(1); StateType state = WaitForStateChangedEventsPrivate (&timeout_time, event_sp); if (state == eStateInvalid) Modified: lldb/trunk/tools/debugserver/source/DNB.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/tools/debugserver/source/DNB.cpp?rev=124049&r1=124048&r2=124049&view=diff ============================================================================== --- lldb/trunk/tools/debugserver/source/DNB.cpp (original) +++ lldb/trunk/tools/debugserver/source/DNB.cpp Sat Jan 22 17:43:18 2011 @@ -175,7 +175,10 @@ DNBProcessLaunch (const char *path, char const *argv[], const char *envp[], - const char *stdio_path, + const char *working_directory, // NULL => dont' change, non-NULL => set working directory for inferior to this + const char *stdin_path, + const char *stdout_path, + const char *stderr_path, bool no_stdio, nub_launch_flavor_t launch_flavor, int disable_aslr, @@ -199,7 +202,17 @@ if (processSP.get()) { DNBError launch_err; - pid_t pid = processSP->LaunchForDebug(path, argv, envp, stdio_path, no_stdio, launch_flavor, disable_aslr, launch_err); + pid_t pid = processSP->LaunchForDebug (path, + argv, + envp, + working_directory, + stdin_path, + stdout_path, + stderr_path, + no_stdio, + launch_flavor, + disable_aslr, + launch_err); if (err_str) { *err_str = '\0'; Modified: lldb/trunk/tools/debugserver/source/DNB.h URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/tools/debugserver/source/DNB.h?rev=124049&r1=124048&r2=124049&view=diff ============================================================================== --- lldb/trunk/tools/debugserver/source/DNB.h (original) +++ lldb/trunk/tools/debugserver/source/DNB.h Sat Jan 22 17:43:18 2011 @@ -33,7 +33,19 @@ //---------------------------------------------------------------------- // Process control //---------------------------------------------------------------------- -nub_process_t DNBProcessLaunch (const char *path, char const *argv[], const char *envp[], const char *stdio_path, bool no_stdio, nub_launch_flavor_t launch_flavor, int disable_aslr, char *err_str, size_t err_len) DNB_EXPORT; +nub_process_t DNBProcessLaunch (const char *path, + char const *argv[], + const char *envp[], + const char *working_directory, // NULL => dont' change, non-NULL => set working directory for inferior to this + const char *stdin_path, + const char *stdout_path, + const char *stderr_path, + bool no_stdio, + nub_launch_flavor_t launch_flavor, + int disable_aslr, + char *err_str, + size_t err_len) DNB_EXPORT; + nub_process_t DNBProcessAttach (nub_process_t pid, struct timespec *timeout, char *err_str, size_t err_len) DNB_EXPORT; nub_process_t DNBProcessAttachByName (const char *name, struct timespec *timeout, char *err_str, size_t err_len) DNB_EXPORT; nub_process_t DNBProcessAttachWait (const char *wait_name, nub_launch_flavor_t launch_flavor, struct timespec *timeout, useconds_t interval, char *err_str, size_t err_len, DNBShouldCancelCallback should_cancel = NULL, void *callback_data = NULL) DNB_EXPORT; Modified: lldb/trunk/tools/debugserver/source/MacOSX/MachProcess.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/tools/debugserver/source/MacOSX/MachProcess.cpp?rev=124049&r1=124048&r2=124049&view=diff ============================================================================== --- lldb/trunk/tools/debugserver/source/MacOSX/MachProcess.cpp (original) +++ lldb/trunk/tools/debugserver/source/MacOSX/MachProcess.cpp Sat Jan 22 17:43:18 2011 @@ -1491,7 +1491,10 @@ const char *path, char const *argv[], char const *envp[], - const char *stdio_path, + const char *working_directory, // NULL => dont' change, non-NULL => set working directory for inferior to this + const char *stdin_path, + const char *stdout_path, + const char *stderr_path, bool no_stdio, nub_launch_flavor_t launch_flavor, int disable_aslr, @@ -1517,7 +1520,10 @@ DNBArchProtocol::GetArchitecture (), argv, envp, - stdio_path, + working_directory, + stdin_path, + stdout_path, + stderr_path, no_stdio, this, disable_aslr, @@ -1607,7 +1613,10 @@ cpu_type_t cpu_type, char const *argv[], char const *envp[], - const char *stdio_path, + const char *working_directory, + const char *stdin_path, + const char *stdout_path, + const char *stderr_path, bool no_stdio, MachProcess* process, int disable_aslr, @@ -1665,14 +1674,13 @@ pid_t pid = INVALID_NUB_PROCESS; if (file_actions_valid) { - if (stdio_path == NULL && !no_stdio) + if (stdin_path == NULL && stdout_path == NULL && stderr_path == NULL && !no_stdio) { pty_error = pty.OpenFirstAvailableMaster(O_RDWR|O_NOCTTY); if (pty_error == PseudoTerminal::success) - stdio_path = pty.SlaveName(); - // Make sure we were able to get the slave name - if (stdio_path == NULL) - stdio_path = "/dev/null"; + { + stdin_path = stdout_path = stderr_path = pty.SlaveName(); + } } // if no_stdio, then do open file actions, opening /dev/null. @@ -1693,11 +1701,11 @@ if (err.Fail() || DNBLogCheckLogBit (LOG_PROCESS)) err.LogThreaded ("::posix_spawn_file_actions_addopen (&file_actions, filedes=STDERR_FILENO, path=/dev/null)"); } - else if (stdio_path != NULL) + else { - int slave_fd_err = open (stdio_path, O_RDWR, 0); - int slave_fd_in = open (stdio_path, O_RDONLY, 0); - int slave_fd_out = open (stdio_path, O_WRONLY, 0); + int slave_fd_err = open (stderr_path ? stderr_path : "/dev/null", O_RDWR , 0); + int slave_fd_in = open (stdin_path ? stdin_path : "/dev/null", O_RDONLY, 0); + int slave_fd_out = open (stdout_path ? stdout_path : "/dev/null", O_WRONLY, 0); err.SetError( ::posix_spawn_file_actions_adddup2(&file_actions, slave_fd_err, STDERR_FILENO), DNBError::POSIX); if (err.Fail() || DNBLogCheckLogBit(LOG_PROCESS)) Modified: lldb/trunk/tools/debugserver/source/MacOSX/MachProcess.h URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/tools/debugserver/source/MacOSX/MachProcess.h?rev=124049&r1=124048&r2=124049&view=diff ============================================================================== --- lldb/trunk/tools/debugserver/source/MacOSX/MachProcess.h (original) +++ lldb/trunk/tools/debugserver/source/MacOSX/MachProcess.h Sat Jan 22 17:43:18 2011 @@ -47,9 +47,30 @@ // Child process control //---------------------------------------------------------------------- pid_t AttachForDebug (pid_t pid, char *err_str, size_t err_len); - pid_t LaunchForDebug (const char *path, char const *argv[], char const *envp[], const char *stdio_path, bool no_stdio, nub_launch_flavor_t launch_flavor, int disable_aslr, DNBError &err); + pid_t LaunchForDebug (const char *path, + char const *argv[], + char const *envp[], + const char *working_directory, + const char *stdin_path, + const char *stdout_path, + const char *stderr_path, + bool no_stdio, + nub_launch_flavor_t launch_flavor, + int disable_aslr, + DNBError &err); static pid_t ForkChildForPTraceDebugging (const char *path, char const *argv[], char const *envp[], MachProcess* process, DNBError &err); - static pid_t PosixSpawnChildForPTraceDebugging (const char *path, cpu_type_t cpu_type, char const *argv[], char const *envp[], const char *stdio_path, bool no_stdio, MachProcess* process, int disable_aslr, DNBError& err); + static pid_t PosixSpawnChildForPTraceDebugging (const char *path, + cpu_type_t cpu_type, + char const *argv[], + char const *envp[], + const char *working_directory, + const char *stdin_path, + const char *stdout_path, + const char *stderr_path, + bool no_stdio, + MachProcess* process, + int disable_aslr, + DNBError& err); nub_addr_t GetDYLDAllImageInfosAddress (); static const void * PrepareForAttach (const char *path, nub_launch_flavor_t launch_flavor, bool waitfor, DNBError &err_str); static void CleanupAfterAttach (const void *attach_token, bool success, DNBError &err_str); Modified: lldb/trunk/tools/debugserver/source/RNBContext.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/tools/debugserver/source/RNBContext.cpp?rev=124049&r1=124048&r2=124049&view=diff ============================================================================== --- lldb/trunk/tools/debugserver/source/RNBContext.cpp (original) +++ lldb/trunk/tools/debugserver/source/RNBContext.cpp Sat Jan 22 17:43:18 2011 @@ -12,11 +12,15 @@ //===----------------------------------------------------------------------===// #include "RNBContext.h" + +#include +#include + #include "RNBRemote.h" #include "DNB.h" #include "DNBLog.h" #include "CFString.h" -#include + //---------------------------------------------------------------------- // Destructor @@ -49,6 +53,20 @@ return NULL; } +bool +RNBContext::SetWorkingDirectory (const char *path) +{ + struct stat working_directory_stat; + if (::stat (path, &working_directory_stat) != 0) + { + m_working_directory.clear(); + return false; + } + m_working_directory.assign(path); + return true; +} + + void RNBContext::SetProcessID (nub_process_t pid) { Modified: lldb/trunk/tools/debugserver/source/RNBContext.h URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/tools/debugserver/source/RNBContext.h?rev=124049&r1=124048&r2=124049&view=diff ============================================================================== --- lldb/trunk/tools/debugserver/source/RNBContext.h (original) +++ lldb/trunk/tools/debugserver/source/RNBContext.h Sat Jan 22 17:43:18 2011 @@ -95,6 +95,16 @@ const char * LaunchStatusAsString (std::string& s); nub_launch_flavor_t LaunchFlavor () const { return m_launch_flavor; } void SetLaunchFlavor (nub_launch_flavor_t flavor) { m_launch_flavor = flavor; } + + const char * GetWorkingDirectory () const + { + if (!m_working_directory.empty()) + return m_working_directory.c_str(); + return NULL; + } + + bool SetWorkingDirectory (const char *path); + protected: //------------------------------------------------------------------ // Classes that inherit from RNBContext can see and modify these @@ -107,6 +117,7 @@ DNBError m_launch_status; // This holds the status from the last launch attempt. std::vector m_arg_vec; std::vector m_env_vec; // This will be unparsed - entries FOO=value + std::string m_working_directory; void StartProcessStatusThread(); void StopProcessStatusThread(); Modified: lldb/trunk/tools/debugserver/source/RNBRemote.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/tools/debugserver/source/RNBRemote.cpp?rev=124049&r1=124048&r2=124049&view=diff ============================================================================== --- lldb/trunk/tools/debugserver/source/RNBRemote.cpp (original) +++ lldb/trunk/tools/debugserver/source/RNBRemote.cpp Sat Jan 22 17:43:18 2011 @@ -3126,6 +3126,7 @@ // No response to should be sent to the kill packet if (m_ctx.HasValidProcessID()) DNBProcessKill (m_ctx.ProcessID()); + SendPacket ("W09"); return rnb_success; } Modified: lldb/trunk/tools/debugserver/source/debugserver.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/tools/debugserver/source/debugserver.cpp?rev=124049&r1=124048&r2=124049&view=diff ============================================================================== --- lldb/trunk/tools/debugserver/source/debugserver.cpp (original) +++ lldb/trunk/tools/debugserver/source/debugserver.cpp Sat Jan 22 17:43:18 2011 @@ -61,26 +61,18 @@ #define RNBLogSTDERR(fmt, ...) do { if (g_isatty) { fprintf(stderr, fmt, ## __VA_ARGS__); } else { _DNBLog(0, fmt, ## __VA_ARGS__); } } while (0) //---------------------------------------------------------------------- -// Run Loop function prototypes -//---------------------------------------------------------------------- -RNBRunLoopMode RNBRunLoopGetStartModeFromRemote (RNBRemoteSP &remote); -RNBRunLoopMode RNBRunLoopInferiorExecuting (RNBRemoteSP &remote); - - -//---------------------------------------------------------------------- // Get our program path and arguments from the remote connection. // We will need to start up the remote connection without a PID, get the // arguments, wait for the new process to finish launching and hit its // entry point, and then return the run loop mode that should come next. //---------------------------------------------------------------------- RNBRunLoopMode -RNBRunLoopGetStartModeFromRemote (RNBRemoteSP &remoteSP) +RNBRunLoopGetStartModeFromRemote (RNBRemote* remote) { std::string packet; - if (remoteSP.get() != NULL) + if (remote) { - RNBRemote* remote = remoteSP.get(); RNBContext& ctx = remote->Context(); uint32_t event_mask = RNBContext::event_read_packet_available; @@ -151,7 +143,7 @@ // or crash process state. //---------------------------------------------------------------------- RNBRunLoopMode -RNBRunLoopLaunchInferior (RNBRemoteSP &remote, const char *stdio_path, bool no_stdio) +RNBRunLoopLaunchInferior (RNBRemote *remote, const char *stdin_path, const char *stdout_path, const char *stderr_path, bool no_stdio) { RNBContext& ctx = remote->Context(); @@ -208,7 +200,10 @@ nub_process_t pid = DNBProcessLaunch (resolved_path, &inferior_argv[0], &inferior_envp[0], - stdio_path, + ctx.GetWorkingDirectory(), + stdin_path, + stdout_path, + stderr_path, no_stdio, launch_flavor, g_disable_aslr, @@ -317,7 +312,7 @@ // or crash process state. //---------------------------------------------------------------------- RNBRunLoopMode -RNBRunLoopLaunchAttaching (RNBRemoteSP &remote, nub_process_t attach_pid, nub_process_t& pid) +RNBRunLoopLaunchAttaching (RNBRemote *remote, nub_process_t attach_pid, nub_process_t& pid) { RNBContext& ctx = remote->Context(); @@ -381,7 +376,7 @@ // Return the new run loop mode based off of the current process state RNBRunLoopMode -HandleProcessStateChange (RNBRemoteSP &remote, bool initialize) +HandleProcessStateChange (RNBRemote *remote, bool initialize) { RNBContext& ctx = remote->Context(); nub_process_t pid = ctx.ProcessID(); @@ -460,7 +455,7 @@ // makes the inferior run, we need to leave this function with a new state // as the return code. RNBRunLoopMode -RNBRunLoopInferiorExecuting (RNBRemoteSP &remote) +RNBRunLoopInferiorExecuting (RNBRemote *remote) { DNBLogThreadedIf (LOG_RNB_MINIMAL, "#### %s", __FUNCTION__); RNBContext& ctx = remote->Context(); @@ -565,19 +560,19 @@ //---------------------------------------------------------------------- static int -StartListening (RNBRemoteSP remoteSP, int listen_port) +StartListening (RNBRemote *remote, int listen_port) { - if (!remoteSP->Comm().IsConnected()) + if (!remote->Comm().IsConnected()) { RNBLogSTDOUT ("Listening to port %i...\n", listen_port); - if (remoteSP->Comm().Listen(listen_port) != rnb_success) + if (remote->Comm().Listen(listen_port) != rnb_success) { RNBLogSTDERR ("Failed to get connection from a remote gdb process.\n"); return 0; } else { - remoteSP->StartReadRemoteDataThread(); + remote->StartReadRemoteDataThread(); } } return 1; @@ -656,10 +651,14 @@ { "waitfor-interval", required_argument, NULL, 'i' }, // Time in usecs to wait between sampling the pid list when waiting for a process by name { "waitfor-duration", required_argument, NULL, 'd' }, // The time in seconds to wait for a process to show up by name { "native-regs", no_argument, NULL, 'r' }, // Specify to use the native registers instead of the gdb defaults for the architecture. - { "stdio-path", required_argument, NULL, 's' }, // Set the STDIO path to be used when launching applications + { "stdio-path", required_argument, NULL, 's' }, // Set the STDIO path to be used when launching applications (STDIN, STDOUT and STDERR) + { "stdin-path", required_argument, NULL, 'I' }, // Set the STDIN path to be used when launching applications + { "stdout-path", required_argument, NULL, 'O' }, // Set the STDIN path to be used when launching applications + { "stderr-path", required_argument, NULL, 'E' }, // Set the STDIN path to be used when launching applications { "no-stdio", no_argument, NULL, 'n' }, // Do not set up any stdio (perhaps the program is a GUI program) { "setsid", no_argument, NULL, 'S' }, // call setsid() to make debugserver run in its own sessions { "disable-aslr", no_argument, NULL, 'D' }, // Use _POSIX_SPAWN_DISABLE_ASLR to avoid shared library randomization + { "chdir", no_argument, NULL, 'c' }, // Use _POSIX_SPAWN_DISABLE_ASLR to avoid shared library randomization { NULL, 0, NULL, 0 } }; @@ -696,8 +695,11 @@ std::string compile_options; std::string waitfor_pid_name; // Wait for a process that starts with this name std::string attach_pid_name; - std::string stdio_path; + std::string stdin_path; + std::string stdout_path; + std::string stderr_path; std::string arch_name; + std::string working_directory; // The new working directory to use for the inferior useconds_t waitfor_interval = 1000; // Time in usecs between process lists polls when waiting for a process by name, default 1 msec. useconds_t waitfor_duration = 0; // Time in seconds to wait for a process by name, 0 means wait forever. bool no_stdio = false; @@ -783,6 +785,11 @@ } break; + case 'c': + if (optarg && optarg[0]) + working_directory.assign(optarg); + break; + case 'x': if (optarg && optarg[0]) { @@ -856,7 +863,21 @@ break; case 's': - stdio_path = optarg; + stdin_path.assign(optarg); + stdout_path.assign(optarg); + stderr_path.assign(optarg); + break; + + case 'I': + stdin_path.assign(optarg); + break; + + case 'O': + stdout_path.assign(optarg); + break; + + case 'E': + stderr_path.assign(optarg); break; case 'n': @@ -910,7 +931,6 @@ g_remoteSP.reset (new RNBRemote (use_native_registers, arch_name.c_str())); - RNBRemote *remote = g_remoteSP.get(); if (remote == NULL) { @@ -918,7 +938,16 @@ return -1; } - g_remoteSP->Initialize(); + if (!working_directory.empty()) + { + if (remote->Context().SetWorkingDirectory (working_directory.c_str()) == false) + { + RNBLogSTDERR ("error: working directory doesn't exist '%s'.\n", working_directory.c_str()); + exit (8); + } + } + + remote->Initialize(); RNBContext& ctx = remote->Context(); @@ -1054,9 +1083,9 @@ #if defined (__arm__) if (g_lockdown_opt) { - if (!g_remoteSP->Comm().IsConnected()) + if (!remote->Comm().IsConnected()) { - if (g_remoteSP->Comm().ConnectToService () != rnb_success) + if (remote->Comm().ConnectToService () != rnb_success) { RNBLogSTDERR ("Failed to get connection from a remote gdb process.\n"); mode = eRNBRunLoopModeExit; @@ -1069,21 +1098,21 @@ { DNBLogDebug("Task list: %s", applist_plist.c_str()); - g_remoteSP->Comm().Write(applist_plist.c_str(), applist_plist.size()); + remote->Comm().Write(applist_plist.c_str(), applist_plist.size()); // Issue a read that will never yield any data until the other side // closes the socket so this process doesn't just exit and cause the // socket to close prematurely on the other end and cause data loss. std::string buf; - g_remoteSP->Comm().Read(buf); + remote->Comm().Read(buf); } - g_remoteSP->Comm().Disconnect(false); + remote->Comm().Disconnect(false); mode = eRNBRunLoopModeExit; break; } else { // Start watching for remote packets - g_remoteSP->StartReadRemoteDataThread(); + remote->StartReadRemoteDataThread(); } } } @@ -1091,19 +1120,19 @@ #endif if (listen_port != INT32_MAX) { - if (!StartListening (g_remoteSP, listen_port)) + if (!StartListening (remote, listen_port)) mode = eRNBRunLoopModeExit; } else if (str[0] == '/') { - if (g_remoteSP->Comm().OpenFile (str)) + if (remote->Comm().OpenFile (str)) mode = eRNBRunLoopModeExit; } if (mode != eRNBRunLoopModeExit) { RNBLogSTDOUT ("Got a connection, waiting for process information for launching or attaching.\n"); - mode = RNBRunLoopGetStartModeFromRemote (g_remoteSP); + mode = RNBRunLoopGetStartModeFromRemote (remote); } break; @@ -1157,7 +1186,7 @@ RNBLogSTDOUT ("Attaching to process %i...\n", attach_pid); nub_process_t attached_pid; - mode = RNBRunLoopLaunchAttaching (g_remoteSP, attach_pid, attached_pid); + mode = RNBRunLoopLaunchAttaching (remote, attach_pid, attached_pid); if (mode != eRNBRunLoopModeInferiorExecuting) { const char *error_str = remote->Context().LaunchStatus().AsString(); @@ -1201,12 +1230,12 @@ { if (listen_port != INT32_MAX) { - if (!StartListening (g_remoteSP, listen_port)) + if (!StartListening (remote, listen_port)) mode = eRNBRunLoopModeExit; } else if (str[0] == '/') { - if (g_remoteSP->Comm().OpenFile (str)) + if (remote->Comm().OpenFile (str)) mode = eRNBRunLoopModeExit; } if (mode != eRNBRunLoopModeExit) @@ -1215,33 +1244,39 @@ break; case eRNBRunLoopModeInferiorLaunching: - mode = RNBRunLoopLaunchInferior (g_remoteSP, stdio_path.empty() ? NULL : stdio_path.c_str(), no_stdio); - - if (mode == eRNBRunLoopModeInferiorExecuting) { - if (listen_port != INT32_MAX) + mode = RNBRunLoopLaunchInferior (remote, + stdin_path.empty() ? NULL : stdin_path.c_str(), + stdout_path.empty() ? NULL : stdout_path.c_str(), + stderr_path.empty() ? NULL : stderr_path.c_str(), + no_stdio); + + if (mode == eRNBRunLoopModeInferiorExecuting) { - if (!StartListening (g_remoteSP, listen_port)) - mode = eRNBRunLoopModeExit; + if (listen_port != INT32_MAX) + { + if (!StartListening (remote, listen_port)) + mode = eRNBRunLoopModeExit; + } + else if (str[0] == '/') + { + if (remote->Comm().OpenFile (str)) + mode = eRNBRunLoopModeExit; + } + + if (mode != eRNBRunLoopModeExit) + RNBLogSTDOUT ("Got a connection, waiting for debugger instructions.\n"); } - else if (str[0] == '/') + else { - if (g_remoteSP->Comm().OpenFile (str)) - mode = eRNBRunLoopModeExit; + const char *error_str = remote->Context().LaunchStatus().AsString(); + RNBLogSTDERR ("error: failed to launch process %s: %s\n", argv[0], error_str ? error_str : "unknown error."); } - - if (mode != eRNBRunLoopModeExit) - RNBLogSTDOUT ("Got a connection, waiting for debugger instructions.\n"); - } - else - { - const char *error_str = remote->Context().LaunchStatus().AsString(); - RNBLogSTDERR ("error: failed to launch process %s: %s\n", argv[0], error_str ? error_str : "unknown error."); } break; case eRNBRunLoopModeInferiorExecuting: - mode = RNBRunLoopInferiorExecuting(g_remoteSP); + mode = RNBRunLoopInferiorExecuting(remote); break; default: @@ -1251,8 +1286,8 @@ } } - g_remoteSP->StopReadRemoteDataThread (); - g_remoteSP->Context().SetProcessID(INVALID_NUB_PROCESS); + remote->StopReadRemoteDataThread (); + remote->Context().SetProcessID(INVALID_NUB_PROCESS); return 0; } From gclayton at apple.com Sat Jan 22 18:09:32 2011 From: gclayton at apple.com (Greg Clayton) Date: Sun, 23 Jan 2011 00:09:32 -0000 Subject: [Lldb-commits] [lldb] r124050 - /lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFCompileUnit.cpp Message-ID: <20110123000932.826682A6C12C@llvm.org> Author: gclayton Date: Sat Jan 22 18:09:32 2011 New Revision: 124050 URL: http://llvm.org/viewvc/llvm-project?rev=124050&view=rev Log: Fixed a crasher that would happen when we run into malformed DWARF. It is nice to know about the issue, but we shouldn't crash. Modified: lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFCompileUnit.cpp Modified: lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFCompileUnit.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFCompileUnit.cpp?rev=124050&r1=124049&r2=124050&view=diff ============================================================================== --- lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFCompileUnit.cpp (original) +++ lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFCompileUnit.cpp Sat Jan 22 18:09:32 2011 @@ -12,6 +12,7 @@ #include "lldb/Core/Mangled.h" #include "lldb/Core/Stream.h" #include "lldb/Core/Timer.h" +#include "lldb/Symbol/ObjectFile.h" #include "DWARFDebugAbbrev.h" #include "DWARFDebugAranges.h" @@ -219,7 +220,17 @@ break; // We are done with this compile unit! } - assert(offset <= GetNextCompileUnitOffset()); + if (offset > GetNextCompileUnitOffset()) + { + char path[PATH_MAX]; + ObjectFile *objfile = m_dwarf2Data->GetObjectFile(); + if (objfile) + { + objfile->GetFileSpec().GetPath(path, sizeof(path)); + } + fprintf (stderr, "warning: DWARF compile unit extends beyond its bounds cu 0x%8.8x at 0x%8.8x in '%s'\n", GetOffset(), offset, path); + break; + } } SetDIERelations(); return m_die_array.size(); From gclayton at apple.com Sat Jan 22 18:34:52 2011 From: gclayton at apple.com (Greg Clayton) Date: Sun, 23 Jan 2011 00:34:52 -0000 Subject: [Lldb-commits] [lldb] r124051 - /lldb/trunk/source/Expression/ClangASTSource.cpp Message-ID: <20110123003453.0016B2A6C12C@llvm.org> Author: gclayton Date: Sat Jan 22 18:34:52 2011 New Revision: 124051 URL: http://llvm.org/viewvc/llvm-project?rev=124051&view=rev Log: Watch out for NULL types in NameSearchContext::AddTypeDecl or we crash. Modified: lldb/trunk/source/Expression/ClangASTSource.cpp Modified: lldb/trunk/source/Expression/ClangASTSource.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Expression/ClangASTSource.cpp?rev=124051&r1=124050&r2=124051&view=diff ============================================================================== --- lldb/trunk/source/Expression/ClangASTSource.cpp (original) +++ lldb/trunk/source/Expression/ClangASTSource.cpp Sat Jan 22 18:34:52 2011 @@ -240,26 +240,26 @@ clang::NamedDecl * NameSearchContext::AddTypeDecl(void *type) { - QualType qual_type = QualType::getFromOpaquePtr(type); - - if (TagType *tag_type = dyn_cast(qual_type)) - { - TagDecl *tag_decl = tag_type->getDecl(); - - m_decls.push_back(tag_decl); - - return tag_decl; - } - else if (ObjCObjectType *objc_object_type = dyn_cast(qual_type)) + if (type) { - ObjCInterfaceDecl *interface_decl = objc_object_type->getInterface(); - - m_decls.push_back((NamedDecl*)interface_decl); - - return (NamedDecl*)interface_decl; - } - else - { - return NULL; + QualType qual_type = QualType::getFromOpaquePtr(type); + + if (TagType *tag_type = dyn_cast(qual_type)) + { + TagDecl *tag_decl = tag_type->getDecl(); + + m_decls.push_back(tag_decl); + + return tag_decl; + } + else if (ObjCObjectType *objc_object_type = dyn_cast(qual_type)) + { + ObjCInterfaceDecl *interface_decl = objc_object_type->getInterface(); + + m_decls.push_back((NamedDecl*)interface_decl); + + return (NamedDecl*)interface_decl; + } } + return NULL; } From gclayton at apple.com Sat Jan 22 23:56:20 2011 From: gclayton at apple.com (Greg Clayton) Date: Sun, 23 Jan 2011 05:56:20 -0000 Subject: [Lldb-commits] [lldb] r124060 - in /lldb/trunk: include/lldb/API/ include/lldb/Host/ include/lldb/Target/ source/API/ source/Commands/ source/Core/ source/Host/common/ source/Host/macosx/ source/Plugins/Process/Linux/ source/Plugins/Process/MacOSX-User/source/ source/Plugins/Process/gdb-remote/ source/Target/ tools/darwin-debug/ tools/debugserver/source/ tools/debugserver/source/MacOSX/ Message-ID: <20110123055620.C6D632A6C12C@llvm.org> Author: gclayton Date: Sat Jan 22 23:56:20 2011 New Revision: 124060 URL: http://llvm.org/viewvc/llvm-project?rev=124060&view=rev Log: Added a new variant of SBTarget::Launch() that deprectates the old one that takes separate file handles for stdin, stdout, and stder and also allows for the working directory to be specified. Added support to "process launch" to a new option: --working-dir=PATH. We can now set the working directory. If this is not set, it defaults to that of the process that has LLDB loaded. Added the working directory to the host LaunchInNewTerminal function to allows the current working directory to be set in processes that are spawned in their own terminal. Also hooked this up to the lldb_private::Process and all mac plug-ins. The linux plug-in had its API changed, but nothing is making use of it yet. Modfied "debugserver" and "darwin-debug" to also handle the current working directory options and modified the code in LLDB that spawns these tools to pass the info along. Fixed ProcessGDBRemote to properly pass along all file handles for stdin, stdout and stderr. After clearing the default values for the stdin/out/err file handles for process to be NULL, we had a crasher in UserSettingsController::UpdateStringVariable which is now fixed. Also fixed the setting of boolean values to be able to be set as "true", "yes", "on", "1" for true (case insensitive) and "false", "no", "off", or "0" for false. Fixed debugserver to properly handle files for STDIN, STDOUT and STDERR that are not already opened. Previous to this fix debugserver would only correctly open and dupe file handles for the slave side of a pseudo terminal. It now correctly handles getting STDIN for the inferior from a file, and spitting STDOUT and STDERR out to files. Also made sure the file handles were correctly opened with the NOCTTY flag for terminals. Modified: lldb/trunk/include/lldb/API/SBTarget.h lldb/trunk/include/lldb/Host/Host.h lldb/trunk/include/lldb/Target/Process.h lldb/trunk/source/API/SBTarget.cpp lldb/trunk/source/Commands/CommandObjectProcess.cpp lldb/trunk/source/Core/UserSettingsController.cpp lldb/trunk/source/Host/common/Host.cpp lldb/trunk/source/Host/macosx/Host.mm lldb/trunk/source/Plugins/Process/Linux/ProcessLinux.cpp lldb/trunk/source/Plugins/Process/Linux/ProcessLinux.h lldb/trunk/source/Plugins/Process/MacOSX-User/source/ProcessMacOSX.cpp lldb/trunk/source/Plugins/Process/MacOSX-User/source/ProcessMacOSX.h lldb/trunk/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp lldb/trunk/source/Plugins/Process/gdb-remote/ProcessGDBRemote.h lldb/trunk/source/Target/Process.cpp lldb/trunk/tools/darwin-debug/darwin-debug.cpp lldb/trunk/tools/debugserver/source/DNB.cpp lldb/trunk/tools/debugserver/source/MacOSX/MachProcess.cpp lldb/trunk/tools/debugserver/source/debugserver.cpp Modified: lldb/trunk/include/lldb/API/SBTarget.h URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/API/SBTarget.h?rev=124060&r1=124059&r2=124060&view=diff ============================================================================== --- lldb/trunk/include/lldb/API/SBTarget.h (original) +++ lldb/trunk/include/lldb/API/SBTarget.h Sat Jan 22 23:56:20 2011 @@ -55,16 +55,20 @@ GetProcess (); lldb::SBProcess - LaunchProcess (char const **argv, - char const **envp, - const char *tty, - uint32_t launch_flags, // See LaunchFlags - bool stop_at_entry); + Launch (char const **argv, + char const **envp, + const char *tty, + uint32_t launch_flags, // See LaunchFlags + bool stop_at_entry, + lldb::SBError& error); lldb::SBProcess Launch (char const **argv, char const **envp, - const char *tty, + const char *stdin_path, + const char *stdout_path, + const char *stderr_path, + const char *working_directory, uint32_t launch_flags, // See LaunchFlags bool stop_at_entry, lldb::SBError& error); Modified: lldb/trunk/include/lldb/Host/Host.h URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Host/Host.h?rev=124060&r1=124059&r2=124060&view=diff ============================================================================== --- lldb/trunk/include/lldb/Host/Host.h (original) +++ lldb/trunk/include/lldb/Host/Host.h Sat Jan 22 23:56:20 2011 @@ -329,8 +329,9 @@ static lldb::pid_t LaunchInNewTerminal (const char *tty_name, // Optional partial or full tty name ("/dev/ttys000" or "ttys000") - const char **argv, // argv[0] is executable - const char **envp, + const char **argv, // argv[0] is executable, argv[1] and on are the arguments + const char **envp, + const char *working_dir, const ArchSpec *arch_spec, bool stop_at_entry, bool disable_aslr); Modified: lldb/trunk/include/lldb/Target/Process.h URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Target/Process.h?rev=124060&r1=124059&r2=124060&view=diff ============================================================================== --- lldb/trunk/include/lldb/Target/Process.h (original) +++ lldb/trunk/include/lldb/Target/Process.h Sat Jan 22 23:56:20 2011 @@ -540,6 +540,9 @@ /// process. If all stdXX_path arguments are NULL, a pseudo /// terminal will be used. /// + /// @param[in] working_directory + /// The working directory to have the child process run in + /// /// @return /// An error object. Call GetID() to get the process ID if /// the error object is success. @@ -550,7 +553,8 @@ uint32_t launch_flags, const char *stdin_path, const char *stdout_path, - const char *stderr_path); + const char *stderr_path, + const char *working_directory); //------------------------------------------------------------------ /// Attach to an existing process using a process ID. @@ -950,6 +954,9 @@ /// process. If all stdXX_path arguments are NULL, a pseudo /// terminal will be used. /// + /// @param[in] working_directory + /// The working directory to have the child process run in + /// /// @return /// A new valid process ID, or LLDB_INVALID_PROCESS_ID if /// launching fails. @@ -961,7 +968,8 @@ uint32_t launch_flags, const char *stdin_path, const char *stdout_path, - const char *stderr_path) = 0; + const char *stderr_path, + const char *working_directory) = 0; //------------------------------------------------------------------ /// Called after launching a process. Modified: lldb/trunk/source/API/SBTarget.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/API/SBTarget.cpp?rev=124060&r1=124059&r2=124060&view=diff ============================================================================== --- lldb/trunk/source/API/SBTarget.cpp (original) +++ lldb/trunk/source/API/SBTarget.cpp Sat Jan 22 23:56:20 2011 @@ -117,51 +117,48 @@ } SBProcess -SBTarget::LaunchProcess +SBTarget::Launch ( char const **argv, char const **envp, const char *tty, uint32_t launch_flags, - bool stop_at_entry + bool stop_at_entry, + SBError &error ) { - LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); - - if (log) - log->Printf ("SBTarget(%p)::LaunchProcess (argv=%p, envp=%p, tty=\"%s\", launch_flags=%d, stop_at_entry=%i)", - m_opaque_sp.get(), argv, envp, tty, launch_flags, stop_at_entry); - - SBError sb_error; - SBProcess sb_process = Launch (argv, envp, tty, launch_flags, stop_at_entry, sb_error); - - log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API); - if (log) - { - log->Printf ("SBTarget(%p)::LaunchProcess (...) => SBProcess(%p)", - m_opaque_sp.get(), sb_process.get()); - } - - return sb_process; + return Launch (argv, envp, tty, tty, tty, NULL, launch_flags, stop_at_entry, error); } SBProcess -SBTarget::Launch +SBTarget::Launch ( char const **argv, char const **envp, - const char *tty, - uint32_t launch_flags, + const char *stdin_path, + const char *stdout_path, + const char *stderr_path, + const char *working_directory, + uint32_t launch_flags, // See LaunchFlags bool stop_at_entry, - SBError &error + lldb::SBError& error ) { LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); if (log) { - log->Printf ("SBTarget(%p)::Launch (argv=%p, envp=%p, tty=\"%s\", launch_flags=%d, stop_at_entry=%i, &error (%p))...", - m_opaque_sp.get(), argv, envp, tty, launch_flags, stop_at_entry, error.get()); + log->Printf ("SBTarget(%p)::Launch (argv=%p, envp=%p, stdin=%s, stdout=%s, stderr=%s, working-dir=%s, launch_flags=0x%x, stop_at_entry=%i, &error (%p))...", + m_opaque_sp.get(), + argv, + envp, + stdin_path ? stdin_path : "NULL", + stdout_path ? stdout_path : "NULL", + stderr_path ? stderr_path : "NULL", + working_directory ? working_directory : "NULL", + launch_flags, + stop_at_entry, + error.get()); } SBProcess sb_process; if (m_opaque_sp) @@ -171,7 +168,7 @@ if (sb_process.IsValid()) { - error.SetError (sb_process->Launch (argv, envp, launch_flags, tty, tty, tty)); + error.SetError (sb_process->Launch (argv, envp, launch_flags, stdin_path, stdout_path, stderr_path, working_directory)); if (error.Success()) { // We we are stopping at the entry point, we can return now! Modified: lldb/trunk/source/Commands/CommandObjectProcess.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Commands/CommandObjectProcess.cpp?rev=124060&r1=124059&r2=124060&view=diff ============================================================================== --- lldb/trunk/source/Commands/CommandObjectProcess.cpp (original) +++ lldb/trunk/source/Commands/CommandObjectProcess.cpp Sat Jan 22 23:56:20 2011 @@ -57,12 +57,13 @@ switch (short_option) { - case 's': stop_at_entry = true; break; - case 'e': stderr_path = option_arg; break; - case 'i': stdin_path = option_arg; break; - case 'o': stdout_path = option_arg; break; - case 'p': plugin_name = option_arg; break; - case 'n': no_stdio = true; break; + case 's': stop_at_entry = true; break; + case 'e': stderr_path.assign (option_arg); break; + case 'i': stdin_path.assign (option_arg); break; + case 'o': stdout_path.assign (option_arg); break; + case 'p': plugin_name.assign (option_arg); break; + case 'n': no_stdio = true; break; + case 'w': working_dir.assign (option_arg); break; case 't': if (option_arg && option_arg[0]) tty_name.assign (option_arg); @@ -87,6 +88,7 @@ stdout_path.clear(); stderr_path.clear(); plugin_name.clear(); + working_dir.clear(); no_stdio = false; } @@ -110,6 +112,7 @@ std::string stdin_path; std::string stdout_path; std::string plugin_name; + std::string working_dir; }; @@ -249,6 +252,9 @@ const char **inferior_envp = environment.GetArgumentCount() ? environment.GetConstArgumentVector() : NULL; Error error; + const char *working_dir = NULL; + if (!m_options.working_dir.empty()) + working_dir = m_options.working_dir.c_str(); if (m_options.in_new_tty) { @@ -256,6 +262,7 @@ lldb::pid_t pid = Host::LaunchInNewTerminal (m_options.tty_name.c_str(), inferior_argv, inferior_envp, + working_dir, &exe_module->GetArchitecture(), true, process->GetDisableASLR()); @@ -287,19 +294,13 @@ stderr_path = m_options.stderr_path.empty() ? NULL : m_options.stderr_path.c_str(); } - if (stdin_path == NULL) - stdin_path = "/dev/null"; - if (stdout_path == NULL) - stdout_path = "/dev/null"; - if (stderr_path == NULL) - stderr_path = "/dev/null"; - error = process->Launch (inferior_argv, inferior_envp, launch_flags, stdin_path, stdout_path, - stderr_path); + stderr_path, + working_dir); } if (error.Success()) @@ -363,6 +364,7 @@ { SET1 | SET2 | SET3, false, "plugin", 'p', required_argument, NULL, 0, eArgTypePlugin, "Name of the process plugin you want to use."}, { SET2 , false, "tty", 't', optional_argument, NULL, 0, eArgTypePath, "Start the process in a terminal. If is specified, look for a terminal whose name contains , else start the process in a new terminal."}, { SET3, false, "no-stdio", 'n', no_argument, NULL, 0, eArgTypeNone, "Do not set up for terminal I/O to go to running process."}, +{ SET1 | SET2 | SET3, false, "working-dir", 'w', required_argument, NULL, 0, eArgTypePath, "Set the current working directory to when running the inferior."}, { 0, false, NULL, 0, 0, NULL, 0, eArgTypeNone, NULL } }; Modified: lldb/trunk/source/Core/UserSettingsController.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Core/UserSettingsController.cpp?rev=124060&r1=124059&r2=124060&view=diff ============================================================================== --- lldb/trunk/source/Core/UserSettingsController.cpp (original) +++ lldb/trunk/source/Core/UserSettingsController.cpp Sat Jan 22 23:56:20 2011 @@ -1946,9 +1946,17 @@ Error &err) { if (op == lldb::eVarSetOperationAssign) - string_var = new_value; + { + if (new_value && new_value[0]) + string_var.assign (new_value); + else + string_var.clear(); + } else if (op == lldb::eVarSetOperationAppend) - string_var.append (new_value); + { + if (new_value && new_value[0]) + string_var.append (new_value); + } else if (op == lldb::eVarSetOperationClear) string_var.clear(); else @@ -1964,19 +1972,25 @@ if (op != lldb::eVarSetOperationAssign) err.SetErrorString ("Invalid operation for Boolean variable. Cannot update value.\n"); + if (new_value && new_value[0]) + { + if ((::strcasecmp(new_value, "true") == 0) || + (::strcasecmp(new_value, "yes") == 0) || + (::strcasecmp(new_value, "on") == 0) || + (::strcasecmp(new_value, "1") == 0)) + bool_var = true; + else + if ((::strcasecmp(new_value, "false") == 0) || + (::strcasecmp(new_value, "no") == 0) || + (::strcasecmp(new_value, "off") == 0) || + (::strcasecmp(new_value, "0") == 0)) + bool_var = false; + else + err.SetErrorStringWithFormat ("Invalid boolean value '%s'\n", new_value); + } + else + err.SetErrorString ("Invalid value. Cannot perform update.\n"); - if ((new_value == NULL) - || (new_value[0] == '\0')) - err.SetErrorString ("Invalid value. Cannot perform update.\n"); - - std::string bool_val_str (new_value); - - std::transform (bool_val_str.begin(), bool_val_str.end(), bool_val_str.begin(), ::tolower); - - if (bool_val_str == "true") - bool_var = true; - else if (bool_val_str == "false") - bool_var = false; } void Modified: lldb/trunk/source/Host/common/Host.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Host/common/Host.cpp?rev=124060&r1=124059&r2=124060&view=diff ============================================================================== --- lldb/trunk/source/Host/common/Host.cpp (original) +++ lldb/trunk/source/Host/common/Host.cpp Sat Jan 22 23:56:20 2011 @@ -907,6 +907,7 @@ const char *tty_name, const char **argv, const char **envp, + const char *working_dir, const ArchSpec *arch_spec, bool stop_at_entry, bool disable_aslr Modified: lldb/trunk/source/Host/macosx/Host.mm URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Host/macosx/Host.mm?rev=124060&r1=124059&r2=124060&view=diff ============================================================================== --- lldb/trunk/source/Host/macosx/Host.mm (original) +++ lldb/trunk/source/Host/macosx/Host.mm Sat Jan 22 23:56:20 2011 @@ -226,6 +226,7 @@ ( const char **argv, const char **envp, + const char *working_dir, const ArchSpec *arch_spec, bool stop_at_entry, bool disable_aslr @@ -404,6 +405,7 @@ const char *tty_name, const char **argv, const char **envp, + const char *working_dir, const ArchSpec *arch_spec, bool stop_at_entry, bool disable_aslr @@ -440,6 +442,9 @@ if (arch_spec && arch_spec->IsValid()) command.Printf(" --arch=%s", arch_spec->AsCString()); + if (working_dir) + command.Printf(" --working-dir '%s'", working_dir); + if (disable_aslr) command.PutCString(" --disable-aslr"); @@ -520,15 +525,16 @@ const char *tty_name, const char **argv, const char **envp, + const char *working_dir, const ArchSpec *arch_spec, bool stop_at_entry, bool disable_aslr ) { #if defined (LLDB_HOST_USE_APPLESCRIPT) - return LaunchInNewTerminalWithAppleScript (tty_name, argv, envp, arch_spec, stop_at_entry, disable_aslr); + return LaunchInNewTerminalWithAppleScript (tty_name, argv, envp, working_dir, arch_spec, stop_at_entry, disable_aslr); #else - return LaunchInNewTerminalWithCommandFile (argv, envp, arch_spec, stop_at_entry, disable_aslr); + return LaunchInNewTerminalWithCommandFile (argv, envp, working_dir, arch_spec, stop_at_entry, disable_aslr); #endif } Modified: lldb/trunk/source/Plugins/Process/Linux/ProcessLinux.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Process/Linux/ProcessLinux.cpp?rev=124060&r1=124059&r2=124060&view=diff ============================================================================== --- lldb/trunk/source/Plugins/Process/Linux/ProcessLinux.cpp (original) +++ lldb/trunk/source/Plugins/Process/Linux/ProcessLinux.cpp Sat Jan 22 23:56:20 2011 @@ -122,7 +122,8 @@ uint32_t launch_flags, const char *stdin_path, const char *stdout_path, - const char *stderr_path) + const char *stderr_path, + const char *working_directory) { Error error; assert(m_monitor == NULL); Modified: lldb/trunk/source/Plugins/Process/Linux/ProcessLinux.h URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Process/Linux/ProcessLinux.h?rev=124060&r1=124059&r2=124060&view=diff ============================================================================== --- lldb/trunk/source/Plugins/Process/Linux/ProcessLinux.h (original) +++ lldb/trunk/source/Plugins/Process/Linux/ProcessLinux.h Sat Jan 22 23:56:20 2011 @@ -72,7 +72,8 @@ uint32_t launch_flags, const char *stdin_path, const char *stdout_path, - const char *stderr_path); + const char *stderr_path, + const char *working_directory); virtual void DidLaunch(); Modified: lldb/trunk/source/Plugins/Process/MacOSX-User/source/ProcessMacOSX.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Process/MacOSX-User/source/ProcessMacOSX.cpp?rev=124060&r1=124059&r2=124060&view=diff ============================================================================== --- lldb/trunk/source/Plugins/Process/MacOSX-User/source/ProcessMacOSX.cpp (original) +++ lldb/trunk/source/Plugins/Process/MacOSX-User/source/ProcessMacOSX.cpp Sat Jan 22 23:56:20 2011 @@ -316,7 +316,8 @@ uint32_t flags, const char *stdin_path, const char *stdout_path, - const char *stderr_path + const char *stderr_path, + const char *working_dir ) { // ::LogSetBitMask (PD_LOG_DEFAULT); Modified: lldb/trunk/source/Plugins/Process/MacOSX-User/source/ProcessMacOSX.h URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Process/MacOSX-User/source/ProcessMacOSX.h?rev=124060&r1=124059&r2=124060&view=diff ============================================================================== --- lldb/trunk/source/Plugins/Process/MacOSX-User/source/ProcessMacOSX.h (original) +++ lldb/trunk/source/Plugins/Process/MacOSX-User/source/ProcessMacOSX.h Sat Jan 22 23:56:20 2011 @@ -95,8 +95,9 @@ char const *envp[], // Can be NULL uint32_t launch_flags, const char *stdin_path, // Can be NULL - const char *stdout_path, // Can be NULL - const char *stderr_path); // Can be NULL + const char *stdout_path, // Can be NULL + const char *stderr_path, // Can be NULL + const char *working_dir); // Can be NULL virtual void DidLaunch (); Modified: lldb/trunk/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp?rev=124060&r1=124059&r2=124060&view=diff ============================================================================== --- lldb/trunk/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp (original) +++ lldb/trunk/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp Sat Jan 22 23:56:20 2011 @@ -375,7 +375,8 @@ uint32_t launch_flags, const char *stdin_path, const char *stdout_path, - const char *stderr_path + const char *stderr_path, + const char *working_dir ) { Error error; @@ -400,7 +401,10 @@ error = StartDebugserverProcess (host_port, argv, envp, - NULL, //stdin_path, + stdin_path, + stdout_path, + stderr_path, + working_dir, launch_process, LLDB_INVALID_PROCESS_ID, NULL, false, @@ -420,10 +424,14 @@ error = StartDebugserverProcess (host_port, NULL, NULL, - NULL, //stdin_path + stdin_path, + stdout_path, + stderr_path, + working_dir, launch_process, LLDB_INVALID_PROCESS_ID, - NULL, false, + NULL, + false, launch_flags, inferior_arch); if (error.Fail()) @@ -644,6 +652,9 @@ NULL, // inferior_argv NULL, // inferior_envp NULL, // stdin_path + NULL, // stdout_path + NULL, // stderr_path + NULL, // working_dir false, // launch_process == false (we are attaching) LLDB_INVALID_PROCESS_ID, // Don't send any attach to pid options to debugserver NULL, // Don't send any attach by process name option to debugserver @@ -746,6 +757,9 @@ NULL, // inferior_argv NULL, // inferior_envp NULL, // stdin_path + NULL, // stdout_path + NULL, // stderr_path + NULL, // working_dir false, // launch_process == false (we are attaching) LLDB_INVALID_PROCESS_ID, // Don't send any attach to pid options to debugserver NULL, // Don't send any attach by process name option to debugserver @@ -1732,7 +1746,10 @@ const char *debugserver_url, // The connection string to use in the spawned debugserver ("localhost:1234" or "/dev/tty...") char const *inferior_argv[], // Arguments for the inferior program including the path to the inferior itself as the first argument char const *inferior_envp[], // Environment to pass along to the inferior program - char const *stdio_path, + const char *stdin_path, + const char *stdout_path, + const char *stderr_path, + const char *working_dir, bool launch_process, // Set to true if we are going to be launching a the process lldb::pid_t attach_pid, // If inferior inferior_argv == NULL, and attach_pid != LLDB_INVALID_PROCESS_ID send this pid as an argument to debugserver const char *attach_name, // Wait for the next process to launch whose basename matches "attach_name" @@ -1824,7 +1841,13 @@ char arg_cstr[PATH_MAX]; lldb_utility::PseudoTerminal pty; - if (launch_process && stdio_path == NULL && m_local_debugserver && !no_stdio) + const char *stdio_path = NULL; + if (launch_process && + stdin_path == NULL && + stdout_path == NULL && + stderr_path == NULL && + m_local_debugserver && + no_stdio == false) { if (pty.OpenFirstAvailableMaster(O_RDWR|O_NOCTTY, NULL, 0)) stdio_path = pty.GetSlaveName (NULL, 0); @@ -1843,14 +1866,60 @@ debugserver_args.AppendArguments("--disable-aslr"); // Only set the inferior - if (launch_process && stdio_path) + if (launch_process) { - debugserver_args.AppendArgument("--stdio-path"); - debugserver_args.AppendArgument(stdio_path); + if (no_stdio) + debugserver_args.AppendArgument("--no-stdio"); + else + { + if (stdin_path && stdout_path && stderr_path && + strcmp(stdin_path, stdout_path) == 0 && + strcmp(stdin_path, stderr_path) == 0) + { + stdio_path = stdin_path; + stdin_path = stdout_path = stderr_path = NULL; + } + + if (stdio_path) + { + // All file handles to stdin, stdout, stderr are the same... + debugserver_args.AppendArgument("--stdio-path"); + debugserver_args.AppendArgument(stdio_path); + } + else + { + if (stdin_path == NULL && (stdout_path || stderr_path)) + stdin_path = "/dev/null"; + + if (stdout_path == NULL && (stdin_path || stderr_path)) + stdout_path = "/dev/null"; + + if (stderr_path == NULL && (stdin_path || stdout_path)) + stderr_path = "/dev/null"; + + if (stdin_path) + { + debugserver_args.AppendArgument("--stdin-path"); + debugserver_args.AppendArgument(stdin_path); + } + if (stdout_path) + { + debugserver_args.AppendArgument("--stdout-path"); + debugserver_args.AppendArgument(stdout_path); + } + if (stderr_path) + { + debugserver_args.AppendArgument("--stderr-path"); + debugserver_args.AppendArgument(stderr_path); + } + } + } } - else if (launch_process && no_stdio) + + if (working_dir) { - debugserver_args.AppendArgument("--no-stdio"); + debugserver_args.AppendArgument("--working-dir"); + debugserver_args.AppendArgument(working_dir); } const char *env_debugserver_log_file = getenv("LLDB_DEBUGSERVER_LOG_FILE"); Modified: lldb/trunk/source/Plugins/Process/gdb-remote/ProcessGDBRemote.h URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Process/gdb-remote/ProcessGDBRemote.h?rev=124060&r1=124059&r2=124060&view=diff ============================================================================== --- lldb/trunk/source/Plugins/Process/gdb-remote/ProcessGDBRemote.h (original) +++ lldb/trunk/source/Plugins/Process/gdb-remote/ProcessGDBRemote.h Sat Jan 22 23:56:20 2011 @@ -82,8 +82,9 @@ char const *envp[], // Can be NULL uint32_t flags, const char *stdin_path, // Can be NULL - const char *stdout_path, // Can be NULL - const char *stderr_path); // Can be NULL + const char *stdout_path, // Can be NULL + const char *stderr_path, // Can be NULL + const char *working_dir); // Can be NULL virtual void DidLaunch (); @@ -295,6 +296,9 @@ char const *inferior_argv[], char const *inferior_envp[], const char *stdin_path, + const char *stdout_path, + const char *stderr_path, + const char *working_dir, bool launch_process, // Set to true if we are going to be launching a the process lldb::pid_t attach_pid, // If inferior inferior_argv == NULL, then attach to this pid const char *attach_pid_name, // Wait for the next process to launch whose basename matches "attach_wait_name" Modified: lldb/trunk/source/Target/Process.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Target/Process.cpp?rev=124060&r1=124059&r2=124060&view=diff ============================================================================== --- lldb/trunk/source/Target/Process.cpp (original) +++ lldb/trunk/source/Target/Process.cpp Sat Jan 22 23:56:20 2011 @@ -1456,7 +1456,8 @@ uint32_t launch_flags, const char *stdin_path, const char *stdout_path, - const char *stderr_path + const char *stderr_path, + const char *working_directory ) { Error error; @@ -1507,7 +1508,8 @@ launch_flags, stdin_path, stdout_path, - stderr_path); + stderr_path, + working_directory); if (error.Fail()) { @@ -3252,10 +3254,10 @@ { "run-args", eSetVarTypeArray, NULL, NULL, false, false, "A list containing all the arguments to be passed to the executable when it is run." }, { "env-vars", eSetVarTypeDictionary, NULL, NULL, false, false, "A list of all the environment variables to be passed to the executable's environment, and their values." }, { "inherit-env", eSetVarTypeBoolean, "true", NULL, false, false, "Inherit the environment from the process that is running LLDB." }, - { "input-path", eSetVarTypeString, "/dev/stdin", NULL, false, false, "The file/path to be used by the executable program for reading its input." }, - { "output-path", eSetVarTypeString, "/dev/stdout", NULL, false, false, "The file/path to be used by the executable program for writing its output." }, - { "error-path", eSetVarTypeString, "/dev/stderr", NULL, false, false, "The file/path to be used by the executable program for writings its error messages." }, - { "plugin", eSetVarTypeEnum, NULL , g_plugins, false, false, "The plugin to be used to run the process." }, + { "input-path", eSetVarTypeString, NULL, NULL, false, false, "The file/path to be used by the executable program for reading its input." }, + { "output-path", eSetVarTypeString, NULL, NULL, false, false, "The file/path to be used by the executable program for writing its output." }, + { "error-path", eSetVarTypeString, NULL, NULL, false, false, "The file/path to be used by the executable program for writings its error messages." }, + { "plugin", eSetVarTypeEnum, NULL, g_plugins, false, false, "The plugin to be used to run the process." }, { "disable-aslr", eSetVarTypeBoolean, "true", NULL, false, false, "Disable Address Space Layout Randomization (ASLR)" }, { "disable-stdio", eSetVarTypeBoolean, "false", NULL, false, false, "Disable stdin/stdout for process (e.g. for a GUI application)" }, { NULL, eSetVarTypeNone, NULL, NULL, false, false, NULL } Modified: lldb/trunk/tools/darwin-debug/darwin-debug.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/tools/darwin-debug/darwin-debug.cpp?rev=124060&r1=124059&r2=124060&view=diff ============================================================================== --- lldb/trunk/tools/darwin-debug/darwin-debug.cpp (original) +++ lldb/trunk/tools/darwin-debug/darwin-debug.cpp Sat Jan 22 23:56:20 2011 @@ -30,8 +30,9 @@ #include #include #include -#include #include +#include +#include #include #include @@ -50,6 +51,7 @@ { "help", no_argument, NULL, 'h' }, { "setsid", no_argument, NULL, 's' }, { "unix-socket", required_argument, NULL, 'u' }, + { "working-dir", required_argument, NULL, 'w' }, { NULL, 0, NULL, 0 } }; @@ -62,7 +64,7 @@ " for debugging.\n" "\n" "SYNOPSIS\n" -" darwin-debug --unix-socket= [--arch=] [--disable-aslr] [--no-env] [--setsid] [--help] -- [ ....]\n" +" darwin-debug --unix-socket= [--arch=] [--working-dir=] [--disable-aslr] [--no-env] [--setsid] [--help] -- [ ....]\n" "\n" "DESCRIPTION\n" " darwin-debug will exec itself into a child process that is\n" @@ -95,7 +97,13 @@ } pid_t -posix_spawn_for_debug (char *const *argv, char *const *envp, cpu_type_t cpu_type, int disable_aslr) +posix_spawn_for_debug +( + char *const *argv, + char *const *envp, + const char *working_dir, + cpu_type_t cpu_type, + int disable_aslr) { pid_t pid = 0; @@ -126,6 +134,15 @@ size_t ocount = 0; exit_with_errno (::posix_spawnattr_setbinpref_np (&attr, 1, &cpu_type, &ocount), "posix_spawnattr_setbinpref_np () error: "); } + + // I wish there was a posix_spawn flag to change the working directory of + // the inferior process we will spawn, but there currently isn't. If there + // ever is a better way to do this, we should use it. I would rather not + // manually fork, chdir in the child process, and then posix_spawn with exec + // as the whole reason for doing posix_spawn is to not hose anything up + // after the fork and prior to the exec... + if (working_dir) + ::chdir (working_dir); exit_with_errno (::posix_spawnp (&pid, path, NULL, &attr, (char * const*)argv, (char * const*)envp), "posix_spawn() error: "); @@ -157,6 +174,7 @@ int disable_aslr = 0; // By default we disable ASLR int pass_env = 1; std::string unix_socket_name; + std::string working_dir; while ((ch = getopt_long(argc, argv, "a:dehsu:?", g_long_options, NULL)) != -1) { switch (ch) @@ -199,6 +217,16 @@ unix_socket_name.assign (optarg); break; + case 'w': + { + struct stat working_dir_stat; + if (stat (optarg, &working_dir_stat) == 0) + working_dir.assign (optarg); + else + ::fprintf(stderr, "warning: working directory doesn't exist: '%s'\n", optarg); + } + break; + case 'h': case '?': default: @@ -254,7 +282,15 @@ close (s); system("clear"); - printf ("Launching '%s' for debug with %u arguments:\n", argv[0], argc); + if (working_dir.empty()) + { + char cwd[PATH_MAX]; + const char *cwd_ptr = getcwd(cwd, sizeof(cwd)); + printf ("Launching '%s' in '%s' for debug with %u arguments:\n", argv[0], cwd_ptr, argc); + } + else + printf ("Launching '%s' in '%s' for debug with %u arguments:\n", argv[0], working_dir.c_str(), argc); + for (int i=0; i 0) err_str[0] = '\0'; struct stat path_stat; Modified: lldb/trunk/tools/debugserver/source/MacOSX/MachProcess.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/tools/debugserver/source/MacOSX/MachProcess.cpp?rev=124060&r1=124059&r2=124060&view=diff ============================================================================== --- lldb/trunk/tools/debugserver/source/MacOSX/MachProcess.cpp (original) +++ lldb/trunk/tools/debugserver/source/MacOSX/MachProcess.cpp Sat Jan 22 23:56:20 2011 @@ -1625,7 +1625,16 @@ { posix_spawnattr_t attr; short flags; - DNBLogThreadedIf(LOG_PROCESS, "%s ( path='%s', argv=%p, envp=%p, process )", __FUNCTION__, path, argv, envp); + DNBLogThreadedIf(LOG_PROCESS, "%s ( path='%s', argv=%p, envp=%p, working_dir=%s, stdin=%s, stdout=%s stderr=%s, no-stdio=%i)", + __FUNCTION__, + path, + argv, + envp, + working_directory, + stdin_path, + stdout_path, + stderr_path, + no_stdio); err.SetError( ::posix_spawnattr_init (&attr), DNBError::POSIX); if (err.Fail() || DNBLogCheckLogBit(LOG_PROCESS)) @@ -1703,9 +1712,9 @@ } else { - int slave_fd_err = open (stderr_path ? stderr_path : "/dev/null", O_RDWR , 0); - int slave_fd_in = open (stdin_path ? stdin_path : "/dev/null", O_RDONLY, 0); - int slave_fd_out = open (stdout_path ? stdout_path : "/dev/null", O_WRONLY, 0); + int slave_fd_err = open (stderr_path ? stderr_path : "/dev/null", O_NOCTTY | O_CREAT | O_RDWR , 0640); + int slave_fd_in = open (stdin_path ? stdin_path : "/dev/null", O_NOCTTY | O_RDONLY); + int slave_fd_out = open (stdout_path ? stdout_path : "/dev/null", O_NOCTTY | O_CREAT | O_WRONLY , 0640); err.SetError( ::posix_spawn_file_actions_adddup2(&file_actions, slave_fd_err, STDERR_FILENO), DNBError::POSIX); if (err.Fail() || DNBLogCheckLogBit(LOG_PROCESS)) @@ -1719,12 +1728,23 @@ if (err.Fail() || DNBLogCheckLogBit(LOG_PROCESS)) err.LogThreaded("::posix_spawn_file_actions_adddup2 ( &file_actions, filedes = %d, newfiledes = STDOUT_FILENO )", slave_fd_out); } + + // TODO: Verify if we can set the working directory back immediately + // after the posix_spawnp call without creating a race condition??? + if (working_directory) + ::chdir (working_directory); + err.SetError( ::posix_spawnp (&pid, path, &file_actions, &attr, (char * const*)argv, (char * const*)envp), DNBError::POSIX); if (err.Fail() || DNBLogCheckLogBit(LOG_PROCESS)) err.LogThreaded("::posix_spawnp ( pid => %i, path = '%s', file_actions = %p, attr = %p, argv = %p, envp = %p )", pid, path, &file_actions, &attr, argv, envp); } else { + // TODO: Verify if we can set the working directory back immediately + // after the posix_spawnp call without creating a race condition??? + if (working_directory) + ::chdir (working_directory); + err.SetError( ::posix_spawnp (&pid, path, NULL, &attr, (char * const*)argv, (char * const*)envp), DNBError::POSIX); if (err.Fail() || DNBLogCheckLogBit(LOG_PROCESS)) err.LogThreaded("::posix_spawnp ( pid => %i, path = '%s', file_actions = %p, attr = %p, argv = %p, envp = %p )", pid, path, NULL, &attr, argv, envp); Modified: lldb/trunk/tools/debugserver/source/debugserver.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/tools/debugserver/source/debugserver.cpp?rev=124060&r1=124059&r2=124060&view=diff ============================================================================== --- lldb/trunk/tools/debugserver/source/debugserver.cpp (original) +++ lldb/trunk/tools/debugserver/source/debugserver.cpp Sat Jan 22 23:56:20 2011 @@ -651,14 +651,14 @@ { "waitfor-interval", required_argument, NULL, 'i' }, // Time in usecs to wait between sampling the pid list when waiting for a process by name { "waitfor-duration", required_argument, NULL, 'd' }, // The time in seconds to wait for a process to show up by name { "native-regs", no_argument, NULL, 'r' }, // Specify to use the native registers instead of the gdb defaults for the architecture. - { "stdio-path", required_argument, NULL, 's' }, // Set the STDIO path to be used when launching applications (STDIN, STDOUT and STDERR) - { "stdin-path", required_argument, NULL, 'I' }, // Set the STDIN path to be used when launching applications - { "stdout-path", required_argument, NULL, 'O' }, // Set the STDIN path to be used when launching applications - { "stderr-path", required_argument, NULL, 'E' }, // Set the STDIN path to be used when launching applications - { "no-stdio", no_argument, NULL, 'n' }, // Do not set up any stdio (perhaps the program is a GUI program) - { "setsid", no_argument, NULL, 'S' }, // call setsid() to make debugserver run in its own sessions + { "stdio-path", required_argument, NULL, 's' }, // Set the STDIO path to be used when launching applications (STDIN, STDOUT and STDERR) (only if debugserver launches the process) + { "stdin-path", required_argument, NULL, 'I' }, // Set the STDIN path to be used when launching applications (only if debugserver launches the process) + { "stdout-path", required_argument, NULL, 'O' }, // Set the STDIN path to be used when launching applications (only if debugserver launches the process) + { "stderr-path", required_argument, NULL, 'E' }, // Set the STDIN path to be used when launching applications (only if debugserver launches the process) + { "no-stdio", no_argument, NULL, 'n' }, // Do not set up any stdio (perhaps the program is a GUI program) (only if debugserver launches the process) + { "setsid", no_argument, NULL, 'S' }, // call setsid() to make debugserver run in its own session { "disable-aslr", no_argument, NULL, 'D' }, // Use _POSIX_SPAWN_DISABLE_ASLR to avoid shared library randomization - { "chdir", no_argument, NULL, 'c' }, // Use _POSIX_SPAWN_DISABLE_ASLR to avoid shared library randomization + { "working-dir", required_argument, NULL, 'W' }, // The working directory that the inferior process should have (only if debugserver launches the process) { NULL, 0, NULL, 0 } }; @@ -699,7 +699,7 @@ std::string stdout_path; std::string stderr_path; std::string arch_name; - std::string working_directory; // The new working directory to use for the inferior + std::string working_dir; // The new working directory to use for the inferior useconds_t waitfor_interval = 1000; // Time in usecs between process lists polls when waiting for a process by name, default 1 msec. useconds_t waitfor_duration = 0; // Time in seconds to wait for a process by name, 0 means wait forever. bool no_stdio = false; @@ -785,9 +785,9 @@ } break; - case 'c': + case 'W': if (optarg && optarg[0]) - working_directory.assign(optarg); + working_dir.assign(optarg); break; case 'x': @@ -826,7 +826,7 @@ else if (strcasecmp(optarg, "stderr") == 0) log_file = stderr; else - log_file = fopen(optarg, "w+"); + log_file = fopen(optarg, "w"); if (log_file == NULL) { @@ -938,11 +938,11 @@ return -1; } - if (!working_directory.empty()) + if (!working_dir.empty()) { - if (remote->Context().SetWorkingDirectory (working_directory.c_str()) == false) + if (remote->Context().SetWorkingDirectory (working_dir.c_str()) == false) { - RNBLogSTDERR ("error: working directory doesn't exist '%s'.\n", working_directory.c_str()); + RNBLogSTDERR ("error: working directory doesn't exist '%s'.\n", working_dir.c_str()); exit (8); } } From gclayton at apple.com Sun Jan 23 00:21:25 2011 From: gclayton at apple.com (Greg Clayton) Date: Sun, 23 Jan 2011 06:21:25 -0000 Subject: [Lldb-commits] [lldb] r124063 - in /lldb/trunk: include/lldb/API/SBTarget.h lldb.xcodeproj/project.pbxproj resources/LLDB-Info.plist source/API/SBTarget.cpp tools/debugserver/debugserver.xcodeproj/project.pbxproj Message-ID: <20110123062125.4F4D02A6C12C@llvm.org> Author: gclayton Date: Sun Jan 23 00:21:25 2011 New Revision: 124063 URL: http://llvm.org/viewvc/llvm-project?rev=124063&view=rev Log: Restored some missing APIs for the test suite. Now testsuite still has some failures due to overloaded SBTarget::Launch() calls. Bumping Xcode project versions: lldb-42 and debugserver-127. Modified: lldb/trunk/include/lldb/API/SBTarget.h lldb/trunk/lldb.xcodeproj/project.pbxproj lldb/trunk/resources/LLDB-Info.plist lldb/trunk/source/API/SBTarget.cpp lldb/trunk/tools/debugserver/debugserver.xcodeproj/project.pbxproj Modified: lldb/trunk/include/lldb/API/SBTarget.h URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/API/SBTarget.h?rev=124063&r1=124062&r2=124063&view=diff ============================================================================== --- lldb/trunk/include/lldb/API/SBTarget.h (original) +++ lldb/trunk/include/lldb/API/SBTarget.h Sun Jan 23 00:21:25 2011 @@ -55,6 +55,13 @@ GetProcess (); lldb::SBProcess + LaunchProcess (char const **argv, + char const **envp, + const char *tty, + uint32_t launch_flags, // See LaunchFlags + bool stop_at_entry); + + lldb::SBProcess Launch (char const **argv, char const **envp, const char *tty, Modified: lldb/trunk/lldb.xcodeproj/project.pbxproj URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/lldb.xcodeproj/project.pbxproj?rev=124063&r1=124062&r2=124063&view=diff ============================================================================== --- lldb/trunk/lldb.xcodeproj/project.pbxproj (original) +++ lldb/trunk/lldb.xcodeproj/project.pbxproj Sun Jan 23 00:21:25 2011 @@ -2950,9 +2950,9 @@ buildSettings = { ALWAYS_SEARCH_USER_PATHS = NO; COPY_PHASE_STRIP = NO; - CURRENT_PROJECT_VERSION = 41; + CURRENT_PROJECT_VERSION = 42; DYLIB_COMPATIBILITY_VERSION = 1; - DYLIB_CURRENT_VERSION = 41; + DYLIB_CURRENT_VERSION = 42; EXPORTED_SYMBOLS_FILE = "resources/lldb-framework-exports"; FRAMEWORK_SEARCH_PATHS = ( "$(inherited)", @@ -3007,11 +3007,11 @@ buildSettings = { ALWAYS_SEARCH_USER_PATHS = NO; COPY_PHASE_STRIP = NO; - CURRENT_PROJECT_VERSION = 41; + CURRENT_PROJECT_VERSION = 42; DEAD_CODE_STRIPPING = YES; DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; DYLIB_COMPATIBILITY_VERSION = 1; - DYLIB_CURRENT_VERSION = 41; + DYLIB_CURRENT_VERSION = 42; EXPORTED_SYMBOLS_FILE = "resources/lldb-framework-exports"; FRAMEWORK_SEARCH_PATHS = ( "$(inherited)", @@ -3086,7 +3086,7 @@ isa = XCBuildConfiguration; buildSettings = { COPY_PHASE_STRIP = YES; - CURRENT_PROJECT_VERSION = 41; + CURRENT_PROJECT_VERSION = 42; DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; FRAMEWORK_SEARCH_PATHS = ( "$(inherited)", @@ -3121,11 +3121,11 @@ buildSettings = { ALWAYS_SEARCH_USER_PATHS = NO; COPY_PHASE_STRIP = YES; - CURRENT_PROJECT_VERSION = 41; + CURRENT_PROJECT_VERSION = 42; DEAD_CODE_STRIPPING = YES; DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; DYLIB_COMPATIBILITY_VERSION = 1; - DYLIB_CURRENT_VERSION = 41; + DYLIB_CURRENT_VERSION = 42; EXPORTED_SYMBOLS_FILE = "resources/lldb-framework-exports"; FRAMEWORK_SEARCH_PATHS = ( "$(inherited)", @@ -3179,7 +3179,7 @@ buildSettings = { CODE_SIGN_IDENTITY = lldb_codesign; COPY_PHASE_STRIP = NO; - CURRENT_PROJECT_VERSION = 41; + CURRENT_PROJECT_VERSION = 42; FRAMEWORK_SEARCH_PATHS = ( "$(inherited)", "\"$(SYSTEM_LIBRARY_DIR)/PrivateFrameworks\"", @@ -3217,7 +3217,7 @@ ); CODE_SIGN_IDENTITY = lldb_codesign; COPY_PHASE_STRIP = YES; - CURRENT_PROJECT_VERSION = 41; + CURRENT_PROJECT_VERSION = 42; DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; FRAMEWORK_SEARCH_PATHS = ( "$(inherited)", Modified: lldb/trunk/resources/LLDB-Info.plist URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/resources/LLDB-Info.plist?rev=124063&r1=124062&r2=124063&view=diff ============================================================================== --- lldb/trunk/resources/LLDB-Info.plist (original) +++ lldb/trunk/resources/LLDB-Info.plist Sun Jan 23 00:21:25 2011 @@ -17,7 +17,7 @@ CFBundleSignature ???? CFBundleVersion - 41 + 42 CFBundleName ${EXECUTABLE_NAME} Modified: lldb/trunk/source/API/SBTarget.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/API/SBTarget.cpp?rev=124063&r1=124062&r2=124063&view=diff ============================================================================== --- lldb/trunk/source/API/SBTarget.cpp (original) +++ lldb/trunk/source/API/SBTarget.cpp Sun Jan 23 00:21:25 2011 @@ -117,6 +117,36 @@ } SBProcess +SBTarget::LaunchProcess +( + char const **argv, + char const **envp, + const char *tty, + uint32_t launch_flags, + bool stop_at_entry +) +{ + LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); + + if (log) + log->Printf ("SBTarget(%p)::LaunchProcess (argv=%p, envp=%p, tty=\"%s\", launch_flags=%d, stop_at_entry=%i)", + m_opaque_sp.get(), argv, envp, tty, launch_flags, stop_at_entry); + + SBError sb_error; + SBProcess sb_process = Launch (argv, envp, tty, tty, tty, NULL, launch_flags, stop_at_entry, sb_error); + + log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API); + if (log) + { + log->Printf ("SBTarget(%p)::LaunchProcess (...) => SBProcess(%p)", + m_opaque_sp.get(), sb_process.get()); + } + + return sb_process; +} + + +SBProcess SBTarget::Launch ( char const **argv, Modified: lldb/trunk/tools/debugserver/debugserver.xcodeproj/project.pbxproj URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/tools/debugserver/debugserver.xcodeproj/project.pbxproj?rev=124063&r1=124062&r2=124063&view=diff ============================================================================== --- lldb/trunk/tools/debugserver/debugserver.xcodeproj/project.pbxproj (original) +++ lldb/trunk/tools/debugserver/debugserver.xcodeproj/project.pbxproj Sun Jan 23 00:21:25 2011 @@ -460,7 +460,7 @@ i386, ); COPY_PHASE_STRIP = NO; - CURRENT_PROJECT_VERSION = 126; + CURRENT_PROJECT_VERSION = 127; GCC_WARN_ABOUT_RETURN_TYPE = YES; GCC_WARN_UNUSED_VARIABLE = YES; STRIP_INSTALLED_PRODUCT = NO; @@ -478,7 +478,7 @@ x86_64, i386, ); - CURRENT_PROJECT_VERSION = 126; + CURRENT_PROJECT_VERSION = 127; DEAD_CODE_STRIPPING = YES; GCC_WARN_ABOUT_RETURN_TYPE = YES; GCC_WARN_UNUSED_VARIABLE = YES; @@ -498,7 +498,7 @@ x86_64, i386, ); - CURRENT_PROJECT_VERSION = 126; + CURRENT_PROJECT_VERSION = 127; DEAD_CODE_STRIPPING = YES; GCC_WARN_ABOUT_RETURN_TYPE = YES; GCC_WARN_UNUSED_VARIABLE = YES; @@ -515,7 +515,7 @@ buildSettings = { "CODE_SIGN_ENTITLEMENTS[sdk=iphoneos*]" = "source/debugserver-entitlements.plist"; COPY_PHASE_STRIP = YES; - CURRENT_PROJECT_VERSION = 126; + CURRENT_PROJECT_VERSION = 127; DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; FRAMEWORK_SEARCH_PATHS = $SDKROOT/System/Library/PrivateFrameworks; "FRAMEWORK_SEARCH_PATHS[sdk=iphoneos*][arch=*]" = ( @@ -556,7 +556,7 @@ "CODE_SIGN_ENTITLEMENTS[sdk=iphoneos*]" = "source/debugserver-entitlements.plist"; "CODE_SIGN_IDENTITY[sdk=macosx*]" = lldb_codesign; COPY_PHASE_STRIP = YES; - CURRENT_PROJECT_VERSION = 126; + CURRENT_PROJECT_VERSION = 127; FRAMEWORK_SEARCH_PATHS = $SDKROOT/System/Library/PrivateFrameworks; "FRAMEWORK_SEARCH_PATHS[sdk=iphoneos*][arch=*]" = ( "$(SDKROOT)/System/Library/PrivateFrameworks", @@ -597,7 +597,7 @@ "CODE_SIGN_ENTITLEMENTS[sdk=iphoneos*]" = "source/debugserver-entitlements.plist"; "CODE_SIGN_IDENTITY[sdk=macosx*]" = lldb_codesign; COPY_PHASE_STRIP = YES; - CURRENT_PROJECT_VERSION = 126; + CURRENT_PROJECT_VERSION = 127; DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; FRAMEWORK_SEARCH_PATHS = $SDKROOT/System/Library/PrivateFrameworks; "FRAMEWORK_SEARCH_PATHS[sdk=iphoneos*][arch=*]" = ( From johnny.chen at apple.com Sun Jan 23 02:11:49 2011 From: johnny.chen at apple.com (Johnny Chen) Date: Sun, 23 Jan 2011 08:11:49 -0000 Subject: [Lldb-commits] [lldb] r124069 - /lldb/trunk/include/lldb/API/SBTarget.h Message-ID: <20110123081149.ADA382A6C12C@llvm.org> Author: johnny Date: Sun Jan 23 02:11:49 2011 New Revision: 124069 URL: http://llvm.org/viewvc/llvm-project?rev=124069&view=rev Log: Let's teach SWIG to rename the overloaded SBTarget::Launch() function which has provision for specifying a working directory with the name LaunchWithCWD in our target language (Python) for now. This fixes the test suite failures due to the overloading. Modified: lldb/trunk/include/lldb/API/SBTarget.h Modified: lldb/trunk/include/lldb/API/SBTarget.h URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/API/SBTarget.h?rev=124069&r1=124068&r2=124069&view=diff ============================================================================== --- lldb/trunk/include/lldb/API/SBTarget.h (original) +++ lldb/trunk/include/lldb/API/SBTarget.h Sun Jan 23 02:11:49 2011 @@ -69,6 +69,18 @@ bool stop_at_entry, lldb::SBError& error); +#ifdef SWIG +%rename(LaunchWithCWD) Launch (char const **argv, + char const **envp, + const char *stdin_path, + const char *stdout_path, + const char *stderr_path, + const char *working_directory, + uint32_t launch_flags, // See LaunchFlags + bool stop_at_entry, + lldb::SBError& error); +#endif + lldb::SBProcess Launch (char const **argv, char const **envp, From gclayton at apple.com Sun Jan 23 11:46:23 2011 From: gclayton at apple.com (Greg Clayton) Date: Sun, 23 Jan 2011 17:46:23 -0000 Subject: [Lldb-commits] [lldb] r124075 - in /lldb/trunk: include/lldb/API/ source/API/ test/ test/array_types/ test/bitfields/ test/breakpoint_conditions/ test/breakpoint_ignore_count/ test/class_static/ test/class_types/ test/conditional_break/ test/expression_command/test/ test/foundation/ test/hello_world/ test/objc-stepping/ test/python_api/event/ test/python_api/frame/ test/python_api/symbol-context/ test/source-manager/ test/threads/ Message-ID: <20110123174623.540422A6C12C@llvm.org> Author: gclayton Date: Sun Jan 23 11:46:22 2011 New Revision: 124075 URL: http://llvm.org/viewvc/llvm-project?rev=124075&view=rev Log: Deprecated old forms of SBTarget::Launch. There is not just one and no SWIG renaming done to work around deprecated APIs. Modified: lldb/trunk/include/lldb/API/SBTarget.h lldb/trunk/source/API/SBTarget.cpp lldb/trunk/test/array_types/TestArrayTypes.py lldb/trunk/test/bitfields/TestBitfields.py lldb/trunk/test/breakpoint_conditions/TestBreakpointConditions.py lldb/trunk/test/breakpoint_ignore_count/TestBreakpointIgnoreCount.py lldb/trunk/test/class_static/TestStaticVariables.py lldb/trunk/test/class_types/TestClassTypes.py lldb/trunk/test/conditional_break/TestConditionalBreak.py lldb/trunk/test/expression_command/test/TestExprs.py lldb/trunk/test/foundation/TestObjCMethods.py lldb/trunk/test/foundation/TestSymbolTable.py lldb/trunk/test/hello_world/TestHelloWorld.py lldb/trunk/test/lldbtest.py lldb/trunk/test/objc-stepping/TestObjCStepping.py lldb/trunk/test/python_api/event/TestEvents.py lldb/trunk/test/python_api/frame/TestFrames.py lldb/trunk/test/python_api/symbol-context/TestSymbolContext.py lldb/trunk/test/source-manager/TestSourceManager.py lldb/trunk/test/threads/TestPrintStackTraces.py Modified: lldb/trunk/include/lldb/API/SBTarget.h URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/API/SBTarget.h?rev=124075&r1=124074&r2=124075&view=diff ============================================================================== --- lldb/trunk/include/lldb/API/SBTarget.h (original) +++ lldb/trunk/include/lldb/API/SBTarget.h Sun Jan 23 11:46:22 2011 @@ -55,33 +55,6 @@ GetProcess (); lldb::SBProcess - LaunchProcess (char const **argv, - char const **envp, - const char *tty, - uint32_t launch_flags, // See LaunchFlags - bool stop_at_entry); - - lldb::SBProcess - Launch (char const **argv, - char const **envp, - const char *tty, - uint32_t launch_flags, // See LaunchFlags - bool stop_at_entry, - lldb::SBError& error); - -#ifdef SWIG -%rename(LaunchWithCWD) Launch (char const **argv, - char const **envp, - const char *stdin_path, - const char *stdout_path, - const char *stderr_path, - const char *working_directory, - uint32_t launch_flags, // See LaunchFlags - bool stop_at_entry, - lldb::SBError& error); -#endif - - lldb::SBProcess Launch (char const **argv, char const **envp, const char *stdin_path, Modified: lldb/trunk/source/API/SBTarget.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/API/SBTarget.cpp?rev=124075&r1=124074&r2=124075&view=diff ============================================================================== --- lldb/trunk/source/API/SBTarget.cpp (original) +++ lldb/trunk/source/API/SBTarget.cpp Sun Jan 23 11:46:22 2011 @@ -116,49 +116,6 @@ return debugger; } -SBProcess -SBTarget::LaunchProcess -( - char const **argv, - char const **envp, - const char *tty, - uint32_t launch_flags, - bool stop_at_entry -) -{ - LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); - - if (log) - log->Printf ("SBTarget(%p)::LaunchProcess (argv=%p, envp=%p, tty=\"%s\", launch_flags=%d, stop_at_entry=%i)", - m_opaque_sp.get(), argv, envp, tty, launch_flags, stop_at_entry); - - SBError sb_error; - SBProcess sb_process = Launch (argv, envp, tty, tty, tty, NULL, launch_flags, stop_at_entry, sb_error); - - log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API); - if (log) - { - log->Printf ("SBTarget(%p)::LaunchProcess (...) => SBProcess(%p)", - m_opaque_sp.get(), sb_process.get()); - } - - return sb_process; -} - - -SBProcess -SBTarget::Launch -( - char const **argv, - char const **envp, - const char *tty, - uint32_t launch_flags, - bool stop_at_entry, - SBError &error -) -{ - return Launch (argv, envp, tty, tty, tty, NULL, launch_flags, stop_at_entry, error); -} SBProcess SBTarget::Launch Modified: lldb/trunk/test/array_types/TestArrayTypes.py URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/array_types/TestArrayTypes.py?rev=124075&r1=124074&r2=124075&view=diff ============================================================================== --- lldb/trunk/test/array_types/TestArrayTypes.py (original) +++ lldb/trunk/test/array_types/TestArrayTypes.py Sun Jan 23 11:46:22 2011 @@ -110,7 +110,8 @@ substrs = ["resolved = 1"]) # Now launch the process, and do not stop at entry point. - self.process = target.LaunchProcess([], [], os.ctermid(), 0, False) + error = lldb.SBError() + self.process = target.Launch (None, None, os.ctermid(), os.ctermid(), os.ctermid(), None, 0, False, error) self.process = target.GetProcess() self.assertTrue(self.process.IsValid(), PROCESS_IS_VALID) Modified: lldb/trunk/test/bitfields/TestBitfields.py URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/bitfields/TestBitfields.py?rev=124075&r1=124074&r2=124075&view=diff ============================================================================== --- lldb/trunk/test/bitfields/TestBitfields.py (original) +++ lldb/trunk/test/bitfields/TestBitfields.py Sun Jan 23 11:46:22 2011 @@ -94,7 +94,8 @@ breakpoint = target.BreakpointCreateByLocation("main.c", self.line) self.assertTrue(breakpoint.IsValid(), VALID_BREAKPOINT) - self.process = target.LaunchProcess([], [], os.ctermid(), False, 0) + error = lldb.SBError() + self.process = target.Launch (None, None, os.ctermid(), os.ctermid(), os.ctermid(), None, 0, False, error) self.assertTrue(self.process.IsValid(), PROCESS_IS_VALID) # The stop reason of the thread should be breakpoint. Modified: lldb/trunk/test/breakpoint_conditions/TestBreakpointConditions.py URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/breakpoint_conditions/TestBreakpointConditions.py?rev=124075&r1=124074&r2=124075&view=diff ============================================================================== --- lldb/trunk/test/breakpoint_conditions/TestBreakpointConditions.py (original) +++ lldb/trunk/test/breakpoint_conditions/TestBreakpointConditions.py Sun Jan 23 11:46:22 2011 @@ -139,7 +139,8 @@ startstr = 'val == 3') # Now launch the process, and do not stop at entry point. - self.process = target.LaunchProcess([], [], os.ctermid(), 0, False) + error = lldb.SBError() + self.process = target.Launch (None, None, os.ctermid(), os.ctermid(), os.ctermid(), None, 0, False, error) self.process = target.GetProcess() self.assertTrue(self.process.IsValid(), PROCESS_IS_VALID) Modified: lldb/trunk/test/breakpoint_ignore_count/TestBreakpointIgnoreCount.py URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/breakpoint_ignore_count/TestBreakpointIgnoreCount.py?rev=124075&r1=124074&r2=124075&view=diff ============================================================================== --- lldb/trunk/test/breakpoint_ignore_count/TestBreakpointIgnoreCount.py (original) +++ lldb/trunk/test/breakpoint_ignore_count/TestBreakpointIgnoreCount.py Sun Jan 23 11:46:22 2011 @@ -101,7 +101,8 @@ "SetIgnoreCount() works correctly") # Now launch the process, and do not stop at entry point. - self.process = target.LaunchProcess([], [], os.ctermid(), 0, False) + error = lldb.SBError() + self.process = target.Launch (None, None, os.ctermid(), os.ctermid(), os.ctermid(), None, 0, False, error) self.process = target.GetProcess() self.assertTrue(self.process.IsValid(), PROCESS_IS_VALID) Modified: lldb/trunk/test/class_static/TestStaticVariables.py URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/class_static/TestStaticVariables.py?rev=124075&r1=124074&r2=124075&view=diff ============================================================================== --- lldb/trunk/test/class_static/TestStaticVariables.py (original) +++ lldb/trunk/test/class_static/TestStaticVariables.py Sun Jan 23 11:46:22 2011 @@ -80,7 +80,8 @@ self.assertTrue(breakpoint.IsValid(), VALID_BREAKPOINT) # Now launch the process, and do not stop at entry point. - self.process = target.LaunchProcess([], [], os.ctermid(), 0, False) + error = lldb.SBError() + self.process = target.Launch (None, None, os.ctermid(), os.ctermid(), os.ctermid(), None, 0, False, error) self.process = target.GetProcess() self.assertTrue(self.process.IsValid(), PROCESS_IS_VALID) Modified: lldb/trunk/test/class_types/TestClassTypes.py URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/class_types/TestClassTypes.py?rev=124075&r1=124074&r2=124075&view=diff ============================================================================== --- lldb/trunk/test/class_types/TestClassTypes.py (original) +++ lldb/trunk/test/class_types/TestClassTypes.py Sun Jan 23 11:46:22 2011 @@ -119,12 +119,12 @@ str(self.line)]) # Now launch the process, and do not stop at entry point. - rc = lldb.SBError() - self.process = target.Launch([], [], os.ctermid(), 0, False, rc) + error = lldb.SBError() + self.process = target.Launch (None, None, os.ctermid(), os.ctermid(), os.ctermid(), None, 0, False, error) #self.breakAfterLaunch(self.process, "C::C(int, int, int)") - if not rc.Success() or not self.process.IsValid(): - self.fail("SBTarget.LaunchProcess() failed") + if not error.Success() or not self.process.IsValid(): + self.fail("SBTarget.Launch() failed") if self.process.GetState() != lldb.eStateStopped: self.fail("Process should be in the 'stopped' state, " Modified: lldb/trunk/test/conditional_break/TestConditionalBreak.py URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/conditional_break/TestConditionalBreak.py?rev=124075&r1=124074&r2=124075&view=diff ============================================================================== --- lldb/trunk/test/conditional_break/TestConditionalBreak.py (original) +++ lldb/trunk/test/conditional_break/TestConditionalBreak.py Sun Jan 23 11:46:22 2011 @@ -52,10 +52,10 @@ self.assertTrue(breakpoint.IsValid(), VALID_BREAKPOINT) # Now launch the process, and do not stop at entry point. - rc = lldb.SBError() - self.process = target.Launch([], [], os.ctermid(), 0, False, rc) + error = lldb.SBError() + self.process = target.Launch (None, None, os.ctermid(), os.ctermid(), os.ctermid(), None, 0, False, error) - self.assertTrue(rc.Success() and self.process.IsValid(), PROCESS_IS_VALID) + self.assertTrue(error.Success() and self.process.IsValid(), PROCESS_IS_VALID) # The stop reason of the thread should be breakpoint. self.assertTrue(self.process.GetState() == lldb.eStateStopped, Modified: lldb/trunk/test/expression_command/test/TestExprs.py URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/expression_command/test/TestExprs.py?rev=124075&r1=124074&r2=124075&view=diff ============================================================================== --- lldb/trunk/test/expression_command/test/TestExprs.py (original) +++ lldb/trunk/test/expression_command/test/TestExprs.py Sun Jan 23 11:46:22 2011 @@ -100,10 +100,10 @@ # Launch the process, and do not stop at the entry point. # Pass 'X Y Z' as the args, which makes argc == 4. - rc = lldb.SBError() - self.process = target.Launch(['X', 'Y', 'Z'], [], os.ctermid(), 0, False, rc) + error = lldb.SBError() + self.process = target.Launch(['X', 'Y', 'Z'], None, os.ctermid(), os.ctermid(), os.ctermid(), None, 0, False, error) - if not rc.Success() or not self.process.IsValid(): + if not error.Success() or not self.process.IsValid(): self.fail("SBTarget.LaunchProcess() failed") if self.process.GetState() != lldb.eStateStopped: Modified: lldb/trunk/test/foundation/TestObjCMethods.py URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/foundation/TestObjCMethods.py?rev=124075&r1=124074&r2=124075&view=diff ============================================================================== --- lldb/trunk/test/foundation/TestObjCMethods.py (original) +++ lldb/trunk/test/foundation/TestObjCMethods.py Sun Jan 23 11:46:22 2011 @@ -212,7 +212,8 @@ self.assertTrue(break1.IsValid(), VALID_BREAKPOINT) # Now launch the process, and do not stop at entry point. - self.process = target.LaunchProcess([], [], os.ctermid(), 0, False) + error = lldb.SBError() + self.process = target.Launch (None, None, os.ctermid(), os.ctermid(), os.ctermid(), None, 0, False, error) self.assertTrue(self.process.IsValid(), PROCESS_IS_VALID) Modified: lldb/trunk/test/foundation/TestSymbolTable.py URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/foundation/TestSymbolTable.py?rev=124075&r1=124074&r2=124075&view=diff ============================================================================== --- lldb/trunk/test/foundation/TestSymbolTable.py (original) +++ lldb/trunk/test/foundation/TestSymbolTable.py Sun Jan 23 11:46:22 2011 @@ -45,7 +45,8 @@ self.assertTrue(target.IsValid(), VALID_TARGET) # Launch the process, and do not stop at the entry point. - process = target.LaunchProcess([], [], os.ctermid(), 0, False) + error = lldb.SBError() + process = target.Launch (None, None, os.ctermid(), os.ctermid(), os.ctermid(), None, 0, False, error) # # Exercise Python APIs to access the symbol table entries. Modified: lldb/trunk/test/hello_world/TestHelloWorld.py URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/hello_world/TestHelloWorld.py?rev=124075&r1=124074&r2=124075&view=diff ============================================================================== --- lldb/trunk/test/hello_world/TestHelloWorld.py (original) +++ lldb/trunk/test/hello_world/TestHelloWorld.py Sun Jan 23 11:46:22 2011 @@ -49,10 +49,11 @@ "Breakpoint.SetEnabled(True) works") # rdar://problem/8364687 - # SBTarget.LaunchProcess() issue (or is there some race condition)? + # SBTarget.Launch() issue (or is there some race condition)? if useLaunchAPI: - process = target.LaunchProcess([], [], os.ctermid(), 0, False) + error = lldb.SBError() + process = target.Launch (None, None, os.ctermid(), os.ctermid(), os.ctermid(), None, 0, False, error) # The following isn't needed anymore, rdar://8364687 is fixed. # # Apply some dances after LaunchProcess() in order to break at "main". Modified: lldb/trunk/test/lldbtest.py URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/lldbtest.py?rev=124075&r1=124074&r2=124075&view=diff ============================================================================== --- lldb/trunk/test/lldbtest.py (original) +++ lldb/trunk/test/lldbtest.py Sun Jan 23 11:46:22 2011 @@ -816,7 +816,7 @@ def breakAfterLaunch(self, process, func, trace=False): """ - Perform some dancees after LaunchProcess() to break at func name. + Perform some dances after Launch() to break at func name. Return True if we can successfully break at the func name in due time. """ Modified: lldb/trunk/test/objc-stepping/TestObjCStepping.py URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/objc-stepping/TestObjCStepping.py?rev=124075&r1=124074&r2=124075&view=diff ============================================================================== --- lldb/trunk/test/objc-stepping/TestObjCStepping.py (original) +++ lldb/trunk/test/objc-stepping/TestObjCStepping.py Sun Jan 23 11:46:22 2011 @@ -64,7 +64,8 @@ self.assertTrue(break_returnStruct_call_super.IsValid(), VALID_BREAKPOINT) # Now launch the process, and do not stop at entry point. - self.process = target.LaunchProcess([], [], os.ctermid(), 0, False) + error = lldb.SBError() + self.process = target.Launch (None, None, os.ctermid(), os.ctermid(), os.ctermid(), None, 0, False, error) self.assertTrue(self.process.IsValid(), PROCESS_IS_VALID) Modified: lldb/trunk/test/python_api/event/TestEvents.py URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/python_api/event/TestEvents.py?rev=124075&r1=124074&r2=124075&view=diff ============================================================================== --- lldb/trunk/test/python_api/event/TestEvents.py (original) +++ lldb/trunk/test/python_api/event/TestEvents.py Sun Jan 23 11:46:22 2011 @@ -60,7 +60,8 @@ VALID_BREAKPOINT) # Now launch the process, and do not stop at entry point. - self.process = target.LaunchProcess([], [], os.ctermid(), 0, False) + error = lldb.SBError() + self.process = target.Launch (None, None, os.ctermid(), os.ctermid(), os.ctermid(), None, 0, False, error) self.process = target.GetProcess() self.assertTrue(self.process.IsValid(), PROCESS_IS_VALID) @@ -121,7 +122,8 @@ VALID_BREAKPOINT) # Now launch the process, and do not stop at the entry point. - self.process = target.LaunchProcess([], [], os.ctermid(), 0, False) + error = lldb.SBError() + self.process = target.Launch (None, None, os.ctermid(), os.ctermid(), os.ctermid(), None, 0, False, error) self.process = target.GetProcess() self.assertTrue(self.process.GetState() == lldb.eStateStopped, Modified: lldb/trunk/test/python_api/frame/TestFrames.py URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/python_api/frame/TestFrames.py?rev=124075&r1=124074&r2=124075&view=diff ============================================================================== --- lldb/trunk/test/python_api/frame/TestFrames.py (original) +++ lldb/trunk/test/python_api/frame/TestFrames.py Sun Jan 23 11:46:22 2011 @@ -44,7 +44,8 @@ # Note that we don't assign the process to self.process as in other test # cases. We want the inferior to run till it exits and there's no need # for the testing framework to kill the inferior upon tearDown(). - process = target.LaunchProcess([], [], os.ctermid(), 0, False) + error = lldb.SBError() + process = target.Launch (None, None, os.ctermid(), os.ctermid(), os.ctermid(), None, 0, False, error) process = target.GetProcess() self.assertTrue(process.GetState() == lldb.eStateStopped, Modified: lldb/trunk/test/python_api/symbol-context/TestSymbolContext.py URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/python_api/symbol-context/TestSymbolContext.py?rev=124075&r1=124074&r2=124075&view=diff ============================================================================== --- lldb/trunk/test/python_api/symbol-context/TestSymbolContext.py (original) +++ lldb/trunk/test/python_api/symbol-context/TestSymbolContext.py Sun Jan 23 11:46:22 2011 @@ -47,7 +47,8 @@ VALID_BREAKPOINT) # Now launch the process, and do not stop at entry point. - self.process = target.LaunchProcess([], [], os.ctermid(), 0, False) + error = lldb.SBError() + self.process = target.Launch (None, None, os.ctermid(), os.ctermid(), os.ctermid(), None, 0, False, error) self.process = target.GetProcess() self.assertTrue(self.process.IsValid(), PROCESS_IS_VALID) Modified: lldb/trunk/test/source-manager/TestSourceManager.py URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/source-manager/TestSourceManager.py?rev=124075&r1=124074&r2=124075&view=diff ============================================================================== --- lldb/trunk/test/source-manager/TestSourceManager.py (original) +++ lldb/trunk/test/source-manager/TestSourceManager.py Sun Jan 23 11:46:22 2011 @@ -43,7 +43,8 @@ self.assertTrue(target.IsValid(), VALID_TARGET) # Launch the process, and do not stop at the entry point. - process = target.LaunchProcess([], [], os.ctermid(), 0, False) + error = lldb.SBError() + process = target.Launch (None, None, os.ctermid(), os.ctermid(), os.ctermid(), None, 0, False, error) # # Exercise Python APIs to display source lines. Modified: lldb/trunk/test/threads/TestPrintStackTraces.py URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/threads/TestPrintStackTraces.py?rev=124075&r1=124074&r2=124075&view=diff ============================================================================== --- lldb/trunk/test/threads/TestPrintStackTraces.py (original) +++ lldb/trunk/test/threads/TestPrintStackTraces.py Sun Jan 23 11:46:22 2011 @@ -35,7 +35,7 @@ # Now launch the process, and do not stop at entry point. rc = lldb.SBError() - self.process = target.Launch([], [], os.ctermid(), 0, False, rc) + self.process = target.Launch (None, None, os.ctermid(), os.ctermid(), os.ctermid(), None, 0, False, rc) if not rc.Success() or not self.process.IsValid(): self.fail("SBTarget.LaunchProcess() failed") From gclayton at apple.com Sun Jan 23 13:58:50 2011 From: gclayton at apple.com (Greg Clayton) Date: Sun, 23 Jan 2011 19:58:50 -0000 Subject: [Lldb-commits] [lldb] r124080 - in /lldb/trunk/source: Plugins/Process/gdb-remote/ProcessGDBRemote.cpp Target/Process.cpp Message-ID: <20110123195850.167192A6C12C@llvm.org> Author: gclayton Date: Sun Jan 23 13:58:49 2011 New Revision: 124080 URL: http://llvm.org/viewvc/llvm-project?rev=124080&view=rev Log: Improved process logging for both lldb_private::Process and ProcessGDBRemote. Modified: lldb/trunk/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp lldb/trunk/source/Target/Process.cpp Modified: lldb/trunk/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp?rev=124080&r1=124079&r2=124080&view=diff ============================================================================== --- lldb/trunk/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp (original) +++ lldb/trunk/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp Sun Jan 23 13:58:49 2011 @@ -1181,18 +1181,35 @@ { Error error; - if (m_gdb_comm.IsRunning()) + LogSP log (ProcessGDBRemoteLog::GetLogIfAllCategoriesSet(GDBR_LOG_PROCESS)); + + const bool is_running = m_gdb_comm.IsRunning(); + if (log) + log->Printf ("ProcessGDBRemote::InterruptIfRunning(discard_thread_plans=%i, catch_stop_event=%i, resume_private_state_thread=%i) is_running=%i", + discard_thread_plans, + catch_stop_event, + resume_private_state_thread, + is_running); + + if (catch_stop_event) + { + if (log) + log->Printf ("ProcessGDBRemote::InterruptIfRunning() pausing private state thread"); + PausePrivateStateThread(); + } + + if (discard_thread_plans) + { + if (log) + log->Printf ("ProcessGDBRemote::InterruptIfRunning() discarding all thread plans"); + m_thread_list.DiscardThreadPlans(); + } + if (is_running) { bool timed_out = false; bool sent_interrupt = false; Mutex::Locker locker; - if (catch_stop_event) - PausePrivateStateThread(); - - if (discard_thread_plans) - m_thread_list.DiscardThreadPlans(); - //m_debugserver_pid = LLDB_INVALID_PROCESS_ID; if (!m_gdb_comm.SendInterrupt (locker, 1, sent_interrupt, timed_out)) { @@ -1205,20 +1222,27 @@ return error; } - if (catch_stop_event) { TimeValue timeout_time; timeout_time = TimeValue::Now(); timeout_time.OffsetWithSeconds(1); StateType state = WaitForProcessStopPrivate (&timeout_time, stop_event_sp); + + const bool timed_out = state == eStateInvalid; + if (log) + log->Printf ("ProcessGDBRemote::InterruptIfRunning() catch stop event: state = %s, timed-out=%i", StateAsCString(state), timed_out); - if (state == eStateInvalid) + if (timed_out) error.SetErrorString("unable to verify target stopped"); } if (catch_stop_event && resume_private_state_thread) + { + if (log) + log->Printf ("ProcessGDBRemote::InterruptIfRunning() resuming private state thread"); ResumePrivateStateThread(); + } } return error; } @@ -1226,6 +1250,10 @@ Error ProcessGDBRemote::WillDetach () { + LogSP log (ProcessGDBRemoteLog::GetLogIfAllCategoriesSet(GDBR_LOG_PROCESS)); + if (log) + log->Printf ("ProcessGDBRemote::WillDetach()"); + bool discard_thread_plans = true; bool catch_stop_event = true; bool resume_private_state_thread = false; // DoDetach will resume the thread @@ -1269,11 +1297,16 @@ Error ProcessGDBRemote::WillDestroy () { + LogSP log (ProcessGDBRemoteLog::GetLogIfAllCategoriesSet(GDBR_LOG_PROCESS)); + if (log) + log->Printf ("ProcessGDBRemote::WillDestroy()"); bool discard_thread_plans = true; bool catch_stop_event = true; bool resume_private_state_thread = true; EventSP event_sp; - return InterruptIfRunning (discard_thread_plans, catch_stop_event, resume_private_state_thread, event_sp); + return InterruptIfRunning (discard_thread_plans, catch_stop_event, resume_private_state_thread, event_sp); + + } Error Modified: lldb/trunk/source/Target/Process.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Target/Process.cpp?rev=124080&r1=124079&r2=124080&view=diff ============================================================================== --- lldb/trunk/source/Target/Process.cpp (original) +++ lldb/trunk/source/Target/Process.cpp Sun Jan 23 13:58:49 2011 @@ -1398,13 +1398,31 @@ { // Fixme: we should track the blocks we've allocated, and clean them up... // We could even do our own allocator here if that ends up being more efficient. - return DoAllocateMemory (size, permissions, error); + addr_t allocated_addr = DoAllocateMemory (size, permissions, error); + LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_PROCESS)); + if (log) + log->Printf("Process::AllocateMemory(size = %zu, permissions=%c%c%c) => 0x%16.16llx (m_stop_id = %u)", + size, + permissions & ePermissionsReadable ? 'r' : '-', + permissions & ePermissionsWritable ? 'w' : '-', + permissions & ePermissionsExecutable ? 'x' : '-', + (uint64_t)allocated_addr, + m_stop_id); + return allocated_addr; } Error Process::DeallocateMemory (addr_t ptr) { - return DoDeallocateMemory (ptr); + Error error(DoDeallocateMemory (ptr)); + + LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_PROCESS)); + if (log) + log->Printf("Process::DeallocateMemory(addr=0x%16.16llx) => err = %s (m_stop_id = %u)", + ptr, + error.AsCString("SUCCESS"), + m_stop_id); + return error; } From jingham at apple.com Sun Jan 23 15:14:08 2011 From: jingham at apple.com (Jim Ingham) Date: Sun, 23 Jan 2011 21:14:08 -0000 Subject: [Lldb-commits] [lldb] r124084 - in /lldb/trunk: lldb.xcodeproj/project.pbxproj source/Core/Broadcaster.cpp source/Target/Process.cpp Message-ID: <20110123211408.7A71B2A6C12C@llvm.org> Author: jingham Date: Sun Jan 23 15:14:08 2011 New Revision: 124084 URL: http://llvm.org/viewvc/llvm-project?rev=124084&view=rev Log: Add some more logging of broadcaster and Process. Also, protect the event broadcasting against hijacking in mid-event delivery. Modified: lldb/trunk/lldb.xcodeproj/project.pbxproj lldb/trunk/source/Core/Broadcaster.cpp lldb/trunk/source/Target/Process.cpp Modified: lldb/trunk/lldb.xcodeproj/project.pbxproj URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/lldb.xcodeproj/project.pbxproj?rev=124084&r1=124083&r2=124084&view=diff ============================================================================== --- lldb/trunk/lldb.xcodeproj/project.pbxproj (original) +++ lldb/trunk/lldb.xcodeproj/project.pbxproj Sun Jan 23 15:14:08 2011 @@ -2384,7 +2384,6 @@ isa = PBXProject; buildConfigurationList = 1DEB91EF08733DB70010E9CD /* Build configuration list for PBXProject "lldb" */; compatibilityVersion = "Xcode 3.1"; - developmentRegion = English; hasScannedForEncodings = 1; knownRegions = ( en, Modified: lldb/trunk/source/Core/Broadcaster.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Core/Broadcaster.cpp?rev=124084&r1=124083&r2=124084&view=diff ============================================================================== --- lldb/trunk/source/Core/Broadcaster.cpp (original) +++ lldb/trunk/source/Core/Broadcaster.cpp Sun Jan 23 15:14:08 2011 @@ -213,16 +213,18 @@ const uint32_t event_type = event_sp->GetType(); - LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_EVENTS)); + Mutex::Locker event_types_locker(m_listeners_mutex); + LogSP log(lldb_private::GetLogIfAnyCategoriesSet (LIBLLDB_LOG_EVENTS | LIBLLDB_LOG_PROCESS)); if (log) { StreamString event_description; event_sp->Dump (&event_description); - log->Printf ("%p Broadcaster(\"%s\")::BroadcastEvent (event_sp = {%s}, unique =%i)", + log->Printf ("%p Broadcaster(\"%s\")::BroadcastEvent (event_sp = {%s}, unique =%i) hijack = %p", this, m_broadcaster_name.AsCString(""), event_description.GetData(), - unique); + unique, + m_hijacking_listener); } if (m_hijacking_listener != NULL && m_hijacking_mask & event_type) @@ -233,7 +235,6 @@ } else { - Mutex::Locker event_types_locker(m_listeners_mutex); collection::iterator pos, end = m_listeners.end(); @@ -270,7 +271,8 @@ Broadcaster::HijackBroadcaster (Listener *listener, uint32_t event_mask) { Mutex::Locker event_types_locker(m_listeners_mutex); - + assert (m_hijacking_listener == NULL); + if (m_hijacking_listener != NULL) return false; Modified: lldb/trunk/source/Target/Process.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Target/Process.cpp?rev=124084&r1=124083&r2=124084&view=diff ============================================================================== --- lldb/trunk/source/Target/Process.cpp (original) +++ lldb/trunk/source/Target/Process.cpp Sun Jan 23 15:14:08 2011 @@ -2627,15 +2627,15 @@ exe_ctx.thread->QueueThreadPlan(thread_plan_sp, true); - Listener listener("ClangFunction temporary listener"); + Listener listener("lldb.process.listener.run-thread-plan"); exe_ctx.process->HijackProcessEvents(&listener); - lldb::LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_STEP)); + lldb::LogSP log(lldb_private::GetLogIfAnyCategoriesSet (LIBLLDB_LOG_STEP | LIBLLDB_LOG_PROCESS)); if (log) { StreamString s; thread_plan_sp->GetDescription(&s, lldb::eDescriptionLevelVerbose); - log->Printf ("Resuming thread 0x%x to run thread plan \"%s\".", tid, s.GetData()); + log->Printf ("Resuming thread %u - 0x%4.4x to run thread plan \"%s\".", exe_ctx.thread->GetIndexID(), exe_ctx.thread->GetID(), s.GetData()); } Error resume_error = exe_ctx.process->Resume (); @@ -2738,14 +2738,15 @@ if (log) log->Printf ("Halt failed: \"%s\", I'm just going to wait a little longer and see if the world gets nicer to me.", halt_error.AsCString()); + abort(); - if (single_thread_timeout_usec != 0) - { - real_timeout = TimeValue::Now(); - real_timeout.OffsetWithMicroSeconds(single_thread_timeout_usec); - timeout_ptr = &real_timeout; - } - continue; + if (single_thread_timeout_usec != 0) + { + real_timeout = TimeValue::Now(); + real_timeout.OffsetWithMicroSeconds(single_thread_timeout_usec); + timeout_ptr = &real_timeout; + } + continue; } } From jingham at apple.com Sun Jan 23 15:20:20 2011 From: jingham at apple.com (Jim Ingham) Date: Sun, 23 Jan 2011 21:20:20 -0000 Subject: [Lldb-commits] [lldb] r124086 - /lldb/trunk/source/Core/Broadcaster.cpp Message-ID: <20110123212020.5115F2A6C12C@llvm.org> Author: jingham Date: Sun Jan 23 15:20:20 2011 New Revision: 124086 URL: http://llvm.org/viewvc/llvm-project?rev=124086&view=rev Log: A little less noise, please. Modified: lldb/trunk/source/Core/Broadcaster.cpp Modified: lldb/trunk/source/Core/Broadcaster.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Core/Broadcaster.cpp?rev=124086&r1=124085&r2=124086&view=diff ============================================================================== --- lldb/trunk/source/Core/Broadcaster.cpp (original) +++ lldb/trunk/source/Core/Broadcaster.cpp Sun Jan 23 15:20:20 2011 @@ -214,7 +214,7 @@ const uint32_t event_type = event_sp->GetType(); Mutex::Locker event_types_locker(m_listeners_mutex); - LogSP log(lldb_private::GetLogIfAnyCategoriesSet (LIBLLDB_LOG_EVENTS | LIBLLDB_LOG_PROCESS)); + LogSP log(lldb_private::GetLogIfAnyCategoriesSet (LIBLLDB_LOG_EVENTS)); if (log) { StreamString event_description; @@ -229,6 +229,11 @@ if (m_hijacking_listener != NULL && m_hijacking_mask & event_type) { + // FIXME: REMOVE THIS EXTRA LOGGING + LogSP log_process(lldb_private::GetLogIfAnyCategoriesSet (LIBLLDB_LOG_PROCESS)); + if (log_process) + log_process->Printf ("Hijacking event delivery for Broadcaster(\"%s\").", m_broadcaster_name.AsCString("")); + if (unique && m_hijacking_listener->PeekAtNextEventForBroadcasterWithType (this, event_type)) return; m_hijacking_listener->AddEvent (event_sp); From jingham at apple.com Sun Jan 23 21:46:59 2011 From: jingham at apple.com (Jim Ingham) Date: Mon, 24 Jan 2011 03:46:59 -0000 Subject: [Lldb-commits] [lldb] r124103 - /lldb/trunk/tools/debugserver/source/debugserver.cpp Message-ID: <20110124034659.646E82A6C12D@llvm.org> Author: jingham Date: Sun Jan 23 21:46:59 2011 New Revision: 124103 URL: http://llvm.org/viewvc/llvm-project?rev=124103&view=rev Log: Linebuffer the log file. Modified: lldb/trunk/tools/debugserver/source/debugserver.cpp Modified: lldb/trunk/tools/debugserver/source/debugserver.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/tools/debugserver/source/debugserver.cpp?rev=124103&r1=124102&r2=124103&view=diff ============================================================================== --- lldb/trunk/tools/debugserver/source/debugserver.cpp (original) +++ lldb/trunk/tools/debugserver/source/debugserver.cpp Sun Jan 23 21:46:59 2011 @@ -826,8 +826,12 @@ else if (strcasecmp(optarg, "stderr") == 0) log_file = stderr; else + { log_file = fopen(optarg, "w"); - + if (log_file != NULL) + setlinebuf(log_file); + } + if (log_file == NULL) { const char *errno_str = strerror(errno); From jingham at apple.com Sun Jan 23 22:09:26 2011 From: jingham at apple.com (Jim Ingham) Date: Mon, 24 Jan 2011 04:09:26 -0000 Subject: [Lldb-commits] [lldb] r124107 - in /lldb/trunk: include/lldb/Core/StreamFile.h source/Commands/CommandObjectLog.cpp source/Core/StreamFile.cpp Message-ID: <20110124040926.2212C2A6C12C@llvm.org> Author: jingham Date: Sun Jan 23 22:09:25 2011 New Revision: 124107 URL: http://llvm.org/viewvc/llvm-project?rev=124107&view=rev Log: Add a method to StreamFile to line buffer the file. Use that in "log enable -f file" to line buffer the log output. Modified: lldb/trunk/include/lldb/Core/StreamFile.h lldb/trunk/source/Commands/CommandObjectLog.cpp lldb/trunk/source/Core/StreamFile.cpp Modified: lldb/trunk/include/lldb/Core/StreamFile.h URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Core/StreamFile.h?rev=124107&r1=124106&r2=124107&view=diff ============================================================================== --- lldb/trunk/include/lldb/Core/StreamFile.h (original) +++ lldb/trunk/include/lldb/Core/StreamFile.h Sun Jan 23 22:09:25 2011 @@ -61,6 +61,9 @@ const char * GetFilePathname (); + + void + SetLineBuffered(); protected: //------------------------------------------------------------------ Modified: lldb/trunk/source/Commands/CommandObjectLog.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Commands/CommandObjectLog.cpp?rev=124107&r1=124106&r2=124107&view=diff ============================================================================== --- lldb/trunk/source/Commands/CommandObjectLog.cpp (original) +++ lldb/trunk/source/Commands/CommandObjectLog.cpp Sun Jan 23 22:09:25 2011 @@ -113,23 +113,30 @@ std::string channel(args.GetArgumentAtIndex(0)); args.Shift (); // Shift off the channel StreamSP log_stream_sp; - + StreamFile *log_file_ptr = NULL; // This will get put in the log_stream_sp, no need to free it. if (m_options.log_file.empty()) { - log_stream_sp.reset(new StreamFile(m_interpreter.GetDebugger().GetOutputFileHandle())); + log_file_ptr = new StreamFile(m_interpreter.GetDebugger().GetOutputFileHandle()); + log_stream_sp.reset(log_file_ptr); } else { LogStreamMap::iterator pos = m_log_streams.find(m_options.log_file); if (pos == m_log_streams.end()) { - log_stream_sp.reset (new StreamFile (m_options.log_file.c_str(), "w")); + log_file_ptr = new StreamFile (m_options.log_file.c_str(), "w"); + log_stream_sp.reset (log_file_ptr); m_log_streams[m_options.log_file] = log_stream_sp; } else log_stream_sp = pos->second; } assert (log_stream_sp.get()); + + // If we ended up making a StreamFile for log output, line buffer it. + if (log_file_ptr != NULL) + log_file_ptr->SetLineBuffered(); + uint32_t log_options = m_options.log_options; if (log_options == 0) log_options = LLDB_LOG_OPTION_PREPEND_THREAD_NAME | LLDB_LOG_OPTION_THREADSAFE; Modified: lldb/trunk/source/Core/StreamFile.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Core/StreamFile.cpp?rev=124107&r1=124106&r2=124107&view=diff ============================================================================== --- lldb/trunk/source/Core/StreamFile.cpp (original) +++ lldb/trunk/source/Core/StreamFile.cpp Sun Jan 23 22:09:25 2011 @@ -95,6 +95,13 @@ } void +StreamFile::SetLineBuffered () +{ + if (m_file != NULL) + setlinebuf (m_file); +} + +void StreamFile::Flush () { if (m_file) From jingham at apple.com Sun Jan 23 22:11:25 2011 From: jingham at apple.com (Jim Ingham) Date: Mon, 24 Jan 2011 04:11:25 -0000 Subject: [Lldb-commits] [lldb] r124108 - /lldb/trunk/source/Target/ThreadList.cpp Message-ID: <20110124041125.544BF2A6C12C@llvm.org> Author: jingham Date: Sun Jan 23 22:11:25 2011 New Revision: 124108 URL: http://llvm.org/viewvc/llvm-project?rev=124108&view=rev Log: Some useful logging. Also don't stuff the temporary thread into a shared pointer for no apparent reason. Modified: lldb/trunk/source/Target/ThreadList.cpp Modified: lldb/trunk/source/Target/ThreadList.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Target/ThreadList.cpp?rev=124108&r1=124107&r2=124108&view=diff ============================================================================== --- lldb/trunk/source/Target/ThreadList.cpp (original) +++ lldb/trunk/source/Target/ThreadList.cpp Sun Jan 23 22:11:25 2011 @@ -316,22 +316,27 @@ // Run through the threads and ask whether we should report this event. // The rule is NO vote wins over everything, a YES vote wins over no opinion. + LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_STEP)); + for (pos = m_threads.begin(); pos != end; ++pos) { - ThreadSP thread_sp(*pos); - if (thread_sp->GetResumeState () != eStateSuspended) - - switch (thread_sp->ShouldReportRun (event_ptr)) + if ((*pos)->GetResumeState () != eStateSuspended) { - case eVoteNoOpinion: - continue; - case eVoteYes: - if (result == eVoteNoOpinion) - result = eVoteYes; - break; - case eVoteNo: - result = eVoteNo; - break; + switch ((*pos)->ShouldReportRun (event_ptr)) + { + case eVoteNoOpinion: + continue; + case eVoteYes: + if (result == eVoteNoOpinion) + result = eVoteYes; + break; + case eVoteNo: + log->Printf ("ThreadList::ShouldReportRun() thread %d (0x%4.4x) says don't report.", + (*pos)->GetIndexID(), + (*pos)->GetID()); + result = eVoteNo; + break; + } } } return result; From gclayton at apple.com Sun Jan 23 23:36:47 2011 From: gclayton at apple.com (Greg Clayton) Date: Mon, 24 Jan 2011 05:36:47 -0000 Subject: [Lldb-commits] [lldb] r124109 - /lldb/trunk/source/Target/ThreadList.cpp Message-ID: <20110124053647.3E6DC2A6C12C@llvm.org> Author: gclayton Date: Sun Jan 23 23:36:47 2011 New Revision: 124109 URL: http://llvm.org/viewvc/llvm-project?rev=124109&view=rev Log: Fix a crasher when you have no log. Modified: lldb/trunk/source/Target/ThreadList.cpp Modified: lldb/trunk/source/Target/ThreadList.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Target/ThreadList.cpp?rev=124109&r1=124108&r2=124109&view=diff ============================================================================== --- lldb/trunk/source/Target/ThreadList.cpp (original) +++ lldb/trunk/source/Target/ThreadList.cpp Sun Jan 23 23:36:47 2011 @@ -331,9 +331,10 @@ result = eVoteYes; break; case eVoteNo: - log->Printf ("ThreadList::ShouldReportRun() thread %d (0x%4.4x) says don't report.", - (*pos)->GetIndexID(), - (*pos)->GetID()); + if (log) + log->Printf ("ThreadList::ShouldReportRun() thread %d (0x%4.4x) says don't report.", + (*pos)->GetIndexID(), + (*pos)->GetID()); result = eVoteNo; break; }