development.xml 41 KB

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