Debugger visualizers in Visual Sudio 11 Developer Preview

Visual Studio 11 Developer Preview introduces new style debugger visualizers. The autoexp.dat definition of templates in previous versions of the Visual Studio debugger is being replaced with new style definitions based on XML and stored in defaultvis.natvis file.

Microsoft explains the motivation behind redesigning the native type visualization mechanism is to give better diagnostic reporting (visualizer expressions can be now evaluated and displayed in the output window to help debugging .natvis file), provide XSD schema defining type definition, support of multiple files for type definition: system-wide in %ProgramFiles%\Microsoft Visual Studio 11.0\Common7\Packages\Debugger\Visualizers\defaultvis.natvis and user-defined in %USERPROFILE%\My Documents\Visual Studio Dev11\Visualizers\xxx.natvis.

It sounds really good and has a great usability potential for programmers who uses C++ generative programming capabilities, defines complex C++ types, heavily uses C++ Standard Library and Boost C++ Libraries.

Here is example of new style visualizer defined in XML copied from the defaultvis.natvis:

  <!--std::unique_ptr from <memory>-->
  <Type Name="std::unique_ptr<*>">
    <DisplayString Condition="_Myptr == 0">empty</DisplayString>
    <DisplayString>unique_ptr {*_Myptr}</DisplayString>
    <Expand>
      <Item Name="[ptr]" Condition="_Myptr != 0">_Myptr</Item>
    </Expand>
  </Type>

For most types from C++ Standard Library and Windows SDK, the new visualizers work very well. However, the currently available Visual Studio 11 Developer Preview (Version 11.0.40825.2 PREREL) is shipped with incorrect definitions in the defaultvis.natvis. The C++TR1 definitions introduced in Visual Studio 2008 are only forwarded (aliased) from std:tr1:: to std:: in Visual Studio 2010. In Visual Studio 11, they have completely moved from std::tr1:: to std:: to align with C++11 standard. But, the new visualizers in defaultvis.natvis define templates are still referring to the C++11 types in std::tr1:: namespace.

This prevents the correct visualization for types like std::shared_ptr:

vs11-visualizers-broken-2

There is an easy workaround possible:

  1. Make private copy of defaultvis.natvis in %USERPROFILE%\My Documents\Visual Studio Dev11\Visualizers\xxx.natvis where xxx is your preferred name.
  2. Open xxx.natvis in a text editor.
  3. Find std::tr1:: and replace with std::.
  4. Save the changes and relaunch the Visual Studio 11.
  5. You should see objects of the C++11 types correctly visualized.

vs11-visualizers-fixed-3

I have reported this issue to Microsoft Connect in Incorrect Type Name references in defaultvis.natvis visualizers for standard library ticket.

File version is not supported by the launcher

UPDATE: This bug (see below) has been fixed a few days ago. The fix is available in CMake git repo and should be release in the upcoming CMake 2.8.7 release.

What is the difference between these two Visual Studio solution (.sln) files?

vs11-cmake-sln-version-compare

They both have been generated using CMake 2.8.6. However, having Visual Studio 11 Developer Preview installed, every time I try to launch the Hello2011.sln I’m getting mysterious error message: File version is not supported by the launcher.

Quick look at what CMake actually outputs in to .sln confirms there is a bug. CMake generates .sln file signature which does not match release version/name of the Visual Studio 11. In Hello2011.sln CMake generated:

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 2011

but correct version of the output, fixed in Hello11.sln, is this:

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 11

Bug report submitted to CMake developers.

By the way, I have to admit different icons displayed for correct and incorrect .sln file are quite useful.

FindBoost.cmake patched for Visual Studio 11

My patch updating CMake module FindBoost.cmake for Boost C++ Libraries lookup has been accepted and committed to the CMake Git repository. Thanks to Brad King for quick review.

The patch adds most recent versions of Boost 1.47 and 1.48 to the lookup table and uses correct toolset tag vc110 (see Library Naming) when checking for libraries built using Visual Studio 11.

OSGeo Charter Nomination for Martin Daly

This month, OSGeo Foundation is conducting annual election of new OSGeo Charter Members.

I have nominated Martin Daly (CTO of Cadcorp) for Charter Member of the OSGeo Foundation.

Martin has long-standing experience in development of geospatial software and development, and adoption of open standards for geospatial under his belt.

