Re: [Lldb-commits] [lldb] r217717 - llgs: fix thread names broken by recent native thread changes.
llgs: fix thread names broken by recent native thread changes. That's not quite accurate. The usage of a stack variable pointer after it went out of scope was there before - the issue just didn't surface until the code was shuffled. A better title would have been: llgs: fix Linux thread name bug surfaced by recent native thread changes -Todd On Fri, Sep 12, 2014 at 3:51 PM, Todd Fiala todd.fi...@gmail.com wrote: Author: tfiala Date: Fri Sep 12 17:51:49 2014 New Revision: 217717 URL: http://llvm.org/viewvc/llvm-project?rev=217717view=rev Log: llgs: fix thread names broken by recent native thread changes. * Fixes the local stack variable return pointer usage in NativeThreadLinux::GetName(). * Changes NativeThreadProtocol::GetName() to return a std::string. * Adds a unit test to verify thread names don't regress in the future. Currently only run on Linux since I know default thread names there. Modified: lldb/trunk/source/Host/common/NativeThreadProtocol.h lldb/trunk/source/Plugins/Process/Linux/NativeThreadLinux.cpp lldb/trunk/source/Plugins/Process/Linux/NativeThreadLinux.h lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServer.cpp lldb/trunk/test/tools/lldb-gdbserver/TestGdbRemote_qThreadStopInfo.py Modified: lldb/trunk/source/Host/common/NativeThreadProtocol.h URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Host/common/NativeThreadProtocol.h?rev=217717r1=217716r2=217717view=diff == --- lldb/trunk/source/Host/common/NativeThreadProtocol.h (original) +++ lldb/trunk/source/Host/common/NativeThreadProtocol.h Fri Sep 12 17:51:49 2014 @@ -31,7 +31,7 @@ namespace lldb_private { } -virtual const char * +virtual std::string GetName() = 0; virtual lldb::StateType Modified: lldb/trunk/source/Plugins/Process/Linux/NativeThreadLinux.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Process/Linux/NativeThreadLinux.cpp?rev=217717r1=217716r2=217717view=diff == --- lldb/trunk/source/Plugins/Process/Linux/NativeThreadLinux.cpp (original) +++ lldb/trunk/source/Plugins/Process/Linux/NativeThreadLinux.cpp Fri Sep 12 17:51:49 2014 @@ -61,7 +61,7 @@ NativeThreadLinux::NativeThreadLinux (Na { } -const char * +std::string NativeThreadLinux::GetName() { NativeProcessProtocolSP process_sp = m_process_wp.lock (); Modified: lldb/trunk/source/Plugins/Process/Linux/NativeThreadLinux.h URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Process/Linux/NativeThreadLinux.h?rev=217717r1=217716r2=217717view=diff == --- lldb/trunk/source/Plugins/Process/Linux/NativeThreadLinux.h (original) +++ lldb/trunk/source/Plugins/Process/Linux/NativeThreadLinux.h Fri Sep 12 17:51:49 2014 @@ -27,7 +27,7 @@ namespace lldb_private // - // NativeThreadProtocol Interface // - -const char * +std::string GetName() override; lldb::StateType Modified: lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServer.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServer.cpp?rev=217717r1=217716r2=217717view=diff == --- lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServer.cpp (original) +++ lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServer.cpp Fri Sep 12 17:51:49 2014 @@ -871,21 +871,21 @@ GDBRemoteCommunicationServer::SendStopRe response.Printf (thread:% PRIx64 ;, tid); // Include the thread name if there is one. -const char *thread_name = thread_sp-GetName (); -if (thread_name thread_name[0]) +const std::string thread_name = thread_sp-GetName (); +if (!thread_name.empty ()) { -size_t thread_name_len = strlen(thread_name); +size_t thread_name_len = thread_name.length (); -if (::strcspn (thread_name, $#+-;:) == thread_name_len) +if (::strcspn (thread_name.c_str (), $#+-;:) == thread_name_len) { response.PutCString (name:); -response.PutCString (thread_name); +response.PutCString (thread_name.c_str ()); } else { // The thread name contains special chars, send as hex bytes. response.PutCString (hexname:); -response.PutCStringAsRawHex8 (thread_name); +response.PutCStringAsRawHex8 (thread_name.c_str ()); }
[Lldb-commits] [lldb] r217717 - llgs: fix thread names broken by recent native thread changes.
Author: tfiala Date: Fri Sep 12 17:51:49 2014 New Revision: 217717 URL: http://llvm.org/viewvc/llvm-project?rev=217717view=rev Log: llgs: fix thread names broken by recent native thread changes. * Fixes the local stack variable return pointer usage in NativeThreadLinux::GetName(). * Changes NativeThreadProtocol::GetName() to return a std::string. * Adds a unit test to verify thread names don't regress in the future. Currently only run on Linux since I know default thread names there. Modified: lldb/trunk/source/Host/common/NativeThreadProtocol.h lldb/trunk/source/Plugins/Process/Linux/NativeThreadLinux.cpp lldb/trunk/source/Plugins/Process/Linux/NativeThreadLinux.h lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServer.cpp lldb/trunk/test/tools/lldb-gdbserver/TestGdbRemote_qThreadStopInfo.py Modified: lldb/trunk/source/Host/common/NativeThreadProtocol.h URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Host/common/NativeThreadProtocol.h?rev=217717r1=217716r2=217717view=diff == --- lldb/trunk/source/Host/common/NativeThreadProtocol.h (original) +++ lldb/trunk/source/Host/common/NativeThreadProtocol.h Fri Sep 12 17:51:49 2014 @@ -31,7 +31,7 @@ namespace lldb_private { } -virtual const char * +virtual std::string GetName() = 0; virtual lldb::StateType Modified: lldb/trunk/source/Plugins/Process/Linux/NativeThreadLinux.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Process/Linux/NativeThreadLinux.cpp?rev=217717r1=217716r2=217717view=diff == --- lldb/trunk/source/Plugins/Process/Linux/NativeThreadLinux.cpp (original) +++ lldb/trunk/source/Plugins/Process/Linux/NativeThreadLinux.cpp Fri Sep 12 17:51:49 2014 @@ -61,7 +61,7 @@ NativeThreadLinux::NativeThreadLinux (Na { } -const char * +std::string NativeThreadLinux::GetName() { NativeProcessProtocolSP process_sp = m_process_wp.lock (); Modified: lldb/trunk/source/Plugins/Process/Linux/NativeThreadLinux.h URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Process/Linux/NativeThreadLinux.h?rev=217717r1=217716r2=217717view=diff == --- lldb/trunk/source/Plugins/Process/Linux/NativeThreadLinux.h (original) +++ lldb/trunk/source/Plugins/Process/Linux/NativeThreadLinux.h Fri Sep 12 17:51:49 2014 @@ -27,7 +27,7 @@ namespace lldb_private // - // NativeThreadProtocol Interface // - -const char * +std::string GetName() override; lldb::StateType Modified: lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServer.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServer.cpp?rev=217717r1=217716r2=217717view=diff == --- lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServer.cpp (original) +++ lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServer.cpp Fri Sep 12 17:51:49 2014 @@ -871,21 +871,21 @@ GDBRemoteCommunicationServer::SendStopRe response.Printf (thread:% PRIx64 ;, tid); // Include the thread name if there is one. -const char *thread_name = thread_sp-GetName (); -if (thread_name thread_name[0]) +const std::string thread_name = thread_sp-GetName (); +if (!thread_name.empty ()) { -size_t thread_name_len = strlen(thread_name); +size_t thread_name_len = thread_name.length (); -if (::strcspn (thread_name, $#+-;:) == thread_name_len) +if (::strcspn (thread_name.c_str (), $#+-;:) == thread_name_len) { response.PutCString (name:); -response.PutCString (thread_name); +response.PutCString (thread_name.c_str ()); } else { // The thread name contains special chars, send as hex bytes. response.PutCString (hexname:); -response.PutCStringAsRawHex8 (thread_name); +response.PutCStringAsRawHex8 (thread_name.c_str ()); } response.PutChar (';'); } Modified: lldb/trunk/test/tools/lldb-gdbserver/TestGdbRemote_qThreadStopInfo.py URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/tools/lldb-gdbserver/TestGdbRemote_qThreadStopInfo.py?rev=217717r1=217716r2=217717view=diff == --- lldb/trunk/test/tools/lldb-gdbserver/TestGdbRemote_qThreadStopInfo.py (original) +++