The following looks like a bug to me:
--- C program tst.c ----------------------------------
struct s1 {
int x;
short a;
};
struct s2 {
struct s1 b;
short c;
int d;
} s = {
{ 1, 0x0102 },
0x0304,
0x05060708
};
void
fun(struct s2 *p)
{
printf(" sizeof(struct s1) = %d\n", sizeof(struct s1));
printf(" sizeof(struct s2) = %d\n", sizeof(struct s2));
printf(" b.a %04x, c %04x, d %08x\n\n", p->b.a, p->c, p->d);
}
int
main()
{
fun(&s);
return 0;
}
--- dtrace script ------------------------------
/usr/sbin/dtrace -q -s /dev/fd/0 -c tst <<'eof'
struct s1 {
int x;
short a;
};
struct s2 {
struct s1 b;
short c;
int d;
};
pid$target::fun:entry
{
printf("** sizeof(struct s1) = %d\n", sizeof(struct s1));
printf("** sizeof(struct s2) = %d\n", sizeof(struct s2));
p = (struct s2 *)copyin(arg0, sizeof(struct s2));
printf("** b.a %04x, c %04x, d %08x\n", p->b.a, p->c, p->d);
}
eof
--- output -------------------------------------
sizeof(struct s1) = 8
sizeof(struct s2) = 16
b.a 0102, c 0304, d 05060708
** sizeof(struct s1) = 6
** sizeof(struct s2) = 12
** b.a 0102, c 0000, d 03040000
-------------------------------------------------
Dtrace shows wrong sizes for struct s1 and s2 and consequently accesses
the wrong locations and outputs the wrong data. After adding a short to
the end of s1 in the dtrace script (not in the C program)
struct s1 {
int x;
short a;
short dummy;
};
everything works as expected. Is this a known bug?
Another question: Is there a simple way of making dtrace read from
stdin? Having to use "dtrace -s /dev/fd/0" in the above script is a bit
unusual for a unix tool. Implementing something like "dtrace -s -"
should be easy I guess?
Michael
=== Michael Mueller ==================
Tel. + 49 8171 63600
Fax. + 49 8171 63615
Web: http://www.michael-mueller-it.de
======================================
_______________________________________________
dtrace-discuss mailing list
[email protected]