Giter Club home page Giter Club logo

structlayout's Introduction

StructLayout

Visual Studio Extension for C++ struct memory layout visualization

MarketPlace2022 MarketPlace Donate

Download latest from the Visual Studio Marketplace 2022

Download latest from the Visual Studio Marketplace 2017/2019

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 can use different systems to parse the C++ files and extract the memory layout information. Depending on the complexity and quirks of the build system and Visual Studio setup one option will be more convinent than the others. The method used can be changed in the Extension Options Window

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

  • Retrieve the active document and cursor position.
  • Extract the relevant project context.
  • Add/Override any extra parameters from the extension options.
  • Trigger the selected LayoutParser with all the arguments gathered.
  • Visualize the results or print any issues found in the StructLayout Output Pane.

Clang Libtooling

This method will process the file location through a Clang LibTooling executable which will parse the current file and headers. This method can give really accurate results as it retrieves the data directly from the Clang AST but it will need the exact build context to be able to properly understand all the code.

When a query to the clang libtooling is triggered the extension will try to gather the following data from the active project and configuration:

  1. Include directories
  2. Force includes
  3. Preprocessor definitions
  4. Exclude directories

PDB

This method takes advantage of the fact that the pdb (Program DataBase) will most likely contain all the layout information for all user defined types. This application uses the DIA SDK (Debug Interface Access) to open and query the pdb. This system can be useful if our setup is not ready to be compiled with a Clang compiler, the build system is quite complex hitting some corner cases or we have some MSVC specific code. The caveat is that we would need to compile the projects before performing any queries keeping the pdbs up to date.

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

structlayout's People

Contributors

marcaudy avatar nedwardsnae avatar viladoman avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.