I meet errors when I modify the return value or parameters of userspace function by systemtap

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

I meet errors when I modify the return value or parameters of userspace function by systemtap

张威
I meet errors when I modify the return value or parameters of userspace function by systemtap.

My test program is as follows:

#include <stdio.h>

int func(int *p, int val)
{
        printf("p=%p val=%d\n", p, val);
        return 1;
}

int main()
{
        int a = 7;
        func(&a, a);
        return 0;
}

gcc -g -o test test.c

I try:

# stap -e 'probe process("./test").function("func").return { $return = 8}' -g
It report:

In file included from /usr/local/share/systemtap/runtime/linux/runtime.h:217:0,
                 from /usr/local/share/systemtap/runtime/runtime.h:26,
                 from /tmp/stapT3qC74/stap_9773c65134daae52581873c5e83f3c28_1223_src.c:26:
/tmp/stapT3qC74/stap_9773c65134daae52581873c5e83f3c28_1223_src.c: In function ‘function___private__input___dwarf_tvar_set_return_0’:
root@redis-server1:/home/fit508/test# stap -e 'probe process("./test").function("func").return { $return = 8}' -g
In file included from /usr/local/share/systemtap/runtime/linux/runtime.h:217:0,
                 from /usr/local/share/systemtap/runtime/runtime.h:26,
                 from /tmp/stapMDBcSh/stap_9773c65134daae52581873c5e83f3c28_1223_src.c:26:
/tmp/stapMDBcSh/stap_9773c65134daae52581873c5e83f3c28_1223_src.c: In function ‘function___private__input___dwarf_tvar_set_return_0’:
/usr/local/share/systemtap/runtime/linux/loc2c-runtime.h:297:69: error: ‘regnoo’ undeclared (first use in this function); did you mean ‘rep_nop’?
 #define u_store_register(regno,value) check_store_register(c->uregs,regnoo,_stp_is_compat_task()?ARRAY_SIZE(url_i386):ARRAY_SIZE(url_x86_64),value,uu_store_register)
                                                                     ^
/usr/local/share/systemtap/runtime/linux/loc2c-runtime.h:44:23: note: in definition of macro ‘check_store_register’
   if ((regs) == 0 || (regno) < 0 || (regno) > (maxregno)) {      \
                       ^~~~~
/tmp/stapMDBcSh/stap_9773c65134daae52581873c5e83f3c28_1223_src.c:182:3: note: in expansion of macro ‘u_store_register’
   u_store_register(0, l->__tmp0);
   ^~~~~~~~~~~~~~~~
/usr/local/share/systemtap/runtime/linux/loc2c-runtime.h:297:69: note: each undeclared identifier is reported only once for each function it appears in
 #define u_store_register(regno,value) check_store_register(c->uregs,regnoo,_stp_is_compat_task()?ARRAY_SIZE(url_i386):ARRAY_SIZE(url_x86_64),value,uu_store_register)
                                                                     ^
/usr/local/share/systemtap/runtime/linux/loc2c-runtime.h:44:23: note: in definition of macro ‘check_store_register’
   if ((regs) == 0 || (regno) < 0 || (regno) > (maxregno)) {      \
                       ^~~~~
/tmp/stapMDBcSh/stap_9773c65134daae52581873c5e83f3c28_1223_src.c:182:3: note: in expansion of macro ‘u_store_register’
   u_store_register(0, l->__tmp0);
   ^~~~~~~~~~~~~~~~
scripts/Makefile.build:330: recipe for target '/tmp/stapMDBcSh/stap_9773c65134daae52581873c5e83f3c28_1223_src.o' failed
make[1]: *** [/tmp/stapMDBcSh/stap_9773c65134daae52581873c5e83f3c28_1223_src.o] Error 1
Makefile:1577: recipe for target '_module_/tmp/stapMDBcSh' failed
make: *** [_module_/tmp/stapMDBcSh] Error 2
WARNING: kbuild exited with status: 2
Pass 4: compilation failed.  [man error::pass4]
but I can trace its return value of funcion, it work well:

# stap -e 'probe process("./test").function("func").returnntf("%d\n", $return);}' -g
1
So, I want to ask if i can modify the return value of the user space function, just like system call function example in http://www.programmersought.com/article/9329729776/.

my os is :ubuntu 18.04, kernel is 4.15.0-96
systemtap version: 4.2
gcc version: gcc (Ubuntu 7.5.0-3ubuntu1~18.04) 7.5.0


--
-------------------------------------------------------------------------------
Zhang Wei  
Email. [hidden email]
*******************************************************
Reply | Threaded
Open this post in threaded view
|

Re: I meet errors when I modify the return value or parameters of userspace function by systemtap

Sourceware - systemtap mailing list
张威 <[hidden email]> writes:

> /usr/local/share/systemtap/runtime/linux/loc2c-runtime.h:297:69: error: ‘regnoo’ undeclared (first use in this function); did you mean ‘rep_nop’?
> [...]

You're doing nothing wrong; we had a typo.  The following patch fixes
it.  You can hand-apply the change to your copy of
/usr/share/systemtap/runtime/linux/loc2c-runtime.h .

commit ccad93fd0f81851fd69ff0257c6010a8d1984c8c
Author: HATAYAMA Daisuke <[hidden email]>
Date:   Fri Feb 7 04:07:21 2020 +0000

https://sourceware.org/git/?p=systemtap.git;a=commitdiff;h=ccad93fd0f81851fd69ff0257c6010a8d1984c8c

- FChE