Tracepoints (Software handled)

* Tracepoint discussed in this article is a Atmel studio feature (inherited from Visual studio), that suspends a running program by inserting a breakpoint and executes a specified action and resumes the execution automatically.  

* For timing insensitive programs this mechanism works really well, but for interrupt driven and timing sensitive programs the delay caused by breaking the program and resuming might not be a good solution. But if you are someone who want a simple tracing feature at free of cost then this is an article for you. 

* This article is a copy of this MSDN document, but for the sake of distinguishing the explanation in the context of Atmel studio, I am rewriting it here. 

Tracepoints are a new way to use breakpoints. A tracepoint is a breakpoint with a custom action associated with it. When the tracepoint is hit, it causes the debugger to perform the specified action instead of (or in addition to) breaking program execution. 

You can create a tracepoint in two different ways: 

  • You can convert an existing breakpoint into a tracepoint by adding a tracepoint action. Any type of breakpoint can be converted into a tracepoint. 

  • You can create a tracepoint from scratch with the New Tracepoint command. 

To create a tracepoint from scratch 

  1. In a source window, right click a line where you want to set a tracepoint, and then select Insert Tracepoint from Breakpoints on the shortcut menu. 

  1. The When Hit dialog box appears. It contains two text boxes where you can enter custom actions: Print a message and Run a macro 

  1. At this point, you can accept the preselected tracepoint settings, or modify them as follows: 

  1. To create a tracepoint that prints a message to the Output window, select Print a Message and enter the message text in the corresponding text box. By using Print a Message, you can use tracepoints for same purposes that you would use a trace class, but without the need to modify your code. 

  1. In function '{$FUNC}', {$CALLSTACK} 

  1. -or- 

  1. Used variable: {varName}, function name: {functionName($FUNC)} 

  1. You can use any of the keywords shown on the When Breakpoint Is Hit dialog box. In addition, you can use two other keywords that are not shown in the dialog box:$TICK inserts the current CPU tick count, while $FILEPOS inserts the current file position. 

  1. A default message appears in Print a Message when the When Breakpoint Is Hit dialog box opens. If you want to accept this message, click OK. 

  1. Run a Macro option is currently not supported. 

  1. When you select Print a Message, the Continue Execution check box becomes active. Select Continue Execution if you do not want the tracepoint to break execution of your program. 

  2. Click OK. 

To create a tracepoint from an existing breakpoint 

  1. In a source, Disassembly, or Call Stack window, right-click a breakpoint glyph and select When Hit. 

  1. -or- 

  1. In the Breakpoints window, right-click a breakpoint glyph and select When Hit. 

  1. The When Hit dialog box appears. 

  2. Click OK to accept the preselected tracepoint settings, or modify them as explained in the previous procedure.