Home Learning Paths ECU Lab Assessments Interview Preparation Arena Pricing Log In Sign Up

Breakpoints: Software and Hardware

TypeImplementationLimitUse Case
Software (SW)Replaces instruction with BKPT opcode in RAMUnlimited in RAM; 0 in flashDebug builds in RAM; most common type
Hardware (HW)FPB (Flash Patch Breakpoint) unit on Cortex-M2–8 per coreFlash breakpoints; halt on instruction fetch
ConditionalSW/HW BP + debugger evaluates conditionSame as type aboveBreak only when counter==100 or error_code!=0
Temporary/stepDebugger places BP at next instruction for step-over1Step over function call

GDB Command Reference for Embedded C

Textgdb_commands.txt
# GDB commands for ARM Cortex-M debugging via OpenOCD

# Connect (from VS Code launch.json or command line)
# target extended-remote :3333    # OpenOCD port

# Breakpoints
break main                         # break at function entry
break can_driver.c:45              # break at source line
break *0x80000200                  # break at address
break g_can_rx_pending == 0        # conditional: only if variable == 0
watch g_shared_counter             # watchpoint: break on any write
rwatch g_status_reg                # read watchpoint
awatch g_dma_buf                   # read/write watchpoint
info breakpoints                   # list all breakpoints
delete 3                           # delete breakpoint 3

# Execution control
continue                           # run until next break
next                               # step over (source line)
step                               # step into function
finish                             # run until current function returns
until 80                           # run until line 80

# Inspect memory and registers
info registers                     # show all CPU registers
x/8xw 0x70001000                   # show 8 words at address (hex)
x/16xb &g_can_rx_data              # show 16 bytes of variable
print g_shared_counter             # print variable value
print/x *(uint32_t*)0xF0001000     # print hardware register
set variable g_pwm_duty = 50       # set variable value
display g_can_rx_pending           # auto-display on every break

# Stack and call graph
backtrace                          # show call stack
frame 2                            # switch to stack frame 2
info locals                        # show local variables in current frame
info args                          # show function arguments

Watchpoints: Catching Data Corruption

Cwatchpoint_debug.c
/* Scenario: g_shared_counter gets corrupted — which code path does it? */
/* Technique: set a hardware watchpoint in GDB; execution stops on write */

/* In GDB:
   watch g_shared_counter          # set watchpoint
   commands 1                      # run these commands when WP fires:
     backtrace                     # show call stack at time of corruption
     print g_shared_counter        # show new (corrupted) value
     continue
   end

   Run until corruption occurs → GDB halts showing exact code that wrote the value
*/

/* DWT watchpoint: Cortex-M hardware watchpoint via DWT comparator */
/* TRACE32 equivalent: Break.Set &g_shared_counter /Write /Size 4 */

/* Common scenario: stack overflow corrupts adjacent variable */
uint32_t g_canary   = 0xDEADC0DEu;   /* sentinel: place next to suspected corruption */
uint32_t g_counter;
/* Set watchpoint on g_canary; when it changes from 0xDEADC0DE: overflow detected */

Summary

Hardware watchpoints (DWT comparators on Cortex-M, up to 4 on M4/M7) are the most powerful embedded debugging tool: they halt execution the instant a specific memory address is written (or read), regardless of which code path triggered it. This makes them invaluable for debugging data corruption bugs that are impossible to find by reading code. GDB's watch command sets a DWT comparator via the debug adapter; TRACE32's Break.Set /Write does the same. The watchpoint + backtrace combination immediately identifies the exact write instruction and call stack that caused the corruption.

🔬 Deep Dive — Core Concepts Expanded

This section builds on the foundational concepts covered above with additional technical depth, edge cases, and configuration nuances that separate competent engineers from experts. When working on production ECU projects, the details covered here are the ones most commonly responsible for integration delays and late-phase defects.

Key principles to reinforce:

  • Configuration over coding: In AUTOSAR and automotive middleware environments, correctness is largely determined by ARXML configuration, not application code. A correctly implemented algorithm can produce wrong results due to a single misconfigured parameter.
  • Traceability as a first-class concern: Every configuration decision should be traceable to a requirement, safety goal, or architecture decision. Undocumented configuration choices are a common source of regression defects when ECUs are updated.
  • Cross-module dependencies: In tightly integrated automotive software stacks, changing one module's configuration often requires corresponding updates in dependent modules. Always perform a dependency impact analysis before submitting configuration changes.

🏭 How This Topic Appears in Production Projects

  • Project integration phase: The concepts covered in this lesson are most commonly encountered during ECU integration testing — when multiple software components from different teams are combined for the first time. Issues that were invisible in unit tests frequently surface at this stage.
  • Supplier/OEM interface: This is a topic that frequently appears in technical discussions between Tier-1 ECU suppliers and OEM system integrators. Engineers who can speak fluently about these details earn credibility and are often brought into critical design review meetings.
  • Automotive tool ecosystem: Vector CANoe/CANalyzer, dSPACE tools, and ETAS INCA are the standard tools used to validate and measure the correct behaviour of the systems described in this lesson. Familiarity with these tools alongside the conceptual knowledge dramatically accelerates debugging in real projects.

⚠️ Common Mistakes and How to Avoid Them

  1. Assuming default configuration is correct: Automotive software tools ship with default configurations that are designed to compile and link, not to meet project-specific requirements. Every configuration parameter needs to be consciously set. 'It compiled' is not the same as 'it is correctly configured'.
  2. Skipping documentation of configuration rationale: In a 3-year ECU project with team turnover, undocumented configuration choices become tribal knowledge that disappears when engineers leave. Document why a parameter is set to a specific value, not just what it is set to.
  3. Testing only the happy path: Automotive ECUs must behave correctly under fault conditions, voltage variations, and communication errors. Always test the error handling paths as rigorously as the nominal operation. Many production escapes originate in untested error branches.
  4. Version mismatches between teams: In a multi-team project, the BSW team, SWC team, and system integration team may use different versions of the same ARXML file. Version management of all ARXML files in a shared repository is mandatory, not optional.

📊 Industry Note

Engineers who master both the theoretical concepts and the practical toolchain skills covered in this course are among the most sought-after professionals in the automotive software industry. The combination of AUTOSAR standards knowledge, safety engineering understanding, and hands-on configuration experience commands premium salaries at OEMs and Tier-1 suppliers globally.

← PreviousHands-On: C++ Adaptive Application ModuleNext →Memory Leak & Stack Overflow Detection