<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<!DOCTYPE bugzilla SYSTEM "https://bugzilla.yoctoproject.org/page.cgi?id=bugzilla.dtd">

<bugzilla version="5.0.6"
          urlbase="https://bugzilla.yoctoproject.org/"
          
          maintainer="it-coreprojects-helpdesk@linuxfoundation.org"
>

    <bug>
          <bug_id>9481</bug_id>
          
          <creation_ts>2016-04-19 07:23:26 +0000</creation_ts>
          <short_desc>Add example to &quot;5.23. Debugging With the GNU Project Debugger (GDB) Remotely&quot;</short_desc>
          <delta_ts>2017-01-18 23:35:47 +0000</delta_ts>
          <reporter_accessible>1</reporter_accessible>
          <cclist_accessible>1</cclist_accessible>
          <classification_id>9</classification_id>
          <classification>Documentation</classification>
          <product>Development Manual</product>
          <component>development</component>
          <version>unspecified</version>
          <rep_platform>x86</rep_platform>
          <op_sys>Multiple</op_sys>
          <bug_status>RESOLVED</bug_status>
          <resolution>FIXED</resolution>
          
          
          <bug_file_loc></bug_file_loc>
          <status_whiteboard>18 Jan 2017: RESOLVED</status_whiteboard>
          <keywords></keywords>
          <priority>Medium+</priority>
          <bug_severity>enhancement</bug_severity>
          <target_milestone>2.3 M2</target_milestone>
          
          
          <everconfirmed>1</everconfirmed>
          <reporter name="Hongxu Jia">hongxu.jia</reporter>
          <assigned_to name="Mark Hatle">mark.hatle</assigned_to>
          <cc>jose.perez.carranza</cc>
    
    <cc>liezhi.yang</cc>
    
    <cc>mark.hatle</cc>
    
    <cc>patrick.ohly</cc>
    
    <cc>richard.purdie</cc>
    
    <cc>ross.burton</cc>
    
    <cc>schnitzeltony</cc>
    
    <cc>srifenbark</cc>
          
          <qa_contact name="Francisco Pedraza">francisco.j.pedraza.gonzalez</qa_contact>
          <cf_os>---</cf_os>
          <cf_regression_type>---</cf_regression_type>
          
          <cf_docchange>Done (doc changes complete)</cf_docchange>

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>61370</commentid>
    <comment_count>0</comment_count>
    <who name="Hongxu Jia">hongxu.jia</who>
    <bug_when>2016-04-19 07:23:26 +0000</bug_when>
    <thetext>Since -fdebug-prefix-map was added to DEBUG_FLAGS, previously
remote debug could not work correctly, so we add an example to
explain how to do remote debug.

Example:

1. Build a image with gdbserver and gzip installed. The gzip
   is the debug binary. Append the following to local.conf
...
IMAGE_INSTALL_append = &quot; gdbserver gzip&quot;
...

$ bitbake core-image-sato

2. Build gdb-cross for remote debug on host

$ bitbake gdb-cross-i586

3. start qemu

$ runqemu qemux86 core-image-sato

4. On host side, create symlink /usr/src/debug to
   ${BASE_WORKDIR}/${MULTIMACH_TARGET_SYS} which the
   location of sources is /usr/src/debug.

$ ln -snf /TOPDIR/tmp/work/i586-poky-linux /usr/src/debug

5. On target side, ipaddr is 128.224.163.187,
   run gdbserver to debug &quot;gzip -h&quot;

root@qemux86-64:~# gdbserver localhost:1024 gzip -h
Process gzip created; pid = 530
Listening on port 1024

6. On host side, enter gzip&apos;s devshell
$ bitbake -cdevshell gzip

7. On host side, run gdb-cross to remote debug gzip

gzip-1.6# i586-poky-linux-gdb ../build/gzip

8. Use path ${STAGING_DIR_HOST} as the system root for
   the program being debugged. Any absolute shared
   library paths will be prefixed with path;

(gdb) set sysroot /TOPDIR/tmp/sysroots/qemux86


9. Start remote target, set break point at help()

(gdb) target remote 128.224.163.187:1024
(gdb) break gzip.c:325
(gdb) info break
Num     Type           Disp Enb Address            What
1       breakpoint     keep y   0x0000000000401ec1 in main at /usr/src/debug/gzip/1.6-r0/gzip-1.6/gzip.c:325
(gdb) c
Continuing.

