OLD | NEW |
1 {{+bindTo:partials.standard_nacl_article}} | 1 {{+bindTo:partials.standard_nacl_article}} |
2 | 2 |
3 <span class="target" id="sdk-examples-2"></span><section id="examples"> | 3 <span class="target" id="sdk-examples-2"></span><section id="examples"> |
4 <h1 id="examples">Examples</h1> | 4 <h1 id="examples">Examples</h1> |
5 <p>Every Native Client SDK bundle comes with a folder of example applications. | 5 <p>Every Native Client SDK bundle comes with a folder of example applications. |
6 Each example demonstrates one or two key Native Client programming concepts. | 6 Each example demonstrates one or two key Native Client programming concepts. |
7 After you’ve <a class="reference internal" href="/native-client/sdk/downlo
ad.html"><em>downloaded the SDK</em></a>, follow the instructions | 7 After you’ve <a class="reference internal" href="/native-client/sdk/downlo
ad.html"><em>downloaded the SDK</em></a>, follow the instructions |
8 on this page to build and run the examples.</p> | 8 on this page to build and run the examples.</p> |
9 <p>Your version of Chrome must be equal to or greater than the version of your S
DK | 9 <p>Your version of Chrome must be equal to or greater than the version of your S
DK |
10 bundle. For example, if you’re developing with the <code>pepper_35</code>
bundle, you | 10 bundle. For example, if you’re developing with the <code>pepper_35</code>
bundle, you |
11 must use Google Chrome version 35 or greater. To find out what version of Chrome | 11 must use Google Chrome version 35 or greater. To find out what version of Chrome |
12 you’re using, type <code>about:chrome</code> or <code>about:version</code>
in the Chrome address | 12 you’re using, type <code>about:chrome</code> or <code>about:version</code>
in the Chrome address |
13 bar.</p> | 13 bar.</p> |
14 <h2 id="enable-native-client"><span id="id1"></span>Enable Native Client</h2> | 14 <h2 id="build-the-sdk-examples"><span id="id1"></span>Build the SDK examples</h2
> |
15 <p>If you are using Chrome 31 or later, you can skip this section. To run Portab
le | |
16 Native Client applications you must specifically enable Native Client in Chrome:
</p> | |
17 <ol class="arabic"> | |
18 <li><p class="first">Type <code>about:flags</code> in the Chrome address bar and
scroll down to “Native | |
19 Client”.</p> | |
20 <ul class="small-gap"> | |
21 <li><p class="first">If the link below “Native Client” says “D
isable”, then Native Client is | |
22 already enabled and you don’t need to do anything else.</p> | |
23 </li> | |
24 </ul> | |
25 <ul class="small-gap"> | |
26 <li><p class="first">If the link below “Native Client” says “E
nable”, click the “Enable” | |
27 link.</p> | |
28 </li> | |
29 </ul> | |
30 </li> | |
31 <li><p class="first">Scroll down to the bottom of the page, and click “Rel
aunch Now”. All browser | |
32 windows will restart when you relaunch Chrome.</p> | |
33 </li> | |
34 </ol> | |
35 <h2 id="build-the-sdk-examples"><span id="id2"></span>Build the SDK examples</h2
> | |
36 <p>The Makefile scripts for the SDK examples can build multiple versions of the | 15 <p>The Makefile scripts for the SDK examples can build multiple versions of the |
37 examples using any of the three SDK toolchains (newlib, glibc, and PNaCl) and in | 16 examples using any of the three SDK toolchains (newlib, glibc, and PNaCl) and in |
38 both release and debug configurations. Note that some examples, <code>dlopen</co
de> for | 17 both release and debug configurations. Note that some examples, <code>dlopen</co
de> for |
39 example, build only with particular toolchains.</p> | 18 example, build only with particular toolchains.</p> |
40 <p>Find the toolchains for each example by looking at the <code>VALID_TOOLCHAINS
</code> | 19 <p>Find the toolchains for each example by looking at the <code>VALID_TOOLCHAINS
</code> |
41 variable in the Makefile for a particular example. The first item listed is the | 20 variable in the Makefile for a particular example. The first item listed is the |
42 default. It’s built when you run an example make file without parameters.
for | 21 default. It’s built when you run an example make file without parameters.
for |
43 example running make in the <code>core</code> directory of pepper_35 builds the
example | 22 example running make in the <code>core</code> directory of pepper_35 builds the
example |
44 using the <code>newlib</code> toolchain.</p> | 23 using the <code>newlib</code> toolchain.</p> |
45 <pre class="prettyprint"> | 24 <pre class="prettyprint"> |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
101 CXX glibc/Release/core_x86_32.o | 80 CXX glibc/Release/core_x86_32.o |
102 LINK glibc/Release/core_unstripped_x86_32.nexe | 81 LINK glibc/Release/core_unstripped_x86_32.nexe |
103 VALIDATE glibc/Release/core_unstripped_x86_32.nexe | 82 VALIDATE glibc/Release/core_unstripped_x86_32.nexe |
104 CXX glibc/Release/core_x86_64.o | 83 CXX glibc/Release/core_x86_64.o |
105 LINK glibc/Release/core_unstripped_x86_64.nexe | 84 LINK glibc/Release/core_unstripped_x86_64.nexe |
106 VALIDATE glibc/Release/core_unstripped_x86_64.nexe | 85 VALIDATE glibc/Release/core_unstripped_x86_64.nexe |
107 ... | 86 ... |
108 (content excerpted) | 87 (content excerpted) |
109 ... | 88 ... |
110 </pre> | 89 </pre> |
111 <h3 id="build-results"><span id="id3"></span>Build results</h3> | 90 <h3 id="build-results"><span id="id2"></span>Build results</h3> |
112 <p>After running <code>make</code>, example directories will contain one or more
of the | 91 <p>After running <code>make</code>, example directories will contain one or more
of the |
113 following subdirectories, depending on which Makefile you run:</p> | 92 following subdirectories, depending on which Makefile you run:</p> |
114 <ul class="small-gap"> | 93 <ul class="small-gap"> |
115 <li><code>newlib</code> with subdirectories <code>Debug</code> and <code>Release
</code>;</li> | 94 <li><code>newlib</code> with subdirectories <code>Debug</code> and <code>Release
</code>;</li> |
116 <li><code>glibc</code> with subdirectories <code>Debug</code> and <code>Release<
/code>;</li> | 95 <li><code>glibc</code> with subdirectories <code>Debug</code> and <code>Release<
/code>;</li> |
117 <li><code>pnacl</code> with subdirectories <code>Debug</code> and <code>Release<
/code>;</li> | 96 <li><code>pnacl</code> with subdirectories <code>Debug</code> and <code>Release<
/code>;</li> |
118 </ul> | 97 </ul> |
119 <p>For the newlib and glibc toolchains the Debug and Release subdirectories | 98 <p>For the newlib and glibc toolchains the Debug and Release subdirectories |
120 contain .nexe files for all target architectures. For the PNaCl toolchain | 99 contain .nexe files for all target architectures. For the PNaCl toolchain |
121 they contain a single .pexe file. PNaCl debug also produces pre-translated | 100 they contain a single .pexe file. PNaCl debug also produces pre-translated |
122 .nexe files, for ease of debugging. All Debug and Release directories contain | 101 .nexe files, for ease of debugging. All Debug and Release directories contain |
123 a manifest (.nmf) file that references the associated .nexe or .pexe files. | 102 a manifest (.nmf) file that references the associated .nexe or .pexe files. |
124 For information about Native Client manifest files, see the <a class="reference
internal" href="/native-client/overview.html"><em>Technical | 103 For information about Native Client manifest files, see the <a class="reference
internal" href="/native-client/overview.html"><em>Technical |
125 Overview</em></a>.</p> | 104 Overview</em></a>.</p> |
126 <p>For details on how to use <code>make</code>, see the <a class="reference exte
rnal" href="http://www.gnu.org/software/make/manual/make.html">GNU ‘make&#
8217; Manual</a>. For details on how to | 105 <p>For details on how to use <code>make</code>, see the <a class="reference exte
rnal" href="http://www.gnu.org/software/make/manual/make.html">GNU ‘make&#
8217; Manual</a>. For details on how to |
127 use the SDK toolchain itself, see <a class="reference internal" href="/native-cl
ient/devguide/devcycle/building.html"><em>Building Native Client Modules</em></a
>.</p> | 106 use the SDK toolchain itself, see <a class="reference internal" href="/native-cl
ient/devguide/devcycle/building.html"><em>Building Native Client Modules</em></a
>.</p> |
128 <h2 id="run-the-sdk-examples"><span id="running-the-sdk-examples"></span>Run the
SDK examples</h2> | 107 <h2 id="run-the-sdk-examples"><span id="running-the-sdk-examples"></span>Run the
SDK examples</h2> |
129 <h3 id="disable-the-chrome-cache"><span id="disable-chrome-cache"></span>Disable
the Chrome cache</h3> | 108 <h3 id="disable-the-chrome-cache"><span id="disable-chrome-cache"></span>Disable
the Chrome cache</h3> |
130 <p>Chrome’s intelligent caching caches resources aggressively. When buildi
ng a | 109 <p>Chrome’s intelligent caching caches resources aggressively. When buildi
ng a |
131 Native Client application you should disable the cache to make sure that Chrome | 110 Native Client application you should disable the cache to make sure that Chrome |
132 loads the latest version. Intelligent caching only remains inactive while | 111 loads the latest version. Intelligent caching only remains inactive while |
133 Developer Tools are open. Otherwise, agressive caching continues.</p> | 112 Developer Tools are open. Otherwise, agressive caching continues.</p> |
134 <ol class="arabic simple"> | 113 <ol class="arabic simple"> |
135 <li>Open Chrome’s developer tools by clicking the menu icon <img alt="menu
-icon" src="/native-client/images/menu-icon.png" /> and | 114 <li>Open Chrome’s developer tools by clicking the menu icon <img alt="menu
-icon" src="/native-client/images/menu-icon.png" /> and |
136 choosing Tools > Developer tools.</li> | 115 choosing Tools > Developer tools.</li> |
137 <li>Click the gear icon <img alt="gear-icon" src="/native-client/images/gear-ico
n.png" /> in the bottom right corner of the Chrome | 116 <li>Click the gear icon <img alt="gear-icon" src="/native-client/images/gear-ico
n.png" /> in the bottom right corner of the Chrome |
138 window.</li> | 117 window.</li> |
139 <li>Under the “General” settings, check the box next to “Disab
le cache”.</li> | 118 <li>Under the “General” settings, check the box next to “Disab
le cache”.</li> |
140 </ol> | 119 </ol> |
141 <h3 id="run-the-examples"><span id="id4"></span>Run the examples</h3> | 120 <h3 id="run-the-examples"><span id="id3"></span>Run the examples</h3> |
142 <p>To run the SDK examples, use the <code>make run</code> command:</p> | 121 <p>To run the SDK examples, use the <code>make run</code> command:</p> |
143 <pre class="prettyprint"> | 122 <pre class="prettyprint"> |
144 $ cd pepper_35/examples/api/core | 123 $ cd pepper_35/examples/api/core |
145 $ make run | 124 $ make run |
146 </pre> | 125 </pre> |
147 <p>This launches a local HTTP server that serves the example. It then launches | 126 <p>This launches a local HTTP server that serves the example. It then launches |
148 Chrome with the address of this server, usually <code>http://localhost:5103</cod
e>. | 127 Chrome with the address of this server, usually <code>http://localhost:5103</cod
e>. |
149 After you close Chrome, the local HTTP server automatically shuts down.</p> | 128 After you close Chrome, the local HTTP server automatically shuts down.</p> |
150 <p>This command tries to find an executable named <code>google-chrome</code> in
your | 129 <p>This command tries to find an executable named <code>google-chrome</code> in
your |
151 <code>PATH</code> environment variable. If it can’t, you’ll get an e
rror message like | 130 <code>PATH</code> environment variable. If it can’t, you’ll get an e
rror message like |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
193 application files. Refer to <a class="reference external" href="/apps/about_apps
">What are Chrome Apps</a> for more | 172 application files. Refer to <a class="reference external" href="/apps/about_apps
">What are Chrome Apps</a> for more |
194 information about creating a packaged application.</p> | 173 information about creating a packaged application.</p> |
195 <p>Some Pepper features, such as TCP/UDP socket access, are only allowed in | 174 <p>Some Pepper features, such as TCP/UDP socket access, are only allowed in |
196 packaged applications. The examples that use these features must be run as | 175 packaged applications. The examples that use these features must be run as |
197 packaged applications, by using the following command:</p> | 176 packaged applications, by using the following command:</p> |
198 <pre class="prettyprint"> | 177 <pre class="prettyprint"> |
199 $ make run_package | 178 $ make run_package |
200 </pre> | 179 </pre> |
201 <p>You can use <code>TOOLCHAIN</code> and <code>CONFIG</code> parameters as desc
ribed above to run | 180 <p>You can use <code>TOOLCHAIN</code> and <code>CONFIG</code> parameters as desc
ribed above to run |
202 with a different toolchain or configuration.</p> | 181 with a different toolchain or configuration.</p> |
203 <h2 id="debugging-the-sdk-examples"><span id="id5"></span>Debugging the SDK exam
ples</h2> | 182 <h2 id="debugging-the-sdk-examples"><span id="id4"></span>Debugging the SDK exam
ples</h2> |
204 <p>The NaCl SDK uses <a class="reference external" href="https://www.gnu.org/sof
tware/gdb/">GDB</a> to debug Native | 183 <p>The NaCl SDK uses <a class="reference external" href="https://www.gnu.org/sof
tware/gdb/">GDB</a> to debug Native |
205 Client code. The SDK includes a prebuilt version of GDB that is compatible with | 184 Client code. The SDK includes a prebuilt version of GDB that is compatible with |
206 NaCl code. To use it, run the <code>make debug</code> command from an example di
rectory:</p> | 185 NaCl code. To use it, run the <code>make debug</code> command from an example di
rectory:</p> |
207 <pre class="prettyprint"> | 186 <pre class="prettyprint"> |
208 $ make debug | 187 $ make debug |
209 </pre> | 188 </pre> |
210 <p>This launches Chrome with the <code>--enable-nacl-debug</code> flag set. This
flag causes | 189 <p>This launches Chrome with the <code>--enable-nacl-debug</code> flag set. This
flag causes |
211 Chrome to pause when a NaCl module is first loaded, waiting for a connection | 190 Chrome to pause when a NaCl module is first loaded, waiting for a connection |
212 from gdb. The <code>make debug</code> command also simultaneously launches GDB a
nd loads | 191 from gdb. The <code>make debug</code> command also simultaneously launches GDB a
nd loads |
213 the symbols for that NEXE. To connect GDB to Chrome, in the GDB console, type:</
p> | 192 the symbols for that NEXE. To connect GDB to Chrome, in the GDB console, type:</
p> |
214 <pre class="prettyprint"> | 193 <pre class="prettyprint"> |
215 (gdb) target remote :4014 | 194 (gdb) target remote :4014 |
216 </pre> | 195 </pre> |
217 <p>This tells GDB to connect to a TCP port on <code>localhost:4014</code>, the p
ort that | 196 <p>This tells GDB to connect to a TCP port on <code>localhost:4014</code>, the p
ort that |
218 Chrome is listening on. GDB will respond:</p> | 197 Chrome is listening on. GDB will respond:</p> |
219 <pre class="prettyprint"> | 198 <pre class="prettyprint"> |
220 Remote debugging using :4014 | 199 Remote debugging using :4014 |
221 0x000000000fa00080 in ?? () | 200 0x000000000fa00080 in ?? () |
222 </pre> | 201 </pre> |
223 <p>At this point, you can use the standard GDB commands to debug your NaCl modul
e. | 202 <p>At this point, you can use the standard GDB commands to debug your NaCl modul
e. |
224 The most common commands you will use to debug are <code>continue</code>, <code>
step</code>, | 203 The most common commands you will use to debug are <code>continue</code>, <code>
step</code>, |
225 <code>next</code>, <code>break</code> and <code>backtrace</code>. See | 204 <code>next</code>, <code>break</code> and <code>backtrace</code>. See |
226 <a class="reference internal" href="/native-client/devguide/devcycle/debugging.h
tml"><em>Debugging</em></a> for more information about | 205 <a class="reference internal" href="/native-client/devguide/devcycle/debugging.h
tml"><em>Debugging</em></a> for more information about |
227 debugging a Native Client application.</p> | 206 debugging a Native Client application.</p> |
228 </section> | 207 </section> |
229 | 208 |
230 {{/partials.standard_nacl_article}} | 209 {{/partials.standard_nacl_article}} |
OLD | NEW |