[lldb-dev] PATCH for REVIEW: Implement Host::SetThreadName on Linux

Michael Sartain mikesart at valvesoftware.com
Mon May 13 09:41:35 PDT 2013


On Fri, May 10, 2013 at 5:30 PM, Mike Sartain <mikesart at valvesoftware.com>wrote:

> On Fri, May 10, 2013 at 1:41 PM, Kopec, Matt <matt.kopec at intel.com> wrote:
>
> > Some comments about the patch...
> >
> > > +#elif defined (__linux__)
> > > +    void *fn = dlsym (RTLD_DEFAULT, "pthread_setname_np");
> > > +    if (fn)
> > > +    {
> >
> > I believe this pthread function can be added by including pthread.h for
> Linux. That way you don't need dlsym and can just re-use most of the code
> that is already there for apple.
>
> pthread_setname_np was added in glibc v2.12, so anything running less than
> that would run into issues if we called it directly. As an example on the
> Ubuntu side, I believe 10.04 LTS shipped with 2.11.1. What are your
> thoughts / requirements for minspecs like this?
>

...


> > > +        const char *lastdot = ::strrchr( thread_name, '.' );
> > > +
> > > +        if (lastdot && lastdot != thread_name)
> > > +            thread_name = lastdot + 1;
> > > +        ::strncpy (namebuf, thread_name, sizeof(namebuf));
> > > +        namebuf[ sizeof(namebuf) - 1 ] = 0;
> > > +
> > > +        int namebuflen = strlen(namebuf);
> >
> > It would have been nice to use std::string and its' facilities. It would
> make this easier to write and understand but what you have is fine.
>

I just wrote this up with std::string, but since Host::ThreadCreated()
takes a regular C string, converting that to a std::string does a memory
allocation. I personally would prefer the above code to it being more
optimal, but that may also just be me not finding it more difficult to
understand than the std::string.

I'll code to whatever the project guidelines are though, so when you get a
chance, let me know what folks on this project prefer and how to proceed
with the glibc v2.12 issue and I'll resubmit all this.

Thanks much.
 -Mike
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/lldb-dev/attachments/20130513/69a0b58a/attachment.html>


More information about the lldb-dev mailing list