本文摘自:http://blogs.msdn.com/b/vcblog/archive/2006/08/04/689026.aspx

Hi, my name is Sergey Grankin and I'm a developer on the VC++ IDE Team.  I mostly work on the C++ debugger expression evaluators -- the code responsible for the magic behind the debugger watch windows.

Visual Studio's (native) C++ debugger has many useful features that can make your debugging much more pleasant, if you know what they are.  These tend to accumulate over releases, and get forgotten and unused, unless you happen upon an archaic piece of documentation. On this topic, then, there are special expression and format specifiers that you can use to better examine the content in the debugger's watch windows.

For example, say we break after the following bit of code:

int i = 0x12345678;

You can use the by, wo, and dw operators to view contents of a variable as an unsigned byte, word, or dword:

i                 0x12345678             int

by i            0x78 'x'                    unsigned char

wo i           0x5678                    unsigned short

dw i           0x12345678            unsigned long

You can also use the operators on a register to do the same to the destination of the register:

eax 0x0012ff2c                       unsigned long

by eax       0x78 'x'                 unsigned char

wo eax      0x5678                 unsigned short

dw eax      0x12345678         unsigned long

These come in handy when debugging through assembly.

Another way to change debugger output is through format specifiers.  These are directives passed after the expression, separated by a comma. For example, to change the radix out the output, you can append ',o' for octal, ',d' for decimal, or ',x' for hex:

i       42                                  int

i,o     052                              int

i,d     42                                int

i,x     0x0000002a                 int

To interpret a pointer expression as a string, you can use ',s' for an simple null-terminated string, ',s8' for a UTF-8 string, or ',su' for a Unicode string. (Note that the expression has to be a pointer type for this to work).

char str[] = "hello";

wchar_t str2[] = L"world";

str                          0x0012ff00 "hello"                        char [6]

str,s                        "hello"                                            char [6]

str2                         0x0012fee8 "world"                     wchar_t [6]

(void*)str2,su      "world"                                           void *

The memory operators can be used to display up to 64 bytes of memory in the preview line, as bytes, words, dwords, quads, or ascii characters.

str,m          0x0012ff00   68 65 6c 6c 6f 00 cc cc cc cc cc cc cc cc cc cc  hello.                   char [6]

str,mb        0x0012ff00    68 65 6c 6c 6f 00 cc cc cc cc cc cc cc cc cc cc  hello.                   char [6]

str,mw       0x0012ff00    6568 6c6c 006f cccc cccc cccc cccc cccc                                      char [6]

str,md        0x0012ff00    6c6c6568 cccc006f cccccccc cccccccc                                          char [6]

str2,mu      0x0012feec    0077 006f 0072 006c 0064 0000 cccc cccc  world.??              wchar_t [6]

str,mq        0x0012ff00    cccc006f6c6c6568 cccccccccccccccc                                            char [6]

