Visual Studio Debugger Watch problems

早过忘川 提交于 2019-12-11 02:59:32

问题


How can I find out the address of a variable on the stack in the visual studio debugger watch window (or elsewhere?)

Reading the variable works fine:

streets     streets [11790](0x1c66a690 [...] std::vector<Street *,std::allocator<Street *> >

But prefixing with & doesn't give me an address:

&streets        streets [11790](0x1c66a690 [...] std::vector<Street *,std::allocator<Street *> >

Also, trying to read the size doesn't work, why is that?

streets.size()  CXX0075: Error: Cannot set up Function Evaluation   

The program is compiled in debug mode.


回答1:


The Visual Studio Debugger drives debugger watch, quick-watch, auto, and local variable views through a translation defined by schema in a file called autoexp.dat (depending on your VS version, the content therein can vary markedly). The file is located in your VS-InstallDir/Common7/Packages/Debugger folder (at least it is for VS2010 and VS2012).

Knowing this, a couple of ideas for you to try/consider:

Method One: Library Know-How

To access the actual address of the first element within the vector I ultimately just do this:

streets._Myfirst

if you know the number of elements you're going to view, you can use the array-expansion extension by:

streets._Myfirst,N

where N is the number of elements

Note: this only works as shown above with vectors. The practice is different depending on which container you are using. There are no-doubt simpler ways that are probably less dependent on the implementation of std::vector<>, but this is the simplest wasy I know how to get you up and debugging quickly.


Method Two: Scorched Earth

Under Tools/Options/Debugging/General is a list of features you can switch on and off. One of them you will find particularly useful to this question:

Show raw structure of objects in variable windows.

Turn this ON to see raw member variables of all structures and containers, including standard containers like std::vector<>. This effectively disables usage of the templates in autoexp.dat




回答2:


To see the address, cast to a void *, like so: (void *)&streets.

This is Visual Studio's attempt to be helpful by showing you the pointed-to vector directly. A similar problem affects arrays of vectors.



来源:https://stackoverflow.com/questions/13420650/visual-studio-debugger-watch-problems

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!