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.

llvm-svn: 217717
This commit is contained in:
Todd Fiala 2014-09-12 22:51:49 +00:00
parent 8a0c9e6247
commit 7206c6d11f
5 changed files with 44 additions and 12 deletions

View File

@ -31,7 +31,7 @@ namespace lldb_private
{
}
virtual const char *
virtual std::string
GetName() = 0;
virtual lldb::StateType

View File

@ -61,7 +61,7 @@ NativeThreadLinux::NativeThreadLinux (NativeProcessLinux *process, lldb::tid_t t
{
}
const char *
std::string
NativeThreadLinux::GetName()
{
NativeProcessProtocolSP process_sp = m_process_wp.lock ();

View File

@ -27,7 +27,7 @@ namespace lldb_private
// ---------------------------------------------------------------------
// NativeThreadProtocol Interface
// ---------------------------------------------------------------------
const char *
std::string
GetName() override;
lldb::StateType

View File

@ -871,21 +871,21 @@ GDBRemoteCommunicationServer::SendStopReplyPacketForThread (lldb::tid_t tid)
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 (';');
}

View File

@ -1,3 +1,4 @@
import sys
import unittest2
import gdbremote_testcase
@ -40,6 +41,7 @@ class TestGdbRemote_qThreadStopInfo(gdbremote_testcase.GdbRemoteTestCaseBase):
# 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(gdbremote_testcase.GdbRemoteTestCaseBase):
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(gdbremote_testcase.GdbRemoteTestCaseBase):
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(gdbremote_testcase.GdbRemoteTestCaseBase):
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()