mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-07-06 11:18:30 +00:00
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
This commit is contained in:
parent
c541225af0
commit
14e192e5ba
138 changed files with 1519 additions and 631 deletions
|
@ -20,7 +20,7 @@
|
|||
#include "libc/bits/weaken.h"
|
||||
#include "libc/calls/calls.h"
|
||||
#include "libc/calls/internal.h"
|
||||
#include "libc/calls/sysdebug.internal.h"
|
||||
#include "libc/calls/strace.internal.h"
|
||||
#include "libc/mem/mem.h"
|
||||
#include "libc/nexgen32e/bsr.h"
|
||||
#include "libc/nt/createfile.h"
|
||||
|
@ -39,7 +39,7 @@
|
|||
static textwindows ssize_t sys_readlinkat_nt_error(void) {
|
||||
uint32_t e;
|
||||
e = GetLastError();
|
||||
SYSDEBUG("sys_readlinkat_nt() error %d", e);
|
||||
STRACE("sys_readlinkat_nt() error %d", e);
|
||||
switch (e) {
|
||||
case kNtErrorNotAReparsePoint:
|
||||
return einval();
|
||||
|
@ -56,11 +56,11 @@ textwindows ssize_t sys_readlinkat_nt(int dirfd, const char *path, char *buf,
|
|||
uint64_t w;
|
||||
wint_t x, y;
|
||||
void *freeme;
|
||||
uint32_t e, i, j, n, mem;
|
||||
uint32_t i, j, n, mem;
|
||||
char16_t path16[PATH_MAX], *p;
|
||||
struct NtReparseDataBuffer *rdb;
|
||||
if (__mkntpathat(dirfd, path, 0, path16) == -1) {
|
||||
SYSDEBUG("sys_readlinkat_nt() failed b/c __mkntpathat() failed");
|
||||
STRACE("sys_readlinkat_nt() failed b/c __mkntpathat() failed");
|
||||
return -1;
|
||||
}
|
||||
if (weaken(malloc)) {
|
||||
|
@ -72,7 +72,7 @@ textwindows ssize_t sys_readlinkat_nt(int dirfd, const char *path, char *buf,
|
|||
rdb = (struct NtReparseDataBuffer *)buf;
|
||||
freeme = 0;
|
||||
} else {
|
||||
SYSDEBUG("sys_readlinkat_nt() needs bigger buffer malloc() to be yoinked");
|
||||
STRACE("sys_readlinkat_nt() needs bigger buffer malloc() to be yoinked");
|
||||
return enomem();
|
||||
}
|
||||
if ((h = CreateFile(path16, 0, 0, 0, kNtOpenExisting,
|
||||
|
@ -113,20 +113,20 @@ textwindows ssize_t sys_readlinkat_nt(int dirfd, const char *path, char *buf,
|
|||
if (freeme || (intptr_t)(buf + j) <= (intptr_t)(p + i)) {
|
||||
rc = j;
|
||||
} else {
|
||||
SYSDEBUG("sys_readlinkat_nt() too many astral codepoints");
|
||||
STRACE("sys_readlinkat_nt() too many astral codepoints");
|
||||
rc = enametoolong();
|
||||
}
|
||||
} else {
|
||||
SYSDEBUG("sys_readlinkat_nt() should have kNtIoReparseTagSymlink");
|
||||
STRACE("sys_readlinkat_nt() should have kNtIoReparseTagSymlink");
|
||||
rc = einval();
|
||||
}
|
||||
} else {
|
||||
SYSDEBUG("DeviceIoControl(kNtFsctlGetReparsePoint) failed");
|
||||
STRACE("%s failed %m", "DeviceIoControl(kNtFsctlGetReparsePoint)");
|
||||
rc = sys_readlinkat_nt_error();
|
||||
}
|
||||
CloseHandle(h);
|
||||
} else {
|
||||
SYSDEBUG("CreateFile(kNtFileFlagOpenReparsePoint) failed");
|
||||
STRACE("%s failed %m", "CreateFile(kNtFileFlagOpenReparsePoint)");
|
||||
rc = sys_readlinkat_nt_error();
|
||||
}
|
||||
if (freeme && weaken(free)) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue