Main menu:

Site search

Categories

Archive

DTrace C++ Mysteries Solved

I’ve been using DTrace on Leopard in my recent work, and while it’s a great tool, the C++ support is confusing and I couldn’t find proper documentation. But eventually I found sketchy documentation that gave me the answers, so in the interest of saving others from pain:

Basic Call Profiling. One of the most basic profiling tasks is recording function call entries and returns. And DTrace is very good at this, using the pid provider. For example, if you have a simple C program ‘prog’ that contains a function ‘foo’, you can get DTrace to trace calls to ‘foo’ like this:

sudo dtrace -c './prog' -n 'pid$target:prog:foo:entry'

Unpacking this, the -c option starts a program and the process id in a special DTrace variable-type-thing called $target. The -n option specifies a probe to trace using DTrace’s standard 4-part syntax. In this case, the 4 parts are: (1) the provider, pid$target, which means user function call tracing in process $target, (2) prog, the module to trace functions in, (3) the function to trace, foo, and (4) entry, meaning we want function entries (as opposed to returns or other instructions). (Thanks to Vlad for giving me the verbal tutorial on this part.)

This time, with C++. So far, so good, but when you try to do this for C++ programs, some weirdness sets in. Let’s say our C++ program has a class C that contains a method bar that takes an int argument. This means the C-style symbol that the linker operates on is the mangled name, some junk like __ZN1C1barEi. According to Sun’s article on DTrace with C++, which is all I could find by Googling “dtrace c++” you use the mangled name in the provider specification, as in

sudo dtrace -c './prog' -n 'pid$target:prog:__ZN1C1barEi:entry'

But that didn’t work at all for me on Leopard. DTrace said “invalid probe specifier, blah, blah, blah”. I figured out part of the answer by trial and error, but I didn’t get the full answer until I remembered that Vlad suggested the support for demangled names might have been added as part of Objective C support, Googled “dtrace objective c”, found a blog post, followed a link from there to the Apple dtrace man page, saw the “-xmangled” option, Googled “xmangled”, and found an Apple mailing list thread. Ugh. Is there no better way to find documentation? (I guess I should be comparing with the effort of searching a wall full of manuals, and instead of complaining, I should be grateful that once again, Teh Mighty Interwebs have proven infinitely wise.)

Anyway, the answer is that on Leopard you can specify probes for C++ functions using either mangled names or unmangled names, with appropriate obscure incantations either way.

Unmangled:

sudo dtrace -c './prog' -n 'pid$target:prog:C??f(int):entry'

The key is that you have to give the whole signature for the method, but you can’t have colons in there because the probe specification parser gets confused, so you use the ? wildcard instead. You can also abbreviate using other wildcards, as in C??f*.

Mangled:

sudo dtrace -c './prog' -n 'pid$target:prog:__ZN1C1barEi:entry' -xmangled

-xmangled tells DTrace to use the mangled names. If you do it this way, you’ll also see the mangled names in the output.

Comments

Pingback from Taras’ Blog » Blog Archives » Random News in the Dehydra Corner
Time: March 3, 2008, 6:05 pm

[...] at the stage where one can interactively query the codebase from an ajax UI, but we are making steps in the right direction. As part of this trend, dehydra documentation is starting to migrate to MDC. [...]

Pingback from Random News in the Dehydra Corner · Get Latest Mozilla Firefox Browsers
Time: March 4, 2008, 10:19 am

[...] at the stage where one can interactively query the codebase from an ajax UI, but we are making steps in the right direction. As part of this trend, dehydra documentation is starting to migrate to MDC. [...]

Comment from Kimberley24
Time: November 20, 2009, 2:40 pm

That is plainly that essays writers can bring the knowledge just about dissertation hence, we could without the efforts order essay or buy thesis about this post

Comment from web design sydney
Time: February 12, 2010, 9:40 pm

It is really nice written article from you guys. I would suggest it to everyone who wants to read and learn more. There is so many helpful information’s which I couldn’t find on other websites and other similar blogs. Thank You for that.

Comment from sonnerie portable
Time: May 20, 2010, 11:17 pm

This article gives the light in which we can observe the reality. This is very nice one and gives in depth information. Thanks for this nice article. Good post…..Valuable information for all.

Comment from Watch FiFa World Cup 2010 Online
Time: May 21, 2010, 7:22 pm

This is a really good read for me. Must agree that you are one of the coolest blogger I ever saw. Thanks for posting this useful information. This was just what I was on looking for. I’ll come back to this blog for sure! I bookmarked this blog a while ago because of the useful content and I am never being disappointed. Keep up the good work

