Commit: eba3307fd35d076d2eb1989431abbd17e8b11fcb
Parent: 6f9a8436cf0cc98b4c2c944cc4c2124b69507270
Author: Randy Palamar
Date: Thu, 24 Oct 2024 06:17:47 -0600
make debug line dump slightly more usable
we need some other info about the terminal to make sure we can
recreate the bug based on the line dump.
Diffstat:
3 files changed, 38 insertions(+), 17 deletions(-)
diff --git a/debug.c b/debug.c
@@ -56,26 +56,38 @@ fput_line_info(FILE *f, Term *t, Line *l)
}
static void
-dump_last_line_to_file(Term *t)
+dump_lines_to_file(Term *t)
{
- char *fname = "last_line.bin";
- FILE *f = fopen(fname, "w");
+ char buf[256];
+ u64 current_time = os_get_time();
+ snprintf(buf, sizeof(buf), "%zu-lines.bin", current_time);
+
+ FILE *f = fopen(buf, "w");
if (!f) return;
- printf("dumping line to %s\n", fname);
+ printf("dumping lines to %s\n", buf);
TermView *tv = t->views + t->view_idx;
- fputs("Line Idx -1:\n", f);
- Line *line = tv->lines.buf + get_line_idx(&tv->lines, -1);
- s8 l = line_to_s8(line, &tv->log);
- fput_line_info(f, t, line);
- fwrite(l.data, 1, l.len, f);
-
- fputs("\nLine Idx 0:\n", f);
- line = tv->lines.buf + get_line_idx(&tv->lines, 0);
- l = line_to_s8(line, &tv->log);
- fput_line_info(f, t, line);
- fwrite(l.data, 1, l.len, f);
+ size line_count = MIN(256, tv->lines.filled);
+
+ fputs("Term Info:\n", f);
+ fprintf(f, " Size: %ux%u\n", t->size.w, t->size.h);
+ fprintf(f, " Window Size: %ux%u\n", (u32)t->gl.window_size.w, (u32)t->gl.window_size.h);
+ fprintf(f, " Mode: 0x%X\n", t->mode);
+ fprintf(f, " Window Mode: 0x%X\n", t->gl.mode);
+ fprintf(f, " Scroll Region:\n");
+ fprintf(f, " Top: %u\n", t->top);
+ fprintf(f, " Bottom: %u\n", t->bot);
+ fprintf(f, " Offset: %d\n", t->scroll_offset);
+ fprintf(f, "Raw Line Count: %u\n", (u32)line_count);
+ fputs("==============================\n", f);
+
+ for (size i = -(line_count - 1); i <= 0; i++) {
+ Line *line = tv->lines.buf + get_line_idx(&tv->lines, i);
+ s8 l = line_to_s8(line, &tv->log);
+ fwrite(l.data, 1, l.len, f);
+ }
+ fputc('\n', f);
fclose(f);
}
diff --git a/os_unix.c b/os_unix.c
@@ -4,11 +4,11 @@
#include <pwd.h>
#include <stdarg.h>
#include <stdio.h>
-#include <stdlib.h>
#include <sys/mman.h>
#include <sys/select.h>
#include <sys/stat.h>
#include <sys/wait.h>
+#include <time.h>
#include <unistd.h>
typedef struct timespec os_filetime;
@@ -27,6 +27,15 @@ typedef struct {
#define OS_MAP_READ PROT_READ
#define OS_MAP_PRIVATE MAP_PRIVATE
+static u64
+os_get_time(void)
+{
+ struct timespec ts;
+ clock_gettime(CLOCK_REALTIME, &ts);
+ u64 result = ts.tv_sec;
+ return result;
+}
+
static void
os_write_err_msg(s8 msg)
{
diff --git a/vtgl.c b/vtgl.c
@@ -609,7 +609,7 @@ key_callback(GLFWwindow *win, i32 key, i32 sc, i32 act, i32 mods)
#ifdef _DEBUG
if (key == GLFW_KEY_F1 && act == GLFW_PRESS) {
- dump_last_line_to_file(t);
+ dump_lines_to_file(t);
return;
}
if (key == GLFW_KEY_F2 && act == GLFW_PRESS) {