mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-05-22 21:32:31 +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
|
@ -22,46 +22,37 @@
|
|||
#include "libc/runtime/symbols.internal.h"
|
||||
#include "libc/str/str.h"
|
||||
|
||||
static char *g_comdbg;
|
||||
static char g_comdbg_buf[PATH_MAX + 1];
|
||||
|
||||
static optimizesize textstartup void g_comdbg_init() {
|
||||
char *p;
|
||||
size_t n;
|
||||
static bool once;
|
||||
if (!once) {
|
||||
if (!(g_comdbg = getenv("COMDBG"))) {
|
||||
p = program_executable_name;
|
||||
n = strlen(p);
|
||||
if (n > 4 && READ32LE(p + n - 4) == READ32LE(".dbg")) {
|
||||
g_comdbg = p;
|
||||
} else if (n > 4 && READ32LE(p + n - 4) == READ32LE(".com") &&
|
||||
n + 4 <= PATH_MAX) {
|
||||
mempcpy(mempcpy(g_comdbg_buf, p, n), ".dbg", 5);
|
||||
if (fileexists(g_comdbg_buf)) {
|
||||
g_comdbg = g_comdbg_buf;
|
||||
}
|
||||
} else if (n + 8 <= PATH_MAX) {
|
||||
mempcpy(mempcpy(g_comdbg_buf, p, n), ".com.dbg", 9);
|
||||
if (fileexists(g_comdbg_buf)) {
|
||||
g_comdbg = g_comdbg_buf;
|
||||
}
|
||||
}
|
||||
}
|
||||
once = true;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns path of binary with the debug information, or null.
|
||||
*
|
||||
* @return path to debug binary, or NULL
|
||||
*/
|
||||
const char *FindDebugBinary(void) {
|
||||
g_comdbg_init();
|
||||
return g_comdbg;
|
||||
static bool once;
|
||||
static char *res;
|
||||
static char buf[PATH_MAX + 1];
|
||||
char *p;
|
||||
size_t n;
|
||||
if (!once) {
|
||||
if (!(res = getenv("COMDBG"))) {
|
||||
p = program_executable_name;
|
||||
n = strlen(p);
|
||||
if (n > 4 && READ32LE(p + n - 4) == READ32LE(".dbg")) {
|
||||
res = p;
|
||||
} else if (n > 4 && READ32LE(p + n - 4) == READ32LE(".com") &&
|
||||
n + 4 <= PATH_MAX) {
|
||||
mempcpy(mempcpy(buf, p, n), ".dbg", 5);
|
||||
if (fileexists(buf)) {
|
||||
res = buf;
|
||||
}
|
||||
} else if (n + 8 <= PATH_MAX) {
|
||||
mempcpy(mempcpy(buf, p, n), ".com.dbg", 9);
|
||||
if (fileexists(buf)) {
|
||||
res = buf;
|
||||
}
|
||||
}
|
||||
}
|
||||
once = true;
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
const void *const g_comdbg_ctor[] initarray = {
|
||||
g_comdbg_init,
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue