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)
}


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")
}


Reply via email to