[ALL]: Emit better diagnostic messages
[acme@mica pahole]$ pahole lala pahole: Permission denied [acme@mica pahole]$ pahole foo pahole: No such file or directory [acme@mica pahole]$ pahole ctracer.c pahole: couldn't load DWARF info from ctracer.c [acme@mica pahole]$ Thanks to Matthew Wilcox for noticing how lame it was :-) Signed-off-by: Arnaldo Carvalho de Melo <acme@ghostprotocols.net>
This commit is contained in:
parent
7bd8fb3c43
commit
c87d8d831a
14
codiff.c
14
codiff.c
|
@ -593,7 +593,7 @@ static void print_total_function_diff(const char *filename)
|
|||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
int option, option_index;
|
||||
int option, option_index, err;
|
||||
struct cus *old_cus, *new_cus;
|
||||
const char *old_filename, *new_filename;
|
||||
|
||||
|
@ -633,15 +633,15 @@ int main(int argc, char *argv[])
|
|||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
if (cus__load(old_cus, old_filename) != 0) {
|
||||
fprintf(stderr, "codiff: couldn't load DWARF info from %s\n",
|
||||
old_filename);
|
||||
err = cus__load(old_cus, old_filename);
|
||||
if (err != 0) {
|
||||
cus__print_error_msg("codiff", old_filename, err);
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
if (cus__load(new_cus, new_filename) != 0) {
|
||||
fprintf(stderr, "codiff: couldn't load DWARF info from %s\n",
|
||||
new_filename);
|
||||
err = cus__load(new_cus, new_filename);
|
||||
if (err != 0) {
|
||||
cus__print_error_msg("codiff", new_filename, err);
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
|
|
15
ctracer.c
15
ctracer.c
|
@ -614,7 +614,7 @@ static void usage(void)
|
|||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
int option, option_index, recursive = 0;
|
||||
int option, option_index, err, recursive = 0;
|
||||
const char *filename = NULL, *dirname = NULL, *glob = NULL,
|
||||
*kprobes_filename = NULL;
|
||||
char *class_name = NULL;
|
||||
|
@ -680,7 +680,8 @@ out_enomem:
|
|||
kprobes_cus = cus__new(&cus__definitions, &cus__fwd_decls);
|
||||
if (kprobes_cus == NULL)
|
||||
goto out_enomem;
|
||||
if (cus__load(kprobes_cus, kprobes_filename) != 0) {
|
||||
err = cus__load(kprobes_cus, kprobes_filename);
|
||||
if (err != 0) {
|
||||
filename = kprobes_filename;
|
||||
goto out_dwarf_err;
|
||||
}
|
||||
|
@ -709,11 +710,13 @@ out_enomem:
|
|||
/*
|
||||
* If a filename was specified, for instance "vmlinux", load it too.
|
||||
*/
|
||||
if (filename != NULL && cus__load(methods_cus, filename) != 0) {
|
||||
if (filename != NULL) {
|
||||
err = cus__load(methods_cus, filename);
|
||||
if (err != 0) {
|
||||
out_dwarf_err:
|
||||
fprintf(stderr, "ctracer: couldn't load DWARF info from %s\n",
|
||||
filename);
|
||||
return EXIT_FAILURE;
|
||||
cus__print_error_msg("ctracer", filename, err);
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
|
|
|
@ -45,6 +45,7 @@ static void usage(void)
|
|||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
int err;
|
||||
struct cus *cus;
|
||||
char *filename = argv[1];
|
||||
|
||||
|
@ -61,9 +62,9 @@ int main(int argc, char *argv[])
|
|||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
if (cus__load(cus, filename) != 0) {
|
||||
fprintf(stderr, "dtagnames: couldn't load DWARF info from %s\n",
|
||||
filename);
|
||||
err = cus__load(cus, filename);
|
||||
if (err != 0) {
|
||||
cus__print_error_msg("codiff", filename, err);
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
|
|
18
dwarves.c
18
dwarves.c
|
@ -13,6 +13,7 @@
|
|||
#include <assert.h>
|
||||
#include <dirent.h>
|
||||
#include <dwarf.h>
|
||||
#include <errno.h>
|
||||
#include <fcntl.h>
|
||||
#include <fnmatch.h>
|
||||
#include <libelf.h>
|
||||
|
@ -3253,12 +3254,15 @@ int cus__load(struct cus *self, const char *filename)
|
|||
uint8_t addr_size, offset_size;
|
||||
size_t hdr_size;
|
||||
Dwarf *dwarf;
|
||||
int err = -1;
|
||||
int fd = open(filename, O_RDONLY);
|
||||
int err;
|
||||
|
||||
if (fd < 0)
|
||||
if (fd < 0) {
|
||||
err = errno;
|
||||
goto out;
|
||||
}
|
||||
|
||||
err = -EINVAL;
|
||||
dwarf = dwarf_begin(fd, DWARF_C_READ);
|
||||
if (dwarf == NULL)
|
||||
goto out_close;
|
||||
|
@ -3288,6 +3292,16 @@ out:
|
|||
return err;
|
||||
}
|
||||
|
||||
void cus__print_error_msg(const char *progname, const char *filename,
|
||||
const int err)
|
||||
{
|
||||
if (err == -EINVAL)
|
||||
fprintf(stderr, "%s: couldn't load DWARF info from %s\n",
|
||||
progname, filename);
|
||||
else
|
||||
fprintf(stderr, "%s: %s\n", progname, strerror(err));
|
||||
}
|
||||
|
||||
struct cus *cus__new(struct list_head *definitions,
|
||||
struct list_head *fwd_decls)
|
||||
{
|
||||
|
|
|
@ -288,6 +288,8 @@ extern struct cus *cus__new(struct list_head *definitions,
|
|||
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);
|
||||
extern void cus__print_error_msg(const char *progname, const char *filename,
|
||||
const int err);
|
||||
extern struct cu *cus__find_cu_by_name(const struct cus *self,
|
||||
const char *name);
|
||||
extern struct tag *cu__find_base_type_by_name(const struct cu *self,
|
||||
|
|
17
pahole.c
17
pahole.c
|
@ -8,6 +8,7 @@
|
|||
published by the Free Software Foundation.
|
||||
*/
|
||||
|
||||
#include <errno.h>
|
||||
#include <getopt.h>
|
||||
#include <stdio.h>
|
||||
#include <dwarf.h>
|
||||
|
@ -376,7 +377,7 @@ static struct option long_options[] = {
|
|||
static void usage(void)
|
||||
{
|
||||
fprintf(stderr,
|
||||
"usage: pahole [options] <file_name> {<class_name>}\n"
|
||||
"usage: pahole [options] <filename> {<class_name>}\n"
|
||||
" where: \n"
|
||||
" -h, --help show usage info\n"
|
||||
" -B, --bit_holes <nr_holes> show only structs at least "
|
||||
|
@ -411,9 +412,9 @@ static void usage(void)
|
|||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
int option, option_index, reorganize = 0, show_reorg_steps = 0;
|
||||
int option, option_index, err, reorganize = 0, show_reorg_steps = 0;
|
||||
struct cus *cus;
|
||||
char *file_name;
|
||||
char *filename;
|
||||
char *class_name = NULL;
|
||||
size_t cacheline_size = 0;
|
||||
void (*formatter)(const struct structure *s) = class_formatter;
|
||||
|
@ -451,13 +452,13 @@ int main(int argc, char *argv[])
|
|||
|
||||
if (optind < argc) {
|
||||
switch (argc - optind) {
|
||||
case 1: file_name = argv[optind++];
|
||||
case 1: filename = argv[optind++];
|
||||
if (reorganize) {
|
||||
usage();
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
break;
|
||||
case 2: file_name = argv[optind++];
|
||||
case 2: filename = argv[optind++];
|
||||
class_name = argv[optind++]; break;
|
||||
default: usage(); return EXIT_FAILURE;
|
||||
}
|
||||
|
@ -474,9 +475,9 @@ int main(int argc, char *argv[])
|
|||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
if (cus__load(cus, file_name) != 0) {
|
||||
fprintf(stderr, "pahole: couldn't load DWARF info from %s\n",
|
||||
file_name);
|
||||
err = cus__load(cus, filename);
|
||||
if (err != 0) {
|
||||
cus__print_error_msg("pahole", filename, err);
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
|
|
|
@ -56,6 +56,7 @@ static void usage(void)
|
|||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
int err;
|
||||
struct cus *cus;
|
||||
char *filename = argv[1];
|
||||
|
||||
|
@ -72,9 +73,9 @@ int main(int argc, char *argv[])
|
|||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
if (cus__load(cus, filename) != 0) {
|
||||
fprintf(stderr, "pdwtags: couldn't load DWARF info from %s\n",
|
||||
filename);
|
||||
err = cus__load(cus, filename);
|
||||
if (err != 0) {
|
||||
cus__print_error_msg("pdwtags", filename, err);
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
|
|
16
pfunct.c
16
pfunct.c
|
@ -339,7 +339,7 @@ static struct option long_options[] = {
|
|||
static void usage(void)
|
||||
{
|
||||
fprintf(stdout,
|
||||
"usage: pfunct [options] <file_name> {<function_name>}\n"
|
||||
"usage: pfunct [options] <filename> {<function_name>}\n"
|
||||
" where: \n"
|
||||
" -c, --class=<class> functions that have "
|
||||
"<class> pointer "
|
||||
|
@ -369,8 +369,8 @@ static void usage(void)
|
|||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
int option, option_index;
|
||||
const char *file_name;
|
||||
int option, option_index, err;
|
||||
const char *filename;
|
||||
struct cus *cus;
|
||||
char *class_name = NULL;
|
||||
char *function_name = NULL;
|
||||
|
@ -400,8 +400,8 @@ int main(int argc, char *argv[])
|
|||
|
||||
if (optind < argc) {
|
||||
switch (argc - optind) {
|
||||
case 1: file_name = argv[optind++]; break;
|
||||
case 2: file_name = argv[optind++];
|
||||
case 1: filename = argv[optind++]; break;
|
||||
case 2: filename = argv[optind++];
|
||||
function_name = argv[optind++]; break;
|
||||
default: usage(); return EXIT_FAILURE;
|
||||
}
|
||||
|
@ -418,9 +418,9 @@ int main(int argc, char *argv[])
|
|||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
if (cus__load(cus, file_name) != 0) {
|
||||
fprintf(stderr, "pfunct: couldn't load DWARF info from %s\n",
|
||||
file_name);
|
||||
err = cus__load(cus, filename);
|
||||
if (err != 0) {
|
||||
cus__print_error_msg("pfunct", filename, err);
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
|
|
10
pglobal.c
10
pglobal.c
|
@ -273,7 +273,7 @@ static struct option long_options[] = {
|
|||
static void usage(void)
|
||||
{
|
||||
fprintf(stdout,
|
||||
"usage: pglobal [options] <file_name>\n"
|
||||
"usage: pglobal [options] <filename>\n"
|
||||
" where: \n"
|
||||
" -v, --variables show global variables\n"
|
||||
" -f, --functions show global functions\n"
|
||||
|
@ -283,9 +283,9 @@ static void usage(void)
|
|||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
int option, option_index, err;
|
||||
char *filename;
|
||||
struct cus *cus;
|
||||
int option, option_index;
|
||||
int walk_var = 0, walk_fun = 0;
|
||||
|
||||
while ((option = getopt_long(argc, argv, "vfVh",
|
||||
|
@ -317,9 +317,9 @@ int main(int argc, char *argv[])
|
|||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
if (cus__load(cus, filename) != 0) {
|
||||
fprintf(stderr, "pglobal: couldn't load DWARF info from %s\n",
|
||||
filename);
|
||||
err = cus__load(cus, filename);
|
||||
if (err != 0) {
|
||||
cus__print_error_msg("pglobal", filename, err);
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
|
|
14
prefcnt.c
14
prefcnt.c
|
@ -24,7 +24,7 @@ static struct option long_options[] = {
|
|||
static void usage(void)
|
||||
{
|
||||
fprintf(stderr,
|
||||
"usage: prefcnt [options] <file_name>\n"
|
||||
"usage: prefcnt [options] <filename>\n"
|
||||
" where: \n"
|
||||
" -h, --help usage options\n");
|
||||
}
|
||||
|
@ -152,9 +152,9 @@ static int cu_lost_iterator(struct cu *cu, void *cookie)
|
|||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
int option, option_index;
|
||||
int option, option_index, err;
|
||||
struct cus *cus;
|
||||
const char *file_name;
|
||||
const char *filename;
|
||||
|
||||
while ((option = getopt_long(argc, argv, "h",
|
||||
long_options, &option_index)) >= 0)
|
||||
|
@ -165,7 +165,7 @@ int main(int argc, char *argv[])
|
|||
|
||||
if (optind < argc) {
|
||||
switch (argc - optind) {
|
||||
case 1: file_name = argv[optind++]; break;
|
||||
case 1: filename = argv[optind++]; break;
|
||||
default: usage(); return EXIT_FAILURE;
|
||||
}
|
||||
} else {
|
||||
|
@ -181,9 +181,9 @@ int main(int argc, char *argv[])
|
|||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
if (cus__load(cus, file_name) != 0) {
|
||||
fprintf(stderr, "prefcnt: couldn't load DWARF info from %s\n",
|
||||
file_name);
|
||||
err = cus__load(cus, filename);
|
||||
if (err != 0) {
|
||||
cus__print_error_msg("pdwtags", filename, err);
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue