Print this page
12310 Add demangle(1) command


   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 2018 Jason King
  14  * Copyright 2019, Joyent, Inc.
  15  */
  16 
  17 #include <stdlib.h>
  18 #include <stdio.h>
  19 #include <string.h>
  20 #include <errno.h>
  21 #include <pthread.h>
  22 #include <sys/ctype.h>
  23 #include <sys/debug.h>

  24 #include <stdarg.h>
  25 #include "demangle-sys.h"
  26 #include "demangle_int.h"
  27 
  28 #define DEMANGLE_DEBUG  "DEMANGLE_DEBUG"
  29 
  30 static pthread_once_t debug_once = PTHREAD_ONCE_INIT;
  31 volatile boolean_t demangle_debug;
  32 FILE *debugf = stderr;
  33 









  34 static const char *
  35 langstr(sysdem_lang_t lang)
  36 {
  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");











  46         }



  47 }
  48 
  49 static sysdem_lang_t
  50 detect_lang(const char *str, size_t n)
  51 {
  52         const char *p = str;
  53         size_t len;
  54 
  55         if (n < 3 || str[0] != '_')
  56                 return (SYSDEM_LANG_AUTO);
  57 
  58         /*
  59          * Check for ^_Z or ^__Z
  60          */
  61         p = str + 1;
  62         if (*p == '_') {
  63                 p++;
  64         }
  65 
  66         if (*p != 'Z')




   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 2018 Jason King
  14  * Copyright 2019, Joyent, Inc.
  15  */
  16 
  17 #include <stdlib.h>
  18 #include <stdio.h>
  19 #include <string.h>
  20 #include <errno.h>
  21 #include <pthread.h>
  22 #include <sys/ctype.h>
  23 #include <sys/debug.h>
  24 #include <sys/sysmacros.h>
  25 #include <stdarg.h>
  26 #include "demangle-sys.h"
  27 #include "demangle_int.h"
  28 
  29 #define DEMANGLE_DEBUG  "DEMANGLE_DEBUG"
  30 
  31 static pthread_once_t debug_once = PTHREAD_ONCE_INIT;
  32 volatile boolean_t demangle_debug;
  33 FILE *debugf = stderr;
  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 
  44 static const char *
  45 langstr(sysdem_lang_t lang)
  46 {
  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);
  52         }


  53         return ("invalid");
  54 }
  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 
  71 static sysdem_lang_t
  72 detect_lang(const char *str, size_t n)
  73 {
  74         const char *p = str;
  75         size_t len;
  76 
  77         if (n < 3 || str[0] != '_')
  78                 return (SYSDEM_LANG_AUTO);
  79 
  80         /*
  81          * Check for ^_Z or ^__Z
  82          */
  83         p = str + 1;
  84         if (*p == '_') {
  85                 p++;
  86         }
  87 
  88         if (*p != 'Z')