Hello, How can I access frame pointer? I am trying to get a variable value. Here is the disassembly of the function. function+0x208: st %l0, [%fp - 0xc] I am trying to the value at [%fp - 0xc] Thanks -- This message posted from opensolaris.org
On Fri, May 07, 2010 at 12:38:02PM -0700, tester wrote:> Hello, > > How can I access frame pointer? I am trying to get a variable value. Here is the disassembly of the function. > > function+0x208: st %l0, [%fp - 0xc] > > I am trying to the value at [%fp - 0xc]You can access the registers via the uregs[] array. See: http://wikis.sun.com/display/DTrace/User+Process+Tracing I don''t think you can get at the registers of code executing in kernel- mode. Also, uregs[] only works for the current user-land stack frame. Nico --
It doesn''t appear to be documented, but it appears that uregs[R_FP] will give you the value. (At least on SPARC, you''ll need to know which register the FP is stored in on x86.) Chad On Fri, May 7, 2010 at 3:38 PM, tester <solaris.identity at gmail.com> wrote:> Hello, > > How can I access frame pointer? I am trying to get a variable value. Here is the disassembly of the function. > > function+0x208: ? ?st ? ? ? ?%l0, [%fp - 0xc] > > I am trying to the value at [%fp - 0xc] > > Thanks > -- > This message posted from opensolaris.org > _______________________________________________ > dtrace-discuss mailing list > dtrace-discuss at opensolaris.org >
Thanks. Do I need to add stack bias 2047to fp to get actual data? which is correct? printf("localvar value is %x\n", (uregs[R_I6])); or printf("localvar value is %x\n", uregs[R_I6] + 2047); Thanks -- This message posted from opensolaris.org
On Fri, May 07, 2010 at 12:56:25PM -0700, tester wrote:> Do I need to add stack bias 2047to fp to get actual data?On 64-bit SPARC, yes. Nico --
On Fri, May 7, 2010 at 3:56 PM, tester <solaris.identity at gmail.com> wrote:> Thanks. > > Do I need to add stack bias 2047to fp to get actual data? > > which is ?correct? > > ?printf("localvar value is %x\n", (uregs[R_I6])); > or > ?printf("localvar value is %x\n", uregs[R_I6] + 2047); >I don''t think you need to add the stack bias, but that''s based on the value I get from when I print an example of uregs[R_FP] (0xffbff8a8). Note that uregs(R_I6) contains the FP itself, not the value at [%fp]. You want to do something like this (which doesn''t give you the value in a variable, but does let you inspect it): dtrace -n ''pid$target::a:18{tracemem(copyin(uregs[R_FP] - 8, 64), 64)}'' -c ./a.out I did this with this program: void a(int b, int c, int d) { int x; x = b + c + d; } int main() { a(1,2,3); } Which generates this disassembly: a() a: 9d e3 bf 98 save %sp, -0x68, %sp a+0x4: f4 27 a0 4c st %i2, [%fp + 0x4c] a+0x8: 92 06 00 19 add %i0, %i1, %o1 a+0xc: d0 07 a0 4c ld [%fp + 0x4c], %o0 a+0x10: 90 02 40 08 add %o1, %o0, %o0 a+0x14: d0 27 bf fc st %o0, [%fp - 0x4] a+0x18: 81 c7 e0 08 ret a+0x1c: 81 e8 00 00 restore a+0x20: 81 c7 e0 08 ret a+0x24: 81 e8 00 00 restore The output of the above dtrace line is this: # dtrace -n ''pid$target::a:18{tracemem(copyin(uregs[R_FP] - 8, 64), 64)}'' -c ./a.out dtrace: description ''pid$target::a:18'' matched 1 probe dtrace: pid 209 has exited CPU ID FUNCTION:NAME 16 61196 a:18 0 1 2 3 4 5 6 7 8 9 a b c d e f 0123456789abcdef 0: 00 00 00 00 00 00 00 06 00 00 00 00 00 00 00 00 ................ 10: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................ 20: 00 00 00 00 00 00 00 00 00 00 00 01 ff bf f8 f4 ................ 30: ff bf f8 fc 00 02 0c 00 ff 38 00 c0 00 00 00 00 .........8...... And we see the value 6 where we expect it. (Modifying the values of b, c, and d changes the result in that location appropriately.) Chad
Chad/Nico, Thank you for your help -- This message posted from opensolaris.org
> # dtrace -n > ''pid$target::a:18{tracemem(copyin(uregs[R_FP] - 8, 64), 64)}'' -c ./a.outHello Chad, Why do you need to subtract 8 from FP? Thanks -- This message posted from opensolaris.org
On Fri, May 7, 2010 at 5:13 PM, tester <solaris.identity at gmail.com> wrote:>> # dtrace -n >> ''pid$target::a:18{tracemem(copyin(uregs[R_FP] - 8, 64), 64)}'' -c ./a.out > > Hello Chad, > > Why do you need to subtract 8 from FP? ThanksThe disassembly showed the value of x being stored at $fp - 4: a+0x14: d0 27 bf fc st %o0, [%fp - 0x4] So I subtracted 8 and dumped the contents of memory from that location so that we''d see that value ''6'' stored in the second (4-byte) word from there. A little bit sloppy, as I could have dumped memory at %fp - 4 for exactly four bytes. Chad
> The disassembly showed the value of x being stored at > $fp - 4: > > a+0x14: d0 27 bf fc st > %o0, [%fp - 0x4] > ubtracted 8 and dumped the contents of memory from > that location > so that we''d see that value ''6'' stored in the second > (4-byte) word > from there. A little bit sloppy, as I could have > dumped memory at %fp > - 4 for exactly four bytes.Chad, Thanks -- This message posted from opensolaris.org