debugging.rst 51 KB

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