Breakpoint 1, main (argc=2, argv=0x7fffffffeca8) at /usr/src/debug/gzip/1.6-r0/gzip-1.6/gzip.c:465
465                 help(); do_exit(OK); break;
(gdb) list
460             case &apos;d&apos;:
461                 decompress = 1; break;
462             case &apos;f&apos;:
463                 force++; break;
464             case &apos;h&apos;: case &apos;H&apos;:
465                 help(); do_exit(OK); break;
466             case &apos;k&apos;:
467                 keep = 1; break;
468             case &apos;l&apos;:
469                 list = decompress = to_stdout = 1; break;
(gdb) c
Continuing.
[Inferior 1 (process 1246) exited normally]


10. On target side, get output of &quot;gzip -h&quot;
[snip]
Remote debugging from host 128.224.153.74
Usage: gzip [OPTION]... [FILE]...
Compress or uncompress FILEs (by default, compress FILES in-place).

Mandatory arguments to long options are mandatory for short options too.

  -c, --stdout      write on standard output, keep original files unchanged
  -d, --decompress  decompress
  -f, --force       force overwrite of output file and compress links
  -h, --help        give this help
  -k, --keep        keep (don&apos;t delete) input files
  -l, --list        list compressed file contents
  -L, --license     display software license
  -n, --no-name     do not save or restore the original name and time stamp
  -N, --name        save or restore the original name and time stamp
  -q, --quiet       suppress all warnings
  -r, --recursive   operate recursively on directories
  -S, --suffix=SUF  use suffix SUF on compressed files
  -t, --test        test compressed file integrity
  -v, --verbose     verbose mode
  -V, --version     display version number
  -1, --fast        compress faster
  -9, --best        compress better

With no FILE, or when FILE is -, read standard input.

Report bugs to &lt;bug-gzip@gnu.org&gt;.

Child exited with status 0
GDBserver exiting
[snip]

//Hongxu</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>61371</commentid>
    <comment_count>1</comment_count>
    <who name="Hongxu Jia">hongxu.jia</who>
    <bug_when>2016-04-19 08:02:56 +0000</bug_when>
    <thetext>The main difference than before is:

4. On host side, create symlink /usr/src/debug to
   ${BASE_WORKDIR}/${MULTIMACH_TARGET_SYS} which the
   location of sources is /usr/src/debug.

$ ln -snf /TOPDIR/tmp/work/i586-poky-linux /usr/src/debug

8. Use path ${STAGING_DIR_HOST} as the system root for
   the program being debugged. Any absolute shared
   library paths will be prefixed with path;

(gdb) set sysroot /TOPDIR/tmp/sysroots/qemux86

//Hongxu</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>61395</commentid>
    <comment_count>2</comment_count>
    <who name="Hongxu Jia">hongxu.jia</who>
    <bug_when>2016-04-19 13:03:09 +0000</bug_when>
    <thetext>
&gt; 4. On host side, create symlink /usr/src/debug to
&gt;    ${BASE_WORKDIR}/${MULTIMACH_TARGET_SYS} which the
&gt;    location of sources is /usr/src/debug.
&gt; 
&gt; $ ln -snf /TOPDIR/tmp/work/i586-poky-linux /usr/src/debug
&gt; 

As Mark Hatle suggested, we use a better way to set the substitution
of source path, here is the update of 4.

4. On host side, Set a substitution rule for finding source files.
   Replace /usr/src/debug with ${BASE_WORKDIR}/${MULTIMACH_TARGET_SYS}

(gdb) set substitute-path /usr/src/debug /TOPDIR/tmp/work/i586-poky-linux

//Hongxu</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>61396</commentid>
    <comment_count>3</comment_count>
    <who name="Hongxu Jia">hongxu.jia</who>
    <bug_when>2016-04-19 13:06:50 +0000</bug_when>
    <thetext>Changed in V2:
- Move 4) to 8)

Example:

1. Build a image with gdbserver and gzip installed. The gzip
   is the debug binary. Append the following to local.conf
...
IMAGE_INSTALL_append = &quot; gdbserver gzip&quot;
...

$ bitbake core-image-sato

2. Build gdb-cross for remote debug on host

$ bitbake gdb-cross-i586

3. start qemu

$ runqemu qemux86 core-image-sato

