dwarves: Don't pass argp to dwarf_loadfl

Now we just pass a NULL terminated array of filenames, since we got rid
of that ugly -e insertion hack.

Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
This commit is contained in:
Arnaldo Carvalho de Melo 2009-02-09 21:43:56 -02:00
parent 3bbd1342b2
commit 138cc4739c
15 changed files with 72 additions and 67 deletions

View File

@ -676,7 +676,7 @@ int main(int argc, char *argv[])
int remaining, err;
struct cus *old_cus, *new_cus;
char *old_filename, *new_filename;
char *dwfl_argv[4];
char *filenames[2];
struct stat st;
if (dwarves__init(0)) {
@ -684,9 +684,8 @@ int main(int argc, char *argv[])
return EXIT_FAILURE;
}
argp_parse(&codiff__argp, argc, argv, 0, &remaining, NULL);
if (remaining < argc) {
if (argp_parse(&codiff__argp, argc, argv, 0, &remaining, NULL) ||
remaining < argc) {
switch (argc - remaining) {
case 2: old_filename = argv[remaining++];
new_filename = argv[remaining++]; break;
@ -695,7 +694,7 @@ int main(int argc, char *argv[])
}
} else {
failure:
argp_help(&codiff__argp, stderr, ARGP_HELP_SEE, "codiff");
argp_help(&codiff__argp, stderr, ARGP_HELP_SEE, argv[0]);
return EXIT_FAILURE;
}
@ -716,13 +715,12 @@ failure:
return EXIT_FAILURE;
}
dwfl_argv[0] = argv[0];
dwfl_argv[2] = NULL;
filenames[1] = NULL;
/* If old_file is a character device, leave its cus empty */
if (!S_ISCHR(st.st_mode)) {
dwfl_argv[1] = old_filename;
err = cus__loadfl(old_cus, NULL, 2, dwfl_argv);
filenames[0] = old_filename;
err = cus__loadfl(old_cus, filenames);
if (err != 0) {
cus__print_error_msg("codiff", old_cus, old_filename, err);
return EXIT_FAILURE;
@ -736,8 +734,8 @@ failure:
/* If old_file is a character device, leave its cus empty */
if (!S_ISCHR(st.st_mode)) {
dwfl_argv[1] = new_filename;
err = cus__loadfl(new_cus, NULL, 2, dwfl_argv);
filenames[0] = new_filename;
err = cus__loadfl(new_cus, filenames);
if (err != 0) {
cus__print_error_msg("codiff", new_cus, new_filename, err);
return EXIT_FAILURE;

View File

@ -14,7 +14,6 @@
#include <string.h>
#include <limits.h>
#include <libgen.h>
#include <argp.h>
#include <zlib.h>
#include <gelf.h>
@ -788,18 +787,13 @@ static void open_files(struct ctf_state *sp, const char *in_filename)
}
}
int ctf__load(struct cus *self, struct argp *argp, int argc, char *argv[],
bool parsed)
int ctf__load(struct cus *self, char *filenames[])
{
struct ctf_state state;
memset(&state, 0, sizeof(state));
if (argc > 2 && !parsed &&
argp_parse(argp, argc - 1, argv, 0, NULL, NULL))
return -1;
open_files(&state, argv[argc - 1]);
open_files(&state, filenames[0]);
if (elf_version(EV_CURRENT) == EV_NONE) {
fprintf(stderr, "Cannot set libelf version.\n");

View File

@ -8,12 +8,8 @@
published by the Free Software Foundation.
*/
#include <stdbool.h>
struct cus;
struct argp;
int ctf__load(struct cus *self, struct argp *argp, int argc, char *argv[],
bool parsed);
int ctf__load(struct cus *self, char *filenames[]);
#endif /* _CTF_LOADER_H_ */

View File

@ -899,9 +899,8 @@ int main(int argc, char *argv[])
return EXIT_FAILURE;
}
argp_parse(&ctracer__argp, argc, argv, 0, &remaining, NULL);
if (remaining < argc) {
if (argp_parse(&ctracer__argp, argc, argv, 0, &remaining, NULL) ||
remaining < argc) {
switch (argc - remaining) {
case 1: goto failure;
case 2: filename = argv[remaining++];
@ -910,7 +909,7 @@ int main(int argc, char *argv[])
}
} else {
failure:
argp_help(&ctracer__argp, stderr, ARGP_HELP_SEE, "ctracer");
argp_help(&ctracer__argp, stderr, ARGP_HELP_SEE, argv[0]);
return EXIT_FAILURE;
}

View File

@ -39,7 +39,7 @@ static void cus__dump_class_tag_names(struct cus *self)
cus__for_each_cu(self, cu__dump_class_tag_names, NULL, NULL);
}
int main(int argc, char *argv[])
int main(int argc __unused, char *argv[])
{
int err;
struct cus *cus = cus__new();
@ -49,7 +49,7 @@ int main(int argc, char *argv[])
return EXIT_FAILURE;
}
err = cus__loadfl(cus, NULL, argc, argv);
err = cus__loadfl(cus, argv + 1);
if (err != 0)
return EXIT_FAILURE;

View File

@ -9,7 +9,6 @@
#include <assert.h>
#include <dirent.h>
#include <dwarf.h>
#include <argp.h>
#include <elfutils/libdwfl.h>
#include <errno.h>
#include <fcntl.h>
@ -1132,26 +1131,25 @@ out:
return err;
}
int dwarf__load(struct cus *self, struct argp *argp, int argc, char *argv[],
bool parsed __unused)
int dwarf__load(struct cus *self, char *filenames[], bool parsed __unused)
{
int err = 0, remaining = 1;
int err = 0, i = 0;
elf_version(EV_CURRENT);
if (argp != NULL)
argp_parse(argp, argc, argv, 0, &remaining, NULL);
do {
int fd = open(argv[remaining], O_RDONLY);
while (filenames[i] != NULL) {
int fd = open(filenames[i], O_RDONLY);
if (fd == -1) {
fprintf(stderr, "%s: couldn't open %s\n", __func__,
argv[remaining]);
filenames[i]);
++i;
continue;
}
cus__process_file(self, fd, argv[remaining]);
cus__process_file(self, fd, filenames[i]);
close(fd);
} while (++remaining < argc);
++i;
}
return err;
}

View File

@ -9,10 +9,8 @@
*/
struct cus;
struct argp;
int dwarf__load_filename(struct cus *self, const char *filename);
int dwarf__load(struct cus *self, struct argp *argp, int argc, char *argv[],
bool parsed);
int dwarf__load(struct cus *self, char *filenames[]);
#endif /* _DWARF_LOADER_H_ */

View File

@ -12,7 +12,6 @@
#include <assert.h>
#include <dirent.h>
#include <dwarf.h>
#include <argp.h>
#include <errno.h>
#include <fcntl.h>
#include <fnmatch.h>
@ -2568,9 +2567,9 @@ int cus__load(struct cus *self, const char *filename)
return err;
}
int cus__loadfl(struct cus *self, struct argp *argp, int argc, char *argv[])
int cus__loadfl(struct cus *self, char *filenames[])
{
int err = dwarf__load(self, argp, argc, argv, false);
int err = dwarf__load(self, filenames);
/*
* If dwarf__load fails, try ctf__load. Eventually we should just
* register all the shared objects at some directory and ask them
@ -2579,12 +2578,9 @@ int cus__loadfl(struct cus *self, struct argp *argp, int argc, char *argv[])
* support.
* FIXME: for now we just check if no DWARF info was found
* by looking at the list of CUs found:
*
* XXX We have to avoid calling argp_parse twice, so tell the
* loaders if we already processed it.
*/
if (list_empty(&self->cus))
err = ctf__load(self, argp, argc, argv, true);
err = ctf__load(self, filenames);
return err;
}