Martin has used and supported numerous open source software projects. Martin led Cadcorp to offer first implementation of PostGIS by a GIS vendor, to become a GDAL/OGR Silver Sponsor, to contribute funds and time of Cadcorp development team to make the wheels of PostGIS Raster project (aka WKT Raster) spinning. Improvements in PostgreSQL are also on not-a-short list of contributions to the Free and Open Source Software projects, as is GEOS.

Martin was one of the original members of the OGC Architecture Board (OAB). He was also the main author of the OpenGIS Coordinate Transformation Services Specification as well as participated in developing several other OpenGIS specifications. Martin is one of authors of the GeoJSON Format Specification and actively participates in future development of GeoJSON.

Martin is a member of the Advisory Board of the Open Source Geospatial Lab (OSGL) at the University of Nottingham Centre for Geospatial Science.

Martin also participates and leads Cadcorp involvement in the annual FOSS4G WMS Benchmark.

I believe Martin Daly’s experience and contributions make him a valuable candidate for the OSGeo Charter Member.

New SOCI Project Leader needed

Maciej Sobczak, current leader of SOCI project has just announced on soci-users mailing list that he is looking for a volunteer willing to take over the project leadership. For someone, who would like to take over the project management responsibilities and has a good understanding of the subject as well as a solid vision of what to do with the project in the future.

SOCI is a database access library for C++ that makes the illusion of embedding SQL queries in the regular C++ code, staying entirely within the Standard C++.

Building Boost with Visual Studio 11 Developer Preview

Yesterday, I installed Visual Studio 11 Developer Preview. The new release is available for free and is usable for free until June 2012, so it’s a great opportunity to try and learn what Microsoft has to offer for C++ programmers. And, it looks it offers a lot, including SCARY features.

The first test I usually do when it comes to test a new C++ toolset is to build Boost C++ Libraries using mainstream development sources.

The Boost simply builds well. I have even configured build of Boost.Python using Python version 3.2.

There are no hacks required to make the build happen. Simply, follow Boost Getting Started on Windows, section 5.3. Or, Build Binaries From Source. Once the Boost.Build tools bootstrapped, I issued the following command:

b2 --toolset=msvc variant=debug runtime-link=shared threading=multi define=_CRT_NONSTDC_NO_DEPRECATE define=_CRT_SECURE_NO_DEPRECATE define=_SCL_SECURE_NO_DEPRECATE stage

Fifteen minutes later, the Boost build was ready and staged.

By the way, some time ago Christian Henning posted a quick cheat sheet of bjam commands for Visual Studio. It’s very handy.

shared_ptr almost like intrusive_ptr

The current C++11 Standard consists of a very important remark in section 20.9.11.2.6. It is about creation of shared_ptr object. The remarks state:

Implementations are encouraged, but not required, to perform no more than one memory allocation.
[Note: this provides efficiency equivalent to an intrusive smart pointer. end note]

At work [1], I use Visual C++ 2010+ implementation of C++. I couldn’t resist myself to check if the standard managed to encourage Stephan T. Lavavej (STL) and his team at Microsoft to go for this optimisation.

I compiled and run a quick test:


#include <memory>
int main()
{
    std::shared_ptr<int> p0(
       new int(3)); // #1

    std::shared_ptr<int> p1
        = std::make_shared<int>(3); // #2
    return 0;
}

Quick check using breakpoints confirmed that Visual C++ 2010 indeed optimises construction of the shared_ptr. The difference between #1 and #2 is an important one: the second version causes 50% less memory allocations than the first one. Namely, one allocation. std::make_shared packs bookkeeping data and the user-defined data into a single block of memory.

Know your tools or suffer fragmented.

GCC At Home

I couldn’t leave a blog post alone without some kind of unrelated off-topic and pointless digression. So, here is one: Stephan T. Lavavej on his homepage provides custom-built distribution of MinGW toolset with What MinGW Is section starting as follows:

I recommend that anyone who is learning Standard C++ and who uses Windows for a primary development environment should use two compilers: the most modern version of Microsoft Visual C++ (currently 2010 SP1) and the most modern version of GCC, the GNU Compiler Collection.

Stephan works at Microsoft. I admire this kind of professionalism free from strategically competitive marketing b******t. GCC should definitely be included in the list of New Seven Wonders of the World. Recently, a new wonder has emerged: LLVM/Clang. I’m a user of all the three compilers (and related toolsets). It is easy for me to dream about Visual C++Visual Studio IDE based on LLVM/Clang as C++ compiler and shipped with C/C++ standard libraries provided by GCC. That would be a real C++ Renaissance