Debug recap

Most of the time, I debug programs with my head and print out the stuff I am interested in. Today I found it hard to make progress if the call stack was too deep that my head couldn’t follow up the entire procedure. I doubt that I rely on my head too much, and my head is not that smart and large enough to remember all the things. I should rely on paper and pen or the debugger.

Then I turn to Intellij Idea’s debugger for help.

It’s a multiple-thread program. Though I set the breakpoint in the thread where I cared, it didn’t stop there. It takes me some time to make the non-main thread suspend. I don’t know why but it seems it’s by design after some googling. It deserves to be documented here.

Takeaways

  1. step into: enter the function at current breakpoint.
  2. smart step into. It’s set by default. If current line contains multiple functions, you can choose the one that matters.
  3. force step into, force into the method that cannot be step into.
  4. step over: execute to next line.
  5. step out: exit current function execution. If there’re other breakpoints following, it will stop at the point. It’s a quick way to jump to other breakpoints.
  6. show execution point: move cursor back to current execution point.
  7. right click the breakpoint to set suspend policy. Two options: all or thread. I suggest setting the option to thread if you are debugging multiple thread program. Otherwise, if there are suspend all breakpoints in main thread, the debugger will always focus on the main thread and ignore the breakpoints at other threads when you step by step execution.
  8. Frame window shows current execution frame. When main thread suspends, you can switch to another thread’s frame and do step by step debugging.
  9. Thread window displays all threads’ frames and status.