2 Copyright © 2009-2012, The AROS Development Team. All rights reserved.
5 Bifteck -- Retrieves memory-stored debug output.
8 #include <exec/memory.h>
11 #include <proto/exec.h>
12 #include <proto/dos.h>
22 ULONG length
; /* number of data bytes that follow */
27 struct SignalSemaphore lock
;
28 struct MinList buffers
;
29 struct LogBlock
*block
;
34 static TEXT
GetLogChar(struct LogData
*data
, struct LogBlock
**block
,
37 const TEXT
template[] = "TO/K";
38 const TEXT version_string
[] = "$VER: Bifteck 41.2 (30.8.2012)";
40 static const TEXT data_name
[] = "bifteck";
45 struct RDArgs
*read_args
;
46 LONG error
= 0, result
= RETURN_OK
;
48 struct Args args
= {NULL
};
50 struct LogBlock
*block
;
52 TEXT ch
, old_ch
= '\n';
56 read_args
= ReadArgs(template, (SIPTR
*)&args
, NULL
);
61 data
= (struct LogData
*)FindSemaphore("bifteck");
64 if (read_args
!= NULL
&& data
!= NULL
)
66 ObtainSemaphore(&data
->lock
);
67 block
= (struct LogBlock
*)data
->buffers
.mlh_Head
;
72 output
= Open(args
.to
, MODE_NEWFILE
);
78 if (output
!= (BPTR
)NULL
)
80 while ((ch
= GetLogChar(data
, &block
, &pos
)) != '\0' && error
== 0)
83 if (SetSignal(0, SIGBREAKF_CTRL_C
) & SIGBREAKF_CTRL_C
)
98 /* Close the destination file */
100 if (args
.to
!= NULL
&& output
!= BNULL
)
103 ReleaseSemaphore(&data
->lock
);
107 result
= RETURN_FAIL
;
108 if (read_args
!= NULL
&& data
== NULL
)
110 PutStr("Debug data not found. "
111 "Add \"debug=memory\" to boot options.\n");
112 error
= ERROR_OBJECT_NOT_FOUND
;
120 /* Print any error message and exit */
122 if (result
== RETURN_OK
)
125 PrintFault(error
, NULL
);
131 static TEXT
GetLogChar(struct LogData
*data
, struct LogBlock
**block
,
136 /* Move on to next block if necessary */
138 if (*pos
== (*block
)->length
)
140 *block
= (struct LogBlock
*)(*block
)->node
.mln_Succ
;
144 /* Retrieve a character if the current block is valid and we're not past
145 the used portion of the last block. Assume that block_pos is updated
148 if ((*block
)->node
.mln_Succ
!= NULL
149 && (*block
!= data
->block
|| *pos
< data
->block_pos
))
150 ch
= ((UBYTE
*)*block
)[sizeof(struct LogBlock
) + (*pos
)++];