Chapter 2: Understanding your app’s logic through debugging techniques
This introduction defines a debugger and explains its role in understanding complex code.
After this chapter you will be able to
- Debugger execution control. Explain how a debugger helps a developer understand code by controlling execution and observing data.
- Nonlinear code reading. Explain how reading code differs from reading a poem and what a code investigation aims to establish.
- Investigation depth and complexity. Explain why seemingly simple code can require deeper investigation and how choosing what to examine affects complexity.
- Debugger navigation and observation. Describe how a debugger helps manage code investigation.
- Choosing an investigation point. Explain how to choose where to begin debugging and why reading the code first saves time.
- Breakpoint setup and execution. Describe how to set a breakpoint, start the app with a debugger, and interpret where execution pauses.
- Paused variable values. Explain how inspecting variables in scope at a breakpoint helps reveal the data being processed.
- Execution stack trace. Describe what the execution stack trace shows at a pause and how it helps an investigation.
- Execution stack trace as map. Explain what a paused execution stack trace shows and how it helps guide debugging.
- Tracing the altered parameter. Describe how the example uses a breakpoint and execution stack trace to find why the printed parameter changes.
- Debugger navigation operations. Distinguish step over, step into, and step out in terms of where execution continues.
- Efficient stepping strategy. Explain how to begin an investigation and why stepping over is generally preferred before stepping into a method.
- Nested investigation workflow. Describe what to do after stepping into a method, whether reading it resolves the question or not.
- Finding a Debugging Starting Point. Explain why investigating wrong output requires finding where to pause execution and how class design or other techniques can affect that search.
- Performance Investigation Alternatives. Describe why a debugger is usually not enough for performance problems and identify the approaches suggested for slowness and complete blocking.
- Investigation After an App Crash. Explain why a debugger cannot observe an app after it has crashed and identify the evidence suggested for investigating the crash.
- Multithreading and Debugger Interference. Explain how debugging can affect a multithreaded app's behavior and why complex investigations may need a combination of techniques.
Section by section
Introduction
This introduction defines a debugger and explains its role in understanding complex code.
- Debugger execution control: Explain how a debugger helps a developer understand code by controlling execution and observing data.
Why it matters: This explains why a debugger is useful for understanding what code does.
Key terms: debugger, execution, data
2.1 When analyzing code is not enough
This section explains why reading code can become complex and how a debugger helps navigate and observe its execution.
- Nonlinear code reading: Explain how reading code differs from reading a poem and what a code investigation aims to establish.
Why it matters: Recognizing code reading as a nonlinear investigation helps explain why it is easy to lose your place. - Investigation depth and complexity: Explain why seemingly simple code can require deeper investigation and how choosing what to examine affects complexity.
Why it matters: Choosing where to investigate further balances understanding against the effort of tracking many paths. - Debugger navigation and observation: Describe how a debugger helps manage code investigation.
Why it matters: A debugger can make a complex investigation easier to follow while showing what happens to data.
Key terms: reading code, data being processed, investigation, investigation plan, cognitive complexity, reading path, debugger, data
2.2 Investigating code with a debugger
This section explains how to focus a debugging investigation, pause execution with breakpoints, and inspect the information available at a pause.
- Choosing an investigation point: Explain how to choose where to begin debugging and why reading the code first saves time.
Why it matters: Starting at the unclear logic keeps the investigation focused and saves time. - Breakpoint setup and execution: Describe how to set a breakpoint, start the app with a debugger, and interpret where execution pauses.
Why it matters: A correctly placed breakpoint lets you stop at the code you want to investigate. - Paused variable values: Explain how inspecting variables in scope at a breakpoint helps reveal the data being processed.
Why it matters: Variable values make the data being processed visible without having to infer every change from reading alone. - Execution stack trace: Describe what the execution stack trace shows at a pause and how it helps an investigation.
Why it matters: The stack trace provides a map of how execution reached the current instruction.
Key terms: debugger, breakpoint, Debug option, Run option, variables in scope, execution stack trace, calling chain, execution path
2.2.1 What is the execution stack trace, and how do I use it?
This section explains how to read a paused execution stack trace and use it to uncover framework logic hidden from the apparent code path.
- Execution stack trace as map: Explain what a paused execution stack trace shows and how it helps guide debugging.
Why it matters: The stack trace helps you see how execution reached the point you are investigating. - Hidden framework aspect logic: Explain why framework aspects can make an execution path harder to understand from source code alone.
Why it matters: Hidden framework logic can explain behavior that the apparent calls alone do not account for. - Tracing the altered parameter: Describe how the example uses a breakpoint and execution stack trace to find why the printed parameter changes.
Why it matters: This example shows how a stack trace can expose the source of an unexpected value.
Key terms: execution stack trace, method names, class names, aspects, interceptors, execution chain, breakpoint, ProductController, ProductService, aspect
2.2.2 Navigating code with the debugger
This section explains debugger navigation operations and how to use them efficiently to investigate code.
- Debugger navigation operations: Distinguish step over, step into, and step out in terms of where execution continues.
Why it matters: These operations let you control the level of detail you inspect while debugging. - Efficient stepping strategy: Explain how to begin an investigation and why stepping over is generally preferred before stepping into a method.
Why it matters: Observing results before entering calls can keep an investigation focused and manageable. - Nested investigation workflow: Describe what to do after stepping into a method, whether reading it resolves the question or not.
Why it matters: Reading before continuing helps avoid spending time on an investigation that is no longer needed. - Next execution line: Distinguish the next execution line from the next line in the source, including the section’s exception example.
Why it matters: This distinction prevents a debugger jump from being mistaken for an error in the navigation operation.
Key terms: step over, step into, step out, execution stack trace, investigation plan, breakpoint, next execution line
2.3 When using the debugger might not be enough
This section explains when debugging alone may be ineffective and identifies other investigation approaches for those situations.
- Finding a Debugging Starting Point: Explain why investigating wrong output requires finding where to pause execution and how class design or other techniques can affect that search.
Why it matters: Knowing where to stop makes a debugging session more useful. - Performance Investigation Alternatives: Describe why a debugger is usually not enough for performance problems and identify the approaches suggested for slowness and complete blocking.
Why it matters: Choosing an appropriate tool can save time when an app is slow or stuck. - Investigation After an App Crash: Explain why a debugger cannot observe an app after it has crashed and identify the evidence suggested for investigating the crash.
Why it matters: After execution stops, the investigation must use evidence other than a live debugger. - Multithreading and Debugger Interference: Explain how debugging can affect a multithreaded app's behavior and why complex investigations may need a combination of techniques.
Why it matters: An investigation can change the behavior it is trying to observe.
Key terms: pause the execution, class design, profiling, stubs, performance problems, logging, thread dump, crash, logs, thread dumps
2.4 Summary
Where this is used later
- Minimizing investigation time with conditional breakpoints (chapter 3) · Conditional breakpoints refine where an investigation pauses.
- (chapter intro) (chapter 4) · The use of a debugger to investigate an app’s execution.
- Using breakpoints that don’t pause the execution (chapter 3) · Execution stack traces
- Dynamically altering the investigation scenario (chapter 3) · Execution stack traces show the calls leading to a point in the program.
- Rewinding the investigation case (chapter 3) · The execution stack trace and its method layers.
- Finding issues in remote environments (chapter 4) · Breakpoint and step-over navigation.
- Finding out what code executes (chapter 6) · Finding what code executes can help locate an investigation starting point.
- Identifying slowness in an app’s execution (chapter 6) · Investigating slowness builds on recognizing profiling as an alternative to debugging.
Concepts explained in this chapter
- debuggerA software tool that lets a developer inspect and control a program's execution to examine its behavior or diagnose faults.
- stack traceA representation of the sequence of method calls active at a particular point in a program's execution.
- code analysisThe examination of source code to understand program behavior or investigate a possible cause of a problem.
- breakpointA breakpoint is a selected point in a program where a debugger pauses execution.
- Step IntoA debugger action that enters a method or instruction called at the current execution point.
- Step OutA debugger action that resumes execution until the current method exits, then pauses in the calling context.
- Step OverA debugger action that executes the current line without entering called methods and pauses at the next line in the current method.
- code navigation operationA debugger action that advances or redirects program execution through code.
- interceptorAn aspect is a modular unit of cross-cutting logic that can augment the execution of selected methods under specified conditions.
- profilingThe practice of gathering information about a program's execution to understand its performance or behavior.
These guides are generated from the text of Manning books by Manning's knowledge graph and link to the sections they draw on. The full books are available on liveBook and at manning.com.
