亚洲香蕉成人av网站在线观看_欧美精品成人91久久久久久久_久久久久久久久久久亚洲_热久久视久久精品18亚洲精品_国产精自产拍久久久久久_亚洲色图国产精品_91精品国产网站_中文字幕欧美日韩精品_国产精品久久久久久亚洲调教_国产精品久久一区_性夜试看影院91社区_97在线观看视频国产_68精品久久久久久欧美_欧美精品在线观看_国产精品一区二区久久精品_欧美老女人bb

首頁 > 編程 > C++ > 正文

Debugging Tips and Tricks for C++ in Visual Studio

2019-11-06 06:18:43
字體:
來源:轉載
供稿:網友

Visual C++ Team Blog

July 11, 2016 by Andrew B Hall - MSFT // 33 Comments

When we write software our goal is to create correctly functioning applications the first time. Unfortunately, it rarely works that way and we spend a significant amount of time and effort debugging PRoblems in the code rather than adding new value. Fortunately, when issues arise that need investigation Visual Studio ships a world class debugging experience to help find the issue quickly. However, many of us don’t take full advantage of the debugger because we don’t know or simply forget about many of the capabilities it offers to speed up problem solving.

In this post I’ll provide a brief overview the debugging features I showed in a recent C++ Debugging Tips and Tricks video. It certainly doesn’t cover everything but each capability is linked to more detailed information if you want to dive deeper. Additionally, each tip contains a direct link to the exact point in the video I show it.

So go through the following 22 tips and let us know how many of these are new to you – is there anybody that knew all of them? Which one is your favorite?

Finally, before you continue please take a minute to sign up to help us continue to improve the debugger to better meet your needs.

Tips and Tricks

