debugging.rst 50 KB

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