Started implementing debugging facilities

This commit is contained in:
2022-12-14 21:45:24 +00:00
parent 51e065faaf
commit 72bf6faadd
11 changed files with 124 additions and 11 deletions

View File

@@ -0,0 +1,62 @@
#!/usr/bin/env python3
import sys
import os
import subprocess
import time
import signal
qemu_args = []
gdb_args = []
cur_program = ''
def run_process(args):
p = subprocess.Popen(args,
bufsize=1,
shell=True,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE)
while True:
retcode = p.poll()
line = p.stdout.read(1)
yield line
if retcode is not None:
break
for arg in sys.argv[1:]:
if arg == '--qemu':
cur_program = 'qemu'
continue
elif arg == '--gdb':
cur_program = 'gdb'
continue
if cur_program == 'qemu':
qemu_args += [arg]
elif cur_program == 'gdb':
gdb_args += [arg]
else:
print('No program specified')
exit(-1)
env = os.environ.copy()
signal.signal(signal.SIGINT, signal.SIG_IGN)
qemu = subprocess.Popen(qemu_args,
env=env,
start_new_session=True,
restore_signals=False)
time.sleep(1)
if qemu.poll() is not None:
print('Failed to start QEMU')
exit(-1)
subprocess.run(gdb_args,
env=env,
stdout=sys.stdout,
stdin=sys.stdin,
stderr=sys.stderr)
qemu.kill()

View File

@@ -0,0 +1,26 @@
#!/bin/bash
gdb_cfg=$1
lldb_cfg=$2
shift 2
if command -v gdb &> /dev/null; then
tmux \
new-session -d -s hz-debug "sleep 0.3; gdb -tui -x $gdb_cfg" \; \
split-window -h -l 80 \; \
split-window -v -l 25 "$@"\; \
select-pane -t 0
elif command -v lldb &> /dev/null; then
tmux \
new-session -d -s hz-debug "sleep 0.1; lldb --source $lldb_cfg" \; \
split-window -h -l 80 \; \
split-window -v -l 25 "$@"\; \
select-pane -t 0
else
echo "No debugger available"
exit -1
fi
tmux a -t hz-debug
tmux kill-session -t hz-debug

View File

@@ -0,0 +1,4 @@
set confirm off
symbol-file build/socks_kernel
target remote localhost:1234
set confirm on

View File

@@ -0,0 +1,2 @@
file build/socks_kernel
gdb-remote localhost:1234

View File

@@ -2,7 +2,7 @@ LD := $(ARCH)-elf-gcc
CC := $(ARCH)-elf-gcc
ASM := $(ARCH)-elf-gcc
CFLAGS := -nostdlib -nostdinc -ffreestanding -Wl,-nostdlib
CFLAGS := -ffreestanding -nostdlib
ASMFLAGS := $(CFLAGS)
LDFLAGS := -nostdlib