{"id":7271,"date":"2015-12-07T14:52:00","date_gmt":"2015-12-07T14:52:00","guid":{"rendered":"https:\/\/blogs.msdn.microsoft.com\/vcblog\/2015\/12\/07\/using-visual-studio-2015-to-debug-an-android-app-built-with-marmalade\/"},"modified":"2021-10-05T14:31:52","modified_gmt":"2021-10-05T14:31:52","slug":"using-visual-studio-2015-to-debug-an-android-app-built-with-marmalade","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/cppblog\/using-visual-studio-2015-to-debug-an-android-app-built-with-marmalade\/","title":{"rendered":"Using Visual Studio 2015 to debug an Android app built with Marmalade"},"content":{"rendered":"<p class=\"Normal1\"><em><span lang=\"EN-GB\">For this blog post, we welcome Alex Baude of <a href=\"https:\/\/www.madewithmarmalade.com\/\">Marmalade<\/a> (<a href=\"https:\/\/www.madewithmarmalade.com\/\">https:\/\/www.madewithmarmalade.com<\/a>) as a guest author on our blog. His team&rsquo;s most recent release of <a href=\"https:\/\/www.madewithmarmalade.com\/blog\/new-marmalade-platform-release\">Marmalade Platform<\/a> now supports Visual Studio 2015 and we invited him to tell us more about their work on this.<\/span><\/em><\/p>\n<p class=\"Normal1\"><span lang=\"EN-GB\">Visual Studio 2015 provides new cross-platform native development technology for building and debugging cross-platform C++ code on the Android platform. Out-of-the-box, Visual Studio 2015 offers templates based on the Android Native-Activity to quickly create high-performance applications.<\/span><\/p>\n<p class=\"Normal1\"><span lang=\"EN-GB\">The Marmalade Platform includes a cross-platform C++ SDK, Marmalade Core, a key feature of which is a platform abstraction API, hiding much of the complexity of the native platforms and allowing the developer to write code once and deploy to many targets. C++ based Marmalade Core apps can be deployed to iOS, Android, NaCL, Windows Phone, and Windows 10, to name a few.<\/span><\/p>\n<p class=\"Normal1\"><span lang=\"EN-GB\">And now, with our latest SDK release, by leveraging the new cross-platform features of Visual Studio 2015, native debugging of Marmalade Core apps running on either the Visual Studio Emulator for Android (x86) or an attached Android device (ARM) is possible.<\/span><\/p>\n<h2><span lang=\"EN-GB\">Building a Marmalade Core app using Visual Studio 2015<\/span><\/h2>\n<p class=\"Normal1\"><span lang=\"EN-GB\">By default, Marmalade Core projects produce a Visual Studio solution capable of generating an app binary that can be deployed to several target platforms without recompilation. This so-called &ldquo;single-binary&rdquo; uses proprietary Marmalade technology and can be used to target iOS from a Windows machine, as well as Android. This type of Visual Studio solution is ideal for generating a binary for distribution or for debugging on the Marmalade Desktop Simulator.<\/span><\/p>\n<p class=\"Normal1\"><span lang=\"EN-GB\">For on-device native debugging, Marmalade Core projects can also generate a special Visual Studio solution that allows for debugging on Windows Phone, Windows 10 and now Android.<\/span><\/p>\n<p class=\"Normal1\"><span lang=\"EN-GB\">Visual Studio 2015 can be launched in Android Native Debug mode either from the command-line or from the Marmalade Hub.&nbsp;<\/span><\/p>\n<p class=\"Normal1\"><span lang=\"EN-GB\">From the command-line, run the following command:<\/span><\/p>\n<p class=\"Normal1\"><span style=\"font-family: 'courier new', courier\">mkb MyProject.mkb &#8211;buildenv=VC14 &#8211;buildenv-toolset=ANDROIDNATIVE<\/span><\/p>\n<p class=\"Normal1\"><span lang=\"EN-GB\">From the Marmalade Hub, select <strong>Android<\/strong> as the target platform in the project screen and click the <strong>Open in IDE for debugging<\/strong> button as shown below.<\/span><\/p>\n<p class=\"Normal1\"><a href=\"https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2021\/10\/6281.marmelade-1.png\"><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2021\/10\/6281.marmelade-1.png\" alt=\"Image 6281 marmelade 1\" width=\"1026\" height=\"732\" class=\"alignnone size-full wp-image-29236\" srcset=\"https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2021\/10\/6281.marmelade-1.png 1026w, https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2021\/10\/6281.marmelade-1-300x214.png 300w, https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2021\/10\/6281.marmelade-1-1024x731.png 1024w, https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2021\/10\/6281.marmelade-1-768x548.png 768w\" sizes=\"(max-width: 1026px) 100vw, 1026px\" \/><\/a><\/p>\n<p class=\"Normal1\"><a href=\"https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2021\/10\/4263.marmelade-2.png\"><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2021\/10\/4263.marmelade-2.png\" alt=\"Image 4263 marmelade 2\" width=\"1026\" height=\"732\" class=\"alignnone size-full wp-image-29235\" srcset=\"https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2021\/10\/4263.marmelade-2.png 1026w, https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2021\/10\/4263.marmelade-2-300x214.png 300w, https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2021\/10\/4263.marmelade-2-1024x731.png 1024w, https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2021\/10\/4263.marmelade-2-768x548.png 768w\" sizes=\"(max-width: 1026px) 100vw, 1026px\" \/><\/a><\/p>\n<p class=\"Normal1\"><span lang=\"EN-GB\">In the Visual Studio IDE you&rsquo;ll notice that the generated solution consists of two projects as shown below.<\/span><\/p>\n<p class=\"Normal1\"><a href=\"https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2021\/10\/2437.marmelade-3.png\"><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2021\/10\/2437.marmelade-3.png\" alt=\"Image 2437 marmelade 3\" width=\"818\" height=\"607\" class=\"alignnone size-full wp-image-29232\" srcset=\"https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2021\/10\/2437.marmelade-3.png 818w, https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2021\/10\/2437.marmelade-3-300x223.png 300w, https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2021\/10\/2437.marmelade-3-768x570.png 768w\" sizes=\"(max-width: 818px) 100vw, 818px\" \/><\/a><\/p>\n<p class=\"Normal1\"><strong><span lang=\"EN-GB\">Android.Packaging<\/span><\/strong><\/p>\n<p class=\"Normal1\" style=\"padding-left: 30px\"><span lang=\"EN-GB\">This project contains the Visual Studio configuration required to package and deploy your app to an Android target.<\/span><\/p>\n<p class=\"Normal1\"><strong><span lang=\"EN-GB\">&lt;app_name&gt;_vc14_androidnativetoolset <\/span><\/strong><\/p>\n<p class=\"Normal1\" style=\"padding-left: 30px\">This project contains your app&#8217;s sources and produces a dynamic library that will be included in the APK created by the <strong>Android.Packaging<\/strong> project.<\/p>\n<p class=\"Normal1\">Marmalade&#8217;s makefile builder system will automatically populate the project&#8217;s C++ and linker settings with the appropriate flags appropriate for a Marmalade Core app. By default, GCC 4.9 is selected to build for ARMv7-a and vfpv3-d16 fpu variant and softfp float ABI.<\/p>\n<p class=\"Normal1\"><span lang=\"EN-GB\">Once generated, the developer can edit, build and run the app from the IDE, as per usual, with the new Visual Studio 2015 Android specific features such as IntelliSense for code-completion and code-highlighting available.<\/span><\/p>\n<h2><span lang=\"EN-GB\">Debugging a Marmalade Core app using Visual Studio 2015<\/span><\/h2>\n<p class=\"Normal1\"><span lang=\"EN-GB\">Debugging a Marmalade Core app is straightforward: simply use the existing Visual Studio debugging capabilities as normal.<\/span><\/p>\n<p class=\"Normal1\"><span lang=\"EN-GB\">For example, hit F5 and the app will be built, packaged then deployed to the connected Android device or the Visual Studio Emulator for Android. The app will then launch automatically with the debugger attached.<\/span><\/p>\n<p class=\"Normal1\"><a href=\"https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2021\/10\/4048.marmelade-4.png\"><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2021\/10\/4048.marmelade-4.png\" alt=\"Image 4048 marmelade 4\" width=\"1030\" height=\"556\" class=\"alignnone size-full wp-image-29234\" srcset=\"https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2021\/10\/4048.marmelade-4.png 1030w, https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2021\/10\/4048.marmelade-4-300x162.png 300w, https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2021\/10\/4048.marmelade-4-1024x553.png 1024w, https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2021\/10\/4048.marmelade-4-768x415.png 768w\" sizes=\"(max-width: 1030px) 100vw, 1030px\" \/><\/a><\/p>\n<p class=\"Normal1\"><span lang=\"EN-GB\">To further demonstrate the debugging capabilities of Visual Studio 2015, we will walk through a debug session using a real game, SineWave, made with Marmalade by Mad Fellows Games Studio, available for iOS, Android and Windows. The game is a futuristic on-rails shooter where the music sets the beat for you to time your moves to.<\/span><\/p>\n<h3><span lang=\"EN-GB\">Setting a breakpoint and inspecting local variables<\/span><\/h3>\n<p class=\"Normal1\"><span lang=\"EN-GB\">A breakpoint has been set in the callback for the Sound button in the main menu to demonstrate hitting a breakpoint when some user interaction occurs.<\/span><\/p>\n<p class=\"Normal1\"><a href=\"https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2021\/10\/0572.marmelade-5.png\"><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2021\/10\/0572.marmelade-5.png\" alt=\"Image 0572 marmelade 5\" width=\"1184\" height=\"840\" class=\"alignnone size-full wp-image-29229\" srcset=\"https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2021\/10\/0572.marmelade-5.png 1184w, https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2021\/10\/0572.marmelade-5-300x213.png 300w, https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2021\/10\/0572.marmelade-5-1024x726.png 1024w, https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2021\/10\/0572.marmelade-5-768x545.png 768w\" sizes=\"(max-width: 1184px) 100vw, 1184px\" \/><\/a><\/p>\n<p class=\"Normal1\"><span lang=\"EN-GB\">In the <strong>MainMenu.cpp<\/strong> source window, the yellow arrow shows the current point of execution. When the game is paused you can drag this yellow arrow to another point to skip to that point of execution to bypass a particular code path. The breakpoints can be disabled and enabled in the source window as well as the <strong>Breakpoints<\/strong> window.<\/span><\/p>\n<p class=\"Normal1\"><span lang=\"EN-GB\">One of the most useful features is the <strong>Call Stack<\/strong> window which provides source file and line numbers for the functions along a code path. Also, in the <strong>Locals<\/strong> window, Visual Studio offers quick access to the local variables within the current scope providing the memory address and value of variables. In this example the <strong>CMainMenu<\/strong> instance and its member variables.<\/span><\/p>\n<h3><span lang=\"EN-GB\">Stepping through disassembly<\/span><\/h3>\n<p class=\"Normal1\"><span lang=\"EN-GB\">It is often necessary to view the disassembly of a particular function particularly if the code has inline assembly. Visual Studio offers this capability for both x86 and ARM as shown below at the same breakpoint:<\/span><\/p>\n<table border=\"0\">\n<tbody>\n<tr>\n<td><a href=\"https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2021\/10\/2744.marmelade-6.png\"><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2021\/10\/2744.marmelade-6.png\" alt=\"Image 2744 marmelade 6\" width=\"669\" height=\"451\" class=\"alignnone size-full wp-image-29233\" srcset=\"https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2021\/10\/2744.marmelade-6.png 669w, https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2021\/10\/2744.marmelade-6-300x202.png 300w\" sizes=\"(max-width: 669px) 100vw, 669px\" \/><\/a><\/td>\n<td><a href=\"https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2021\/10\/1727.marmelade-7.png\"><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2021\/10\/1727.marmelade-7.png\" alt=\"Image 1727 marmelade 7\" width=\"683\" height=\"401\" class=\"alignnone size-full wp-image-29231\" srcset=\"https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2021\/10\/1727.marmelade-7.png 683w, https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2021\/10\/1727.marmelade-7-300x176.png 300w\" sizes=\"(max-width: 683px) 100vw, 683px\" \/><\/a><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h3><span lang=\"EN-GB\">Using the Immediate Window<\/span><\/h3>\n<p class=\"Normal1\"><span lang=\"EN-GB\">For more control the developer also has access to the <strong>Immediate Window<\/strong> from which you can evaluate functions at runtime (on the same thread as the one that hit the breakpoint). This is useful to evaluate things that are dynamic or that vary per device.<\/span><\/p>\n<p class=\"Normal1\"><span lang=\"EN-GB\">Below is an example of Marmalade Core function, <strong>s3eDeviceGetInt<\/strong>, being called to retrieve properties such as the PPI, Logical PPI, amount of free memory and the architecture for both ARM device and x86 emulator:<\/span><\/p>\n<table border=\"0\">\n<tbody>\n<tr>\n<td>\n<p>x86 Emulator<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2021\/10\/0880.marmelade-8.png\"><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2021\/10\/0880.marmelade-8.png\" alt=\"Image 0880 marmelade 8\" width=\"287\" height=\"165\" class=\"alignnone size-full wp-image-29230\" \/><\/a><\/p>\n<\/td>\n<td>\n<p>ARM device<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2021\/10\/7571.marmelade-9.png\"><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2021\/10\/7571.marmelade-9.png\" alt=\"Image 7571 marmelade 9\" width=\"287\" height=\"165\" class=\"alignnone size-full wp-image-29238\" \/><\/a><\/p>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h2><span lang=\"EN-GB\">Conclusion<\/span><\/h2>\n<p class=\"Normal1\"><span lang=\"EN-GB\">Visual Studio 2015&rsquo;s new capabilities to build and debug native C++ Android apps are fully leveraged by the Marmalade Platform. This allows us to provide our users with a powerful addition to their development toolbox.<\/span><\/p>\n<p class=\"Normal1\"><span lang=\"EN-GB\">The Visual Studio Emulator for Android offers a fast x86 emulator for debugging on a variety of form factors and Android versions with different technical specifications. The ability to also debug on an attached device offers the developer an easy way to deploy and benchmark their games with minimal effort, all from within the Visual Studio IDE.<\/span><\/p>\n<table border=\"0\">\n<tbody>\n<tr>\n<td width=\"132\"><a href=\"https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2021\/10\/6874.marmelade-alex-baude.jpg\"><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2021\/10\/6874.marmelade-alex-baude.jpg\" alt=\"Image 6874 marmelade alex baude\" width=\"131\" height=\"159\" class=\"alignnone size-full wp-image-29237\" \/><\/a><\/td>\n<td><strong>Alex Baude<\/strong> is a senior sofware engineer at Marmalade Technologies working on the Marmalade Platform, a cross-platform SDK that allows developers to target various mobile and desktop platforms from a single codebase. He has worked extensively on Windows Phone and iOS specializing on cross-compilers and low-level tooling and is currently focused on extending Android support in the Marmalade SDK<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p class=\"Normal1\">&nbsp;<\/p>\n<p><span lang=\"EN-GB\"><br \/><\/span><\/p>\n","protected":false},"excerpt":{"rendered":"<p>For this blog post, we welcome Alex Baude of Marmalade (https:\/\/www.madewithmarmalade.com) as a guest author on our blog. His team&rsquo;s most recent release of Marmalade Platform now supports Visual Studio 2015 and we invited him to tell us more about their work on this. Visual Studio 2015 provides new cross-platform native development technology for building [&hellip;]<\/p>\n","protected":false},"author":308,"featured_media":35994,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[1],"tags":[],"class_list":["post-7271","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-cplusplus"],"acf":[],"blog_post_summary":"<p>For this blog post, we welcome Alex Baude of Marmalade (https:\/\/www.madewithmarmalade.com) as a guest author on our blog. His team&rsquo;s most recent release of Marmalade Platform now supports Visual Studio 2015 and we invited him to tell us more about their work on this. Visual Studio 2015 provides new cross-platform native development technology for building [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/cppblog\/wp-json\/wp\/v2\/posts\/7271","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/cppblog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/cppblog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/cppblog\/wp-json\/wp\/v2\/users\/308"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/cppblog\/wp-json\/wp\/v2\/comments?post=7271"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/cppblog\/wp-json\/wp\/v2\/posts\/7271\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/cppblog\/wp-json\/wp\/v2\/media\/35994"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/cppblog\/wp-json\/wp\/v2\/media?parent=7271"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/cppblog\/wp-json\/wp\/v2\/categories?post=7271"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/cppblog\/wp-json\/wp\/v2\/tags?post=7271"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}