简体   繁体   中英

Visual C++ debugger visualizer?

How does Visual Studio show the elements of a vector, or the characters of a string, in C++? Is there a way for me to make it show my own classes in a custom way?

http://msdn.microsoft.com/en-us/library/zf0e8s14(v=VS.100).aspx

For native code, you can add custom data type expansions to the file autoexp.dat, which is located in the Program Files\\Microsoft Visual Studio 10.0\\Common7\\Packages\\Debugger directory. Instructions on how to write autoexp rules are located in the file itself.

For this class:

template<class T>
struct  auto_array {
     T* data;
     int Len;
};

the autoexp.data might look like:

auto_array<*> {
    children
    (
        #array
        (
            expr :      $e.Data[$i],
            size :      $e.Len
        )
    )
    preview
    (
        #(
            "[", $e.Len , "](",
            #array
            (
                expr :  $e.Data[$i],
                size :  $e.Len
            ),
            ")"
        )
    )
}

KindDragon reports that Visual Studio 2012 uses a new file format: natvis

You can add visualizers for custom C++ types to the autoexp.dat file. The format used in the file and the location change from version to version of Visual Studio but if you Google for autoexp.dat you should find some examples of how to customize it.

对于VS2017 / 2015,使用Natvis可视化在Visual Studio调试器中创建本机对象的自定义视图。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM