~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/tools/perf/util/demangle-java.c

Version: ~ [ linux-6.12-rc7 ] ~ [ linux-6.11.7 ] ~ [ linux-6.10.14 ] ~ [ linux-6.9.12 ] ~ [ linux-6.8.12 ] ~ [ linux-6.7.12 ] ~ [ linux-6.6.60 ] ~ [ linux-6.5.13 ] ~ [ linux-6.4.16 ] ~ [ linux-6.3.13 ] ~ [ linux-6.2.16 ] ~ [ linux-6.1.116 ] ~ [ linux-6.0.19 ] ~ [ linux-5.19.17 ] ~ [ linux-5.18.19 ] ~ [ linux-5.17.15 ] ~ [ linux-5.16.20 ] ~ [ linux-5.15.171 ] ~ [ linux-5.14.21 ] ~ [ linux-5.13.19 ] ~ [ linux-5.12.19 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.229 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.285 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.323 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.336 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.337 ] ~ [ linux-4.4.302 ] ~ [ linux-3.10.108 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.12 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

Diff markup

Differences between /tools/perf/util/demangle-java.c (Architecture alpha) and /tools/perf/util/demangle-java.c (Architecture sparc)


  1 // SPDX-License-Identifier: GPL-2.0                 1 // SPDX-License-Identifier: GPL-2.0
  2 #include <sys/types.h>                              2 #include <sys/types.h>
  3 #include <stdio.h>                                  3 #include <stdio.h>
  4 #include <stdlib.h>                                 4 #include <stdlib.h>
  5 #include <string.h>                                 5 #include <string.h>
  6 #include "symbol.h"                                 6 #include "symbol.h"
  7                                                     7 
  8 #include "demangle-java.h"                          8 #include "demangle-java.h"
  9                                                     9 
 10 #include <linux/ctype.h>                           10 #include <linux/ctype.h>
 11 #include <linux/kernel.h>                          11 #include <linux/kernel.h>
 12                                                    12 
 13 enum {                                             13 enum {
 14         MODE_PREFIX = 0,                           14         MODE_PREFIX = 0,
 15         MODE_CLASS  = 1,                           15         MODE_CLASS  = 1,
 16         MODE_FUNC   = 2,                           16         MODE_FUNC   = 2,
 17         MODE_TYPE   = 3,                           17         MODE_TYPE   = 3,
 18         MODE_CTYPE  = 4, /* class arg */           18         MODE_CTYPE  = 4, /* class arg */
 19 };                                                 19 };
 20                                                    20 
 21 #define BASE_ENT(c, n)  [c - 'A']=n                21 #define BASE_ENT(c, n)  [c - 'A']=n
 22 static const char *base_types['Z' - 'A' + 1] =     22 static const char *base_types['Z' - 'A' + 1] = {
 23         BASE_ENT('B', "byte" ),                    23         BASE_ENT('B', "byte" ),
 24         BASE_ENT('C', "char" ),                    24         BASE_ENT('C', "char" ),
 25         BASE_ENT('D', "double" ),                  25         BASE_ENT('D', "double" ),
 26         BASE_ENT('F', "float" ),                   26         BASE_ENT('F', "float" ),
 27         BASE_ENT('I', "int" ),                     27         BASE_ENT('I', "int" ),
 28         BASE_ENT('J', "long" ),                    28         BASE_ENT('J', "long" ),
 29         BASE_ENT('S', "short" ),                   29         BASE_ENT('S', "short" ),
 30         BASE_ENT('Z', "boolean" ),                 30         BASE_ENT('Z', "boolean" ),
 31 };                                                 31 };
 32                                                    32 
 33 /*                                                 33 /*
 34  * demangle Java symbol between str and end po     34  * demangle Java symbol between str and end positions and stores
 35  * up to maxlen characters into buf. The parse     35  * up to maxlen characters into buf. The parser starts in mode.
 36  *                                                 36  *
 37  * Use MODE_PREFIX to process entire prototype     37  * Use MODE_PREFIX to process entire prototype till end position
 38  * Use MODE_TYPE to process return type if str     38  * Use MODE_TYPE to process return type if str starts on return type char
 39  *                                                 39  *
 40  *  Return:                                        40  *  Return:
 41  *      success: buf                               41  *      success: buf
 42  *      error  : NULL                              42  *      error  : NULL
 43  */                                                43  */
 44 static char *                                      44 static char *
 45 __demangle_java_sym(const char *str, const cha     45 __demangle_java_sym(const char *str, const char *end, char *buf, int maxlen, int mode)
 46 {                                                  46 {
 47         int rlen = 0;                              47         int rlen = 0;
 48         int array = 0;                             48         int array = 0;
 49         int narg = 0;                              49         int narg = 0;
 50         const char *q;                             50         const char *q;
 51                                                    51 
 52         if (!end)                                  52         if (!end)
 53                 end = str + strlen(str);           53                 end = str + strlen(str);
 54                                                    54 
 55         for (q = str; q != end; q++) {             55         for (q = str; q != end; q++) {
 56                                                    56 
 57                 if (rlen == (maxlen - 1))          57                 if (rlen == (maxlen - 1))
 58                         break;                     58                         break;
 59                                                    59 
 60                 switch (*q) {                      60                 switch (*q) {
 61                 case 'L':                          61                 case 'L':
 62                         if (mode == MODE_PREFI     62                         if (mode == MODE_PREFIX || mode == MODE_TYPE) {
 63                                 if (mode == MO     63                                 if (mode == MODE_TYPE) {
 64                                         if (na     64                                         if (narg)
 65                                                    65                                                 rlen += scnprintf(buf + rlen, maxlen - rlen, ", ");
 66                                         narg++     66                                         narg++;
 67                                 }                  67                                 }
 68                                 if (mode == MO     68                                 if (mode == MODE_PREFIX)
 69                                         mode =     69                                         mode = MODE_CLASS;
 70                                 else               70                                 else
 71                                         mode =     71                                         mode = MODE_CTYPE;
 72                         } else                     72                         } else
 73                                 buf[rlen++] =      73                                 buf[rlen++] = *q;
 74                         break;                     74                         break;
 75                 case 'B':                          75                 case 'B':
 76                 case 'C':                          76                 case 'C':
 77                 case 'D':                          77                 case 'D':
 78                 case 'F':                          78                 case 'F':
 79                 case 'I':                          79                 case 'I':
 80                 case 'J':                          80                 case 'J':
 81                 case 'S':                          81                 case 'S':
 82                 case 'Z':                          82                 case 'Z':
 83                         if (mode == MODE_TYPE)     83                         if (mode == MODE_TYPE) {
 84                                 if (narg)          84                                 if (narg)
 85                                         rlen +     85                                         rlen += scnprintf(buf + rlen, maxlen - rlen, ", ");
 86                                 rlen += scnpri     86                                 rlen += scnprintf(buf + rlen, maxlen - rlen, "%s", base_types[*q - 'A']);
 87                                 while (array--     87                                 while (array--)
 88                                         rlen +     88                                         rlen += scnprintf(buf + rlen, maxlen - rlen, "[]");
 89                                 array = 0;         89                                 array = 0;
 90                                 narg++;            90                                 narg++;
 91                         } else                     91                         } else
 92                                 buf[rlen++] =      92                                 buf[rlen++] = *q;
 93                         break;                     93                         break;
 94                 case 'V':                          94                 case 'V':
 95                         if (mode == MODE_TYPE)     95                         if (mode == MODE_TYPE) {
 96                                 rlen += scnpri     96                                 rlen += scnprintf(buf + rlen, maxlen - rlen, "void");
 97                                 while (array--     97                                 while (array--)
 98                                         rlen +     98                                         rlen += scnprintf(buf + rlen, maxlen - rlen, "[]");
 99                                 array = 0;         99                                 array = 0;
100                         } else                    100                         } else
101                                 buf[rlen++] =     101                                 buf[rlen++] = *q;
102                         break;                    102                         break;
103                 case '[':                         103                 case '[':
104                         if (mode != MODE_TYPE)    104                         if (mode != MODE_TYPE)
105                                 goto error;       105                                 goto error;
106                         array++;                  106                         array++;
107                         break;                    107                         break;
108                 case '(':                         108                 case '(':
109                         if (mode != MODE_FUNC)    109                         if (mode != MODE_FUNC)
110                                 goto error;       110                                 goto error;
111                         buf[rlen++] = *q;         111                         buf[rlen++] = *q;
112                         mode = MODE_TYPE;         112                         mode = MODE_TYPE;
113                         break;                    113                         break;
114                 case ')':                         114                 case ')':
115                         if (mode != MODE_TYPE)    115                         if (mode != MODE_TYPE)
116                                 goto error;       116                                 goto error;
117                         buf[rlen++] = *q;         117                         buf[rlen++] = *q;
118                         narg = 0;                 118                         narg = 0;
119                         break;                    119                         break;
120                 case ';':                         120                 case ';':
121                         if (mode != MODE_CLASS    121                         if (mode != MODE_CLASS && mode != MODE_CTYPE)
122                                 goto error;       122                                 goto error;
123                         /* safe because at lea    123                         /* safe because at least one other char to process */
124                         if (isalpha(*(q + 1))     124                         if (isalpha(*(q + 1)) && mode == MODE_CLASS)
125                                 rlen += scnpri    125                                 rlen += scnprintf(buf + rlen, maxlen - rlen, ".");
126                         if (mode == MODE_CLASS    126                         if (mode == MODE_CLASS)
127                                 mode = MODE_FU    127                                 mode = MODE_FUNC;
128                         else if (mode == MODE_    128                         else if (mode == MODE_CTYPE)
129                                 mode = MODE_TY    129                                 mode = MODE_TYPE;
130                         break;                    130                         break;
131                 case '/':                         131                 case '/':
132                         if (mode != MODE_CLASS    132                         if (mode != MODE_CLASS && mode != MODE_CTYPE)
133                                 goto error;       133                                 goto error;
134                         rlen += scnprintf(buf     134                         rlen += scnprintf(buf + rlen, maxlen - rlen, ".");
135                         break;                    135                         break;
136                 default :                         136                 default :
137                         buf[rlen++] = *q;         137                         buf[rlen++] = *q;
138                 }                                 138                 }
139         }                                         139         }
140         buf[rlen] = '\0';                         140         buf[rlen] = '\0';
141         return buf;                               141         return buf;
142 error:                                            142 error:
143         return NULL;                              143         return NULL;
144 }                                                 144 }
145                                                   145 
146 /*                                                146 /*
147  * Demangle Java function signature (openJDK,     147  * Demangle Java function signature (openJDK, not GCJ)
148  * input:                                         148  * input:
149  *      str: string to parse. String is not mo    149  *      str: string to parse. String is not modified
150  *    flags: combination of JAVA_DEMANGLE_* fl    150  *    flags: combination of JAVA_DEMANGLE_* flags to modify demangling
151  * return:                                        151  * return:
152  *      if input can be demangled, then a newl    152  *      if input can be demangled, then a newly allocated string is returned.
153  *      if input cannot be demangled, then NUL    153  *      if input cannot be demangled, then NULL is returned
154  *                                                154  *
155  * Note: caller is responsible for freeing dem    155  * Note: caller is responsible for freeing demangled string
156  */                                               156  */
157 char *                                            157 char *
158 java_demangle_sym(const char *str, int flags)     158 java_demangle_sym(const char *str, int flags)
159 {                                                 159 {
160         char *buf, *ptr;                          160         char *buf, *ptr;
161         char *p;                                  161         char *p;
162         size_t len, l1 = 0;                       162         size_t len, l1 = 0;
163                                                   163 
164         if (!str)                                 164         if (!str)
165                 return NULL;                      165                 return NULL;
166                                                   166 
167         /* find start of return type */           167         /* find start of return type */
168         p = strrchr(str, ')');                    168         p = strrchr(str, ')');
169         if (!p)                                   169         if (!p)
170                 return NULL;                      170                 return NULL;
171                                                   171 
172         /*                                        172         /*
173          * expansion factor estimated to 3x       173          * expansion factor estimated to 3x
174          */                                       174          */
175         len = strlen(str) * 3 + 1;                175         len = strlen(str) * 3 + 1;
176         buf = malloc(len);                        176         buf = malloc(len);
177         if (!buf)                                 177         if (!buf)
178                 return NULL;                      178                 return NULL;
179                                                   179 
180         buf[0] = '\0';                            180         buf[0] = '\0';
181         if (!(flags & JAVA_DEMANGLE_NORET)) {     181         if (!(flags & JAVA_DEMANGLE_NORET)) {
182                 /*                                182                 /*
183                  * get return type first          183                  * get return type first
184                  */                               184                  */
185                 ptr = __demangle_java_sym(p +     185                 ptr = __demangle_java_sym(p + 1, NULL, buf, len, MODE_TYPE);
186                 if (!ptr)                         186                 if (!ptr)
187                         goto error;               187                         goto error;
188                                                   188 
189                 /* add space between return ty    189                 /* add space between return type and function prototype */
190                 l1 = strlen(buf);                 190                 l1 = strlen(buf);
191                 buf[l1++] = ' ';                  191                 buf[l1++] = ' ';
192         }                                         192         }
193                                                   193 
194         /* process function up to return type     194         /* process function up to return type */
195         ptr = __demangle_java_sym(str, p + 1,     195         ptr = __demangle_java_sym(str, p + 1, buf + l1, len - l1, MODE_PREFIX);
196         if (!ptr)                                 196         if (!ptr)
197                 goto error;                       197                 goto error;
198                                                   198 
199         return buf;                               199         return buf;
200 error:                                            200 error:
201         free(buf);                                201         free(buf);
202         return NULL;                              202         return NULL;
203 }                                                 203 }
204                                                   204 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

sflogo.php