Hi all, So I just took Sun''s dtrace class this week and one thing that piqued my interest was the instrumenting of a process''s instructions and how to find the original instructions. (I''m looking around at resources for learning SPARC assembly to help me when using mdb for analysis, though I vaguely remember pieces from a grad school compiler theory class about 10 years ago. If anyone has any recommendations for learning SPARC assembly, please let me know.) So, in one window I run mdb on a simple program and run it to a breakpoint: $ mdb a.out> _start::bp > :rmdb: stop at _start mdb: target stopped at: _start: clr %fp> main::dismain: save %sp, -0x70, %sp main+4: call +0x2c <globalsum> main+8: nop main+0xc: mov %o0, %g1 main+0x10: sethi %hi(0x10400), %o5 main+0x14: or %o5, 0x3f8, %o0 main+0x18: mov %g1, %o1 main+0x1c: call +0x101a4 <PLT:printf> main+0x20: nop main+0x24: mov %g1, %i0 main+0x28: ret main+0x2c: restore>In a second window I run dtrace on the running process: bash-3.00# dtrace -n ''pid$1:a.out::{}'' 20784 dtrace: description ''pid$1:a.out::'' matched 67 probes Back to mdb in the first window:> main::dismain: ta 0x38 main+4: ta 0x38 main+8: ta 0x38 main+0xc: ta 0x38 main+0x10: ta 0x38 main+0x14: ta 0x38 main+0x18: ta 0x38 main+0x1c: ta 0x38 main+0x20: ta 0x38 main+0x24: ta 0x38 main+0x28: ta 0x38 main+0x2c: ta 0x38>Here''s the 64-bit question: Is it possible while the instructions are instrumented as shown by the traps above to locate the original instructions? For example, is it possible to use the address main+0xc to display the original mov instruction? Whether or not this is possible, where is the original instruction located at this point? Thanks, Justin -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://mail.opensolaris.org/pipermail/dtrace-discuss/attachments/20070503/b89cfdc7/attachment.html>
Hi Justin, I filed RFE 5109439 "pid provider obscures original instruction" and have recently begun work on addressing it in the pid provider. I don''t have any sort of estimated time of arrival for the fix, I will try to fix it when I can get sufficient time. As far as the best way to learn SPARC assembly, you are pretty much doing it :) Get a copy of the SPARCv9 architecture manual, ISBN 0-13-825001-4, and keep asking questions. I believe the manual can be had in PDF form from either docs.sun.com or the SPARC website. In the past, I have written some ugly perl scripts to post-processes DTrace pid provder offset probes and correlate them with the instructions at that address. I wrote some blog entries about it and then got side tracked by some other stuff ( http://blogs.sun.com/ejo/Observability ). Now that the other stuff is mostly not bugging me any more, I plan to come back and work on this particular problem. Regards, ejo Justin Lloyd wrote:> > Hi all, > > So I just took Sun?s dtrace class this week and one thing that piqued > my interest was the instrumenting of a process?s instructions and how > to find the original instructions. (I?m looking around at resources > for learning SPARC assembly to help me when using mdb for analysis, > though I vaguely remember pieces from a grad school compiler theory > class about 10 years ago. If anyone has any recommendations for > learning SPARC assembly, please let me know.) > > So, in one window I run mdb on a simple program and run it to a > breakpoint: > > [deletia] > > Here?s the 64-bit question: Is it possible while the instructions are > instrumented as shown by the traps above to locate the original > instructions? For example, is it possible to use the address main+0xc > to display the original mov instruction? Whether or not this is > possible, where is the original instruction located at this point? > > Thanks, > > Justin >
Erik, Thanks for all the great information and good luck with that provider work! By the way, the link to your blog was a bit off (ejo/category/Observability), but I found the scripts from the blog''s front page. Also, I found Adam Leventhal''s "Inside the DTrace pid Provider" presentation (http://blogs.sun.com/ahl/date/20050301), which helps answer my question about where the instructions go when instrumented. :) Justin> -----Original Message----- > From: Erik.Oshaughnessy at Sun.COM [mailto:Erik.Oshaughnessy at Sun.COM] > Sent: Thursday, May 03, 2007 9:11 PM > To: Justin Lloyd > Cc: dtrace-discuss at opensolaris.org > Subject: Re: [dtrace-discuss] Finding instrumented code > > Hi Justin, > > I filed RFE 5109439 "pid provider obscures original instruction" and > have recently begun work on addressing it in the pid provider. I don''t > have any sort of estimated time of arrival for the fix, I will try to > fix it when I can get sufficient time. As far as the best way to learn > SPARC assembly, you are pretty much doing it :) Get a copy of the > SPARCv9 architecture manual, ISBN 0-13-825001-4, and keep asking > questions. I believe the manual can be had in PDF form from either > docs.sun.com or the SPARC website. > > In the past, I have written some ugly perl scripts to post-processes > DTrace pid provder offset probes and correlate them with the > instructions at that address. I wrote some blog entries about it and > then got side tracked by some other stuff ( > http://blogs.sun.com/ejo/Observability ). Now that the other stuff is > mostly not bugging me any more, I plan to come back and work on this > particular problem. > > Regards, > ejo > > > Justin Lloyd wrote: > > > > Hi all, > > > > So I just took Sun''s dtrace class this week and one thing thatpiqued> > my interest was the instrumenting of a process''s instructions andhow> > to find the original instructions. (I''m looking around at resources > > for learning SPARC assembly to help me when using mdb for analysis, > > though I vaguely remember pieces from a grad school compiler theory > > class about 10 years ago. If anyone has any recommendations for > > learning SPARC assembly, please let me know.) > > > > So, in one window I run mdb on a simple program and run it to a > > breakpoint: > > > > [deletia] > > > > Here''s the 64-bit question: Is it possible while the instructionsare> > instrumented as shown by the traps above to locate the original > > instructions? For example, is it possible to use the addressmain+0xc> > to display the original mov instruction? Whether or not this is > > possible, where is the original instruction located at this point? > > > > Thanks, > > > > Justin > >
If you check the developers documentation on docs.sun.com, there''s actually a pretty decent SPARC assebler book. I''m just rushing out but I''ll dig it up tonight. On 5/3/07, Justin Lloyd <jlloyd at digitalglobe.com> wrote:> > > > Hi all, > > So I just took Sun''s dtrace class this week and one thing that piqued my > interest was the instrumenting of a process''s instructions and how to find > the original instructions. (I''m looking around at resources for learning > SPARC assembly to help me when using mdb for analysis, though I vaguely > remember pieces from a grad school compiler theory class about 10 years ago. > If anyone has any recommendations for learning SPARC assembly, please let me > know.) > > So, in one window I run mdb on a simple program and run it to a breakpoint: > > $ mdb a.out > > > _start::bp > > > :r > > mdb: stop at _start > > mdb: target stopped at: > > _start: clr %fp > > > main::dis > > main: save %sp, -0x70, %sp > > main+4: call +0x2c <globalsum> > > main+8: nop > > main+0xc: mov %o0, %g1 > > main+0x10: sethi %hi(0x10400), %o5 > > main+0x14: or %o5, 0x3f8, %o0 > > main+0x18: mov %g1, %o1 > > main+0x1c: call +0x101a4 <PLT:printf> > > main+0x20: nop > > main+0x24: mov %g1, %i0 > > main+0x28: ret > > main+0x2c: restore > > > > > > > In a second window I run dtrace on the running process: > > bash-3.00# dtrace -n ''pid$1:a.out::{}'' 20784 > > dtrace: description ''pid$1:a.out::'' matched 67 probes > > > > Back to mdb in the first window: > > > main::dis > > main: ta 0x38 > > main+4: ta 0x38 > > main+8: ta 0x38 > > main+0xc: ta 0x38 > > main+0x10: ta 0x38 > > main+0x14: ta 0x38 > > main+0x18: ta 0x38 > > main+0x1c: ta 0x38 > > main+0x20: ta 0x38 > > main+0x24: ta 0x38 > > main+0x28: ta 0x38 > > main+0x2c: ta 0x38 > > > > > Here''s the 64-bit question: Is it possible while the instructions are > instrumented as shown by the traps above to locate the original > instructions? For example, is it possible to use the address main+0xc to > display the original mov instruction? Whether or not this is possible, where > is the original instruction located at this point? > > Thanks, > > Justin > > > _______________________________________________ > dtrace-discuss mailing list > dtrace-discuss at opensolaris.org >-- Laissez-nous faire, laissez-nous passer. Le monde va de lui-m?me.
On Thu, May 03, 2007 at 05:59:37PM -0600, Justin Lloyd wrote:> Here''s the 64-bit question: Is it possible while the instructions are > instrumented as shown by the traps above to locate the original > instructions? For example, is it possible to use the address main+0xc to > display the original mov instruction? Whether or not this is possible, > where is the original instruction located at this point?Absolutely. The fasttrap module (which exports the pid provider and USDT providers) has an associated pseudo-device that accepts an ioctl(2) to query the original instruction for a given address and pid; libdtrace uses this internally when disassembling functions: http://cvs.opensolaris.org/source/xref/onnv/onnv-gate/usr/src/lib/libdtrace/i386/dt_isadep.c#432 A reasonable RFE for mdb would be to incorporate this logic so that instrumented functions could be annotated with their original instructions. Adam -- Adam Leventhal, Solaris Kernel Development http://blogs.sun.com/ahl