Introduce --strace flag for system call tracing
This is similar to the --ftrace (c function call trace) flag, except
it's less noisy since it only logs system calls to stderr. Having this
flag is valuable because (1) system call tracing tells us a lot about
the behavior of complex programs and (2) it's usually very hard to get
system call tracing on various operating systems, e.g. strace, ktrace,
dtruss, truss, nttrace, etc. Especially on Apple platforms where even
with the special boot trick, debuggers still aren't guaranteed to work.
make -j8 o//examples
o//examples/hello.com --strace
This is enabled by default in MODE=, MODE=opt, and MODE=dbg. In MODE=dbg
extra information will be printed.
make -j8 MODE=dbg o/dbg/examples
o/dbg/examples/hello.com --strace |& less
This change also changes:
- Rename IsText() → _istext()
- Rename IsUtf8() → _isutf8()
- Fix madvise() on Windows NT
- Fix empty string case of inet_ntop()
- vfork() wrapper now saves and restores errno
- Update xsigaction() to yoink syscall support
2022-03-19 01:07:28 +00:00
|
|
|
#ifndef COSMOPOLITAN_LIBC_CALLS_STRACE_INTERNAL_H_
|
|
|
|
#define COSMOPOLITAN_LIBC_CALLS_STRACE_INTERNAL_H_
|
2023-11-10 12:14:27 +00:00
|
|
|
|
|
|
|
#ifndef SYSDEBUG
|
2023-11-29 11:45:54 +00:00
|
|
|
#define SYSDEBUG 0
|
2023-11-10 12:14:27 +00:00
|
|
|
#endif
|
Introduce --strace flag for system call tracing
This is similar to the --ftrace (c function call trace) flag, except
it's less noisy since it only logs system calls to stderr. Having this
flag is valuable because (1) system call tracing tells us a lot about
the behavior of complex programs and (2) it's usually very hard to get
system call tracing on various operating systems, e.g. strace, ktrace,
dtruss, truss, nttrace, etc. Especially on Apple platforms where even
with the special boot trick, debuggers still aren't guaranteed to work.
make -j8 o//examples
o//examples/hello.com --strace
This is enabled by default in MODE=, MODE=opt, and MODE=dbg. In MODE=dbg
extra information will be printed.
make -j8 MODE=dbg o/dbg/examples
o/dbg/examples/hello.com --strace |& less
This change also changes:
- Rename IsText() → _istext()
- Rename IsUtf8() → _isutf8()
- Fix madvise() on Windows NT
- Fix empty string case of inet_ntop()
- vfork() wrapper now saves and restores errno
- Update xsigaction() to yoink syscall support
2022-03-19 01:07:28 +00:00
|
|
|
|
2024-09-03 01:21:03 +00:00
|
|
|
#ifdef MODE_DBG
|
|
|
|
#define _STRACE_VERBOSE 1
|
|
|
|
#else
|
|
|
|
#define _STRACE_VERBOSE 0
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#define _NTTRACE _STRACE_VERBOSE /* not configurable w/ flag yet */
|
|
|
|
#define _KERNTRACE _STRACE_VERBOSE /* not configurable w/ flag yet */
|
|
|
|
#define _POLLTRACE _STRACE_VERBOSE /* not configurable w/ flag yet */
|
|
|
|
#define _LOCKTRACE _STRACE_VERBOSE /* not configurable w/ flag yet */
|
|
|
|
#define _DATATRACE 1 /* not configurable w/ flag yet */
|
|
|
|
#define _STDIOTRACE 0 /* not configurable w/ flag yet */
|
|
|
|
#define _TIMETRACE 0 /* not configurable w/ flag yet */
|
2022-04-16 17:40:23 +00:00
|
|
|
|
2023-10-03 21:47:20 +00:00
|
|
|
#define STRACE_PROLOGUE "%rSYS %6P %6H %'18T "
|
Introduce --strace flag for system call tracing
This is similar to the --ftrace (c function call trace) flag, except
it's less noisy since it only logs system calls to stderr. Having this
flag is valuable because (1) system call tracing tells us a lot about
the behavior of complex programs and (2) it's usually very hard to get
system call tracing on various operating systems, e.g. strace, ktrace,
dtruss, truss, nttrace, etc. Especially on Apple platforms where even
with the special boot trick, debuggers still aren't guaranteed to work.
make -j8 o//examples
o//examples/hello.com --strace
This is enabled by default in MODE=, MODE=opt, and MODE=dbg. In MODE=dbg
extra information will be printed.
make -j8 MODE=dbg o/dbg/examples
o/dbg/examples/hello.com --strace |& less
This change also changes:
- Rename IsText() → _istext()
- Rename IsUtf8() → _isutf8()
- Fix madvise() on Windows NT
- Fix empty string case of inet_ntop()
- vfork() wrapper now saves and restores errno
- Update xsigaction() to yoink syscall support
2022-03-19 01:07:28 +00:00
|
|
|
|
|
|
|
#if !(__ASSEMBLER__ + __LINKER__ + 0)
|
|
|
|
COSMOPOLITAN_C_START_
|
|
|
|
|
2023-11-10 12:14:27 +00:00
|
|
|
#define STRACE(FMT, ...) \
|
|
|
|
((void)(SYSDEBUG && strace_enabled(0) > 0 && \
|
|
|
|
(__stracef(STRACE_PROLOGUE FMT "\n", ##__VA_ARGS__), 0)))
|
Introduce --strace flag for system call tracing
This is similar to the --ftrace (c function call trace) flag, except
it's less noisy since it only logs system calls to stderr. Having this
flag is valuable because (1) system call tracing tells us a lot about
the behavior of complex programs and (2) it's usually very hard to get
system call tracing on various operating systems, e.g. strace, ktrace,
dtruss, truss, nttrace, etc. Especially on Apple platforms where even
with the special boot trick, debuggers still aren't guaranteed to work.
make -j8 o//examples
o//examples/hello.com --strace
This is enabled by default in MODE=, MODE=opt, and MODE=dbg. In MODE=dbg
extra information will be printed.
make -j8 MODE=dbg o/dbg/examples
o/dbg/examples/hello.com --strace |& less
This change also changes:
- Rename IsText() → _istext()
- Rename IsUtf8() → _isutf8()
- Fix madvise() on Windows NT
- Fix empty string case of inet_ntop()
- vfork() wrapper now saves and restores errno
- Update xsigaction() to yoink syscall support
2022-03-19 01:07:28 +00:00
|
|
|
|
2023-11-10 12:14:27 +00:00
|
|
|
#define DATATRACE(FMT, ...) \
|
|
|
|
((void)(SYSDEBUG && _DATATRACE && strace_enabled(0) > 0 && \
|
|
|
|
(__stracef(STRACE_PROLOGUE FMT "\n", ##__VA_ARGS__), 0)))
|
2022-04-18 07:01:26 +00:00
|
|
|
|
2023-11-10 12:14:27 +00:00
|
|
|
#define POLLTRACE(FMT, ...) \
|
|
|
|
((void)(SYSDEBUG && _POLLTRACE && strace_enabled(0) > 0 && \
|
|
|
|
(__stracef(STRACE_PROLOGUE FMT "\n", ##__VA_ARGS__), 0)))
|
2022-04-16 17:40:23 +00:00
|
|
|
|
2024-09-03 01:21:03 +00:00
|
|
|
#define KERNTRACE(FMT, ...) \
|
|
|
|
((void)(SYSDEBUG && _KERNTRACE && strace_enabled(0) > 0 && \
|
|
|
|
(__stracef(STRACE_PROLOGUE "\e[2m" FMT "\e[0m\n", ##__VA_ARGS__), \
|
|
|
|
0)))
|
2022-04-16 17:40:23 +00:00
|
|
|
|
2023-11-10 12:14:27 +00:00
|
|
|
#define STDIOTRACE(FMT, ...) \
|
|
|
|
((void)(SYSDEBUG && _STDIOTRACE && strace_enabled(0) > 0 && \
|
|
|
|
(__stracef(STRACE_PROLOGUE FMT "\n", ##__VA_ARGS__), 0)))
|
2022-10-10 05:38:28 +00:00
|
|
|
|
2023-11-10 12:14:27 +00:00
|
|
|
#define NTTRACE(FMT, ...) \
|
|
|
|
((void)(SYSDEBUG && _NTTRACE && strace_enabled(0) > 0 && \
|
|
|
|
(__stracef(STRACE_PROLOGUE "\e[2m" FMT "\e[0m\n", ##__VA_ARGS__), \
|
|
|
|
0)))
|
2022-04-16 17:40:23 +00:00
|
|
|
|
2023-11-10 12:14:27 +00:00
|
|
|
#define LOCKTRACE(FMT, ...) \
|
|
|
|
((void)(SYSDEBUG && _LOCKTRACE && strace_enabled(0) > 0 && \
|
|
|
|
(__stracef(STRACE_PROLOGUE FMT "\n", ##__VA_ARGS__), 0)))
|
2022-10-16 19:05:08 +00:00
|
|
|
|
2023-11-10 12:14:27 +00:00
|
|
|
#define TIMETRACE(FMT, ...) \
|
|
|
|
((void)(SYSDEBUG && _TIMETRACE && strace_enabled(0) > 0 && \
|
|
|
|
(__stracef(STRACE_PROLOGUE FMT "\n", ##__VA_ARGS__), 0)))
|
2023-10-03 02:25:19 +00:00
|
|
|
|
2023-11-10 12:14:27 +00:00
|
|
|
int strace_enabled(int);
|
Introduce --strace flag for system call tracing
This is similar to the --ftrace (c function call trace) flag, except
it's less noisy since it only logs system calls to stderr. Having this
flag is valuable because (1) system call tracing tells us a lot about
the behavior of complex programs and (2) it's usually very hard to get
system call tracing on various operating systems, e.g. strace, ktrace,
dtruss, truss, nttrace, etc. Especially on Apple platforms where even
with the special boot trick, debuggers still aren't guaranteed to work.
make -j8 o//examples
o//examples/hello.com --strace
This is enabled by default in MODE=, MODE=opt, and MODE=dbg. In MODE=dbg
extra information will be printed.
make -j8 MODE=dbg o/dbg/examples
o/dbg/examples/hello.com --strace |& less
This change also changes:
- Rename IsText() → _istext()
- Rename IsUtf8() → _isutf8()
- Fix madvise() on Windows NT
- Fix empty string case of inet_ntop()
- vfork() wrapper now saves and restores errno
- Update xsigaction() to yoink syscall support
2022-03-19 01:07:28 +00:00
|
|
|
void __stracef(const char *, ...);
|
|
|
|
|
|
|
|
COSMOPOLITAN_C_END_
|
|
|
|
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
|
|
|
|
#endif /* COSMOPOLITAN_LIBC_CALLS_STRACE_INTERNAL_H_ */
|