10

GDB is complaining that my source file is more recent than the executable, and it appears the debugging information is indeed related to an older version of the source file, because gdb is stopping on a blank line:

Program received signal SIGSEGV, Segmentation fault.
0x0000000000000000 in ?? ()
(gdb) up
#1  0x00007ffff7ba2d88 in CBKeyPairGenerate (keyPair=0x602010) at library/src/CBHDKeys.c:246
warning: Source file is more recent than executable.
246
(gdb) list
241             if (versionBytes == CB_HD_KEY_VERSION_TEST_PUBLIC
242                     || versionBytes == CB_HD_KEY_VERSION_TEST_PRIVATE)
243                     return CB_NETWORK_TEST;
244
245             return CB_NETWORK_UNKNOWN;
246
247     }
248
249     uint8_t * CBHDKeyGetPrivateKey(CBHDKey * key) {
250

But the executable is more recent than the source file, see here:

$ ls -l library/src/CBHDKeys.c 
-rw-r--r-- 1 matt matt 9249 Apr 29 22:40 library/src/CBHDKeys.c
$ ls -l bin/noLowerAddressGenerator 
-rwxr-xr-x 1 matt matt 17845 Apr 30 15:52 bin/noLowerAddressGenerator

I tried rebuilding after make clean and ccache -C but the same problem occurs. When I updated the source file I only added whitespace, so the program logic remains equal.I feel that has something to do with it, but since I cleared the ccache and cleaned the build and bin directory with make clean I'm not sure what is going on.

Versions:

  • GNU Make 3.81
  • gcc (Debian 4.8.2-16) 4.8.2
  • GNU gdb (GDB) 7.6.2 (Debian 7.6.2-1)
  • ccache version 3.1.9
  • SolydXK - SMP Debian 3.13.5-1 (2014-03-04)
Matthew Mitchell
  • 5,293
  • 14
  • 70
  • 122
  • 1
    `CBKeyPairGenerate` will be the function name, `noLowerAddressGenerator` is an executable. – Oliver Matthews Apr 30 '14 at 15:21
  • Checking the obvious, but: I'll assume there are no other noLowerAddressGenerator exes on the path that gdb could be picking up? – Oliver Matthews Apr 30 '14 at 15:21
  • There is only one noLowerAddressGenerator and how could gdb get files mixed up anywhere when I pass in the exact path to the file? – Matthew Mitchell Apr 30 '14 at 15:23
  • 1
    The CBHDKeys.c file is one source file which is built into a library which noLowerAddressGenerator is linked against. – Matthew Mitchell Apr 30 '14 at 15:24
  • Ah, good point. Maybe the wrong library is being loaded... – Matthew Mitchell Apr 30 '14 at 15:25
  • 1
    Yep, I previously (I forgot about this) installed the library in /usr/local/lib and it's loading from there instead of the path I gave with the `-L` flag. Is it worth having an answer to this question, or should it be deleted? – Matthew Mitchell Apr 30 '14 at 15:55
  • Though I do wonder how I can compile a library that gives precedence to one path over /usr/local/lib. – Matthew Mitchell Apr 30 '14 at 15:57
  • @MatthewMitchell: You should post your `/usr/local/lib` discovery as the accepted answer as this just happened to me too. You can set `LD_LIBRARY_PATH` before running your binary if you want it to pick up libraries from another path, like a development version of the library. – Malvineous Feb 14 '15 at 14:34

1 Answers1

3

Perhaps you're not using the most recent compiled version of the code, if it's in a shared library. You could use ldd noLowerAddressGenerator to see the library dependencies of your program; I don't know if it's possible from within GDB to locate the relevant library, but there ought to be a way (please comment or edit if you know how).

If this is indeed the case, you might want to set environment LD_LIBRARY_PATH in GDB prior to running the program, to place your newly-built library ahead of any installed ones. You could look into setting the RPATH ELF variable when linking, but that's likely to be less help.

Another possibility is to run your debugger on a system where you know the library isn't installed. I've had good results using schroot to keep build/debug/install environments separated.

Toby Speight
  • 27,591
  • 48
  • 66
  • 103