Print `last logf lines on panic().

If logf is enabled, panic() will print the last lines. On small
screens this is more or less useless, but on large screens it
can be very useful for debugging.

Change-Id: I26dfc76e9ac4a2ddc2def8db1616a04f943dbba3
Reviewed-on: http://gerrit.rockbox.org/709
Reviewed-by: Thomas Martitz <kugel@rockbox.org>
Reviewed-by: Frank Gevaerts <frank@gevaerts.be>
Tested: Frank Gevaerts <frank@gevaerts.be>
This commit is contained in:
Frank Gevaerts 2014-01-05 22:20:26 +01:00
parent fe73d75e74
commit 25e50ed8f1
3 changed files with 55 additions and 0 deletions

View file

@ -39,6 +39,8 @@ extern bool logfwrap;
#define logf _logf #define logf _logf
void _logf(const char *format, ...) ATTRIBUTE_PRINTF(1, 2); void _logf(const char *format, ...) ATTRIBUTE_PRINTF(1, 2);
void logf_panic_dump(int *y);
#else /* !ROCKBOX_HAS_LOGF */ #else /* !ROCKBOX_HAS_LOGF */
/* built without logf() support enabled, replace logf() by DEBUGF() */ /* built without logf() support enabled, replace logf() by DEBUGF() */

View file

@ -32,6 +32,7 @@
#include "config.h" #include "config.h"
#include "system.h" #include "system.h"
#include "font.h" #include "font.h"
#include "lcd.h"
#ifdef HAVE_REMOTE_LCD #ifdef HAVE_REMOTE_LCD
#include "lcd-remote.h" #include "lcd-remote.h"
#endif #endif
@ -254,6 +255,54 @@ void _logf(const char *fmt, ...)
} }
#endif #endif
void logf_panic_dump(int *y)
{
int i;
/* nothing to print ? */
if(logfindex == 0 && !logfwrap)
{
lcd_puts(1, (*y)++, "no logf data");
lcd_update();
return;
}
lcd_puts(1, (*y)++, "start of logf data");
lcd_update();
i = logfindex - 2; /* The last actual characer (i.e. not '\0') */
while(i >= 0)
{
while(logfbuffer[i] != 0 && i>=0)
{
i--;
}
if(strlen( &logfbuffer[i + 1]) > 0)
{
lcd_puts(1, (*y)++, &logfbuffer[i + 1]);
lcd_update();
}
i--;
}
if(logfwrap)
{
i = MAX_LOGF_SIZE - 1;
while(i >= logfindex)
{
while(logfbuffer[i] != 0 && i >= logfindex)
{
i--;
}
if(strlen( &logfbuffer[i + 1]) > 0)
{
lcd_putsf(1, (*y)++, "%*s", (MAX_LOGF_SIZE-i) &logfbuffer[i + 1]);
lcd_update();
}
}
i--;
}
lcd_puts(1, (*y)++, "end of logf data");
lcd_update();
}
#endif #endif
#ifdef ROCKBOX_HAS_LOGDISKF #ifdef ROCKBOX_HAS_LOGDISKF

View file

@ -30,6 +30,7 @@
#include "led.h" #include "led.h"
#include "power.h" #include "power.h"
#include "system.h" #include "system.h"
#include "logf.h"
#if defined(CPU_ARM) #if defined(CPU_ARM)
#include "gcc_extensions.h" #include "gcc_extensions.h"
@ -115,6 +116,9 @@ void panicf( const char *fmt, ...)
#if defined(CPU_ARM) #if defined(CPU_ARM)
backtrace(pc, sp, &y); backtrace(pc, sp, &y);
#endif #endif
#ifdef ROCKBOX_HAS_LOGF
logf_panic_dump(&y);
#endif
#else #else
/* no LCD */ /* no LCD */
#endif #endif