Skip to content

Commit 18145a7

Browse files
committed
Add --hyperlink option
Introduce a new command-line option '--hyperlink' to add terminal hyperlinks (using OSC 8 escape sequences) from system call names in the trace output to their corresponding Linux manual pages on man7.org. This improves the diagnostic and educational usability of strace outputs in modern terminals supporting OSC 8. * NEWS: Mention this change. * doc/strace.1.in: Document --hyperlink option. * src/color.h (hyperlink_is_enabled): Declare. * src/print_fields.c (OSC8_BEGIN, OSC8_END, STRACE_PRINT_SYSCALL): New macros. (hyperlink_is_enabled): Define. (tprints_arg_begin): Use STRACE_PRINT_SYSCALL. * src/strace.c (usage): Document --hyperlink option. (init) <GETOPT_HYPERLINK>: New enum constant. <longopts>: Add "hyperlink" option. Handle GETOPT_HYPERLINK. * tests/Makefile.am (MISC_TESTS): Add strace--hyperlink.test. * tests/strace--hyperlink.test: New test. Assisted-by: Antigravity:gemini-3.5-flash (commit log) Signed-off-by: Masatake YAMATO <yamato@redhat.com>
1 parent 88e5c7c commit 18145a7

7 files changed

Lines changed: 57 additions & 1 deletion

File tree

NEWS

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ Noteworthy changes in release ?.? (????-??-??)
55
* Implemented decoding of IFLA_BRPORT_NEIGH_FORWARD_GRAT attribute.
66
* Updated lists of BPF_*, ETH_P_*, FS_*, IFLA_*, KVM_*, LANDLOCK_*, NL80211_*,
77
O_*, RTEXT_*, V4L2_*, and XFRM_MSG_* constants.
8+
* Added --hyperlink option that adds hyperlinks from system call names to
9+
manual pages at man7.org.
810

911
Noteworthy changes in release 7.1 (2026-06-15)
1012
==============================================

doc/strace.1.in

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1159,6 +1159,11 @@ Recognized color keys are:
11591159
.BR retval ,
11601160
.BR error .
11611161
.TP
1162+
.B \-\-hyperlink
1163+
Add hyperlinks from system call names to manual pages at
1164+
.UR https://man7.org/linux/man-pages/man2
1165+
man7.org.
1166+
.TP
11621167
.B \-q
11631168
.TQ
11641169
.B \-\-quiet