Configuring launch options from project properties (1:25). One common pattern when developing software is to add configuration options to change behavior or test alternate designs based on either command line or environment variable settings. You can configure both command line parameters and set environment variables for the target application on the “Debugging” tab of the Project Properties page (Right click on the project in Solution Explorer and choose “Properties” from the context menu.

Function return values (2:34). When stepping through code in the debugger, the Autos window shows you the values returned by all functions called on the previous line of code.

clip_image002

Set next statement (3:16) enables you to change the next instruction in the application that will execute. This is great for going back and re-running a piece of that that just executed, or can be useful for forcing the application down different code paths to test functionality (e.g. you can move execution inside of a conditional block even if the condition evaluates to false). You can change the next statement by either click and dragging the yellow instruction pointer in the left margin to the desired line, access it through the context menu by right clicking on the desired line and choosing “Set Next Statement” from the context menu, or by using the keyboard shortcut Ctrl+Shift+F10 to set the next statement to line the cursor is on. It is important to note that this simply changes the next instruction that will execute, it does not undo anything that happened previously or run code if you move it forward, for example, if you skip a line of code that initializes a variable using set next statement, the application will crash since the variable will remain initialized.

Step into specific (4:07) allows you to step directly into a function when there are multiple function calls on the same line without the need to navigate to the definition, set a breakpoint, and then continue execution to hit the breakpoint. Step Into Specific can be access from the editor’s context menu by right clicking on the current line, or using the keyboard shortcut Shift+Alt+F11

Run to cursor (5:05) functions as a onetime use breakpoint, by running the debugger to that line and then stopping at that point. Run to cursor can be accessed from both the editor context menu or by using the keyboard shortcut Ctrl+F10 to run to the line the cursor is on. Another useful tip for Run To Cursor is even at design time (when you’re not debugging) the keyboard shortcut Ctrl+F10 will start debugging and run the application to that line of code just like you set a breakpoint and hit F5.

Edit and Continue (6:57) is one of the great productivity time savers when debugging code. If you notice a simple mistake you can correct it while stopped in the debugger without the need to stop debugging, recompile, and run the application back to that location. In Visual Studio 2015 we added support for Edit and Continue into the default C++ debug engine including support for x64 debugging.

Exception Settings (8:31) configure the debugger to stop when specified exceptions are thrown, even if they will later be caught in the application. This is useful when debugging issues where the application is handling the exception but you need to debug why the exception is happening.

Conditional, Hit Count, and Filter Breakpoints (13:44). A Conditional Expression tells the debugger to stop only when a certain condition in the application is met (e.g. when a variable matches a certain string). A Hit Count enables you to break based on the number of times the breakpoint has been hit when equal to an absolute number, equal to or greater, or when the count is a multiple of the number; which is useful if you need to take a sampling based approach to solving an issue (e.g. only show every 100th value). Filter conditions are designed for parallel processing scenarios and enable you to stop when executing on a certain thread, process, or machine.

clip_image004

Pinning DataTips (19:17) when working inside an iterative code path (e.g. for loop) you’re often focused on a single value. Inspecting variables by hovering over them in the editor is great but the DataTips disappear when you move the mouse. By clicking the “pin icon” on the far right side of the DataTip you can “stick” it to the editor so it stays visible on that line of source code until you choose to close it.

clip_image006

Parallel Stacks window (19:42) shows you the call stacks of all of the threads in the process in a concise view. The Parallel Stacks window is opened through the Debug -> Windows menu.

clip_image008

Show External Code (20:30). Visual Studio by default enables a feature we call Just My Code that helps you focus on the code you control by collapsing Operating system and runtime frames on the call stack into a single [External Code] frame. I you want or need to see the complete stack, you can right click in either the Call Stack or Parallel Stacks window to show the complete call stack. If you prefer to debug with this always off, you can permanently disable Just My Code under Debug -> Options

Parallel Watch window (22:00) shows the value of a variable across all threads executing in the current function. It also will show the value of the same variable across stack frames in the case of a recursive method.

clip_image010

Freeze and Thaw threads (23:13) gives you fine grained control over the execution of individual threads. If a particular thread is problematic but you don’t want other threads running while your debugging a single thread you can freeze the threads you don’t want running. When frozen they do not execute any code even when you resume execution of the application.

Flag Threads and Run Flagged Threads to Cursor (24:18) flagging threads enables you to create groups of threads, and then just like Run to Cursor enables you to run the application to a specific line of code, Run Flagged Threads to Cursor enables you to move a group of threads to a specific line. This can be very useful in situations where you need to control the location of certain threads (e.g. to make sure that none of them are holding a lock and then freeze them).

Show Threads in Source (26:13) is a setting that enables you to see what threads are executing with a small glyph in the breakpoint margin. To turn it on, click the “Show Threads in Source” button the debugger toolbar (shown below).

clip_image012

This feature is incredibly powerful when working in code that is running in parallel, but does come at a small performance cost so shouldn’t be left on indefinitely when you’re not using it.

clip_image014

Debug Location toolbar (28:09) is a toolbar that gives you access to the current call stack and the ability to quickly switch between threads among other capabilities. It is visible by default if you use the “General Settings” profile, otherwise you’ll need to manually enable it through View -> Toolbars.

Debugging Heap Corruption with PageHeap (29:43). Heap corruption can be one of the most difficult types of bugs to solve, since the logic error that resulted in the corruption usually occurs long before the application crashes or behaves strangely making it hard to diagnose the location the issue occurs at. PageHeap is a capability in Windows that causes in the operating system to raise an exception if the application either writes to or reads from memory it no longer owns resulting in heap corruption causing the debugger to stop at the location causing the heap corruption. Enabling page heap currently requires using the gflags utility built into the Debugging Tools for Windows as part of the Windows SDK. Once you’ve installed the Debugging Tools for Windows, open an administrative command prompt and run gflags /p /enable [executable name] to enable PageHeap, then debug the application in Visual Studio like normal. A quick Word of caution, PageHeap causes Windows to do more memory tracking, so it slows down the speed of the application it is enabled for, so you shouldn’t leave this on indefinitely if not debugging heap corruption.

clip_image016

PerfTips (33:32) shows you the time your code was executing between stops in the debugger (both when stepping over code and running between breakpoints).

clip_image018

Integrated CPU Profiling (35:53) when writing code, often we do all we can to get it working correctly and it can be difficult or impossible to take the time to profile it separately. To improve the convenience of quickly finding major issues in performance we’ve integrated a CPU profiler into the debugger, that can be access through the Diagnostic Tools window.

Integrated Memory Profiling (38:01) tracking down memory leaks can be hard. To make this easy as possible we’ve integrated memory profiling tools designed to help find and fix leaks directly in to the debugger through the Diagnostic Tools window. By integrating it directly into the debugger, you have fine grained control over where you take snapshots, meaning you look at the memory changes introduced by a single function call or a single line of code.

clip_image020

Natvis (41:03) lets you customize the way Visual Studio displays native types in the debugger. In Visual Studio 2015 we added support for adding project local natvis files, that take effect in the debugger as soon as they are updated, no need to restart debugging.

Showing what source code causes an Access Violation (42:43) frequently a single line of code will deference multiple pointers, which results in hunting for exactly which pointer triggered an access violation. In Visual Studio 2015 Update 1 we added analysis logic into the debugger to show you the exact source expression that triggered the Access Violation.

clip_image022


發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表

圖片精選

亚洲香蕉成人av网站在线观看_欧美精品成人91久久久久久久_久久久久久久久久久亚洲_热久久视久久精品18亚洲精品_国产精自产拍久久久久久_亚洲色图国产精品_91精品国产网站_中文字幕欧美日韩精品_国产精品久久久久久亚洲调教_国产精品久久一区_性夜试看影院91社区_97在线观看视频国产_68精品久久久久久欧美_欧美精品在线观看_国产精品一区二区久久精品_欧美老女人bb
精品女同一区二区三区在线播放| 欧美亚洲一级片| 欧美一级电影免费在线观看| 亚洲男人天堂2023| 亚洲国产成人精品女人久久久| 国产精品99久久久久久人| 夜夜狂射影院欧美极品| 亚洲人成电影在线观看天堂色| 精品国产乱码久久久久久婷婷| 亚洲成色www8888| 欧美在线视频观看免费网站| 国产精品丝袜高跟| 日韩网站免费观看高清| 91国内产香蕉| 欧美精品电影免费在线观看| 国产成人jvid在线播放| 亚洲电影天堂av| 国产日本欧美一区| 97视频com| 欧美一级黑人aaaaaaa做受| 亚洲精品视频免费| 亚洲性av网站| 欧美野外wwwxxx| 北条麻妃在线一区二区| 欧美日韩午夜剧场| 亚洲伊人第一页| 欧美影院在线播放| 亚洲一区中文字幕在线观看| 黑人巨大精品欧美一区二区一视频| 国产玖玖精品视频| 欧美精品亚州精品| 国产精品自拍偷拍视频| 国产91色在线|| 国产欧美一区二区三区在线看| 正在播放国产一区| 色综合老司机第九色激情| 国产成人精品一区| 欧美日韩爱爱视频| 91国产精品视频在线| 日韩免费视频在线观看| 亚洲一区二区三区乱码aⅴ蜜桃女| 两个人的视频www国产精品| 色琪琪综合男人的天堂aⅴ视频| 日韩欧美aⅴ综合网站发布| 秋霞av国产精品一区| 日韩三级成人av网| 91av视频在线| 国产精品小说在线| 欧美一区二区三区艳史| 国产视频欧美视频| 国产专区欧美专区| 国产成人久久精品| 国产一区二区日韩| 国产精品一区二区三区久久| 永久免费看mv网站入口亚洲| 日韩www在线| 亚洲一区二区在线| 亚洲女性裸体视频| 91精品国产高清久久久久久| 国产精品国产三级国产aⅴ浪潮| 95av在线视频| 国产自摸综合网| 日韩中文在线中文网在线观看| 国产精品免费久久久久久| 国产视频精品xxxx| 91情侣偷在线精品国产| 国产精品久久一区| 欧美放荡办公室videos4k| 欧美日韩免费在线观看| 在线观看日韩视频| 欧美成人午夜视频| 国产精品一区二区性色av| 91av在线播放视频| 97视频在线播放| 免费不卡欧美自拍视频| 国产91网红主播在线观看| 91老司机在线| 992tv在线成人免费观看| 精品久久久香蕉免费精品视频| 色多多国产成人永久免费网站| 91久久精品国产91久久| 中日韩美女免费视频网站在线观看| 成人欧美一区二区三区在线湿哒哒| 在线播放国产一区二区三区| 在线亚洲国产精品网| 狠狠躁夜夜躁久久躁别揉| 91九色国产在线| 欧美精品videos性欧美| 久久精品99无色码中文字幕| 欧美高跟鞋交xxxxxhd| 日韩在线视频免费观看| 成人激情av在线| 日韩三级影视基地| 日本精品视频在线观看| 色综合久久悠悠| 亚洲一级黄色片| 亚洲欧美一区二区三区四区| 91国偷自产一区二区三区的观看方式| 在线观看视频亚洲| 久久久999国产精品| 亚洲一区二区三区四区在线播放| 亚洲a∨日韩av高清在线观看| 成人免费直播live| 国产99久久精品一区二区 夜夜躁日日躁| 色综合影院在线| 国产精品v日韩精品| 在线视频欧美性高潮| 亚洲欧美国产视频| 国产女同一区二区| 日韩中文字幕在线视频| 亚洲天堂av女优| 日韩有码视频在线| 青青a在线精品免费观看| 色综合色综合久久综合频道88| 欧美成人免费观看| 国产不卡精品视男人的天堂| 久久中文字幕国产| 亚洲成人免费在线视频| 欧美精品在线极品| 精品电影在线观看| 全球成人中文在线| 亚洲三级 欧美三级| 成人淫片在线看| 欧美日韩亚洲高清| 日韩一区视频在线| 亚洲国产精品久久久久| 亚洲精品在线看| 亚洲www视频| 精品亚洲精品福利线在观看| 国产精品极品美女粉嫩高清在线| 久久久噜久噜久久综合| 亚洲欧美日韩在线高清直播| 中文字幕日韩精品有码视频| 久久精品成人动漫| 这里只有精品视频在线| www.久久久久| 欧美黑人巨大xxx极品| 亚洲成人精品在线| 欧美性在线视频| 国产成人高清激情视频在线观看| 中文字幕亚洲欧美一区二区三区| 国产精品老女人精品视频| 日韩精品免费在线播放| 欧美视频一区二区三区…| 在线观看中文字幕亚洲| 亚洲欧洲午夜一线一品| 亚洲激情成人网| 98精品国产自产在线观看| 91国内精品久久| 成人激情电影一区二区| 久久精品视频在线播放| 国产精品自拍小视频| 欧美色道久久88综合亚洲精品| 日韩在线视频国产| 亚洲丝袜一区在线| 欧美极度另类性三渗透| 欧美一区二区三区免费视| 亚洲天堂av图片| 亚洲嫩模很污视频| 亚洲欧洲成视频免费观看| 中文字幕日韩综合av| 久久精品国产亚洲| 狠狠色香婷婷久久亚洲精品| 欧美激情精品久久久久久蜜臀|