Changeset 26684

Show
Ignore:
Timestamp:
07/30/08 06:03:22 (4 months ago)
Author:
axeld
Message:

* Made struct ring_buffer public (within the kernel).
* Added "syslog" command that dumps the contents of the syslog ring buffer into

KDL. Use the '-n' option to only show what hasn't been sent to the syslog
daemon yet.

* When entering the kernel debugger, the current thread ID and name are also

printed (not only the current CPU).

Location:
haiku/trunk
Files:
3 modified

Legend:

Unmodified
Added
Removed
  • haiku/trunk/headers/private/kernel/util/ring_buffer.h

    r12357 r26684  
    1010 
    1111 
    12 struct ring_buffer; 
     12struct ring_buffer { 
     13        int32           first; 
     14        int32           in; 
     15        int32           size; 
     16        uint8           buffer[0]; 
     17}; 
     18 
    1319 
    1420#ifdef __cplusplus 
  • haiku/trunk/src/system/kernel/debug/debug.cpp

    r26581 r26684  
    11/* 
    2  * Copyright 2002-2008, Axel Dörfler, axeld@pinc-software.de 
     2 * Copyright 2002-2008, Axel Dörfler, axeld@pinc-software.de. 
    33 * Distributed under the terms of the MIT License. 
    44 * 
     
    651651        sDebuggerOnCPU = smp_get_current_cpu(); 
    652652 
    653         // set a few temporary debug variables 
     653        kprintf("Welcome to Kernel Debugging Land...\n"); 
     654 
    654655        if (struct thread* thread = thread_get_current_thread()) { 
     656                // set a few temporary debug variables 
    655657                set_debug_variable("_thread", (uint64)(addr_t)thread); 
    656658                set_debug_variable("_threadID", thread->id); 
     
    658660                set_debug_variable("_teamID", thread->team->id); 
    659661                set_debug_variable("_cpu", sDebuggerOnCPU); 
    660         } 
    661  
    662         kprintf("Welcome to Kernel Debugging Land...\n"); 
    663         kprintf("Running on CPU %ld\n", sDebuggerOnCPU); 
     662 
     663                kprintf("Thread %ld \"%s\" running on CPU %ld\n", thread->id, 
     664                        thread->name, sDebuggerOnCPU); 
     665        } else 
     666                kprintf("Running on CPU %ld\n", sDebuggerOnCPU); 
    664667 
    665668        int32 continuableLine = -1; 
     
    719722 
    720723 
     724static int 
     725cmd_dump_syslog(int argc, char **argv) 
     726{ 
     727        if (!sSyslogOutputEnabled) { 
     728                kprintf("Syslog is not enabled.\n"); 
     729                return 0; 
     730        } 
     731 
     732        bool currentOnly = false; 
     733        if (argc > 1) { 
     734                if (!strcmp(argv[1], "-n")) 
     735                        currentOnly = true; 
     736                else { 
     737                        print_debugger_command_usage(argv[0]); 
     738                        return 0; 
     739                } 
     740        } 
     741 
     742        uint32 start = sSyslogBuffer->first; 
     743        size_t end = start + sSyslogBuffer->in; 
     744        if (!currentOnly) { 
     745                // Start the buffer after the current end (we don't really know if 
     746                // this part has been written to already). 
     747                start = (start + sSyslogBuffer->in) % sSyslogBuffer->size; 
     748                end = start + sSyslogBuffer->size; 
     749        } else if (!ring_buffer_readable(sSyslogBuffer)) { 
     750                kprintf("Syslog is empty.\n"); 
     751                return 0; 
     752        } 
     753 
     754        // break it down to lines to make it grep'able 
     755 
     756        bool newLine = false; 
     757        char line[256]; 
     758        size_t linePos = 0; 
     759        for (int32 i = start; i < end; i++) { 
     760                char c = sSyslogBuffer->buffer[i % sSyslogBuffer->size]; 
     761                if (c == '\0' || (uint8)c == 0xcc) 
     762                        continue; 
     763 
     764                line[linePos++] = c; 
     765                newLine = false; 
     766 
     767                if (c == '\n' || linePos == sizeof(line) - 1) { 
     768                        newLine = c == '\n'; 
     769                        line[linePos] = '\0'; 
     770                        linePos = 0; 
     771                        kprintf(line); 
     772                } 
     773        } 
     774        if (!newLine) 
     775                kprintf("\n"); 
     776 
     777        return 0; 
     778} 
     779 
     780 
    721781static status_t 
    722782syslog_sender(void *data) 
     
    880940                get_haiku_revision()); 
    881941        syslog_write(revisionBuffer, length); 
     942 
     943        add_debugger_command_etc("syslog", &cmd_dump_syslog, 
     944                "Dumps the syslog buffer.\n", 
     945                "[-n]\nDumps the whole syslog buffer, or, if -n is specified, only " 
     946                "the part that hasn't been send yet.\n", 0); 
    882947        return B_OK; 
    883948 
  • haiku/trunk/src/system/kernel/util/ring_buffer.cpp

    r18391 r26684  
    11/* 
    2  * Copyright 2005-2006, Axel Dörfler, axeld@pinc-software.de. All rights reserved. 
     2 * Copyright 2005-2008, Axel Dörfler, axeld@pinc-software.de. 
    33 * Distributed under the terms of the MIT License. 
    44 */ 
     
    1919#endif 
    2020 
    21 /**     This is a light-weight ring_buffer implementation. 
     21/*!     This is a light-weight ring_buffer implementation. 
    2222 *      It does not provide any locking - you are supposed to ensure thread-safety 
    2323 *      with the restrictions you choose. Unless you are passing in unsafe buffers, 
     
    2626 *      They also don't use malloc() or any kind of locking after initialization. 
    2727 */ 
    28  
    29 struct ring_buffer { 
    30         int32           first; 
    31         int32           in; 
    32         int32           size; 
    33         uint8           buffer[0]; 
    34 }; 
    3528 
    3629