summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTodd Fiala <todd.fiala@gmail.com>2014-09-12 22:51:49 +0000
committerTodd Fiala <todd.fiala@gmail.com>2014-09-12 22:51:49 +0000
commit7206c6d11fa4cb5fd44aa680106cb37ce85d9e3b (patch)
tree50ad47af318c189b3652bfb0649fd43216e6193e
parent8a0c9e624764b705791b26ed98f66034b9896cef (diff)
downloadbcm5719-llvm-7206c6d11fa4cb5fd44aa680106cb37ce85d9e3b.tar.gz
bcm5719-llvm-7206c6d11fa4cb5fd44aa680106cb37ce85d9e3b.zip
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
-rw-r--r--lldb/source/Host/common/NativeThreadProtocol.h2
-rw-r--r--lldb/source/Plugins/Process/Linux/NativeThreadLinux.cpp2
-rw-r--r--lldb/source/Plugins/Process/Linux/NativeThreadLinux.h2
-rw-r--r--lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServer.cpp12
-rw-r--r--lldb/test/tools/lldb-gdbserver/TestGdbRemote_qThreadStopInfo.py38
5 files changed, 44 insertions, 12 deletions
diff --git a/lldb/source/Host/common/NativeThreadProtocol.h b/lldb/source/Host/common/NativeThreadProtocol.h
index 9b404be500b..15ecffe8b82 100644
--- a/lldb/source/Host/common/NativeThreadProtocol.h
+++ b/lldb/source/Host/common/NativeThreadProtocol.h
@@ -31,7 +31,7 @@ namespace lldb_private
{
}
- virtual const char *
+ virtual std::string
GetName() = 0;
virtual lldb::StateType
diff --git a/lldb/source/Plugins/Process/Linux/NativeThreadLinux.cpp b/lldb/source/Plugins/Process/Linux/NativeThreadLinux.cpp
index 4158e3d1e14..f362477d923 100644
--- a/lldb/source/Plugins/Process/Linux/NativeThreadLinux.cpp
+++ b/lldb/source/Plugins/Process/Linux/NativeThreadLinux.cpp
@@ -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 ();
diff --git a/lldb/source/Plugins/Process/Linux/NativeThreadLinux.h b/lldb/source/Plugins/Process/Linux/NativeThreadLinux.h
index 8a042f22b22..2effd849006 100644
--- a/lldb/source/Plugins/Process/Linux/NativeThreadLinux.h
+++ b/lldb/source/Plugins/Process/Linux/NativeThreadLinux.h
@@ -27,7 +27,7 @@ namespace lldb_private
// ---------------------------------------------------------------------
// NativeThreadProtocol Interface
// ---------------------------------------------------------------------
- const char *
+ std::string
GetName() override;
lldb::StateType
diff --git a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServer.cpp b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServer.cpp
index e3aadf1bc25..11658fe0a87 100644
--- a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServer.cpp
+++ b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServer.cpp
@@ -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 (';');
}
diff --git a/lldb/test/tools/lldb-gdbserver/TestGdbRemote_qThreadStopInfo.py b/lldb/test/tools/lldb-gdbserver/TestGdbRemote_qThreadStopInfo.py
index 2eaa710651f..1d8147a0695 100644
--- a/lldb/test/tools/lldb-gdbserver/TestGdbRemote_qThreadStopInfo.py
+++ b/lldb/test/tools/lldb-gdbserver/TestGdbRemote_qThreadStopInfo.py
@@ -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()
OpenPOWER on IntegriCloud