* Run system tap with a user defined function
@ 2022-08-07 16:09 Yeshpal Jain
2022-08-08 9:30 ` Bryn M. Reeves
2022-08-16 17:53 ` Frank Ch. Eigler
0 siblings, 2 replies; 5+ messages in thread
From: Yeshpal Jain @ 2022-08-07 16:09 UTC (permalink / raw)
To: systemtap
I want to run a user defined function inside one of the function probes.
for ex :
#! /usr/bin/env stap
function __read_phase:long(phase:long) %{ /* pure */
struct phase *phase_s = (struct phase *)((long)STAP_ARG_phase);
int phase_st = phase->p_state;
STAP_RETURN(phase_st);
%} /* <-- function body */
function trace_phase(entry_p, extra) {
%( $# > 1 %? if (tid() in trace) %)
printf("%s%s%s %s phase = %d\n",
thread_indent (entry_p),
(entry_p>0?"->":"<-"),
ppfunc (),
extra, __read_phase($fom))
}
probe process("/root/test/.libs/mylib.so").function("*_test_func").call {
trace_phase(1, $$parms) }
i am running stap with -g option,
when i compile i am getting error,
error: dereferencing pointer to incomplete type ‘struct phase’
struct phase is a structure defined in mylibrary,
Is there a way to include custom directory/headers while generating system
tap.
--
Thanks and Regards,
Yeshpal Jain.
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: Run system tap with a user defined function
2022-08-07 16:09 Run system tap with a user defined function Yeshpal Jain
@ 2022-08-08 9:30 ` Bryn M. Reeves
2022-08-09 5:17 ` Yeshpal Jain
2022-08-16 17:53 ` Frank Ch. Eigler
1 sibling, 1 reply; 5+ messages in thread
From: Bryn M. Reeves @ 2022-08-08 9:30 UTC (permalink / raw)
To: Yeshpal Jain; +Cc: systemtap
On Sun, Aug 07, 2022 at 09:39:23PM +0530, Yeshpal Jain via Systemtap wrote:
> I want to run a user defined function inside one of the function probes.
> for ex :
> #! /usr/bin/env stap
>
>
> function __read_phase:long(phase:long) %{ /* pure */
> struct phase *phase_s = (struct phase *)((long)STAP_ARG_phase);
> int phase_st = phase->p_state;
> STAP_RETURN(phase_st);
> %} /* <-- function body */
>
> function trace_phase(entry_p, extra) {
> %( $# > 1 %? if (tid() in trace) %)
> printf("%s%s%s %s phase = %d\n",
> thread_indent (entry_p),
> (entry_p>0?"->":"<-"),
> ppfunc (),
> extra, __read_phase($fom))
>
> }
>
> probe process("/root/test/.libs/mylib.so").function("*_test_func").call {
> trace_phase(1, $$parms) }
>
> i am running stap with -g option,
> when i compile i am getting error,
> error: dereferencing pointer to incomplete type ‘struct phase’
> struct phase is a structure defined in mylibrary,
> Is there a way to include custom directory/headers while generating system
> tap.
Just put the include directives inside %{..%} at file level, e.g.:
%{
#include <myheader.h>
%}
... rest of script
Regards,
Bryn.
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: Run system tap with a user defined function
2022-08-08 9:30 ` Bryn M. Reeves
@ 2022-08-09 5:17 ` Yeshpal Jain
2022-08-12 7:16 ` Yeshpal Jain
0 siblings, 1 reply; 5+ messages in thread
From: Yeshpal Jain @ 2022-08-09 5:17 UTC (permalink / raw)
To: Bryn M. Reeves; +Cc: systemtap
Thanks for your reply,
Is there a way i can add my header path in stap common so that it looks in
my header path, when i try to add a header it is erroring out because other
files in myheader.h are not accessible, if somehow i can include the header
path in compilation command then that should resolve this problem.
Below is the command which stap will execute.
gcc -Wp,-MD,/tmp/stap0qTelA/.stap_symbols.o.d -nostdinc -isystem
/usr/lib/gcc/x86_64-redhat-linux/8/include -I./arch/x86/include
-I./arch/x86/include/generated -I./include/drm-backport -I./include
-I./arch/x86/include/uapi -I./arch/x86/include/generated/uapi
-I./include/uapi -I./include/generated/uapi -include
./include/linux/kconfig.h -include ./include/linux/compiler_types.h
-D__KERNEL__ -Wall -Wundef -Wstrict-prototypes -Wno-trigraphs
-fno-strict-aliasing -fno-common -fshort-wchar
-Werror-implicit-function-declaration -Wno-format-security -std=gnu89
-fno-PIE -DCC_HAVE_ASM_GOTO -mno-sse -mno-mmx -mno-sse2 -mno-3dnow -mno-avx
-m64 -falign-jumps=1 -falign-loops=1 -mno-80387 -mno-fp-ret-in-387
-mpreferred-stack-boundary=3 -mskip-rax-setup -mtune=generic -mno-red-zone
-mcmodel=kernel -funit-at-a-time -DCONFIG_AS_CFI=1
-DCONFIG_AS_CFI_SIGNAL_FRAME=1 -DCONFIG_AS_CFI_SECTIONS=1
-DCONFIG_AS_FXSAVEQ=1 -DCONFIG_AS_SSSE3=1 -DCONFIG_AS_CRC32=1
-DCONFIG_AS_AVX=1 -DCONFIG_AS_AVX2=1 -DCONFIG_AS_AVX512=1
-DCONFIG_AS_SHA1_NI=1 -DCONFIG_AS_SHA256_NI=1 -DCONFIG_TPAUSE=1 -pipe
-Wno-sign-compare -fno-asynchronous-unwind-tables
-mindirect-branch=thunk-extern -mindirect-branch-register -fno-jump-tables
-fno-delete-null-pointer-checks -Wno-frame-address -Wno-format-truncation
-Wno-format-overflow -Wno-int-in-bool-context -O2
--param=allow-store-data-races=0 -Wframe-larger-than=2048
-fstack-protector-strong -Wno-unused-but-set-variable
-Wno-unused-const-variable -gdwarf-4 -pg -mrecord-mcount -mfentry
-DCC_USING_FENTRY -fno-inline-functions-called-once
-Wdeclaration-after-statement -Wno-pointer-sign -Wno-stringop-truncation
-fno-strict-overflow -fno-merge-all-constants -fmerge-constants
-fno-stack-check -fconserve-stack -Werror=implicit-int
-Werror=strict-prototypes -Werror=date-time
-Werror=incompatible-pointer-types -Werror=designated-init
-fmacro-prefix-map=./= -Wno-packed-not-aligned -Iinclude2/asm/mach-default
-I/lib/modules/4.18.0-305.3.1.el8_4.x86_64/build -include
/tmp/stap0qTelA/stapconf_ee8a8c12ef5d50607466e03c8831c981_784.h
-freorder-blocks -fasynchronous-unwind-tables -fno-ipa-icf -Wno-unused
-Werror -Wno-pragmas -Wno-pointer-to-int-cast -Wno-int-to-pointer-cast
-I/usr/share/systemtap/runtime -DMODULE
-DKBUILD_BASENAME='"stap_symbols"' -DKBUILD_MODNAME='"stap_3268232"' -c -o
/tmp/stap0qTelA/stap_symbols.o /tmp/stap0qTelA/stap_symbols.c
Regards,
Yeshpal.
On Mon, Aug 8, 2022 at 3:00 PM Bryn M. Reeves <breeves@redhat.com> wrote:
> On Sun, Aug 07, 2022 at 09:39:23PM +0530, Yeshpal Jain via Systemtap wrote:
> > I want to run a user defined function inside one of the function probes.
> > for ex :
> > #! /usr/bin/env stap
> >
> >
> > function __read_phase:long(phase:long) %{ /* pure */
> > struct phase *phase_s = (struct phase *)((long)STAP_ARG_phase);
> > int phase_st = phase->p_state;
> > STAP_RETURN(phase_st);
> > %} /* <-- function body */
> >
> > function trace_phase(entry_p, extra) {
> > %( $# > 1 %? if (tid() in trace) %)
> > printf("%s%s%s %s phase = %d\n",
> > thread_indent (entry_p),
> > (entry_p>0?"->":"<-"),
> > ppfunc (),
> > extra, __read_phase($fom))
> >
> > }
> >
> > probe process("/root/test/.libs/mylib.so").function("*_test_func").call
> {
> > trace_phase(1, $$parms) }
> >
> > i am running stap with -g option,
> > when i compile i am getting error,
> > error: dereferencing pointer to incomplete type ‘struct phase’
> > struct phase is a structure defined in mylibrary,
> > Is there a way to include custom directory/headers while generating
> system
> > tap.
>
> Just put the include directives inside %{..%} at file level, e.g.:
>
> %{
> #include <myheader.h>
> %}
>
> ... rest of script
>
> Regards,
> Bryn.
>
>
--
Thanks and Regards,
Yeshpal Jain.
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: Run system tap with a user defined function
2022-08-09 5:17 ` Yeshpal Jain
@ 2022-08-12 7:16 ` Yeshpal Jain
0 siblings, 0 replies; 5+ messages in thread
From: Yeshpal Jain @ 2022-08-12 7:16 UTC (permalink / raw)
To: Bryn M. Reeves; +Cc: systemtap
I mean,is there a way i can include my project header path while running
stap to avoid compilation error related to header inclusion.
Regards,
Yeshpal.
On Tue, Aug 9, 2022 at 10:47 AM Yeshpal Jain <jainyeshpal@gmail.com> wrote:
> Thanks for your reply,
> Is there a way i can add my header path in stap common so that it looks in
> my header path, when i try to add a header it is erroring out because other
> files in myheader.h are not accessible, if somehow i can include the header
> path in compilation command then that should resolve this problem.
> Below is the command which stap will execute.
>
> gcc -Wp,-MD,/tmp/stap0qTelA/.stap_symbols.o.d -nostdinc -isystem
> /usr/lib/gcc/x86_64-redhat-linux/8/include -I./arch/x86/include
> -I./arch/x86/include/generated -I./include/drm-backport -I./include
> -I./arch/x86/include/uapi -I./arch/x86/include/generated/uapi
> -I./include/uapi -I./include/generated/uapi -include
> ./include/linux/kconfig.h -include ./include/linux/compiler_types.h
> -D__KERNEL__ -Wall -Wundef -Wstrict-prototypes -Wno-trigraphs
> -fno-strict-aliasing -fno-common -fshort-wchar
> -Werror-implicit-function-declaration -Wno-format-security -std=gnu89
> -fno-PIE -DCC_HAVE_ASM_GOTO -mno-sse -mno-mmx -mno-sse2 -mno-3dnow -mno-avx
> -m64 -falign-jumps=1 -falign-loops=1 -mno-80387 -mno-fp-ret-in-387
> -mpreferred-stack-boundary=3 -mskip-rax-setup -mtune=generic -mno-red-zone
> -mcmodel=kernel -funit-at-a-time -DCONFIG_AS_CFI=1
> -DCONFIG_AS_CFI_SIGNAL_FRAME=1 -DCONFIG_AS_CFI_SECTIONS=1
> -DCONFIG_AS_FXSAVEQ=1 -DCONFIG_AS_SSSE3=1 -DCONFIG_AS_CRC32=1
> -DCONFIG_AS_AVX=1 -DCONFIG_AS_AVX2=1 -DCONFIG_AS_AVX512=1
> -DCONFIG_AS_SHA1_NI=1 -DCONFIG_AS_SHA256_NI=1 -DCONFIG_TPAUSE=1 -pipe
> -Wno-sign-compare -fno-asynchronous-unwind-tables
> -mindirect-branch=thunk-extern -mindirect-branch-register -fno-jump-tables
> -fno-delete-null-pointer-checks -Wno-frame-address -Wno-format-truncation
> -Wno-format-overflow -Wno-int-in-bool-context -O2
> --param=allow-store-data-races=0 -Wframe-larger-than=2048
> -fstack-protector-strong -Wno-unused-but-set-variable
> -Wno-unused-const-variable -gdwarf-4 -pg -mrecord-mcount -mfentry
> -DCC_USING_FENTRY -fno-inline-functions-called-once
> -Wdeclaration-after-statement -Wno-pointer-sign -Wno-stringop-truncation
> -fno-strict-overflow -fno-merge-all-constants -fmerge-constants
> -fno-stack-check -fconserve-stack -Werror=implicit-int
> -Werror=strict-prototypes -Werror=date-time
> -Werror=incompatible-pointer-types -Werror=designated-init
> -fmacro-prefix-map=./= -Wno-packed-not-aligned -Iinclude2/asm/mach-default
> -I/lib/modules/4.18.0-305.3.1.el8_4.x86_64/build -include
> /tmp/stap0qTelA/stapconf_ee8a8c12ef5d50607466e03c8831c981_784.h
> -freorder-blocks -fasynchronous-unwind-tables -fno-ipa-icf -Wno-unused
> -Werror -Wno-pragmas -Wno-pointer-to-int-cast -Wno-int-to-pointer-cast
> -I/usr/share/systemtap/runtime -DMODULE
> -DKBUILD_BASENAME='"stap_symbols"' -DKBUILD_MODNAME='"stap_3268232"' -c -o
> /tmp/stap0qTelA/stap_symbols.o /tmp/stap0qTelA/stap_symbols.c
>
> Regards,
> Yeshpal.
>
> On Mon, Aug 8, 2022 at 3:00 PM Bryn M. Reeves <breeves@redhat.com> wrote:
>
>> On Sun, Aug 07, 2022 at 09:39:23PM +0530, Yeshpal Jain via Systemtap
>> wrote:
>> > I want to run a user defined function inside one of the function probes.
>> > for ex :
>> > #! /usr/bin/env stap
>> >
>> >
>> > function __read_phase:long(phase:long) %{ /* pure */
>> > struct phase *phase_s = (struct phase *)((long)STAP_ARG_phase);
>> > int phase_st = phase->p_state;
>> > STAP_RETURN(phase_st);
>> > %} /* <-- function body */
>> >
>> > function trace_phase(entry_p, extra) {
>> > %( $# > 1 %? if (tid() in trace) %)
>> > printf("%s%s%s %s phase = %d\n",
>> > thread_indent (entry_p),
>> > (entry_p>0?"->":"<-"),
>> > ppfunc (),
>> > extra, __read_phase($fom))
>> >
>> > }
>> >
>> > probe
>> process("/root/test/.libs/mylib.so").function("*_test_func").call {
>> > trace_phase(1, $$parms) }
>> >
>> > i am running stap with -g option,
>> > when i compile i am getting error,
>> > error: dereferencing pointer to incomplete type ‘struct phase’
>> > struct phase is a structure defined in mylibrary,
>> > Is there a way to include custom directory/headers while generating
>> system
>> > tap.
>>
>> Just put the include directives inside %{..%} at file level, e.g.:
>>
>> %{
>> #include <myheader.h>
>> %}
>>
>> ... rest of script
>>
>> Regards,
>> Bryn.
>>
>>
>
> --
> Thanks and Regards,
> Yeshpal Jain.
>
--
Thanks and Regards,
Yeshpal Jain.
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: Run system tap with a user defined function
2022-08-07 16:09 Run system tap with a user defined function Yeshpal Jain
2022-08-08 9:30 ` Bryn M. Reeves
@ 2022-08-16 17:53 ` Frank Ch. Eigler
1 sibling, 0 replies; 5+ messages in thread
From: Frank Ch. Eigler @ 2022-08-16 17:53 UTC (permalink / raw)
To: Yeshpal Jain; +Cc: systemtap
Yeshpal Jain via Systemtap <systemtap@sourceware.org> writes:
> function __read_phase:long(phase:long) %{ /* pure */
> struct phase *phase_s = (struct phase *)((long)STAP_ARG_phase);
> int phase_st = phase->p_state;
> STAP_RETURN(phase_st);
> %} /* <-- function body */
Keeping in mind that, by default, you're using the linux kernel runtime,
this means that any declarations your embedded-C code needs need to be
included manually (like Bryn said), but in such a way that a
kernel-oriented module build can use it. So no #include <stdio.h>,
which is a userspace header.
You might find it simpler to code this up as pure script code:
{ ...
print ("%s", @cast($fom, "phase", "<mylibrary/phase.h>")->p_state;
...
}
In this case, @cast() takes a -userpace- header file name, and should
generate enough debuginfo out of it to let the ->p_state part resolve
naturally. As a bonus, no -g guru mode required.
- FChE
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2022-08-16 17:53 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-08-07 16:09 Run system tap with a user defined function Yeshpal Jain
2022-08-08 9:30 ` Bryn M. Reeves
2022-08-09 5:17 ` Yeshpal Jain
2022-08-12 7:16 ` Yeshpal Jain
2022-08-16 17:53 ` Frank Ch. Eigler
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).