Upstream version 9.38.198.0
[platform/framework/web/crosswalk.git] / src / native_client_sdk / doc_generated / devguide / devcycle / vs-addin.html
1 {{+bindTo:partials.standard_nacl_api}}
2
3 <section id="debugging-with-visual-studio">
4 <h1 id="debugging-with-visual-studio">Debugging With Visual Studio</h1>
5 <div class="contents local" id="table-of-contents" style="display: none">
6 <p class="topic-title first">Table Of Contents</p>
7 <ul class="small-gap">
8 <li><a class="reference internal" href="#introduction" id="id1">Introduction</a></li>
9 <li><p class="first"><a class="reference internal" href="#platforms" id="id2">Platforms</a></p>
10 <ul class="small-gap">
11 <li><a class="reference internal" href="#the-ppapi-platform" id="id3">The PPAPI platform</a></li>
12 <li><a class="reference internal" href="#the-native-client-platforms" id="id4">The Native Client platforms</a></li>
13 </ul>
14 </li>
15 <li><p class="first"><a class="reference internal" href="#installing-the-add-in" id="id5">Installing the add-in</a></p>
16 <ul class="small-gap">
17 <li><a class="reference internal" href="#set-environment-variables" id="id6">Set environment variables</a></li>
18 <li><a class="reference internal" href="#download-the-add-in" id="id7">Download the add-in</a></li>
19 <li><a class="reference internal" href="#run-the-installer" id="id8">Run the installer</a></li>
20 </ul>
21 </li>
22 <li><p class="first"><a class="reference internal" href="#try-the-hello-world-gles-sample-project" id="id9">Try the <code>hello_world_gles</code> sample project</a></p>
23 <ul class="small-gap">
24 <li><a class="reference internal" href="#select-the-nacl64-platform" id="id10">Select the NaCl64 platform</a></li>
25 <li><a class="reference internal" href="#build-and-run-the-project" id="id11">Build and run the project</a></li>
26 <li><a class="reference internal" href="#test-the-nacl-gdb-debugger" id="id12">Test the nacl-gdb debugger</a></li>
27 <li><a class="reference internal" href="#test-the-visual-studio-debugger" id="id13">Test the Visual Studio debugger</a></li>
28 <li><a class="reference internal" href="#inspect-the-platform-properties" id="id14">Inspect the platform properties</a></li>
29 </ul>
30 </li>
31 <li><p class="first"><a class="reference internal" href="#developing-for-native-client-in-visual-studio" id="id15">Developing for Native Client in Visual Studio</a></p>
32 <ul class="small-gap">
33 <li><a class="reference internal" href="#adding-platforms-to-a-project" id="id16">Adding platforms to a project</a></li>
34 <li><a class="reference internal" href="#selecting-a-toolchain" id="id17">Selecting a toolchain</a></li>
35 <li><a class="reference internal" href="#adding-libraries-to-a-project" id="id18">Adding libraries to a project</a></li>
36 <li><a class="reference internal" href="#running-a-web-server" id="id19">Running a web server</a></li>
37 <li><a class="reference internal" href="#keeping-track-of-all-the-pieces" id="id20">Keeping track of all the pieces</a></li>
38 <li><a class="reference internal" href="#using-the-debuggers" id="id21">Using the debuggers</a></li>
39 <li><a class="reference internal" href="#disable-chrome-caching" id="id22">Disable Chrome caching</a></li>
40 <li><a class="reference internal" href="#a-warning-about-postmessage" id="id23">A warning about PostMessage</a></li>
41 <li><a class="reference internal" href="#porting-windows-applications-to-native-client-in-visual-studio" id="id24">Porting Windows applications to Native Client in Visual Studio</a></li>
42 </ul>
43 </li>
44 </ul>
45
46 </div><p>Whether you&#8217;re porting an existing project or starting from scratch, the Native
47 Client Visual Studio add-in makes it easier to set up, build, run and debug
48 your Native Client app by integrating the Native Client SDK development tools
49 into the Visual Studio environment.</p>
50 <aside class="note">
51 The Native Client add-in requires Visual Studio 2010 with Service Pack 1. No
52 other versions of Visual Studio are currently supported. Visual Studio
53 Express is also not supported.
54 </aside>
55 <h2 id="introduction">Introduction</h2>
56 <p>The Native Client add-in for Visual Studio helps you develop your application
57 more efficiently in many ways:</p>
58 <ul class="small-gap">
59 <li>Organize and maintain your code as a Visual Studio project.</li>
60 <li>Iteratively write and test your application more easily. Visual Studio
61 handles the details of launching a web server to serve your module and run
62 the module in Chrome with a debugger attached.</li>
63 <li>Compile your module into a dynamically-linked library (DLL) using Visual
64 Studio&#8217;s C/C++ compiler and run it as a Pepper plugin. This allows you to
65 develop code incrementally, coding and/or porting one feature at a time into
66 the Pepper APIs while continuing to use native Windows APIs that would
67 otherwise be unavailable in an actual Native Client module.</li>
68 <li>Use Visual Studio&#8217;s built-in debugger to debug your code while it’s running
69 as a Pepper plugin.</li>
70 <li>Compile your module into a .nexe or .pexe file using the Native Client SDK
71 tools and run it as a bona fide Native Client module.</li>
72 <li>Use the Native Client debugger, nacl-gdb, to test your code when it’s running
73 as a Native Client object.</li>
74 </ul>
75 <p>The add-in defines five new Visual Studio platforms: <code>PPAPI</code>, <code>NaCl32</code>,
76 <code>NaCl64</code>, <code>NaClARM</code>, and <code>PNaCl</code>. These platforms can be applied to the
77 debug configuration of solutions and projects. The platforms configure the
78 properties of your project so it can be built and run as either a Pepper plugin
79 or a Native Client module. The platforms also define the behavior associated
80 with the debug command so you can test your code while running in Visual
81 Studio.</p>
82 <h2 id="platforms">Platforms</h2>
83 <p>It is helpful to consider the Visual Studio add-in platforms in two groups. One
84 contains the PPAPI platform only. The other group, which we&#8217;ll call the Native
85 Client platforms, contains platforms that all have &#8220;NaCl&#8221; in their names:
86 <code>NaCl32</code>, <code>NaCl64</code>, <code>NaClARM</code>, and <code>PNaCl</code>. The diagram below shows the
87 platforms, the ways they are normally used, and the build products they produce.</p>
88 <img alt="/native-client/images/visualstudio4.png" src="/native-client/images/visualstudio4.png" />
89 <p>Using platforms, your workflow is faster and more efficient. You can compile,
90 start, and debug your code with one click or key-press. When you press F5, the
91 “start debugging” command, Visual Studio automatically launches a web server to
92 serve your module (if necessary) along with an instance of Chrome that runs
93 your Native Client module, and also attaches an appropriate debugger.</p>
94 <p>You can switch between platforms as you work to compare the behavior of your
95 code.</p>
96 <p>When you run your project, Visual Studio launches the PPAPI and Native Client
97 platforms in different ways, as explained in the next sections.</p>
98 <h3 id="the-ppapi-platform">The PPAPI platform</h3>
99 <p>The PPAPI platform builds your module as a dynamic library and launches a
100 version of Chrome that’s configured to run the library as a plugin when it
101 encounters an <code>&lt;embed&gt;</code> element with <code>type=application/x-nacl</code> (ignoring
102 the information in the manifest file). When running in the PPAPI platform, you
103 can use Windows system calls that are unavailable in a regular Native Client
104 module built and running as a .nexe file. This offers the ability to port
105 existing code incrementally, rewriting functions using the PPAPI interfaces one
106 piece at a time. Since the module is built with Visual Studio’s native compiler
107 (MSBuild) you can use the Visual Studio debugger to control and inspect your
108 code.</p>
109 <h3 id="the-native-client-platforms">The Native Client platforms</h3>
110 <p>There are four Native Client platforms. All of them can be used to build Native
111 Client modules. When you run one of the Native Client platforms Visual Studio
112 builds the corresponding type of Native Client module (either a .nexe or
113 .pexe), starts a web server to serve it up, and launches a copy of Chrome that
114 fetches the module from the server and runs it. Visual Studio will also open a
115 terminal window, launch an instance of nacl-gdb, and attach it to your module&#8217;s
116 process so you can use gdb commands to debug.</p>
117 <h4 id="nacl32-and-nacl64">NaCl32 and NaCl64</h4>
118 <p>The platforms named NaCl32 and NaCl64 are targeted at x86 32-bit and 64-bit
119 systems respectively. You need both platforms to build a full set of .nexe
120 files when you are ready to distribute your application. Note, however, that
121 when you are testing in Visual Studio you must select the NaCl64 platform
122 (because Chrome for Windows runs Native Client in a 64-bit process). If you try
123 to run from the NaCl32 platform you will get an error message.</p>
124 <h4 id="naclarm">NaClARM</h4>
125 <p>The NaClARM platform is targeted at ARM-based processors. You can build .nexe
126 files with the NaClARM platform in Visual Studio but you cannot run them from
127 there. You can use Visual Studio to create a Native Client module that includes
128 an ARM-based .nexe file and then run the module from a Chrome browser on an ARM
129 device, such as one of the newer Chromebook computers. See the instructions at
130 <a class="reference internal" href="/native-client/devguide/devcycle/running.html"><em>Running Native Client Applications</em></a> for more information on
131 testing your module in Chrome.</p>
132 <aside class="note">
133 Note: The NaClARM platform currently supports the newlib toolchain only.
134 </aside>
135 <h4 id="pnacl">PNaCl</h4>
136 <p>The PNaCl (portable NaCl) platform is included in the Visual Studio Native
137 Client add-in versions 1.1 and higher. It supports the .pexe file format. A
138 .pexe file encodes your application as bitcode for a low level virtual machine
139 (LLVM). When you deliver a Native Client application as a PNaCl module, the
140 manifest file will contain a single .pexe file rather than multiple .nexe
141 files. The Chrome client transforms the LLVM bitcode into machine instructions
142 for the local system.</p>
143 <p>When you run the PNaCl platform from Visual Studio, Visual Studio uses the
144 Native Client SDK to transform the .pexe file into a NaCl64 .nexe file and runs
145 it as if you were working with a NaCl64 platform.</p>
146 <aside class="note">
147 Note: The PNaCl platform currently supports the newlib toolchain only.
148 </aside>
149 <h2 id="installing-the-add-in">Installing the add-in</h2>
150 <p>In order to use the Native Client Visual Studio add-in, your development
151 environment should include:</p>
152 <ul class="small-gap">
153 <li>A 64-bit version of Windows Vista or Windows 7.</li>
154 <li>Visual Studio 2010 with Service Pack 1.</li>
155 <li><a class="reference external" href="https://www.google.com/intl/en/chrome/browser/">Chrome</a> version 23 or
156 greater. You can choose to develop using the latest <a class="reference external" href="https://www.google.com/intl/en/chrome/browser/canary.html">canary</a> build of
157 Chrome, running the canary version side-by-side with (and separately from)
158 your regular version of Chrome.</li>
159 <li><a class="reference internal" href="/native-client/sdk/download.html"><em>The Native Client SDK</em></a> with the <code>pepper_23</code>
160 bundle or greater. The version of Chrome that you use must be equal or
161 greater than the version of the SDK bundle.</li>
162 </ul>
163 <h3 id="set-environment-variables">Set environment variables</h3>
164 <p>Before you run the installer you must define two Windows environment variables.
165 They point to the bundle in the Native Client SDK that you use to build your
166 module, and to the Chrome browser that you choose to use for debugging.</p>
167 <p>To set environment variables in Windows 7, go to the Start menu and search for
168 &#8220;environment.&#8221; One of the links in the results is &#8220;Edit environment variables
169 for your account.&#8221; (You can also reach this link from the <code>Control Panel</code>
170 under <code>User Accounts</code>.) Click on the link and use the buttons in the window
171 to create or change these user variables (the values shown below are only for
172 example):</p>
173 <table border="1" class="docutils">
174 <colgroup>
175 </colgroup>
176 <thead valign="bottom">
177 <tr class="row-odd"><th class="head">Variable Name</th>
178 <th class="head">Description</th>
179 </tr>
180 </thead>
181 <tbody valign="top">
182 <tr class="row-even"><td>NACL_SDK_ROOT</td>
183 <td>The path to the pepper directory in the SDK.
184 For example: <code>C:\nacl_sdk\pepper_23</code></td>
185 </tr>
186 <tr class="row-odd"><td>CHROME_PATH</td>
187 <td>The path to the .exe file for the version of Chrome you
188 are testing with.  For example:
189 <code>C:\Users\fred\AppData\Local\Google\Chrome
190 SxS\Application\chrome.exe</code></td>
191 </tr>
192 </tbody>
193 </table>
194 <h3 id="download-the-add-in">Download the add-in</h3>
195 <p>The Native Client Visual Studio add-in is a separate bundle in the SDK named
196 <code>vs_addin</code>. Open a command prompt window, go to the top-level SDK directory,
197 and run the update command, specifying the add-in bundle:</p>
198 <pre class="prettyprint">
199 naclsdk update vs_addin
200 </pre>
201 <p>This creates a folder named <code>vs_addin</code>, containing the add-in itself, its
202 installer files, and a directory of examples.</p>
203 <aside class="note">
204 Note: The vs_addin bundle is only visible when you run <code>naclsdk</code> on a
205 Windows system.
206 </aside>
207 <h3 id="run-the-installer">Run the installer</h3>
208 <p>The installer script is located inside the <code>vs_addin</code> folder in the SDK.
209 Right click on the file <code>install.bat</code> and run it as administrator.</p>
210 <p>The script always installs the NativeClient platforms, and asks you if you’d
211 like to install the PPAPI platform as well. You can skip the PPAPI step and run
212 the installer again later to add the PPAPI platform.</p>
213 <p>You can usually run the installer successfully with no arguments. The new
214 platforms are installed in <code>C:\Program Files
215 (x86)\MSBuild\Microsoft.Cpp\v4.0\Platforms</code>.</p>
216 <p>In some cases system resources may not be in their default locations. You might
217 need to use these command line arguments when you run <code>install.bat</code>:</p>
218 <ul class="small-gap">
219 <li>The MSBuild folder is assumed to be at <code>C:\Program Files (x86)\MSBuild</code>.
220 You can specify an alternate path with the flag <code>--ms-build-path=&lt;path&gt;</code>.
221 The installer assumes Visual Studio has created a user folder at</li>
222 <li><code>%USERPROFILE%\My Documents\Visual Studio 2010</code>. You can specify an
223 alternate path with the flag <code>--vsuser-path=path</code>.</li>
224 </ul>
225 <p>From time to time an update to the Visual Studio add-in may become available.
226 Updates are performed just like an installation. Download the new add-in using
227 naclsdk update and run <code>install.bat</code> as administrator.</p>
228 <p>To uninstall the add-in, run <code>install.bat</code> as administrator and add the
229 <code>--uninstall</code> flag. You&#8217;ll need to run the Command Prompt program as
230 administrator in order to add the flag. Go the to the Windows start menu,
231 search for &#8220;Command Prompt,&#8221; right click on the program and run it as
232 administrator.</p>
233 <p>You can verify that the add-in has been installed and determine its version by
234 selecting Add-in Manager in the Visual Studio Tools menu. If the add-in has
235 been installed it will appear in the list of available add-ins. Select it and
236 read its description.</p>
237 <h2 id="try-the-hello-world-gles-sample-project">Try the <code>hello_world_gles</code> sample project</h2>
238 <p>The add-in comes with an examples directory. Open the sample project
239 <code>examples\hello_world_gles\hello_world_gles.sln</code>. This project is an
240 application that displays a spinning cube.</p>
241 <h3 id="select-the-nacl64-platform">Select the NaCl64 platform</h3>
242 <p>Open the sample project in Visual Studio, select the <code>Configuration Manager</code>,
243 and confirm that the active solution configuration is <code>Debug</code> and the active
244 project platform is <code>NaCl64</code>. Note that the platform for the
245 <code>hello_world_gles</code> project is also <code>NaCl64</code>. (You can get to the
246 <code>Configuration Manager</code> from the <code>Build</code> menu or the project’s
247 <code>Properties</code> window.)</p>
248 <img alt="/native-client/images/visualstudio1.png" src="/native-client/images/visualstudio1.png" />
249 <h3 id="build-and-run-the-project">Build and run the project</h3>
250 <p>Use the debugging command (F5) to build and run the project. As the wheels
251 start to turn, you may be presented with one or more alerts. They are benign;
252 you can accept them and set options to ignore them when that’s possible. Some
253 of the messages you might see include:</p>
254 <ul class="small-gap">
255 <li>&#8220;This project is out of date, would you like to build it?&#8221;</li>
256 <li>&#8220;Please specify the name of the executable file to be used for the debug
257 session.&#8221; This should be the value of the environment variable CHROME_PATH,
258 which is usually supplied as the default value in the dialog.</li>
259 <li>&#8220;Debugging information for chrome.exe cannot be found.&#8221; This is to be
260 expected, you are debugging your module&#8217;s code, not Chrome.</li>
261 <li>&#8220;Open file - security warning. The publisher could not be verified.&#8221; If
262 Visual Studio is complaining about x86_64-nacl-gdb.exe, that’s our debugger.
263 Let it be.</li>
264 </ul>
265 <p>Once you’ve passed these hurdles, the application starts to run and you’ll see
266 activity in three places:</p>
267 <ol class="arabic simple">
268 <li>A terminal window opens running <code>nacl-gdb</code>.</li>
269 <li>Chrome launches running your module in a tab.</li>
270 <li>The Visual Studio output window displays debugging messages when you select
271 the debug output item.
272 Stop the debugging session by closing the Chrome window, or select the stop
273 debugging command from the debug menu. The nacl-gdb window will close when
274 you stop running the program.</li>
275 </ol>
276 <h3 id="test-the-nacl-gdb-debugger">Test the nacl-gdb debugger</h3>
277 <p>Add a breakpoint at the SwapBuffers call in the function MainLoop, which is in
278 hello_world.cc.</p>
279 <img alt="/native-client/images/visualstudio2.png" src="/native-client/images/visualstudio2.png" />
280 <p>Start the debugger again (F5). This time the existing breakpoint is loaded into
281 nacl-gcb and the program will pause there. Type c to continue running. You can
282 use gdb commands to set more breakpoints and step through the application. For
283 details, see <a class="reference internal" href="/native-client/devguide/devcycle/debugging.html#using-gdb"><em>Debugging with nacl-gdb</em></a> (scroll down to the end
284 of the section to see some commonly used gdb commands).</p>
285 <h3 id="test-the-visual-studio-debugger">Test the Visual Studio debugger</h3>
286 <p>If you’ve installed the <code>PPAPI</code> platform, go back to the <code>Configuration
287 Manager</code> and select the <code>PPAPI</code> platform. This time when Chrome launches the
288 <code>nacl-gdb</code> window will not appear; the Visual Studio debugger is fully
289 engaged and on the job.</p>
290 <h3 id="inspect-the-platform-properties">Inspect the platform properties</h3>
291 <p>At this point, it may be helpful to take a look at the properties that are
292 associated with the PPAPI and Native Client platforms&#8212;see the settings in the
293 sample project as an example.</p>
294 <h2 id="developing-for-native-client-in-visual-studio">Developing for Native Client in Visual Studio</h2>
295 <p>After you’ve installed the add-in and tried the sample project, you’re ready to
296 start working with your own code. You can reuse the sample project and the
297 PPAPI and Native Client platforms it already has by replacing the source code
298 with your own. More likely, you will add the platforms to an existing project,
299 or to a new project that you create from scratch.</p>
300 <h3 id="adding-platforms-to-a-project">Adding platforms to a project</h3>
301 <p>Follow these steps to add the Native Client and PPAPI platforms to a project:</p>
302 <ol class="arabic simple">
303 <li>Open the Configuration Manager.</li>
304 <li>On the row corresponding to your project, click the Platform column dropdown
305 menu and select <code>&lt;New...&gt;</code>.</li>
306 <li>Select <code>PPAPI</code>, <code>NaCl32</code>, <code>NaCl64</code>, or <code>PNaCl</code> from the New platform
307 menu.</li>
308 <li>In most cases, you should select <code>&lt;Empty&gt;</code> in the “Copy settings from”
309 menu.  <strong>Never copy settings between ``PPAPI``, ``NaCl32``, ``NaCl64``,
310 ``NaClARM``, or ``PNaCl`` platforms</strong>. You can copy settings from a Win32
311 platform, if one exists, but afterwards be sure that the project properties
312 are properly set for the new platform, as mentioned in step 6 below.</li>
313 <li>If you like, check the “Create new solutions platform” box to create a
314 solution platform in addition to a project platform. (This is optional, but
315 it can be convenient since it lets you switch project platforms from the
316 Visual Studio main window by selecting the solution platform that has the
317 same name.)</li>
318 <li>Review the project properties for the new platform you just added. In most
319 cases, the default properties for each platform should be correct, but it
320 pays to check. Be especially careful about custom properties you may have
321 set beforehand, or copied from a Win32 platform. Also confirm that the
322 Configuration type is correct:<ul class="small-gap">
323 <li><code>Dynamic Library</code> for <code>PPAPI</code></li>
324 <li><code>Application (.pexe)</code> for <code>PNaCl</code></li>
325 <li><code>Application (.nexe)</code> for <code>NaCl32</code>, <code>NaCl64</code>, and <code>NaClARM</code></li>
326 </ul>
327 </li>
328 </ol>
329 <h3 id="selecting-a-toolchain">Selecting a toolchain</h3>
330 <p>When you build a Native Client module directly from the SDK you can use two
331 different toolchains, newlib or glibc. See <a class="reference internal" href="/native-client/devguide/devcycle/dynamic-loading.html"><em>Dynamic Linking and Loading
332 with glibc</em></a> for a description of the two toolchains and
333 instructions on how to build and deploy an application with the glibc
334 toolchain. The Native Client platforms offer you the same toolchain choice. You
335 can specify which toolchain to use in the project properties, under
336 <code>Configuration Properties &gt; General &gt; Native Client &gt; Toolchain</code>.</p>
337 <aside class="note">
338 Currently, the NaClARM and PNaCl platforms only support the newlib toolchain.
339 </aside>
340 <p>There is no toolchain property for the PPAPI platform. The PPAPI platform uses
341 the toolchain and libraries that come with Visual Studio.</p>
342 <h3 id="adding-libraries-to-a-project">Adding libraries to a project</h3>
343 <p>If your Native Client application requires libraries that are not included in
344 the SDK you must add them to the project properties (under <code>Configuration
345 Properties &gt; Linker &gt; Input &gt; Additional Dependencies</code>), just like any other
346 Visual Studio project. This list of dependencies is a semi-colon delimited
347 list. On the PPAPI platform the library names include the .lib extension (e.g.,
348 <code>ppapi_cpp.lib;ppapi.lib</code>). On the Native Client platforms the extension is
349 excluded (e.g., <code>ppapi_cpp;ppapi</code>).</p>
350 <h3 id="running-a-web-server">Running a web server</h3>
351 <p>In order for the Visual Studio add-in to test your Native Client module, you
352 must serve the module from a web server. There are two options:</p>
353 <h4 id="running-your-own-server">Running your own server</h4>
354 <p>When you start a debug run Visual Studio launches Chrome and tries to connect
355 to the web server at the address found in the Chrome command arguments (see the
356 project’s Debugging &gt; Command configuration property), which is usually
357 <code>localhost:$(NaClWebServerPort)</code>. If you are using your own server be sure to
358 specify its address in the command arguments property, and confirm that your
359 server is running before starting a debug session. Also be certain that the
360 server has all the files it needs to deliver a Native Client module (see
361 “Keeping track of all the pieces”, below).</p>
362 <h4 id="running-the-sdk-server">Running the SDK server</h4>
363 <p>If there is no web server running at the specified port, Visual Studio will try
364 to launch the simple Python web server that comes with the Native Client SDK.
365 It looks for a copy of the server in the SDK itself (at
366 <code>%NACL_SDK_ROOT%\tools\httpd.py</code>), and in the project directory
367 (<code>$(ProjectDir)/httpd.py</code>). If the server exists in one of those locations,
368 Visual Studio launches the server. The server output appears in Visual Studio’s
369 Output window, in the pane named “Native Client Web Server Output”. A server
370 launched in this way is terminated when the debugging session ends.</p>
371 <h3 id="keeping-track-of-all-the-pieces">Keeping track of all the pieces</h3>
372 <p>No matter where the web server lives or how it’s launched you must make sure
373 that it has all the files that your application needs:</p>
374 <ul class="small-gap">
375 <li>All Native Client applications must have an <a class="reference internal" href="/native-client/devguide/coding/application-structure.html#html-file"><em>html host page</em></a>. This file is typically called <code>index.html</code>. The host page
376 must have an embed tag with its type attribute set to
377 <code>application-type/x-nacl</code>. If you plan to use a Native Client platform the
378 embed tag must also include a src attribute pointing to a Native Client
379 manifest (.mnf) file.</li>
380 <li>If you are using a Native Client platform you must include a valid
381 <a class="reference internal" href="/native-client/devguide/coding/application-structure.html#manifest-file"><em>manifest file</em></a>. The manifest file points to the .pexe
382 or .nexe files that Visual Studio builds. These will be placed in the
383 directory specified in the project’s <code>General &gt; Output Directory</code>
384 configuration property, which is usually <code>$(ProjectDir)$(ToolchainName)</code>.
385 Visual Studio can use the Native Client SDK script create_nmf.py to
386 automatically generate the manifest file for you.  To use this script set the
387 project&#8217;s <code>Linker &gt; General &gt; Create NMF Automatically</code> property to &#8220;yes.&#8221;</li>
388 </ul>
389 <p>If you are letting Visual Studio discover and run the SDK server, these files
390 should be placed in the project directory. If you are running your own server,
391 you must be sure that the host page <code>index.html</code> is placed in your server’s
392 root directory. Remember, if you’re using one of the Native Client platforms
393 the paths for the manifest file and .pexe or .nexe files must be reachable from
394 the server.</p>
395 <p>The structure of the manifest file can be more complicated if your application
396 uses Native Client&#8217;s ability to dynamically link libraries. You may have to add
397 additional information about dynamically linked libraries to the manifest file
398 even if you create it automatically. The use and limitations of the create_nmf
399 tool are explained in <a class="reference internal" href="/native-client/devguide/devcycle/dynamic-loading.html#dynamic-loading-manifest"><em>Generating a Native Client manifest file for a
400 dynamically linked application</em></a>.</p>
401 <p>You can look at the example projects in the SDK to see how the index and
402 manifest files are organized. The example project <code>hello_nacl</code> has a
403 subdirectory also called <code>hello_nacl</code>. That folder contains <code>index.html</code>
404 and <code>hello_nacl.nmf</code>. The nexe file is found in
405 <code>NaCl64\newlib\Debug\hello_nacl_64.nexe</code>. The <code>hello_world_gles</code> example
406 project contains a subdirectory called <cite>hello_world_gles`</cite>. That directory
407 contains html files built with both toolchains (<code>index_glibc.html</code> and
408 <code>index_newlib.html</code>). The .nexe and .nmf files are found in the newlib and
409 glibc subfolders. For additional information about the parts of a Native Client
410 application, see <a class="reference internal" href="/native-client/devguide/coding/application-structure.html"><em>Application Structure</em></a>.</p>
411 <h3 id="using-the-debuggers">Using the debuggers</h3>
412 <p>PPAPI plugins are built natively by Visual Studio’s compiler (MSBuild), and
413 work with Visual Studio’s debugger in the usual way. You can set breakpoints in
414 the Visual Studio source code files before you begin debugging, and on-the-fly
415 while running the program.</p>
416 <p>NaCl32 and NaClARM executables (.nexe files) cannot be run or debugged from
417 Visual Studio.</p>
418 <p>NaCl64 executables (.nexe files) are compiled using one of the Native Client
419 toolchains in the SDK, which create an <a class="reference external" href="`http://en.wikipedia.org/wiki/Executable_and_Linkable_Format">ELF-formatted</a> executable. To
420 debug a running .nexe you must use nacl-gdb, which is a command line debugger
421 that is not directly integrated with Visual Studio. When you start a debugging
422 session running from a NaCl64 platform, Visual Studio automatically launches
423 nacl-gdb for you and attaches it to the nexe. Breakpoints that you set in
424 Visual Studio before you start debugging are transferred to nacl-gdb
425 automatically. During a NaCl debugging session you can only use nacl-gdb
426 commands.</p>
427 <p>The PNaCl platform generates a .pexe file. When you run the debugger add-in
428 translates the .pexe file to a .nexe file and runs the resulting binary with
429 nacl-gdb attached.</p>
430 <p>For additional information about nacl-gdb, see <a class="reference internal" href="/native-client/devguide/devcycle/debugging.html#using-gdb"><em>Debugging with nacl-gdb</em></a> (scroll down to the end of the section to see some commonly used
431 gdb commands).</p>
432 <p>Note that you can’t use the Start Without Debugging command (Ctrl+F5) with a
433 project in the Debug configuration. If you do, Chrome will hang because the
434 Debug platform launches Chrome with the command argument
435 <code>--wait-for-debugger-children</code> (in PPAPI) or <code>--enable-nacl-debug</code> (in a
436 Native Client platform). These flags cause Chrome to pause and wait for a
437 debugger to attach. If you use the Start Without Debugging command, no debugger
438 attaches and Chrome just waits patiently. To use Start Without Debugging,
439 switch to the Release configuration, or manually remove the offending argument
440 from the <code>Command Arguments</code> property.</p>
441 <h3 id="disable-chrome-caching">Disable Chrome caching</h3>
442 <p>When you debug with a Native Client platform you might want to <a class="reference internal" href="/native-client/devguide/devcycle/running.html#cache"><em>disable
443 Chrome&#8217;s cache</em></a> to be sure you are testing your latest and greatest
444 code.</p>
445 <h3 id="a-warning-about-postmessage">A warning about PostMessage</h3>
446 <p>Some Windows libraries define the symbol <code>PostMessage</code> as <code>PostMessageW</code>.
447 This can cause havoc if you are working with the PPAPI platform and you use the
448 Pepper <code>PostMessage()</code> call in your module. Some Pepper API header files
449 contain a self-defensive fix that you might need yourself, while you are
450 testing on the PPAPI platform. Here it is:</p>
451 <pre class="prettyprint">
452 // If Windows defines PostMessage, undef it.
453 #ifdef PostMessage
454 #undef PostMessage
455 #endif
456 </pre>
457 <h3 id="porting-windows-applications-to-native-client-in-visual-studio">Porting Windows applications to Native Client in Visual Studio</h3>
458 <p>At Google I/O 2012 we demonstrated how to port a Windows desktop application to
459 Native Client in 60 minutes. The <a class="reference external" href="http://www.youtube.com/watch?v=1zvhs5FR0X8&amp;feature=plcp">video</a> is available to
460 watch on YouTube. The <code>vs_addin/examples</code> folder contains a pair of simple
461 examples that demonstrate porting process.  They are designed to be completed
462 in just 5 minutes. The two examples are called <code>hello_nacl</code> and
463 <code>hello_nacl_cpp</code>. They are essentially the same, but the former uses the C
464 PPAPI interface while the latter uses the C++ API.  The application is the
465 familiar &#8220;Hello, World.&#8221;</p>
466 <p>Each example begins with the Windows desktop version running in the <code>Win32</code>
467 platform. From there you move to the <code>PPAPI</code> platform, where you perform a
468 series of steps to set up the Native Client framework, use it to run the
469 desktop version, and then port the behavior from Windows calls to the PPAPI
470 interface.  You wind up with a program that uses no Windows functions, which
471 can run in either the <code>PPAPI</code> or the <code>NaCl64</code> platform.</p>
472 <p>The example projects use a single source file (<code>hello_nacl.c</code> or
473 <code>hello_nacl_cpp.cpp</code>). Each step in the porting process is accomplished by
474 progressively defining the symbols STEP1 through STEP6 in the source. Inline
475 comments explain how each successive step changes the code. View the example
476 code to see how it&#8217;s actually done. Here is a summary of the process:</p>
477 <h4 id="win32-platform">Win32 Platform</h4>
478 <dl class="docutils">
479 <dt>STEP1 Run the desktop application</dt>
480 <dd>Begin by running the original Windows application in the Win32 platform.</dd>
481 </dl>
482 <h4 id="ppapi-platform">PPAPI Platform</h4>
483 <dl class="docutils">
484 <dt>STEP2 Launch Chrome with an empty Native Client module</dt>
485 <dd>Switch to the PPAPI platform and include the code required to initialize a
486 Native Module instance. The code is bare-boned, it does nothing but
487 initialize the module. This step illustrates how Visual Studio handles all
488 the details of launching a web-server and Chrome, and running the Native
489 Client module as a Pepper plugin.</dd>
490 <dt>STEP3 Run the desktop application synchronously from the Native Client module</dt>
491 <dd>The Native Client creates the window directly and then calls WndProc to run
492 the desktop application. Since WndProc spins in its message loop, the call to
493 initialize the module never returns. Close the Hello World window and the
494 module initialization will finish.</dd>
495 <dt>STEP4 Running the desktop application and Native Client asynchronously</dt>
496 <dd>In WndProc replace the message loop with a callback function. Now the app
497 window and the Native Client module are running concurrently.</dd>
498 <dt>STEP5 Redirect output to the web page</dt>
499 <dd>The module initialization code calls initInstanceInBrowserWindow rather than
500 initInstanceInPCWindow. WndProc is no longer used. Instead, postMessage is
501 called to place text (now &#8220;Hello, Native Client&#8221;) in the web page rather than
502 opening and writing to a window. Once you&#8217;ve reached this step you can start
503 porting pieces of the application one feature at a time.</dd>
504 <dt>STEP6 Remove all the Windows code</dt>
505 <dd>All the Windows code is def&#8217;d out, proving we are PPAPI-compliant. The
506 functional code that is running is the same as STEP5.</dd>
507 </dl>
508 <h4 id="nacl64-platform">NaCl64 Platform</h4>
509 <dl class="docutils">
510 <dt>Run the Native Client Module in the NaCl64 platform</dt>
511 <dd>You are still running the STEP6 code, but as a Native Client module rather
512 than a Pepper plugin.</dd>
513 </dl>
514 </section>
515
516 {{/partials.standard_nacl_api}}