Hi, dtracers. Sometimes I have trouble with dtracing at complicated structure access. DTrace seems to make mistakes at calculation of: (1) nested structures'' alignment (2) total size of structure, which has un-aligned field at the end of it Bugster 6734858 seems to be as same as (2) of my problems. # http://bugs.opensolaris.org/bugdatabase/view_bug.do?bug_id=6734858 I think these mistakes are caused by: (1) ctf_type_align() does not care about structure fields other than first (2) ctf_type_size() does not calculate tail padding for alignment and I confirmed these are fixed by the patch attached to this post, on OpenSolaris 2009.06, with onnv_111 sources. Please comment on these problems and my patch ! -- This message posted from opensolaris.org -------------- next part -------------- A non-text attachment was scrubbed... Name: ctf_badalign.patch Type: application/octet-stream Size: 990 bytes Desc: not available URL: <http://mail.opensolaris.org/pipermail/dtrace-discuss/attachments/20100417/e14c54d0/attachment.obj>
You can reporoduce problem easily by D script shown below. ===============struct foo { /* size: */ char f1; /* 1 */ /* 3 (padding for alignemt of f2) */ void* f2; /* 4 (for 32bit env) */ }; /* => 8 */ struct bar { /* size: */ char b1; /* 1 */ /* 3 (padding for alignment of f2) */ struct foo b2; /* 8 */ }; /* => 12 */ struct baz { /* size: */ void* b1; /* 4 (for 32bit env) */ char b2; /* 1 */ /* 3 (padding for alignemt of next array element) */ }; /* => 8 */ BEGIN { printf("sizeof(struct foo)=%d\n", sizeof(struct foo)); printf("sizeof(struct bar)=%d\n", sizeof(struct bar)); printf("sizeof(struct baz)=%d\n", sizeof(struct baz)); exit(0); } =============== For C/C++ compatibility: (1) "sizeof(struct bar)" must be 12, but 9. "3 bytes padding" before "b2" seems to be ignored. (2) "sizeof(struct baz)" must be 8, but 5. "3 bytes padding" after "b2" seems to be ignored. -- This message posted from opensolaris.org