add more asserts

This commit is contained in:
nakst 2022-01-04 13:17:50 +00:00
parent ce5f3ac647
commit aa56fc6144
4 changed files with 35 additions and 2 deletions

View File

@ -268,7 +268,8 @@ uintptr_t APISyscallCheckForCrash(uintptr_t argument0, uintptr_t argument1, uint
uintptr_t returnValue = _APISyscall(argument0, argument1, argument2, unused, argument3, argument4);
EsProcessState state;
_APISyscall(ES_SYSCALL_PROCESS_GET_STATE, ES_CURRENT_PROCESS, (uintptr_t) &state, 0, 0, 0);
while (state.flags & ES_PROCESS_STATE_PAUSED_FROM_CRASH);
volatile int x = 1;
if (state.flags & ES_PROCESS_STATE_PAUSED_FROM_CRASH) while (x);
return returnValue;
}
#endif
@ -1604,6 +1605,10 @@ void EsPanic(const char *cFormat, ...) {
size_t bytes = EsStringFormatV(buffer, sizeof(buffer), cFormat, arguments);
va_end(arguments);
EsPrintDirect(buffer, bytes);
#ifdef PAUSE_ON_USERLAND_CRASH
volatile int x = 1;
while (x);
#endif
EsSyscall(ES_SYSCALL_PROCESS_CRASH, 0, 0, 0, 0);
}

View File

