Print this page
11657 Remove old ctf tools
   1 /*
   2  * This file and its contents are supplied under the terms of the
   3  * Common Development and Distribution License ("CDDL"), version 1.0.
   4  * You may only use this file in accordance with the terms of version
   5  * 1.0 of the CDDL.
   6  *
   7  * A full copy of the text of the CDDL should have accompanied this
   8  * source.  A copy of the CDDL is also available via the Internet at
   9  * http://www.illumos.org/license/CDDL.
  10  */
  11 
  12 /*
  13  * Copyright (c) 2019, Joyent, Inc.
  14  */
  15 
  16 /*
  17  * Create CTF from extant debugging information
  18  */
  19 
  20 #include <stdio.h>
  21 #include <unistd.h>
  22 #include <stdlib.h>
  23 #include <stdarg.h>
  24 #include <sys/types.h>
  25 #include <sys/stat.h>
  26 #include <fcntl.h>
  27 #include <errno.h>
  28 #include <libelf.h>
  29 #include <libctf.h>
  30 #include <string.h>
  31 #include <libgen.h>
  32 #include <limits.h>
  33 #include <strings.h>
  34 #include <sys/debug.h>
  35 
  36 #define CTFCONVERT_OK           0
  37 #define CTFCONVERT_FATAL        1
  38 #define CTFCONVERT_USAGE        2
  39 
  40 #define CTFCONVERT_DEFAULT_NTHREADS     4
  41 
  42 #define CTFCONVERT_ALTEXEC      "CTFCONVERT_ALTEXEC"
  43 
  44 static char *ctfconvert_progname;
  45 
  46 static void
  47 ctfconvert_fatal(const char *fmt, ...)
  48 {
  49         va_list ap;
  50 
  51         (void) fprintf(stderr, "%s: ", ctfconvert_progname);
  52         va_start(ap, fmt);
  53         (void) vfprintf(stderr, fmt, ap);
  54         va_end(ap);
  55 
  56         exit(CTFCONVERT_FATAL);
  57 }
  58 
  59 
  60 static void
  61 ctfconvert_usage(const char *fmt, ...)
  62 {
  63         if (fmt != NULL) {


 205         }
 206 
 207         if (ctf_update(fp) == CTF_ERR) {
 208                 ctfconvert_fatal("failed to update output file: %s\n",
 209                     ctf_errmsg(ctf_errno(fp)));
 210         }
 211 
 212         if (ctf_add_member(fp, cpuid, "cpu_m", mcpu, sz * NBBY) == CTF_ERR) {
 213                 ctfconvert_fatal("failed to add the m_cpu member: %s\n",
 214                     ctf_errmsg(ctf_errno(fp)));
 215         }
 216 
 217         if (ctf_update(fp) == CTF_ERR) {
 218                 ctfconvert_fatal("failed to update output file: %s\n",
 219                     ctf_errmsg(ctf_errno(fp)));
 220         }
 221 
 222         VERIFY(ctf_type_size(fp, cpuid) == sz);
 223 }
 224 
 225 static void
 226 ctfconvert_altexec(char **argv)
 227 {
 228         const char *alt;
 229         char *altexec;
 230 
 231         alt = getenv(CTFCONVERT_ALTEXEC);
 232         if (alt == NULL || *alt == '\0')
 233                 return;
 234 
 235         altexec = strdup(alt);
 236         if (altexec == NULL)
 237                 ctfconvert_fatal("failed to allocate memory for altexec\n");
 238         if (unsetenv(CTFCONVERT_ALTEXEC) != 0)
 239                 ctfconvert_fatal("failed to unset %s from environment: %s\n",
 240                     CTFCONVERT_ALTEXEC, strerror(errno));
 241 
 242         (void) execv(altexec, argv);
 243         ctfconvert_fatal("failed to execute alternate program %s: %s",
 244             altexec, strerror(errno));
 245 }
 246 
 247 int
 248 main(int argc, char *argv[])
 249 {
 250         int c, ifd, err;
 251         boolean_t keep = B_FALSE;
 252         uint_t flags = 0;
 253         uint_t nthreads = CTFCONVERT_DEFAULT_NTHREADS;
 254         const char *outfile = NULL;
 255         const char *label = NULL;
 256         const char *infile = NULL;
 257         char *tmpfile;
 258         ctf_file_t *ofp;
 259         long argj;
 260         char *eptr;
 261         char buf[4096];
 262         boolean_t optx = B_FALSE;
 263         boolean_t ignore_non_c = B_FALSE;
 264 
 265         ctfconvert_progname = basename(argv[0]);
 266 
 267         ctfconvert_altexec(argv);
 268 
 269         while ((c = getopt(argc, argv, ":ij:kl:L:mo:X")) != -1) {
 270                 switch (c) {
 271                 case 'i':
 272                         ignore_non_c = B_TRUE;
 273                         break;
 274                 case 'j':
 275                         errno = 0;
 276                         argj = strtol(optarg, &eptr, 10);
 277                         if (errno != 0 || argj == LONG_MAX ||
 278                             argj > 1024 || *eptr != '\0') {
 279                                 ctfconvert_fatal("invalid argument for -j: "
 280                                     "%s\n", optarg);
 281                         }
 282                         nthreads = (uint_t)argj;
 283                         break;
 284                 case 'k':
 285                         keep = B_TRUE;
 286                         break;
 287                 case 'l':
 288                         label = optarg;


   1 /*
   2  * This file and its contents are supplied under the terms of the
   3  * Common Development and Distribution License ("CDDL"), version 1.0.
   4  * You may only use this file in accordance with the terms of version
   5  * 1.0 of the CDDL.
   6  *
   7  * A full copy of the text of the CDDL should have accompanied this
   8  * source.  A copy of the CDDL is also available via the Internet at
   9  * http://www.illumos.org/license/CDDL.
  10  */
  11 
  12 /*
  13  * Copyright 2019 Joyent, Inc.
  14  */
  15 
  16 /*
  17  * Create CTF from extant debugging information
  18  */
  19 
  20 #include <stdio.h>
  21 #include <unistd.h>
  22 #include <stdlib.h>
  23 #include <stdarg.h>
  24 #include <sys/types.h>
  25 #include <sys/stat.h>
  26 #include <fcntl.h>
  27 #include <errno.h>
  28 #include <libelf.h>
  29 #include <libctf.h>
  30 #include <string.h>
  31 #include <libgen.h>
  32 #include <limits.h>
  33 #include <strings.h>
  34 #include <sys/debug.h>
  35 
  36 #define CTFCONVERT_OK           0
  37 #define CTFCONVERT_FATAL        1
  38 #define CTFCONVERT_USAGE        2
  39 
  40 #define CTFCONVERT_DEFAULT_NTHREADS     4
  41 


  42 static char *ctfconvert_progname;
  43 
  44 static void
  45 ctfconvert_fatal(const char *fmt, ...)
  46 {
  47         va_list ap;
  48 
  49         (void) fprintf(stderr, "%s: ", ctfconvert_progname);
  50         va_start(ap, fmt);
  51         (void) vfprintf(stderr, fmt, ap);
  52         va_end(ap);
  53 
  54         exit(CTFCONVERT_FATAL);
  55 }
  56 
  57 
  58 static void
  59 ctfconvert_usage(const char *fmt, ...)
  60 {
  61         if (fmt != NULL) {


 203         }
 204 
 205         if (ctf_update(fp) == CTF_ERR) {
 206                 ctfconvert_fatal("failed to update output file: %s\n",
 207                     ctf_errmsg(ctf_errno(fp)));
 208         }
 209 
 210         if (ctf_add_member(fp, cpuid, "cpu_m", mcpu, sz * NBBY) == CTF_ERR) {
 211                 ctfconvert_fatal("failed to add the m_cpu member: %s\n",
 212                     ctf_errmsg(ctf_errno(fp)));
 213         }
 214 
 215         if (ctf_update(fp) == CTF_ERR) {
 216                 ctfconvert_fatal("failed to update output file: %s\n",
 217                     ctf_errmsg(ctf_errno(fp)));
 218         }
 219 
 220         VERIFY(ctf_type_size(fp, cpuid) == sz);
 221 }
 222 






















 223 int
 224 main(int argc, char *argv[])
 225 {
 226         int c, ifd, err;
 227         boolean_t keep = B_FALSE;
 228         uint_t flags = 0;
 229         uint_t nthreads = CTFCONVERT_DEFAULT_NTHREADS;
 230         const char *outfile = NULL;
 231         const char *label = NULL;
 232         const char *infile = NULL;
 233         char *tmpfile;
 234         ctf_file_t *ofp;
 235         long argj;
 236         char *eptr;
 237         char buf[4096];
 238         boolean_t optx = B_FALSE;
 239         boolean_t ignore_non_c = B_FALSE;
 240 
 241         ctfconvert_progname = basename(argv[0]);
 242 


 243         while ((c = getopt(argc, argv, ":ij:kl:L:mo:X")) != -1) {
 244                 switch (c) {
 245                 case 'i':
 246                         ignore_non_c = B_TRUE;
 247                         break;
 248                 case 'j':
 249                         errno = 0;
 250                         argj = strtol(optarg, &eptr, 10);
 251                         if (errno != 0 || argj == LONG_MAX ||
 252                             argj > 1024 || *eptr != '\0') {
 253                                 ctfconvert_fatal("invalid argument for -j: "
 254                                     "%s\n", optarg);
 255                         }
 256                         nthreads = (uint_t)argj;
 257                         break;
 258                 case 'k':
 259                         keep = B_TRUE;
 260                         break;
 261                 case 'l':
 262                         label = optarg;