Comment from online sudoku solver
Time: June 8, 2010, 3:06 pm

thanks for the article

Comment from Affiliate Program
Time: June 14, 2010, 2:00 am

The DTrace SDT provider allows the developer to put probe points into the source code. When the probe fires, the dtrace utility shows the arguments with which the probe has been invoked. Akin to printf() debugging, but much more powerful – the probes may be turned on or off during the program execution.

Comment from Medyum
Time: June 18, 2010, 12:39 am

The DTrace SDT provider allows the developer to put probe points into the source code. When the probe fires, the dtrace utility shows the arguments with which the probe has been invoked. Akin to printf() debugging, but much more powerful – the probes may be turned on or off during the program execution.

Comment from office chairs
Time: July 7, 2010, 8:33 am

This ergonomic high back office chair extends the full length of the back,up to the shoulders and includes support for the head and neck. Our chairs are crafted to perfection and designed to the bodies natural shape, you will find complete comfort with its PU leather material and padded arm rests.

The chair is fitted with optimised functions which include gas height adjustment and tilt mechanism, to allow for greater comfort and allowing you to find your ideal position.

Our executive range of office chairs are built to be Safe, to last for years and cannot be beat in any head to head comparison in its class. Easy assemble, a strong nylon base and 360° swivel, top this PU leather, a fantastic executive look.

Comment from bobrick paper towel dispenser
Time: July 7, 2010, 7:45 pm

I found this is an informative and interesting post so i think so it is very useful and knowledgeable.
I´m watching basketball for so many years and always want to know new information about this.
Thanks.

Comment from generosity examples
Time: July 29, 2010, 1:38 pm

thank you for this post david.
i dont know this until you made this post.

Comment from american online bingo games
Time: August 17, 2010, 1:04 am

No matter what “technical indicators”, “technical studies”, or whatever equations you wish to throw at a financial instrument, they are all derived from the same information: price. You can take indicators of indicators, constantly bludgeoning the data into some kind of form that seems to tell us something that the price movement hasn’t told us already, but that’s useless if there is blind faith involved.

Comment from blood pressure remedy
Time: August 17, 2010, 1:05 am

ny information contained in the above article represents my opinions only, and should not be construed as personalized investment advice. I cannot assess, verify or guarantee the suitability of any particular investment to any particular situation and the reader of the article bears complete responsibility for its own investment research and should seek the advice of a qualified investment professional that provides individualized advice prior to making any investment decisions. All opinions expressed and information and data provided therein are subject to change without notice.

Comment from online special education degree
Time: August 29, 2010, 11:58 pm

I admire what you have done here. It is good to see your clarity on this important subject can be easily observed. Tremendous post and will look forward to your future update.

Comment from Onsalenow
Time: September 2, 2010, 8:25 pm

Hello there, truly love what you have been doing, your work is outstanding.

Comment from Serotonin Levels
Time: September 14, 2010, 4:34 am

The way you tell about things is awesome. i always wait for your posts. They are inspiring and helpful.Thanks for sharing your information and stories.

Comment from bingo promotions
Time: September 14, 2010, 6:41 am

Hey, I am new to DTrace and I find it very confusing at current. A friend told me about it and he knows all about it and how to use it. Thanks for taking the time and you are helping me understand it better. I am blonde also, haha.

Comment from sernak plywood
Time: September 21, 2010, 12:11 am

This article gives the light in which we can observe the reality

Comment from Internet Marketing Company
Time: September 21, 2010, 11:30 pm

Great post I would like to thank you for the efforts you have made in writing this interesting and knowledgeable article. I am hoping the same best effort from you in the future as well. In fact your creative writing skills has inspired me.

Comment from otoemlak
Time: September 23, 2010, 7:33 am

thank you for this post david.
i dont know this until you made this post.

Comment from Dissertation Help
Time: September 23, 2010, 9:49 am

Wonderful post about “DTrace C++ Mysteries Solved”.

Comment from Hydraulic Jacks
Time: September 23, 2010, 10:30 pm

Thanks sharing, useful post, Wedding vendors want to wedding invitations communicate with you! Quality wedding professionals look.

Comment from FatCow Reviews
Time: September 27, 2010, 9:31 am

Thanks for the info. Just what I was looking for and i finally got my answers.

Comment from moving company san diego
Time: October 11, 2010, 12:37 am

I would like to thank you for the efforts you have made in writing this article. I am hoping the same best work from you in the future as well.

Comment from Simone
Time: October 11, 2010, 9:37 am

Thanks for the post!

Comment from medyum
Time: October 11, 2010, 11:15 am

