Howdy, Is there by any chance a way to capture the value returned from a function? I am tracing a specific function that returns a char *, and would like to record this value each time the function returns (I am currently using truss, but DTrace would be an optimal fit for what I am trying to do). Also, are the inet_* routines by any chance available to manipulate IPv4 and IPv6 addresses? I checked the Variables and Actions and Subroutines sections in the DTrace users guide, but wasn''t able to find an answer to my questions. Thanks, - Ryan -- UNIX Administrator http://daemons.net/~matty
Adam Leventhal
2005-Nov-09 21:27 UTC
[dtrace-discuss] Capturing return values && inet_* routines?
Check out the chapters on the fbt and pid providers. The return value for non-tail call returns will be in arg1. Adam On Wed, Nov 09, 2005 at 04:03:37PM -0500, Matty wrote:> > Howdy, > > Is there by any chance a way to capture the value returned from a function? > I > am tracing a specific function that returns a char *, and would like to > record > this value each time the function returns (I am currently using truss, but > DTrace > would be an optimal fit for what I am trying to do). Also, are the inet_* > routines by any chance available to manipulate IPv4 and IPv6 addresses? I > checked > the Variables and Actions and Subroutines sections in the DTrace users > guide, > but wasn''t able to find an answer to my questions. > > Thanks, > - Ryan > -- > UNIX Administrator > http://daemons.net/~matty > _______________________________________________ > dtrace-discuss mailing list > dtrace-discuss at opensolaris.org-- Adam Leventhal, Solaris Kernel Development http://blogs.sun.com/ahl
Jonathan Adams
2005-Nov-09 21:33 UTC
[dtrace-discuss] Capturing return values && inet_* routines?
On Wed, Nov 09, 2005 at 04:03:37PM -0500, Matty wrote:> > Howdy, > > Is there by any chance a way to capture the value returned from a function? > I > am tracing a specific function that returns a char *, and would like > to record this value each time the function returns (I am currently > using truss, but DTrace would be an optimal fit for what I am trying > to do).Assuming this is a userland process (since you are using truss), pid$target::funcname:return /arg1 != NULL/ { printf("%s", copyinstr(arg1)); }> Also, are the inet_* routines by any chance available to > manipulate IPv4 and IPv6 addresses? I checked the Variables and > Actions and Subroutines sections in the DTrace users guide, but wasn''t > able to find an answer to my questions.I don''t believe so; which ones in particular would you like to have? Cheers, - jonathan> Thanks, > - Ryan > -- > UNIX Administrator > http://daemons.net/~matty > _______________________________________________ > dtrace-discuss mailing list > dtrace-discuss at opensolaris.org-- Jonathan Adams, Solaris Kernel Development
On Wed, 9 Nov 2005, Adam Leventhal wrote:> Check out the chapters on the fbt and pid providers. The return value for > non-tail call returns will be in arg1.Thanks Adam and Jonathon -- arg1 worked like a charm!!!! As a follow up, is there a way to get the value of a global variable with the pid provider? I am DTracing a function that accesses several global variables, and would like to be able to print the global varaibles value each time they''re accessed. Thanks again for the awesome feedback! - Ryan -- UNIX Administrator http://daemons.net/~matty> Adam > > On Wed, Nov 09, 2005 at 04:03:37PM -0500, Matty wrote: >> >> Howdy, >> >> Is there by any chance a way to capture the value returned from a function? >> I >> am tracing a specific function that returns a char *, and would like to >> record >> this value each time the function returns (I am currently using truss, but >> DTrace >> would be an optimal fit for what I am trying to do). Also, are the inet_* >> routines by any chance available to manipulate IPv4 and IPv6 addresses? I >> checked >> the Variables and Actions and Subroutines sections in the DTrace users >> guide, >> but wasn''t able to find an answer to my questions. >> >> Thanks, >> - Ryan >> -- >> UNIX Administrator >> http://daemons.net/~matty >> _______________________________________________ >> dtrace-discuss mailing list >> dtrace-discuss at opensolaris.org > > -- > Adam Leventhal, Solaris Kernel Development http://blogs.sun.com/ahl >
Adam Leventhal
2005-Nov-09 22:48 UTC
[dtrace-discuss] Capturing return values && inet_* routines?
Hey Ryan, That''s not possible from DTrace yet. What you can do is find the address of the global variable using mdb and then stuff that address into your script. It''s a bit coarse, but it should work. Adam On Wed, Nov 09, 2005 at 05:45:29PM -0500, Matty wrote:> On Wed, 9 Nov 2005, Adam Leventhal wrote: > > >Check out the chapters on the fbt and pid providers. The return value for > >non-tail call returns will be in arg1. > > Thanks Adam and Jonathon -- arg1 worked like a charm!!!! As a follow up, > is there a way to get the value of a global variable with the pid > provider? I am DTracing a function that accesses several global variables, > and would like to be able to print the global varaibles value each time > they''re accessed. > > Thanks again for the awesome feedback! > - Ryan > > -- > UNIX Administrator > http://daemons.net/~matty > > >Adam > > > >On Wed, Nov 09, 2005 at 04:03:37PM -0500, Matty wrote: > >> > >>Howdy, > >> > >>Is there by any chance a way to capture the value returned from a > >>function? > >>I > >>am tracing a specific function that returns a char *, and would like to > >>record > >>this value each time the function returns (I am currently using truss, but > >>DTrace > >>would be an optimal fit for what I am trying to do). Also, are the inet_* > >>routines by any chance available to manipulate IPv4 and IPv6 addresses? I > >>checked > >>the Variables and Actions and Subroutines sections in the DTrace users > >>guide, > >>but wasn''t able to find an answer to my questions. > >> > >>Thanks, > >>- Ryan > >>-- > >>UNIX Administrator > >>http://daemons.net/~matty > >>_______________________________________________ > >>dtrace-discuss mailing list > >>dtrace-discuss at opensolaris.org > > > >-- > >Adam Leventhal, Solaris Kernel Development http://blogs.sun.com/ahl > > > _______________________________________________ > dtrace-discuss mailing list > dtrace-discuss at opensolaris.org-- Adam Leventhal, Solaris Kernel Development http://blogs.sun.com/ahl
Howdy, Is it possible to use offsets from arg1 in a copyin() instruction? Given the following function prototype: request_rec *ap_read_request(conn_rec *conn) and the following format for request_rec: struct request_rec { apr_pool_t *pool; conn_rec *connection; server_rec *server; request_rec *next; request_rec *prev; request_rec *main; char *the_request; [ ... ] } I would like to be able to do something like this: pid$target::ap_read_request:return { printf("Request line: %s\n",copyinstr(arg1 + 48)); } If my math is right for a 64-bit platform, I would expect "the_request" to be offset 48-bytes from the address in arg1 (this is for testing purposes -- the correct solution will use defined types). I verified this by printing the addresses to a logfile: [Thu Nov 10 16:05:30 2005] [error] [client 192.168.1.8] Address request_rec: 149c68 Address request_rec->hostname: 149c98 Given this information, is there a reason that this doesn''t work?: $ cat viewreq.d pid$target::ap_read_request:return { printf("Address: %x Hostname: %s\n",arg1 ,copyinstr(arg1 + 48)); } $ dtrace -p 3796 -s viewreqs.d dtrace: script ''viewreqs.d'' matched 1 probe CPU ID FUNCTION:NAME 0 4 ap_read_request:return Address: 149c68 Hostname: dtrace: error on enabled probe ID 1 (ID 4: pid7006:httpd:ap_read_request:return): invalid address (0x0) in action #2 at DIF offset 36 Thanks for any insight, - Ryan -- UNIX Administrator http://daemons.net/~matty On Wed, 9 Nov 2005, Adam Leventhal wrote:> Check out the chapters on the fbt and pid providers. The return value for > non-tail call returns will be in arg1. > > Adam > > On Wed, Nov 09, 2005 at 04:03:37PM -0500, Matty wrote: >> >> Howdy, >> >> Is there by any chance a way to capture the value returned from a function? >> I >> am tracing a specific function that returns a char *, and would like to >> record >> this value each time the function returns (I am currently using truss, but >> DTrace >> would be an optimal fit for what I am trying to do). Also, are the inet_* >> routines by any chance available to manipulate IPv4 and IPv6 addresses? I >> checked >> the Variables and Actions and Subroutines sections in the DTrace users >> guide, >> but wasn''t able to find an answer to my questions. >> >> Thanks, >> - Ryan >> -- >> UNIX Administrator >> http://daemons.net/~matty >> _______________________________________________ >> dtrace-discuss mailing list >> dtrace-discuss at opensolaris.org > > -- > Adam Leventhal, Solaris Kernel Development http://blogs.sun.com/ahl >
Jonathan Adams
2005-Nov-10 21:36 UTC
[dtrace-discuss] Capturing return values && inet_* routines?
On Thu, Nov 10, 2005 at 04:24:57PM -0500, Matty wrote:> > Howdy, > > Is it possible to use offsets from arg1 in a copyin() instruction? Given > the following function prototype: > > request_rec *ap_read_request(conn_rec *conn) > > and the following format for request_rec: > > struct request_rec { > apr_pool_t *pool; > conn_rec *connection; > server_rec *server; > request_rec *next; > request_rec *prev; > request_rec *main; > char *the_request; > [ ... ] > } > > I would like to be able to do something like this: > > pid$target::ap_read_request:return > { > printf("Request line: %s\n",copyinstr(arg1 + 48)); > }Nope; you need to copy it in twice; once for the pointer, then for the string: pid$target::ap_read_request:return { this->ptr = (uintptr_t *)copyin(arg1 + 48, sizeof (uintptr_t)); printf("Request line: %s\n", copyinstr(*this->ptr)); } (uintptr_t is a pointer-sized integer) Cheers, - jonathan> > If my math is right for a 64-bit platform, I would expect "the_request" to > be offset 48-bytes from the address in arg1 (this is for testing purposes > -- the correct solution will use defined types). I verified this by > printing the addresses to a logfile: > > [Thu Nov 10 16:05:30 2005] [error] [client 192.168.1.8] Address > request_rec: 149c68 Address request_rec->hostname: 149c98 > > Given this information, is there a reason that this doesn''t work?: > > $ cat viewreq.d > > pid$target::ap_read_request:return > { > printf("Address: %x Hostname: %s\n",arg1 ,copyinstr(arg1 + 48)); > } > > $ dtrace -p 3796 -s viewreqs.d > > dtrace: script ''viewreqs.d'' matched 1 probe > CPU ID FUNCTION:NAME > 0 4 ap_read_request:return Address: 149c68 Hostname: > > > dtrace: error on enabled probe ID 1 (ID 4: > pid7006:httpd:ap_read_request:return): invalid address (0x0) in action #2 > at DIF offset 36 > > Thanks for any insight, > - Ryan > -- > UNIX Administrator > http://daemons.net/~matty > > > On Wed, 9 Nov 2005, Adam Leventhal wrote: > > >Check out the chapters on the fbt and pid providers. The return value for > >non-tail call returns will be in arg1. > > > >Adam > > > >On Wed, Nov 09, 2005 at 04:03:37PM -0500, Matty wrote: > >> > >>Howdy, > >> > >>Is there by any chance a way to capture the value returned from a > >>function? > >>I > >>am tracing a specific function that returns a char *, and would like to > >>record > >>this value each time the function returns (I am currently using truss, but > >>DTrace > >>would be an optimal fit for what I am trying to do). Also, are the inet_* > >>routines by any chance available to manipulate IPv4 and IPv6 addresses? I > >>checked > >>the Variables and Actions and Subroutines sections in the DTrace users > >>guide, > >>but wasn''t able to find an answer to my questions. > >> > >>Thanks, > >>- Ryan > >>-- > >>UNIX Administrator > >>http://daemons.net/~matty > >>_______________________________________________ > >>dtrace-discuss mailing list > >>dtrace-discuss at opensolaris.org > > > >-- > >Adam Leventhal, Solaris Kernel Development http://blogs.sun.com/ahl > > > _______________________________________________ > dtrace-discuss mailing list > dtrace-discuss at opensolaris.org-- Jonathan Adams, Solaris Kernel Development
On Thu, 10 Nov 2005, Jonatha> Nope; you need to copy it in twice; once for the pointer, then for the string: > > pid$target::ap_read_request:return > { > this->ptr = (uintptr_t *)copyin(arg1 + 48, sizeof (uintptr_t)); > printf("Request line: %s\n", copyinstr(*this->ptr)); > } > > (uintptr_t is a pointer-sized integer) >Hi Jonathon, Thanks for the pointer, but it still seems to be angry: $ dtrace -p 7133 -s viewreqs.d dtrace: script ''viewreqs.d'' matched 1 probe dtrace: error on enabled probe ID 1 (ID 36860: pid7133:httpd:ap_read_request:return): invalid address (0x0) in action #2 at DIF offset 20 dtrace: error on enabled probe ID 1 (ID 36860: pid7133:httpd:ap_read_request:return): invalid address (0x0) in action #2 at DIF offset 20 Does the error refer to the address of the pointer, or the address of the first byte of the item the pointer points to? Thanks for your help! - Ryan -- UNIX Administrator http://daemons.net/~matty> Cheers, > - jonathan > >> >> If my math is right for a 64-bit platform, I would expect "the_request" to >> be offset 48-bytes from the address in arg1 (this is for testing purposes >> -- the correct solution will use defined types). I verified this by >> printing the addresses to a logfile: >> >> [Thu Nov 10 16:05:30 2005] [error] [client 192.168.1.8] Address >> request_rec: 149c68 Address request_rec->hostname: 149c98 >> >> Given this information, is there a reason that this doesn''t work?: >> >> $ cat viewreq.d >> >> pid$target::ap_read_request:return >> { >> printf("Address: %x Hostname: %s\n",arg1 ,copyinstr(arg1 + 48)); >> } >> >> $ dtrace -p 3796 -s viewreqs.d >> >> dtrace: script ''viewreqs.d'' matched 1 probe >> CPU ID FUNCTION:NAME >> 0 4 ap_read_request:return Address: 149c68 Hostname: >> >> >> dtrace: error on enabled probe ID 1 (ID 4: >> pid7006:httpd:ap_read_request:return): invalid address (0x0) in action #2 >> at DIF offset 36 >> >> Thanks for any insight, >> - Ryan >> -- >> UNIX Administrator >> http://daemons.net/~matty >> >> >> On Wed, 9 Nov 2005, Adam Leventhal wrote: >> >>> Check out the chapters on the fbt and pid providers. The return value for >>> non-tail call returns will be in arg1. >>> >>> Adam >>> >>> On Wed, Nov 09, 2005 at 04:03:37PM -0500, Matty wrote: >>>> >>>> Howdy, >>>> >>>> Is there by any chance a way to capture the value returned from a >>>> function? >>>> I >>>> am tracing a specific function that returns a char *, and would like to >>>> record >>>> this value each time the function returns (I am currently using truss, but >>>> DTrace >>>> would be an optimal fit for what I am trying to do). Also, are the inet_* >>>> routines by any chance available to manipulate IPv4 and IPv6 addresses? I >>>> checked >>>> the Variables and Actions and Subroutines sections in the DTrace users >>>> guide, >>>> but wasn''t able to find an answer to my questions. >>>> >>>> Thanks, >>>> - Ryan >>>> -- >>>> UNIX Administrator >>>> http://daemons.net/~matty >>>> _______________________________________________ >>>> dtrace-discuss mailing list >>>> dtrace-discuss at opensolaris.org >>> >>> -- >>> Adam Leventhal, Solaris Kernel Development http://blogs.sun.com/ahl >>> >> _______________________________________________ >> dtrace-discuss mailing list >> dtrace-discuss at opensolaris.org > > -- > Jonathan Adams, Solaris Kernel Development >
Jonathan Adams
2005-Nov-10 22:20 UTC
[dtrace-discuss] Capturing return values && inet_* routines?
On Thu, Nov 10, 2005 at 04:47:46PM -0500, Matty wrote:> > On Thu, 10 Nov 2005, Jonatha > >Nope; you need to copy it in twice; once for the pointer, then for the > >string: > > > >pid$target::ap_read_request:return > >{ > > this->ptr = (uintptr_t *)copyin(arg1 + 48, sizeof (uintptr_t)); > > printf("Request line: %s\n", copyinstr(*this->ptr)); > >} > > > >(uintptr_t is a pointer-sized integer) > > > > Hi Jonathon, > > Thanks for the pointer, but it still seems to be angry: > > $ dtrace -p 7133 -s viewreqs.d > dtrace: script ''viewreqs.d'' matched 1 probe > dtrace: error on enabled probe ID 1 (ID 36860: > pid7133:httpd:ap_read_request:return): > invalid address (0x0) in action #2 at DIF offset 20 > > dtrace: error on enabled probe ID 1 (ID 36860: > pid7133:httpd:ap_read_request:return): > invalid address (0x0) in action #2 at DIF offset 20 > > Does the error refer to the address of the pointer, or the address of the > first byte of the item the pointer points to?If you''re running this on sparc, it''s hard to tell; the "invalid address" is rounded down to the nearest page. On Intel, you get the exact address. To find out what pointer is NULL, you could do: pid$target::ap_read_request:return { printf("arg1 == %p\n", arg1); } pid$target::ap_read_request:return /(this->ptr = *(uintptr_t *)copyin(arg1 + 48, sizeof (uintptr_t))) != NULL/ { printf("Request line: %s\n", copyinstr(this->ptr)); } pid$target::ap_read_request:return /this->ptr == NULL/ { printf("request line is NULL\n"); } Cheers, - jonathan> > > >> > >>If my math is right for a 64-bit platform, I would expect "the_request" to > >>be offset 48-bytes from the address in arg1 (this is for testing purposes > >>-- the correct solution will use defined types). I verified this by > >>printing the addresses to a logfile: > >> > >>[Thu Nov 10 16:05:30 2005] [error] [client 192.168.1.8] Address > >>request_rec: 149c68 Address request_rec->hostname: 149c98 > >> > >>Given this information, is there a reason that this doesn''t work?: > >> > >>$ cat viewreq.d > >> > >>pid$target::ap_read_request:return > >>{ > >> printf("Address: %x Hostname: %s\n",arg1 ,copyinstr(arg1 + 48)); > >>} > >> > >>$ dtrace -p 3796 -s viewreqs.d > >> > >>dtrace: script ''viewreqs.d'' matched 1 probe > >>CPU ID FUNCTION:NAME > >> 0 4 ap_read_request:return Address: 149c68 Hostname: > >> > >> > >>dtrace: error on enabled probe ID 1 (ID 4: > >>pid7006:httpd:ap_read_request:return): invalid address (0x0) in action #2 > >>at DIF offset 36 > >> > >>Thanks for any insight, > >>- Ryan > >>-- > >>UNIX Administrator > >>http://daemons.net/~matty > >> > >> > >>On Wed, 9 Nov 2005, Adam Leventhal wrote: > >> > >>>Check out the chapters on the fbt and pid providers. The return value for > >>>non-tail call returns will be in arg1. > >>> > >>>Adam > >>> > >>>On Wed, Nov 09, 2005 at 04:03:37PM -0500, Matty wrote: > >>>> > >>>>Howdy, > >>>> > >>>>Is there by any chance a way to capture the value returned from a > >>>>function? > >>>>I > >>>>am tracing a specific function that returns a char *, and would like to > >>>>record > >>>>this value each time the function returns (I am currently using truss, > >>>>but > >>>>DTrace > >>>>would be an optimal fit for what I am trying to do). Also, are the > >>>>inet_* > >>>>routines by any chance available to manipulate IPv4 and IPv6 addresses? > >>>>I > >>>>checked > >>>>the Variables and Actions and Subroutines sections in the DTrace users > >>>>guide, > >>>>but wasn''t able to find an answer to my questions. > >>>> > >>>>Thanks, > >>>>- Ryan > >>>>-- > >>>>UNIX Administrator > >>>>http://daemons.net/~matty > >>>>_______________________________________________ > >>>>dtrace-discuss mailing list > >>>>dtrace-discuss at opensolaris.org > >>> > >>>-- > >>>Adam Leventhal, Solaris Kernel Development http://blogs.sun.com/ahl > >>> > >>_______________________________________________ > >>dtrace-discuss mailing list > >>dtrace-discuss at opensolaris.org > > > >-- > >Jonathan Adams, Solaris Kernel Development > > > _______________________________________________ > dtrace-discuss mailing list > dtrace-discuss at opensolaris.org-- Jonathan Adams, Solaris Kernel Development