• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Custom data formatter for pthread_mutex_t?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Custom data formatter for pthread_mutex_t?


  • Subject: Re: Custom data formatter for pthread_mutex_t?
  • From: Steve Checkoway <email@hidden>
  • Date: Mon, 20 Aug 2007 06:03:26 -0700


On Aug 20, 2007, at 5:14 AM, Karan, Cem (Civ, ARL/CISD) wrote:

Hmmm.... OK, I have no experience with custom data formatters, so please
forgive my ignorance. Is it possible to write a custom formatter that
can call pthread_mutex_trylock()from within XCode/GDB's context on a
lock in the application's context? If so, then I can let my code run
until it hits a breakpoint, know that the code is stopped, and use
trylock() to test the state of the lock. This would also negate the
need for custom macros and all the other usual tricks, and it would be
portable to any pthreads code that needs to be debugged (the data
formatter can be with Xcode, not the project code)

As I mentioned before, calling pthread_mutex_trylock() isn't a good solution because if you have a recursive mutex and it gets called on the same thread, it could report being unlocked when it is really locked.


As for custom data formatters, I posted to this list the layout of the pthread_mutex_t data structure so it is very easy to write a custom data formatter. For PowerPC, at least, gcc lays out bit fields sequentially so that the u_int32_t protocol:2, type:2, rfu:12, lock_count:16; field is layed out with the lock count being bytes 18 and 19 of the __opaque field of the pthread_mutex_t.

I don't know why, but when I view the mutex in Xcode's debugger, the leading underscores are stripped. That said, one simple custom data formatter is
locked = {(bool)$VAR.opaque[18]||$VAR.opaque[19]}


It's possible (probable?) that on x86 the bit fields are laid out in the reverse order so it's likely that you'd want
locked = {(bool)$VAR.opaque[16]||$VAR.opaque[17]}


Of course this isn't portable, but since you're just using it for debugging purposes, it doesn't seem like that'd be much of a problem.

You can get more fancy with something like
inited = {$VAR.sig==1297437784}; locked = {(bool) $VAR.sig==1297437784&&($VAR.opaque[18]||$VAR.opaque[19])}


where 1297437784 is 'MUTX'. On i386, it might be 1481921869 for 'XTUM', I'm not sure.

--
Steve Checkoway



Attachment: smime.p7s
Description: S/MIME cryptographic signature

 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Xcode-users mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

References: 
 >Re: Custom data formatter for pthread_mutex_t? (From: Cem Karan <email@hidden>)
 >Re: Custom data formatter for pthread_mutex_t? (From: Alastair Houghton <email@hidden>)
 >RE: Custom data formatter for pthread_mutex_t? (From: "Karan, Cem (Civ, ARL/CISD)" <email@hidden>)
 >Re: Custom data formatter for pthread_mutex_t? (From: "Kyle Sluder" <email@hidden>)
 >Re: Custom data formatter for pthread_mutex_t? (From: alex <email@hidden>)
 >RE: Custom data formatter for pthread_mutex_t? (From: "Karan, Cem (Civ, ARL/CISD)" <email@hidden>)

  • Prev by Date: RE: Custom data formatter for pthread_mutex_t?
  • Next by Date: RE: Custom data formatter for pthread_mutex_t?
  • Previous by thread: RE: Custom data formatter for pthread_mutex_t?
  • Next by thread: RE: Custom data formatter for pthread_mutex_t?
  • Index(es):
    • Date
    • Thread