3 ms·
Allison asks: “What linker debugging strategies do you have?” Change the linker script randomly (actual thing that has worked) Change variable attributes from
by greenyoda 13y ago
Allison asks: “What linker debugging strategies do you have?”
Change the linker script randomly (actual thing that has worked)
Change variable attributes from ‘private’ to ‘public’ at random (actual other thing that has worked)...
Changing stuff at random (without having any idea why you're doing it and without keeping track of what you've already done) isn't a very productive debugging strategy - it's more like an act of desperation. At least use the scientific method:
- Make a hypothesis about what might happen if you change X.
- Observe and record what actually happens.
- Think about why this could be, and then think about what experiment you could do next to get another step closer to the answer.
If you have a hard time coming up with a reasonable hypothesis, it might help to learn more about the system. In this case, reading the linker documentation to find out what the various options do could be more productive than just making random changes to the linker script.
- pja 13y agoIn this case, reading the linker documentation to find out what the various options do could be more productive than just making random changes to the linker script. If you haven't been faced with a mystifying bug where randomly futzing with things in the hope that you would find a change that had a reliable effect was the best hope you had of solving it then you probably haven't been programming long enough.
- greenyoda 13y agoHaven't been programming long enough? If you're the average age on HN, I may have been programming before you were born. :) And I've dealt with lots of mystifying bugs. But my approach to debugging isn't trying random things, it's gathering more information in deliberate ways: reading the code, tracing code with the debugger, adding logging information if the problem doesn't reproduce under the debugger, running test cases that attempt to narrow down the scope of the bug, etc. I've even debugged customer problems that I couldn't reproduce locally by looking at the code and deducing what execution path had to have occurred to account for the reported behavior. That's one situation in which you absolutely can't try random things to see if they work. If I were truly making random changes, it would suggest to me that I had no understanding of how the system worked. If you do understand the system and its potential failure modes, then you can do better than random.
- pja 13y agoIn this particular case the kernel binary loader was dropping half the binary on the floor, so code would sometimes work and sometimes not in a way which depended on both the environment and the layout of the compiled binary. I'm not surprised the author ended up randomly futzing with things to see if they could find a reliable cause! (This error could have come straight out of the logout; essay that was linked on HN a week or two ago: "I have no tools because I broke my tools with my tools!") Personally I think the reason she was emphasising that changing these things made a difference was because it was so surprising. Now in your infinite and sagacious wisdom you've told us all how she should obviously have been able to debug this problem in a trice using your superior methods. Me, I'm happy to cut her some slack, and recognise that systems development can be a complete nightmare!
- lgeek 13y agoYep, two other more 'deterministic' strategies should have caught this: interactive debugging should have showed that the memory is set to zero immediately after loading, not while running; and inspecting the symbol table could have revealed that only data after a fixed offset is corrupt.
- pja 13y agoIt's much easier to realise the perfect debugging strategy with the benefit of hindsight!
- shabble 13y agoIf only that was how Time-travelling Debuggers[1][2] worked! [1] http://chrononsystems.com/products/chronon-time-travelling-debugger http://chrononsystems.com/products/chronon-time-travelling-d... [2] https://www.gnu.org/software/gdb/news/reversible.html https://www.gnu.org/software/gdb/news/reversible.html
- pja 13y agoTime travelling debuggers are awesome, but they still can't compete with already knowing the cause of the bug when trying to find the shortest path from bug to cause!
- greenyoda 13y agoNo, you don't need hindsight to figure this out. It should be easy to figure out in advance which of these strategies is likely to be more effective in solving a problem: (1) Go into the debugger and trace how the system got to the bad state it was in. (2) Randomly change stuff and see if it fixes the problem. After doing (1), you understand exactly what your code is doing and why. After doing (2), you may not even understand what the problem really was, or why it got fixed, or whether it's really fixed or just doesn't happen any more in this particular situation. I've seen people debug using strategy (2), and when they give up and ask for help, stopping, thinking a while and employing strategy (1) will usually find the problem.
- tlarkworthy 13y agoIf you don't have a causal model yet, random peterbation can get you moving in the right direction (genetic algorithms). Hopefully through observations of enough effects you will start to see enough patterns to construct a causal model.