View File

@ -21,8 +21,6 @@
extern struct strings *strings;
struct argp;
struct cus {
struct list_head cus;
};
@ -539,8 +537,7 @@ extern size_t lexblock__fprintf(const struct lexblock *self,
const struct cu *cu, struct function *function,
uint16_t indent, FILE *fp);
extern int cus__loadfl(struct cus *self, struct argp *argp,
int argc, char *argv[]);
extern int cus__loadfl(struct cus *self, char *filenames[]);
extern int cus__load(struct cus *self, const char *filename);
extern int cus__load_dir(struct cus *self, const char *dirname,
const char *filename_mask, const int recursive);

View File

@ -1044,7 +1044,7 @@ static struct argp pahole__argp = {
int main(int argc, char *argv[])
{
int err;
int err, remaining;
struct cus *cus = cus__new();
if (dwarves__init(cacheline_size) || cus == NULL) {
@ -1052,7 +1052,13 @@ int main(int argc, char *argv[])
return EXIT_FAILURE;
}
err = cus__loadfl(cus, &pahole__argp, argc, argv);
if (argp_parse(&pahole__argp, argc, argv, 0, &remaining, NULL) ||
remaining == argc) {
argp_help(&pahole__argp, stderr, ARGP_HELP_SEE, argv[0]);
return EXIT_FAILURE;
}
err = cus__loadfl(cus, argv + remaining);
if (err != 0)
return EXIT_FAILURE;

View File

@ -101,7 +101,7 @@ static struct argp pdwtags__argp = {
int main(int argc, char *argv[])
{
int err;
int err, remaining;
struct cus *cus = cus__new();
if (dwarves__init(0) || cus == NULL) {
@ -109,7 +109,13 @@ int main(int argc, char *argv[])
return EXIT_FAILURE;
}
err = cus__loadfl(cus, &pdwtags__argp, argc, argv);
if (argp_parse(&pdwtags__argp, argc, argv, 0, &remaining, NULL) ||
remaining == argc) {
argp_help(&pdwtags__argp, stderr, ARGP_HELP_SEE, argv[0]);
return EXIT_FAILURE;
}
err = cus__loadfl(cus, argv + remaining);
if (err != 0)
return EXIT_FAILURE;

View File

@ -491,7 +491,7 @@ static struct argp pfunct__argp = {
int main(int argc, char *argv[])
{
int err;
int err, remaining;
struct cus *cus = cus__new();
if (dwarves__init(0) || cus == NULL) {
@ -499,7 +499,13 @@ int main(int argc, char *argv[])
return EXIT_FAILURE;
}
err = cus__loadfl(cus, &pfunct__argp, argc, argv);
if (argp_parse(&pfunct__argp, argc, argv, 0, &remaining, NULL) ||
remaining == argc) {
argp_help(&pfunct__argp, stderr, ARGP_HELP_SEE, argv[0]);
return EXIT_FAILURE;
}
err = cus__loadfl(cus, argv + remaining);
if (err != 0)
return EXIT_FAILURE;

View File

@ -313,7 +313,7 @@ static struct argp pglobal__argp = {
int main(int argc, char *argv[])
{
int err;
int err, remaining;
struct cus *cus = cus__new();
if (dwarves__init(0) || cus == NULL) {
@ -321,7 +321,13 @@ int main(int argc, char *argv[])
return EXIT_FAILURE;
}
err = cus__loadfl(cus, &pglobal__argp, argc, argv);
if (argp_parse(&pglobal__argp, argc, argv, 0, &remaining, NULL) ||
remaining == argc) {
argp_help(&pglobal__argp, stderr, ARGP_HELP_SEE, argv[0]);
return EXIT_FAILURE;
}
err = cus__loadfl(cus, argv + remaining);
if (err != 0)
return EXIT_FAILURE;

View File

@ -157,7 +157,7 @@ int main(int argc, char *argv[])
return EXIT_FAILURE;
}
err = cus__loadfl(cus, NULL, argc, argv);
err = cus__loadfl(cus, argv + 1);
if (err != 0)
return EXIT_FAILURE;

View File

@ -144,7 +144,7 @@ static struct argp argp = {
int main(int argc, char *argv[])
{
int err;
int err, remaining;
struct cus *cus = cus__new();
if (cus == NULL) {
@ -152,7 +152,12 @@ int main(int argc, char *argv[])
return EXIT_FAILURE;
}
err = cus__loadfl(cus, &argp, argc, argv);
if (argp_parse(&argp, argc, argv, 0, &remaining, NULL) ||
remaining == argc) {
argp_help(&argp, stderr, ARGP_HELP_SEE, argv[0]);
return EXIT_FAILURE;
}
err = cus__loadfl(cus, argv + remaining);
if (err != 0)
return EXIT_FAILURE;