This web site is really very nice .. This article has been perfect. Thank you very much. medyum I follow your stories and documents continuously. Thank you for sharing ..

Comment from niyazi
Time: October 13, 2010, 9:30 am

medyum

Comment from brazil export
Time: October 15, 2010, 12:27 am

A very good review. I love this share though of in brief but had an lot of information.

Comment from San Diego Electrician
Time: October 20, 2010, 11:18 pm

Comfortabl y, the article is in reality the best on this valuable topic. I harmonise with your conclusions and will thirstily look forward to your coming updates. Just saying thanks will not just be sufficient, for the wonderful clarity in your writing. I will instantly grab your rss feed to stay privy of any updates. Fabulous work and much success in your business dealings!

Comment from Cecilia
Time: October 22, 2010, 7:37 pm

love what youre saying and the way you say it.
You make it entertaining and you still manage to keep it smart.

Comment from Flyttstäd Stockholm
Time: October 25, 2010, 4:53 pm

DTrace is very good at recording function call entries and returns.
It is interesting know some thing on it from your page. It takes me lots of useful knowledge.

Comment from Portugalija
Time: October 26, 2010, 4:51 pm

It’s quite hard to find a good site. And I think I am lucky enough to have come here. The posts are doing great and full of good insights. I would be glad to keep on coming back here to check for a new update.

Comment from Portugalija
Time: October 26, 2010, 4:56 pm

It’s a wonderful way to be updated and active. People can see what is your activity and what you were doing recently. I think it’s one of those new media on Internet.

Comment from rachat de credit
Time: October 27, 2010, 6:27 am

It’s a wonder that this is still being brought up. It’s been awhile since I read something about this.

Comment from Northbet.com
Time: October 28, 2010, 7:27 pm

These tutorials explain the C++ language from its basics up to the newest features of ANSI-C++, including basic concepts such as arrays or classes and advanced concepts such as polymorphism or templates. The tutorial is oriented in a practical way, with working example programs in all sections to start practicing each lesson right away.

Comment from Cheap South Pacific Tickets
Time: October 31, 2010, 11:58 pm

I’m still waiting for some interesting thoughts from your side in your next post.I saw many sites but yours is very interesting, you got talent in writing articles, blog bookmarked!

Comment from Cheap Jersey Boys Tickets
Time: November 1, 2010, 12:00 am

I saw many sites but yours is very interesting, you got talent in writing articles, blog bookmarked!Some things in here I have not thought about before.I am happy to find this post very useful for me, as it contains lot of information.Thanks for making such a cool post which is really very well written.will be referring a lot of friends about this.Keep blogging

Comment from dog tags for dogs
Time: November 3, 2010, 7:38 pm

I am happy that I finally found this blog, I couldnt discover any info on this subject matter prior to.I’m always look for people to check out my site. Please stop by and leave a comment sometime!thanks for the post

Comment from Los Angeles Plumbing
Time: November 4, 2010, 9:53 am

While this subject can be very touchy for most people, my opinion is that there has to be a middle or common ground that we all can find. I do appreciate that youve added relevant and intelligent commentary here though. Thank you!

Comment from Los Angeles Plumbing
Time: November 4, 2010, 9:53 am

Thanks For This Blog, was added to my bookmarks.

Comment from Online Printing
Time: November 6, 2010, 12:51 am

I am getting information about DTrace very first time.But i am impressed with this particular software.I will definitely try it for applications. Hope so it won’t disappoint me..Thanks for sharing. Keep posting about such applications…as its really a great source for all of us.Keep it up

Comment from San Diego Granite Countertops
Time: November 9, 2010, 12:56 am

Dreamin. I love blogging. You all express your feelings the right way, because they are your feeling, focus on your blog it is great.

Comment from medyum
Time: November 11, 2010, 10:20 am

thanks for admin wonderfull blog and dissenger

Comment from businessloan
Time: November 15, 2010, 6:19 pm

Excellent post.I want to thank you for this informative read, I really appreciate sharing this great post. Keep up your work…

Comment from Bangla Dictionary
Time: November 15, 2010, 11:49 pm

It is amazing to have a look at performance of IT industry. From last few years it is doing really well to and amazed us. Thanks tou you as well for providing this info

Comment from engraved dog tags
Time: November 16, 2010, 12:17 am

This is a really good read for me. Must agree that you are one of the coolest blogger I ever saw. Thanks for posting this useful information. This was just what I was on looking for. I’ll come back to this blog for sure! I bookmarked this blog a while ago because of the useful content and I am never being disappointed.

Comment from şömine
Time: November 18, 2010, 12:30 pm

thanks for admin wonderfull blog and dissenger.