This is the mail archive of the systemtap@sourceware.org mailing list for the systemtap project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Issue related to systemtap output in guru mode


On Tue, 2007-09-18 at 19:50 +0530, ramya rao wrote:
> Hi,
> 
> We have an issue regarding the usage of systemtap in Guru mode.
> 
> When using systemtap in guru mode, we could not use  printf statement.

The problem is that you're using printf inside an embedded-C function.
See below.

> 
> The compilation stage failed. When we checked with more -v options, we
> observed that an error was generated because of inclusion of printf
> statement.
> 
> I would like to illustrate with a simple example as shown below:
> 
> Code snippet for hello world program
> 
> #!/usr/bin/stap -g
> 
> //hello_world.stp - prints hello world
> 
> function print_hello() %{
> 
>             printf ("Hello World\n");
> 
> %}

Change "%{" to "{" and change "%}" to "}", and this will work.  (You
don't even need guru mode.)

Code between %{ ... %} is interpreted as embedded C code, to be included
as-is in the stap-generated kernel module.  Since the kernel has no
printf function, this yields an error.

printf, as used in SystemTap scripts, is basically built into the
SystemTap language.

> 
> probe begin {
> 
> 
> 
>             print ("Test program\n")
> 
>             print_hello()
> 
> }
> 
> 
> Following observations were made:
> 
> 
> 
> 1. When we executed the program with -vv option, we observed following
> error message:
> 
> /tmp/stapivivxS/stap_a2609c1ce06492087c58daddf95c569a_258.c: In
> function 'function_print_hello':
> 
> /tmp/stapivivxS/stap_a2609c1ce06492087c58daddf95c569a_258.c:105:
> error: implicit declaration of function 'printf'
> 
> make[1]: *** [/tmp/stapivivxS/stap_a2609c1ce06492087c58daddf95c569a_258.o]
> Error 1
> 
> make: *** [_module_/tmp/stapivivxS] Error 2
> 
> make: Leaving directory `/usr/src/linux-2.6.16.46-0.12'
> 
> Pass 4: compiled C into "stap_a2609c1ce06492087c58daddf95c569a_258.ko"
> in 480usr/80sys/595real ms.
> 
> Pass 4: compilation failed.  Try again with more '-v' (verbose) options.
> 
> Running rm -rf /tmp/stapivivxS
> 
> 
> 
> 2. Then we included the stdio.h file as well as shown below
> %{ #include <stdio.h> %}
> 
> 
> 
> However we observed following error messages:
> 
>  /tmp/stapaMIET3/stap_a71619a8fd49b440ead016c3a87d8b4e_306.c:94:19:
> error: stdio.h: No such file or directory

Yes, because the kernel has no stdio.h header file.

> 
> /tmp/stapaMIET3/stap_a71619a8fd49b440ead016c3a87d8b4e_306.c: In
> function 'function_print_hello':
> 
> /tmp/stapaMIET3/stap_a71619a8fd49b440ead016c3a87d8b4e_306.c:109:
> error: implicit declaration of function 'printf'
> 
> make[1]: *** [/tmp/stapaMIET3/stap_a71619a8fd49b440ead016c3a87d8b4e_306.o]
> Error 1
> 
> make: *** [_module_/tmp/stapaMIET3] Error 2
> 
> make: Leaving directory `/usr/src/linux-2.6.16.46-0.12'
> 
> Pass 4: compiled C into "stap_a71619a8fd49b440ead016c3a87d8b4e_306.ko"
> in 490usr/70sys/575real ms.
> 
> Pass 4: compilation failed.  Try again with more '-v' (verbose) options.
> 
> Running rm -rf /tmp/stapaMIET3
> 
> 
> 
>  3. However the program works fine if we use printk in place of printf
> function, output messages appear in /var/log/messages. But we would
> like to have the output to appear on the console.

printf is the right function to use.  As always, please let us know if
you see other problems.

> 
> 
> Can any one please suggest how to display the information on console
> when we are using systemtap in Guru Mode.?
> 
> 
> Regards,
> 
> Ramya

Jim Keniston
IBM Linux Technology Center
Beaverton, OR


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]