4 ms·
Heisenbugs are the worst. Just last week I was on the verge of literally ripping my hair out trying to figure out a frustrating bug that never occurred when ru
by logbiscuitswave 4y ago
Heisenbugs are the worst.
Just last week I was on the verge of literally ripping my hair out trying to figure out a frustrating bug that never occurred when running in the debugger. After a lot of frustration I had an idea: rather than starting the application in the debugger, I’d attach later. When doing this, I began to see a huge amount of interesting first-chance exceptions (this was managed C# code) that clued me into the root cause of the issue and I was finally able to solve the problem.
I came to learn that an underlying library I was using had some code that ran on startup that actually detected if a debugger was attached and would turn off the problematic code path in this case! I came to learn that this was an intentional optimization the initialization of this code caused a bunch of noise during regular debugging (lots of first-chance exceptions that were ignorable). Unfortunately, this also meant that the interesting failure case I was running into was now completely hidden.
- bentcorner 4y agoProduction code that checks if a debugger is attached should be illegal. Ideally there would be a way to get the debugger to lie to the process that a debugger is indeed not attached. Sure, maybe there's a reason today why you actually need to know a debugger isn't attached but at least give future-developers an escape hatch if they need it.
- 10000truths 4y agoOn Linux, you can "lie" to the process by running it with the LD_PRELOAD environment variable set to a library that hijacks ptrace(PTRACE_TRACEME, ...) to return 0. If the process is smart enough to check for LD_PRELOAD as well, you might be able to use something like seccomp to hijack the return value at the OS level.
- virchau13 4y agoYou don't need LD_PRELOAD; the ptrace mechanism by itself can intercept system calls and modify them on the fly.
- mecha_ghidorah 4y agoIt's mostly an attempt at stopping someone attaching a debugger to an application you've shipped
- yarg 4y agoYep, and good luck using a debugger against race conditions (or any other time sensitive bugs).
- vnorilo 4y agoThe worst is when adding log lines changes timings and hides the race!
- sensanaty 4y agoSounds like an easy bugix in that case, just leave the log in!
- SAI_Peregrinus 4y agoThat can be where a debugger comes in handy! Instead of breakpoints it's (sometimes) faster to have the debugger log & continue. This doesn't always work, but often does with microcontrollers that have some dedicated debug/trace hardware.
- deleted 4y ago[deleted]