[Lldb-commits] [PATCH] Add Host::GetMaxThreadNameLength(), modify private state thread name
Todd Fiala
todd.fiala at gmail.com
Wed Jul 16 10:09:33 PDT 2014
Please find attached an adjusted patch. It uses a const static member
variable initialized properly in place of a function call.
Tested:
Linux Ubuntu 14.04 x86_64, clang-3.5-built lldb, all tests pass.
MacOSX 10.9.4, Xcode 6.0 Beta 3-built lldb, all tests pass.
On Sat, Jul 12, 2014 at 3:21 PM, Todd Fiala <tfiala at google.com> wrote:
> Well, we can keep it simple until proven needed to be more complex :-)
> I'll switch it to a constant and re-send.
>
>
> On Saturday, July 12, 2014, Ed Maste <emaste at freebsd.org> wrote:
>
>> On 11 July 2014 11:56, Todd Fiala <todd.fiala at gmail.com> wrote:
>> > My take was it depends on host details. For example, I didn't track
>> down
>> > the Windows way of getting this data, but I wouldn't be surprised if it
>> > turned into a method call to the system (which could be cached, but
>> that's
>> > an impl detail that a method call would allow us to hide).
>> >
>> > I thought it made it more flexible on unknown details for current/future
>> > platforms to have it be a function call.
>>
>> Fair enough, and it's not a big deal - I just assume it will in
>> general be a (possibly empirically determined) constant.
>>
>> I did a little digging and couldn't find a limit for Windows. I did
>> discover the convoluted method used to set the thread name though:
>> http://msdn.microsoft.com/en-us/library/xcb2z8hs.aspx
>> _______________________________________________
>> lldb-commits mailing list
>> lldb-commits at cs.uiuc.edu
>> http://lists.cs.uiuc.edu/mailman/listinfo/lldb-commits
>>
>
>
> --
> Todd Fiala | Software Engineer | tfiala at google.com | 650-943-3180
>
>
--
-Todd
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/lldb-commits/attachments/20140716/737da8ae/attachment.html>
-------------- next part --------------
Index: include/lldb/Host/Host.h
===================================================================
--- include/lldb/Host/Host.h (revision 213170)
+++ include/lldb/Host/Host.h (working copy)
@@ -32,6 +32,10 @@
class Host
{
public:
+
+ /// A value of std::numeric_limits<uint32_t>::max() is used if there is no practical limit.
+ static const uint32_t MAX_THREAD_NAME_LENGTH;
+
typedef bool (*MonitorChildProcessCallback) (void *callback_baton,
lldb::pid_t pid,
bool exited,
Index: source/Host/common/Host.cpp
===================================================================
--- source/Host/common/Host.cpp (revision 213170)
+++ source/Host/common/Host.cpp (working copy)
@@ -49,6 +49,9 @@
#include <pthread_np.h>
#endif
+// C++ includes
+#include <limits>
+
#include "lldb/Host/Host.h"
#include "lldb/Core/ArchSpec.h"
#include "lldb/Core/ConstString.h"
@@ -87,6 +90,12 @@
using namespace lldb;
using namespace lldb_private;
+// Define maximum thread name length
+#if defined (__linux__) || defined (__FreeBSD__) || defined (__FreeBSD_kernel__) || defined (__NetBSD__)
+uint32_t const Host::MAX_THREAD_NAME_LENGTH = 16;
+#else
+uint32_t const Host::MAX_THREAD_NAME_LENGTH = std::numeric_limits<uint32_t>::max ();
+#endif
#if !defined (__APPLE__) && !defined (_WIN32)
struct MonitorInfo
Index: source/Target/Process.cpp
===================================================================
--- source/Target/Process.cpp (revision 213170)
+++ source/Target/Process.cpp (working copy)
@@ -3657,11 +3657,23 @@
// Create a thread that watches our internal state and controls which
// events make it to clients (into the DCProcess event queue).
char thread_name[1024];
- if (already_running)
- snprintf(thread_name, sizeof(thread_name), "<lldb.process.internal-state-override(pid=%" PRIu64 ")>", GetID());
+
+ if (Host::MAX_THREAD_NAME_LENGTH <= 16)
+ {
+ // On platforms with abbreviated thread name lengths, choose thread names that fit within the limit.
+ if (already_running)
+ snprintf(thread_name, sizeof(thread_name), "intern-state-OV");
+ else
+ snprintf(thread_name, sizeof(thread_name), "intern-state");
+ }
else
- snprintf(thread_name, sizeof(thread_name), "<lldb.process.internal-state(pid=%" PRIu64 ")>", GetID());
-
+ {
+ if (already_running)
+ snprintf(thread_name, sizeof(thread_name), "<lldb.process.internal-state-override(pid=%" PRIu64 ")>", GetID());
+ else
+ snprintf(thread_name, sizeof(thread_name), "<lldb.process.internal-state(pid=%" PRIu64 ")>", GetID());
+ }
+
// Create the private state thread, and start it running.
m_private_state_thread = Host::ThreadCreate (thread_name, Process::PrivateStateThread, this, NULL);
bool success = IS_VALID_LLDB_HOST_THREAD(m_private_state_thread);
More information about the lldb-commits
mailing list