src/color.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ enum color_kind_t {
3535
extern enum color_mode_t color_mode;
3636
extern const char *color_seq_table[COLOR_KIND_MAX];
3737
extern bool color_is_enabled;
38+
extern bool hyperlink_is_enabled;
3839

3940
void color_init(int out_fd, bool output_separately);
4041

src/print_fields.c

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,18 @@
99
#include "defs.h"
1010
#include "print_fields.h"
1111

12+
#define OSC8_BEGIN "\033]8;;" "https://man7.org/linux/man-pages/man2/%s.2.html" "\033\\"
13+
#define OSC8_END "\033]8;;\033\\"
14+
#define STRACE_PRINT_SYSCALL(name) do { \
15+
if (hyperlink_is_enabled) \
16+
STRACE_PRINTF(OSC8_BEGIN "%s" OSC8_END, name, name); \
17+
else \
18+
STRACE_PRINTF("%s", name); \
19+
} \
20+
while (0)
21+
22+
bool hyperlink_is_enabled = false;
23+
1224
void
1325
tprint_struct_begin(void)
1426
{
@@ -101,7 +113,7 @@ void
101113
tprints_arg_begin(const char *name)
102114
{
103115
STRACE_PRINT_COLOR_SEQ(COLOR_SYSCALL);
104-
STRACE_PRINTF("%s", name);
116+
STRACE_PRINT_SYSCALL(name);
105117
STRACE_PRINT_COLOR_SEQ(COLOR_PUNCT);
106118
STRACE_PRINTS("(");
107119
STRACE_PRINT_COLOR_SEQ(COLOR_ARGVAL);

src/strace.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -371,6 +371,8 @@ Output format:\n\
371371
alignment COLUMN for printing syscall results (default %d)\n\
372372
--color[=WHEN]\n\
373373
colorize output; WHEN is auto, always, or never (default auto)\n\
374+
--hyperlink\n\
375+
add hyperlinks from system call names to manual pages at man7.org.\n\
374376
-e abbrev=SET, --abbrev=SET\n\
375377
abbreviate output for the syscalls in SET\n\
376378
-e verbose=SET, --verbose=SET\n\
@@ -2450,6 +2452,7 @@ init(int argc, char *argv[])
24502452
GETOPT_STACK_TRACE_FRAME_LIMIT,
24512453
GETOPT_ALWAYS_SHOW_PID,
24522454
GETOPT_COLOR,
2455+
GETOPT_HYPERLINK,
24532456
GETOPT_QUAL_TRACE,
24542457
GETOPT_QUAL_TRACE_FD,
24552458
GETOPT_QUAL_ABBREV,
@@ -2518,6 +2521,7 @@ init(int argc, char *argv[])
25182521
{ "argv0", required_argument, 0, GETOPT_ARGV0 },
25192522
{ "always-show-pid", no_argument, 0, GETOPT_ALWAYS_SHOW_PID },
25202523
{ "color", required_argument, 0, GETOPT_COLOR },
2524+
{ "hyperlink", no_argument, 0, GETOPT_HYPERLINK },
25212525
{ "trace", required_argument, 0, GETOPT_QUAL_TRACE },
25222526
{ "trace-fds", required_argument, 0, GETOPT_QUAL_TRACE_FD },
25232527
{ "abbrev", required_argument, 0, GETOPT_QUAL_ABBREV },
@@ -2827,6 +2831,9 @@ init(int argc, char *argv[])
28272831
color_mode = (enum color_mode_t) color_mode_raw;
28282832
break;
28292833
}
2834+
case GETOPT_HYPERLINK:
2835+
hyperlink_is_enabled = true;
2836+
break;
28302837
case GETOPT_QUAL_SECONTEXT:
28312838
qualify_secontext(optarg ? optarg : secontext_qual);
28322839
break;

tests/Makefile.am

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -716,6 +716,7 @@ MISC_TESTS = \
716716
status-unfinished-threads.test \
717717
strace--color-no-tty.test \
718718
strace--color-tty.test \
719+
strace--hyperlink.test \
719720
strace--argv0.test \
720721
strace--syscall-limit.test \
721722
strace--syscall-limit--seccomp-bpf.test \

tests/strace--hyperlink.test

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#!/bin/sh -efu
2+
#
3+
# Check --hyperlink option
4+
#
5+
# Copyright (c) 2026 Masatake YAMATO <yamato@redhat.com>
6+
# Copyright (c) 2026 The strace developers.
7+
# All rights reserved.
8+
#
9+
# SPDX-License-Identifier: GPL-2.0-or-later
10+
11+
. "${srcdir=.}/init.sh"
12+
13+
unset STRACE_COLORS
14+
unset NO_COLOR
15+
16+
TERM=linux
17+
export TERM
18+
19+
run_prog ../getpid > /dev/null
20+
21+
cmd="../getpid > /dev/null"
22+
23+
csi_color="$(printf '\033\\[')"
24+
csi_link_begin="$(printf '\033]8;;%s\033\\\\' 'https://man7\.org/linux/man-pages/man2/getpid\.2\.html')"
25+
csi_link_end="$(printf '\033]8;;\033\\\\')"
26+
printf '%s\n' ".*${csi_color}33m${csi_link_begin}getpid${csi_link_end}.*${csi_color}0m.*" > "$EXP"
27+
run_strace --trace=getpid --hyperlink --color=always ../getpid > /dev/null
28+
match_grep "$LOG" "$EXP"

0 commit comments

Comments
 (0)