Dtracing gethostbyname I''m trying to read the h_alias array and all the
entries it points to however every time I copyin an entry pointed to by the
first entry in teh h_alias array the other entries in the array get corrupted.
So I have ended up with this script:
#!/usr/bin/dtrace -CZs
#include <netdb.h>
pid$target::gethostbyname_r:return
{
self->r = (struct hostent *)copyin(arg1, sizeof (struct hostent));
printf("%d Host: %s", pid,
copyinstr((uintptr_t)self->r->h_name));
printf(" h_aliases %p ", self->r->h_aliases);
self->a = (char **)copyin((uintptr_t)self->r->h_aliases,
4*sizeof (char *));
}
#define ALIAS(X) \
pid$target::gethostbyname_r:return \
/ self->a[X] != 0 / \
{ \
printf("%d h_alias[%d]: %p", pid, X, (uintptr_t)(self->a[X])); \
self->my_counter++; \
}
#define XSALIAS(X)
#define SALIAS(X) \
pid$target::gethostbyname_r:return \
/ self->a[X] != 0 / \
{ \
printf(" X+1 %p\n", self->a[X+1]); \
printf("%d h_alias[%d]: %s", pid, X, \
copyinstr((uintptr_t)self->a[X])); \
printf("\nX %p", self->a[X]); \
printf(" X+1 %p", self->a[X+1]); \
self->my_counter--; \
}
ALIAS(0)
ALIAS(1)
ALIAS(2)
ALIAS(3)
SALIAS(0)
SALIAS(1)
SALIAS(2)
SALIAS(3)
pid$target::gethostbyname_r:return
/self->my_counter/
{
printf("Stopping...\n");
stop(); exit(0);
}
/* END OF SCRIPT */
This should print out the array of (upto 4) pointers to h_aliases and then
dereference each one. However if it fails to derefrence them is stops the target
program and exits.
: va64-v40zh-gmp03.eu TS 14 $; getent hosts va64-v40zh-gmp03
129.156.213.204 va64-v40zh-gmp03 loghost spamhost
: va64-v40zh-gmp03.eu TS 15 $; pfexec /usr/sbin/dtrace -32 -wZCs
gethostbynam>
dtrace: script ''gethostbyname.d'' matched 0 probes
dtrace: allowing destructive actions
CPU ID FUNCTION:NAME
0 55085 gethostbyname_r:return 4489 Host: va64-v40zh-gmp03
h_aliases 80646ac
0 55085 gethostbyname_r:return 4489 h_alias[0]: 80667a3
0 55085 gethostbyname_r:return 4489 h_alias[1]: 806679a
0 55085 gethostbyname_r:return 0+1 806679a
4489 h_alias[0]: loghost
X 0 0+1 0
0 55085 gethostbyname_r:return Stopping...
: va64-v40zh-gmp03.eu TS 16 $; mdb -p 4489
Loading modules: [ ld.so.1 libc.so.1 ]> 80646ac/4X
0x80646ac: 80667a3 806679a 0
0> 80667a3/s
0x80667a3: loghost> 806679a/s
0x806679a: spamhost>
>From the debugging bits I have added to the SALIAS macro it appear that the
copyinstr is causing the values in self->a[X] and self->a[X+1] to be zerod
but why?
--
This message posted from opensolaris.org
Hi Chris, Scratch space is only valid for the duration of a clause so the scratch space you had the alias pointers in is most likely getting trashed by the copyinstr(). You need to stash the pointers away in something more permanent if you want to access them at a later time. Jon.> Dtracing gethostbyname I''m trying to read the h_alias array and all the entries it points to however every time I copyin an entry pointed to by the first entry in teh h_alias array the other entries in the array get corrupted. > > So I have ended up with this script: > > #!/usr/bin/dtrace -CZs > > #include <netdb.h> > > pid$target::gethostbyname_r:return > { > self->r = (struct hostent *)copyin(arg1, sizeof (struct hostent)); > printf("%d Host: %s", pid, copyinstr((uintptr_t)self->r->h_name)); > printf(" h_aliases %p ", self->r->h_aliases); > self->a = (char **)copyin((uintptr_t)self->r->h_aliases, > 4*sizeof (char *)); > } > #define ALIAS(X) \ > pid$target::gethostbyname_r:return \ > / self->a[X] != 0 / \ > { \ > printf("%d h_alias[%d]: %p", pid, X, (uintptr_t)(self->a[X])); \ > self->my_counter++; \ > } > > #define XSALIAS(X) > #define SALIAS(X) \ > pid$target::gethostbyname_r:return \ > / self->a[X] != 0 / \ > { \ > printf(" X+1 %p\n", self->a[X+1]); \ > printf("%d h_alias[%d]: %s", pid, X, \ > copyinstr((uintptr_t)self->a[X])); \ > printf("\nX %p", self->a[X]); \ > printf(" X+1 %p", self->a[X+1]); \ > self->my_counter--; \ > } > > ALIAS(0) > ALIAS(1) > ALIAS(2) > ALIAS(3) > > SALIAS(0) > SALIAS(1) > SALIAS(2) > SALIAS(3) > > pid$target::gethostbyname_r:return > /self->my_counter/ > { > printf("Stopping...\n"); > stop(); exit(0); > } > > /* END OF SCRIPT */ > > This should print out the array of (upto 4) pointers to h_aliases and then dereference each one. However if it fails to derefrence them is stops the target program and exits. > > : va64-v40zh-gmp03.eu TS 14 $; getent hosts va64-v40zh-gmp03 > 129.156.213.204 va64-v40zh-gmp03 loghost spamhost > : va64-v40zh-gmp03.eu TS 15 $; pfexec /usr/sbin/dtrace -32 -wZCs gethostbynam> > dtrace: script ''gethostbyname.d'' matched 0 probes > dtrace: allowing destructive actions > CPU ID FUNCTION:NAME > 0 55085 gethostbyname_r:return 4489 Host: va64-v40zh-gmp03 h_aliases 80646ac > 0 55085 gethostbyname_r:return 4489 h_alias[0]: 80667a3 > 0 55085 gethostbyname_r:return 4489 h_alias[1]: 806679a > 0 55085 gethostbyname_r:return 0+1 806679a > 4489 h_alias[0]: loghost > X 0 0+1 0 > 0 55085 gethostbyname_r:return Stopping... > > > : va64-v40zh-gmp03.eu TS 16 $; mdb -p 4489 > Loading modules: [ ld.so.1 libc.so.1 ] > >> 80646ac/4X >> > 0x80646ac: 80667a3 806679a 0 0 > >> 80667a3/s >> > 0x80667a3: loghost > >> 806679a/s >> > 0x806679a: spamhost > > > >From the debugging bits I have added to the SALIAS macro it appear that the copyinstr is causing the values in self->a[X] and self->a[X+1] to be zerod but why? > > > -- > This message posted from opensolaris.org > _______________________________________________ > dtrace-discuss mailing list > dtrace-discuss at opensolaris.org >
Thanks Jon. That sorted it out. Allowing the tracing of gethostbyname and gethostbyaddr calls. The results are here: http://blogs.sun.com/chrisg/entry/course_talking -- This message posted from opensolaris.org
Seemingly Similar Threads
- aws-s3 gem install error- bittorrent.rb
- [943] trunk/wxsugar/lib/wx_sugar/enumerable_controls.rb: Fix bug with false positives from #find_string, bounds-checking for
- Missing inet.h and netdb.h for SCO
- Instalar extrafont
- aMSN segfaults at login after configuring my home network