> 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 <[email protected]> wrote: > Author: tfiala > Date: Fri Sep 12 17:51:49 2014 > New Revision: 217717 > > URL: http://llvm.org/viewvc/llvm-project?rev=217717&view=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=217717&r1=217716&r2=217717&view=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=217717&r1=217716&r2=217717&view=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=217717&r1=217716&r2=217717&view=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=217717&r1=217716&r2=217717&view=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=217717&r1=217716&r2=217717&view=diff > > ============================================================================== > --- lldb/trunk/test/tools/lldb-gdbserver/TestGdbRemote_qThreadStopInfo.py > (original) > +++ lldb/trunk/test/tools/lldb-gdbserver/TestGdbRemote_qThreadStopInfo.py > Fri Sep 12 17:51:49 2014 > @@ -1,3 +1,4 @@ > +import sys > import unittest2 > > import gdbremote_testcase > @@ -40,6 +41,7 @@ class TestGdbRemote_qThreadStopInfo(gdbr > > # Grab stop reply for each thread via qThreadStopInfo{tid:hex}. > stop_replies = {} > + thread_dicts = {} > for thread in threads: > # Run the qThreadStopInfo command. > self.reset_test_sequence() > @@ -67,10 +69,13 @@ class TestGdbRemote_qThreadStopInfo(gdbr > self.assertIsNotNone(stop_result_text) > stop_replies[kv_thread_id] = int(stop_result_text, 16) > > - return stop_replies > + # Hang on to the key-val dictionary for the thread. > + thread_dicts[kv_thread_id] = kv_dict > + > + return (stop_replies, thread_dicts) > > def qThreadStopInfo_works_for_multiple_threads(self, thread_count): > - stop_replies = > self.gather_stop_replies_via_qThreadStopInfo(thread_count) > + (stop_replies, _) = > self.gather_stop_replies_via_qThreadStopInfo(thread_count) > self.assertEquals(len(stop_replies), thread_count) > > @debugserver_test > @@ -90,7 +95,7 @@ class TestGdbRemote_qThreadStopInfo(gdbr > self.qThreadStopInfo_works_for_multiple_threads(self.THREAD_COUNT) > > def > qThreadStopInfo_only_reports_one_thread_stop_reason_during_interrupt(self, > thread_count): > - stop_replies = > self.gather_stop_replies_via_qThreadStopInfo(thread_count) > + (stop_replies, _) = > self.gather_stop_replies_via_qThreadStopInfo(thread_count) > self.assertIsNotNone(stop_replies) > > no_stop_reason_count = sum(1 for stop_reason in > stop_replies.values() if stop_reason == 0) > @@ -118,6 +123,33 @@ class TestGdbRemote_qThreadStopInfo(gdbr > self.set_inferior_startup_launch() > > > self.qThreadStopInfo_only_reports_one_thread_stop_reason_during_interrupt(self.THREAD_COUNT) > > + def qThreadStopInfo_has_valid_thread_names(self, thread_count, > expected_thread_name): > + (_, thread_dicts) = > self.gather_stop_replies_via_qThreadStopInfo(thread_count) > + self.assertIsNotNone(thread_dicts) > + > + for thread_dict in thread_dicts.values(): > + name = thread_dict.get("name") > + self.assertIsNotNone(name) > + self.assertEquals(name, expected_thread_name) > + > + @unittest2.skip("MacOSX doesn't have a default thread name") > + @debugserver_test > + @dsym_test > + def > test_qThreadStopInfo_has_valid_thread_names_debugserver_dsym(self): > + self.init_debugserver_test() > + self.buildDsym() > + self.set_inferior_startup_launch() > + self.qThreadStopInfo_has_valid_thread_names(self.THREAD_COUNT, > "a.out") > + > + @unittest2.skipUnless(sys.platform.startswith("linux"), "test > requires OS with set, equal thread names by default") > + @llgs_test > + @dwarf_test > + def test_qThreadStopInfo_has_valid_thread_names_llgs_dwarf(self): > + self.init_llgs_test() > + self.buildDwarf() > + self.set_inferior_startup_launch() > + self.qThreadStopInfo_has_valid_thread_names(self.THREAD_COUNT, > "a.out") > + > > if __name__ == '__main__': > unittest2.main() > > > _______________________________________________ > lldb-commits mailing list > [email protected] > http://lists.cs.uiuc.edu/mailman/listinfo/lldb-commits > -- Todd Fiala | Software Engineer | [email protected] | 650-943-3180
_______________________________________________ lldb-commits mailing list [email protected] http://lists.cs.uiuc.edu/mailman/listinfo/lldb-commits
