I'm getting a crash in pthread_specific() on OS X Lion using a 32-bit server application written with FPC and Indy 10 on Mac OS X. I'm finding it very hard to track down the cause. The crash occurs because gs:[tlsindex] is not readable, but I have no idea why this occurs. The tlsindex is correct, so the descriptor table must somehow have become corrupted.
Is there a way to print the descriptor table using gdb / Xcode 4 on OS X? I'm thinking that if I know the address in memory, I could set a data breakpoint on it and hopefully break at the code that corrupts the descriptor table. Unfortunately I can't find any information on how TLS is actually implemented on OS X (i386).
Or perhaps someone has a brilliant idea on how to tackle this problem?