@ -263,6 +263,9 @@ void TextboxSetActiveLine(EsTextbox *textbox, int lineIndex) {
return;
}
EsAssert(lineIndex >= -1 && lineIndex < (int) textbox->lines.Length());
EsPrint("TextboxSetActiveLine %i\n", lineIndex);
if (lineIndex == -1) {
int32_t lineBytesDelta = textbox->activeLineBytes - textbox->activeLineOldBytes;
@ -277,6 +280,7 @@ void TextboxSetActiveLine(EsTextbox *textbox, int lineIndex) {
lineBytesDelta,
false);
textbox->dataBytes += lineBytesDelta;
EsAssert(textbox->dataBytes >= 0);
// Step 3: Copy the active line back into the data buffer.
@ -828,10 +832,24 @@ void TextboxUndoItemCallback(const void *item, EsUndoManager *manager, EsMessage
void EsTextboxInsert(EsTextbox *textbox, const char *string, ptrdiff_t stringBytes, bool sendUpdatedMessage) {
EsMessageMutexCheck();
EsPrint("EsTextboxInsert \"%s\" at %d:%d->%d:%d.\n",
stringBytes, string, textbox->carets[0].line, textbox->carets[0].byte, textbox->carets[1].line, textbox->carets[1].byte);
#if 0
for (uintptr_t i = 0; i < textbox->lines.Length(); i++) {
EsPrint("line %d %d '%s'\n", i, textbox->lines[i].lengthBytes, textbox->lines[i].lengthBytes, GET_BUFFER(&textbox->lines[i]));
}
#endif
if (string >= textbox->activeLine && string < textbox->activeLine + textbox->activeLineAllocated) {
EsAssert(false);
}
EsAssert(textbox->carets[0].line >= 0 && textbox->carets[0].line < (int32_t) textbox->lines.Length()
&& textbox->carets[0].byte >= 0 && textbox->carets[0].byte <= textbox->lines[textbox->carets[0].line].lengthBytes);
EsAssert(textbox->carets[1].line >= 0 && textbox->carets[1].line < (int32_t) textbox->lines.Length()
&& textbox->carets[1].byte >= 0 && textbox->carets[1].byte <= textbox->lines[textbox->carets[1].line].lengthBytes);
// EsPerformanceTimerPush();
// double measureLineTime = 0;
@ -901,6 +919,7 @@ void EsTextboxInsert(EsTextbox *textbox, const char *string, ptrdiff_t stringByt
EsMemoryMove(textbox->activeLine + deleteTo.byte, textbox->activeLine + line->lengthBytes, deltaBytes, false);
textbox->activeLineBytes += deltaBytes;
line->lengthBytes += deltaBytes;
EsAssert(line->lengthBytes >= 0);
// Step 6: Update the longest line.
@ -928,12 +947,14 @@ void EsTextboxInsert(EsTextbox *textbox, const char *string, ptrdiff_t stringByt
EsMemoryMove(textbox->data + deleteTo.byte + textbox->lines[deleteTo.line].offset, textbox->data + textbox->dataBytes, deltaBytes, false);
textbox->dataBytes += deltaBytes;
EsAssert(textbox->dataBytes >= 0);
// Step 6: Merged the joined lines.
DocumentLine *firstLine = &textbox->lines[deleteFrom.line];
firstLine->lengthBytes = textbox->lines[deleteTo.line].lengthBytes - deleteTo.byte + deleteFrom.byte;
firstLine->lengthWidth = TextGetStringWidth(textbox, &textbox->textStyle, textbox->data + firstLine->offset, firstLine->lengthBytes);
EsAssert(firstLine->lengthBytes >= 0);
// Step 7: Remove the deleted lines and update the textbox.
@ -1011,6 +1032,7 @@ void EsTextboxInsert(EsTextbox *textbox, const char *string, ptrdiff_t stringByt
EsAssert(added == bytesToInsert); // Added incorrect number of bytes in EsTextboxInsert.
line->lengthBytes += bytesToInsert;
EsAssert(line->lengthBytes >= 0);
// Step 3: Update the carets, line width, and repaint it.
@ -1032,11 +1054,13 @@ void EsTextboxInsert(EsTextbox *textbox, const char *string, ptrdiff_t stringByt
TextboxBufferResize((void **) &textbox->data, &textbox->dataAllocated, textbox->dataBytes + bytesToInsert, 1);
EsMemoryMove(textbox->data + byteOffset, textbox->data + textbox->dataBytes, bytesToInsert, false);
textbox->dataBytes += bytesToInsert;
EsAssert(textbox->dataBytes >= 0);
// Step 3: Truncate the insertion line.
int32_t truncation = line->lengthBytes - insertionPoint.byte;
line->lengthBytes = insertionPoint.byte;
EsAssert(line->lengthBytes >= 0);
// Step 4: Add the new lines.
@ -1070,6 +1094,8 @@ void EsTextboxInsert(EsTextbox *textbox, const char *string, ptrdiff_t stringByt
line->lengthBytes += truncation;
}
EsAssert(line->lengthBytes >= 0);
// Step 4c: Update the line's width.
// EsPerformanceTimerPush();

View File

@ -1287,7 +1287,7 @@ void EsMemoryMove(void *_start, void *_end, intptr_t amount, bool zeroEmptySpace
uint8_t *end = (uint8_t *) _end;
if (end < start) {
EsPrint("MemoryMove end < start: %x %x %x %d\n", start, end, amount, zeroEmptySpace);
EsPanic("MemoryMove end < start: %x %x %x %d\n", start, end, amount, zeroEmptySpace);
return;
}

View File

@ -1300,6 +1300,8 @@ void DoCommand(const char *l) {
BuildAndRun(OPTIMISE_FULL, true /* compile */, DEBUG_NONE /* debug */, EMULATOR_QEMU, LOG_NORMAL);
} else if (0 == strcmp(l, "kno")) {
BuildAndRun(OPTIMISE_ON, true /* compile */, DEBUG_NONE /* debug */, EMULATOR_QEMU, LOG_NORMAL);
} else if (0 == strcmp(l, "kd")) {
BuildAndRun(OPTIMISE_OFF, true /* compile */, DEBUG_NONE /* debug */, EMULATOR_QEMU, LOG_NORMAL);
} else if (0 == strcmp(l, "klv")) {
BuildAndRun(OPTIMISE_FULL, true /* compile */, DEBUG_NONE /* debug */, EMULATOR_QEMU, LOG_VERBOSE);
} else if (0 == strcmp(l, "tlv")) {