News for hackers. Stuff that matters.
Re:Things you can do with a debugger but not with print debu... by swaits on Tuesday September 09, 2025 @10:25PM (#45192386)
Author missed one of the best features: easy access to hardware breakpoints. Breaking on a memory read or write, either a raw address or via a symbol, is one of the most time saving debugging tools I know.
Re:Things you can do with a debugger but not with print debu... by coderatlarge on Tuesday September 09, 2025 @10:41PM (#45192521)
windbg used to offer scripting capabilities that teams could use to trigger validation of any number of internal data structures essentially at every breakpoint or watchpoint trigger. it was a tremendous way to detect subtle state corruption. and sharing scripts across teams was also a way to share knowledge of a complex binary that was often not encoded in asserts or other aspects of the codebase.
Re:Things you can do with a debugger but not with print debu... by bpye on Tuesday September 09, 2025 @10:55PM (#45192615)
This still exists? You can also use JavaScript to script/extend and there is a native code API too.

Note: I do work at MSFT, I have used these capabilities but I’m not on the debugger team.

https://learn.microsoft.com/en-us/windows-hardware/drivers/d...

https://www.timdbg.com/posts/whats-the-target-model/

https://github.com/microsoft/WinDbg-Samples/tree/master

Re:Things you can do with a debugger but not with print debu... by coderatlarge on Wednesday September 10, 2025 @01:08AM (#45193538)
thanks for the pointers glad to hear it’s all still there

i haven’t seen this type of capability used in too many companies tbh and it seems like a lot of opportunity to improve stability and debugging speed and even code exploration/learning (did i break something ?)

Re:Things you can do with a debugger but not with print debu... by delta_p_delta_x on Wednesday September 10, 2025 @03:50PM (#45202705)
WinDbg also has time-travel/record-replay debugging.
Re:Things you can do with a debugger but not with print debu... by coderatlarge on Thursday September 11, 2025 @02:59AM (#45208646)
that sounds like a super-powerful feature especially for multithreaded debugging though i’ve never used anything like it.
Re:Things you can do with a debugger but not with print debu... by yakshaving_jgt on Tuesday September 09, 2025 @10:32PM (#45192438)
Is there somewhere where this approach is described in more detail?
Re:Things you can do with a debugger but not with print debu... by lock1 on Wednesday September 10, 2025 @12:04AM (#45193109)
Search for "watchpoint debugging". Usually in most garbage-collected environments, it just observes & breaks on symbols though, not raw addresses.

Vscode (or an editor with ADP support) supports unconditional breakpoints, watchpoints, and logpoints (observe & log values to the debug console).

Re:Things you can do with a debugger but not with print debu... by SAI_Peregrinus on Wednesday September 10, 2025 @11:39AM (#45199303)
What watchpoints observe depends on the device & environment. E.g. for ARM Cortex-M MCUs, the (optional but very common) Data Watchpoint and Trace Unit (DWT) provides 1 or 4 watchpoints by using hardware comparators. They operate on raw addresses, since they work at the machine code level. They issue a debug interrupt when the comparator matches the address & operation (read/write), which the debug probe (J-Link, ST-Link, or other such probe) detects & forwards to the debugger (GDB, LLDB, etc.). Hardware watchpoints are extremely useful for debugging memory corruption in embedded systems, since they bypass the code running on the device under test entirely.
Re:Things you can do with a debugger but not with print debu... by jesse__ on Wednesday September 10, 2025 @01:39AM (#45193740)
Very roughly, hardware watchpoints are memory addresses you ask the processor to issue an "event" for when they're read from, written to, or executed. This event is processed by the kernel, and passed through to the debugger, which breaks execution of the program on the instruction that issued the read/write/exec.

A concrete use case for this is catching memory corruption. If your program corrupts a known piece of memory, just set a hardware watchpoint on that memory address and BOOM, the debugger breaks execution on exactly the line that's responsible for the corruption. It's a fucking godsend sometimes.

Re:Things you can do with a debugger but not with print debu... by jesse__ on Wednesday September 10, 2025 @01:25AM (#45193661)
Oh my god, same. This literally catches bugs with a smoking gun in their hand in a way that's completely impossible with printf. I'd upvote this 100 times if I could.
Re:Things you can do with a debugger but not with print debu... by sherincall on Wednesday September 10, 2025 @03:14AM (#45194303)
> completely impossible with printf

Not printf exactly, but I've found bugs with a combination of mprotect, userfaultfd and backtrace_symbols when I couldn't use HW breakpoints.

Basically, mark a set of pages as non-writable so that any writes trigger a pagefault, then register yourself as a pagefault handler for those and see who is doing the write, apply the write and move on. You can do this with LD_PRELOAD without even recompiling the debugee.

Re:Things you can do with a debugger but not with print debu... by jesse__ on Wednesday September 10, 2025 @11:17AM (#45199014)
Oh yeah, I've done that trick before, it's quite handy. Sometimes catches bugs that would be tricky to find with watchpoints. I wrote an allocator that allocates an extra page either before or after the users allocation, and aligns the user allocation such that it is as close as possible (while respecting user-requested alignment) to butting up against that extra page (marked PROT_NONE). Can catch underflows or overflows with this method, but not both simultaneously. Very handy from time to time.
Re:Things you can do with a debugger but not with print debu... by antonchekhov on Wednesday September 10, 2025 @04:03PM (#45202849)
Back in the early '90s, I was a big fan of the C/C++ debugging library "electric fence" (written by Bruce Perens) - it was a malloc() implementation that used mmap() to set the pages of the returned buffer such that any writes in that region (and even read accesses!) caused a segfault to happen, and the program halts, so you can examine the stack. It was a godsend.
Re:Things you can do with a debugger but not with print debu... by praptak on Wednesday September 10, 2025 @02:28AM (#45194024)
From the same toolbox: expression watch. Set a watch on the invariant being violated (say "bufpos < buflen") and get a breakpoint the moment it changes.
Re:Things you can do with a debugger but not with print debu... by roca on Wednesday September 10, 2025 @04:32AM (#45194866)
Especially with combined with reverse-execution in rr or UndoDB!
Re:Things you can do with a debugger but not with print debu... by AndyKelley on Wednesday September 10, 2025 @07:02PM (#45205294)
Combined with time travel it's mind-blowing.

Stumble upon some corrupted memory? Just put a watch point on it, and run the program backwards. Two weeks just turned into two minutes.

Re:Things you can do with a debugger but not with print debu... by mwcz on Wednesday September 10, 2025 @07:14PM (#45205436)
What time traveling debugger(s) do you recommend? I'm a regular GDB user and keep meaning to try rr.
Re:Things you can do with a debugger but not with print debu... by AndyKelley on Wednesday September 10, 2025 @10:17PM (#45206945)
Since you're already a GDB user, rr will probably feel comfortably familiar.

https://rr-project.org/ already has enough example usage to get you going on the home page right there.

Re:Things you can do with a debugger but not with print debu... by adgjlsfhk1 on Thursday September 11, 2025 @12:24AM (#45207761)
rr is excellent. the only problem is it doesn't work for Windows
Re:Things you can do with a debugger but not with print debu... by delta_p_delta_x on Thursday September 11, 2025 @07:06AM (#45210140)
It's a little odd to use GDB on Windows. Have you considered either the Visual Studio debugger, or WinDbg?

WinDbg has time travel debugging, and is arguably 'more excellent': https://learn.microsoft.com/en-gb/windows-hardware/drivers/d...