From e270c9f35bb4944bdf11308b0fd64167171ec79f Mon Sep 17 00:00:00 2001 From: EnderIce2 Date: Thu, 17 Apr 2025 16:01:03 +0000 Subject: [PATCH] refactor(kernel): update debug messages --- Kernel/core/driver/api.cpp | 4 ++-- Kernel/core/symbols.cpp | 8 ++------ Kernel/exec/elf/elf_loader.cpp | 33 +++++++++++++++++++++++++++++++++ Kernel/tty/vt.cpp | 3 +-- 4 files changed, 38 insertions(+), 10 deletions(-) diff --git a/Kernel/core/driver/api.cpp b/Kernel/core/driver/api.cpp index fa44c975..bc424a4c 100644 --- a/Kernel/core/driver/api.cpp +++ b/Kernel/core/driver/api.cpp @@ -333,7 +333,7 @@ namespace v0 void PS2Wait(dev_t DriverID, const bool Output) { - dbg_api("%d, %d", DriverID, Output); + // dbg_api("%d, %d", DriverID, Output); #if defined(__amd64__) || defined(__i386__) int Timeout = 100000; @@ -379,7 +379,7 @@ namespace v0 uint8_t PS2ReadData(dev_t DriverID) { - dbg_api("%d", DriverID); + // dbg_api("%d", DriverID); #if defined(__amd64__) || defined(__i386__) WaitOutput; diff --git a/Kernel/core/symbols.cpp b/Kernel/core/symbols.cpp index 68a2eade..356bb0dc 100644 --- a/Kernel/core/symbols.cpp +++ b/Kernel/core/symbols.cpp @@ -185,17 +185,13 @@ namespace SymbolResolver if (strlen(name) == 0) continue; - SymbolTable tbl{}; + SymbolTable tbl; tbl.Address = sym->st_value; tbl.FunctionName = new char[strlen(name) + 1]; strcpy(tbl.FunctionName, name); this->SymTable.push_back(tbl); this->SymbolTableExists = true; - - // debug("Symbol %d: %#lx %s(%#lx)", - // i, tbl.Address, - // tbl.FunctionName, - // name); + // debug("Symbol %d: %#lx %s(%#lx)", i, tbl.Address, tbl.FunctionName, name); } } } diff --git a/Kernel/exec/elf/elf_loader.cpp b/Kernel/exec/elf/elf_loader.cpp index 1b606f3f..f51196cc 100644 --- a/Kernel/exec/elf/elf_loader.cpp +++ b/Kernel/exec/elf/elf_loader.cpp @@ -220,6 +220,9 @@ namespace Execute if (ProgramHeader.p_memsz == 0) continue; + if (BaseAddress == 0) + BaseAddress = ALIGN_DOWN(ProgramHeader.p_vaddr, PAGE_SIZE); + void *pAddr = vma->RequestPages(TO_PAGES(ProgramHeader.p_memsz + (ProgramHeader.p_vaddr % PAGE_SIZE)), true); void *vAddr = (void *)ALIGN_DOWN(ProgramHeader.p_vaddr, PAGE_SIZE); uintptr_t destOffset = ProgramHeader.p_vaddr - uintptr_t(vAddr); @@ -411,6 +414,14 @@ namespace Execute this->ip = entry; this->IsElfValid = true; + +#ifdef DEBUG + std::string sanitizedPath = fd->Path; + size_t pos = sanitizedPath.find("\x06root-0\x06"); + if (pos != std::string::npos) + sanitizedPath.erase(pos, std::string("\x06root-0\x06").length()); + debug("gdb: \"-exec add-symbol-file-all /workspaces/Fennix/tmp_rootfs%s %#lx\" entry:%#lx", sanitizedPath.c_str(), base, entry); +#endif } void ELFObject::LoadDyn(FileNode *fd, PCB *TargetProcess) @@ -436,7 +447,21 @@ namespace Execute this->ip = entry; this->IsElfValid = true; +#ifdef DEBUG + std::string sanitizedPath = fd->Path; + size_t pos = sanitizedPath.find("\x06root-0\x06"); + if (pos != std::string::npos) + sanitizedPath.erase(pos, std::string("\x06root-0\x06").length()); + debug("gdb: \"-exec add-symbol-file-all /workspaces/Fennix/tmp_rootfs%s %#lx\" entry:%#lx", sanitizedPath.c_str(), base, entry); +#endif + Elf_Phdr interp = ELFGetSymbolType(fd, PT_INTERP).front(); + if (interp.p_offset == 0) + { + debug("No interpreter found"); + return; + } + std::string interpreterPath; interpreterPath.resize(256); fd->Read(interpreterPath.data(), 256, interp.p_offset); @@ -490,6 +515,14 @@ namespace Execute break; } +#ifdef DEBUG + std::string sanitizedPath = fd->Path; + size_t pos = sanitizedPath.find("\x06root-0\x06"); + if (pos != std::string::npos) + sanitizedPath.erase(pos, std::string("\x06root-0\x06").length()); + debug("gdb: \"-exec add-symbol-file-all /workspaces/Fennix/tmp_rootfs%s %#lx\" entry:%#lx", sanitizedPath.c_str(), base, ehdr.e_entry); +#endif + return true; } case ET_CORE: diff --git a/Kernel/tty/vt.cpp b/Kernel/tty/vt.cpp index 90d5d27a..a3285f42 100644 --- a/Kernel/tty/vt.cpp +++ b/Kernel/tty/vt.cpp @@ -828,8 +828,7 @@ namespace KernelConsole this->Cells = new TerminalCell[Rows * Columns]; - debug("Allocated %d bytes for terminal cells", - (Rows * Columns) * sizeof(TerminalCell)); + debug("Allocated %d entries (%d bytes at %#lx-%#lx for terminal cells)", Rows * Columns, (Rows * Columns) * sizeof(TerminalCell), this->Cells, (char *)this->Cells + (Rows * Columns) * sizeof(TerminalCell)); } VirtualTerminal::~VirtualTerminal() { delete[] this->Cells; }