Visual Studio Extension for C++ struct memory layout visualization

Overview

StructLayout

Visual Studio Extension for C++ struct memory layout visualization

MarketPlace Donate

Download latest from the Visual Studio Marketplace

Motivation

In C++, the structure layout can be affected by different factors. In order to produce performant data cache oriented code or reduce the structure memory footprint, it is important to be aware of the class layouts at the same spot where code is created, updated, removed or debugged. This extension allows programmers to visualize their structures within Visual Studio with just 1 click.

Features

Right click on top of any C++ struct definition and select Show Struct Layout (or press Alt+L) in order to visualize the memory layout.

Interaction

Stack Mode

In this visualization mode the types with children are stacked in order to allow navigation in and out and get a better sense of overall structure.

Stack screenshot

Flat Mode

The flat mode skips all groups and only shows one layer, producing a more compact view.

Flat screenshot

How it works

Struct Layout uses Clang LibTooling internally to parse the C++ files and extract the memory layout information.

When a Layout request is made the extension does the following:

  • Retrieve the active document and cursor position.
  • Extract the relevant file and project properties (cl or nmake).
    1. Include directories
    2. Force includes
    3. Preprocessor definitions
    4. Exclude directories
  • Add the extra parameters from the extension options.
  • Trigger the LayoutParser (Clang libtooling application) with all the arguments gathered.
  • Visualize the results or print any issues found in the StructLayout Output Pane.

Documentation

References

Contributing

This project is open to code contributions.

If you found this extension useful you can always buy me a cup coffee.

paypal

