debugging.rst 50 KB

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