Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

devcontainer: install gdb and enable .gdbinit #69

Merged
merged 3 commits into from
Dec 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
FROM mcr.microsoft.com/devcontainers/rust:1-1-bookworm

RUN apt-get update && apt-get install -y cmake
RUN apt-get update && apt-get install -y cmake vim gdb

ARG LLVM_URL=https://github.com/llvm/llvm-project/releases/download/llvmorg-15.0.0/clang+llvm-15.0.0-x86_64-linux-gnu-rhel-8.4.tar.xz
ARG ZIG_VERSION=zig-linux-x86_64-0.14.0-dev.2540+f857bf72e
Expand Down Expand Up @@ -34,3 +34,10 @@ RUN apt-get update && \
RUN curl -SL https://ziglang.org/builds/${ZIG_VERSION}.tar.xz \
| tar -xJC /tmp \
&& mv /tmp/${ZIG_VERSION} /usr/bin/zig

RUN mkdir -p /home/vscode/.config/gdb \
&& echo "add-auto-load-safe-path /workspaces/mewz/.gdbinit" > /home/vscode/.config/gdb/gdbinit

USER vscode

WORKDIR /workspaces/mewz
25 changes: 23 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,13 +67,34 @@ To use file systems, specify the directory by `-Ddir=<path to dir>`. See [exampl
> [!NOTE]
> QEMU's port 1234 is mapped to localhost:1234.

## Run integration tests

## Development

### GDB

You can debug Mewz with GDB. When you run Mewz with QEMU, it listens on port 12345 for GDB. You can connect to it by just running GDB at the root of the repository as `.gdbinit` is already configured.

```sh
zig build -Dapp-obj=<path to the object file generated by Wasker> run
# In another terminal
gdb
```

`zig build debug` command prevent Mewz from booting up until GDB connects to it. This is useful when you want to debug the boot process.

```sh
zig build -Dapp-obj=<path to the object file generated by Wasker> debug
# In another terminal
gdb
```

### Run integration tests

```sh
zig bulid -Dtest=true run
```

### Current Status
## Current Status


| Feature | Status |
Expand Down
2 changes: 1 addition & 1 deletion scripts/integration-test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ cd $REPO_ROOT
mkdir -p build/test
(stty -echo; sleep 4; (sleep 0.5; echo q) | telnet localhost 1234) &
(sleep 2; curl localhost:1234) &
./scripts/run-qemu.sh | tee build/test/output.txt
./scripts/run-qemu.sh "$@" | tee build/test/output.txt

if ! grep -q "Integration test passed" build/test/output.txt; then
echo "Integration Test FAILED!!"
Expand Down
11 changes: 7 additions & 4 deletions scripts/rewrite-kernel.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,17 @@ set -eux
REPO_ROOT=$(git rev-parse --show-toplevel)
cd $REPO_ROOT

file_path="zig-out/bin/mewz.elf"
src_path="zig-out/bin/mewz.elf"
dest_path="zig-out/bin/mewz.qemu.elf"
offset=18
new_data="\x03\x00"
data_size=2

head -c $offset "$file_path" > temp_head
tail -c +$((offset + 1 + data_size)) "$file_path" > temp_tail
cp "$src_path" "$dest_path"

cat temp_head <(echo -n -e "$new_data") temp_tail > "$file_path"
head -c $offset "$dest_path" > temp_head
tail -c +$((offset + 1 + data_size)) "$dest_path" > temp_tail

cat temp_head <(echo -n -e "$new_data") temp_tail > "$dest_path"

rm temp_head temp_tail
2 changes: 1 addition & 1 deletion scripts/run-qemu.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ cd $REPO_ROOT

QEMU_ARGS=(
"-kernel"
"zig-out/bin/mewz.elf"
"zig-out/bin/mewz.qemu.elf"
"-cpu"
"Icelake-Server"
"-m"
Expand Down
Loading