From c31363e7236f76509c306fddc2605d9f5cd21785 Mon Sep 17 00:00:00 2001 From: neil Date: Fri, 29 May 2009 16:32:32 +0000 Subject: [PATCH] A new utility to retrieve debug data from a memory buffer that has been enabled with the (i386-pc) boot option debug=memory. git-svn-id: https://svn.aros.org/svn/aros/trunk/AROS@31322 fb15a70f-31f2-0310-bbcc-cdcc74a49acc --- workbench/tools/debug/bifteck/Bifteck.c | 158 ++++++++++++++++++++++++++++ workbench/tools/debug/bifteck/mmakefile.src | 14 +++ 2 files changed, 172 insertions(+) create mode 100644 workbench/tools/debug/bifteck/Bifteck.c create mode 100644 workbench/tools/debug/bifteck/mmakefile.src diff --git a/workbench/tools/debug/bifteck/Bifteck.c b/workbench/tools/debug/bifteck/Bifteck.c new file mode 100644 index 000000000..5d9f1e02b --- /dev/null +++ b/workbench/tools/debug/bifteck/Bifteck.c @@ -0,0 +1,158 @@ +/* + Copyright © 2009, The AROS Development Team. All rights reserved. + $Id$ + + Bifteck -- Retrieves memory-stored debug output. +*/ + +#include +#include + +#include +#include + +struct Args +{ + TEXT *to; +}; + +struct LogBlock +{ + struct MinNode node; + ULONG length; /* number of data bytes that follow */ +}; + +struct LogData +{ + struct SignalSemaphore lock; + struct MinList buffers; + struct LogBlock *block; + ULONG block_pos; + APTR pool; +}; + +struct ExecBase *SysBase; +struct DosLibrary *DOSBase; +struct LocaleBase *LocaleBase; + +static TEXT GetLogChar(struct LogData *data, struct LogBlock **block, + ULONG *pos); + +const TEXT template[] = "TO/K"; +const TEXT version_string[] = "$VER: Bifteck 41.1 (29.5.2009)"; +static const TEXT data_name[] = "bifteck"; + + +LONG main(VOID) +{ + struct RDArgs *read_args; + LONG error = 0, result = RETURN_OK; + BPTR output; + struct Args args = {NULL}; + struct LogData *data; + struct LogBlock *block; + ULONG pos = 0; + TEXT ch, old_ch = '\n'; + + /* Parse arguments */ + + read_args = ReadArgs(template, (SIPTR *)&args, NULL); + + /* Get buffer */ + + Forbid(); + data = (struct Data *)FindSemaphore("bifteck"); + Permit(); + + if (read_args != NULL && data != NULL) + { + ObtainSemaphore(&data->lock); + block = (struct LogBlock *)data->buffers.mlh_Head; + + /* Get destination */ + + if (args.to != NULL) + output = Open(args.to, MODE_NEWFILE); + else + output = Output(); + + /* Type debug log */ + + if (output != (BPTR)NULL) + { + while ((ch = GetLogChar(data, &block, &pos)) != '\0' && error == 0) + { + FPutC(output,ch); + if (SetSignal(0, SIGBREAKF_CTRL_C) & SIGBREAKF_CTRL_C) + error = ERROR_BREAK; + old_ch = ch; + } + error = IoErr(); + + if (old_ch != '\n') + FPutC(output, '\n'); + } + else + { + result = RETURN_FAIL; + error = IoErr(); + } + + /* Close the destination file */ + + if (args.to != NULL && output != NULL) + Close(output); + + ReleaseSemaphore(&data->lock); + } + else + { + result = RETURN_FAIL; + if (read_args != NULL && data == NULL) + { + PutStr("Debug data not found. " + "Add \"debug=memory\" to boot options.\n"); + error = ERROR_OBJECT_NOT_FOUND; + } + else + error = IoErr(); + } + + FreeArgs(read_args); + + /* Print any error message and exit */ + + if (result == RETURN_OK) + SetIoErr(0); + else + PrintFault(error, NULL); + + return result; +} + + +static TEXT GetLogChar(struct LogData *data, struct LogBlock **block, + ULONG *pos) +{ + TEXT ch = '\0'; + + /* Move on to next block if necessary */ + + if (*pos == (*block)->length) + { + *block = (struct Block *)(*block)->node.mln_Succ; + *pos = 0; + } + + /* Retrieve a character if the current block is valid and we're not past + the used portion of the last block. Assume that block_pos is updated + atomically */ + + if ((*block)->node.mln_Succ != NULL + && (*block != data->block || *pos < data->block_pos)) + ch = ((UBYTE *)*block)[sizeof(struct LogBlock) + (*pos)++]; + + return ch; +} + + diff --git a/workbench/tools/debug/bifteck/mmakefile.src b/workbench/tools/debug/bifteck/mmakefile.src new file mode 100644 index 000000000..5bafffaf0 --- /dev/null +++ b/workbench/tools/debug/bifteck/mmakefile.src @@ -0,0 +1,14 @@ +# $Id$ +# +# Makefile for Bifteck. + +include $(TOP)/config/make.cfg + +#MM- workbench : workbench-tools +#MM workbench-tools : includes linklibs + +%build_prog mmake=workbench-tools \ + progname=Bifteck targetdir=$(AROSDIR)/Tools/Debug \ + files=Bifteck uselibs="amiga arosc" + +%common -- 2.11.4.GIT