Visual Studio debugging - Order of local variables? - c++

I am wondering on what concept/logic the ordering of the variables is based on in the 'Locals' tab when debugging an application with MS Visual Studio.
For me it seems to be somewhat randomly ordered? Or is there any concept behind the ordering of these variables?
Is there an option to sort these variables alphabetically? This would be very handy.

I don't know a way to sort the items in the locals tab directly. But here is a workaround:
Select all locals (Ctrl-A, Ctrl-C) and paste them to a watch list (Ctrl-V).
Sort the watch list by (workaround again) cut and pasting them.
Note that there is an "Autos" watch window. Maybe it's better suited for your needs, although you neither can sort entries there.
Finally you may have more than one (custom) watch window, see Menu / Debug / Window / Watch / Watch 1 .. 4. This may also be helpful organizing variables to watch.

In my Visual Studio 2008, the sort order of Locals window is as follows: the current class-level Me object is first, with any module-level variables being sub-nodes of that. Then listed below Me are the procedure-level variables in Alphabetical order. After years of searching, I haven't found any way to change the sort order. The only thing left I can think of is a Visual Studio Extensibility Add-In, but I haven't explored that.
I have a strong background in VBA, and I can tell you over there, if there's a Me object in the current context, that comes first just like Visual Studio. But...and here's the difference...the module-level variables are listed in Declaration Order, meaning they're listed in the same order as their Dim statements. And just like Visual Studio, the order can't be changed.
The VBA way of doing it is much more useful, because you can control the order of the Locals window by re-ordering the Dim statements in the code.

Related

Configuring Visual Studio 2019 to automatically pick up the highlighted option from intellisense in C++ by hitting enter

The intro text says it all. I tried messing around with options related with the intellisense on VS, but no success. I mean, it does pick our options via enter, but, by the default, we gotta confirm the selection with the arrow keys first, which is an unnecessary step. Any clues?
To implement your idea, you need to set Member List Commit Aggressive to true.
The specific path is Tools->Options->Text Editor->C/C++->Advanced->Member List Commit Aggressive.

How can I give my class a nominal "value" that can be displayed by a variable browser in a debugger?

When using debuggers (I'm using Visual Studio 2013 for this example), a variable window is often shown giving the names and values of variables in the current scope.
When a value is displayed for a class, it defaults to a format like this: {a=val1 b=val2 ...} which isn't always helpful when debugging.
Is there a way, such as operator overloading, that will let me choose what gets shown as a class' "value"?
I believe what you are looking for are Visualizers as long as you are using Visual Studio.
This website has a nice tutorial on them.

Debugging and difference search after refactoring in Visual Stduio

I am involved in a c++ refactoring project and sometimes there are differences resulting, when there should be none. Currently, what I do is basically setting a breakpoint at some place, and then go through the program by F10/F11. The first problem is the size of the projects, traversing it takes a lot of time. Second, sometimes I have differences only in the end of a very big test sentences (say, 600 words), thus just getting to the different word is painfully slow.
1. Is it possible to write some kind of macro for Visual Studio, which will start from the breakpoint, then go step-by-step through the program until end while printing some fields?
2. Are there any neat tricks or tools to simplify the task?
Thanks!
You can create Macros by using Tools>Macros>Macro IDE
If prefer the following method because it's faster for me.
You can record macros using Tools>Macros>Record temporary macro
Everything you type will then be recorded into a macro.
After you recorded what you want to be automated, you can edit the generated code by using View>Other windows>Macro Explorer. Your macro will be recorded in MyMacros>RecordingModule>TemporaryMacro in Macro Explorer window. If you right click that and select edit.
One way to test if the program is terminated:
While Not DTE.Debugger.CurrentProgram Is Nothing

Build data/class/rtti tree during runtime

With visual studios you can put your mouse over a variable which will pop up [classname] with members and node names. You can look through a tree of objects, see what values they hold, etc with it.
Is there a way i can dump it into a file so i can easily see it? I had to click >50 times to look through this object and its not a very complex object either..
I am using visual studios 2010 but i don't mind gcc if it has a tool for this task
You can use Doxygen to create a cross-referenced documentation of your code based on the annotations. It's quite simple, and will provide the info you're looking for and so much more.
Other than cross-referencing and type hierarchy, you will also be able to get calling graphs, references, and if you put the annotations in your code - documentation. Very powerful tool.

Is there a way to prevent a "keyword" from being syntax highlited in MS Visual Studio

MS Visual Studio editor highlights some non-keyword identifiers as keywords
in C++ files. Particularly "event" and "array" are treated as keywords.
That's very annoying to me, because they are not C++ keywords.
I know how to add my own keywords to the list of syntax-highlighted identifiers,
but how to remove existing built-in ones?
I'm aware that this may require patching some executable files.
So does anyone know how to do this?
Thanks to article mentioned by Steve Guidi, I was able to find executable file that contains Colorizer and IScanner classes. It is named vcpkg.dll and located in /Microsoft Visual Studio 8/VC/vcpackages. (I'm using Visual C++ 2005 Express Edition, things may be different in other versions.)
The vcpkg.dll contains null-terminated UTF-16 encoded strings. I've opened it with hex editor, and searched for "array". There is only one such string in the file, so I've replaced it with "arrry". (It is important to maintain relative alphabetical order with respect to other keywords.) Then I've searched for "event", it shows up in several places, but there is only one that isn't part of some longer string, so I've replaced this one with "evvvt". After starting Visual Studio, it turned out that "array" and "event" weren't any longer highlighted, but "arrry" and "evvvt" were!
Of course this is an ugly hack, and it will void your warranty,
and probably goes against Microsoft EULA, but what a relief for the eyes!
Anyway, if you want to do it, be careful and remember to backup the file.
It doesn't look like a disable-syntax-coloring feature is exposed in a user-friendly way.
The only way I can think of selectively disabling syntax coloring is to create a new syntax coloring plugin for the IDE, and list all of the keywords you want colored. Microsoft gives information in this article on how to accomplish this task.
The drawback to this approach is that your IDE will now have two C++ languages and I'm not sure how it will select which plug-in to choose from once it loads a .h or .cpp file. However, this article suggests that you can override the existing C++ plug-ins by rewriting some registry keys.
I think the only "semi-practical" way to accomplish this to create a Visual Studio package that uses Text Markers to selectively cover up the keywords you don't want colored. Even that is not a little one-day task. Edit: Probably not even a full week task for someone not intricately familiar with the Visual Studio API and all its quirks, especially not getting it bug-free.
In other words, you probably want to just ignore them.