I''m working on a set of USDT probes and need to expose fairly complex data in a reasonable way. I''d like to build up some compound structures but dtrace doesn''t seem to like translating them :( I boiled the problem down to a simple example: 1 typedef struct simple { 2 uint32_t simplevalue; 3 } simple_t; 4 5 typedef struct complex { 6 simple_t simple; 7 } complex_t; 8 9 translator complex_t < uint32_t x > { 10 simple.simplevalue = x; 11 }; 12 13 dtrace:::BEGIN { 14 printf("simplevalue: %d\n", xlate <complex_t> (2).simple.simplevalue ); 15 } dtrace complains of a syntax error on line 10. Is there a way to do what I want? Thanks, -M
On Wed, Apr 07, 2010 at 05:08:07PM +0200, Mark Phalan wrote:> I''m working on a set of USDT probes and need to expose fairly complex > data in a reasonable way. I''d like to build up some compound structures > but dtrace doesn''t seem to like translating them :(The PID provider and USDT do not give you nice syntactic sugar for handling user-land data. In DTrace probe context all you can do is copyin and interpret as necessary. It''s annoying. In theory the D compiler could generate the necessary DOF code by consuming CTF/DWARF/STABS from the relevant user-land programs and objects; in practice that''s a very difficult thing to pull off (this is the standard answer, and I believe it). Nico --
On 04/ 7/10 06:08 PM, Nicolas Williams wrote:> On Wed, Apr 07, 2010 at 05:08:07PM +0200, Mark Phalan wrote: >> I''m working on a set of USDT probes and need to expose fairly complex >> data in a reasonable way. I''d like to build up some compound structures >> but dtrace doesn''t seem to like translating them :( > > The PID provider and USDT do not give you nice syntactic sugar for > handling user-land data. In DTrace probe context all you can do is > copyin and interpret as necessary. It''s annoying. In theory the D > compiler could generate the necessary DOF code by consuming > CTF/DWARF/STABS from the relevant user-land programs and objects; in > practice that''s a very difficult thing to pull off (this is the standard > answer, and I believe it).But this isn''t about user-land data. The structs I''m talking about are dtrace native structs defined in the d script. In the example I gave I wasn''t even tracing a program - it was pure d. CTF data doesn''t come into it... -M
On Wed, Apr 07, 2010 at 06:15:22PM +0200, Mark Phalan wrote:> But this isn''t about user-land data. The structs I''m talking about > are dtrace native structs defined in the d script. In the example I > gave I wasn''t even tracing a program - it was pure d. CTF data > doesn''t come into it...Duh. Well, this works: 2 typedef struct complex { 3 uint32_t simplevalue; 4 } complex_t; 5 6 translator complex_t < uint32_t x > { 7 simplevalue = x; 8 }; 9 10 dtrace:::BEGIN { 11 printf("simplevalue: %d\n", xlate <complex_t>(2).simplevalue); 12 } I couldn''t get your example to work.
On 04/ 7/10 06:32 PM, Nicolas Williams wrote:> On Wed, Apr 07, 2010 at 06:15:22PM +0200, Mark Phalan wrote: >> But this isn''t about user-land data. The structs I''m talking about >> are dtrace native structs defined in the d script. In the example I >> gave I wasn''t even tracing a program - it was pure d. CTF data >> doesn''t come into it... > > Duh. Well, this works: > > 2 typedef struct complex { > 3 uint32_t simplevalue; > 4 } complex_t; > 5 > 6 translator complex_t< uint32_t x> { > 7 simplevalue = x; > 8 }; > 9 > 10 dtrace:::BEGIN { > 11 printf("simplevalue: %d\n", xlate<complex_t>(2).simplevalue); > 12 } >I guess I wasn''t too clear.. I don''t have any problems writing translators for "simple" structs. My problem is when the struct contains another struct which I''d like to initialize/set in the translator.> I couldn''t get your example to work.Right. I was wondering if someone knew if it was possible to modify my example to get it to work. I think this should be possible and if it''s not currently then I''ll probably open a CR for it. -M
On Wed, Apr 07, 2010 at 06:41:35PM +0200, Mark Phalan wrote:> I guess I wasn''t too clear.. I don''t have any problems writing > translators for "simple" structs. My problem is when the struct > contains another struct which I''d like to initialize/set in the > translator.No, it was clear the second time.> >I couldn''t get your example to work. > > Right. I was wondering if someone knew if it was possible to modify my > example to get it to work. I think this should be possible and if > it''s not currently then I''ll probably open a CR for it.It may well be that translator output types have to have simple members. That''s my impression anyways. The examples in /usr/lib/dtrace/ that I looked at have simple members. Nico --
On 04/ 7/10 07:17 PM, Nicolas Williams wrote:> On Wed, Apr 07, 2010 at 06:41:35PM +0200, Mark Phalan wrote: >> I guess I wasn''t too clear.. I don''t have any problems writing >> translators for "simple" structs. My problem is when the struct >> contains another struct which I''d like to initialize/set in the >> translator. > > No, it was clear the second time. > >>> I couldn''t get your example to work. >> >> Right. I was wondering if someone knew if it was possible to modify my >> example to get it to work. I think this should be possible and if >> it''s not currently then I''ll probably open a CR for it. > > It may well be that translator output types have to have simple members. > That''s my impression anyways. The examples in /usr/lib/dtrace/ that I > looked at have simple members.Pity.. guess I''ll have to open an RFE. Thanks, -M