Skip to content

Commit

Permalink
13363 ctfconvert could support more granular ignore for missing debug…
Browse files Browse the repository at this point in the history
… data

Reviewed by: Robert Mustacchi <rm@fingolfin.org>
Approved by: Rich Lowe <richlowe@richlowe.net>
  • Loading branch information
citrus-it committed Dec 17, 2020
1 parent 3dd4cd5 commit 88a0881
Show file tree
Hide file tree
Showing 14 changed files with 207 additions and 373 deletions.
43 changes: 41 additions & 2 deletions usr/src/cmd/ctfconvert/ctfconvert.c
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ ctfconvert_usage(const char *fmt, ...)

(void) fprintf(stderr, "Usage: %s [-fikms] [-j nthrs] [-l label | "
"-L labelenv] [-b batchsize]\n"
" [-o outfile] input\n"
" [-o outfile] [-M ignorefile] input\n"
"\n"
"\t-b batch process this many dies at a time (default %d)\n"
"\t-f always attempt to convert files\n"
Expand All @@ -92,6 +92,7 @@ ctfconvert_usage(const char *fmt, ...)
"\t-l set output container's label to specified value\n"
"\t-L set output container's label to value from environment\n"
"\t-m allow input to have missing debug info\n"
"\t-M allow files listed in ignorefile to have missing debug\n"
"\t-o copy input to outfile and add CTF\n"
"\t-s allow truncation of data that cannot be fully converted\n",
ctfconvert_progname,
Expand Down Expand Up @@ -250,6 +251,7 @@ main(int argc, char *argv[])
const char *outfile = NULL;
const char *label = NULL;
const char *infile = NULL;
const char *ignorefile = NULL;
char *tmpfile;
ctf_file_t *ofp;
char buf[4096] = "";
Expand All @@ -259,7 +261,7 @@ main(int argc, char *argv[])

ctfconvert_progname = basename(argv[0]);

while ((c = getopt(argc, argv, ":b:fij:kl:L:mo:sX")) != -1) {
while ((c = getopt(argc, argv, ":b:fij:kl:L:mM:o:sX")) != -1) {
switch (c) {
case 'b': {
long argno;
Expand Down Expand Up @@ -303,6 +305,9 @@ main(int argc, char *argv[])
case 'm':
flags |= CTF_ALLOW_MISSING_DEBUG;
break;
case 'M':
ignorefile = optarg;
break;
case 'o':
outfile = optarg;
break;
Expand Down Expand Up @@ -370,6 +375,40 @@ main(int argc, char *argv[])
ctfconvert_fatal("Could not set warning callback: %s\n",
strerror(err));

if (ignorefile != NULL) {
char *buf = NULL;
ssize_t cnt;
size_t len = 0;
FILE *fp;

if ((fp = fopen(ignorefile, "r")) == NULL) {
ctfconvert_fatal("Could not open ignorefile '%s': %s\n",
ignorefile, strerror(errno));
}

while ((cnt = getline(&buf, &len, fp)) != -1) {
char *p = buf;

if (cnt == 0 || *p == '#')
continue;

(void) strsep(&p, "\n");
if ((err = ctf_convert_add_ignore(cch, buf)) != 0) {
ctfconvert_fatal(
"Failed to add '%s' to ignore list: %s\n",
buf, strerror(err));
}
}
free(buf);
if (cnt == -1 && ferror(fp) != 0) {
ctfconvert_fatal(
"Error reading from ignorefile '%s': %s\n",
ignorefile, strerror(errno));
}

(void) fclose(fp);
}

ofp = ctf_fdconvert(cch, ifd, &err, buf, sizeof (buf));

ctf_convert_fini(cch);
Expand Down
1 change: 1 addition & 0 deletions usr/src/common/ctf/ctf_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,7 @@ extern void *ctf_alloc(size_t);
extern void ctf_free(void *, size_t);

extern char *ctf_strdup(const char *);
extern void ctf_strfree(char *);
extern const char *ctf_strerror(int);
extern void ctf_dprintf(const char *, ...);

Expand Down
11 changes: 11 additions & 0 deletions usr/src/common/ctf/ctf_util.c
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,17 @@ ctf_strdup(const char *s1)
return (s2);
}

/*
* Free a string which was allocated via ctf_alloc()
*/
void
ctf_strfree(char *s)
{
if (s == NULL)
return;
ctf_free(s, strlen(s) + 1);
}

/*
* Store the specified error code into errp if it is non-NULL, and then
* return NULL for the benefit of the caller.
Expand Down
49 changes: 40 additions & 9 deletions usr/src/lib/libctf/common/ctf_convert.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#include <libctf_impl.h>
#include <assert.h>
#include <gelf.h>
#include <sys/list.h>

static ctf_convert_f ctf_converters[] = {
ctf_dwarf_convert
Expand Down Expand Up @@ -209,17 +210,29 @@ ctf_convert_init(int *errp)
cch->cch_batchsize = CTF_CONVERT_DEFAULT_BATCHSIZE;
cch->cch_warncb = NULL;
cch->cch_warncb_arg = NULL;
list_create(&cch->cch_nodebug, sizeof (ctf_convert_filelist_t),
offsetof(ctf_convert_filelist_t, ccf_node));

return (cch);
}

static void
ctf_convert_fini_filelist(ctf_convert_filelist_t *ccf)
{
ctf_strfree(ccf->ccf_basename);
ctf_free(ccf, sizeof (ctf_convert_filelist_t));
}

void
ctf_convert_fini(ctf_convert_t *cch)
{
if (cch->cch_label != NULL) {
size_t len = strlen(cch->cch_label) + 1;
ctf_free(cch->cch_label, len);
}
ctf_convert_filelist_t *ccf;

ctf_strfree(cch->cch_label);
while ((ccf = list_remove_head(&cch->cch_nodebug)) != NULL)
ctf_convert_fini_filelist(ccf);
list_destroy(&cch->cch_nodebug);

ctf_free(cch, sizeof (struct ctf_convert_handle));
}

Expand Down Expand Up @@ -262,11 +275,7 @@ ctf_convert_set_label(ctf_convert_t *cch, const char *label)
if (dup == NULL)
return (ENOMEM);

if (cch->cch_label != NULL) {
size_t len = strlen(cch->cch_label) + 1;
ctf_free(cch->cch_label, len);
}

ctf_strfree(cch->cch_label);
cch->cch_label = dup;
return (0);
}
Expand All @@ -279,6 +288,28 @@ ctf_convert_set_warncb(ctf_convert_t *cch, ctf_convert_warn_f cb, void *arg)
return (0);
}

int
ctf_convert_add_ignore(ctf_convert_t *cch, const char *basename)
{
ctf_convert_filelist_t *ccf;

if (strchr(basename, '/') != NULL)
return (EINVAL);

ccf = ctf_alloc(sizeof (ctf_convert_filelist_t));
if (ccf == NULL)
return (ENOMEM);

ccf->ccf_basename = ctf_strdup(basename);
if (ccf->ccf_basename == NULL) {
ctf_free(ccf, sizeof (ctf_convert_filelist_t));
return (ENOMEM);
}
list_insert_tail(&cch->cch_nodebug, ccf);

return (0);
}

ctf_file_t *
ctf_fdconvert(ctf_convert_t *cch, int fd, int *errp,
char *errbuf, size_t errlen)
Expand Down
Loading

0 comments on commit 88a0881

Please sign in to comment.