[PATCH] Make --tips more easily available

Dmitry V. Levin ldv at strace.io
Sat Apr 1 10:55:07 UTC 2023


Allow --tips option to be used without any tracing, so that tips, tricks
and tweaks could be displayed without running any program or attaching
to any process.

* src/strace.c (init): When --tips is specified without running any
program or attaching to any process, show the tips and exit.
* tests/strace--tips-0.exp: New file.
* tests/Makefile.am (check_DATA): Add it.
* tests/strace--tips.test: Check that simple "strace --tips=0" works
as expected.
* tests/options-syntax.test: Update expected output.
---
 src/strace.c              |  4 ++++
 tests/Makefile.am         |  1 +
 tests/options-syntax.test |  2 +-
 tests/strace--tips-0.exp  | 10 ++++++++++
 tests/strace--tips.test   |  5 +++++
 5 files changed, 21 insertions(+), 1 deletion(-)
 create mode 100644 tests/strace--tips-0.exp

diff --git a/src/strace.c b/src/strace.c
index 21b693d02..7a58bdbd6 100644
--- a/src/strace.c
+++ b/src/strace.c
@@ -2606,6 +2606,10 @@ init(int argc, char *argv[])
 	argc -= optind;
 
 	if (argc < 0 || (!nprocs && !argc)) {
+		if (show_tips != TIPS_NONE) {
+			print_totd();
+			exit(exit_code);
+		}
 		error_msg_and_help("must have PROG [ARGS] or -p PID");
 	}
 
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 9cbfc33f8..70153a5b1 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -718,6 +718,7 @@ check_DATA = \
 	strace--syscall-times-s.expected \
 	strace--syscall-times-us.expected \
 	strace--tips.exp \
+	strace--tips-0.exp \
 	strace-T_upper.expected \
 	strauss_body.exp \
 	strauss_head.exp \
diff --git a/tests/options-syntax.test b/tests/options-syntax.test
index c400fa689..c76c161d9 100755
--- a/tests/options-syntax.test
+++ b/tests/options-syntax.test
@@ -95,7 +95,7 @@ for opt in '--tips' \
 	   '--tips=format:compact --tips' \
 	   '--tips --tips=format:full,3,none,id:42,compact'
 do
-	check_h "must have PROG [ARGS] or -p PID" $opt
+	check_h "invalid -a argument: '-42'" $opt -a -42
 done
 
 check_h 'PROG [ARGS] must be specified with -D/--daemonize' -D -p $$
diff --git a/tests/strace--tips-0.exp b/tests/strace--tips-0.exp
new file mode 100644
index 000000000..9fb3d1f56
--- /dev/null
+++ b/tests/strace--tips-0.exp
@@ -0,0 +1,10 @@
+  ______________________________________________         ____
+ /                                              \       /    \
+ | strace has an extensive manual page          |      |-. .-.|
+ | that covers all the possible options         \      (_@)(_@)
+ | and contains several useful invocation        \     .---_  \
+ | examples.                                     _\   /..   \_/
+ |                                              /     |__.-^ /
+ |                                              |         }  |
+ \______________________________________________/        |   [
+                                                         [  ]
diff --git a/tests/strace--tips.test b/tests/strace--tips.test
index c08733bbc..7bb89c0d0 100755
--- a/tests/strace--tips.test
+++ b/tests/strace--tips.test
@@ -11,6 +11,11 @@ tips_fmt_opt=""
 [ 1 -ne "$TIPS_FULL" ] || tips_fmt_opt="--tips=full"
 
 
+# Check that simple "strace --tips=0" works as expected
+args='--tips=0'
+"$STRACE" $args 2> "${OUT}"
+match_diff "${OUT}" $srcdir/strace--tips-0.exp
+
 # Check that random tip is random
 "$STRACE" -qqq -enone --tips $tips_fmt_opt ../sleep 0 2> "${OUT}.r0"
 i=0

-- 
ldv


More information about the Strace-devel mailing list