Discussion:
compilation, types and include files
Vladimir Kotal
2011-04-14 10:19:03 UTC
Permalink
Hi again,

I am trying to construct set of scripts with common translator
definitions stored in separate header file (so that all the scripts can
use it):

$ cat xlate.h

#include <sys/types.h>

inline string state_string[int32_t state] =
state == 0 ? "initial" :
state == 1 ? "other" :
state == 2 ? "next" :
"<unknown>";

$ cat state.d
#!/usr/sbin/dtrace -I. -Cs

#include "xlate.h"

BEGIN
{
printf("%s", state_string[1]);
}


However, it fails with:

$ chmod +x ./state.d
$ ./state.d
dtrace: no probes specified
$ dtrace -I. -Cs state.d
dtrace: failed to compile script state.d: "./xlate.h", line 8: failed to
resolve type string: Unknown type name

If I concatenate the 2 files together it works fine:

$ cat concat.d
inline string state_string[int32_t state] =
state == 0 ? "initial" :
state == 1 ? "other" :
state == 2 ? "next" :
"<unknown>";

BEGIN
{
printf("%s", state_string[1]);
}

$ dtrace -s concat.d
dtrace: script 'concat.d' matched 1 probe
CPU ID FUNCTION:NAME
1 1 :BEGIN other
^C

Any clues what I am doing wrong ?


v.
Adam Leventhal
2011-04-14 17:35:02 UTC
Permalink
Post by Vladimir Kotal
#!/usr/sbin/dtrace -I. -Cs
The kernel only picks up one argument from the #! line. You can use
#pragma incdir instead of the -I option.

Adam
--
Adam Leventhal, Delphix
http://dtrace.org/blogs/ahl

275 Middlefield Road, Suite 50
Menlo Park, CA 94025
http://www.delphix.com
Vladimir Kotal
2011-04-27 10:01:16 UTC
Permalink
Post by Adam Leventhal
Post by Vladimir Kotal
#!/usr/sbin/dtrace -I. -Cs
The kernel only picks up one argument from the #! line. You can use
#pragma incdir instead of the -I option.
I can't get this to work. If I remove the include line and header from
state.d and run it like this:

dtrace -I. -Cs state.d

it reports the same error:

dtrace: failed to compile script state.d: "./xlate.h", line 7: failed to
resolve type string: Unknown type name

Even if I remove the include <sys/types.h> from xlate.h and convert all
int<x>_t types to plain int it reports the same:

dtrace: failed to compile script state.d: "./xlate.h", line 5: failed to
resolve type string: Unknown type name

I also tried the incdir pragma option but this failed too:

$ cat state.d
#pragma D option incdir=.
#pragma D option cpp

#include "xlate.h"

BEGIN
{
printf("%s", state_string[1]);
}

$ dtrace -s state.d
dtrace: failed to compile script state.d: line 1: failed to set option
'incdir' to '.': Option cannot be used from within a D program


Maybe I should try to avoid the string type ?


v.

Loading...