summaryrefslogtreecommitdiffstats
path: root/documentation/poky-ref-manual/development.xml
diff options
context:
space:
mode:
authorRichard Purdie <rpurdie@linux.intel.com>2010-10-15 11:55:59 +0100
committerRichard Purdie <rpurdie@linux.intel.com>2010-10-15 11:55:59 +0100
commit22083287912ebd552e33b79f7c567bc966376d43 (patch)
treea16fa012a97a249e25a405d4092b0a89321bfaf6 /documentation/poky-ref-manual/development.xml
parent13a702e9e572a2dc9f6b52a1531a2237d4d98ff1 (diff)
downloadpoky-22083287912ebd552e33b79f7c567bc966376d43.tar.gz
handbook: Move into documentation directory
Signed-off-by: Richard Purdie <rpurdie@linux.intel.com>
Diffstat (limited to 'documentation/poky-ref-manual/development.xml')
-rw-r--r--documentation/poky-ref-manual/development.xml825
1 files changed, 825 insertions, 0 deletions
diff --git a/documentation/poky-ref-manual/development.xml b/documentation/poky-ref-manual/development.xml
new file mode 100644
index 0000000000..a383a2f4a8
--- /dev/null
+++ b/documentation/poky-ref-manual/development.xml
@@ -0,0 +1,825 @@
1<!DOCTYPE chapter PUBLIC "-//OASIS//DTD DocBook XML V4.2//EN"
2"http://www.oasis-open.org/docbook/xml/4.2/docbookx.dtd">
3
4<chapter id="platdev">
5<title>Platform Development with Poky</title>
6
7<section id="platdev-appdev">
8 <title>Software development</title>
9 <para>
10 Poky supports several methods of software development. These different
11 forms of development are explained below and can be switched
12 between as needed.
13 </para>
14
15 <section id="platdev-appdev-external-sdk">
16 <title>Developing externally using the Poky SDK</title>
17
18 <para>
19 The meta-toolchain and meta-toolchain-sdk targets (<link linkend='ref-images'>see
20 the images section</link>) build tarballs which contain toolchains and
21 libraries suitable for application development outside Poky. These unpack into the
22 <filename class="directory">/opt/poky</filename> directory and contain
23 a setup script, e.g.
24 <filename>/opt/poky/environment-setup-i586-poky-linux</filename> which
25 can be sourced to initialise a suitable environment. After sourcing this, the
26 compiler, QEMU scripts, QEMU binary, a special version of pkgconfig and other
27 useful utilities are added to the PATH. Variables to assist pkgconfig and
28 autotools are also set so that, for example, configure can find pre-generated test
29 results for tests which need target hardware to run.
30 </para>
31
32 <para>
33 Using the toolchain with autotool enabled packages is straightforward, just pass the
34 appropriate host option to configure e.g. "./configure --host=arm-poky-linux-gnueabi".
35 For other projects it is usually a case of ensuring the cross tools are used e.g.
36 CC=arm-poky-linux-gnueabi-gcc and LD=arm-poky-linux-gnueabi-ld.
37 </para>
38 </section>
39
40 <section id="platdev-appdev-external-anjuta">
41 <title>Developing externally using the Anjuta plugin</title>
42
43 <para>
44 An Anjuta IDE plugin exists to make developing software within the Poky framework
45 easier for the application developer. It presents a graphical IDE from which the
46 developer can cross compile an application then deploy and execute the output in a QEMU
47 emulation session. It also supports cross debugging and profiling.
48 </para>
49<!-- DISBALED, TOO BIG!
50 <screenshot>
51 <mediaobject>
52 <imageobject>
53 <imagedata fileref="screenshots/ss-anjuta-poky-1.png" format="PNG"/>
54 </imageobject>
55 <caption>
56 <para>The Anjuta Poky SDK plugin showing an active QEMU session running Sato</para>
57 </caption>
58 </mediaobject>
59 </screenshot>
60-->
61 <para>
62 To use the plugin, a toolchain and SDK built by Poky is required along with Anjuta it's development
63 headers and the Anjuta plugin. The Poky Anjuta plugin is available to download as a tarball at the
64 <ulink url='http://labs.o-hand.com/anjuta-poky-sdk-plugin/'>OpenedHand labs</ulink> page or
65 directly from the Poky Git repository located at git://git.pokylinux.org/anjuta-poky; a web interface
66 to the repository can be accessed at <ulink url='http://git.pokylinux.org/?p=anjuta-poky.git;a=summary'/>.
67 </para>
68 <para>
69 See the README file contained in the project for more information on dependencies and building
70 the plugin. If you want to disable remote gdb debugging, please pass --diable-gdb-integration
71 switch when doing configure.
72 </para>
73
74 <section id="platdev-appdev-external-anjuta-setup">
75 <title>Setting up the Anjuta plugin</title>
76
77 <para>Extract the tarball for the toolchain into / as root. The
78 toolchain will be installed into
79 <filename class="directory">/opt/poky</filename>.</para>
80
81 <para>To use the plugin, first open or create an existing
82 project. If creating a new project the "C GTK+" project type
83 will allow itself to be cross-compiled. However you should be
84 aware that this uses glade for the UI.</para>
85
86 <para>To activate the plugin go to
87 <menuchoice><guimenu>Edit</guimenu><guimenuitem>Preferences</guimenuitem></menuchoice>,
88 then choose <guilabel>General</guilabel> from the left hand side. Choose the
89 Installed plugins tab, scroll down to <guilabel>Poky
90 SDK</guilabel> and check the
91 box. The plugin is now activated but first it must be
92 configured.</para>
93 </section>
94
95 <section id="platdev-appdev-external-anjuta-configuration">
96 <title>Configuring the Anjuta plugin</title>
97
98 <para>The configuration options for the SDK can be found by choosing
99 the <guilabel>Poky SDK</guilabel> icon from the left hand side. The following options
100 need to be set:</para>
101
102 <itemizedlist>
103
104 <listitem><para><guilabel>SDK root</guilabel>: If we use external toolchain, we need to set SDK root.
105 this is the root directory of the SDK's sysroot. For an i586 SDK this will be <filename
106 class="directory">/opt/poky/</filename>.
107 This directory will contain directories named like "bin",
108 "include", "var", etc. under your selected target architecture subdirectory<filename class="directory">
109 /opt/poky/sysroot/i586-poky-linux/</filename>. Needed cross compile tools are under
110 <filename class ="directory">/opt/poky/sysroot/i586-pokysdk-linux/</filename>
111 </para></listitem>
112
113 <listitem><para><guilabel>Poky root</guilabel>: If we have local poky build tree, we need to set the Poky root.
114 this is the root directory of the poky build tree, if you build your i586 target architecture
115 under the subdirectory of build_x86 within your poky tree, the Poky root directory should be
116 <filename class="directory">${Poky_tree}/build_x86/</filename>.
117 </para></listitem>
118
119 <listitem><para><guilabel>Target Architecture</guilabel>: this is the cross compile
120 triplet, e.g. "i586-poky-linux". This target triplet is the prefix extracted from
121 the set up script file name. For examle, "i586-poky-linux" is extracted from set up script file
122 <filename>/opt/poky/environment-setup-i586-poky-linux</filename>
123 </para></listitem>
124
125 <listitem><para><guilabel>Kernel</guilabel>: use the file chooser to select the kernel
126 to use with QEMU</para></listitem>
127
128 <listitem><para><guilabel>Root filesystem</guilabel>: use the file chooser to select
129 the root filesystem directory, this is the directory where you use "poky-extract-sdk" command to
130 extract the poky-image-sdk tarball.</para></listitem>
131 </itemizedlist>
132<!-- DISBALED, TOO BIG!
133 <screenshot>
134 <mediaobject>
135 <imageobject>
136 <imagedata fileref="screenshots/ss-anjuta-poky-2.png" format="PNG"/>
137 </imageobject>
138 <caption>
139 <para>Anjuta Preferences Dialog</para>
140 </caption>
141 </mediaobject>
142 </screenshot>
143-->
144
145 </section>
146
147 <section id="platdev-appdev-external-anjuta-usage">
148 <title>Using the Anjuta plugin</title>
149
150 <para>As an example, cross-compiling a project, deploying it into
151 QEMU and running a debugger against it and then doing a system
152 wide profile.</para>
153
154 <para>Choose <menuchoice><guimenu>Build</guimenu><guimenuitem>Run
155 Configure</guimenuitem></menuchoice> or
156 <menuchoice><guimenu>Build</guimenu><guimenuitem>Run
157 Autogenerate</guimenuitem></menuchoice> to run "configure"
158 (or to run "autogen") for the project. This passes command line
159 arguments to instruct it to cross-compile.</para>
160
161 <para>Next do
162 <menuchoice><guimenu>Build</guimenu><guimenuitem>Build
163 Project</guimenuitem></menuchoice> to build and compile the
164 project. If you have previously built the project in the same
165 tree without using the cross-compiler you may find that your
166 project fails to link. Simply do
167 <menuchoice><guimenu>Build</guimenu><guimenuitem>Clean
168 Project</guimenuitem></menuchoice> to remove the old
169 binaries. You may then try building again.</para>
170
171 <para>Next start QEMU by using
172 <menuchoice><guimenu>Tools</guimenu><guimenuitem>Start
173 QEMU</guimenuitem></menuchoice>, this will start QEMU and
174 will show any error messages in the message view. Once Poky has
175 fully booted within QEMU you may now deploy into it.</para>
176
177 <para>Once built and QEMU is running, choose
178 <menuchoice><guimenu>Tools</guimenu><guimenuitem>Deploy</guimenuitem></menuchoice>,
179 this will install the package into a temporary directory and
180 then copy using rsync over SSH into the target. Progress and
181 messages will be shown in the message view.</para>
182
183 <para>To debug a program installed into onto the target choose
184 <menuchoice><guimenu>Tools</guimenu><guimenuitem>Debug
185 remote</guimenuitem></menuchoice>. This prompts for the
186 local binary to debug and also the command line to run on the
187 target. The command line to run should include the full path to
188 the to binary installed in the target. This will start a
189 gdbserver over SSH on the target and also an instance of a
190 cross-gdb in a local terminal. This will be preloaded to connect
191 to the server and use the <guilabel>SDK root</guilabel> to find
192 symbols. This gdb will connect to the target and load in
193 various libraries and the target program. You should setup any
194 breakpoints or watchpoints now since you might not be able to
195 interrupt the execution later. You may stop
196 the debugger on the target using
197 <menuchoice><guimenu>Tools</guimenu><guimenuitem>Stop
198 debugger</guimenuitem></menuchoice>.</para>
199
200 <para>It is also possible to execute a command in the target over
201 SSH, the appropriate environment will be be set for the
202 execution. Choose
203 <menuchoice><guimenu>Tools</guimenu><guimenuitem>Run
204 remote</guimenuitem></menuchoice> to do this. This will open
205 a terminal with the SSH command inside.</para>
206
207 <para>To do a system wide profile against the system running in
208 QEMU choose
209 <menuchoice><guimenu>Tools</guimenu><guimenuitem>Profile
210 remote</guimenuitem></menuchoice>. This will start up
211 OProfileUI with the appropriate parameters to connect to the
212 server running inside QEMU and will also supply the path to the
213 debug information necessary to get a useful profile.</para>
214
215 </section>
216 </section>
217
218
219 <section id="platdev-appdev-qemu">
220 <title>Developing externally in QEMU</title>
221 <para>
222 Running Poky QEMU images is covered in the <link
223 linkend='intro-quickstart-qemu'>Running an Image</link> section.
224 </para>
225 <para>
226 Poky's QEMU images contain a complete native toolchain. This means
227 that applications can be developed within QEMU in the same was as a
228 normal system. Using qemux86 on an x86 machine is fast since the
229 guest and host architectures match, qemuarm is slower but gives
230 faithful emulation of ARM specific issues. To speed things up these
231 images support using distcc to call a cross-compiler outside the
232 emulated system too. If <command>runqemu</command> was used to start
233 QEMU, and distccd is present on the host system, any bitbake cross
234 compiling toolchain available from the build system will automatically
235 be used from within qemu simply by calling distcc
236 (<command>export CC="distcc"</command> can be set in the enviroment).
237 Alterntatively, if a suitable SDK/toolchain is present in
238 <filename class="directory">/opt/poky</filename> it will also
239 automatically be used.
240 </para>
241
242 <para>
243 There are several options for connecting into the emulated system.
244 QEMU provides a framebuffer interface which has standard consoles
245 available. There is also a serial connection available which has a
246 console to the system running on it and IP networking as standard.
247 The images have a dropbear ssh server running with the root password
248 disabled allowing standard ssh and scp commands to work. The images
249 also contain an NFS server exporting the guest's root filesystem
250 allowing that to be made available to the host.
251 </para>
252 </section>
253
254 <section id="platdev-appdev-insitu">
255 <title>Developing in Poky directly</title>
256 <para>
257 Working directly in Poky is a fast and effective development technique.
258 The idea is that you can directly edit files in
259 <glossterm><link linkend='var-WORKDIR'>WORKDIR</link></glossterm>
260 or the source directory <glossterm><link linkend='var-S'>S</link></glossterm>
261 and then force specific tasks to rerun in order to test the changes.
262 An example session working on the matchbox-desktop package might
263 look like this:
264 </para>
265
266 <para>
267 <literallayout class='monospaced'>
268$ bitbake matchbox-desktop
269$ sh
270$ cd tmp/work/armv5te-poky-linux-gnueabi/matchbox-desktop-2.0+svnr1708-r0/
271$ cd matchbox-desktop-2
272$ vi src/main.c
273$ exit
274$ bitbake matchbox-desktop -c compile -f
275$ bitbake matchbox-desktop
276</literallayout>
277 </para>
278
279 <para>
280 Here, we build the package, change into the work directory for the package,
281 change a file, then recompile the package. Instead of using sh like this,
282 you can also use two different terminals. The risk with working like this
283 is that a command like unpack could wipe out the changes you've made to the
284 work directory so you need to work carefully.
285 </para>
286
287 <para>
288 It is useful when making changes directly to the work directory files to do
289 so using quilt as detailed in the <link linkend='usingpoky-modifying-packages-quilt'>
290 modifying packages with quilt</link> section. The resulting patches can be copied
291 into the recipe directory and used directly in the <glossterm><link
292 linkend='var-SRC_URI'>SRC_URI</link></glossterm>.
293 </para>
294 <para>
295 For a review of the skills used in this section see Sections <link
296 linkend="usingpoky-components-bitbake">2.1.1</link> and <link
297 linkend="usingpoky-debugging-taskrunning">2.4.2</link>.
298 </para>
299
300 </section>
301
302 <section id="platdev-appdev-devshell">
303 <title>Developing with 'devshell'</title>
304
305 <para>
306 When debugging certain commands or even to just edit packages, the
307 'devshell' can be a useful tool. To start it you run a command like:
308 </para>
309
310 <para>
311 <literallayout class='monospaced'>
312$ bitbake matchbox-desktop -c devshell
313</literallayout>
314 </para>
315
316 <para>
317 which will open a terminal with a shell prompt within the Poky
318 environment. This means PATH is setup to include the cross toolchain,
319 the pkgconfig variables are setup to find the right .pc files,
320 configure will be able to find the Poky site files etc. Within this
321 environment, you can run configure or compile command as if they
322 were being run by Poky itself. You are also changed into the
323 source (<glossterm><link linkend='var-S'>S</link></glossterm>)
324 directory automatically. When finished with the shell just exit it
325 or close the terminal window.
326 </para>
327
328 <para>
329 The default shell used by devshell is the gnome-terminal. Other
330 forms of terminal can also be used by setting the <glossterm>
331 <link linkend='var-TERMCMD'>TERMCMD</link></glossterm> and <glossterm>
332 <link linkend='var-TERMCMDRUN'>TERMCMDRUN</link></glossterm> variables
333 in local.conf. For examples of the other options available, see
334 <filename>meta/conf/bitbake.conf</filename>. An external shell is
335 launched rather than opening directly into the original terminal
336 window to make interaction with bitbakes multiple threads easier
337 and also allow a client/server split of bitbake in the future
338 (devshell will still work over X11 forwarding or similar).
339 </para>
340
341 <para>
342 It is worth remembering that inside devshell you need to use the full
343 compiler name such as <command>arm-poky-linux-gnueabi-gcc</command>
344 instead of just <command>gcc</command> and the same applies to other
345 applications from gcc, bintuils, libtool etc. Poky will have setup
346 environmental variables such as CC to assist applications, such as make,
347 find the correct tools.
348 </para>
349
350 </section>
351
352 <section id="platdev-appdev-srcrev">
353 <title>Developing within Poky with an external SCM based package</title>
354
355 <para>
356 If you're working on a recipe which pulls from an external SCM it
357 is possible to have Poky notice new changes added to the
358 SCM and then build the latest version. This only works for SCMs
359 where its possible to get a sensible revision number for changes.
360 Currently it works for svn, git and bzr repositories.
361 </para>
362
363 <para>
364 To enable this behaviour it is simply a case of adding <glossterm>
365 <link linkend='var-SRCREV'>SRCREV</link></glossterm>_pn-<glossterm>
366 <link linkend='var-PN'>PN</link></glossterm> = "${AUTOREV}" to
367 local.conf where <glossterm><link linkend='var-PN'>PN</link></glossterm>
368 is the name of the package for which you want to enable automatic source
369 revision updating.
370 </para>
371 </section>
372
373 </section>
374
375<section id="platdev-gdb-remotedebug">
376 <title>Debugging with GDB Remotely</title>
377
378 <para>
379 <ulink url="http://sourceware.org/gdb/">GDB</ulink> (The GNU Project Debugger)
380 allows you to examine running programs to understand and fix problems and
381 also to perform postmortem style analsys of program crashes. It is available
382 as a package within poky and installed by default in sdk images. It works best
383 when -dbg packages for the application being debugged are installed as the
384 extra symbols give more meaningful output from GDB.
385 </para>
386
387 <para>
388 Sometimes, due to memory or disk space constraints, it is not possible
389 to use GDB directly on the remote target to debug applications. This is
390 due to the fact that
391 GDB needs to load the debugging information and the binaries of the
392 process being debugged. GDB then needs to perform many
393 computations to locate information such as function names, variable
394 names and values, stack traces, etc. even before starting the debugging
395 process. This places load on the target system and can alter the
396 characteristics of the program being debugged.
397 </para>
398 <para>
399 This is where GDBSERVER comes into play as it runs on the remote target
400 and does not load any debugging information from the debugged process.
401 Instead, the debugging information processing is done by a GDB instance
402 running on a distant computer - the host GDB. The host GDB then sends
403 control commands to GDBSERVER to make it stop or start the debugged
404 program, as well as read or write some memory regions of that debugged
405 program. All the debugging information loading and processing as well
406 as the heavy debugging duty is done by the host GDB, giving the
407 GDBSERVER running on the target a chance to remain small and fast.
408 </para>
409 <para>
410 As the host GDB is responsible for loading the debugging information and
411 doing the necessary processing to make actual debugging happen, the
412 user has to make sure it can access the unstripped binaries complete
413 with their debugging information and compiled with no optimisations. The
414 host GDB must also have local access to all the libraries used by the
415 debugged program. On the remote target the binaries can remain stripped
416 as GDBSERVER does not need any debugging information there. However they
417 must also be compiled without optimisation matching the host's binaries.
418 </para>
419
420 <para>
421 The binary being debugged on the remote target machine is hence referred
422 to as the 'inferior' in keeping with GDB documentation and terminology.
423 Further documentation on GDB, is available on
424 <ulink url="http://sourceware.org/gdb/documentation/">on their site</ulink>.
425 </para>
426
427 <section id="platdev-gdb-remotedebug-launch-gdbserver">
428 <title>Launching GDBSERVER on the target</title>
429 <para>
430 First, make sure gdbserver is installed on the target. If not,
431 install the gdbserver package (which needs the libthread-db1
432 package).
433 </para>
434 <para>
435 To launch GDBSERVER on the target and make it ready to "debug" a
436 program located at <emphasis>/path/to/inferior</emphasis>, connect
437 to the target and launch:
438 <programlisting>$ gdbserver localhost:2345 /path/to/inferior</programlisting>
439 After that, gdbserver should be listening on port 2345 for debugging
440 commands coming from a remote GDB process running on the host computer.
441 Communication between the GDBSERVER and the host GDB will be done using
442 TCP. To use other communication protocols please refer to the
443 GDBSERVER documentation.
444 </para>
445 </section>
446
447 <section id="platdev-gdb-remotedebug-launch-gdb">
448 <title>Launching GDB on the host computer</title>
449
450 <para>
451 Running GDB on the host computer takes a number of stages, described in the
452 following sections.
453 </para>
454
455 <section id="platdev-gdb-remotedebug-launch-gdb-buildcross">
456 <title>Build the cross GDB package</title>
457 <para>
458 A suitable gdb cross binary is required which runs on your host computer but
459 knows about the the ABI of the remote target. This can be obtained from
460 the the Poky toolchain, e.g.
461 <filename>/opt/poky/sysroots/x86_64-pokysdk-linux/usr/bin/armv5te-poky-linux-gnueabi/arm-poky-linux-gnueabi-gdb</filename>
462 which "x86_64" is the host architecture, "arm" is the target architecture and "linux-gnueabi" the target ABI.
463 </para>
464
465 <para>
466 Alternatively this can be built directly by Poky. To do this you would build
467 the gdb-cross package so for example you would run:
468 <programlisting>bitbake gdb-cross</programlisting>
469 Once built, the cross gdb binary can be found at
470 <programlisting>tmp/sysroots/&lt;host-arch&gt;/usr/bin/\
471&lt;target-arch&gt;-poky-&lt;target-abi&gt;/&lt;target-arch&gt;-poky-&lt;target-abi&gt;-gdb </programlisting>
472 </para>
473
474 </section>
475 <section id="platdev-gdb-remotedebug-launch-gdb-inferiorbins">
476
477 <title>Making the inferior binaries available</title>
478
479 <para>
480 The inferior binary needs to be available to GDB complete with all debugging
481 symbols in order to get the best possible results along with any libraries
482 the inferior depends on and their debugging symbols. There are a number of
483 ways this can be done.
484 </para>
485
486 <para>
487 Perhaps the easiest is to have an 'sdk' image corresponding to the plain
488 image installed on the device. In the case of 'pky-image-sato',
489 'poky-image-sdk' would contain suitable symbols. The sdk images already
490 have the debugging symbols installed so its just a question expanding the
491 archive to some location and telling GDB where this is.
492 </para>
493
494 <para>
495 Alternatively, poky can build a custom directory of files for a specific
496 debugging purpose by reusing its tmp/rootfs directory, on the host computer
497 in a slightly different way to normal. This directory contains the contents
498 of the last built image. This process assumes the image running on the
499 target was the last image to be built by Poky, the package <emphasis>foo</emphasis>
500 contains the inferior binary to be debugged has been built without without
501 optimisation and has debugging information available.
502 </para>
503 <para>
504 Firstly you want to install the <emphasis>foo</emphasis> package to tmp/rootfs
505 by doing:
506 </para>
507 <programlisting>tmp/sysroots/i686-linux/usr/bin/opkg-cl -f \
508tmp/work/&lt;target-abi&gt;/poky-image-sato-1.0-r0/opkg.conf -o \
509tmp/rootfs/ update</programlisting>
510 <para>
511 then,
512 </para>
513 <programlisting>tmp/sysroots/i686-linux/usr/bin/opkg-cl -f \
514tmp/work/&lt;target-abi&gt;/poky-image-sato-1.0-r0/opkg.conf \
515-o tmp/rootfs install foo
516
517tmp/sysroots/i686-linux/usr/bin/opkg-cl -f \
518tmp/work/&lt;target-abi&gt;/poky-image-sato-1.0-r0/opkg.conf \
519-o tmp/rootfs install foo-dbg</programlisting>
520 <para>
521 which installs the debugging information too.
522 </para>
523
524 </section>
525 <section id="platdev-gdb-remotedebug-launch-gdb-launchhost">
526
527 <title>Launch the host GDB</title>
528 <para>
529 To launch the host GDB, run the cross gdb binary identified above with
530 the inferior binary specified on the commandline:
531 <programlisting>&lt;target-arch&gt;-poky-&lt;target-abi&gt;-gdb rootfs/usr/bin/foo</programlisting>
532 This loads the binary of program <emphasis>foo</emphasis>
533 as well as its debugging information. Once the gdb prompt
534 appears, you must instruct GDB to load all the libraries
535 of the inferior from tmp/rootfs:
536 <programlisting>set solib-absolute-prefix /path/to/tmp/rootfs</programlisting>
537 where <filename>/path/to/tmp/rootfs</filename> must be
538 the absolute path to <filename>tmp/rootfs</filename> or wherever the
539 binaries with debugging information are located.
540 </para>
541 <para>
542 Now, tell GDB to connect to the GDBSERVER running on the remote target:
543 <programlisting>target remote remote-target-ip-address:2345</programlisting>
544 Where remote-target-ip-address is the IP address of the
545 remote target where the GDBSERVER is running. 2345 is the
546 port on which the GDBSERVER is running.
547 </para>
548
549 </section>
550 <section id="platdev-gdb-remotedebug-launch-gdb-using">
551
552 <title>Using the Debugger</title>
553 <para>
554 Debugging can now proceed as normal, as if the debugging were being done on the
555 local machine, for example to tell GDB to break in the <emphasis>main</emphasis>
556 function, for instance:
557 <programlisting>break main</programlisting>
558 and then to tell GDB to "continue" the inferior execution,
559 <programlisting>continue</programlisting>
560 </para>
561 <para>
562 For more information about using GDB please see the
563 project's online documentation at <ulink
564 url="http://sourceware.org/gdb/download/onlinedocs/"/>.
565 </para>
566 </section>
567 </section>
568
569</section>
570
571<section id="platdev-oprofile">
572 <title>Profiling with OProfile</title>
573
574 <para>
575 <ulink url="http://oprofile.sourceforge.net/">OProfile</ulink> is a
576 statistical profiler well suited to finding performance
577 bottlenecks in both userspace software and the kernel. It provides
578 answers to questions like "Which functions does my application spend
579 the most time in when doing X?". Poky is well integrated with OProfile
580 to make profiling applications on target hardware straightforward.
581 </para>
582
583 <para>
584 To use OProfile you need an image with OProfile installed. The easiest
585 way to do this is with "tools-profile" in <glossterm><link
586 linkend='var-IMAGE_FEATURES'>IMAGE_FEATURES</link></glossterm>. You also
587 need debugging symbols to be available on the system where the analysis
588 will take place. This can be achieved with "dbg-pkgs" in <glossterm><link
589 linkend='var-IMAGE_FEATURES'>IMAGE_FEATURES</link></glossterm> or by
590 installing the appropriate -dbg packages. For
591 successful call graph analysis the binaries must preserve the frame
592 pointer register and hence should be compiled with the
593 "-fno-omit-framepointer" flag. In Poky this can be achieved with
594 <glossterm><link linkend='var-SELECTED_OPTIMIZATION'>SELECTED_OPTIMIZATION
595 </link></glossterm> = "-fexpensive-optimizations -fno-omit-framepointer
596 -frename-registers -O2" or by setting <glossterm><link
597 linkend='var-DEBUG_BUILD'>DEBUG_BUILD</link></glossterm> = "1" in
598 local.conf (the latter will also add extra debug information making the
599 debug packages large).
600 </para>
601
602 <section id="platdev-oprofile-target">
603 <title>Profiling on the target</title>
604
605 <para>
606 All the profiling work can be performed on the target device. A
607 simple OProfile session might look like:
608 </para>
609
610 <para>
611 <literallayout class='monospaced'>
612# opcontrol --reset
613# opcontrol --start --separate=lib --no-vmlinux -c 5
614[do whatever is being profiled]
615# opcontrol --stop
616$ opreport -cl
617</literallayout>
618 </para>
619
620 <para>
621 Here, the reset command clears any previously profiled data,
622 OProfile is then started. The options used to start OProfile mean
623 dynamic library data is kept separately per application, kernel
624 profiling is disabled and callgraphing is enabled up to 5 levels
625 deep. To profile the kernel, you would specify the
626 <parameter>--vmlinux=/path/to/vmlinux</parameter> option (the vmlinux file is usually in
627 <filename class="directory">/boot/</filename> in Poky and must match the running kernel). The profile is
628 then stopped and the results viewed with opreport with options
629 to see the separate library symbols and callgraph information.
630 </para>
631 <para>
632 Callgraphing means OProfile not only logs infomation about which
633 functions time is being spent in but also which functions
634 called those functions (their parents) and which functions that
635 function calls (its children). The higher the callgraphing depth,
636 the more accurate the results but this also increased the loging
637 overhead so it should be used with caution. On ARM, binaries need
638 to have the frame pointer enabled for callgraphing to work (compile
639 with the gcc option -fno-omit-framepointer).
640 </para>
641 <para>
642 For more information on using OProfile please see the OProfile
643 online documentation at <ulink
644 url="http://oprofile.sourceforge.net/docs/"/>.
645 </para>
646 </section>
647
648 <section id="platdev-oprofile-oprofileui">
649 <title>Using OProfileUI</title>
650
651 <para>
652 A graphical user interface for OProfile is also available. You can
653 either use prebuilt Debian packages from the <ulink
654 url='http://debian.o-hand.com/'>OpenedHand repository</ulink> or
655 download and build from svn at
656 http://svn.o-hand.com/repos/oprofileui/trunk/. If the
657 "tools-profile" image feature is selected, all necessary binaries
658 are installed onto the target device for OProfileUI interaction.
659 </para>
660
661<!-- DISBALED, Need a more 'contexual' shot?
662 <screenshot>
663 <mediaobject>
664 <imageobject>
665 <imagedata fileref="screenshots/ss-oprofile-viewer.png" format="PNG"/>
666 </imageobject>
667 <caption>
668 <para>OProfileUI Viewer showing an application being profiled on a remote device</para>
669 </caption>
670 </mediaobject>
671 </screenshot>
672-->
673 <para>
674 In order to convert the data in the sample format from the target
675 to the host the <filename>opimport</filename> program is needed.
676 This is not included in standard Debian OProfile packages but an
677 OProfile package with this addition is also available from the <ulink
678 url='http://debian.o-hand.com/'>OpenedHand repository</ulink>.
679 We recommend using OProfile 0.9.3 or greater. Other patches to
680 OProfile may be needed for recent OProfileUI features, but Poky
681 usually includes all needed patches on the target device. Please
682 see the <ulink
683 url='http://svn.o-hand.com/repos/oprofileui/trunk/README'>
684 OProfileUI README</ulink> for up to date information, and the
685 <ulink url="http://labs.o-hand.com/oprofileui">OProfileUI website
686 </ulink> for more information on the OProfileUI project.
687 </para>
688
689 <section id="platdev-oprofile-oprofileui-online">
690 <title>Online mode</title>
691
692 <para>
693 This assumes a working network connection with the target
694 hardware. In this case you just need to run <command>
695 "oprofile-server"</command> on the device. By default it listens
696 on port 4224. This can be changed with the <parameter>--port</parameter> command line
697 option.
698
699 </para>
700
701 <para>
702 The client program is called <command>oprofile-viewer</command>. The
703 UI is relatively straightforward, the key functionality is accessed
704 through the buttons on the toolbar (which are duplicated in the
705 menus.) These buttons are:
706 </para>
707
708 <itemizedlist>
709 <listitem>
710 <para>
711 Connect - connect to the remote host, the IP address or hostname for the
712 target can be supplied here.
713 </para>
714 </listitem>
715 <listitem>
716 <para>
717 Disconnect - disconnect from the target.
718 </para>
719 </listitem>
720 <listitem>
721 <para>
722 Start - start the profiling on the device.
723 </para>
724 </listitem>
725 <listitem>
726 <para>
727 Stop - stop the profiling on the device and download the data to the local
728 host. This will generate the profile and show it in the viewer.
729 </para>
730 </listitem>
731 <listitem>
732 <para>
733 Download - download the data from the target, generate the profile and show it
734 in the viewer.
735 </para>
736 </listitem>
737 <listitem>
738 <para>
739 Reset - reset the sample data on the device. This will remove the sample
740 information that was collected on a previous sampling run. Ensure you do this
741 if you do not want to include old sample information.
742 </para>
743 </listitem>
744 <listitem>
745 <para>
746 Save - save the data downloaded from the target to another directory for later
747 examination.
748 </para>
749 </listitem>
750 <listitem>
751 <para>
752 Open - load data that was previously saved.
753 </para>
754 </listitem>
755 </itemizedlist>
756
757 <para>
758 The behaviour of the client is to download the complete 'profile archive' from
759 the target to the host for processing. This archive is a directory containing
760 the sample data, the object files and the debug information for said object
761 files. This archive is then converted using a script included in this
762 distribution ('oparchconv') that uses 'opimport' to convert the archive from
763 the target to something that can be processed on the host.
764 </para>
765
766 <para>
767 Downloaded archives are kept in /tmp and cleared up when they are no longer in
768 use.
769 </para>
770
771 <para>
772 If you wish to profile into the kernel, this is possible, you just need to ensure
773 a vmlinux file matching the running kernel is available. In Poky this is usually
774 located in /boot/vmlinux-KERNELVERSION, where KERNEL-version is the version of
775 the kernel e.g. 2.6.23. Poky generates separate vmlinux packages for each kernel
776 it builds so it should be a question of just ensuring a matching package is
777 installed (<command> opkg install kernel-vmlinux</command>. These are automatically
778 installed into development and profiling images alongside OProfile. There is a
779 configuration option within the OProfileUI settings page where the location of
780 the vmlinux file can be entered.
781 </para>
782
783 <para>
784 Waiting for debug symbols to transfer from the device can be slow and it's not
785 always necessary to actually have them on device for OProfile use. All that is
786 needed is a copy of the filesystem with the debug symbols present on the viewer
787 system. The <link linkend='platdev-gdb-remotedebug-launch-gdb'>GDB remote debug
788 section</link> covers how to create such a directory with Poky and the location
789 of this directory can again be specified in the OProfileUI settings dialog. If
790 specified, it will be used where the file checksums match those on the system
791 being profiled.
792 </para>
793 </section>
794 <section id="platdev-oprofile-oprofileui-offline">
795 <title>Offline mode</title>
796
797 <para>
798 If no network access to the target is available an archive for processing in
799 'oprofile-viewer' can be generated with the following set of command.
800 </para>
801
802 <para>
803 <literallayout class='monospaced'>
804# opcontrol --reset
805# opcontrol --start --separate=lib --no-vmlinux -c 5
806[do whatever is being profiled]
807# opcontrol --stop
808# oparchive -o my_archive
809</literallayout>
810 </para>
811
812 <para>
813 Where my_archive is the name of the archive directory where you would like the
814 profile archive to be kept. The directory will be created for you. This can
815 then be copied to another host and loaded using 'oprofile-viewer''s open
816 functionality. The archive will be converted if necessary.
817 </para>
818 </section>
819 </section>
820</section>
821
822</chapter>
823<!--
824vim: expandtab tw=80 ts=4
825-->