My Wiki!

CPP debug

Strace

strace ./program
strace -f ./program <------ trace thread

Output of strace shows attempt to load dynamic libraries and their results

stat64("/vendor/lib/libstdc++.so", 0xbea97908) = -1 ENOENT (No such file or directory)
stat64("/system/lib/libstdc++.so", {st_mode=S_IFREG|0777, st_size=4132, ...}) = 0
open("/system/lib/libstdc++.so", O_RDONLY) = 3
lseek(3, 0, SEEK_SET)                   = 0
read(3, "\177ELF\1\1\1\0\0\0\0\0\0\0\0\0\3\0(\0\1\0\0\0�\5\0\0004\0\0\0"..., 4096) = 4096
lseek(3, -8, SEEK_END)                  = 4124
read(3, "nfoD2Ev\0", 8)                 = 8
mmap2(0x80100000, 36864, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x80100000
mmap2(0x80100000, 1976, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_FIXED, 3, 0) = 0x80100000
mprotect(0x80100000, 4096, PROT_READ|PROT_WRITE|PROT_EXEC) = 0
mmap2(0x80108000, 2084, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED, 3, 0) = 0x80108000
close(3)                                = 0
mprotect(0x80100000, 4096, PROT_READ|PROT_EXEC) = 0
getuid32()                              = 0
geteuid32()                             = 0
getgid32()                              = 0
getegid32()                             = 0
write(2, "reloc_library[1311]:  2626 canno"..., 61reloc_library[1311]:  2626 cannot locate '_ZNKSs5c_strEv'...
) = 61
write(2, "CANNOT LINK EXECUTABLE\n\0", 24CANNOT LINK EXECUTABLE
) = 24
SYS_248(0xffffffff, 0xfffffff4, 0xb0009498, 0x1, 0xffffffff <unfinished ... exit status 255>

Running program yields this error:

'2626 cannot locate 'ZNKSs5cstrEv'…' with c++filt you can decode the symbol.

# c++filt _ZNKSs5c_strEv

c++filt decodes that symbol to

std::basic_string<char, std::char_traits<char>, std::allocator<char> >::c_str() const

This function might not be available…

To find the function inside the library:

objdump -xxx binary

Compile libs with --enable-debug

Some libs have the option be compiled with Debug enabled. Check:

  ./configure --help 
  

Look for –enable-debug option.

GDB is must

Run program with GDB

On host:

  gdb ./program
  run
  

On remote with gdbserver.

See content of library

 nm -C mymlib.a
 
 ar -vt /usr/lib/libnsl.a | head 5

Navigation