thread list format

I’ve seen this asked by Ed before, but hadn’t seen it answered: Is there a reason for the single single quote in the default thread-format?

(lldb) thread list

Process 29603 stopped

  • thread #1: tid = 29603, 0x000000000040113f blahmain(argc=1, argv=0x00007fff71d34f18) + 495 at blah.cpp:71, name = 'mainthrd, stop reason = breakpoint 2.1 thread #2: tid = 29766, 0x00007f282ba7084d libc.so.6__nanosleep + 45 at syscall-template.S:82, name = 'thread_0
    thread #3: tid = 29767, 0x00007f282ba7084d libc.so.6`__nanosleep + 45 at syscall-template.S:82, name = 'thread_1

It’s defined here in Debugger.cpp:

102 #define DEFAULT_THREAD_FORMAT “thread #${thread.index}: tid = ${thread.id}”
103 “{, ${frame.pc}}”
104 MODULE_WITH_FUNC
105 FILE_AND_LINE
106 “{, name = '${thread.name}}”
107 “{, queue = '${thread.queue}}”
108 “{, stop reason = ${thread.stop-reason}}”
109 “{\nReturn value: ${thread.return-value}}”
110 “\n”

(lldb) settings show thread-format
thread-format (string) = “thread #${thread.index}: tid = ${thread.id}{, ${frame.pc}}{ ${module.file.basename}{`${function.name-with-args}${function.pc-offset}}}{ at ${line.file.basename}:${line.number}}{, name = '${thread.name}}{, queue = '${thread.queue}}{, stop reason = ${thread.stop-reason}}{\nReturn value: ${thread.return-value}}\n”

I’m assuming this isn’t deliberate and we can add the missing quote? Hopefully? :slight_smile:

Thanks!

-Mike

The thread name missing end quote is just an error and should be fixed. Looks like one is missing for the thread queue as well.

Greg

Also, It looks like you've switched the tids to decimal here, which
we'll want to do also on FreeBSD. My guess is that on Darwin it's
desired to keep displaying them in hex; can we do a target-specific
tid formatter?

Also, It looks like you've switched the tids to decimal here, which
we'll want to do also on FreeBSD. My guess is that on Darwin it's
desired to keep displaying them in hex; can we do a target-specific
tid formatter?

This is part of a patch I'm working on right now. It's only partly done so
far (to get feedback from Matt), but here it is:

http://llvm-reviews.chandlerc.com/D1189

I'll add the ability to have a target specific formatter and default it to
be decimal for FreeBSD and Linux.

One of Matt's comments:

I was thinking we could create a new class LinuxThread which would inherit

from POSIXThread and we implement Linux specific behavior in that class.
There is a similar parallel with the ProcessPOSIX and ProcessLinux classes.
Doing this would save us from Linux ifdefs. Although one would still be
needed to create to the instances of LinuxThread from the ProcessPOSIX
class.
In this particular case, we could implement our own RefreshStateAfterStop
in LinuxThread to invalidate the thread name and then call the POSIXThread
version of RefreshStateAfterStop.
We'll probably start running into some more Linux specific behavior anyway
and FreeBSD support is ramping up as well.

If you have any comments / suggestions on this, I'd love to hear em also...

Thanks Ed.

-Mike

Here is a patch that defaults thread ids to decimal for freebsd + linux,
and also adds the ability to add print specifiers to process.id, thread.id,
thread.protocol.id, thread.index, and line.number. Something like this:

            // Allow format specifiers: x|X|u with optional width
specifiers.
            // {thread.id%x} ; hex
            // {thread.id%X} ; uppercase hex
            // {thread.id%u} ; unsigned decimal
            // {thread.id%8.8X} ; width.precision + specifier

http://llvm-reviews.chandlerc.com/D1234

Please holler with any feedback. Thanks,
-Mike

Overall it looks fine to me. I think we'd ideally have a run-time
default, so that if you e.g. debug a Linux core on OS X you get
decimal TIDs, but that could be done later if it's awkward.

>
> Here is a patch that defaults thread ids to decimal for freebsd + linux,
and
> also adds the ability to add print specifiers to process.id, thread.id,
> thread.protocol.id, thread.index, and line.number. Something like this:
>
> // Allow format specifiers: x|X|u with optional width
> specifiers.
> // {thread.id%x} ; hex
> // {thread.id%X} ; uppercase hex
> // {thread.id%u} ; unsigned decimal
> // {thread.id%8.8X} ; width.precision + specifier
>
> http://llvm-reviews.chandlerc.com/D1234
>
> Please holler with any feedback. Thanks,
> -Mike

Overall it looks fine to me. I think we'd ideally have a run-time
default, so that if you e.g. debug a Linux core on OS X you get
decimal TIDs, but that could be done later if it's awkward.

I added a %tid specifier which seems to be a fairly clean way of getting
this. Default thread format looks like this now:

#define DEFAULT_THREAD_FORMAT "thread #${thread.index}: tid = ${thread.id

%tid}"\
    "{, ${frame.pc}}"\ ...

Let me know if this looks ok and I'll commit...
Thanks.
-Mike

Yep, this looks good to me. Thanks!

-Ed

The patch looks fine. The "%tid" seems like it shouldn't need to exist. If we just leave it off, then it should "do the right thing", which would mean to default to the standard way to display a thread ID.