A debugging journey - debugging a weird bug in macOS
jimhester.com
jimhester.com
I just introduced my five year old son to the passwd utility, when he asked me if I could change the password on his laptop[1]. The look of pride on his face when he mastered it (blind password entry was a challenge) was priceless.
[1] ThinkPad X121e w/ SSD and Xubuntu. X series ThinkPads running Linux make great kids machines. Cheap, decent keyboards, and hard to break.
Back on thread: As an outsider, it seems to me that tracking down obscure bugs is a similar challenge to sorting out edge cases in obscure mathematics.
https://www.instagram.com/p/BXPY61pFkRK/
I keep my setup scripts in GitLab, so I can spin up a new dev machine pretty quickly:
https://opensource.apple.com/release/macos-10126.html
Which corresponds to 10.12.6 release.
Could there be a bug in a library/3rd party code? Could there be a possible race condition?
I remember recently hitting a bug in a 3rd party library in a Jar provided by Oracle in WebLogic to do with an incorrect implementation of the W3C DOM API causing XML validation to fail whenever attributes were present. Of course the J-Unit tests provide a different Jar and thus a different (correct) implementation and no bug. Took ages to track down.
You should add a ace md <textarea> below each question where I can fill in the answers and save a pdf to share with my peers.
I remember debugging this issue -- it took me a few hours to find out why our test were using old data, until I found someone else reporting the issue [1], and implemented a workaround.
Just saying {x} sucks... well sucks.
Probably fans of higher level languages might prefer exceptions, but this would be inapplicable to C.
Some frameworks (glib, parts of cocoa) have a concept of "error object" which is an extra pointer to a struct parameter that can receive rich error context.
Being sometimes a macro, sometimes not, not threadsafe? And more.
Otherwise it's a horrible piece of crap:
- It's a global (sorry, thread-local) variable, updated behind the scenes.
- You can't tell whether a function will update errno or not by its signature. You have to consult the documentation.
- You can't tell the range of possible errno values unless it's explicitly documented (and the documentation is kept in sync with the implementation).
- Errno only communicates error metadata; the success/error bit has to be communicated in-band via the return value (e.g. printf returning < 0).
- Except for some functions which return void (or like readdir, which returns NULL when reaching the end of the directory, or on error) and set errno on error.
- In which case you better set errno to 0 before calling the function, because while these functions set errno on failure, they not necessarily set it to 0 on success...