1 /* Copyright (C) 1998, 1999, 2000, 2002, 2005 Red Hat, Inc.
2 This file is part of elfutils.
3 Written by Ulrich Drepper <drepper@redhat.com>, 1998.
5 This file is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 3 of the License, or
8 (at your option) any later version.
10 elfutils is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>. */
28 main (int argc, char *argv[])
38 puts ("missing parameter");
42 fd = open (argv[1], O_RDONLY);
45 printf ("cannot open \"%s\": %s\n", argv[1], strerror (errno));
49 elf_version (EV_CURRENT);
51 elf = elf_begin (fd, ELF_C_READ, NULL);
54 printf ("cannot open ELF file: %s\n", elf_errmsg (-1));
58 if (elf_kind (elf) != ELF_K_ELF)
60 printf ("\"%s\" is not an ELF file\n", argv[1]);
64 if (gelf_getehdr (elf, &ehdr) == NULL)
66 printf ("cannot get the ELF header: %s\n", elf_errmsg (-1));
70 strndx = ehdr.e_shstrndx;
73 while ((scn = elf_nextscn (elf, scn)) != NULL)
78 if (gelf_getshdr (scn, &shdr) != NULL)
79 name = elf_strptr (elf, strndx, (size_t) shdr.sh_name);
81 printf ("section: `%s'\n", name);
84 if (elf_end (elf) != 0)
86 printf ("error while freeing ELF descriptor: %s\n", elf_errmsg (-1));