title: GDB won't load source file
body: <ol>
  <li>I'm using <code>arm-linux-gcc</code> to compile a simple C file at host (debian i386) with <code>-g</code>.</li>
  <li>Then copy the <code>a.out</code> file to the target (arm,uclibc) computer.</li>
  <li>Run the <code>a.out</code> – it's just ok.</li>
  <li>Use GDB (target) <code>gdb a.out</code> and list the source code, it says <code>No such file or directory</code>.
  The fact has always been so?</li>
  <li>If I copy the <code>1.c</code> file to the target, then <code>list</code> command it lists the source code.</li>
  </ol>
  
  <p>My Question:</p>
  
  <h3>GDB has always been so, or there are other options I can control?</h3>
  
  <h3>Do you have any suggestions to debug the program?</h3>
  
  <p>Some information maybe is useful:</p>
  
  <p><strong>source code 1.c file</strong>:</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;string.h&gt;
  #include &lt;stdlib.h&gt;
  // main function
  int main(void)
  {
      int i;
      for(i=0;i&lt;3;i++){
          printf("i=%d\n",i);
      }
      return 0;
  }
  </code></pre>
  
  <p><strong>cross compile version(host)</strong></p>
  
  <pre><code>zodiac1111@debian:tmp$ arm-linux-gcc -v
  Using built-in specs.
  Target:arm-unknown-linux-uclibcgnueabi
  Configured with:/home/ldsh/rt9x5/linux/buildroot/buildroot/output/toolchain/gcc-4.3.5/configure \
  --prefix=/opt/rt9x5/arm-linux-uclibcgnueabi/usr --build=i686-pc-linux-gnu --host=i686-pc-linux-gnu \
  --target=arm-unknown-linux-uclibcgnueabi --enable-languages=c,c++ \
  --with-sysroot=/opt/rt9x5/arm-linux-uclibcgnueabi/usr/arm-unknown-linux-uclibcgnueabi/sysroot \
  --with-build-time-tools=/opt/rt9x5/arm-linux-uclibcgnueabi/usr/arm-unknown-linux-uclibcgnueabi/bin \
  --disable-__cxa_atexit --enable-target-optspace --disable-libgomp --with-gnu-ld --disable-libssp \
  --disable-multilib --disable-tls --enable-shared --with-gmp=/opt/rt9x5/arm-linux-uclibcgnueabi/usr \
  --with-mpfr=/opt/rt9x5/arm-linux-uclibcgnueabi/usr --enable-threads --disable-decimal-float \
  --with-float=soft --with-abi=aapcs-linux --with-arch=armv5te --with-tune=arm926ej-s \
  --with-pkgversion='Buildroot 2011.05-dirty' \
  --with-bugurl=http://bugs.buildroot.net/ : (reconfigured) /home/ldsh/rt9x5/linux/buildroot/buildroot/output/toolchain/gcc-4.3.5/configure \
  --prefix=/opt/rt9x5/arm-linux-uclibcgnueabi/usr --build=i686-pc-linux-gnu --host=i686-pc-linux-gnu \
  --target=arm-unknown-linux-uclibcgnueabi --enable-languages=c,c++ \
  --with-sysroot=/opt/rt9x5/arm-linux-uclibcgnueabi/usr/arm-unknown-linux-uclibcgnueabi/sysroot \
  --with-build-time-tools=/opt/rt9x5/arm-linux-uclibcgnueabi/usr/arm-unknown-linux-uclibcgnueabi/bin \
  --disable-__cxa_atexit --enable-target-optspace --disable-libgomp --with-gnu-ld --disable-libssp \
  --disable-multilib --disable-tls --enable-shared --with-gmp=/opt/rt9x5/arm-linux-uclibcgnueabi/usr \
  --with-mpfr=/opt/rt9x5/arm-linux-uclibcgnueabi/usr --enable-threads --disable-decimal-float \
  --with-float=soft --with-abi=aapcs-linux --with-arch=armv5te --with-tune=arm926ej-s \
  --with-pkgversion='Buildroot 2011.05-dirty' --with-bugurl=http://bugs.buildroot.net/
  Thread model:posix
  gcc version 4.3.5 (Buildroot 2011.05-dirty) 
  </code></pre>
  
  <p><strong>compile command:</strong></p>
  
  <pre><code>arm-linux-gcc -g 1.c
  </code></pre>
  
  <p><strong>host:</strong></p>
  
  <pre><code>zodiac1111@debian:tmp$ uname -a
  Linux debian 3.12-1-686-pae #1 SMP Debian 3.12.9-1 (2014-02-01) i686 GNU/Linux
  </code></pre>
  
  <p><strong>target:</strong></p>
  
  <pre><code># uname -a
  Linux AT91SAM9-RT9x5 2.6.39 #25 Mon Dec 30 17:40:40 CST 2013 armv5tejl GNU/Linux
  </code></pre>
  
  <p><strong>after copy to the target,then:</strong></p>
  
  <pre><code># ls -l
  total 1
  -rwxr--r--    1 ftp      83            6094 Feb 21 15:19 a.out
  </code></pre>
  
  <p><strong>execute is ok</strong></p>
  
  <pre><code># ./a.out 
  i=0
  i=1
  i=2
  </code></pre>
  
  <p><strong>the target gdb version</strong></p>
  
  <pre><code># gdb -v
  
  
  dlopen failed on 'libthread_db.so.1' - File not found
  GDB will not be able to debug pthreads.
  
  GNU gdb 6.8
  Copyright (C) 2008 Free Software Foundation, Inc.
  License GPLv3+: GNU GPL version 3 or later &lt;http://gnu.org/licenses/gpl.html&gt;
  This is free software: you are free to change and redistribute it.
  There is NO WARRANTY, to the extent permitted by law.  Type "show copying"
  and "show warranty" for details.
  This GDB was configured as "arm-unknown-linux-uclibcgnueabi".
  </code></pre>
  
  <p><strong>debug a.out</strong></p>
  
  <pre><code># gdb a.out 
  &lt;...&gt;
  (gdb) list
  1   1.c: No such file or directory.
      in 1.c
  (gdb) break main 
  Breakpoint 1 at 0x847c: file 1.c, line 8.
  (gdb) run 
  Starting program: /data/a.out 
  
  Breakpoint 1, main () at 1.c:8
  8   in 1.c
  (gdb) step
  9   in 1.c
      (gdb) p i
  $1 = 0
  (gdb) step
  i=0
  8   in 1.c
  (gdb) p i
  $2 = 0
  (gdb) step
  9   in 1.c
  (gdb) p i
  $3 = 1
  (gdb) 
  </code></pre>
  
  <p><strong>if I copy the source code file 1.c into the same directory</strong></p>
  
  <pre><code># ls -l
  -rw-r--r--    1 ftp      83             158 Feb 21 15:51 1.c
  -rwxr--r--    1 ftp      83            6094 Feb 21 15:19 a.out
  </code></pre>
  
  <p><strong>gdb could list the source code now.</strong></p>
  
  <pre><code># gdb a.out 
  &lt;...&gt;
  (gdb) list
  warning: Source file is more recent than executable.
  1   #include &lt;stdio.h&gt;
  2   #include &lt;string.h&gt;
  3   #include &lt;stdlib.h&gt;
  4   // main function
  5   int main(void)
  6   {
  7       int i;
  8       for(i=0;i&lt;3;i++){
  9           printf("i=%d\n",i);
  10      }
  (gdb) 
  </code></pre>
  
  <p>At host Platform,if I </p>
  
  <ol>
  <li>compile with <code>gcc -g 1.c</code> at host platform. </li>
  <li>than <strong>rename</strong> or <strong>remove</strong> the <code>1.c</code> file.</li>
  <li>Use<code>gdb a.out</code></li>
  </ol>
  
  <p>The same situation occurs.</p>
  
  <pre><code>zodiac1111@debian:tmp$ gdb -v
  GNU gdb (GDB) 7.6.2 (Debian 7.6.2-1)
  Copyright (C) 2013 Free Software Foundation, Inc.
  License GPLv3+: GNU GPL version 3 or later &lt;http://gnu.org/licenses/gpl.html&gt;
  This is free software: you are free to change and redistribute it.
  There is NO WARRANTY, to the extent permitted by law.  Type "show copying"
  and "show warranty" for details.
  This GDB was configured as "i486-linux-gnu".
  For bug reporting instructions, please see:
  &lt;http://www.gnu.org/software/gdb/bugs/&gt;.
  zodiac1111@debian:tmp$ gcc -v
  Using built-in specs.
  COLLECT_GCC=gcc
  COLLECT_LTO_WRAPPER=/usr/lib/gcc/i486-linux-gnu/4.8/lto-wrapper
  Target: i486-linux-gnu
  Configured with: ../src/configure -v --with-pkgversion='Debian 4.8.2-14' --with-bugurl=file:///usr/share/doc/gcc-4.8/README.Bugs --enable-languages=c,c++,java,go,d,fortran,objc,obj-c++ --prefix=/usr --program-suffix=-4.8 --enable-shared --enable-linker-build-id --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --with-gxx-include-dir=/usr/include/c++/4.8 --libdir=/usr/lib --enable-nls --with-sysroot=/ --enable-clocale=gnu --enable-libstdcxx-debug --enable-libstdcxx-time=yes --enable-gnu-unique-object --disable-libmudflap --enable-plugin --with-system-zlib --disable-browser-plugin --enable-java-awt=gtk --enable-gtk-cairo --with-java-home=/usr/lib/jvm/java-1.5.0-gcj-4.8-i386/jre --enable-java-home --with-jvm-root-dir=/usr/lib/jvm/java-1.5.0-gcj-4.8-i386 --with-jvm-jar-dir=/usr/lib/jvm-exports/java-1.5.0-gcj-4.8-i386 --with-arch-directory=i386 --with-ecj-jar=/usr/share/java/eclipse-ecj.jar --enable-objc-gc --enable-targets=all --enable-multiarch --with-arch-32=i586 --with-multilib-list=m32,m64,mx32 --with-tune=generic --enable-checking=release --build=i486-linux-gnu --host=i486-linux-gnu --target=i486-linux-gnu
  Thread model: posix
  gcc version 4.8.2 (Debian 4.8.2-14) 
  </code></pre>