From ldv at strace.io Thu Feb 2 18:42:10 2023 From: ldv at strace.io (Dmitry V. Levin) Date: Thu, 2 Feb 2023 21:42:10 +0300 Subject: [PATCH] pc.test: Fix up order of strace messages again In-Reply-To: References: Message-ID: <20230202184210.GA32720@altlinux.org> On Tue, Jan 31, 2023 at 08:49:01PM +0100, Helge Deller wrote: > It seems I managed to swap two lines with my last patch. > This fixes it up again and brings it in the correct logical order. > > There is no functional change. The testcase succeeds in both > cases. > > Fixes: 1b828bb0f48a ("hppa: Fix pc.test testcase on hppa architecture") > Signed-off-by: Helge Deller > > > diff --git a/tests/pc.test b/tests/pc.test > index 7da0d6b0c..b70669eab 100755 > --- a/tests/pc.test > +++ b/tests/pc.test > @@ -31,8 +31,8 @@ addr="$(echo "$ip" |sed -r 's/^0+//')" && addr=${addr%?} && > > cat > "$EXP" << __EOF__ > \\[[[:xdigit:]]{$len}\\] munmap\\(0x[[:xdigit:]]+, 0\\) += -1 .* > -\\[pid +$pid\\] \\[\\?{$len}\\] \\+\\+\\+ killed by SIGSEGV( \\(core dumped\\))? \\+\\+\\+ > \\[pid +$pid\\] \\[$ip\\] --- SIGSEGV \\{si_signo=SIGSEGV, si_code=SEGV_MAPERR, si_addr=0x$addr[[:xdigit:]]\\} --- > +\\[pid +$pid\\] \\[\\?{$len}\\] \\+\\+\\+ killed by SIGSEGV( \\(core dumped\\))? \\+\\+\\+ > \\[\\?{$len}\\] \\+\\+\\+ exited with 0 \\+\\+\\+ > __EOF__ Applied, thanks. -- ldv From ldv at strace.io Thu Feb 2 18:43:17 2023 From: ldv at strace.io (Dmitry V. Levin) Date: Thu, 2 Feb 2023 21:43:17 +0300 Subject: [PATCH v2] membarrier: add MEMBARRIER_CMD_GET_REGISTRATIONS flag In-Reply-To: <20230113173717.GA15563@altlinux.org> References: <20230112131052.3092810-1-svens@linux.ibm.com> <20230113173717.GA15563@altlinux.org> Message-ID: <20230202184317.GB32720@altlinux.org> On Fri, Jan 13, 2023 at 08:37:17PM +0300, Dmitry V. Levin wrote: > On Thu, Jan 12, 2023 at 02:10:52PM +0100, Sven Schnelle wrote: > > Signed-off-by: Sven Schnelle > > --- > > Changes in v2: > > - add src/xlat/membarrier_cmds.in file > > > > src/xlat/membarrier_cmds.in | 1 + > > tests/membarrier.c | 10 ++++++++++ > > 2 files changed, 11 insertions(+) > > > > diff --git a/src/xlat/membarrier_cmds.in b/src/xlat/membarrier_cmds.in > > index cfa683328636..86124bd1e645 100644 > > --- a/src/xlat/membarrier_cmds.in > > +++ b/src/xlat/membarrier_cmds.in > > @@ -8,3 +8,4 @@ MEMBARRIER_CMD_PRIVATE_EXPEDITED_SYNC_CORE (1 << 5) > > MEMBARRIER_CMD_REGISTER_PRIVATE_EXPEDITED_SYNC_CORE (1 << 6) > > MEMBARRIER_CMD_PRIVATE_EXPEDITED_RSEQ (1 << 7) > > MEMBARRIER_CMD_REGISTER_PRIVATE_EXPEDITED_RSEQ (1 << 8) > > +MEMBARRIER_CMD_GET_REGISTRATIONS (1 << 9) > > I see this as next-20230113~55^2~14^2~2 in linux-next, > but not in mainline yet, when is it expected to land there? Hopefully this will land in v6.3, so applied anyway. -- ldv From karan.handa_ug23 at ashoka.edu.in Sat Feb 11 17:57:03 2023 From: karan.handa_ug23 at ashoka.edu.in (Karan Handa) Date: Sat, 11 Feb 2023 23:27:03 +0530 Subject: [GSoC] Introduction and Microproject Message-ID: Greetings! I'm a third year Computer Science major interested in getting involved with the community, contributing to strace, and grokking C! With regards to relevant background, I've worked with C code on small projects. I'm also somewhat familiar with the internal structure of xv6, which is a toy operating system being used in an Operating Systems course that I'm a teaching assistant for. I'm familiar with using UNIX based environments, syscalls, monitoring and profiling programs, diagnostics, etc. I'm also deeply in sync with the CPU level and hardware abstractions, so I'm aware of the lower-level issues when programming in lower level languages and extremely careful and meticulous when writing low-level code. With regards to open source, I'm completely new but I'm excited to learn! As for my microproject, I'm interested in adding a system call parser / ioctl command parser / netlink protocol parser. Could you point me towards some resources for understanding the general structure for strace as well as how to get started with the microproject? I tried going back to the initial commits to try and understand the initial barebones codebase, but the git commits only go back until Feb 1999. Are the original 1992 commits available somewhere? Any additional tips would be greatly appreciated! -- Regards, Karan From icegambit91 at gmail.com Sun Feb 12 13:14:40 2023 From: icegambit91 at gmail.com (Ice Gambit) Date: Sun, 12 Feb 2023 18:44:40 +0530 Subject: GSoC: Student Introduction Message-ID: Hello, My name is Sahil and I am a final year computer science undergrad. I am interested in working on the "Improve Statistics Handling" project as part of GSoC 2023. I have been using strace as an end-user for a long time but have never been involved in its development. I have an interest in systems programming and binary analysis, and am comfortable with C, C++ and Python. I am also working on enhancing my Rust skills. I have worked on some bite-sized tasks and issues in other open source organisations in the past (eg: https://github.com/htop-dev/htop/pull/1062). I am confident that I'll be able to learn on the fly while working through the project and I believe I'll get to learn a lot. I was going through the list of possible microtasks as well as open issues on github, and I would like to work on issue #179 ("allow process detaching after N syscalls captured" - https://github.com/strace/strace/issues/179). I would love to hear back from you. Regards, Sahil Github profile: https://github.com/valdaarhun From ldv at strace.io Mon Feb 13 16:00:25 2023 From: ldv at strace.io (Dmitry V. Levin) Date: Mon, 13 Feb 2023 19:00:25 +0300 Subject: [GSoC] Introduction and Microproject In-Reply-To: References: Message-ID: <20230213160024.GA15649@altlinux.org> Hi Karan, On Sat, Feb 11, 2023 at 11:27:03PM +0530, Karan Handa wrote: > Greetings! > > I'm a third year Computer Science major interested in getting involved > with the community, contributing to strace, and grokking C! > > With regards to relevant background, I've worked with C code on small > projects. I'm also somewhat familiar with the internal structure of > xv6, which is a toy operating system being used in an Operating > Systems course that I'm a teaching assistant for. I'm familiar with > using UNIX based environments, syscalls, monitoring and profiling > programs, diagnostics, etc. I'm also deeply in sync with the CPU level > and hardware abstractions, so I'm aware of the lower-level issues when > programming in lower level languages and extremely careful and > meticulous when writing low-level code. With regards to open source, > I'm completely new but I'm excited to learn! > > As for my microproject, I'm interested in adding a system call parser > / ioctl command parser / netlink protocol parser. > > Could you point me towards some resources for understanding the > general structure for strace as well as how to get started with the > microproject? I tried going back to the initial commits to try and > understand the initial barebones codebase, but the git commits only go > back until Feb 1999. Are the original 1992 commits available > somewhere? > > Any additional tips would be greatly appreciated! Thank you for your interest in strace project. With regards to the prehistoric commits, the cvs repository started in 1999, that's all we have. However, the project changed a lot since that time, so I'd suggest to have a look at the latest commits in the area you're interested in. For example, if you're interested in adding a syscall/ioctl/netlink parser, just look for the latest commits in these areas. -- ldv From ldv at strace.io Mon Feb 13 16:02:57 2023 From: ldv at strace.io (Dmitry V. Levin) Date: Mon, 13 Feb 2023 19:02:57 +0300 Subject: GSoC: Student Introduction In-Reply-To: References: Message-ID: <20230213160257.GB15649@altlinux.org> Hi Sahil, On Sun, Feb 12, 2023 at 06:44:40PM +0530, Ice Gambit wrote: > Hello, > > My name is Sahil and I am a final year computer science undergrad. I > am interested in working on the "Improve Statistics Handling" project > as part of GSoC 2023. I have been using strace as an end-user for a > long time but have never been involved in its development. > > I have an interest in systems programming and binary analysis, and am > comfortable with C, C++ and Python. I am also working on enhancing my > Rust skills. I have worked on some bite-sized tasks and issues in > other open source organisations in the past (eg: > https://github.com/htop-dev/htop/pull/1062). > > I am confident that I'll be able to learn on the fly while working > through the project and I believe I'll get to learn a lot. I was going > through the list of possible microtasks as well as open issues on > github, and I would like to work on issue #179 ("allow process > detaching after N syscalls captured" - > https://github.com/strace/strace/issues/179). > > I would love to hear back from you. Thank you for your interest in strace project. Feel free to ask any specific questions related to the area of your interest. -- ldv From icegambit91 at gmail.com Tue Feb 14 21:23:59 2023 From: icegambit91 at gmail.com (Sahil Siddiq) Date: Wed, 15 Feb 2023 02:53:59 +0530 Subject: [PATCH/RFC v1 0/2] [GSoC] Stop condition based on number of syscalls Message-ID: <20230214212401.74150-1-icegambit91@gmail.com> Hi, This patch adds the option to detach strace after capturing a specified number of syscalls. I went through the relevant parts of the codebase while working on this patch and there are a few things that I am not clear on. 1. I have assumed that a syscall is considered to be traced only if "syscall_exiting_decode()" returns a non-zero value (does not "bail out"). I am not sure if that is correct. 2. I tried to understand the workings of the "trace_syscall()" function. When can there a situation where "syscall_entering_decode()" does not bail out, but "syscall_exiting_decode" bails out? Sahil Siddiq (2): Stop condition based on number of syscalls Make relevant changes in NEWS and man page NEWS | 2 ++ doc/strace.1.in | 8 ++++++++ src/strace.c | 17 ++++++++++++++++- 3 files changed, 26 insertions(+), 1 deletion(-) -- 2.39.1 From icegambit91 at gmail.com Tue Feb 14 21:24:00 2023 From: icegambit91 at gmail.com (Sahil Siddiq) Date: Wed, 15 Feb 2023 02:54:00 +0530 Subject: [PATCH/RFC v1 1/2] [GSoC] Stop condition based on number of syscalls In-Reply-To: <20230214212401.74150-1-icegambit91@gmail.com> References: <20230214212401.74150-1-icegambit91@gmail.com> Message-ID: <20230214212401.74150-2-icegambit91@gmail.com> Add option to detach strace after capturing a specified number of syscalls. * src/strace.c: Implementation of -l/--syscall-limit option Signed-off-by: Sahil Siddiq --- src/strace.c | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/src/strace.c b/src/strace.c index 4e710db80..bdfa705cf 100644 --- a/src/strace.c +++ b/src/strace.c @@ -84,6 +84,7 @@ int Tflag_scale = 1000; int Tflag_width = 6; bool iflag; bool nflag; +int syscall_limit = -1; bool count_wallclock; static int tflag_scale = 1000000000; static unsigned tflag_width = 0; @@ -461,6 +462,10 @@ Statistics:\n\ -w, --summary-wall-clock\n\ summarise syscall latency (default is system time)\n\ \n\ +Stop condition:\n\ + -l LIMIT, --syscall-limit=LIMIT\n\ + Detach tracer after tracing LIMIT syscalls\n\ +\n\ Tampering:\n\ -e inject=SET[:error=ERRNO|:retval=VALUE][:signal=SIG][:syscall=SYSCALL]\n\ [:delay_enter=DELAY][:delay_exit=DELAY]\n\ @@ -2245,7 +2250,7 @@ init(int argc, char *argv[]) #endif static const char optstring[] = - "+a:Ab:cCdDe:E:fFhiI:kno:O:p:P:qrs:S:tTu:U:vVwxX:yYzZ"; + "+a:Ab:cCdDe:E:fFhiI:kl:no:O:p:P:qrs:S:tTu:U:vVwxX:yYzZ"; enum { GETOPT_SECCOMP = 0x100, @@ -2291,6 +2296,7 @@ init(int argc, char *argv[]) { "instruction-pointer", no_argument, 0, 'i' }, { "interruptible", required_argument, 0, 'I' }, { "stack-traces", no_argument, 0, 'k' }, + { "syscall-limit", required_argument, 0, 'l' }, { "syscall-number", no_argument, 0, 'n' }, { "output", required_argument, 0, 'o' }, { "summary-syscall-overhead", required_argument, 0, 'O' }, @@ -2432,6 +2438,11 @@ init(int argc, char *argv[]) "build of strace"); #endif break; + case 'l': + syscall_limit = string_to_uint(optarg); + if (syscall_limit <= 0) + error_opt_arg(c, lopt, optarg); + break; case 'n': nflag = 1; break; @@ -3646,6 +3657,8 @@ trace_syscall(struct tcb *tcp, unsigned int *sig) int res = syscall_exiting_decode(tcp, &ts); if (res != 0) { res = syscall_exiting_trace(tcp, &ts, res); + if (syscall_limit != -1) + syscall_limit--; } syscall_exiting_finish(tcp); return res; @@ -3716,6 +3729,8 @@ dispatch_event(const struct tcb_wait_data *wd) */ return true; } + if (syscall_limit == 0) + return false; if (has_seccomp_filter(current_tcp)) { /* * Syscall and seccomp stops can happen in different -- 2.39.1 From icegambit91 at gmail.com Tue Feb 14 21:24:01 2023 From: icegambit91 at gmail.com (Sahil Siddiq) Date: Wed, 15 Feb 2023 02:54:01 +0530 Subject: [PATCH/RFC v1 2/2] [GSoC] Make relevant changes in NEWS and man page In-Reply-To: <20230214212401.74150-1-icegambit91@gmail.com> References: <20230214212401.74150-1-icegambit91@gmail.com> Message-ID: <20230214212401.74150-3-icegambit91@gmail.com> Document the changes in the man page and NEWS. * doc/strace.1.in: Add -l/--syscall-limit option. * NEWS: Mention this change. Signed-off-by: Sahil Siddiq --- NEWS | 2 ++ doc/strace.1.in | 8 ++++++++ 2 files changed, 10 insertions(+) diff --git a/NEWS b/NEWS index dca78dc97..3a3c14843 100644 --- a/NEWS +++ b/NEWS @@ -6,6 +6,8 @@ Noteworthy changes in release ?.? (????-??-??) netlink attributes. * Updated lists of ALG_*, BPF_*, IFLA_*, KEY_*, and MEMBARRIER_* constants. * Updated lists of ioctl commands from Linux 6.2. + * Implemented ability to automatically detach/stop strace after + capturing a specified number of syscalls. Noteworthy changes in release 6.1 (2022-12-12) ============================================== diff --git a/doc/strace.1.in b/doc/strace.1.in index 71661bd2e..e76929a8b 100644 --- a/doc/strace.1.in +++ b/doc/strace.1.in @@ -52,6 +52,7 @@ strace \- trace system calls and signals .OP \-X format .OM \-P path .OM \-p pid +.OP \-l limit .OP \-\-seccomp\-bpf .if '@ENABLE_SECONTEXT_FALSE@'#' .OP \-\-secontext\fR[=\fIformat\fR] .BR "" { @@ -74,6 +75,7 @@ strace \- trace system calls and signals .OP \-U columns .OM \-P path .OM \-p pid +.OP \-l limit .OP \-\-seccomp\-bpf .BR "" { .OR \-p pid @@ -1332,6 +1334,12 @@ field is not supplied explicitly, it is added as the last column. .B \-\-summary\-wall\-clock Summarise the time difference between the beginning and end of each system call. The default is to summarise the system time. +.SS Stop condition +.TP 12 +.BI "\-l " limit +.TQ +.BR "\-\-syscall\-limit" = \fIlimit\fR +Detach/stop strace after \fIlimit\fR number of syscalls are captured. .SS Tampering .ad l .TP 12 -- 2.39.1 From yamato at redhat.com Tue Feb 14 23:04:22 2023 From: yamato at redhat.com (Masatake YAMATO) Date: Wed, 15 Feb 2023 08:04:22 +0900 (JST) Subject: [PATCH/RFC v1 1/2] [GSoC] Stop condition based on number of syscalls In-Reply-To: <20230214212401.74150-2-icegambit91@gmail.com> References: <20230214212401.74150-1-icegambit91@gmail.com> <20230214212401.74150-2-icegambit91@gmail.com> Message-ID: <20230215.080422.46120978274036135.yamato@redhat.com> > Add option to detach strace after capturing a specified > number of syscalls. > > * src/strace.c: Implementation of -l/--syscall-limit option > > Signed-off-by: Sahil Siddiq > --- > src/strace.c | 17 ++++++++++++++++- > 1 file changed, 16 insertions(+), 1 deletion(-) > > diff --git a/src/strace.c b/src/strace.c > index 4e710db80..bdfa705cf 100644 > --- a/src/strace.c > +++ b/src/strace.c > @@ -84,6 +84,7 @@ int Tflag_scale = 1000; > int Tflag_width = 6; > bool iflag; > bool nflag; > +int syscall_limit = -1; If you don't have a plan to refer to this variable in .c files other than strace.c, you can add static modifier. It seems that my comment is applicable to nflag. Masatake YAMATO > bool count_wallclock; > static int tflag_scale = 1000000000; > static unsigned tflag_width = 0; > @@ -461,6 +462,10 @@ Statistics:\n\ > -w, --summary-wall-clock\n\ > summarise syscall latency (default is system time)\n\ > \n\ > +Stop condition:\n\ > + -l LIMIT, --syscall-limit=LIMIT\n\ > + Detach tracer after tracing LIMIT syscalls\n\ > +\n\ > Tampering:\n\ > -e inject=SET[:error=ERRNO|:retval=VALUE][:signal=SIG][:syscall=SYSCALL]\n\ > [:delay_enter=DELAY][:delay_exit=DELAY]\n\ > @@ -2245,7 +2250,7 @@ init(int argc, char *argv[]) > #endif > > static const char optstring[] = > - "+a:Ab:cCdDe:E:fFhiI:kno:O:p:P:qrs:S:tTu:U:vVwxX:yYzZ"; > + "+a:Ab:cCdDe:E:fFhiI:kl:no:O:p:P:qrs:S:tTu:U:vVwxX:yYzZ"; > > enum { > GETOPT_SECCOMP = 0x100, > @@ -2291,6 +2296,7 @@ init(int argc, char *argv[]) > { "instruction-pointer", no_argument, 0, 'i' }, > { "interruptible", required_argument, 0, 'I' }, > { "stack-traces", no_argument, 0, 'k' }, > + { "syscall-limit", required_argument, 0, 'l' }, > { "syscall-number", no_argument, 0, 'n' }, > { "output", required_argument, 0, 'o' }, > { "summary-syscall-overhead", required_argument, 0, 'O' }, > @@ -2432,6 +2438,11 @@ init(int argc, char *argv[]) > "build of strace"); > #endif > break; > + case 'l': > + syscall_limit = string_to_uint(optarg); > + if (syscall_limit <= 0) > + error_opt_arg(c, lopt, optarg); > + break; > case 'n': > nflag = 1; > break; > @@ -3646,6 +3657,8 @@ trace_syscall(struct tcb *tcp, unsigned int *sig) > int res = syscall_exiting_decode(tcp, &ts); > if (res != 0) { > res = syscall_exiting_trace(tcp, &ts, res); > + if (syscall_limit != -1) > + syscall_limit--; > } > syscall_exiting_finish(tcp); > return res; > @@ -3716,6 +3729,8 @@ dispatch_event(const struct tcb_wait_data *wd) > */ > return true; > } > + if (syscall_limit == 0) > + return false; > if (has_seccomp_filter(current_tcp)) { > /* > * Syscall and seccomp stops can happen in different > -- > 2.39.1 > > -- > Strace-devel mailing list > Strace-devel at lists.strace.io > https://lists.strace.io/mailman/listinfo/strace-devel > From yamato at redhat.com Tue Feb 14 23:23:06 2023 From: yamato at redhat.com (Masatake YAMATO) Date: Wed, 15 Feb 2023 08:23:06 +0900 (JST) Subject: hits for decoding GENL of netlink In-Reply-To: <20230214212401.74150-1-icegambit91@gmail.com> References: <20230214212401.74150-1-icegambit91@gmail.com> Message-ID: <20230215.082306.1491842961597510319.yamato@redhat.com> If you are thinking about decoding GENL of netlink, see https://github.com/masatake/strace/commits/netlink-genl. I'm reworking on https://lists.strace.io/pipermail/strace-devel/2022-March/010996.html so for awhile I have no time to finish the GENL decoder. Masatake YAMATO From icegambit91 at gmail.com Wed Feb 15 15:54:35 2023 From: icegambit91 at gmail.com (Ice Gambit) Date: Wed, 15 Feb 2023 21:24:35 +0530 Subject: [PATCH/RFC v1 1/2] [GSoC] Stop condition based on number of syscalls In-Reply-To: <20230215.080422.46120978274036135.yamato@redhat.com> References: <20230214212401.74150-1-icegambit91@gmail.com> <20230214212401.74150-2-icegambit91@gmail.com> <20230215.080422.46120978274036135.yamato@redhat.com> Message-ID: Hi, You're right, nflag and syscall_limit can both be static variables. I'll submit a patch with these changes. Thanks for the feedback. Regards, Sahil On Wed, Feb 15, 2023 at 4:34 AM Masatake YAMATO wrote: > > > Add option to detach strace after capturing a specified > > number of syscalls. > > > > * src/strace.c: Implementation of -l/--syscall-limit option > > > > Signed-off-by: Sahil Siddiq > > --- > > src/strace.c | 17 ++++++++++++++++- > > 1 file changed, 16 insertions(+), 1 deletion(-) > > > > diff --git a/src/strace.c b/src/strace.c > > index 4e710db80..bdfa705cf 100644 > > --- a/src/strace.c > > +++ b/src/strace.c > > @@ -84,6 +84,7 @@ int Tflag_scale = 1000; > > int Tflag_width = 6; > > bool iflag; > > bool nflag; > > +int syscall_limit = -1; > > If you don't have a plan to refer to this variable in .c files other than strace.c, > you can add static modifier. > > It seems that my comment is applicable to nflag. > > Masatake YAMATO > > > bool count_wallclock; > > static int tflag_scale = 1000000000; > > static unsigned tflag_width = 0; > > @@ -461,6 +462,10 @@ Statistics:\n\ > > -w, --summary-wall-clock\n\ > > summarise syscall latency (default is system time)\n\ > > \n\ > > +Stop condition:\n\ > > + -l LIMIT, --syscall-limit=LIMIT\n\ > > + Detach tracer after tracing LIMIT syscalls\n\ > > +\n\ > > Tampering:\n\ > > -e inject=SET[:error=ERRNO|:retval=VALUE][:signal=SIG][:syscall=SYSCALL]\n\ > > [:delay_enter=DELAY][:delay_exit=DELAY]\n\ > > @@ -2245,7 +2250,7 @@ init(int argc, char *argv[]) > > #endif > > > > static const char optstring[] = > > - "+a:Ab:cCdDe:E:fFhiI:kno:O:p:P:qrs:S:tTu:U:vVwxX:yYzZ"; > > + "+a:Ab:cCdDe:E:fFhiI:kl:no:O:p:P:qrs:S:tTu:U:vVwxX:yYzZ"; > > > > enum { > > GETOPT_SECCOMP = 0x100, > > @@ -2291,6 +2296,7 @@ init(int argc, char *argv[]) > > { "instruction-pointer", no_argument, 0, 'i' }, > > { "interruptible", required_argument, 0, 'I' }, > > { "stack-traces", no_argument, 0, 'k' }, > > + { "syscall-limit", required_argument, 0, 'l' }, > > { "syscall-number", no_argument, 0, 'n' }, > > { "output", required_argument, 0, 'o' }, > > { "summary-syscall-overhead", required_argument, 0, 'O' }, > > @@ -2432,6 +2438,11 @@ init(int argc, char *argv[]) > > "build of strace"); > > #endif > > break; > > + case 'l': > > + syscall_limit = string_to_uint(optarg); > > + if (syscall_limit <= 0) > > + error_opt_arg(c, lopt, optarg); > > + break; > > case 'n': > > nflag = 1; > > break; > > @@ -3646,6 +3657,8 @@ trace_syscall(struct tcb *tcp, unsigned int *sig) > > int res = syscall_exiting_decode(tcp, &ts); > > if (res != 0) { > > res = syscall_exiting_trace(tcp, &ts, res); > > + if (syscall_limit != -1) > > + syscall_limit--; > > } > > syscall_exiting_finish(tcp); > > return res; > > @@ -3716,6 +3729,8 @@ dispatch_event(const struct tcb_wait_data *wd) > > */ > > return true; > > } > > + if (syscall_limit == 0) > > + return false; > > if (has_seccomp_filter(current_tcp)) { > > /* > > * Syscall and seccomp stops can happen in different > > -- > > 2.39.1 > > > > -- > > Strace-devel mailing list > > Strace-devel at lists.strace.io > > https://lists.strace.io/mailman/listinfo/strace-devel > > > From icegambit91 at gmail.com Wed Feb 15 18:07:04 2023 From: icegambit91 at gmail.com (Sahil Siddiq) Date: Wed, 15 Feb 2023 23:37:04 +0530 Subject: [PATCH v2 0/2] [GSoC] Stop condition based on number of syscalls Message-ID: <20230215180706.809186-1-icegambit91@gmail.com> Hi, This patch adds the option to detach strace after capturing a specified number of syscalls. Changes v1 -> v2: - Declare "nflag" and "syscall_limit" with the static modifier. "nflag" and "syscall_limit" are not accessed outside of "strace.c". Sahil Siddiq (2): Stop condition based on number of syscalls Make relevant changes in NEWS and man page NEWS | 2 ++ doc/strace.1.in | 8 ++++++++ src/strace.c | 19 +++++++++++++++++-- 3 files changed, 27 insertions(+), 2 deletions(-) -- 2.39.1 From icegambit91 at gmail.com Wed Feb 15 18:07:05 2023 From: icegambit91 at gmail.com (Sahil Siddiq) Date: Wed, 15 Feb 2023 23:37:05 +0530 Subject: [PATCH v2 1/2] [GSoC] Stop condition based on number of syscalls In-Reply-To: <20230215180706.809186-1-icegambit91@gmail.com> References: <20230215180706.809186-1-icegambit91@gmail.com> Message-ID: <20230215180706.809186-2-icegambit91@gmail.com> Add option to detach strace after capturing a specified number of syscalls. * src/strace.c: Implementation of -l/--syscall-limit option Signed-off-by: Sahil Siddiq --- Changes since v1: - Declare "nflag" and "syscall_limit" with the static modifier. src/strace.c | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/src/strace.c b/src/strace.c index 4e710db80..162c802ab 100644 --- a/src/strace.c +++ b/src/strace.c @@ -83,7 +83,8 @@ bool Tflag; int Tflag_scale = 1000; int Tflag_width = 6; bool iflag; -bool nflag; +static bool nflag; +static int syscall_limit = -1; bool count_wallclock; static int tflag_scale = 1000000000; static unsigned tflag_width = 0; @@ -461,6 +462,10 @@ Statistics:\n\ -w, --summary-wall-clock\n\ summarise syscall latency (default is system time)\n\ \n\ +Stop condition:\n\ + -l LIMIT, --syscall-limit=LIMIT\n\ + Detach tracer after tracing LIMIT syscalls\n\ +\n\ Tampering:\n\ -e inject=SET[:error=ERRNO|:retval=VALUE][:signal=SIG][:syscall=SYSCALL]\n\ [:delay_enter=DELAY][:delay_exit=DELAY]\n\ @@ -2245,7 +2250,7 @@ init(int argc, char *argv[]) #endif static const char optstring[] = - "+a:Ab:cCdDe:E:fFhiI:kno:O:p:P:qrs:S:tTu:U:vVwxX:yYzZ"; + "+a:Ab:cCdDe:E:fFhiI:kl:no:O:p:P:qrs:S:tTu:U:vVwxX:yYzZ"; enum { GETOPT_SECCOMP = 0x100, @@ -2291,6 +2296,7 @@ init(int argc, char *argv[]) { "instruction-pointer", no_argument, 0, 'i' }, { "interruptible", required_argument, 0, 'I' }, { "stack-traces", no_argument, 0, 'k' }, + { "syscall-limit", required_argument, 0, 'l' }, { "syscall-number", no_argument, 0, 'n' }, { "output", required_argument, 0, 'o' }, { "summary-syscall-overhead", required_argument, 0, 'O' }, @@ -2432,6 +2438,11 @@ init(int argc, char *argv[]) "build of strace"); #endif break; + case 'l': + syscall_limit = string_to_uint(optarg); + if (syscall_limit <= 0) + error_opt_arg(c, lopt, optarg); + break; case 'n': nflag = 1; break; @@ -3646,6 +3657,8 @@ trace_syscall(struct tcb *tcp, unsigned int *sig) int res = syscall_exiting_decode(tcp, &ts); if (res != 0) { res = syscall_exiting_trace(tcp, &ts, res); + if (syscall_limit != -1) + syscall_limit--; } syscall_exiting_finish(tcp); return res; @@ -3716,6 +3729,8 @@ dispatch_event(const struct tcb_wait_data *wd) */ return true; } + if (syscall_limit == 0) + return false; if (has_seccomp_filter(current_tcp)) { /* * Syscall and seccomp stops can happen in different -- 2.39.1 From icegambit91 at gmail.com Wed Feb 15 18:07:06 2023 From: icegambit91 at gmail.com (Sahil Siddiq) Date: Wed, 15 Feb 2023 23:37:06 +0530 Subject: [PATCH v2 2/2] [GSoC] Make relevant changes in NEWS and man page In-Reply-To: <20230215180706.809186-1-icegambit91@gmail.com> References: <20230215180706.809186-1-icegambit91@gmail.com> Message-ID: <20230215180706.809186-3-icegambit91@gmail.com> Document the changes in the man page and NEWS. * doc/strace.1.in: Add -l/--syscall-limit option. * NEWS: Mention this change. Signed-off-by: Sahil Siddiq --- Changes since v1: - None NEWS | 2 ++ doc/strace.1.in | 8 ++++++++ 2 files changed, 10 insertions(+) diff --git a/NEWS b/NEWS index 44e15eb18..a77570c53 100644 --- a/NEWS +++ b/NEWS @@ -7,6 +7,8 @@ Noteworthy changes in release ?.? (????-??-??) * Updated lists of ALG_*, BPF_*, IFLA_*, KEY_*, KVM_*, LANDLOCK_*, MEMBARRIER_*, NFT_*, NTF_*, and V4L2_* constants. * Updated lists of ioctl commands from Linux 6.2. + * Implemented ability to automatically detach/stop strace after + capturing a specified number of syscalls. Noteworthy changes in release 6.1 (2022-12-12) ============================================== diff --git a/doc/strace.1.in b/doc/strace.1.in index 71661bd2e..e76929a8b 100644 --- a/doc/strace.1.in +++ b/doc/strace.1.in @@ -52,6 +52,7 @@ strace \- trace system calls and signals .OP \-X format .OM \-P path .OM \-p pid +.OP \-l limit .OP \-\-seccomp\-bpf .if '@ENABLE_SECONTEXT_FALSE@'#' .OP \-\-secontext\fR[=\fIformat\fR] .BR "" { @@ -74,6 +75,7 @@ strace \- trace system calls and signals .OP \-U columns .OM \-P path .OM \-p pid +.OP \-l limit .OP \-\-seccomp\-bpf .BR "" { .OR \-p pid @@ -1332,6 +1334,12 @@ field is not supplied explicitly, it is added as the last column. .B \-\-summary\-wall\-clock Summarise the time difference between the beginning and end of each system call. The default is to summarise the system time. +.SS Stop condition +.TP 12 +.BI "\-l " limit +.TQ +.BR "\-\-syscall\-limit" = \fIlimit\fR +Detach/stop strace after \fIlimit\fR number of syscalls are captured. .SS Tampering .ad l .TP 12 -- 2.39.1 From ldv at strace.io Thu Feb 16 06:57:41 2023 From: ldv at strace.io (Dmitry V. Levin) Date: Thu, 16 Feb 2023 09:57:41 +0300 Subject: [PATCH/RFC v1 0/2] [GSoC] Stop condition based on number of syscalls In-Reply-To: <20230214212401.74150-1-icegambit91@gmail.com> References: <20230214212401.74150-1-icegambit91@gmail.com> Message-ID: <20230216065741.GA20509@altlinux.org> Hi, On Wed, Feb 15, 2023 at 02:53:59AM +0530, Sahil Siddiq wrote: > This patch adds the option to detach strace after capturing a specified > number of syscalls. > > I went through the relevant parts of the codebase while working on this > patch and there are a few things that I am not clear on. > > 1. I have assumed that a syscall is considered to be traced only if > "syscall_exiting_decode()" returns a non-zero value (does not "bail > out"). I am not sure if that is correct. The tracee is being stopped both on entering and on exiting syscall, that is, twice per syscall invocation. If --seccomp-bpf option is in effect, then the tracee is not stopped on syscalls that are filtered out. > 2. I tried to understand the workings of the "trace_syscall()" function. > When can there a situation where "syscall_entering_decode()" does > not bail out, but "syscall_exiting_decode" bails out? syscall_entering_decode doesn't normally bail out, while syscall_exiting_decode routinely bails out on syscalls that are filtered out by syscall_entering_trace. -- ldv From ldv at strace.io Thu Feb 16 10:30:27 2023 From: ldv at strace.io (Dmitry V. Levin) Date: Thu, 16 Feb 2023 13:30:27 +0300 Subject: [PATCH v2 2/2] [GSoC] Make relevant changes in NEWS and man page In-Reply-To: <20230215180706.809186-3-icegambit91@gmail.com> References: <20230215180706.809186-1-icegambit91@gmail.com> <20230215180706.809186-3-icegambit91@gmail.com> Message-ID: <20230216103027.GA21619@altlinux.org> On Wed, Feb 15, 2023 at 11:37:06PM +0530, Sahil Siddiq wrote: [...] > @@ -1332,6 +1334,12 @@ field is not supplied explicitly, it is added as the last column. > .B \-\-summary\-wall\-clock > Summarise the time difference between the beginning and end of > each system call. The default is to summarise the system time. > +.SS Stop condition > +.TP 12 > +.BI "\-l " limit > +.TQ > +.BR "\-\-syscall\-limit" = \fIlimit\fR > +Detach/stop strace after \fIlimit\fR number of syscalls are captured. I'm not sure what exactly do you mean by "captured syscalls". There are syscalls for which strace handles syscall stops, and there are syscalls printed by strace, this excludes those syscall that were handled but filtered out at different stages and therefore not printed. The filtering could be performed by --trace=, --trace-path=, and --status=; my guess is that you intended to take all this filtering into account. Anyway, this new feature needs a test. Maybe even 3 tests: one test for each of these 3 filtering methods. -- ldv From icegambit91 at gmail.com Thu Feb 16 12:35:04 2023 From: icegambit91 at gmail.com (icegambit91 at gmail.com) Date: Thu, 16 Feb 2023 18:05:04 +0530 Subject: [PATCH v2 2/2] [GSoC] Make relevant changes in NEWS and man page In-Reply-To: <20230216103027.GA21619@altlinux.org> References: <20230215180706.809186-1-icegambit91@gmail.com> <20230215180706.809186-3-icegambit91@gmail.com> <20230216103027.GA21619@altlinux.org> Message-ID: <2232577.irdbgypaU6@archlinux> Hi, On Thursday, 16 February 2023 16:00:27 IST Dmitry V. Levin wrote: > On Wed, Feb 15, 2023 at 11:37:06PM +0530, Sahil Siddiq wrote: > [...] > > > @@ -1332,6 +1334,12 @@ field is not supplied explicitly, it is added as > > the last column.> > > .B \-\-summary\-wall\-clock > > Summarise the time difference between the beginning and end of > > each system call. The default is to summarise the system time. > > > > +.SS Stop condition > > +.TP 12 > > +.BI "\-l " limit > > +.TQ > > +.BR "\-\-syscall\-limit" = \fIlimit\fR > > +Detach/stop strace after \fIlimit\fR number of syscalls are captured. > > I'm not sure what exactly do you mean by "captured syscalls". By "captured syscalls", I was referring to syscalls that are handled and are not filtered out (so, syscalls that are decoded and printed). > there are syscalls printed by strace, this excludes those syscall that > were handled but filtered out at different stages and therefore not printed. > > The filtering could be performed by --trace=, --trace-path=, and --status=; > my guess is that you intended to take all this filtering into account. Yes, this is my intention. So, syscalls that are filtered out will not be considered in the maximum syscall count for detaching strace. > Anyway, this new feature needs a test. Maybe even 3 tests: > one test for each of these 3 filtering methods. Sure, I'll send in a new patch with the tests. Thank you for reviewing. Regards, Sahil From icegambit91 at gmail.com Thu Feb 16 12:50:05 2023 From: icegambit91 at gmail.com (Sahil Siddiq) Date: Thu, 16 Feb 2023 18:20:05 +0530 Subject: [PATCH/RFC v1 0/2] [GSoC] Stop condition based on number of syscalls In-Reply-To: <20230216065741.GA20509@altlinux.org> References: <20230214212401.74150-1-icegambit91@gmail.com> <20230216065741.GA20509@altlinux.org> Message-ID: <3580594.iIbC2pHGDl@archlinux> Hi, On Thursday, 16 February 2023 12:27:41 IST Dmitry V. Levin wrote: > Hi, > > On Wed, Feb 15, 2023 at 02:53:59AM +0530, Sahil Siddiq wrote: > > This patch adds the option to detach strace after capturing a specified > > number of syscalls. > > > > I went through the relevant parts of the codebase while working on this > > patch and there are a few things that I am not clear on. > > > > 1. I have assumed that a syscall is considered to be traced only if > > "syscall_exiting_decode()" returns a non-zero value (does not "bail > > out"). I am not sure if that is correct. > > The tracee is being stopped both on entering and on exiting syscall, that > is, twice per syscall invocation. If --seccomp-bpf option is in effect, > then the tracee is not stopped on syscalls that are filtered out. > > > 2. I tried to understand the workings of the "trace_syscall()" function. > > When can there a situation where "syscall_entering_decode()" does > > not bail out, but "syscall_exiting_decode" bails out? > > syscall_entering_decode doesn't normally bail out, while > syscall_exiting_decode routinely bails out on syscalls > that are filtered out by syscall_entering_trace. Thank you for your prompt response. This makes sense now. In this case, it should be alright to decrement "syscall_limit" only when "syscall_exiting_decode" does not bail out/is not filtered out. Regards, Sahil From icegambit91 at gmail.com Mon Feb 20 18:47:09 2023 From: icegambit91 at gmail.com (Sahil Siddiq) Date: Tue, 21 Feb 2023 00:17:09 +0530 Subject: [RFC v1] [GSoC] Add test for -l/--syscall-limit option Message-ID: <20230220184709.1018315-1-icegambit91@gmail.com> This test checks the correctness of the -l/--syscall-limit option when used with the --trace option * test/strace--syscall-limit.c: New file * test/gen_tests.in: Add rule to generate test * test/Makefile.am (check_PROGRAMS): Add strace--syscall-limit * test/.gitignore: Add strace--syscall-limit Signed-off-by: Sahil Siddiq --- Hi, I haven't finished writing all the tests yet. I have to admit that I found the learning curve for writing tests to be a lot higher than working on the actual feature especially since I am not used to working with bash scripts. So, this has been a nice learning experience. I would like to get some feedback on this test before I move on to the other tests. It checks the correctness of the -l option with the --trace option. I went through several of the existing tests to understand how best to write this test. I primarily took inspiration from the "syscall--decode-pids-comm" test. Please do let me know if the test can be improved. Thanks, Sahil tests/.gitignore | 1 + tests/Makefile.am | 1 + tests/gen_tests.in | 1 + tests/strace--syscall-limit.c | 60 +++++++++++++++++++++++++++++++++++ 4 files changed, 63 insertions(+) create mode 100644 tests/strace--syscall-limit.c diff --git a/tests/.gitignore b/tests/.gitignore index 5935c39d9..65999ad24 100644 --- a/tests/.gitignore +++ b/tests/.gitignore @@ -1020,6 +1020,7 @@ strace--strings-in-hex-all strace--strings-in-hex-non-ascii strace--strings-in-hex-non-ascii-chars strace--strings-in-hex-none +strace--syscall-limit strace-Y-0123456789 strace-n strace-no-x diff --git a/tests/Makefile.am b/tests/Makefile.am index 4426cab0c..cc4fae736 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -379,6 +379,7 @@ check_PROGRAMS = $(PURE_EXECUTABLES) \ status-successful-threads \ status-unfinished-threads \ strace--decode-pids-comm \ + strace--syscall-limit \ strace-Y-0123456789 \ strace-p-Y-p2 \ strace-p1-Y-p \ diff --git a/tests/gen_tests.in b/tests/gen_tests.in index eceac8d60..c11c49329 100644 --- a/tests/gen_tests.in +++ b/tests/gen_tests.in @@ -995,6 +995,7 @@ strace--absolute-timestamps-format-unix-precision-ns +strace-ttt.test 9 --absolu strace--absolute-timestamps-format-unix-precision-s +strace-ttt.test 0 --absolute-timestamps=format:unix --absolute-timestamps=precision:s strace--absolute-timestamps-format-unix-precision-us +strace-ttt.test 6 --absolute-timestamps=precision:us --absolute-timestamps=format:unix strace--decode-pids-comm --decode-pids=comm --trace=getppid,tgkill --signal='!SIGCHLD,SIGCONT' -q -f -a 18 +strace--syscall-limit --syscall-limit=4 --trace=getpid,getppid -q -f -a 9 strace--follow-forks-output-separately +strace-ff.test --follow-forks --output-separately strace--relative-timestamps +strace-r.test --relative-timestamps strace--relative-timestamps-ms +strace-r.test --relative-timestamps=ms diff --git a/tests/strace--syscall-limit.c b/tests/strace--syscall-limit.c new file mode 100644 index 000000000..0905ebd85 --- /dev/null +++ b/tests/strace--syscall-limit.c @@ -0,0 +1,60 @@ +/* + * Test -l/--syscall-limit=limit option. + * + * Copyright (c) 2023 The strace developers. + * All rights reserved. + * + * SPDX-License-Identifier: GPL-2.0-or-later + */ + +#include "tests.h" + +#include +#include +#include +#include +#include +#include + +static int +syscall_limit_detach(void) +{ + pid_t pid = getpid(); + pid_t ppid = getppid(); + + printf("%u getpid() = %d\n", pid, pid); + printf("%u getppid() = %d\n", pid, ppid); + fflush(stdout); + + pid_t child = fork(); + if (child < 0) + perror_msg_and_fail("fork"); + else if (child == 0) { + pid = getpid(); + ppid = getppid(); + printf("%u getpid() = %d\n", pid, pid); + printf("%u getppid() = %d\n", pid, ppid); + fflush(stdout); + return 0; + } + int status; + while ((waitpid(child, &status, 0)) != child) { + if (errno == EINTR) + continue; + perror_msg_and_fail("waitpid: %d", child); + } + printf("+++ exited with 0 +++\n"); + + ppid = getpid(); + ppid = getppid(); + printf("%u getpid() = %d\n", pid, pid); + printf("%u getppid() = %d\n", pid, ppid); + printf("+++ exited with 0 +++\n"); + return WEXITSTATUS(status); +} + +int +main(int argc, char **argv) +{ + return syscall_limit_detach(); +} -- 2.39.2 From ldv at strace.io Fri Feb 24 18:15:58 2023 From: ldv at strace.io (Dmitry V. Levin) Date: Fri, 24 Feb 2023 21:15:58 +0300 Subject: [RFC v1] [GSoC] Add test for -l/--syscall-limit option In-Reply-To: <20230220184709.1018315-1-icegambit91@gmail.com> References: <20230220184709.1018315-1-icegambit91@gmail.com> Message-ID: <20230224181558.GA7758@altlinux.org> Hi, On Tue, Feb 21, 2023 at 12:17:09AM +0530, Sahil Siddiq wrote: > This test checks the correctness of the -l/--syscall-limit > option when used with the --trace option > > * test/strace--syscall-limit.c: New file > * test/gen_tests.in: Add rule to generate test > * test/Makefile.am (check_PROGRAMS): Add strace--syscall-limit > * test/.gitignore: Add strace--syscall-limit It's a nice test, it actually demonstrates the aspect of the implementation I didn't expect, see below. > Signed-off-by: Sahil Siddiq > --- > Hi, > > I haven't finished writing all the tests yet. I have to admit > that I found the learning curve for writing tests to be a lot > higher than working on the actual feature especially since I > am not used to working with bash scripts. So, this has been a > nice learning experience. > > I would like to get some feedback on this test before I move > on to the other tests. It checks the correctness of the -l > option with the --trace option. > > I went through several of the existing tests to understand how > best to write this test. I primarily took inspiration from the > "syscall--decode-pids-comm" test. Please do let me know if the > test can be improved. Sure, see below. > Thanks, > Sahil > > tests/.gitignore | 1 + > tests/Makefile.am | 1 + > tests/gen_tests.in | 1 + > tests/strace--syscall-limit.c | 60 +++++++++++++++++++++++++++++++++++ > 4 files changed, 63 insertions(+) > create mode 100644 tests/strace--syscall-limit.c > > diff --git a/tests/.gitignore b/tests/.gitignore > index 5935c39d9..65999ad24 100644 > --- a/tests/.gitignore > +++ b/tests/.gitignore > @@ -1020,6 +1020,7 @@ strace--strings-in-hex-all > strace--strings-in-hex-non-ascii > strace--strings-in-hex-non-ascii-chars > strace--strings-in-hex-none > +strace--syscall-limit You keep the list sorted here, thanks. > strace-Y-0123456789 > strace-n > strace-no-x > diff --git a/tests/Makefile.am b/tests/Makefile.am > index 4426cab0c..cc4fae736 100644 > --- a/tests/Makefile.am > +++ b/tests/Makefile.am > @@ -379,6 +379,7 @@ check_PROGRAMS = $(PURE_EXECUTABLES) \ > status-successful-threads \ > status-unfinished-threads \ > strace--decode-pids-comm \ > + strace--syscall-limit \ You keep the list sorted here, thanks again. > strace-Y-0123456789 \ > strace-p-Y-p2 \ > strace-p1-Y-p \ > diff --git a/tests/gen_tests.in b/tests/gen_tests.in > index eceac8d60..c11c49329 100644 > --- a/tests/gen_tests.in > +++ b/tests/gen_tests.in > @@ -995,6 +995,7 @@ strace--absolute-timestamps-format-unix-precision-ns +strace-ttt.test 9 --absolu > strace--absolute-timestamps-format-unix-precision-s +strace-ttt.test 0 --absolute-timestamps=format:unix --absolute-timestamps=precision:s > strace--absolute-timestamps-format-unix-precision-us +strace-ttt.test 6 --absolute-timestamps=precision:us --absolute-timestamps=format:unix > strace--decode-pids-comm --decode-pids=comm --trace=getppid,tgkill --signal='!SIGCHLD,SIGCONT' -q -f -a 18 > +strace--syscall-limit --syscall-limit=4 --trace=getpid,getppid -q -f -a 9 > strace--follow-forks-output-separately +strace-ff.test --follow-forks --output-separately Please keep this list sorted, too. > strace--relative-timestamps +strace-r.test --relative-timestamps > strace--relative-timestamps-ms +strace-r.test --relative-timestamps=ms > diff --git a/tests/strace--syscall-limit.c b/tests/strace--syscall-limit.c > new file mode 100644 > index 000000000..0905ebd85 > --- /dev/null > +++ b/tests/strace--syscall-limit.c > @@ -0,0 +1,60 @@ > +/* > + * Test -l/--syscall-limit=limit option. > + * > + * Copyright (c) 2023 The strace developers. > + * All rights reserved. > + * > + * SPDX-License-Identifier: GPL-2.0-or-later > + */ > + > +#include "tests.h" > + > +#include > +#include > +#include > +#include > +#include > +#include > + > +static int > +syscall_limit_detach(void) > +{ > + pid_t pid = getpid(); > + pid_t ppid = getppid(); > + > + printf("%u getpid() = %d\n", pid, pid); > + printf("%u getppid() = %d\n", pid, ppid); The format string has to be %-5u instead of plain %u, to match the strace output. There is nothing wrong in using two syscalls, but if I were to write a test like this, I'd be likely using a single syscall instead of two, e.g. chdir("."). > + fflush(stdout); > + > + pid_t child = fork(); > + if (child < 0) > + perror_msg_and_fail("fork"); > + else if (child == 0) { > + pid = getpid(); > + ppid = getppid(); > + printf("%u getpid() = %d\n", pid, pid); > + printf("%u getppid() = %d\n", pid, ppid); > + fflush(stdout); > + return 0; > + } > + int status; > + while ((waitpid(child, &status, 0)) != child) { > + if (errno == EINTR) > + continue; > + perror_msg_and_fail("waitpid: %d", child); > + } Note that your --syscall-limit implementation detaches from the parent process in a way that causes it to be killed by strace with SIGTERM, so the remaining code is not reached. I'm not sure you planned to implement --syscall-limit this way, and I'm doubt that users would expect such behavior. This is also in contrast with --detach-on=execve which also detaches its tracee but doesn't kill it, see detach_on_execve handling in maybe_allocate_tcb(). > + printf("+++ exited with 0 +++\n"); > + > + ppid = getpid(); > + ppid = getppid(); > + printf("%u getpid() = %d\n", pid, pid); > + printf("%u getppid() = %d\n", pid, ppid); > + printf("+++ exited with 0 +++\n"); > + return WEXITSTATUS(status); > +} So this code works unless executed under strace --syscall-limit. > + > +int > +main(int argc, char **argv) > +{ > + return syscall_limit_detach(); > +} It would be better to declare main without arguments if they are not going to be used anyway. -- ldv From icegambit91 at gmail.com Sat Feb 25 16:17:34 2023 From: icegambit91 at gmail.com (Sahil Siddiq) Date: Sat, 25 Feb 2023 21:47:34 +0530 Subject: [RFC v1] [GSoC] Add test for -l/--syscall-limit option In-Reply-To: <20230224181558.GA7758@altlinux.org> References: <20230220184709.1018315-1-icegambit91@gmail.com> <20230224181558.GA7758@altlinux.org> Message-ID: <21787488.EfDdHjke4D@archlinux> Hi, Thank you for the detailed feedback. On Friday, 24 February 2023 23:45:58 IST Dmitry V. Levin wrote: > > diff --git a/tests/gen_tests.in b/tests/gen_tests.in > > index eceac8d60..c11c49329 100644 > > --- a/tests/gen_tests.in > > +++ b/tests/gen_tests.in > > @@ -995,6 +995,7 @@ strace--absolute-timestamps-format-unix-precision-ns > > +strace-ttt.test 9 --absolu> > > strace--absolute-timestamps-format-unix-precision-s +strace-ttt.test 0 > > --absolute-timestamps=format:unix --absolute-timestamps=precision:s > > strace--absolute-timestamps-format-unix-precision-us +strace-ttt.test 6 > > --absolute-timestamps=precision:us --absolute-timestamps=format:unix > > strace--decode-pids-comm --decode-pids=comm --trace=getppid,tgkill > > --signal='!SIGCHLD,SIGCONT' -q -f -a 18> > > +strace--syscall-limit --syscall-limit=4 --trace=getpid,getppid -q -f -a 9 > > > > strace--follow-forks-output-separately +strace-ff.test --follow-forks > > --output-separately > Please keep this list sorted, too. Sorry, I must have missed this. > > + pid_t child = fork(); > > + if (child < 0) > > + perror_msg_and_fail("fork"); > > + else if (child == 0) { > > + pid = getpid(); > > + ppid = getppid(); > > + printf("%u getpid() = %d\n", pid, pid); > > + printf("%u getppid() = %d\n", pid, ppid); > > + fflush(stdout); > > + return 0; > > + } > > + int status; > > + while ((waitpid(child, &status, 0)) != child) { > > + if (errno == EINTR) > > + continue; > > + perror_msg_and_fail("waitpid: %d", child); > > + } > > Note that your --syscall-limit implementation detaches from the parent > process in a way that causes it to be killed by strace with SIGTERM, > so the remaining code is not reached. I'm not sure you planned to > implement --syscall-limit this way, and I'm doubt that users would > expect such behavior. This is also in contrast with --detach-on=execve > which also detaches its tracee but doesn't kill it, see detach_on_execve > handling in maybe_allocate_tcb(). No, it wasn't my intention to kill the tracee with SIGTERM on detaching. I'll take a look at --detach-on=execve to understand the detaching process better. > > + printf("+++ exited with 0 +++\n"); > > + > > + ppid = getpid(); > > + ppid = getppid(); > > + printf("%u getpid() = %d\n", pid, pid); > > + printf("%u getppid() = %d\n", pid, ppid); > > + printf("+++ exited with 0 +++\n"); > > + return WEXITSTATUS(status); > > +} > > So this code works unless executed under strace --syscall-limit. Yes, this is what I expect when a process is started under strace with the --syscall-limit option (strace --syscall-limit=NUMBER process). But if the process is already running as a stand-alone process, and strace is attached to the process via the -p option, then I would expect the process to run to completion normally even after getting detached from strace. > > + > > +int > > +main(int argc, char **argv) > > +{ > > + return syscall_limit_detach(); > > +} > > It would be better to declare main without arguments if they are not going > to be used anyway. I was thinking of making use of arguments when adding the tests for the --trace-path and --status options. I was thinking of having different bash scripts for each option. But each script will make use of the same .c file. I'll use "QUIRK:PROG-ARGS" to pass an argument to the main function. Based on that argument, the relevant helper function will be called. Thanks, Sahil From ldv at strace.io Sat Feb 25 21:04:31 2023 From: ldv at strace.io (Dmitry V. Levin) Date: Sun, 26 Feb 2023 00:04:31 +0300 Subject: [RFC v1] [GSoC] Add test for -l/--syscall-limit option In-Reply-To: <21787488.EfDdHjke4D@archlinux> References: <20230220184709.1018315-1-icegambit91@gmail.com> <20230224181558.GA7758@altlinux.org> <21787488.EfDdHjke4D@archlinux> Message-ID: <20230225210431.GA22528@altlinux.org> On Sat, Feb 25, 2023 at 09:47:34PM +0530, Sahil Siddiq wrote: > On Friday, 24 February 2023 23:45:58 IST Dmitry V. Levin wrote: [...] > > Note that your --syscall-limit implementation detaches from the parent > > process in a way that causes it to be killed by strace with SIGTERM, > > so the remaining code is not reached. I'm not sure you planned to > > implement --syscall-limit this way, and I'm doubt that users would > > expect such behavior. This is also in contrast with --detach-on=execve > > which also detaches its tracee but doesn't kill it, see detach_on_execve > > handling in maybe_allocate_tcb(). > > No, it wasn't my intention to kill the tracee with SIGTERM on detaching. I'll take > a look at --detach-on=execve to understand the detaching process better. > > > > + printf("+++ exited with 0 +++\n"); > > > + > > > + ppid = getpid(); > > > + ppid = getppid(); > > > + printf("%u getpid() = %d\n", pid, pid); > > > + printf("%u getppid() = %d\n", pid, ppid); > > > + printf("+++ exited with 0 +++\n"); > > > + return WEXITSTATUS(status); > > > +} > > > > So this code works unless executed under strace --syscall-limit. > > Yes, this is what I expect when a process is started under strace with the > --syscall-limit option (strace --syscall-limit=NUMBER process). But if the > process is already running as a stand-alone process, and strace is attached > to the process via the -p option, then I would expect the process to run to > completion normally even after getting detached from strace. When strace terminates, it detaches from all its tracees, but it also terminates the process it started. Besides that, it doesn't try to terminate any other tracee. See cleanup() for details. -- ldv From ldv at strace.io Sun Feb 26 22:49:45 2023 From: ldv at strace.io (Dmitry V. Levin) Date: Mon, 27 Feb 2023 00:49:45 +0200 Subject: strace 6.2 released Message-ID: <20230226224945.GB3440@altlinux.org> Starting with version 4.13, strace follows the schedule of linux kernel and new versions of strace are released along with new versions of linux kernel, so strace 6.2 is tagged and uploaded. $ git tag -v v6.2 2> /dev/null | sed -n '/^$/,$p' Noteworthy changes in strace 6.2 (2023-02-26) ============================================= * Improvements * Implemented collision resolution for overlapping ioctl commands from tty and snd subsystems. * Implemented decoding of IFLA_BRPORT_MAB and IFLA_DEVLINK_PORT netlink attributes. * Updated lists of ALG_*, BPF_*, IFLA_*, KEY_*, KVM_*, LANDLOCK_*, MEMBARRIER_*, NFT_*, NTF_*, and V4L2_* constants. * Updated lists of ioctl commands from Linux 6.2. * Bug fixes * Fixed build on alpha architecture. Contributors ============ This release was made possible by the contributions of many people. The maintainers are grateful to everyone who has contributed changes or bug reports. These include: * Dmitry V. Levin * Elvira Khabirova * Fabrice Le Fessant * Gleb Fotengauer-Malinovskiy * Helge Deller * Jan Macku * Masatake YAMATO * Sven Schnelle Please refer to the CREDITS file for the full list of strace contributors. -- ldv