Michael Mueller
2008-Jul-21 09:22 UTC
[dtrace-discuss] size and alignment bug with short in struct?
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 ======================================
Adam Leventhal
2008-Aug-05 18:42 UTC
[dtrace-discuss] size and alignment bug with short in struct?
On Mon, Jul 21, 2008 at 11:22:50AM +0200, Michael Mueller wrote:> The following looks like a bug to me:[ snip ]> everything works as expected. Is this a known bug?That looks like a bug. Please file it if you haven''t already. It would be interesting to see how offsetof() results differed in C and D.> 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?It''s not much better, but we typically do ''dtrace -s /dev/stdin''. - ahl -- Adam Leventhal, Fishworks http://blogs.sun.com/ahl