debugging.rst 50 KB

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