debugging.rst 50 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249
  1. .. SPDX-License-Identifier: CC-BY-SA-2.0-UK
  2. Debugging Tools and Techniques
  3. ******************************
  4. The exact method for debugging build failures depends on the nature of
  5. the problem and on the system's area from which the bug originates.
  6. Standard debugging practices such as comparison against the last known
  7. working version with examination of the changes and the re-application
  8. of steps to identify the one causing the problem are valid for the Yocto
  9. Project just as they are for any other system. Even though it is
  10. impossible to detail every possible potential failure, this section
  11. provides some general tips to aid in debugging given a variety of
  12. situations.
  13. .. note::
  14. A useful feature for debugging is the error reporting tool.
  15. Configuring the Yocto Project to use this tool causes the
  16. OpenEmbedded build system to produce error reporting commands as part
  17. of the console output. You can enter the commands after the build
  18. completes to log error information into a common database, that can
  19. help you figure out what might be going wrong. For information on how
  20. to enable and use this feature, see the
  21. ":ref:`dev-manual/error-reporting-tool:using the error reporting tool`"
  22. section.
  23. The following list shows the debugging topics in the remainder of this
  24. section:
  25. - ":ref:`dev-manual/debugging:viewing logs from failed tasks`" describes
  26. how to find and view logs from tasks that failed during the build
  27. process.
  28. - ":ref:`dev-manual/debugging:viewing variable values`" describes how to
  29. use the BitBake ``-e`` option to examine variable values after a
  30. recipe has been parsed.
  31. - ":ref:`dev-manual/debugging:viewing package information with \`\`oe-pkgdata-util\`\``"
  32. describes how to use the ``oe-pkgdata-util`` utility to query
  33. :term:`PKGDATA_DIR` and
  34. display package-related information for built packages.
  35. - ":ref:`dev-manual/debugging:viewing dependencies between recipes and tasks`"
  36. describes how to use the BitBake ``-g`` option to display recipe
  37. dependency information used during the build.
  38. - ":ref:`dev-manual/debugging:viewing task variable dependencies`" describes
  39. how to use the ``bitbake-dumpsig`` command in conjunction with key
  40. subdirectories in the :term:`Build Directory` to determine variable
  41. dependencies.
  42. - ":ref:`dev-manual/debugging:running specific tasks`" describes
  43. how to use several BitBake options (e.g. ``-c``, ``-C``, and ``-f``)
  44. to run specific tasks in the build chain. It can be useful to run
  45. tasks "out-of-order" when trying isolate build issues.
  46. - ":ref:`dev-manual/debugging:general BitBake problems`" describes how
  47. to use BitBake's ``-D`` debug output option to reveal more about what
  48. BitBake is doing during the build.
  49. - ":ref:`dev-manual/debugging:building with no dependencies`"
  50. describes how to use the BitBake ``-b`` option to build a recipe
  51. while ignoring dependencies.
  52. - ":ref:`dev-manual/debugging:recipe logging mechanisms`"
  53. describes how to use the many recipe logging functions to produce
  54. debugging output and report errors and warnings.
  55. - ":ref:`dev-manual/debugging:debugging parallel make races`"
  56. describes how to debug situations where the build consists of several
  57. parts that are run simultaneously and when the output or result of
  58. one part is not ready for use with a different part of the build that
  59. depends on that output.
  60. - ":ref:`dev-manual/debugging:debugging with the gnu project debugger (gdb) remotely`"
  61. describes how to use GDB to allow you to examine running programs, which can
  62. help you fix problems.
  63. - ":ref:`dev-manual/debugging:debugging with the gnu project debugger (gdb) on the target`"
  64. describes how to use GDB directly on target hardware for debugging.
  65. - ":ref:`dev-manual/debugging:other debugging tips`" describes
  66. miscellaneous debugging tips that can be useful.
  67. Viewing Logs from Failed Tasks
  68. ==============================
  69. You can find the log for a task in the file
  70. ``${``\ :term:`WORKDIR`\ ``}/temp/log.do_``\ `taskname`.
  71. For example, the log for the
  72. :ref:`ref-tasks-compile` task of the
  73. QEMU minimal image for the x86 machine (``qemux86``) might be in
  74. ``tmp/work/qemux86-poky-linux/core-image-minimal/1.0-r0/temp/log.do_compile``.
  75. To see the commands :term:`BitBake` ran
  76. to generate a log, look at the corresponding ``run.do_``\ `taskname` file
  77. in the same directory.
  78. ``log.do_``\ `taskname` and ``run.do_``\ `taskname` are actually symbolic
  79. links to ``log.do_``\ `taskname`\ ``.``\ `pid` and
  80. ``log.run_``\ `taskname`\ ``.``\ `pid`, where `pid` is the PID the task had
  81. when it ran. The symlinks always point to the files corresponding to the
  82. most recent run.
  83. Viewing Variable Values
  84. =======================
  85. Sometimes you need to know the value of a variable as a result of
  86. BitBake's parsing step. This could be because some unexpected behavior
  87. occurred in your project. Perhaps an attempt to :ref:`modify a variable
  88. <bitbake:bitbake-user-manual/bitbake-user-manual-metadata:modifying existing
  89. variables>` did not work out as expected.
  90. BitBake's ``-e`` option is used to display variable values after
  91. parsing. The following command displays the variable values after the
  92. configuration files (i.e. ``local.conf``, ``bblayers.conf``,
  93. ``bitbake.conf`` and so forth) have been parsed::
  94. $ bitbake -e
  95. The following command displays variable values after a specific recipe has
  96. been parsed. The variables include those from the configuration as well::
  97. $ bitbake -e recipename
  98. .. note::
  99. Each recipe has its own private set of variables (datastore).
  100. Internally, after parsing the configuration, a copy of the resulting
  101. datastore is made prior to parsing each recipe. This copying implies
  102. that variables set in one recipe will not be visible to other
  103. recipes.
  104. Likewise, each task within a recipe gets a private datastore based on
  105. the recipe datastore, which means that variables set within one task
  106. will not be visible to other tasks.
  107. In the output of ``bitbake -e``, each variable is preceded by a
  108. description of how the variable got its value, including temporary
  109. values that were later overridden. This description also includes
  110. variable flags (varflags) set on the variable. The output can be very
  111. helpful during debugging.
  112. Variables that are exported to the environment are preceded by
  113. ``export`` in the output of ``bitbake -e``. See the following example::
  114. export CC="i586-poky-linux-gcc -m32 -march=i586 --sysroot=/home/ulf/poky/build/tmp/sysroots/qemux86"
  115. In addition to variable values, the output of the ``bitbake -e`` and
  116. ``bitbake -e`` recipe commands includes the following information:
  117. - The output starts with a tree listing all configuration files and
  118. classes included globally, recursively listing the files they include
  119. or inherit in turn. Much of the behavior of the OpenEmbedded build
  120. system (including the behavior of the :ref:`ref-manual/tasks:normal recipe build tasks`) is
  121. implemented in the :ref:`ref-classes-base` class and the
  122. classes it inherits, rather than being built into BitBake itself.
  123. - After the variable values, all functions appear in the output. For
  124. shell functions, variables referenced within the function body are
  125. expanded. If a function has been modified using overrides or using
  126. override-style operators like ``:append`` and ``:prepend``, then the
  127. final assembled function body appears in the output.
  128. Viewing Package Information with ``oe-pkgdata-util``
  129. ====================================================
  130. You can use the ``oe-pkgdata-util`` command-line utility to query
  131. :term:`PKGDATA_DIR` and display
  132. various package-related information. When you use the utility, you must
  133. use it to view information on packages that have already been built.
  134. Following are a few of the available ``oe-pkgdata-util`` subcommands.
  135. .. note::
  136. You can use the standard \* and ? globbing wildcards as part of
  137. package names and paths.
  138. - ``oe-pkgdata-util list-pkgs [pattern]``: Lists all packages
  139. that have been built, optionally limiting the match to packages that
  140. match pattern.
  141. - ``oe-pkgdata-util list-pkg-files package ...``: Lists the
  142. files and directories contained in the given packages.
  143. .. note::
  144. A different way to view the contents of a package is to look at
  145. the
  146. ``${``\ :term:`WORKDIR`\ ``}/packages-split``
  147. directory of the recipe that generates the package. This directory
  148. is created by the
  149. :ref:`ref-tasks-package` task
  150. and has one subdirectory for each package the recipe generates,
  151. which contains the files stored in that package.
  152. If you want to inspect the ``${WORKDIR}/packages-split``
  153. directory, make sure that :ref:`ref-classes-rm-work` is not
  154. enabled when you build the recipe.
  155. - ``oe-pkgdata-util find-path path ...``: Lists the names of
  156. the packages that contain the given paths. For example, the following
  157. tells us that ``/usr/share/man/man1/make.1`` is contained in the
  158. ``make-doc`` package::
  159. $ oe-pkgdata-util find-path /usr/share/man/man1/make.1
  160. make-doc: /usr/share/man/man1/make.1
  161. - ``oe-pkgdata-util lookup-recipe package ...``: Lists the name
  162. of the recipes that produce the given packages.
  163. For more information on the ``oe-pkgdata-util`` command, use the help
  164. facility::
  165. $ oe-pkgdata-util --help
  166. $ oe-pkgdata-util subcommand --help
  167. Viewing Dependencies Between Recipes and Tasks
  168. ==============================================
  169. Sometimes it can be hard to see why BitBake wants to build other recipes
  170. before the one you have specified. Dependency information can help you
  171. understand why a recipe is built.
  172. To generate dependency information for a recipe, run the following
  173. command::
  174. $ bitbake -g recipename
  175. This command writes the following files in the current directory:
  176. - ``pn-buildlist``: A list of recipes/targets involved in building
  177. `recipename`. "Involved" here means that at least one task from the
  178. recipe needs to run when building `recipename` from scratch. Targets
  179. that are in
  180. :term:`ASSUME_PROVIDED`
  181. are not listed.
  182. - ``task-depends.dot``: A graph showing dependencies between tasks.
  183. The graphs are in :wikipedia:`DOT <DOT_%28graph_description_language%29>`
  184. format and can be converted to images (e.g. using the ``dot`` tool from
  185. `Graphviz <https://www.graphviz.org/>`__).
  186. .. note::
  187. - DOT files use a plain text format. The graphs generated using the
  188. ``bitbake -g`` command are often so large as to be difficult to
  189. read without special pruning (e.g. with BitBake's ``-I`` option)
  190. and processing. Despite the form and size of the graphs, the
  191. corresponding ``.dot`` files can still be possible to read and
  192. provide useful information.
  193. As an example, the ``task-depends.dot`` file contains lines such
  194. as the following::
  195. "libxslt.do_configure" -> "libxml2.do_populate_sysroot"
  196. The above example line reveals that the
  197. :ref:`ref-tasks-configure`
  198. task in ``libxslt`` depends on the
  199. :ref:`ref-tasks-populate_sysroot`
  200. task in ``libxml2``, which is a normal
  201. :term:`DEPENDS` dependency
  202. between the two recipes.
  203. - For an example of how ``.dot`` files can be processed, see the
  204. ``scripts/contrib/graph-tool`` Python script, which finds and
  205. displays paths between graph nodes.
  206. You can use a different method to view dependency information by using
  207. the following command::
  208. $ bitbake -g -u taskexp recipename
  209. This command
  210. displays a GUI window from which you can view build-time and runtime
  211. dependencies for the recipes involved in building recipename.
  212. Viewing Task Variable Dependencies
  213. ==================================
  214. As mentioned in the
  215. ":ref:`bitbake:bitbake-user-manual/bitbake-user-manual-execution:checksums (signatures)`" section of the BitBake
  216. User Manual, BitBake tries to automatically determine what variables a
  217. task depends on so that it can rerun the task if any values of the
  218. variables change. This determination is usually reliable. However, if
  219. you do things like construct variable names at runtime, then you might
  220. have to manually declare dependencies on those variables using
  221. ``vardeps`` as described in the
  222. ":ref:`bitbake:bitbake-user-manual/bitbake-user-manual-metadata:variable flags`" section of the BitBake
  223. User Manual.
  224. If you are unsure whether a variable dependency is being picked up
  225. automatically for a given task, you can list the variable dependencies
  226. BitBake has determined by doing the following:
  227. #. Build the recipe containing the task::
  228. $ bitbake recipename
  229. #. Inside the :term:`STAMPS_DIR`
  230. directory, find the signature data (``sigdata``) file that
  231. corresponds to the task. The ``sigdata`` files contain a pickled
  232. Python database of all the metadata that went into creating the input
  233. checksum for the task. As an example, for the
  234. :ref:`ref-tasks-fetch` task of the
  235. ``db`` recipe, the ``sigdata`` file might be found in the following
  236. location::
  237. ${BUILDDIR}/tmp/stamps/i586-poky-linux/db/6.0.30-r1.do_fetch.sigdata.7c048c18222b16ff0bcee2000ef648b1
  238. For tasks that are accelerated through the shared state
  239. (:ref:`sstate <overview-manual/concepts:shared state cache>`) cache, an
  240. additional ``siginfo`` file is written into
  241. :term:`SSTATE_DIR` along with
  242. the cached task output. The ``siginfo`` files contain exactly the
  243. same information as ``sigdata`` files.
  244. #. Run ``bitbake-dumpsig`` on the ``sigdata`` or ``siginfo`` file. Here
  245. is an example::
  246. $ bitbake-dumpsig ${BUILDDIR}/tmp/stamps/i586-poky-linux/db/6.0.30-r1.do_fetch.sigdata.7c048c18222b16ff0bcee2000ef648b1
  247. In the output of the above command, you will find a line like the
  248. following, which lists all the (inferred) variable dependencies for
  249. the task. This list also includes indirect dependencies from
  250. variables depending on other variables, recursively::
  251. Task dependencies: ['PV', 'SRCREV', 'SRC_URI', 'SRC_URI[md5sum]', 'SRC_URI[sha256sum]', 'base_do_fetch']
  252. .. note::
  253. Functions (e.g. ``base_do_fetch``) also count as variable dependencies.
  254. These functions in turn depend on the variables they reference.
  255. The output of ``bitbake-dumpsig`` also includes the value each
  256. variable had, a list of dependencies for each variable, and
  257. :term:`BB_BASEHASH_IGNORE_VARS`
  258. information.
  259. There is also a ``bitbake-diffsigs`` command for comparing two
  260. ``siginfo`` or ``sigdata`` files. This command can be helpful when
  261. trying to figure out what changed between two versions of a task. If you
  262. call ``bitbake-diffsigs`` with just one file, the command behaves like
  263. ``bitbake-dumpsig``.
  264. You can also use BitBake to dump out the signature construction
  265. information without executing tasks by using either of the following
  266. BitBake command-line options::
  267. ‐‐dump-signatures=SIGNATURE_HANDLER
  268. -S SIGNATURE_HANDLER
  269. .. note::
  270. Two common values for `SIGNATURE_HANDLER` are "none" and "printdiff", which
  271. dump only the signature or compare the dumped signature with the cached one,
  272. respectively.
  273. Using BitBake with either of these options causes BitBake to dump out
  274. ``sigdata`` files in the ``stamps`` directory for every task it would
  275. have executed instead of building the specified target package.
  276. Viewing Metadata Used to Create the Input Signature of a Shared State Task
  277. ==========================================================================
  278. Seeing what metadata went into creating the input signature of a shared
  279. state (sstate) task can be a useful debugging aid. This information is
  280. available in signature information (``siginfo``) files in
  281. :term:`SSTATE_DIR`. For
  282. information on how to view and interpret information in ``siginfo``
  283. files, see the
  284. ":ref:`dev-manual/debugging:viewing task variable dependencies`" section.
  285. For conceptual information on shared state, see the
  286. ":ref:`overview-manual/concepts:shared state`"
  287. section in the Yocto Project Overview and Concepts Manual.
  288. Invalidating Shared State to Force a Task to Run
  289. ================================================
  290. The OpenEmbedded build system uses
  291. :ref:`checksums <overview-manual/concepts:checksums (signatures)>` and
  292. :ref:`overview-manual/concepts:shared state` cache to avoid unnecessarily
  293. rebuilding tasks. Collectively, this scheme is known as "shared state
  294. code".
  295. As with all schemes, this one has some drawbacks. It is possible that
  296. you could make implicit changes to your code that the checksum
  297. calculations do not take into account. These implicit changes affect a
  298. task's output but do not trigger the shared state code into rebuilding a
  299. recipe. Consider an example during which a tool changes its output.
  300. Assume that the output of ``rpmdeps`` changes. The result of the change
  301. should be that all the ``package`` and ``package_write_rpm`` shared
  302. state cache items become invalid. However, because the change to the
  303. output is external to the code and therefore implicit, the associated
  304. shared state cache items do not become invalidated. In this case, the
  305. build process uses the cached items rather than running the task again.
  306. Obviously, these types of implicit changes can cause problems.
  307. To avoid these problems during the build, you need to understand the
  308. effects of any changes you make. Realize that changes you make directly
  309. to a function are automatically factored into the checksum calculation.
  310. Thus, these explicit changes invalidate the associated area of shared
  311. state cache. However, you need to be aware of any implicit changes that
  312. are not obvious changes to the code and could affect the output of a
  313. given task.
  314. When you identify an implicit change, you can easily take steps to
  315. invalidate the cache and force the tasks to run. The steps you can take
  316. are as simple as changing a function's comments in the source code. For
  317. example, to invalidate package shared state files, change the comment
  318. statements of
  319. :ref:`ref-tasks-package` or the
  320. comments of one of the functions it calls. Even though the change is
  321. purely cosmetic, it causes the checksum to be recalculated and forces
  322. the build system to run the task again.
  323. .. note::
  324. For an example of a commit that makes a cosmetic change to invalidate
  325. shared state, see this
  326. :yocto_git:`commit </poky/commit/meta/classes/package.bbclass?id=737f8bbb4f27b4837047cb9b4fbfe01dfde36d54>`.
  327. Running Specific Tasks
  328. ======================
  329. Any given recipe consists of a set of tasks. The standard BitBake
  330. behavior in most cases is: :ref:`ref-tasks-fetch`, :ref:`ref-tasks-unpack`, :ref:`ref-tasks-patch`,
  331. :ref:`ref-tasks-configure`, :ref:`ref-tasks-compile`, :ref:`ref-tasks-install`, :ref:`ref-tasks-package`,
  332. :ref:`do_package_write_* <ref-tasks-package_write_deb>`, and :ref:`ref-tasks-build`. The default task is
  333. :ref:`ref-tasks-build` and any tasks on which it depends build first. Some tasks,
  334. such as :ref:`ref-tasks-devshell`, are not part of the default build chain. If you
  335. wish to run a task that is not part of the default build chain, you can
  336. use the ``-c`` option in BitBake. Here is an example::
  337. $ bitbake matchbox-desktop -c devshell
  338. The ``-c`` option respects task dependencies, which means that all other
  339. tasks (including tasks from other recipes) that the specified task
  340. depends on will be run before the task. Even when you manually specify a
  341. task to run with ``-c``, BitBake will only run the task if it considers
  342. it "out of date". See the
  343. ":ref:`overview-manual/concepts:stamp files and the rerunning of tasks`"
  344. section in the Yocto Project Overview and Concepts Manual for how
  345. BitBake determines whether a task is "out of date".
  346. If you want to force an up-to-date task to be rerun (e.g. because you
  347. made manual modifications to the recipe's
  348. :term:`WORKDIR` that you want to try
  349. out), then you can use the ``-f`` option.
  350. .. note::
  351. The reason ``-f`` is never required when running the
  352. :ref:`ref-tasks-devshell` task is because the
  353. [\ :ref:`nostamp <bitbake:bitbake-user-manual/bitbake-user-manual-metadata:variable flags>`\ ]
  354. variable flag is already set for the task.
  355. The following example shows one way you can use the ``-f`` option::
  356. $ bitbake matchbox-desktop
  357. .
  358. .
  359. make some changes to the source code in the work directory
  360. .
  361. .
  362. $ bitbake matchbox-desktop -c compile -f
  363. $ bitbake matchbox-desktop
  364. This sequence first builds and then recompiles ``matchbox-desktop``. The
  365. last command reruns all tasks (basically the packaging tasks) after the
  366. compile. BitBake recognizes that the :ref:`ref-tasks-compile` task was rerun and
  367. therefore understands that the other tasks also need to be run again.
  368. Another, shorter way to rerun a task and all
  369. :ref:`ref-manual/tasks:normal recipe build tasks`
  370. that depend on it is to use the ``-C`` option.
  371. .. note::
  372. This option is upper-cased and is separate from the ``-c``
  373. option, which is lower-cased.
  374. Using this option invalidates the given task and then runs the
  375. :ref:`ref-tasks-build` task, which is
  376. the default task if no task is given, and the tasks on which it depends.
  377. You could replace the final two commands in the previous example with
  378. the following single command::
  379. $ bitbake matchbox-desktop -C compile
  380. Internally, the ``-f`` and ``-C`` options work by tainting (modifying)
  381. the input checksum of the specified task. This tainting indirectly
  382. causes the task and its dependent tasks to be rerun through the normal
  383. task dependency mechanisms.
  384. .. note::
  385. BitBake explicitly keeps track of which tasks have been tainted in
  386. this fashion, and will print warnings such as the following for
  387. builds involving such tasks:
  388. .. code-block:: none
  389. WARNING: /home/ulf/poky/meta/recipes-sato/matchbox-desktop/matchbox-desktop_2.1.bb.do_compile is tainted from a forced run
  390. The purpose of the warning is to let you know that the work directory
  391. and build output might not be in the clean state they would be in for
  392. a "normal" build, depending on what actions you took. To get rid of
  393. such warnings, you can remove the work directory and rebuild the
  394. recipe, as follows::
  395. $ bitbake matchbox-desktop -c clean
  396. $ bitbake matchbox-desktop
  397. You can view a list of tasks in a given package by running the
  398. :ref:`ref-tasks-listtasks` task as follows::
  399. $ bitbake matchbox-desktop -c listtasks
  400. The results appear as output to the console and are also in
  401. the file ``${WORKDIR}/temp/log.do_listtasks``.
  402. General BitBake Problems
  403. ========================
  404. You can see debug output from BitBake by using the ``-D`` option. The
  405. debug output gives more information about what BitBake is doing and the
  406. reason behind it. Each ``-D`` option you use increases the logging
  407. level. The most common usage is ``-DDD``.
  408. The output from ``bitbake -DDD -v targetname`` can reveal why BitBake
  409. chose a certain version of a package or why BitBake picked a certain
  410. provider. This command could also help you in a situation where you
  411. think BitBake did something unexpected.
  412. Building with No Dependencies
  413. =============================
  414. To build a specific recipe (``.bb`` file), you can use the following
  415. command form::
  416. $ bitbake -b somepath/somerecipe.bb
  417. This command form does
  418. not check for dependencies. Consequently, you should use it only when
  419. you know existing dependencies have been met.
  420. .. note::
  421. You can also specify fragments of the filename. In this case, BitBake
  422. checks for a unique match.
  423. Recipe Logging Mechanisms
  424. =========================
  425. The Yocto Project provides several logging functions for producing
  426. debugging output and reporting errors and warnings. For Python
  427. functions, the following logging functions are available. All of these functions
  428. log to ``${T}/log.do_``\ `task`, and can also log to standard output
  429. (stdout) with the right settings:
  430. - ``bb.plain(msg)``: Writes msg as is to the log while also
  431. logging to stdout.
  432. - ``bb.note(msg)``: Writes "NOTE: msg" to the log. Also logs to
  433. stdout if BitBake is called with "-v".
  434. - ``bb.debug(level, msg)``: Writes "DEBUG: msg" to the
  435. log. Also logs to stdout if the log level is greater than or equal to
  436. level. See the ":ref:`bitbake:bitbake-user-manual/bitbake-user-manual-intro:usage and syntax`" option
  437. in the BitBake User Manual for more information.
  438. - ``bb.warn(msg)``: Writes "WARNING: msg" to the log while also
  439. logging to stdout.
  440. - ``bb.error(msg)``: Writes "ERROR: msg" to the log while also
  441. logging to standard out (stdout).
  442. .. note::
  443. Calling this function does not cause the task to fail.
  444. - ``bb.fatal(msg)``: This logging function is similar to
  445. ``bb.error(msg)`` but also causes the calling task to fail.
  446. .. note::
  447. ``bb.fatal()`` raises an exception, which means you do not need to put a
  448. "return" statement after the function.
  449. The same logging functions are also available in shell functions, under
  450. the names ``bbplain``, ``bbnote``, ``bbdebug``, ``bbwarn``, ``bberror``,
  451. and ``bbfatal``. The :ref:`ref-classes-logging` class
  452. implements these functions. See that class in the ``meta/classes``
  453. folder of the :term:`Source Directory` for information.
  454. Logging With Python
  455. -------------------
  456. When creating recipes using Python and inserting code that handles build
  457. logs, keep in mind the goal is to have informative logs while keeping
  458. the console as "silent" as possible. Also, if you want status messages
  459. in the log, use the "debug" loglevel.
  460. Following is an example written in Python. The code handles logging for
  461. a function that determines the number of tasks needed to be run. See the
  462. ":ref:`ref-tasks-listtasks`"
  463. section for additional information::
  464. python do_listtasks() {
  465. bb.debug(2, "Starting to figure out the task list")
  466. if noteworthy_condition:
  467. bb.note("There are 47 tasks to run")
  468. bb.debug(2, "Got to point xyz")
  469. if warning_trigger:
  470. bb.warn("Detected warning_trigger, this might be a problem later.")
  471. if recoverable_error:
  472. bb.error("Hit recoverable_error, you really need to fix this!")
  473. if fatal_error:
  474. bb.fatal("fatal_error detected, unable to print the task list")
  475. bb.plain("The tasks present are abc")
  476. bb.debug(2, "Finished figuring out the tasklist")
  477. }
  478. Logging With Bash
  479. -----------------
  480. When creating recipes using Bash and inserting code that handles build
  481. logs, you have the same goals --- informative with minimal console output.
  482. The syntax you use for recipes written in Bash is similar to that of
  483. recipes written in Python described in the previous section.
  484. Following is an example written in Bash. The code logs the progress of
  485. the ``do_my_function`` function::
  486. do_my_function() {
  487. bbdebug 2 "Running do_my_function"
  488. if [ exceptional_condition ]; then
  489. bbnote "Hit exceptional_condition"
  490. fi
  491. bbdebug 2 "Got to point xyz"
  492. if [ warning_trigger ]; then
  493. bbwarn "Detected warning_trigger, this might cause a problem later."
  494. fi
  495. if [ recoverable_error ]; then
  496. bberror "Hit recoverable_error, correcting"
  497. fi
  498. if [ fatal_error ]; then
  499. bbfatal "fatal_error detected"
  500. fi
  501. bbdebug 2 "Completed do_my_function"
  502. }
  503. Debugging Parallel Make Races
  504. =============================
  505. A parallel ``make`` race occurs when the build consists of several parts
  506. that are run simultaneously and a situation occurs when the output or
  507. result of one part is not ready for use with a different part of the
  508. build that depends on that output. Parallel make races are annoying and
  509. can sometimes be difficult to reproduce and fix. However, there are some simple
  510. tips and tricks that can help you debug and fix them. This section
  511. presents a real-world example of an error encountered on the Yocto
  512. Project autobuilder and the process used to fix it.
  513. .. note::
  514. If you cannot properly fix a ``make`` race condition, you can work around it
  515. by clearing either the :term:`PARALLEL_MAKE` or :term:`PARALLEL_MAKEINST`
  516. variables.
  517. The Failure
  518. -----------
  519. For this example, assume that you are building an image that depends on
  520. the "neard" package. And, during the build, BitBake runs into problems
  521. and creates the following output.
  522. .. note::
  523. This example log file has longer lines artificially broken to make
  524. the listing easier to read.
  525. If you examine the output or the log file, you see the failure during
  526. ``make``:
  527. .. code-block:: none
  528. | DEBUG: SITE files ['endian-little', 'bit-32', 'ix86-common', 'common-linux', 'common-glibc', 'i586-linux', 'common']
  529. | DEBUG: Executing shell function do_compile
  530. | NOTE: make -j 16
  531. | make --no-print-directory all-am
  532. | /bin/mkdir -p include/near
  533. | /bin/mkdir -p include/near
  534. | /bin/mkdir -p include/near
  535. | ln -s /home/pokybuild/yocto-autobuilder/nightly-x86/build/build/tmp/work/i586-poky-linux/neard/
  536. 0.14-r0/neard-0.14/include/types.h include/near/types.h
  537. | ln -s /home/pokybuild/yocto-autobuilder/nightly-x86/build/build/tmp/work/i586-poky-linux/neard/
  538. 0.14-r0/neard-0.14/include/log.h include/near/log.h
  539. | ln -s /home/pokybuild/yocto-autobuilder/nightly-x86/build/build/tmp/work/i586-poky-linux/neard/
  540. 0.14-r0/neard-0.14/include/plugin.h include/near/plugin.h
  541. | /bin/mkdir -p include/near
  542. | /bin/mkdir -p include/near
  543. | /bin/mkdir -p include/near
  544. | ln -s /home/pokybuild/yocto-autobuilder/nightly-x86/build/build/tmp/work/i586-poky-linux/neard/
  545. 0.14-r0/neard-0.14/include/tag.h include/near/tag.h
  546. | /bin/mkdir -p include/near
  547. | ln -s /home/pokybuild/yocto-autobuilder/nightly-x86/build/build/tmp/work/i586-poky-linux/neard/
  548. 0.14-r0/neard-0.14/include/adapter.h include/near/adapter.h
  549. | /bin/mkdir -p include/near
  550. | ln -s /home/pokybuild/yocto-autobuilder/nightly-x86/build/build/tmp/work/i586-poky-linux/neard/
  551. 0.14-r0/neard-0.14/include/ndef.h include/near/ndef.h
  552. | ln -s /home/pokybuild/yocto-autobuilder/nightly-x86/build/build/tmp/work/i586-poky-linux/neard/
  553. 0.14-r0/neard-0.14/include/tlv.h include/near/tlv.h
  554. | /bin/mkdir -p include/near
  555. | /bin/mkdir -p include/near
  556. | ln -s /home/pokybuild/yocto-autobuilder/nightly-x86/build/build/tmp/work/i586-poky-linux/neard/
  557. 0.14-r0/neard-0.14/include/setting.h include/near/setting.h
  558. | /bin/mkdir -p include/near
  559. | /bin/mkdir -p include/near
  560. | /bin/mkdir -p include/near
  561. | ln -s /home/pokybuild/yocto-autobuilder/nightly-x86/build/build/tmp/work/i586-poky-linux/neard/
  562. 0.14-r0/neard-0.14/include/device.h include/near/device.h
  563. | ln -s /home/pokybuild/yocto-autobuilder/nightly-x86/build/build/tmp/work/i586-poky-linux/neard/
  564. 0.14-r0/neard-0.14/include/nfc_copy.h include/near/nfc_copy.h
  565. | ln -s /home/pokybuild/yocto-autobuilder/nightly-x86/build/build/tmp/work/i586-poky-linux/neard/
  566. 0.14-r0/neard-0.14/include/snep.h include/near/snep.h
  567. | ln -s /home/pokybuild/yocto-autobuilder/nightly-x86/build/build/tmp/work/i586-poky-linux/neard/
  568. 0.14-r0/neard-0.14/include/version.h include/near/version.h
  569. | ln -s /home/pokybuild/yocto-autobuilder/nightly-x86/build/build/tmp/work/i586-poky-linux/neard/
  570. 0.14-r0/neard-0.14/include/dbus.h include/near/dbus.h
  571. | ./src/genbuiltin nfctype1 nfctype2 nfctype3 nfctype4 p2p > src/builtin.h
  572. | i586-poky-linux-gcc -m32 -march=i586 --sysroot=/home/pokybuild/yocto-autobuilder/nightly-x86/
  573. build/build/tmp/sysroots/qemux86 -DHAVE_CONFIG_H -I. -I./include -I./src -I./gdbus -I/home/pokybuild/
  574. yocto-autobuilder/nightly-x86/build/build/tmp/sysroots/qemux86/usr/include/glib-2.0
  575. -I/home/pokybuild/yocto-autobuilder/nightly-x86/build/build/tmp/sysroots/qemux86/usr/
  576. lib/glib-2.0/include -I/home/pokybuild/yocto-autobuilder/nightly-x86/build/build/
  577. tmp/sysroots/qemux86/usr/include/dbus-1.0 -I/home/pokybuild/yocto-autobuilder/
  578. nightly-x86/build/build/tmp/sysroots/qemux86/usr/lib/dbus-1.0/include -I/home/pokybuild/yocto-autobuilder/
  579. nightly-x86/build/build/tmp/sysroots/qemux86/usr/include/libnl3
  580. -DNEAR_PLUGIN_BUILTIN -DPLUGINDIR=\""/usr/lib/near/plugins"\"
  581. -DCONFIGDIR=\""/etc/neard\"" -O2 -pipe -g -feliminate-unused-debug-types -c
  582. -o tools/snep-send.o tools/snep-send.c
  583. | In file included from tools/snep-send.c:16:0:
  584. | tools/../src/near.h:41:23: fatal error: near/dbus.h: No such file or directory
  585. | #include <near/dbus.h>
  586. | ^
  587. | compilation terminated.
  588. | make[1]: *** [tools/snep-send.o] Error 1
  589. | make[1]: *** Waiting for unfinished jobs....
  590. | make: *** [all] Error 2
  591. | ERROR: oe_runmake failed
  592. Reproducing the Error
  593. ---------------------
  594. Because race conditions are intermittent, they do not manifest
  595. themselves every time you do the build. In fact, most times the build
  596. will complete without problems even though the potential race condition
  597. exists. Thus, once the error surfaces, you need a way to reproduce it.
  598. In this example, compiling the "neard" package is causing the problem.
  599. So the first thing to do is build "neard" locally. Before you start the
  600. build, set the
  601. :term:`PARALLEL_MAKE` variable
  602. in your ``local.conf`` file to a high number (e.g. "-j 20"). Using a
  603. high value for :term:`PARALLEL_MAKE` increases the chances of the race
  604. condition showing up::
  605. $ bitbake neard
  606. Once the local build for "neard" completes, start a ``devshell`` build::
  607. $ bitbake neard -c devshell
  608. For information on how to use a ``devshell``, see the
  609. ":ref:`dev-manual/development-shell:using a development shell`" section.
  610. In the ``devshell``, do the following::
  611. $ make clean
  612. $ make tools/snep-send.o
  613. The ``devshell`` commands cause the failure to clearly
  614. be visible. In this case, there is a missing dependency for the ``neard``
  615. Makefile target. Here is some abbreviated, sample output with the
  616. missing dependency clearly visible at the end::
  617. i586-poky-linux-gcc -m32 -march=i586 --sysroot=/home/scott-lenovo/......
  618. .
  619. .
  620. .
  621. tools/snep-send.c
  622. In file included from tools/snep-send.c:16:0:
  623. tools/../src/near.h:41:23: fatal error: near/dbus.h: No such file or directory
  624. #include <near/dbus.h>
  625. ^
  626. compilation terminated.
  627. make: *** [tools/snep-send.o] Error 1
  628. $
  629. Creating a Patch for the Fix
  630. ----------------------------
  631. Because there is a missing dependency for the Makefile target, you need
  632. to patch the ``Makefile.am`` file, which is generated from
  633. ``Makefile.in``. You can use Quilt to create the patch::
  634. $ quilt new parallelmake.patch
  635. Patch patches/parallelmake.patch is now on top
  636. $ quilt add Makefile.am
  637. File Makefile.am added to patch patches/parallelmake.patch
  638. For more information on using Quilt, see the
  639. ":ref:`dev-manual/quilt:using quilt in your workflow`" section.
  640. At this point you need to make the edits to ``Makefile.am`` to add the
  641. missing dependency. For our example, you have to add the following line
  642. to the file::
  643. tools/snep-send.$(OBJEXT): include/near/dbus.h
  644. Once you have edited the file, use the ``refresh`` command to create the
  645. patch::
  646. $ quilt refresh
  647. Refreshed patch patches/parallelmake.patch
  648. Once the patch file is created, you need to add it back to the originating
  649. recipe folder. Here is an example assuming a top-level
  650. :term:`Source Directory` named ``poky``::
  651. $ cp patches/parallelmake.patch poky/meta/recipes-connectivity/neard/neard
  652. The final thing you need to do to implement the fix in the build is to
  653. update the "neard" recipe (i.e. ``neard-0.14.bb``) so that the
  654. :term:`SRC_URI` statement includes
  655. the patch file. The recipe file is in the folder above the patch. Here
  656. is what the edited :term:`SRC_URI` statement would look like::
  657. SRC_URI = "${KERNELORG_MIRROR}/linux/network/nfc/${BPN}-${PV}.tar.xz \
  658. file://neard.in \
  659. file://neard.service.in \
  660. file://parallelmake.patch \
  661. "
  662. With the patch complete and moved to the correct folder and the
  663. :term:`SRC_URI` statement updated, you can exit the ``devshell``::
  664. $ exit
  665. Testing the Build
  666. -----------------
  667. With everything in place, you can get back to trying the build again
  668. locally::
  669. $ bitbake neard
  670. This build should succeed.
  671. Now you can open up a ``devshell`` again and repeat the clean and make
  672. operations as follows::
  673. $ bitbake neard -c devshell
  674. $ make clean
  675. $ make tools/snep-send.o
  676. The build should work without issue.
  677. As with all solved problems, if they originated upstream, you need to
  678. submit the fix for the recipe in OE-Core and upstream so that the
  679. problem is taken care of at its source. See the
  680. ":ref:`dev-manual/changes:submitting a change to the yocto project`"
  681. section for more information.
  682. Debugging With the GNU Project Debugger (GDB) Remotely
  683. ======================================================
  684. GDB allows you to examine running programs, which in turn helps you to
  685. understand and fix problems. It also allows you to perform post-mortem
  686. style analysis of program crashes. GDB is available as a package within
  687. the Yocto Project and is installed in SDK images by default. See the
  688. ":ref:`ref-manual/images:Images`" chapter in the Yocto
  689. Project Reference Manual for a description of these images. You can find
  690. information on GDB at https://sourceware.org/gdb/.
  691. .. note::
  692. For best results, install debug (``-dbg``) packages for the applications you
  693. are going to debug. Doing so makes extra debug symbols available that give
  694. you more meaningful output.
  695. Sometimes, due to memory or disk space constraints, it is not possible
  696. to use GDB directly on the remote target to debug applications. These
  697. constraints arise because GDB needs to load the debugging information
  698. and the binaries of the process being debugged. Additionally, GDB needs
  699. to perform many computations to locate information such as function
  700. names, variable names and values, stack traces and so forth --- even
  701. before starting the debugging process. These extra computations place
  702. more load on the target system and can alter the characteristics of the
  703. program being debugged.
  704. To help get past the previously mentioned constraints, there are two
  705. methods you can use: running a debuginfod server and using gdbserver.
  706. Using the debuginfod server method
  707. ----------------------------------
  708. ``debuginfod`` from ``elfutils`` is a way to distribute ``debuginfo`` files.
  709. Running a ``debuginfod`` server makes debug symbols readily available,
  710. which means you don't need to download debugging information
  711. and the binaries of the process being debugged. You can just fetch
  712. debug symbols from the server.
  713. To run a ``debuginfod`` server, you need to do the following:
  714. - Ensure that ``debuginfod`` is present in :term:`DISTRO_FEATURES`
  715. (it already is in ``OpenEmbedded-core`` defaults and ``poky`` reference distribution).
  716. If not, set in your distro config file or in ``local.conf``::
  717. DISTRO_FEATURES:append = " debuginfod"
  718. This distro feature enables the server and client library in ``elfutils``,
  719. and enables ``debuginfod`` support in clients (at the moment, ``gdb`` and ``binutils``).
  720. - Run the following commands to launch the ``debuginfod`` server on the host::
  721. $ oe-debuginfod
  722. - To use ``debuginfod`` on the target, you need to know the ip:port where
  723. ``debuginfod`` is listening on the host (port defaults to 8002), and export
  724. that into the shell environment, for example in ``qemu``::
  725. root@qemux86-64:~# export DEBUGINFOD_URLS="http://192.168.7.1:8002/"
  726. - Then debug info fetching should simply work when running the target ``gdb``,
  727. ``readelf`` or ``objdump``, for example::
  728. root@qemux86-64:~# gdb /bin/cat
  729. ...
  730. Reading symbols from /bin/cat...
  731. Downloading separate debug info for /bin/cat...
  732. Reading symbols from /home/root/.cache/debuginfod_client/923dc4780cfbc545850c616bffa884b6b5eaf322/debuginfo...
  733. - It's also possible to use ``debuginfod-find`` to just query the server::
  734. root@qemux86-64:~# debuginfod-find debuginfo /bin/ls
  735. /home/root/.cache/debuginfod_client/356edc585f7f82d46f94fcb87a86a3fe2d2e60bd/debuginfo
  736. Using the gdbserver method
  737. --------------------------
  738. gdbserver, which runs on the remote target and does not load any
  739. debugging information from the debugged process. Instead, a GDB instance
  740. processes the debugging information that is run on a remote computer -
  741. the host GDB. The host GDB then sends control commands to gdbserver to
  742. make it stop or start the debugged program, as well as read or write
  743. memory regions of that debugged program. All the debugging information
  744. loaded and processed as well as all the heavy debugging is done by the
  745. host GDB. Offloading these processes gives the gdbserver running on the
  746. target a chance to remain small and fast.
  747. Because the host GDB is responsible for loading the debugging
  748. information and for doing the necessary processing to make actual
  749. debugging happen, you have to make sure the host can access the
  750. unstripped binaries complete with their debugging information and also
  751. be sure the target is compiled with no optimizations. The host GDB must
  752. also have local access to all the libraries used by the debugged
  753. program. Because gdbserver does not need any local debugging
  754. information, the binaries on the remote target can remain stripped.
  755. However, the binaries must also be compiled without optimization so they
  756. match the host's binaries.
  757. To remain consistent with GDB documentation and terminology, the binary
  758. being debugged on the remote target machine is referred to as the
  759. "inferior" binary. For documentation on GDB see the `GDB
  760. site <https://sourceware.org/gdb/documentation/>`__.
  761. The following steps show you how to debug using the GNU project
  762. debugger.
  763. #. *Configure your build system to construct the companion debug
  764. filesystem:*
  765. In your ``local.conf`` file, set the following::
  766. IMAGE_GEN_DEBUGFS = "1"
  767. IMAGE_FSTYPES_DEBUGFS = "tar.bz2"
  768. These options cause the
  769. OpenEmbedded build system to generate a special companion filesystem
  770. fragment, which contains the matching source and debug symbols to
  771. your deployable filesystem. The build system does this by looking at
  772. what is in the deployed filesystem, and pulling the corresponding
  773. ``-dbg`` packages.
  774. The companion debug filesystem is not a complete filesystem, but only
  775. contains the debug fragments. This filesystem must be combined with
  776. the full filesystem for debugging. Subsequent steps in this procedure
  777. show how to combine the partial filesystem with the full filesystem.
  778. #. *Configure the system to include gdbserver in the target filesystem:*
  779. Make the following addition in your ``local.conf`` file::
  780. EXTRA_IMAGE_FEATURES:append = " tools-debug"
  781. The change makes
  782. sure the ``gdbserver`` package is included.
  783. #. *Build the environment:*
  784. Use the following command to construct the image and the companion
  785. Debug Filesystem::
  786. $ bitbake image
  787. Build the cross GDB component and
  788. make it available for debugging. Build the SDK that matches the
  789. image. Building the SDK is best for a production build that can be
  790. used later for debugging, especially during long term maintenance::
  791. $ bitbake -c populate_sdk image
  792. Alternatively, you can build the minimal toolchain components that
  793. match the target. Doing so creates a smaller than typical SDK and
  794. only contains a minimal set of components with which to build simple
  795. test applications, as well as run the debugger::
  796. $ bitbake meta-toolchain
  797. A final method is to build Gdb itself within the build system::
  798. $ bitbake gdb-cross-<architecture>
  799. Doing so produces a temporary copy of
  800. ``cross-gdb`` you can use for debugging during development. While
  801. this is the quickest approach, the two previous methods in this step
  802. are better when considering long-term maintenance strategies.
  803. .. note::
  804. If you run ``bitbake gdb-cross``, the OpenEmbedded build system suggests
  805. the actual image (e.g. ``gdb-cross-i586``). The suggestion is usually the
  806. actual name you want to use.
  807. #. *Set up the* ``debugfs``\ *:*
  808. Run the following commands to set up the ``debugfs``::
  809. $ mkdir debugfs
  810. $ cd debugfs
  811. $ tar xvfj build-dir/tmp/deploy/images/machine/image.rootfs.tar.bz2
  812. $ tar xvfj build-dir/tmp/deploy/images/machine/image-dbg.rootfs.tar.bz2
  813. #. *Set up GDB:*
  814. Install the SDK (if you built one) and then source the correct
  815. environment file. Sourcing the environment file puts the SDK in your
  816. ``PATH`` environment variable and sets ``$GDB`` to the SDK's debugger.
  817. If you are using the build system, Gdb is located in
  818. `build-dir`\ ``/tmp/sysroots/``\ `host`\ ``/usr/bin/``\ `architecture`\ ``/``\ `architecture`\ ``-gdb``
  819. #. *Boot the target:*
  820. For information on how to run QEMU, see the `QEMU
  821. Documentation <https://wiki.qemu.org/Documentation/GettingStartedDevelopers>`__.
  822. .. note::
  823. Be sure to verify that your host can access the target via TCP.
  824. #. *Debug a program:*
  825. Debugging a program involves running gdbserver on the target and then
  826. running Gdb on the host. The example in this step debugs ``gzip``:
  827. .. code-block:: shell
  828. root@qemux86:~# gdbserver localhost:1234 /bin/gzip —help
  829. For
  830. additional gdbserver options, see the `GDB Server
  831. Documentation <https://www.gnu.org/software/gdb/documentation/>`__.
  832. After running gdbserver on the target, you need to run Gdb on the
  833. host and configure it and connect to the target. Use these commands::
  834. $ cd directory-holding-the-debugfs-directory
  835. $ arch-gdb
  836. (gdb) set sysroot debugfs
  837. (gdb) set substitute-path /usr/src/debug debugfs/usr/src/debug
  838. (gdb) target remote IP-of-target:1234
  839. At this
  840. point, everything should automatically load (i.e. matching binaries,
  841. symbols and headers).
  842. .. note::
  843. The Gdb ``set`` commands in the previous example can be placed into the
  844. users ``~/.gdbinit`` file. Upon starting, Gdb automatically runs whatever
  845. commands are in that file.
  846. #. *Deploying without a full image rebuild:*
  847. In many cases, during development you want a quick method to deploy a
  848. new binary to the target and debug it, without waiting for a full
  849. image build.
  850. One approach to solving this situation is to just build the component
  851. you want to debug. Once you have built the component, copy the
  852. executable directly to both the target and the host ``debugfs``.
  853. If the binary is processed through the debug splitting in
  854. OpenEmbedded, you should also copy the debug items (i.e. ``.debug``
  855. contents and corresponding ``/usr/src/debug`` files) from the work
  856. directory. Here is an example::
  857. $ bitbake bash
  858. $ bitbake -c devshell bash
  859. $ cd ..
  860. $ scp packages-split/bash/bin/bash target:/bin/bash
  861. $ cp -a packages-split/bash-dbg/\* path/debugfs
  862. Debugging with the GNU Project Debugger (GDB) on the Target
  863. ===========================================================
  864. The previous section addressed using GDB remotely for debugging
  865. purposes, which is the most usual case due to the inherent hardware
  866. limitations on many embedded devices. However, debugging in the target
  867. hardware itself is also possible with more powerful devices. This
  868. section describes what you need to do in order to support using GDB to
  869. debug on the target hardware.
  870. To support this kind of debugging, you need do the following:
  871. - Ensure that GDB is on the target. You can do this by making
  872. the following addition to your ``local.conf`` file::
  873. EXTRA_IMAGE_FEATURES:append = " tools-debug"
  874. - Ensure that debug symbols are present. You can do so by adding the
  875. corresponding ``-dbg`` package to :term:`IMAGE_INSTALL`::
  876. IMAGE_INSTALL:append = " packagename-dbg"
  877. Alternatively, you can add the following to ``local.conf`` to include
  878. all the debug symbols::
  879. EXTRA_IMAGE_FEATURES:append = " dbg-pkgs"
  880. .. note::
  881. To improve the debug information accuracy, you can reduce the level
  882. of optimization used by the compiler. For example, when adding the
  883. following line to your ``local.conf`` file, you will reduce optimization
  884. from :term:`FULL_OPTIMIZATION` of "-O2" to :term:`DEBUG_OPTIMIZATION`
  885. of "-O -fno-omit-frame-pointer"::
  886. DEBUG_BUILD = "1"
  887. Consider that this will reduce the application's performance and is
  888. recommended only for debugging purposes.
  889. Other Debugging Tips
  890. ====================
  891. Here are some other tips that you might find useful:
  892. - When adding new packages, it is worth watching for undesirable items
  893. making their way into compiler command lines. For example, you do not
  894. want references to local system files like ``/usr/lib/`` or
  895. ``/usr/include/``.
  896. - If you want to remove the ``psplash`` boot splashscreen, add
  897. ``psplash=false`` to the kernel command line. Doing so prevents
  898. ``psplash`` from loading and thus allows you to see the console. It
  899. is also possible to switch out of the splashscreen by switching the
  900. virtual console (e.g. Fn+Left or Fn+Right on a Zaurus).
  901. - Removing :term:`TMPDIR` (usually ``tmp/``, within the
  902. :term:`Build Directory`) can often fix temporary build issues. Removing
  903. :term:`TMPDIR` is usually a relatively cheap operation, because task output
  904. will be cached in :term:`SSTATE_DIR` (usually ``sstate-cache/``, which is
  905. also in the :term:`Build Directory`).
  906. .. note::
  907. Removing :term:`TMPDIR` might be a workaround rather than a fix.
  908. Consequently, trying to determine the underlying cause of an issue before
  909. removing the directory is a good idea.
  910. - Understanding how a feature is used in practice within existing
  911. recipes can be very helpful. It is recommended that you configure
  912. some method that allows you to quickly search through files.
  913. Using GNU Grep, you can use the following shell function to
  914. recursively search through common recipe-related files, skipping
  915. binary files, ``.git`` directories, and the :term:`Build Directory`
  916. (assuming its name starts with "build")::
  917. g() {
  918. grep -Ir \
  919. --exclude-dir=.git \
  920. --exclude-dir='build*' \
  921. --include='*.bb*' \
  922. --include='*.inc*' \
  923. --include='*.conf*' \
  924. --include='*.py*' \
  925. "$@"
  926. }
  927. Following are some usage examples::
  928. $ g FOO # Search recursively for "FOO"
  929. $ g -i foo # Search recursively for "foo", ignoring case
  930. $ g -w FOO # Search recursively for "FOO" as a word, ignoring e.g. "FOOBAR"
  931. If figuring
  932. out how some feature works requires a lot of searching, it might
  933. indicate that the documentation should be extended or improved. In
  934. such cases, consider filing a documentation bug using the Yocto
  935. Project implementation of
  936. :yocto_bugs:`Bugzilla <>`. For information on
  937. how to submit a bug against the Yocto Project, see the Yocto Project
  938. Bugzilla :yocto_wiki:`wiki page </Bugzilla_Configuration_and_Bug_Tracking>`
  939. and the
  940. ":ref:`dev-manual/changes:submitting a defect against the yocto project`"
  941. section.
  942. .. note::
  943. The manuals might not be the right place to document variables
  944. that are purely internal and have a limited scope (e.g. internal
  945. variables used to implement a single ``.bbclass`` file).