Building a DNS Server from Scratch in Zig! After completing Ziglings, I'm taking on the #codecrafters DNS challenge to push deeper into systems programming. Live and unfiltered.
Changing the approach today, instead of relying on Codecrafters and print-based debugging, I'm going to swallow the pill and use a debugger to understand what's going on with the server.
I'm sure it'll be fun, so CHALLENGE ACCEPTED 💪🏼🤓.
Related Playlists:
• Build to Learn: DNS Server in Zig
• Ziglings: Livecoding
Notes:
✅ Session 1: https://sourcery.zone/articles/2025/0...
✅ Session 2: https://sourcery.zone/articles/2025/0...
✅ Session 3: https://sourcery.zone/articles/2025/0...
✅ Session 4: https://sourcery.zone/articles/2025/0...
✅ Session 5: https://sourcery.zone/articles/2025/0...
✅ Session 6, 7, and 8: https://sourcery.zone/articles/2025/0...
✅ Session 9, and 10: https://sourcery.zone/articles/2025/0...
⭐ Sessions 11 to 17: https://sourcery.zone/articles/2025/1...
Reach out and Chat
Matrix: https://matrix.to/#/#sourcery-zone:matrix.org
Timestamps
00:00:00 Stream Warm Up
00:01:12 recap; refactoring DNS question parsing logic
00:02:07 identifies offset over-movement bug causing failures
00:02:38 reflection on relying too much on print debugging
00:03:18 switches to LLDB for proper debugging setup
00:04:00 configures LLVM build and `.lldbinit` helper for RR reload
00:04:48 sets up debugger workflow for Zig build-run cycle
00:05:42 first LLDB session; hits index-out-of-range in main
00:06:57 inspects offset and buffer sizes at runtime
00:08:09 suspects miscalculated response buffer length
00:09:05 adds `question_len` accumulation to fix offset math
00:09:35 reruns program; offset still overflows buffer
00:10:05 inspects question structure inside LLDB
00:11:30 sees insufficient buffer for question section
00:12:04 isolates faulty logic; incremental rebuild
00:13:40 verifies breakpoints and LLDB commands
00:14:47 realizes LLDB alters runtime behavior vs direct run
00:15:37 compares `question_len` and `answer_len` calculations
00:16:50 validates combined buffer sizes; mismatch found
00:17:59 experiments with LLDB command syntax and Zig expressions
00:20:24 tests printing question items via LLDB expressions
00:23:12 explores breakpoint list management in LLDB
00:25:18 calculates question section size by name + type/class fields
00:26:10 detects bug in domain name reconstruction
00:27:27 sets new breakpoint inside `parseLabel` loop
00:28:01 finds second label parsed incorrectly ("def" only)
00:29:27 suspects loop-entry condition causing skipped iterations
00:31:04 observes label size mismatch vs buffer slice length
00:33:11 confirms wrong data copied into label slice
00:35:49 corrects scope and variable reference of `label`
00:36:53 loop repeats excessively; likely wrong offset increment
00:38:48 verifies offset growth exceeds expected label total
00:40:06 prints expected label lengths sequence (3-11-3)
00:41:06 breakpoints confirm current offset starts correctly
00:43:11 checks per-iteration offset and label size consistency
00:45:33 offset arithmetic verified; progression mostly correct
00:47:22 notices parser exits early without jump trigger
00:49:53 confirms compression branch never triggered
00:50:17 quick explanation of Zig’s background to viewer question
00:52:22 prints sequence of label sizes: 11, 3, 0 → identifies null terminator
00:54:58 finds jump flag not applied when compression expected
00:56:39 pinpoints faulty conditional blocking compression path
00:58:11 verifies label sizes printed but jump logic skipped
01:00:47 confirms condition never reached; pointer compression not firing
01:02:13 zero byte correctly detected; label loop ends too early
01:03:03 breakpoints through pointer detection condition
01:05:24 validates expected byte count vs observed offset increment
01:09:53 concludes compression parsing broke after offset fix; plans rewrite
#zig #lowlevelprogramming #systemprogramming #coding #codinglive