GMS Linux: start?

This commit is contained in:
2025-12-30 01:20:20 +00:00
commit ac241a9148
48 changed files with 2028 additions and 0 deletions
+15
View File
@@ -0,0 +1,15 @@
TARGET = debug
SRCS = debug.c
CC = gcc
CFLAGS = -static -Wall
OUT_BIN ?= $(TARGET)
all: $(OUT_BIN)
$(OUT_BIN): $(SRCS)
@echo " [CC] Compiling to $(OUT_BIN)..."
$(CC) $(CFLAGS) -o $@ $^
clean:
rm -f $(TARGET)
+59
View File
@@ -0,0 +1,59 @@
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/wait.h>
#include <sys/time.h>
int main(int argc, char *argv[]) {
if (argc < 2) {
printf("Usage: debug <command> [args...]\n");
return 1;
}
struct timeval start, end;
gettimeofday(&start, NULL);
pid_t pid = fork();
if (pid < 0) {
perror("debug: fork failed");
return 1;
}
if (pid == 0) {
execvp(argv[1], &argv[1]);
perror("debug: exec failed");
exit(127);
}
else {
int status;
waitpid(pid, &status, 0);
gettimeofday(&end, NULL);
long seconds = end.tv_sec - start.tv_sec;
long micros = end.tv_usec - start.tv_usec;
if (micros < 0) {
seconds -= 1;
micros += 1000000;
}
double elapsed = seconds + micros / 1000000.0;
printf("\n\033[1;33m[Debug Report]\033[0m\n");
printf("Target : %s\n", argv[1]);
printf("PID : %d\n", pid);
printf("Time Elapsed : %.6f sec\n", elapsed);
if (WIFEXITED(status)) {
printf("Exit Code : %d\n", WEXITSTATUS(status));
} else if (WIFSIGNALED(status)) {
printf("Terminated by Signal : %d\n", WTERMSIG(status));
}
printf("------------------------------\n");
}
return 0;
}