str,ma         0x0012ff00    hello.(..(......T..                                                                     char [6]

You can use ,wc ,wm and ,hr to view data as a window class, window message, or HRESULT.

0x00400000,wc     WS_OVERLAPPEDWINDOW                                                   int

0x10,wm               WM_CLOSE                                                                                   int

0x10,hr                 0x00000010 The directory cannot be removed.                              int

Finally, you can use ,! to turn off STL visualizations on the expression:

str       "hello world"                                                                                                       std::basic_string< ... >

str,!     {_Bx={...} _Mysize=0x0000000b _Myres=0x0000000f}                               std::basic_string<...>

All of these operators can be used to ease the way you get to data while debugging, and become necessary whern creating custom visualizations. You can check-out the autoexp.dat file in your Visual Studio directory for examples of how to combine these operators and the visualization language to create custom visualizers for your own data.

-- sergey grankin // vc++ dev team

VC++ Debugger Tips[转]的更多相关文章

  1. Visual Studio原生开发的10个调试技巧(二)

    来源:oschina 发布时间:2013-08-10 阅读次数:397 51   我以前关于Visual Studio调试技巧的文章引起了大家很大的兴趣,以至于我决定分享更多调试的知识.以下的列表中你 ...

  2. (转)Visual Studio原生开发的10个调试技巧(二)

    我以前关于Visual Studio调试技巧的文章引起了大家很大的兴趣,以至于我决定分享更多调试的知识.以下的列表中你可以看到写原生开发的调试技巧(接着以前的文章来编号).这些技巧可以应用在VS200 ...

  3. Visual Studio 原生开发的10个调试技巧(二)

    原文:Visual Studio 原生开发的10个调试技巧(二) 我以前关于 Visual Studio 调试技巧的文章引起了大家很大的兴趣,以至于我决定分享更多调试的知识.以下的列表中你可以看到写原 ...

  4. Microsoft Build 2015 汇总

    简要概括(GitHub 完成约 45%): Visual Studio Code Preview(意料之外) Visual Studio 2015 RC Visual Studio 2013 Upda ...

  5. IOS本地化应用

    BK项目已完成7788,在项目的后期需要被翻译成多国语言版.为了适应全球多个国家使用多个存储. 应用本地化是分别对字符串.图片和 xib 或 storyboard 文件本地化,而传统的做法是对 xib ...

  6. Microsoft Build 2015

    Microsoft Build 2015 汇总   简要概括(GitHub 完成约 45%): Visual Studio Code Preview Visual Studio 2015 RC Vis ...

  7. VC Debug和Release区别

    https://msdn.microsoft.com/en-us/library/xz7ttk5s.aspx   Optimizing Your Code Visual Studio 2015 The ...

  8. Create views of OpenCASCADE objects in the Debugger

    Create views of OpenCASCADE objects in the Debugger eryar@163.com Abstract. The Visual Studio Natvis ...

  9. android 官方文档 JNI TIPS

    文章地址  http://developer.android.com/training/articles/perf-jni.html JNI Tips JNI is the Java Native I ...

随机推荐

  1. cf 730i

    题意:有n个人,每个人有两个能力值,选a个人用它的第一个能力值,b个人用它的第二个能力值,每个人只能选一次,求一个方案使得能力值之和最大,并输出选择方案. 题解:最小费用最大流,原点1向n个人每个人i ...

  2. Android Studio新建一个HelloWorld 程序(App)

    Android Studio新建一个HelloWorld程序(App) 新建 或者直接启动程序(注:如果已有程序,此方法会直接打开最近一次关闭从程序) 更改App名 选择App运行平台 选择模板 更改 ...

  3. linux中用户、组的管理(密码管理、权限管理及其修改用户、组)(转)

    process(进程) 1 计算资源 权限 用户(获取资源或服务的凭证或标识) 用户,容器,关联权限:用户组(标识符),方便地指派权限 2 用户.组.权限   安全上下文(secure context ...

  4. JS实现动态提示文本框可输入剩余字数(类似发表微博数字提示)

    一.实现效果: 为了更直观的体现用户在文本框输入文本时能看到自己输入了多少字,项目中需要通过判断提示文本框剩余可输入字数. html & JS: <div> <textare ...

  5. js 阻止浏览器默认行为

    <!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8" ...

  6. (转)jQuery EasyUI Tree - TreeGrid动态加载子节点

    有时我们已经得到充分的分层树形网格(TreeGrid)的数据. 我们还想让树形网格(TreeGrid)按层次惰性加载节点. 首先,只加载顶层节点. 然后点击节点的展开图标来加载它的子节点. 本教程展示 ...

  7. .net学习笔记--文件读写的几种方式

    在.net中有很多有用的类库来读写硬盘上的文件 一般比较常用的有: File:1.什么时候使用:当读写件大小不大,同时可以一次性进行读写操作的时候使用         2.不同的方式可以读写文件类型不 ...

  8. css3的背景颜色渐变@线性渐变

    背景颜色渐变之线性渐变 语法形式: firefox浏览器 background:-moz-linear-gradient(position/deg,startColor,endColor); oper ...

  9. transform-style: preserve-3d在iphone下的bug

    经测,当元素设置transform-style: preserve-3d;后,其实现rotateY时的动画效果会穿透上层的覆盖图层. 马克一下

  10. spring+hibernate实体类注解详解(非原创) + cascade属性取值

    @Entity //继承策略.另一个类继承本类,那么本类里的属性应用到另一个类中 @Inheritance(strategy = InheritanceType.JOINED ) @Table(nam ...