[Ltrace-devel] Fwd: Couldn't get data of section #0 from "/proc/3829/exe": no error

Petr Machata pmachata at redhat.com
Sun May 11 16:28:46 UTC 2014


Ciapata Koza <ciapatakoza at gmail.com> writes:

> ./ltrace pwd
>
> Output:
> root at raspberrypi:/home/pi/src/ltrace# ./ltrace pwd
> Couldn't get data of section #0 from "/proc/14845/exe": no error

Where does "pwd" come from?  What does "file $(which pwd) ./ltrace" say?
Why I'm asking: you aren't cross-compiling and then running ltrace on
native pwd, are you?

I'm really not sure what might be going wrong.  What does this do when
compiled?

#include <fcntl.h>
#include <libelf.h>
#include <gelf.h>
#include <unistd.h>
#include <assert.h>

int
main(int argc, char *argv[])
{
  elf_version (EV_CURRENT);

  int fd = open (argv[1], O_RDONLY);
  assert (fd != -1);

  Elf *elf = elf_begin(fd, ELF_C_READ_MMAP, NULL);
  assert (elf != NULL);

  Elf_Scn *scn = elf_getscn(elf, 0);
  assert (scn != NULL);

  GElf_Shdr shdr_mem, *shdr = gelf_getshdr(scn, &shdr_mem);
  assert (shdr != NULL);

  elf_end(elf);
  close(fd);
  return 0;
}

If ELF_C_READ_MMAP is not available, just replace it with ELF_C_READ.

Build it:
$ gcc that-file.c -lelf -Wall

And use it like:
$ ./a.out ./a.out
$ ./a.out $(which pwd)
$ ./a.out /dev/null 
a.out: elf.c:19: main: Assertion `scn != ((void *)0)' failed.

etc.  It should return 0 and shouldn't assert on ELF files.  If it
behaves consistently with ltrace, the error is probably in libelf.
Otherwise we may have a bug in ltrace.

Thanks,
PM



More information about the Ltrace-devel mailing list