Print this page
12310 Add demangle(1) command

Split Close
Expand all
Collapse all
          --- old/usr/src/lib/libdemangle/common/demangle.c
          +++ new/usr/src/lib/libdemangle/common/demangle.c
↓ open down ↓ 13 lines elided ↑ open up ↑
  14   14   * Copyright 2019, Joyent, Inc.
  15   15   */
  16   16  
  17   17  #include <stdlib.h>
  18   18  #include <stdio.h>
  19   19  #include <string.h>
  20   20  #include <errno.h>
  21   21  #include <pthread.h>
  22   22  #include <sys/ctype.h>
  23   23  #include <sys/debug.h>
       24 +#include <sys/sysmacros.h>
  24   25  #include <stdarg.h>
  25   26  #include "demangle-sys.h"
  26   27  #include "demangle_int.h"
  27   28  
  28   29  #define DEMANGLE_DEBUG  "DEMANGLE_DEBUG"
  29   30  
  30   31  static pthread_once_t debug_once = PTHREAD_ONCE_INIT;
  31   32  volatile boolean_t demangle_debug;
  32   33  FILE *debugf = stderr;
  33   34  
       35 +static struct {
       36 +        const char      *str;
       37 +        sysdem_lang_t   lang;
       38 +} lang_tbl[] = {
       39 +        { "auto", SYSDEM_LANG_AUTO },
       40 +        { "c++", SYSDEM_LANG_CPP },
       41 +        { "rust", SYSDEM_LANG_RUST },
       42 +};
       43 +
  34   44  static const char *
  35   45  langstr(sysdem_lang_t lang)
  36   46  {
  37      -        switch (lang) {
  38      -        case SYSDEM_LANG_AUTO:
  39      -                return ("auto");
  40      -        case SYSDEM_LANG_CPP:
  41      -                return ("c++");
  42      -        case SYSDEM_LANG_RUST:
  43      -                return ("rust");
  44      -        default:
  45      -                return ("invalid");
       47 +        size_t i;
       48 +
       49 +        for (i = 0; i < ARRAY_SIZE(lang_tbl); i++) {
       50 +                if (lang == lang_tbl[i].lang)
       51 +                        return (lang_tbl[i].str);
  46   52          }
       53 +        return ("invalid");
  47   54  }
  48   55  
       56 +boolean_t
       57 +sysdem_parse_lang(const char *str, sysdem_lang_t *langp)
       58 +{
       59 +        size_t i;
       60 +
       61 +        for (i = 0; i < ARRAY_SIZE(lang_tbl); i++) {
       62 +                if (strcmp(str, lang_tbl[i].str) == 0) {
       63 +                        *langp = lang_tbl[i].lang;
       64 +                        return (B_TRUE);
       65 +                }
       66 +        }
       67 +
       68 +        return (B_FALSE);
       69 +}
       70 +
  49   71  static sysdem_lang_t
  50   72  detect_lang(const char *str, size_t n)
  51   73  {
  52   74          const char *p = str;
  53   75          size_t len;
  54   76  
  55   77          if (n < 3 || str[0] != '_')
  56   78                  return (SYSDEM_LANG_AUTO);
  57   79  
  58   80          /*
↓ open down ↓ 115 lines elided ↑ open up ↑
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX