在Visual studio中使用跟踪断点


https://blogs.msdn.microsoft.com/visualstudioalm/2013/10/10/tracepoints/


This blog post is part of a series on breakpoints in the Visual Studio debugger and has been updated to reflect the experience of using Visual Studio 2015. If you are interested in details about setting tracepoints using earlier versions of Visual Studio please see the MSDN documentation.

What is a tracepoint? It is a point in the application that allows the developer to perform some action, like logging a message to the output window, and then have the option to continue execution of the program, so it does not have to break at that point during debugging.

To first illustrate how tracepoints are used, we will look at the GCD function in our managed sample. Let’s say we wanted to see all of the steps in calculating the GCD, but we didn’t want to have to stop the program at every iteration.

To get started, first create a breakpoint in the GCD function, and then hover over the breakpoint to bring up the breakpoint’s toolbar and click the “Settings…” icon.

You can also right-click on the breakpoint to bring up the context menu, and select “Actions…”

This will bring up the Breakpoint Settings window. Select “Actions” and “Continue execution”. In the message field you can include custom text, variables, and expressions. (Tip: Using the context menu will open the window with the Actions box already checked.)

You can include the value of a variable or other expression by placing it in curly braces. (To insert a curly brace or backslash into your message as text use “\{“ or “\\” respectively).

There are also many pseudo variables available to output for tracepoint messages. The following special keywords will be replaced with their current
values when the tracepoint is reached during debugging.
 

Pseudo Variable:

Description:

$ADDRESS

Current Instruction

$CALLER

Previous Function Name

$CALLSTACK

Call Stack

$FUNCTION

Current Function Name

$PID

Process Id

$PNAME

Process Name

$TID

Thread Id

$TNAME

Thread Name

You’ll notice that, the breakpoint icon takes on a diamond shape. This indicates that the action is set to continue execution automatically so the program will not stop at that location.

When the program is executed, you can view the results of the tracepoints in the Output Window.

In this way, tracepoints give you a way to print out values without having to make changes to your source code.

Additionally, if you use IntelliTrace, you can view your tracepoints in the Events View and after selecting the event, you can view the output of the tracepoint in the Locals window.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值