Make it possible to log kprintf() to file

It's now possible to compile Emacs using cosmocc. However we need to
troubleshoot why it's event loop isn't working correctly at runtime.
This commit is contained in:
Justine Tunney 2023-06-05 04:16:15 -07:00
parent 9cc3e37263
commit f554dd800e
No known key found for this signature in database
GPG key ID: BE714B4575D6E328
12 changed files with 94 additions and 15 deletions

View file

@ -61,7 +61,8 @@ static bool IsMyDebugBinaryImpl(const char *path) {
// which is currently running in memory.
if ((size = lseek(fd, 0, SEEK_END)) != -1 &&
(map = mmap(0, size, PROT_READ, MAP_SHARED, fd, 0)) != MAP_FAILED) {
if (GetElfSymbolValue(map, size, "_etext", &value)) {
if (IsElf64Binary(map, size) &&
GetElfSymbolValue(map, size, "_etext", &value)) {
res = !_etext || value == (uintptr_t)_etext;
}
munmap(map, size);
@ -94,7 +95,8 @@ const char *FindDebugBinary(void) {
if (!once) {
p = GetProgramExecutableName();
n = strlen(p);
if (n > 4 && READ32LE(p + n - 4) == READ32LE(".dbg")) {
if (n > 4 && READ32LE(p + n - 4) == READ32LE(".dbg") ||
IsMyDebugBinary(p)) {
res = p;
} else if (n > 4 && READ32LE(p + n - 4) == READ32LE(".com") &&
n + 4 < ARRAYLEN(buf)) {