development.xml 41 KB

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