4. On target side, ipaddr is 128.224.163.187,
   run gdbserver to debug &quot;gzip -h&quot;

root@qemux86-64:~# gdbserver localhost:1024 gzip -h
Process gzip created; pid = 530
Listening on port 1024

5. On host side, enter gzip&apos;s devshell
$ bitbake -cdevshell gzip

6. On host side, run gdb-cross to remote debug gzip

gzip-1.6# i586-poky-linux-gdb ../build/gzip

7. Use path ${STAGING_DIR_HOST} as the system root for
   the program being debugged. Any absolute shared
   library paths will be prefixed with path;

(gdb) set sysroot /TOPDIR/tmp/sysroots/qemux86

8. On host side, set a substitution rule for finding source files.
   Replace /usr/src/debug with ${BASE_WORKDIR}/${MULTIMACH_TARGET_SYS}

(gdb) set substitute-path /usr/src/debug /TOPDIR/tmp/work/i586-poky-linux

9. Start remote target, set break point at help()

(gdb) target remote 128.224.163.187:1024
(gdb) break gzip.c:325
(gdb) info break
Num     Type           Disp Enb Address            What
1       breakpoint     keep y   0x0000000000401ec1 in main at /usr/src/debug/gzip/1.6-r0/gzip-1.6/gzip.c:325
(gdb) c
Continuing.

Breakpoint 1, main (argc=2, argv=0x7fffffffeca8) at /usr/src/debug/gzip/1.6-r0/gzip-1.6/gzip.c:465
465                 help(); do_exit(OK); break;
(gdb) list
460             case &apos;d&apos;:
461                 decompress = 1; break;
462             case &apos;f&apos;:
463                 force++; break;
464             case &apos;h&apos;: case &apos;H&apos;:
465                 help(); do_exit(OK); break;
466             case &apos;k&apos;:
467                 keep = 1; break;
468             case &apos;l&apos;:
469                 list = decompress = to_stdout = 1; break;
(gdb) c
Continuing.
[Inferior 1 (process 1246) exited normally]


10. On target side, get output of &quot;gzip -h&quot;
[snip]
Remote debugging from host 128.224.153.74
Usage: gzip [OPTION]... [FILE]...
Compress or uncompress FILEs (by default, compress FILES in-place).

Mandatory arguments to long options are mandatory for short options too.

  -c, --stdout      write on standard output, keep original files unchanged
  -d, --decompress  decompress
  -f, --force       force overwrite of output file and compress links
  -h, --help        give this help
  -k, --keep        keep (don&apos;t delete) input files
  -l, --list        list compressed file contents
  -L, --license     display software license
  -n, --no-name     do not save or restore the original name and time stamp
  -N, --name        save or restore the original name and time stamp
  -q, --quiet       suppress all warnings
  -r, --recursive   operate recursively on directories
  -S, --suffix=SUF  use suffix SUF on compressed files
  -t, --test        test compressed file integrity
  -v, --verbose     verbose mode
  -V, --version     display version number
  -1, --fast        compress faster
  -9, --best        compress better

With no FILE, or when FILE is -, read standard input.

Report bugs to &lt;bug-gzip@gnu.org&gt;.

Child exited with status 0
GDBserver exiting
[snip]

//Hongxu</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>61397</commentid>
    <comment_count>4</comment_count>
    <who name="Hongxu Jia">hongxu.jia</who>
    <bug_when>2016-04-19 13:15:28 +0000</bug_when>
    <thetext>So the main difference than before is:

7. Use path ${STAGING_DIR_HOST} as the system root for
   the program being debugged. Any absolute shared
   library paths will be prefixed with path;

(gdb) set sysroot /TOPDIR/tmp/sysroots/qemux86

8. On host side, set a substitution rule for finding source files.
   Replace /usr/src/debug with ${BASE_WORKDIR}/${MULTIMACH_TARGET_SYS}

(gdb) set substitute-path /usr/src/debug /TOPDIR/tmp/work/i586-poky-linux

//Hongxu</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>61398</commentid>
    <comment_count>5</comment_count>
    <who name="Hongxu Jia">hongxu.jia</who>
    <bug_when>2016-04-19 13:18:13 +0000</bug_when>
    <thetext>
In http://www.yoctoproject.org/docs/2.1/dev-manual/dev-manual.html#platdev-gdb-remotedebug

5.23.3.2. Create the GDB Initialization File and Point to Your Root Filesystem¶

