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

Mike Sartain mikesart at valvesoftware.com
Fri May 10 17:30:01 PDT 2013


On Fri, May 10, 2013 at 1:41 PM, Kopec, Matt <matt.kopec at intel.com> wrote:

> Thanks for contributing the patch! This will help many of us in debugging lldb. Good to know there are other Linux lldb developers out there. :)

Thanks Matt. We're doing a lot of debugging on Linux and I'm hoping to do whatever I can to make lldb a much better debugger than gdb / cgdb - what most of use are currently using. I'm just now starting to get in the code and poke around and see what's there. If you have any suggestions on where I could help and not duplicate work, please fire away.

> 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'll switch this over to using std::string on Monday and resubmit. Would have done it today but I just got back from a Pioneer Farms fieldtrip. Whee! :)

Thanks for the reply. Have a great weekend.
 -Mike




More information about the lldb-dev mailing list