1*6881a400Schristos /* Split a symbol name. 2*6881a400Schristos 3*6881a400Schristos Copyright (C) 2022-2023 Free Software Foundation, Inc. 4*6881a400Schristos 5*6881a400Schristos This file is part of GDB. 6*6881a400Schristos 7*6881a400Schristos This program is free software; you can redistribute it and/or modify 8*6881a400Schristos it under the terms of the GNU General Public License as published by 9*6881a400Schristos the Free Software Foundation; either version 3 of the License, or 10*6881a400Schristos (at your option) any later version. 11*6881a400Schristos 12*6881a400Schristos This program is distributed in the hope that it will be useful, 13*6881a400Schristos but WITHOUT ANY WARRANTY; without even the implied warranty of 14*6881a400Schristos MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15*6881a400Schristos GNU General Public License for more details. 16*6881a400Schristos 17*6881a400Schristos You should have received a copy of the GNU General Public License 18*6881a400Schristos along with this program. If not, see <http://www.gnu.org/licenses/>. */ 19*6881a400Schristos 20*6881a400Schristos #include "defs.h" 21*6881a400Schristos #include "split-name.h" 22*6881a400Schristos #include "cp-support.h" 23*6881a400Schristos 24*6881a400Schristos /* See split-name.h. */ 25*6881a400Schristos 26*6881a400Schristos std::vector<gdb::string_view> 27*6881a400Schristos split_name (const char *name, split_style style) 28*6881a400Schristos { 29*6881a400Schristos std::vector<gdb::string_view> result; 30*6881a400Schristos unsigned int previous_len = 0; 31*6881a400Schristos 32*6881a400Schristos switch (style) 33*6881a400Schristos { 34*6881a400Schristos case split_style::CXX: 35*6881a400Schristos for (unsigned int current_len = cp_find_first_component (name); 36*6881a400Schristos name[current_len] != '\0'; 37*6881a400Schristos current_len += cp_find_first_component (name + current_len)) 38*6881a400Schristos { 39*6881a400Schristos gdb_assert (name[current_len] == ':'); 40*6881a400Schristos result.emplace_back (&name[previous_len], 41*6881a400Schristos current_len - previous_len); 42*6881a400Schristos /* Skip the '::'. */ 43*6881a400Schristos current_len += 2; 44*6881a400Schristos previous_len = current_len; 45*6881a400Schristos } 46*6881a400Schristos break; 47*6881a400Schristos 48*6881a400Schristos case split_style::UNDERSCORE: 49*6881a400Schristos /* Handle the Ada encoded (aka mangled) form here. */ 50*6881a400Schristos for (const char *iter = strstr (name, "__"); 51*6881a400Schristos iter != nullptr; 52*6881a400Schristos iter = strstr (iter, "__")) 53*6881a400Schristos { 54*6881a400Schristos result.emplace_back (&name[previous_len], 55*6881a400Schristos iter - &name[previous_len]); 56*6881a400Schristos iter += 2; 57*6881a400Schristos previous_len = iter - name; 58*6881a400Schristos } 59*6881a400Schristos break; 60*6881a400Schristos 61*6881a400Schristos case split_style::DOT: 62*6881a400Schristos /* D and Go-style names. */ 63*6881a400Schristos for (const char *iter = strchr (name, '.'); 64*6881a400Schristos iter != nullptr; 65*6881a400Schristos iter = strchr (iter, '.')) 66*6881a400Schristos { 67*6881a400Schristos result.emplace_back (&name[previous_len], 68*6881a400Schristos iter - &name[previous_len]); 69*6881a400Schristos ++iter; 70*6881a400Schristos previous_len = iter - name; 71*6881a400Schristos } 72*6881a400Schristos break; 73*6881a400Schristos 74*6881a400Schristos default: 75*6881a400Schristos break; 76*6881a400Schristos } 77*6881a400Schristos 78*6881a400Schristos result.emplace_back (&name[previous_len]); 79*6881a400Schristos return result; 80*6881a400Schristos } 81*6881a400Schristos 82