Aside from the GDB cross-binary, you also need a GDB initialization file in the same top directory in which your binary resides. When you start GDB on your host development system, GDB finds this initialization file and executes all the commands within. For information on the .gdbinit, see &quot;Debugging with GDB&quot;, which is maintained by sourceware.org.

You need to add a statement in the ~/.gdbinit file that points to your root filesystem. Here is an example that points to the root filesystem for target device:

     set sysroot &lt;value of ${STAGING_DIR_HOST}&gt;
     set substitute-path /usr/src/debug &lt;value of ${BASE_WORKDIR}/${MULTIMACH_TARGET_SYS}&gt;</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>61399</commentid>
    <comment_count>6</comment_count>
    <who name="Mark Hatle">mark.hatle</who>
    <bug_when>2016-04-19 13:22:32 +0000</bug_when>
    <thetext>I&apos;m writing up a complete set of steps.  It will take me a few minutes to perform a build and verify the steps are correct.

My concern with the previous comments is that these steps are very specific on a use-case of attaching the debugger to a work dir.  This is not and should not be the typical debugging way a user debugs a target.  (It can be an alternative use-case, but shouldn&apos;t be the primary.)</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>61402</commentid>
    <comment_count>7</comment_count>
    <who name="Hongxu Jia">hongxu.jia</who>
    <bug_when>2016-04-19 13:37:03 +0000</bug_when>
    <thetext>(In reply to comment #6)
&gt; I&apos;m writing up a complete set of steps.  It will take me a few minutes to
&gt; perform a build and verify the steps are correct.
&gt; 
&gt; My concern with the previous comments is that these steps are very specific
&gt; on a use-case of attaching the debugger to a work dir.  This is not and
&gt; should not be the typical debugging way a user debugs a target.  (It can be
&gt; an alternative use-case, but shouldn&apos;t be the primary.)

Agree

//Hongxu</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>61406</commentid>
    <comment_count>8</comment_count>
    <who name="Mark Hatle">mark.hatle</who>
    <bug_when>2016-04-19 14:43:24 +0000</bug_when>
    <thetext>(There is currently a bug in master where the IMAGE_FSTYPES_DEBUGFS settings do not work.  This will be fixed in the release, or specific limitations will be noted.)

5.23:  I would remove the note.  It’s simply going to be confusing to someone.  Without the src’s in the -dbg packages things become undebuggable.  The only advantage is that you can inspect variables and get backtraces — but you have no correlation to the actual source used to build the binary.

At this stage of the documentation, I wouldn’t want to confuse someone with these types of options, as they’re corner cases — and should not be standard configurations.

The rest of the parts of 5.23.* should be modified to match the items below.

1. Configure your build system to construct the companion debug filesystem

In the local.conf:

IMAGE_GEN_DEBUGFS = &apos;1&apos;
IMAGE_FSTYPES_DEBUGFS = &apos;tar.bz2&apos;

The options above will cause the system to generate a special companion filesystem fragment, that contains the matching source and debug symbols to your deployable filesystem.  It does this by looking at what is in the deployed filesystem, and pulling the corresponding -dbg packages.

The companion debug filesystem is NOT a complete filesystem, but only contains the debug fragements.  It must be combined with the full filesystem for debugging.  (Later steps will show this.)

2. Configure the system to include gdbserver in the target filesystem

In the local.conf (or an image recipe):

IMAGE_INSTALL_append = “ gdbserver&quot;

3. Build the environment

Construct the image (and companion Debug Filesystem)
   bitbake &lt;image&gt;

Build the cross GDB component and make it available for debugging

 Build the SDK that matches the image (this is best for a production build for later debugging, especially during long term maintenance)
   bitbake -c populate_sdk &lt;image&gt;

   or 

 Build the minimal toolchain components that match the target (this is smaller then a typical SDK and only contains a minimal set of components to build simple test applications, as well as run the debugger)
   bitbake meta-toolchain

   or

 Build gdb itself within the build system (this produces a temporary copy of cross-gdb that can be used for debugging during development.  It is the quickest approach, but the other methods are better for long term maintenance strategies.)
   bitbake gdb-cross-&lt;arch&gt;

 (Note: If you run bitbake gdb-cross, the system will give you a suggestion like gdb-cross-i586, the suggestion is likely the actual name you want to use.)

4. Setup your environment

4.1 Setup the debugfs

$ mkdir debugfs
$ cd debugfs
$ tar xvfj &lt;build dir&gt;/tmp-glibc/deploy/images/&lt;machine&gt;/&lt;image&gt;.rootfs.tar.bz2
$ tar xvfj &lt;build dir&gt;/tmp-glibc/deploy/images/&lt;machine&gt;/&lt;image&gt;-dbg.rootfs.tar.bz2

4.2 Setup GDB

Install the SDK (if you built one) and source the correct environment file.  This will put it in your path.

if using the build system gdb will be in &lt;build&gt;/&lt;tmp&gt;/sysroots/&lt;host&gt;/usr/bin/&lt;arch&gt;/&lt;arch&gt;-gdb

5. Boot the target

For QEMU, &lt;link to runqemu docs…&gt;

(verify that your host can access the target via TCP)

6. Debug a program

6.1 Run gdbserver on the target, such as:

(We’ll debug gzip in this example, see gdbserver docs for additional options)

root@qemux86:~# gdbserver localhost:1234 /bin/gzip —help

6.2 On the host, run gdb, configure it and connect to the target:

$ cd &lt;directory holding the debugfs dir&gt;
$ &lt;arch&gt;-gdb

(gdb) set sysroot debugfs
(gdb) set substitute-path /usr/src/debug debugfs/usr/src/debug
(gdb) target remote &lt;ip of target&gt;:1234

At this point everything should automatically load (matching binaries, symbols and headers.)

Note: the gdb ‘set’ commands above can be placed into the users ~/.gdbinit   GDB will automatically run whatever commands are in that file when it is started.


7. Deploying WITHOUT a full image rebuild

In many cases, during development you want a quick method to deploy a new binary to the target and debug it, without waiting for a full image build.

One approach to this is to build the component you want to debug.  Then directly copy the executable to BOTH the target and the host ‘debugfs’.  If the binary is processed through the debug splitting in OE, you should also copy the debug items (the .debug contents and corresponding /usr/src/debug) from the work dir.

Such as:

$ bitbake bash
$ bitbake -c devshell bash
$ cd ..
$ scp packages-split/bash/bin/bash &lt;target&gt;:/bin/bash
$ cp -a packages-split/bash-dbg/* &lt;path&gt;/debugfs</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>61407</commentid>
    <comment_count>9</comment_count>
    <who name="Mark Hatle">mark.hatle</who>
    <bug_when>2016-04-19 14:48:51 +0000</bug_when>
    <thetext>Example in step 7 was missing a copy...

Should be:

7. Deploying WITHOUT a full image rebuild

In many cases, during development you want a quick method to deploy a new binary to the target and debug it, without waiting for a full image build.

One approach to this is to build the component you want to debug.  Then directly copy the executable to BOTH the target and the host ‘debugfs’.  If the binary is processed through the debug splitting in OE, you should also copy the debug items (the .debug contents and corresponding /usr/src/debug) from the work dir.

Such as:

$ bitbake bash
$ bitbake -c devshell bash
$ cd ..
$ scp packages-split/bash/bin/bash &lt;target&gt;:/bin/bash
$ cp packages-split/bash/bin/bash &lt;path&gt;/debugfs/bin/bash
$ cp -r packages-split/bash-dbg/* &lt;path&gt;/debugfs</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>63156</commentid>
    <comment_count>10</comment_count>
    <who name="Scott Rifenbark">srifenbark</who>
    <bug_when>2016-06-20 15:44:16 +0000</bug_when>
    <thetext>added myself to the CC list for the doc component.

Scott</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>63484</commentid>
    <comment_count>11</comment_count>
    <who name="Scott Rifenbark">srifenbark</who>
    <bug_when>2016-06-29 20:17:33 +0000</bug_when>
    <thetext>Mark, 

I am looking at the section in the dev-manual at http://www.yoctoproject.org/docs/2.2/dev-manual/dev-manual.html#platdev-gdb-remotedebug and trying to map the steps to what is there in the 5.24.* subsections.  They don&apos;t map that well.  Should I replace the entire existing 5.24 section with the steps you have in your comments here?

Thanks, 
Scott</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>66595</commentid>
    <comment_count>12</comment_count>
    <who name="Scott Rifenbark">srifenbark</who>
    <bug_when>2016-09-26 16:43:46 +0000</bug_when>
    <thetext>Setting to NEEDINFO.  Please see my last comment.

Scott</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>67124</commentid>
    <comment_count>13</comment_count>
    <who name="Mark Hatle">mark.hatle</who>
    <bug_when>2016-10-11 07:31:35 +0000</bug_when>
    <thetext>All of the steps for building the SDK and/or cross-gdb are still applicable.  The thing that changes is primarily around the notes to &quot;be sure to include the -dbg&quot; packages in your image.  That is simply not necessary.

Instead if you use the steps from my previous comment you can produce a release image, and a corresponding debug symbol image.

Then on the target you deploy the release image, on the host you can use the debug symbol image with the cross debugger.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>67145</commentid>
    <comment_count>14</comment_count>
    <who name="Scott Rifenbark">srifenbark</who>
    <bug_when>2016-10-11 16:47:29 +0000</bug_when>
    <thetext>(In reply to comment #8)
&gt; (There is currently a bug in master where the IMAGE_FSTYPES_DEBUGFS settings
&gt; do not work.  This will be fixed in the release, or specific limitations
&gt; will be noted.)
&gt; 
&gt; 5.23:  I would remove the note.  It’s simply going to be confusing to
&gt; someone.  Without the src’s in the -dbg packages things become undebuggable.
&gt; The only advantage is that you can inspect variables and get backtraces —
&gt; but you have no correlation to the actual source used to build the binary.
&gt; 
&gt; At this stage of the documentation, I wouldn’t want to confuse someone with
&gt; these types of options, as they’re corner cases — and should not be standard
&gt; configurations.

I am assuming that the section under question is 5.24.  I think since you had added these comments a new sub-section was added.  So, I am removing the &quot;note&quot; at the end of the section.  I am leaving the &quot;tip&quot;. 

&gt; 
&gt; The rest of the parts of 5.23.* should be modified to match the items below.

I am removing the sub-section scheme completely and replacing it with a numbered list based on your steps here.

&gt; 
&gt; 1. Configure your build system to construct the companion debug filesystem
&gt; 
&gt; In the local.conf:
&gt; 
&gt; IMAGE_GEN_DEBUGFS = &apos;1&apos;
&gt; IMAGE_FSTYPES_DEBUGFS = &apos;tar.bz2&apos;
&gt; 
&gt; The options above will cause the system to generate a special companion
&gt; filesystem fragment, that contains the matching source and debug symbols to
&gt; your deployable filesystem.  It does this by looking at what is in the
&gt; deployed filesystem, and pulling the corresponding -dbg packages.
&gt; 
&gt; The companion debug filesystem is NOT a complete filesystem, but only
&gt; contains the debug fragements.  It must be combined with the full filesystem
&gt; for debugging.  (Later steps will show this.)
&gt; 
&gt; 2. Configure the system to include gdbserver in the target filesystem
&gt; 
&gt; In the local.conf (or an image recipe):
&gt; 
&gt; IMAGE_INSTALL_append = “ gdbserver&quot;
&gt; 
&gt; 3. Build the environment
&gt; 
&gt; Construct the image (and companion Debug Filesystem)
&gt;    bitbake &lt;image&gt;
&gt; 
&gt; Build the cross GDB component and make it available for debugging
&gt; 
&gt;  Build the SDK that matches the image (this is best for a production build
&gt; for later debugging, especially during long term maintenance)
&gt;    bitbake -c populate_sdk &lt;image&gt;
&gt; 
&gt;    or 
&gt; 
&gt;  Build the minimal toolchain components that match the target (this is
&gt; smaller then a typical SDK and only contains a minimal set of components to
&gt; build simple test applications, as well as run the debugger)
&gt;    bitbake meta-toolchain
&gt; 
&gt;    or
&gt; 
&gt;  Build gdb itself within the build system (this produces a temporary copy of
&gt; cross-gdb that can be used for debugging during development.  It is the
&gt; quickest approach, but the other methods are better for long term
&gt; maintenance strategies.)
&gt;    bitbake gdb-cross-&lt;arch&gt;
&gt; 
&gt;  (Note: If you run bitbake gdb-cross, the system will give you a suggestion
&gt; like gdb-cross-i586, the suggestion is likely the actual name you want to
&gt; use.)
&gt; 
&gt; 4. Setup your environment
&gt; 
&gt; &gt; 4.1 Setup the debugfs
&gt; 
&gt; $ mkdir debugfs
&gt; $ cd debugfs
&gt; $ tar xvfj &lt;build
&gt; dir&gt;/tmp-glibc/deploy/images/&lt;machine&gt;/&lt;image&gt;.rootfs.tar.bz2
&gt; $ tar xvfj &lt;build
&gt; dir&gt;/tmp-glibc/deploy/images/&lt;machine&gt;/&lt;image&gt;-dbg.rootfs.tar.bz2
&gt; 
4.2 Setup GDB
&gt; 
&gt; Install the SDK (if you built one) and source the correct environment file. 
&gt; This will put it in your path.
&gt; 
&gt; if using the build system gdb will be in
&gt; &lt;build&gt;/&lt;tmp&gt;/sysroots/&lt;host&gt;/usr/bin/&lt;arch&gt;/&lt;arch&gt;-gdb
&gt; 
&gt; 5. Boot the target
&gt; 
&gt; For QEMU, &lt;link to runqemu docs…&gt;
&gt; 
&gt; (verify that your host can access the target via TCP)
&gt; 
&gt; 6. Debug a program
&gt; 
&gt; 6.1 Run gdbserver on the target, such as:
&gt; 
&gt; (We’ll debug gzip in this example, see gdbserver docs for additional options)
&gt; 
&gt; root@qemux86:~# gdbserver localhost:1234 /bin/gzip —help
&gt; 
&gt; 6.2 On the host, run gdb, configure it and connect to the target:
&gt; 
&gt; $ cd &lt;directory holding the debugfs dir&gt;
&gt; $ &lt;arch&gt;-gdb
&gt; 
&gt; (gdb) set sysroot debugfs
&gt; (gdb) set substitute-path /usr/src/debug debugfs/usr/src/debug
&gt; (gdb) target remote &lt;ip of target&gt;:1234
&gt; 
&gt; At this point everything should automatically load (matching binaries,
&gt; symbols and headers.)
&gt; 
&gt; Note: the gdb ‘set’ commands above can be placed into the users ~/.gdbinit  
&gt; GDB will automatically run whatever commands are in that file when it is
&gt; started.
&gt; 
&gt; 
&gt; 7. Deploying WITHOUT a full image rebuild
&gt; 
&gt; In many cases, during development you want a quick method to deploy a new
&gt; binary to the target and debug it, without waiting for a full image build.
&gt; 
&gt; One approach to this is to build the component you want to debug.  Then
&gt; directly copy the executable to BOTH the target and the host ‘debugfs’.  If
&gt; the binary is processed through the debug splitting in OE, you should also
&gt; copy the debug items (the .debug contents and corresponding /usr/src/debug)
&gt; from the work dir.
&gt; 
&gt; Such as:
&gt; 
&gt; $ bitbake bash
&gt; $ bitbake -c devshell bash
&gt; $ cd ..
&gt; $ scp packages-split/bash/bin/bash &lt;target&gt;:/bin/bash
&gt; $ cp -a packages-split/bash-dbg/* &lt;path&gt;/debugfs

You can see the new section at http://www.yoctoproject.org/docs/2.2/dev-manual/dev-manual.html#platdev-gdb-remotedebug.  It needs to be reviewed as I did some rewriting and guessing in some spots. 

Thanks,
Scott</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>69577</commentid>
    <comment_count>15</comment_count>
    <who name="Scott Rifenbark">srifenbark</who>
    <bug_when>2017-01-06 15:26:40 +0000</bug_when>
    <thetext>It has been quite some time since this change was made for the docs.  I have yet to get an &quot;okay&quot; on the solution. 

Thanks, 
Scott</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>69763</commentid>
    <comment_count>16</comment_count>
    <who name="Mark Hatle">mark.hatle</who>
    <bug_when>2017-01-12 16:36:50 +0000</bug_when>
    <thetext>Sorry thought I had responded previously.

I&apos;ve reviewed the new section and it appears to be correct and functional to me.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>69916</commentid>
    <comment_count>17</comment_count>
    <who name="Scott Rifenbark">srifenbark</who>
    <bug_when>2017-01-18 23:35:47 +0000</bug_when>
    <thetext>Mark, 

Thanks for getting back to me.  I am marking the bug RESOLVED and setting the Doc flag to &quot;done.&quot;

Scott</thetext>
  </long_desc>
      
      

    </bug>

</bugzilla>