Issues
  • Immediate VS crash on button press

    Immediate VS crash on button press

    In one (but not all) of my projects, the entire Studio immediately crashes half a second or so after I click the "show struct layout" Button. No error messages or anything.

    When I run the studio with devenv /log, the last two log entries are:

      <entry>
        <record>728</record>
        <time>2020/10/31 06:30:09.126</time>
        <type>Warning</type>
        <source>GlobalBrokeredServiceContainer</source>
        <description>Request for &quot;Microsoft.VisualStudio.Shell.Internal.SettingsManager (1.0)&quot; from Process denied because the service is only exposed RemoteExclusiveClient, LiveShareGuest.</description>
      </entry>
      <entry>
        <record>729</record>
        <time>2020/10/31 06:30:09.126</time>
        <type>Warning</type>
        <source>GlobalBrokeredServiceContainer</source>
        <description>Request for proxy to &quot;Microsoft.VisualStudio.Shell.Internal.SettingsManager (1.0)&quot; is declined: ServiceAudienceMismatch.</description>
      </entry>
    </activity>
    

    Any other kind of log I could post to help?

    bug 
    opened by s9w 18
  • [ERROR] Unable to scan the given location.

    [ERROR] Unable to scan the given location.

    running 0.2.1 (0.2.0 also didn't work):

    struct.h:13:10: fatal error: 'Base Project'\NA-Project Constants.h' file not found #include "Base Project\NA-Project Constants.h" ^~~~~~~~~~~~~~~~~~~~~~~ 1 error generated. Error while processing C:\Users\Eric\source\Proj\NA-Project\VS\VerXXXXXX\MsgHdrs\struct.h. [ERROR] Unable to scan the given location. (394.0328 ms)

    no configuration file was generated so I can't attempt to include additional paths. My Additional Include Directories is set as "$(ProjectDir);$(SolutionDir);%(AdditionalIncludeDirectories)"

    bug 
    opened by ericthobbs 9
  • Not working with cmake projects

    Not working with cmake projects

    Hi. This is a really useful tool. Will save me a lot of time and it's convenient.

    I tested it out with a few cmake projects opened with VS. Get this error in my output:

    [14:22:23] [ERROR] Unable to retrieve the project configuration
    

    Regenerating the cmake cache and restarting VS don't fix this so I assume it relies on data from VS projects. Also tried creating a new cmake project, same error. It works on the normal VS projects I tested it on. I could paste my structs/classes into a normal VS project and check them there but that'd remove some of the convenience.

    enhancement 
    opened by Moneyl 8
  • Error dialog -

    Error dialog - "Unable to retrieve the project configuration"

    I just installed this VisualStudio extension, and consistently get the dialog box error, making the extension unusable. This is a standard C++ VS project, and it definitely has a valid project configuration.

    opened by Pnyxor 6
  • Not working with std::string_view

    Not working with std::string_view

    code: #include <string_view>

    void f() { std::string_view name, prefix, suffix; }

    struct MyStruct { int x, y, z; };

    output: [19:23:57] Looking for structures at D:\C++\Testing\TestCode\TestCode\src\struct_layout.cpp:8:11... [19:23:57] COMMAND LINE: D:\C++\Testing\TestCode\TestCode\src\struct_layout.cpp -- -x c++ -m64 -w -DFORCE_STATIC_VCRT -D_MBCS -ID:\C++\Testing\TestCode\TestCode\SDL\ -ID:\C++\Testing\TestCode\TestCode\include [19:23:57] Execution Log: D:\C++\Testing\TestCode\TestCode\src\struct_layout.cpp:5:7: error: no type named 'string_view' in namespace 'std' std::string_view name, prefix, suffix; ~~~~~^ 1 error generated. Error while processing D:\C++\Testing\TestCode\TestCode\src\struct_layout.cpp.

    [19:23:57] [ERROR] Unable to scan the given location. (37.0765 ms)

    bug 
    opened by RisingLiberty 6
  • Error parsing intrin.h, included by other standard headers

    Error parsing intrin.h, included by other standard headers

    I've recently started getting this issue on any data structure that I try seeing the layout of:

    [12:02:59] Capturing configuration from VS projects...
    [12:02:59] Looking for structures at C:\dev\halley\src\engine\utils\include\halley\data_structures\maybe.h:17:14...
    [12:02:59] COMMAND LINE: C:\dev\halley\src\engine\utils\include\halley\data_structures\maybe.h -- -x c++ -m64 -std=c++17 -w -DWIN32 -D_WINDOWS -D_ENABLE_EXTENDED_ALIGNED_STORAGE -DGSL_THROW_ON_CONTRACT_VIOLATION -DDEV_BUILD -D_WIN32_WINNT=0x0601 -DWINVER=0x0601 -D_SILENCE_ALL_CXX17_DEPRECATION_WARNINGS -DWITH_SDL2 -DBOOST_ALL_NO_LIB -DBOOST_CONFIG_SUPPRESS_OUTDATED_MESSAGE -DWITH_OPENGL -DWITH_ASIO -DWITH_DX11 -DWITH_MEDIA_FOUNDATION -DCMAKE_INTDIR=\"Debug\" -IC:\dev\halley\src\contrib -IC:\dev\halley\src\engine\utils\include -IC:\dev\halley\src\engine\utils\..\core\include -IC:\dev\halley\src\engine\utils\..\..\contrib\yaml-cpp\include -IC:\dev\halley_deps\Boost\include\boost-1_72 -working-directory=C:\dev\build\halley\src\engine\utils -std=c++17
    [12:02:59] Execution Log:
    In file included from C:\dev\halley\src\engine\utils\include\halley\data_structures\maybe.h:3:
    In file included from C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.28.29333\include\optional:18:
    In file included from C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.28.29333\include\xmemory:13:
    In file included from C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.28.29333\include\limits:14:
    In file included from C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.28.29333\include\intrin0.h:18:
    C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.28.29333\include\intrin.h:56:1: error: expected function body after function declarator
    __MACHINE(void * _AddressOfReturnAddress(void))
    ^
    1 error generated.
    Error while processing C:\dev\halley\src\engine\utils\include\halley\data_structures\maybe.h.
    
    [12:02:59] [ERROR] Unable to scan the given location. (241.0200 ms)
    

    It seems that pretty much any standard header eventually includes intrin.h, which causes that issue.

    The extension used to work fine on this project, so it was either a recent update or updating Visual Studio to 16.8.2 (sorry, those two things happened at the same time, not sure who's at fault).

    opened by amzeratul 5
  • No structure found at the given location.

    No structure found at the given location.

    In VS 2019 16.2.0

    I get the following error at Last l{};:

    [10:56:29] Looking for structures at C:\Users\Source\Repos\StructLayout\StructLayout\StructLayout.cpp:24:7... [10:56:29] COMMAND LINE: C:\Users\Source\Repos\StructLayout\StructLayout\StructLayout.cpp -- -x c++ -m32 -w -DWIN32 -D_DEBUG -D_CONSOLE -working-directory=C:\Users\Source\Repos\StructLayout\StructLayout [10:56:31] No structure found at the given location. (1.0630 s)

    Note: This message is printed in Output. It would be nice to have some other popup or way to report that nothing happened. As I didn't notice the Output I thought that the extension failed.

    Is VS 2019 16.2.0 adequate for this extension?

    #include <iostream>
    #include <string>
    
    struct Base {
    	int i;
    };
    
    struct Derived: Base {
    
    	int i;
    	bool c;
    	Base b;
    };
    
    struct Last : Derived {
    	std::string c;
    };
    
    int main()
    {
    	Last l{};
        std::cout << "Hello World!\n" << l.c << std::endl;
    }
    
    enhancement 
    opened by Zingam 5
  • Strange errors about missing include files that aren't missing

    Strange errors about missing include files that aren't missing

    As a simple example I am trying your Visual Studio TestProject sample. I can layout Base from TestHeader.h without errors, but if I try TestStruct from TestProject.cpp I get error:

    [04:57:01] Using manual configuration... [04:57:01] Looking for structures at H:\temp\StructLayout\TestProjects\Regular\TestProject.cpp:7:16... [04:57:01] COMMAND LINE: H:\temp\StructLayout\TestProjects\Regular\TestProject.cpp -- -x c++ -m64 [04:57:01] Execution Log: H:\temp\StructLayout\TestProjects\Regular\TestProject.cpp:1:10: fatal error: 'cstdio' file not found #include ^~~~~~~~ 1 error generated. Error while processing H:\temp\StructLayout\TestProjects\Regular\TestProject.cpp.

    [04:57:01] [ERROR] Unable to scan the given location. (313.0954 ms)

    but when I compile the project there are no errors and I can open cstdio without a problem.

    If I force include cstdio then it complains about another header and if that one is forced then another and another ad infinitum. Has anybody ran into a similar situation? The truth is that I am getting a similar error in a more complex project but the symptoms are the same.

    I have tried other options, and visual studio settings but nothing helps. None of the current issues seem similar (at least that's the impression I get and i have read them all). Does anybody have any suggestions or things I may try to find the source of my problem? Anything would be greatly appreciated as this extension can be very useful but I am totally stumped.

    I realize that the problem is with my system as nobody else seems to talk about it but other than this extension I have no problems with visual studio (2019). Thank you.

    Paxcut

    opened by paxcut 4
  • Not working with relative include paths and full include paths that contain whitespaces

    Not working with relative include paths and full include paths that contain whitespaces

    Repro 1- Create an empty project with a source file 2- Add a relative path in C/C++ -> Additional Include Directories 3- Include a file from this directory in your source file 4- Define a random struct after 5- Ensure it compiles 6- Run Show Struct Layout on the struct

    Result fatal error: 'included_file.h' file not found

    The same result arises when there's a whitespace in a full include path. That's because include paths passed to Clang with -I don't seem to be delimited with "".

    bug 
    opened by jpanneton 4
  • MS-style inline assembly is not available. Unable to find target for this triple (no targets are registered).

    MS-style inline assembly is not available. Unable to find target for this triple (no targets are registered).

    When I right click on class name and press Show Struct Layout I get this error: MS-style inline assembly is not available. Unable to find target for this triple (no targets are registered). https://imgur.com/Of08Imx Can you please fix this?

    bug 
    opened by pavledev 3
  • Support for Visual Studio Property Sheet

    Support for Visual Studio Property Sheet

    Automatic extraction of include dirs are not working if those include dirs are coming from a Property Sheet. In my project I use Property Sheets to configure include dirs/linkers dirs and so on, to avoid having to define them for every project. However the automatic extraction process is not working correctly

    enhancement 
    opened by Alekssasho 3
  • Troublesome unions with PDB extraction

    Troublesome unions with PDB extraction

    [Visual Studio Community 2022 v17.1.5 / Struct Layout v0.6.0, PDB extraction]

    I don't think this is correct. image

    It is impossible to interact with struct C when an array is introduced. image

    It works fine with Clang extraction, but I'm running into some troubles with it not parsing my #includes properly.

    bug 
    opened by PersonMedBrukernavn 2
  • support MSVC toolset option for side-by-side toolset installations

    support MSVC toolset option for side-by-side toolset installations

    Struct Layout compilation uses incorrect version of MSVC++ toolchain when the system has multiple VS installations, and/or multiple toolchain installed side-by-side on a single VS instance, and a given project is configured to select a specific version.

    Here is the project configuration snapshot where this setting is made:

    image

    To reproduce, install a secondary (older) version of C++ toolchain using the VS Installer (locate one under individual component install). Configure a sample project to use this older version. Struct Layout will insist on using the latest version available, instead of the one specified by the project.

    On non-trivial codes, this causes compiler errors because the code may not be compatible with the new toolchain versions (hence the official support for such per-project selection and side-by-side paradigm by VS). To reproduce this scenario artificially, add the following preprocessor condition in code:

    For example,

    #if _MSC_VER > 1927
    #error "unsupported compiler
    #endif
    

    where 19.27 corresponds to v14.27 of the MSVC toolchain:

    image

    bug 
    opened by slymz 1
  • Include file not found

    Include file not found

    I keep getting "File not found" no matter if I explicitly include the file in settings or not. the message reads

    In the file included from x:\xxx\xxxtypes.h:3:
    x:\xxx\xxxconstants.h:3:10 fatal error: 'ultra64.h' file not found
    #include <ultra64.h>
         ^~~~~~~~
    1 error generated.
    error while processing x:\xxx\xxxtypes.h.
    

    I have explicitly included ultra64.h in the settings dialog but it still complains.

    opened by Trevor89 4
  • MSVC Support for /d1reportSingleClassLayoutXXX

    MSVC Support for /d1reportSingleClassLayoutXXX

    I've been unable to get StructLayout to compile so far, due to differences between Clang/MSVC. For MSVC, there is a flag to CL.exe, /d1reportSingleClassLayoutX that reports struct layout (where X is the name of a class, such as /d1reportSingleClassLayoutMyClassName ).

    Having an option to use this to get the struct data, and then display it in StructLayout's window, may be a helpful alternative for others to set up this add-in as well. Though I am not sure what Clang's AST provides that may be missing with this approach.

    enhancement 
    opened by skarolewics 1
  • Do not work if project path contains æøå.

    Do not work if project path contains æøå.

    When I run this on my project I get the following output: image

    As you can see my username is Grønbech, which somehow manages to break your code. I have tested on a project that was stored on a path with no special symbols and it works fine.

    bug 
    opened by Groenbech96 2
Releases(v0.6.0)
Owner
Ramon Viladomat
A game programmer trying to make the 'Hello World!' a better place.
Ramon Viladomat
The Hoard Memory Allocator: A Fast, Scalable, and Memory-efficient Malloc for Linux, Windows, and Mac.

The Hoard Memory Allocator Copyright (C) 1998-2020 by Emery Berger The Hoard memory allocator is a fast, scalable, and memory-efficient memory allocat

Emery Berger 882 May 13, 2022
Custom memory allocators in C++ to improve the performance of dynamic memory allocation

Table of Contents Introduction Build instructions What's wrong with Malloc? Custom allocators Linear Allocator Stack Allocator Pool Allocator Free lis

Mariano Trebino 1.2k May 9, 2022
MMCTX (Memory Management ConTeXualizer), is a tiny (< 300 lines), single header C99 library that allows for easier memory management by implementing contexts that remember allocations for you and provide freeall()-like functionality.

MMCTX (Memory Management ConTeXualizer), is a tiny (< 300 lines), single header C99 library that allows for easier memory management by implementing contexts that remember allocations for you and provide freeall()-like functionality.

A.P. Jo. 4 Oct 2, 2021
Memory-dumper - A tool for dumping files from processes memory

What is memory-dumper memory-dumper is a tool for dumping files from process's memory. The main purpose is to find patterns inside the process's memor

Alexander Nestorov 29 Feb 5, 2022
Mesh - A memory allocator that automatically reduces the memory footprint of C/C++ applications.

Mesh: Compacting Memory Management for C/C++ Mesh is a drop in replacement for malloc(3) that can transparently recover from memory fragmentation with

PLASMA @ UMass 1.4k May 7, 2022
STL compatible C++ memory allocator library using a new RawAllocator concept that is similar to an Allocator but easier to use and write.

memory The C++ STL allocator model has various flaws. For example, they are fixed to a certain type, because they are almost necessarily required to b

Jonathan Müller 1.1k May 9, 2022
Public domain cross platform lock free thread caching 16-byte aligned memory allocator implemented in C

rpmalloc - General Purpose Memory Allocator This library provides a public domain cross platform lock free thread caching 16-byte aligned memory alloc

Mattias Jansson 1.5k May 10, 2022
OpenXenium JTAG and Flash Memory programmer

OpenXenium JTAG and Flash Memory programmer * Read: "Home Brew" on ORIGINAL XBOX - a detailed article on why and how * The tools in this repo will all

Koos du Preez 25 Feb 14, 2022
manually map driver for a signed driver memory space

smap manually map driver for a signed driver memory space credits https://github.com/btbd/umap tested system Windows 10 Education 20H2 UEFI installati

ekknod 71 Apr 9, 2022
Memory instrumentation tool for android app&game developers.

Overview LoliProfiler is a C/C++ memory profiling tool for Android games and applications. LoliProfiler supports profiling debuggable applications out

Tencent 416 May 13, 2022
A single file drop-in memory leak tracking solution for C++ on Windows

MemLeakTracker A single file drop-in memory leak tracking solution for C++ on Windows This small piece of code allows for global memory leak tracking

null 22 Apr 23, 2022
Dump the memory of a PPL with a userland exploit

PPLdump This tool implements a userland exploit that was initially discussed by James Forshaw (a.k.a. @tiraniddo) - in this blog post - for dumping th

Clément Labro 546 May 14, 2022
Implementation of System V shared memory (a type of inter process communication) in xv6 operating system.

NOTE: we have stopped maintaining the x86 version of xv6, and switched our efforts to the RISC-V version (https://github.com/mit-pdos/xv6-riscv.git)

Viraj Jadhav 5 Feb 21, 2022
An In-memory Embedding of CPython

An In-memory Embedding of CPython This repository contains all the build artifacts necessary to build an embedding of CPython 3.8.2 that can be run en

null 100 Apr 26, 2022
Execute MachO binaries in memory using CGo

Execute Thin Mach-O Binaries in Memory This is a CGo implementation of the initial technique put forward by Stephanie Archibald in her blog, Running E

Dwight Hohnstein 55 Apr 15, 2022
Initialize the 8-bit computer memory with a program to be executed automatically on powering.

Initialize the 8-bit computer memory with a program to be executed automatically on powering. This project is small extension of Ben Eater's computer

Dmytro Striletskyi 62 Dec 13, 2021
Artifacts of that Memory Management Tsoding Session

Artifacts of those Memory Management Tsoding Sessions Quick Start $ make $ ./heap Limitations The pointers to the heap can only be located in the heap

Tsoding 51 May 15, 2022
PoC for CVE-2021-32537: an out-of-bounds memory access that leads to pool corruption in the Windows kernel.

CVE-2021-32537: Out-of-bounds access in RTKVHD64 leading to pool corruption. This is a bug that I reported to Realtek beginning of April 2021. The aff

Axel Souchet 55 Feb 14, 2022
A simple windows driver that can read and write to process memory from kernel mode

ReadWriteProcessMemoryDriver A simple windows driver that can read and write to process memory from kernel mode This was just a small project for me t

Hypervisor 6 Mar 30, 2022