This is the mail archive of the
systemtap@sourceware.org
mailing list for the systemtap project.
Re: How can I user @cast in the user-space's program or have other ways to aasign valus to the user-space pointer to a structure.
- From: David Smith <dsmith at redhat dot com>
- To: Liu Tianhao <tianhaox dot liu at intel dot com>
- Cc: utrace-devel at redhat dot com, Systemtap List <systemtap at sourceware dot org>
- Date: Tue, 27 Mar 2012 13:11:33 -0500
- Subject: Re: How can I user @cast in the user-space's program or have other ways to aasign valus to the user-space pointer to a structure.
- References: <loom.20120327T050452-561@post.gmane.org>
Liu,
This is really a question for the systemtap list, not the utrace list.
Forwarding there. Also see possible answer below.
On 03/26/2012 10:06 PM, Liu Tianhao wrote:
> I have a problem to cast a pointer to a structure in the user-spaceâs program.
> It always report âERROR: kernel write fault at 0x0000000000400675 (addr) near
> identifier '@cast' at test.stp:3:8â.
>
> Compile the source file and execute the stap command.
> liuth@liuthivb:~/$ gcc -g -o test test.c
> liuth@liuthivb:~/$ sudo stap -w -vg test.stp -c ./test
> Pass 1: parsed user script and 81 library script(s) using
> 49344virt/22060res/2024shr kb, in 130usr/0sys/125real ms.
> Pass 2: analyzed script: 2 probe(s), 9 function(s), 0 embed(s), 0 global(s)
> using 51992virt/23168res/2540shr kb, in 10usr/0sys/5real ms.
> Pass 3: using
> cached /home/liuth/.systemtap/cache/5c/stap_5c288dc4a44724d509924f222aedb626_90
> 50.c
> Pass 4: using
> cached /home/liuth/.systemtap/cache/5c/stap_5c288dc4a44724d509924f222aedb626_90
> 50.ko
> Pass 5: starting run.
> hello world
> call------------------------------call
> The value of a:[F] The value of b:[10]
> call------------------------------call
> ERROR: kernel write fault at 0x00000000004005b5 (addr) near identifier '@cast'
> at test.stp:3:8
> Pass 5: run completed in 10usr/0sys/589real ms.
> Pass 5: run failed. Try again with another '--vp 00001' option.
>
> I have modified the test.stp as follows.
> probe process
> ("/home/liuth/worksource/ddtv/tracedrv/java/DDTVConfig/test").function
> ("funcStruct").call
> {
> // compilation error
> // @cast($pStruct, "struct TestStruct", "test.h ")->a = 31
> //@cast($pStruct, "struct TestStruct", "test.h ")->b = 32
>
> // ERROR: kernel write fault at 0x00000000004005b5 (addr) near
> identifier '@cast' at test.stp:3:8
> //@cast($pStruct, "struct TestStruct", "<test.h> ")->a = 31
> //@cast($pStruct, "struct TestStruct", "<test.h> ")->b = 32
>
> // ERROR: kernel read fault at 0x000000200000001f (addr) near
> identifier '$pStruct' at test.stp:5:60
> //@cast(&$pStruct, "struct TestStruct", "<test.h> ")->a = 31
> //@cast(&$pStruct, "struct TestStruct", "<test.h> ")->b = 32
>
> @cast($pStruct, "struct TestStruct")->a = 31
> @cast($pStruct, "struct TestStruct")->b = 32
> printf("The value of a:[%X] The value of b:[%X]\n", $pStruct->a,
> $pStruct->b)
> }
Hmm, what happens when you just use the pointer directly, like this:
$pStruct->a = 31
$pStruct->b = 32
> The following are the program and the script.
> -------------------------------------------------------------------------------
> -------------------------------------------------------------------------------
> -----
> Header file test.h:
> #include <stdlib.h>
> #include <stdio.h>
> typedef struct TestStruct
> {
> int a;
> int b;
> }ST_Test_Struct;
>
> //int func(int a, int b, int c)
> int func(ST_Test_Struct tmpStruct);
> int funcStruct(ST_Test_Struct* pStruct);
>
> source file test.c:
> #include "test.h"
> int func(ST_Test_Struct tmpStruct)
> {
> return tmpStruct.a + tmpStruct.b;
> }
>
> int funcStruct(ST_Test_Struct* pStruct)
> {
> return pStruct->a + pStruct->b;
> }
>
> int main(int argc, char** argv)
> {
> ST_Test_Struct tmpStruct = { 1,2 };
> func(tmpStruct);
> funcStruct(&tmpStruct);
> printf("hello world\n");
> return 0;
> }
>
> script test.stp:
> probe process
> ("/home/liuth/worksource/ddtv/tracedrv/java/DDTVConfig/test").function
> ("funcStruct").call
> {
> @cast($pStruct, "struct TestStruct")->a = 31
> @cast($pStruct, "struct TestStruct")->b = 32
> printf("The value of a:[%X] The value of b:[%X]\n", $pStruct->a,
> $pStruct->b)
> }
> probe process
> ("/home/liuth/worksource/ddtv/tracedrv/java/DDTVConfig/test").function
> ("func").call
> {
> printf("call------------------------------call\n")
> $tmpStruct->a =15;
> $tmpStruct->b =16;
> printf("The value of a:[%X] The value of b:[%X]\n", $tmpStruct->a,
> $tmpStruct->b)
> printf("call------------------------------call\n")
> }
>
>
--
David Smith
dsmith@redhat.com
Red Hat
http://www.redhat.com
256.217.0141 (direct)
256.837.0057 (fax)