Visualize Macro Expansion for C++

Mryam Girmay

We are excited to announce the availability of Visualize Macro Expansion in Visual Studio 17.7 Preview. This feature lets you visualize the step-by-step expansion of macros. To begin utilizing this feature, ensure that you update to the latest version of Visual Studio Preview.

Visualize Macro Expansion

Visual Studio has introduced an enhanced Macro Expansion feature. This feature brings significant benefits, enabling you to comprehend and review complex multi-level macro expansions in a step-by-step manner. When you hover over a macro, you can access Quick Info, which now includes the Visualize Expansion link in addition to the Copy and Expand Inline options. The Visual Expansion will enable you to visualize the preprocessor passes of the expansion.

Image of Visualize Expansion.
Image of Visualize Expansion.

The Visual Expansion link opens a new window that initially displays the first step of macro expansion. By utilizing the arrows next to the expansion step numbers, you can easily navigate through the subsequent steps of the expansion. This feature proves especially valuable in scenarios involving nested macros with lengthy expansions. In cases where nested macros have long expansions, this feature will help to precisely identify the actions taking place at each step, facilitating a deeper understanding of the macro’s behavior. Ultimately, this feature greatly enhances the efficiency of your debugging efforts, enabling you to pinpoint and resolve issues more effectively.  

 Gif for visualizing macro expansion process. 
Gif for visualizing macro expansion process.

Send us your feedback!

Download the latest version of Visual Studio Preview, and try out Visualize Macro ExpansionWe would love to hear your thoughts, so please share your feedback in the comments below, on Developer Community, or reach out to us on Twitter (@VisualC) or via email at visualcpp@microsoft.com. Your input is highly appreciated! 

 

 

 

 

 

8 comments

Discussion is closed. Login to edit/delete existing comments.

  • David Lowndes 1

    If I hover over a Windows SUCCEEDED macro, invoke the visualization for it, then click the right pointing blue arrow, it kills VS:
    Application: devenv.exe
    Framework Version: v4.0.30319
    Description: The process was terminated due to an unhandled exception.
    Exception Info: System.ArgumentOutOfRangeException
    at System.ThrowHelper.ThrowArgumentOutOfRangeException(System.ExceptionArgument, System.ExceptionResource)
    at System.Collections.Generic.List`1[[System.__Canon, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]].get_Item(Int32)
    at Microsoft.VisualStudio.VC.MacroExpansionView.Forwards_Click(System.Object, System.Windows.RoutedEventArgs)
    at System.Windows.EventRoute.InvokeHandlersImpl(System.Object, System.Windows.RoutedEventArgs, Boolean)
    at System.Windows.UIElement.RaiseEventImpl(System.Windows.DependencyObject, System.Windows.RoutedEventArgs)
    at System.Windows.Controls.Primitives.ButtonBase.OnClick()
    at System.Windows.Controls.Button.OnClick()
    at System.Windows.Controls.Primitives.ButtonBase.OnMouseLeftButtonUp(System.Windows.Input.MouseButtonEventArgs)
    at System.Windows.RoutedEventArgs.InvokeHandler(System.Delegate, System.Object)
    at System.Windows.RoutedEventHandlerInfo.InvokeHandler(System.Object, System.Windows.RoutedEventArgs)
    at System.Windows.EventRoute.InvokeHandlersImpl(System.Object, System.Windows.RoutedEventArgs, Boolean)
    at System.Windows.UIElement.ReRaiseEventAs(System.Windows.DependencyObject, System.Windows.RoutedEventArgs, System.Windows.RoutedEvent)
    at System.Windows.UIElement.OnMouseUpThunk(System.Object, System.Windows.Input.MouseButtonEventArgs)
    at System.Windows.RoutedEventArgs.InvokeHandler(System.Delegate, System.Object)
    at System.Windows.RoutedEventHandlerInfo.InvokeHandler(System.Object, System.Windows.RoutedEventArgs)
    at System.Windows.EventRoute.InvokeHandlersImpl(System.Object, System.Windows.RoutedEventArgs, Boolean)
    at System.Windows.UIElement.RaiseEventImpl(System.Windows.DependencyObject, System.Windows.RoutedEventArgs)
    at System.Windows.UIElement.RaiseTrustedEvent(System.Windows.RoutedEventArgs)
    at System.Windows.Input.InputManager.ProcessStagingArea()
    at System.Windows.Input.InputManager.ProcessInput(System.Windows.Input.InputEventArgs)
    at System.Windows.Input.InputProviderSite.ReportInput(System.Windows.Input.InputReport)
    at System.Windows.Interop.HwndMouseInputProvider.ReportInput(IntPtr, System.Windows.Input.InputMode, Int32, System.Windows.Input.RawMouseActions, Int32, Int32, Int32)
    at System.Windows.Interop.HwndMouseInputProvider.FilterMessage(IntPtr, MS.Internal.Interop.WindowMessage, IntPtr, IntPtr, Boolean ByRef)
    at System.Windows.Interop.HwndSource.InputFilterMessage(IntPtr, Int32, IntPtr, IntPtr, Boolean ByRef)
    at MS.Win32.HwndWrapper.WndProc(IntPtr, Int32, IntPtr, IntPtr, Boolean ByRef)
    at MS.Win32.HwndSubclass.DispatcherCallbackOperation(System.Object)
    at System.Windows.Threading.ExceptionWrapper.InternalRealCall(System.Delegate, System.Object, Int32)
    at System.Windows.Threading.ExceptionWrapper.TryCatchWhen(System.Object, System.Delegate, System.Object, Int32, System.Delegate)
    at System.Windows.Threading.Dispatcher.LegacyInvokeImpl(System.Windows.Threading.DispatcherPriority, System.TimeSpan, System.Delegate, System.Object, Int32)
    at MS.Win32.HwndSubclass.SubclassWndProc(IntPtr, Int32, IntPtr, IntPtr)

  • Georgi Hadzhigeorgiev 3

    That’s a very nice feature, Mryam!

  • Lauri Vasama 0

    The font should probably be changed to use a monospace one by default. Perhaps the same font as the code editor.

Feedback usabilla icon