#include <debug_hooks.h>
#define DEBUG_MAX_LINE_LEN 256
-#define LOCK_DEBUG_OUTPUT 1 // Avoid interleaving of output lines?
+#define LOCK_DEBUG_OUTPUT 0 // Avoid interleaving of output lines?
#define TRACE_TO_KTERM 0 // Send ENTER/DEBUG/LEAVE to debug?
// === IMPORTS ===
IPStack_SendDebugText(Str);
// Output to the kernel terminal
- if( UseKTerm && gbDebug_IsKPanic < 2 && giDebug_KTerm != -1)
+ if( UseKTerm && gbDebug_IsKPanic < 2 && giDebug_KTerm != -1 && gbInPutChar == 0)
{
- if(gbInPutChar) return ;
gbInPutChar = 1;
VFS_Write(giDebug_KTerm, len, Str);
gbInPutChar = 0;
bool LogF(const char *Fmt, ...)
{
#if LOCK_DEBUG_OUTPUT
- if(CPU_HAS_LOCK(&glDebug_Lock)) return true;
+ if(CPU_HAS_LOCK(&glDebug_Lock)) {
+ Debug_Puts("[#]");
+ return true;
+ }
SHORTLOCK(&glDebug_Lock);
#endif
void Debug_SetKTerminal(const char *File)
{
- int tmp;
if(giDebug_KTerm != -1) {
- tmp = giDebug_KTerm;
+ // Clear FD to -1 before closing (prevents writes to closed FD)
+ int oldfd = giDebug_KTerm;
giDebug_KTerm = -1;
- VFS_Close(tmp);
+ VFS_Close(oldfd);
}
- tmp = VFS_Open(File, VFS_OPENFLAG_WRITE);
-// Log_Log("Debug", "Opened '%s' as 0x%x", File, tmp);
- giDebug_KTerm = tmp;
-// Log_Log("Debug", "Returning to %p", __builtin_return_address(0));
+ giDebug_KTerm = VFS_Open(File, VFS_OPENFLAG_WRITE);
}
void Debug_Enter(const char *FuncName, const char *ArgTypes, ...)
// If the server has terminated, send SIGPIPE
if( pty->ServerNode && pty->ServerNode->ReferenceCount == 0 )
{
+ LOG("SIGPIPE, server has terminated");
Threads_PostSignal(SIGPIPE);
errno = EIO;
return -1;
}
// Write to either FIFO or directly to output function
+ LOG("pty->OutputFcn = %p", pty->OutputFcn);
if( pty->OutputFcn ) {
pty->OutputFcn(pty->OutputHandle, Length, Buffer);
return Length;
* drv/vterm_input.c
* - Virtual Terminal - Input code
*/
+#define DEBUG 0
#include "vterm.h"
#include <api_drv_video.h>
-#define DEBUG 0
// === CODE ===
/**
if( Term != gpVT_CurTerm ) return ;
- ENTER("pTerm bShow", Term, Show);
+ ENTER("pTerm bShow", Term, bShow);
if( !bShow )
{
*/
void VT_int_UpdateScreen( tVTerm *Term, int UpdateAll )
{
- // Only update if this is the current terminal
- if( Term != gpVT_CurTerm ) return;
-
ENTER("pTerm iUpdateAll", Term, UpdateAll);
+ // Only update if this is the current terminal
+ if( Term != gpVT_CurTerm ) {
+ LOG("Term != gpVT_CurTerm (%p)", gpVT_CurTerm);
+ LEAVE('-');
+ return;
+ }
switch( Term->Mode )
{
size_t view_pos = (Term->Flags & VT_FLAG_ALTBUF) ? 0 : Term->ViewTopRow*Term->TextWidth;
const tVT_Pos *wrpos = VT_int_GetWritePosPtr(Term);
const tVT_Char *buffer = (Term->Flags & VT_FLAG_ALTBUF) ? Term->AltBuf : Term->Text;
- LOG("view_pos = %i, wrpos = %p, buffer=%p", view_pos, wrpos, buffer);
+ LOG("view_pos = %i, wrpos = %p (R%i,C%i), buffer=%p", view_pos, wrpos, wrpos->Row, wrpos->Col, buffer);
// Re copy the entire screen?
if(UpdateAll) {
VFS_WriteAt(
// Only copy the current line
else {
size_t ofs = wrpos->Row * Term->TextWidth;
+ LOG("ofs = %i", ofs);
VFS_WriteAt(
giVT_OutputDevHandle,
(ofs - view_pos)*sizeof(tVT_Char),
{
ASSERTC(wrpos->Col, <=, Term->TextWidth);
VT_int_UpdateScreen( Term, 0 );
- //wrpos->Row ++;
+ wrpos->Row ++;
wrpos->Col = 0;
}
case '\0': // Ignore NULL byte
return;
case '\n':
- LOG("Newline, update");
+ LOG("Newline, update @ %i", write_pos);
VT_int_UpdateScreen( Term, 0 ); // Update the line before newlining
wrpos->Row ++;
// TODO: Force scroll?
buffer[ write_pos ].Colour = Term->CurColour;
// Update the line before wrapping
if( (write_pos + 1) % Term->TextWidth == 0 ) {
- LOG("Line wrap, update");
+ LOG("Line wrap, update @ %i", write_pos);
VT_int_UpdateScreen( Term, 0 );
+ // NOTE: Code at the top of PutChar handles the actual wrapping
}
- write_pos ++;
wrpos->Col ++;
+ write_pos ++;
break;
}