From 35708fa9001592826bb0077c1311ec00b5237acb Mon Sep 17 00:00:00 2001 From: Jonas 'Sortie' Termansen Date: Tue, 5 Aug 2014 00:39:59 +0200 Subject: [PATCH] Retire calltrace support in favor of the kernel debugger. --- kernel/Makefile | 4 -- kernel/calltrace.cpp | 44 ------------------ kernel/include/sortix/kernel/calltrace.h | 36 --------------- kernel/interrupt.cpp | 1 - kernel/panic.cpp | 9 ---- kernel/x64/calltrace.S | 57 ----------------------- kernel/x86-family/interrupt.cpp | 22 --------- kernel/x86/calltrace.S | 59 ------------------------ libc/Makefile | 2 - libc/calltrace/calltrace.cpp | 44 ------------------ libc/include/calltrace.h | 36 --------------- libc/stdlib/abort.cpp | 7 --- libc/x64/calltrace.S | 53 --------------------- libc/x86/calltrace.S | 55 ---------------------- 14 files changed, 429 deletions(-) delete mode 100644 kernel/calltrace.cpp delete mode 100644 kernel/include/sortix/kernel/calltrace.h delete mode 100644 kernel/x64/calltrace.S delete mode 100644 kernel/x86/calltrace.S delete mode 100644 libc/calltrace/calltrace.cpp delete mode 100644 libc/include/calltrace.h delete mode 100644 libc/x64/calltrace.S delete mode 100644 libc/x86/calltrace.S diff --git a/kernel/Makefile b/kernel/Makefile index a4b44668..48b67b6b 100644 --- a/kernel/Makefile +++ b/kernel/Makefile @@ -5,7 +5,6 @@ include ../dirs.mak # Default values in case the user doesn't override these variables. OPTLEVEL?=$(DEFAULT_HOST_OPTLEVEL) -CALLTRACE?=0 DISKWRITE?=1 CPPFLAGS?= CXXFLAGS?=$(OPTLEVEL) @@ -20,7 +19,6 @@ ifeq ($(PANIC_SHORT),1) CPPFLAGS:=$(CPPFLAGS) -DPANIC_SHORT endif CPPFLAGS:=$(CPPFLAGS) -DENABLE_DISKWRITE=$(DISKWRITE) -CPPFLAGS:=$(CPPFLAGS) -DENABLE_CALLTRACE=$(CALLTRACE) ifdef VERSION CPPFLAGS:=$(CPPFLAGS) -DVERSIONSTR=\"$(VERSION)\" endif @@ -75,11 +73,9 @@ $(CPUOBJS) \ addralloc.o \ alarm.o \ ata.o \ -calltrace.o \ clock.o \ com.o \ copy.o \ -$(CPU)/calltrace.o \ $(CPU)/kthread.o \ crc32.o \ debugger.o \ diff --git a/kernel/calltrace.cpp b/kernel/calltrace.cpp deleted file mode 100644 index 67615a84..00000000 --- a/kernel/calltrace.cpp +++ /dev/null @@ -1,44 +0,0 @@ -/******************************************************************************* - - Copyright(C) Jonas 'Sortie' Termansen 2012, 2013. - - This file is part of Sortix. - - Sortix is free software: you can redistribute it and/or modify it under the - terms of the GNU General Public License as published by the Free Software - Foundation, either version 3 of the License, or (at your option) any later - version. - - Sortix is distributed in the hope that it will be useful, but WITHOUT ANY - WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS - FOR A PARTICULAR PURPOSE. See the GNU General Public License for more - details. - - You should have received a copy of the GNU General Public License along with - Sortix. If not, see . - - calltrace.cpp - Traverses the stack and prints the callstack, which aids debugging. - -*******************************************************************************/ - -#include -#include - -namespace Sortix { -namespace Calltrace { - -extern "C" void calltrace(unsigned long ptr); -extern "C" void calltrace_print_function(size_t index, addr_t ip) -{ - Log::PrintF("%zu: 0x%zx\n", index, ip); -} - -void Perform(unsigned long ptr) -{ - Log::PrintF("Calltrace:\n"); - calltrace(ptr); -} - -} // namespace Calltrace -} // namespace Sortix diff --git a/kernel/include/sortix/kernel/calltrace.h b/kernel/include/sortix/kernel/calltrace.h deleted file mode 100644 index 7858047e..00000000 --- a/kernel/include/sortix/kernel/calltrace.h +++ /dev/null @@ -1,36 +0,0 @@ -/******************************************************************************* - - Copyright(C) Jonas 'Sortie' Termansen 2012, 2013. - - This file is part of Sortix. - - Sortix is free software: you can redistribute it and/or modify it under the - terms of the GNU General Public License as published by the Free Software - Foundation, either version 3 of the License, or (at your option) any later - version. - - Sortix is distributed in the hope that it will be useful, but WITHOUT ANY - WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS - FOR A PARTICULAR PURPOSE. See the GNU General Public License for more - details. - - You should have received a copy of the GNU General Public License along with - Sortix. If not, see . - - sortix/kernel/calltrace.h - Traverses the stack and prints the callstack, which aids debugging. - -*******************************************************************************/ - -#ifndef INCLUDE_SORTIX_KERNEL_CALLTRACE_H -#define INCLUDE_SORTIX_KERNEL_CALLTRACE_H - -namespace Sortix { -namespace Calltrace { - -void Perform(unsigned long ptr = 0); - -} // namespace Calltrace -} // namespace Sortix - -#endif diff --git a/kernel/interrupt.cpp b/kernel/interrupt.cpp index c18b95e8..f9bcf4db 100644 --- a/kernel/interrupt.cpp +++ b/kernel/interrupt.cpp @@ -26,7 +26,6 @@ #include #include -#include #include #include #include diff --git a/kernel/panic.cpp b/kernel/panic.cpp index 4a3ec4e4..d1721030 100644 --- a/kernel/panic.cpp +++ b/kernel/panic.cpp @@ -25,7 +25,6 @@ #include #include -#include #include #include #include @@ -116,18 +115,10 @@ void PanicInit() longpanic ? PanicLogoLong() : PanicLogoShort(); } -static void PanicCalltrace() -{ - Log::Print("\n"); - Calltrace::Perform(); -} - static void PanicHooks() { if ( doublepanic ) return; - if ( ENABLE_CALLTRACE ) - PanicCalltrace(); } extern "C" __attribute__((noreturn)) void Panic(const char* error) diff --git a/kernel/x64/calltrace.S b/kernel/x64/calltrace.S deleted file mode 100644 index 3c31b490..00000000 --- a/kernel/x64/calltrace.S +++ /dev/null @@ -1,57 +0,0 @@ -/******************************************************************************* - - Copyright(C) Jonas 'Sortie' Termansen 2012, 2013. - - This file is part of Sortix. - - Sortix is free software: you can redistribute it and/or modify it under the - terms of the GNU General Public License as published by the Free Software - Foundation, either version 3 of the License, or (at your option) any later - version. - - Sortix is distributed in the hope that it will be useful, but WITHOUT ANY - WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS - FOR A PARTICULAR PURPOSE. See the GNU General Public License for more - details. - - You should have received a copy of the GNU General Public License along with - Sortix. If not, see . - - x64/calltrace.S - Attempts to unwind the stack and prints the code locations where functions - were called. This greatly aids debugging. - -*******************************************************************************/ - -.section .text - -.global calltrace -.type calltrace, @function -calltrace: - push %rbp - push %rbx - movq %rsp, %rbp - push %rbx - movq %rdi, %rbx - testq %rbx, %rbx - jnz 1f - movq %rbp, %rbx -1: - xorl %edi, %edi - -calltrace_unwind: - testq %rbx, %rbx - jz calltrace_done - movq 8(%rbx), %rsi # Previous RIP - movq 0(%rbx), %rbx # Previous RBP - pushq %rdi - call calltrace_print_function - popq %rdi - incq %rdi - jmp calltrace_unwind - -calltrace_done: - popq %rbx - popq %rbp - retq -.size calltrace, . - calltrace diff --git a/kernel/x86-family/interrupt.cpp b/kernel/x86-family/interrupt.cpp index 4c386f6d..3ea1b9f6 100644 --- a/kernel/x86-family/interrupt.cpp +++ b/kernel/x86-family/interrupt.cpp @@ -28,7 +28,6 @@ #include #include -#include #include #include #include @@ -104,8 +103,6 @@ namespace Interrupt { extern "C" { unsigned long asm_is_cpu_interrupted = 0; } -const bool CALLTRACE_KERNEL = false; -const bool CALLTRACE_USER = false; const bool RUN_DEBUGGER_ON_KERNEL_CRASH = false; const bool RUN_DEBUGGER_ON_USER_CRASH = false; @@ -260,26 +257,11 @@ uintptr_t ExceptionLocation(const struct interrupt_context* intctx) #endif } -void CrashCalltrace(const struct interrupt_context* intctx) -{ -#if defined(__x86_64__) - Calltrace::Perform(intctx->rbp); -#elif defined(__i386__) - Calltrace::Perform(intctx->ebp); -#else - #warning "Please provide a calltrace implementation for your CPU." -#endif -} - __attribute__((noreturn)) void KernelCrashHandler(struct interrupt_context* intctx) { Scheduler::SaveInterruptedContext(intctx, &CurrentThread()->registers); - // Walk and print the stack frames if this is a debug build. - if ( CALLTRACE_KERNEL ) - CrashCalltrace(intctx); - // Possibly switch to the kernel debugger in event of a crash. if ( RUN_DEBUGGER_ON_KERNEL_CRASH ) Debugger::Run(false); @@ -310,10 +292,6 @@ void UserCrashHandler(struct interrupt_context* intctx) return Signal::DispatchHandler(intctx, NULL); } - // Walk and print the stack frames if this is a debug build. - if ( CALLTRACE_USER ) - CrashCalltrace(intctx); - // Possibly switch to the kernel debugger in event of a crash. if ( RUN_DEBUGGER_ON_USER_CRASH ) Debugger::Run(false); diff --git a/kernel/x86/calltrace.S b/kernel/x86/calltrace.S deleted file mode 100644 index 735874b4..00000000 --- a/kernel/x86/calltrace.S +++ /dev/null @@ -1,59 +0,0 @@ -/******************************************************************************* - - Copyright(C) Jonas 'Sortie' Termansen 2012, 2013. - - This file is part of Sortix. - - Sortix is free software: you can redistribute it and/or modify it under the - terms of the GNU General Public License as published by the Free Software - Foundation, either version 3 of the License, or (at your option) any later - version. - - Sortix is distributed in the hope that it will be useful, but WITHOUT ANY - WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS - FOR A PARTICULAR PURPOSE. See the GNU General Public License for more - details. - - You should have received a copy of the GNU General Public License along with - Sortix. If not, see . - - x86/calltrace.S - Attempts to unwind the stack and prints the code locations where functions - were called. This greatly aids debugging. - -*******************************************************************************/ - -.section .text - -.global calltrace -.type calltrace, @function -calltrace: - push %ebp - push %ebx - movl %esp, %ebp - push %ebx - movl 8(%ebp), %ebx - testl %ebx, %ebx - jnz 1f - movl %ebp, %ebx -1: - xorl %edi, %edi - -calltrace_unwind: - testl %ebx, %ebx - jz calltrace_done - movl 4(%ebx), %esi # Previous EIP - movl 0(%ebx), %ebx # Previous EBP - pushl %esi - pushl %edi - call calltrace_print_function - popl %edi - addl $4, %esp - incl %edi - jmp calltrace_unwind - -calltrace_done: - popl %ebx - popl %ebp - retl -.size calltrace, . - calltrace diff --git a/libc/Makefile b/libc/Makefile index 02c04522..f50b5a85 100644 --- a/libc/Makefile +++ b/libc/Makefile @@ -313,8 +313,6 @@ arpa/inet/inet_addr.o \ arpa/inet/inet_ntoa.o \ arpa/inet/inet_ntop.o \ arpa/inet/inet_pton.o \ -calltrace/calltrace.o \ -$(CPUDIR)/calltrace.o \ $(CPUDIR)/fork.o \ $(CPUDIR)/setjmp.o \ $(CPUDIR)/signal.o \ diff --git a/libc/calltrace/calltrace.cpp b/libc/calltrace/calltrace.cpp deleted file mode 100644 index dccacf34..00000000 --- a/libc/calltrace/calltrace.cpp +++ /dev/null @@ -1,44 +0,0 @@ -/******************************************************************************* - - Copyright(C) Jonas 'Sortie' Termansen 2012. - - This file is part of the Sortix C Library. - - The Sortix C Library is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License as published by - the Free Software Foundation, either version 3 of the License, or (at your - option) any later version. - - The Sortix C Library is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY - or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public - License for more details. - - You should have received a copy of the GNU Lesser General Public License - along with the Sortix C Library. If not, see . - - calltrace/calltrace.cpp - Traverses the stack and prints the callstack. - -*******************************************************************************/ - -#include -#include -#include -#include -#include - -extern "C" void asm_calltrace(); - -extern "C" void calltrace_print_function(size_t index, unsigned long ip) -{ - fprintf(stdout, "[pid=%ji %s] %zu: 0x%lx\n", (intmax_t) getpid(), - program_invocation_short_name, index, ip); -} - -extern "C" void calltrace() -{ - fprintf(stdout, "[pid=%ji %s] Calltrace: (%s)\n", (intmax_t) getpid(), - program_invocation_short_name, program_invocation_name); - asm_calltrace(); -} diff --git a/libc/include/calltrace.h b/libc/include/calltrace.h deleted file mode 100644 index df83bc94..00000000 --- a/libc/include/calltrace.h +++ /dev/null @@ -1,36 +0,0 @@ -/******************************************************************************* - - Copyright(C) Jonas 'Sortie' Termansen 2012. - - This file is part of the Sortix C Library. - - The Sortix C Library is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License as published by - the Free Software Foundation, either version 3 of the License, or (at your - option) any later version. - - The Sortix C Library is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY - or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public - License for more details. - - You should have received a copy of the GNU Lesser General Public License - along with the Sortix C Library. If not, see . - - calltrace.h - Traverses the stack and prints the callstack. - -*******************************************************************************/ - -#ifndef _CALLTRACE_H -#define _CALLTRACE_H 1 - -#include - -__BEGIN_DECLS - -void calltrace(); - -__END_DECLS - -#endif diff --git a/libc/stdlib/abort.cpp b/libc/stdlib/abort.cpp index 0524d778..4194119b 100644 --- a/libc/stdlib/abort.cpp +++ b/libc/stdlib/abort.cpp @@ -25,7 +25,6 @@ #include #include -#include #include #include #include @@ -44,12 +43,6 @@ extern "C" void abort(void) extern "C" void abort(void) { - struct stat st; - if ( stat("/etc/calltrace", &st) == 0 ) - calltrace(); - if ( stat("/etc/calltrace_loop", &st) == 0 ) - while ( true ); - sigset_t set_of_sigabrt; sigemptyset(&set_of_sigabrt); sigaddset(&set_of_sigabrt, SIGABRT); diff --git a/libc/x64/calltrace.S b/libc/x64/calltrace.S deleted file mode 100644 index 11eb18e7..00000000 --- a/libc/x64/calltrace.S +++ /dev/null @@ -1,53 +0,0 @@ -/******************************************************************************* - - Copyright(C) Jonas 'Sortie' Termansen 2011, 2012, 2013. - - This file is part of the Sortix C Library. - - The Sortix C Library is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License as published by - the Free Software Foundation, either version 3 of the License, or (at your - option) any later version. - - The Sortix C Library is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY - or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public - License for more details. - - You should have received a copy of the GNU Lesser General Public License - along with the Sortix C Library. If not, see . - - x64/calltrace.S - Attempts to unwind the stack and prints the code locations where functions - were called. This greatly aids debugging. - -*******************************************************************************/ - -.global asm_calltrace -.type asm_calltrace, @function -asm_calltrace: - push %rbp - mov %rsp, %rbp - push %rbx - push %r12 - xor %r12, %r12 - mov %rbp, %rbx - -.Lasm_calltrace_unwind: - test %rbx, %rbx - jz .Lasm_calltrace_done - mov 8(%rbx), %rsi # Previous RIP - mov 0(%rbx), %rbx # Previous RBP - test %rsi, %rsi - jz .Lasm_calltrace_done - mov %r12, %rdi - call calltrace_print_function - inc %r12 - jmp .Lasm_calltrace_unwind - -.Lasm_calltrace_done: - pop %r12 - pop %rbx - pop %rbp - ret -.size asm_calltrace, . - asm_calltrace diff --git a/libc/x86/calltrace.S b/libc/x86/calltrace.S deleted file mode 100644 index 7156e682..00000000 --- a/libc/x86/calltrace.S +++ /dev/null @@ -1,55 +0,0 @@ -/******************************************************************************* - - Copyright(C) Jonas 'Sortie' Termansen 2011, 2012, 2013. - - This file is part of the Sortix C Library. - - The Sortix C Library is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License as published by - the Free Software Foundation, either version 3 of the License, or (at your - option) any later version. - - The Sortix C Library is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY - or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public - License for more details. - - You should have received a copy of the GNU Lesser General Public License - along with the Sortix C Library. If not, see . - - x86/calltrace.S - Attempts to unwind the stack and prints the code locations where functions - were called. This greatly aids debugging. - -*******************************************************************************/ - -.global asm_calltrace -.type asm_calltrace, @function -asm_calltrace: - push %ebp - mov %esp, %ebp - push %ebx - push %esi - xor %esi, %esi - mov %ebp, %ebx - -.Lasm_calltrace_unwind: - test %ebx, %ebx - jz .Lasm_calltrace_done - mov 4(%ebx), %ecx # Previous EIP - mov 0(%ebx), %ebx # Previous EBP - test %ecx, %ecx - jz .Lasm_calltrace_done - push %ecx - push %esi - call calltrace_print_function - add $8, %esp - inc %esi - jmp .Lasm_calltrace_unwind - -.Lasm_calltrace_done: - pop %esi - pop %ebx - pop %ebp - ret -.size asm_calltrace, . - asm_calltrace