When my Cocoa app hits an assertion in the code, gdb gives me a prompt as expected, but it's never (ok, rarely) in the right thread.
I know I can use Xcode's GUI debugger and it makes it a little less painful, but I'm thinking there has to be a gdb command line trick I don't know.
Is there an easier way of finding the thread that asserted other than changing to each thread a开发者_开发知识库nd issuing where
?
Nikolai suggested 'thread apply all bt'. There's also 'info threads' which can sometimes help you find the one you want with less verbosity.
Suppose, 'info threads' doesn't show what you want, and you are forced to comb through the stacktraces for all threads. That can be painful if your process has many threads (this can easily be hundreds in some programs). You can limit the number of frames shown per thread to something more tractable (say 5 frames)
(gdb) thread apply all where 5
But even this can be difficult to comb through, since you may have to keep hitting the pager prompt looking for what you want, and can miss your target easily. When that's the case, I've found the combination of enabling logging and crippling the pager very helpful
(gdb) set height 10000
(gdb) set logging on
(gdb) thread apply all where 5
(gdb) shell
Now examine gdb.txt and find your thread.
(gdb) thread apply all bt
精彩评论