size_t lldb_private::formatters::NSArrayMSyntheticFrontEnd::GetIndexOfChildWithName (const ConstString &name) { if (!m_data_32 && !m_data_64) return UINT32_MAX; const char* item_name = name.GetCString(); uint32_t idx = ExtractIndexFromString(item_name); if (idx < UINT32_MAX && idx >= CalculateNumChildren()) return UINT32_MAX; return idx; }
//bool //OptionValueProperties::GetQualifiedName (Stream &strm) //{ // bool dumped_something = false; //// lldb::OptionValuePropertiesSP parent_sp(GetParent ()); //// if (parent_sp) //// { //// parent_sp->GetQualifiedName (strm); //// strm.PutChar('.'); //// dumped_something = true; //// } // if (m_name) // { // strm << m_name; // dumped_something = true; // } // return dumped_something; //} // lldb::OptionValueSP OptionValueProperties::GetValueForKey (const ExecutionContext *exe_ctx, const ConstString &key, bool will_modify) const { lldb::OptionValueSP value_sp; size_t idx = m_name_to_index.Find (key.GetCString(), SIZE_MAX); if (idx < m_properties.size()) value_sp = GetPropertyAtIndex(exe_ctx, will_modify, idx)->GetValue(); return value_sp; }
//------------------------------------------------------------------ /// Returns true if the filespec represents an implementation source /// file (files with a ".c", ".cpp", ".m", ".mm" (many more) /// extension). /// /// @return /// \b true if the filespec represents an implementation source /// file, \b false otherwise. //------------------------------------------------------------------ bool FileSpec::IsSourceImplementationFile () const { ConstString extension (GetFileNameExtension()); if (extension) { static RegularExpression g_source_file_regex ("^(c|m|mm|cpp|c\\+\\+|cxx|cc|cp|s|asm|f|f77|f90|f95|f03|for|ftn|fpp|ada|adb|ads)$", llvm::Regex::IgnoreCase); return g_source_file_regex.Execute (extension.GetCString()); } return false; }
size_t ValueObjectSynthetic::GetIndexOfChildWithName (const ConstString &name) { UpdateValueIfNeeded(); uint32_t found_index = UINT32_MAX; bool did_find = m_name_toindex.GetValueForKey(name.GetCString(), found_index); if (!did_find && m_synth_filter_ap.get() != NULL) { uint32_t index = m_synth_filter_ap->GetIndexOfChildWithName (name); if (index == UINT32_MAX) return index; m_name_toindex.SetValueForKey(name.GetCString(), index); return index; } else if (!did_find && m_synth_filter_ap.get() == NULL) return UINT32_MAX; else /*if (iter != m_name_toindex.end())*/ return found_index; }
void OptionValueProperties::AppendProperty(const ConstString &name, const ConstString &desc, bool is_global, const OptionValueSP &value_sp) { Property property(name, desc, is_global, value_sp); m_name_to_index.Append(name.GetCString(),m_properties.size()); m_properties.push_back(property); value_sp->SetParent (shared_from_this()); m_name_to_index.Sort(); }
bool PathMappingList::RemapPath(const ConstString &path, ConstString &new_path) const { const char *path_cstr = path.GetCString(); // CLEANUP: Convert this function to use StringRefs internally instead // of raw c-strings. if (!path_cstr) return false; const_iterator pos, end = m_pairs.end(); for (pos = m_pairs.begin(); pos != end; ++pos) { const size_t prefixLen = pos->first.GetLength(); if (::strncmp(pos->first.GetCString(), path_cstr, prefixLen) == 0) { std::string new_path_str(pos->second.GetCString()); new_path_str.append(path.GetCString() + prefixLen); new_path.SetCString(new_path_str.c_str()); return true; } } return false; }
uint32_t Module::FindTypes (const SymbolContext& sc, const ConstString &name, bool exact_match, uint32_t max_matches, TypeList& types) { uint32_t num_matches = 0; const char *type_name_cstr = name.GetCString(); std::string type_scope; std::string type_basename; const bool append = true; TypeClass type_class = eTypeClassAny; if (Type::GetTypeScopeAndBasename (type_name_cstr, type_scope, type_basename, type_class)) { // Check if "name" starts with "::" which means the qualified type starts // from the root namespace and implies and exact match. The typenames we // get back from clang do not start with "::" so we need to strip this off // in order to get the qualfied names to match if (type_scope.size() >= 2 && type_scope[0] == ':' && type_scope[1] == ':') { type_scope.erase(0,2); exact_match = true; } ConstString type_basename_const_str (type_basename.c_str()); if (FindTypes_Impl(sc, type_basename_const_str, NULL, append, max_matches, types)) { types.RemoveMismatchedTypes (type_scope, type_basename, type_class, exact_match); num_matches = types.GetSize(); } } else { // The type is not in a namespace/class scope, just search for it by basename if (type_class != eTypeClassAny) { // The "type_name_cstr" will have been modified if we have a valid type class // prefix (like "struct", "class", "union", "typedef" etc). num_matches = FindTypes_Impl(sc, ConstString(type_name_cstr), NULL, append, max_matches, types); types.RemoveMismatchedTypes (type_class); num_matches = types.GetSize(); } else { num_matches = FindTypes_Impl(sc, name, NULL, append, max_matches, types); } } return num_matches; }
void ClangPersistentVariables::RegisterPersistentDecl(const ConstString &name, clang::NamedDecl *decl) { m_persistent_decls.insert( std::pair<const char *, clang::NamedDecl *>(name.GetCString(), decl)); if (clang::EnumDecl *enum_decl = llvm::dyn_cast<clang::EnumDecl>(decl)) { for (clang::EnumConstantDecl *enumerator_decl : enum_decl->enumerators()) { m_persistent_decls.insert(std::pair<const char *, clang::NamedDecl *>( ConstString(enumerator_decl->getNameAsString()).GetCString(), enumerator_decl)); } } }
uint32_t SymbolFileSymtab::FindFunctions(const ConstString &name, const ClangNamespaceDecl *namespace_decl, uint32_t name_type_mask, bool include_inlines, bool append, SymbolContextList& sc_list) { Timer scoped_timer (__PRETTY_FUNCTION__, "SymbolFileSymtab::FindFunctions (name = '%s')", name.GetCString()); // If we ever support finding STABS or COFF debug info symbols, // we will need to add support here. We are not trying to find symbols // here, just "lldb_private::Function" objects that come from complete // debug information. Any symbol queries should go through the symbol // table itself in the module's object file. return 0; }
bool Symbol::SetReExportedSymbolName(const ConstString &name) { if (m_type == eSymbolTypeReExported) { // For eSymbolTypeReExported, the "const char *" from a ConstString // is used as the offset in the address range base address. m_addr_range.GetBaseAddress().SetOffset((intptr_t)name.GetCString()); return true; } return false; }
bool operator < (const SourceInfo &rhs) const { if (function.GetCString() < rhs.function.GetCString()) return true; if (line_entry.file.GetDirectory().GetCString() < rhs.line_entry.file.GetDirectory().GetCString()) return true; if (line_entry.file.GetFilename().GetCString() < rhs.line_entry.file.GetFilename().GetCString()) return true; if (line_entry.line < rhs.line_entry.line) return true; return false; }
uint32_t Module::FindTypes (const SymbolContext& sc, const ConstString &name, const ClangNamespaceDecl *namespace_decl, bool append, uint32_t max_matches, TypeList& types) { uint32_t retval = FindTypes_Impl(sc, name, namespace_decl, append, max_matches, types); if (retval == 0) { const char *stripped = StripTypeName(name.GetCString()); return FindTypes_Impl(sc, ConstString(stripped), namespace_decl, append, max_matches, types); } else return retval; }
bool PathMappingList::RemapPath (const ConstString &path, ConstString &new_path) const { const char *path_cstr = path.GetCString(); if (!path_cstr) return false; const_iterator pos, end = m_pairs.end(); for (pos = m_pairs.begin(); pos != end; ++pos) { const size_t prefixLen = pos->first.GetLength(); if (::strncmp (pos->first.GetCString(), path_cstr, prefixLen) == 0) { std::string new_path_str (pos->second.GetCString()); new_path_str.append(path.GetCString() + prefixLen); new_path.SetCString(new_path_str.c_str()); return true; } } return false; }
uint32_t SyntheticArrayView::FrontEnd::GetIndexOfChildWithName (const ConstString &name_cs) { const char* name_cstr = name_cs.GetCString(); if (*name_cstr != '[') return UINT32_MAX; std::string name(name_cstr+1); if (name[name.size()-1] != ']') return UINT32_MAX; name = name.erase(name.size()-1,1); int index = Args::StringToSInt32 (name.c_str(), -1); if (index < 0) return UINT32_MAX; return index; }
uint32_t Symtab::AppendSymbolIndexesWithName (const ConstString& symbol_name, std::vector<uint32_t>& indexes) { Mutex::Locker locker (m_mutex); Timer scoped_timer (__PRETTY_FUNCTION__, "%s", __PRETTY_FUNCTION__); if (symbol_name) { const char *symbol_cstr = symbol_name.GetCString(); if (!m_name_indexes_computed) InitNameIndexes(); return m_name_to_index.GetValues (symbol_cstr, indexes); } return 0; }
//---------------------------------------------------------------------- // We "guess" the language because we can't determine a symbol's language // from it's name. For example, a Pascal symbol can be mangled using the // C++ Itanium scheme, and defined in a compilation unit within the same // module as other C++ units. In addition, different targets could have // different ways of mangling names from a given language, likewise the // compilation units within those targets. //---------------------------------------------------------------------- lldb::LanguageType Mangled::GuessLanguage () const { ConstString mangled = GetMangledName(); if (mangled) { if (GetDemangledName(lldb::eLanguageTypeUnknown)) { const char *mangled_name = mangled.GetCString(); if (CPlusPlusLanguage::IsCPPMangledName(mangled_name)) return lldb::eLanguageTypeC_plus_plus; else if (ObjCLanguage::IsPossibleObjCMethodName(mangled_name)) return lldb::eLanguageTypeObjC; } } return lldb::eLanguageTypeUnknown; }
void SwiftPersistentExpressionState::SwiftDeclMap::AddDecl (swift::ValueDecl *value_decl, bool check_existing, const ConstString &alias) { std::string name_str; if (alias.IsEmpty()) { name_str = (value_decl->getName().str()); } else { name_str.assign(alias.GetCString()); } if (!check_existing) { m_swift_decls.insert(std::make_pair(name_str, value_decl)); return; } SwiftDeclMapTy::iterator map_end = m_swift_decls.end(); std::pair<SwiftDeclMapTy::iterator, SwiftDeclMapTy::iterator> found_range = m_swift_decls.equal_range(name_str); if (found_range.first == map_end) { m_swift_decls.insert(std::make_pair(name_str, value_decl)); return; } else { SwiftDeclMapTy::iterator cur_item; bool done = false; for (cur_item = found_range.first; !done && cur_item != found_range.second; cur_item++) { swift::ValueDecl *cur_decl = (*cur_item).second; if (DeclsAreEquivalent(cur_decl, value_decl)) { m_swift_decls.erase (cur_item); break; } } m_swift_decls.insert(std::make_pair(name_str, value_decl)); } }
void BreakpointResolverName::AddNameLookup(ConstString name, FunctionNameType name_type_mask) { ObjCLanguage::MethodName objc_method(name.GetCString(), false); if (objc_method.IsValid(false)) { std::vector<ConstString> objc_names; objc_method.GetFullNames(objc_names, true); for (ConstString objc_name : objc_names) { Module::LookupInfo lookup; lookup.SetName(name); lookup.SetLookupName(objc_name); lookup.SetNameTypeMask(eFunctionNameTypeFull); m_lookups.push_back(lookup); } } else { Module::LookupInfo lookup(name, name_type_mask, m_language); m_lookups.push_back(lookup); } }
bool RichManglingContext::FromItaniumName(const ConstString &mangled) { bool err = m_ipd.partialDemangle(mangled.GetCString()); if (!err) { ResetProvider(ItaniumPartialDemangler); } if (Log *log = lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_DEMANGLE)) { if (!err) { ParseFullName(); LLDB_LOG(log, "demangled itanium: {0} -> \"{1}\"", mangled, m_ipd_buf); } else { LLDB_LOG(log, "demangled itanium: {0} -> error: failed to demangle", mangled); } } return !err; // true == success }
size_t TypeFilterImpl::FrontEnd::GetIndexOfChildWithName(const ConstString &name) { const char *name_cstr = name.GetCString(); if (name_cstr) { for (size_t i = 0; i < filter->GetCount(); i++) { const char *expr_cstr = filter->GetExpressionPathAtIndex(i); if (expr_cstr) { if (*expr_cstr == '.') expr_cstr++; else if (*expr_cstr == '-' && *(expr_cstr + 1) == '>') expr_cstr += 2; } if (expr_cstr) { if (!::strcmp(name_cstr, expr_cstr)) return i; } } } return UINT32_MAX; }
bool ABI::GetRegisterInfoByName(const ConstString &name, RegisterInfo &info) { uint32_t count = 0; const RegisterInfo *register_info_array = GetRegisterInfoArray(count); if (register_info_array) { const char *unique_name_cstr = name.GetCString(); uint32_t i; for (i = 0; i < count; ++i) { if (register_info_array[i].name == unique_name_cstr) { info = register_info_array[i]; return true; } } for (i = 0; i < count; ++i) { if (register_info_array[i].alt_name == unique_name_cstr) { info = register_info_array[i]; return true; } } } return false; }
bool lldb_private::formatters::swift::NSContiguousString_SummaryProvider (ValueObject& valobj, Stream& stream, const TypeSummaryOptions& options) { static ConstString g_StringCoreType("_TtVs11_StringCore"); lldb::addr_t core_location = valobj.GetValueAsUnsigned(LLDB_INVALID_ADDRESS); if (core_location == LLDB_INVALID_ADDRESS) return false; ProcessSP process_sp(valobj.GetProcessSP()); if (!process_sp) return false; size_t ptr_size = process_sp->GetAddressByteSize(); core_location += 2*ptr_size; Error error; InferiorSizedWord isw_1(process_sp->ReadPointerFromMemory(core_location, error),*process_sp); InferiorSizedWord isw_2(process_sp->ReadPointerFromMemory(core_location+ptr_size, error),*process_sp); InferiorSizedWord isw_3(process_sp->ReadPointerFromMemory(core_location+ptr_size+ptr_size, error),*process_sp); DataBufferSP buffer_sp(new DataBufferHeap(3*ptr_size, 0)); uint8_t* buffer = buffer_sp->GetBytes(); buffer = isw_1.CopyToBuffer(buffer); buffer = isw_2.CopyToBuffer(buffer); buffer = isw_3.CopyToBuffer(buffer); DataExtractor data(buffer_sp, process_sp->GetByteOrder(), ptr_size); SwiftASTContext* lldb_swift_ast = process_sp->GetTarget().GetScratchSwiftASTContext(error); if (!lldb_swift_ast) return false; CompilerType string_core_type = lldb_swift_ast->GetTypeFromMangledTypename(g_StringCoreType.GetCString(), error); if (string_core_type.IsValid() == false) return false; ValueObjectSP string_core_sp = ValueObject::CreateValueObjectFromData("stringcore", data, valobj.GetExecutionContextRef(), string_core_type); if (string_core_sp) return StringCore_SummaryProvider(*string_core_sp, stream, options); return false; }
lldb::BasicType GoASTContext::GetBasicTypeEnumeration(lldb::opaque_compiler_type_t type) { ConstString name = GetTypeName(type); if (name) { typedef UniqueCStringMap<lldb::BasicType> TypeNameToBasicTypeMap; static TypeNameToBasicTypeMap g_type_map; static std::once_flag g_once_flag; std::call_once(g_once_flag, [](){ // "void" g_type_map.Append(ConstString("void").GetCString(), eBasicTypeVoid); // "int" g_type_map.Append(ConstString("int").GetCString(), eBasicTypeInt); g_type_map.Append(ConstString("uint").GetCString(), eBasicTypeUnsignedInt); // Miscellaneous g_type_map.Append(ConstString("bool").GetCString(), eBasicTypeBool); // Others. Should these map to C types? g_type_map.Append(ConstString("byte").GetCString(), eBasicTypeOther); g_type_map.Append(ConstString("uint8").GetCString(), eBasicTypeOther); g_type_map.Append(ConstString("uint16").GetCString(), eBasicTypeOther); g_type_map.Append(ConstString("uint32").GetCString(), eBasicTypeOther); g_type_map.Append(ConstString("uint64").GetCString(), eBasicTypeOther); g_type_map.Append(ConstString("int8").GetCString(), eBasicTypeOther); g_type_map.Append(ConstString("int16").GetCString(), eBasicTypeOther); g_type_map.Append(ConstString("int32").GetCString(), eBasicTypeOther); g_type_map.Append(ConstString("int64").GetCString(), eBasicTypeOther); g_type_map.Append(ConstString("float32").GetCString(), eBasicTypeOther); g_type_map.Append(ConstString("float64").GetCString(), eBasicTypeOther); g_type_map.Append(ConstString("uintptr").GetCString(), eBasicTypeOther); g_type_map.Sort(); }); return g_type_map.Find(name.GetCString(), eBasicTypeInvalid); } return eBasicTypeInvalid; }
void Mangled::SetValue (const ConstString &name) { if (name) { if (cstring_is_mangled(name.GetCString())) { m_demangled.Clear(); m_mangled = name; } else { m_demangled = name; m_mangled.Clear(); } } else { m_demangled.Clear(); m_mangled.Clear(); } }
void SwiftPersistentExpressionState::RegisterSymbol (const ConstString &name, lldb::addr_t addr) { m_symbol_map[name.GetCString()] = addr; }
lldb::OptionValueSP OptionValueDictionary::GetSubValue (const ExecutionContext *exe_ctx, const char *name, bool will_modify, Error &error) const { lldb::OptionValueSP value_sp; if (name && name[0]) { const char *sub_name = nullptr; ConstString key; const char *open_bracket = ::strchr (name, '['); if (open_bracket) { const char *key_start = open_bracket + 1; const char *key_end = nullptr; switch (open_bracket[1]) { case '\'': ++key_start; key_end = strchr(key_start, '\''); if (key_end) { if (key_end[1] == ']') { if (key_end[2]) sub_name = key_end + 2; } else { error.SetErrorStringWithFormat ("invalid value path '%s', single quoted key names must be formatted as ['<key>'] where <key> is a string that doesn't contain quotes", name); return value_sp; } } else { error.SetErrorString ("missing '] key name terminator, key name started with ['"); return value_sp; } break; case '"': ++key_start; key_end = strchr(key_start, '"'); if (key_end) { if (key_end[1] == ']') { if (key_end[2]) sub_name = key_end + 2; break; } error.SetErrorStringWithFormat ("invalid value path '%s', double quoted key names must be formatted as [\"<key>\"] where <key> is a string that doesn't contain quotes", name); return value_sp; } else { error.SetErrorString ("missing \"] key name terminator, key name started with [\""); return value_sp; } break; default: key_end = strchr(key_start, ']'); if (key_end) { if (key_end[1]) sub_name = key_end + 1; } else { error.SetErrorString ("missing ] key name terminator, key name started with ["); return value_sp; } break; } if (key_start && key_end) { key.SetCStringWithLength (key_start, key_end - key_start); value_sp = GetValueForKey (key); if (value_sp) { if (sub_name) return value_sp->GetSubValue (exe_ctx, sub_name, will_modify, error); } else { error.SetErrorStringWithFormat("dictionary does not contain a value for the key name '%s'", key.GetCString()); } } } if (!value_sp && error.AsCString() == nullptr) { error.SetErrorStringWithFormat ("invalid value path '%s', %s values only support '[<key>]' subvalues where <key> a string value optionally delimited by single or double quotes", name, GetTypeAsCString()); } } return value_sp; }
size_t ModuleList::FindFunctions (const ConstString &name, uint32_t name_type_mask, bool include_symbols, bool include_inlines, bool append, SymbolContextList &sc_list) const { if (!append) sc_list.Clear(); const size_t old_size = sc_list.GetSize(); if (name_type_mask & eFunctionNameTypeAuto) { ConstString lookup_name; uint32_t lookup_name_type_mask = 0; bool match_name_after_lookup = false; Module::PrepareForFunctionNameLookup (name, name_type_mask, eLanguageTypeUnknown, // TODO: add support lookup_name, lookup_name_type_mask, match_name_after_lookup); Mutex::Locker locker(m_modules_mutex); collection::const_iterator pos, end = m_modules.end(); for (pos = m_modules.begin(); pos != end; ++pos) { (*pos)->FindFunctions(lookup_name, nullptr, lookup_name_type_mask, include_symbols, include_inlines, true, sc_list); } if (match_name_after_lookup) { SymbolContext sc; size_t i = old_size; while (i < sc_list.GetSize()) { if (sc_list.GetContextAtIndex(i, sc)) { const char *func_name = sc.GetFunctionName().GetCString(); if (func_name != nullptr && strstr(func_name, name.GetCString()) == nullptr) { // Remove the current context sc_list.RemoveContextAtIndex(i); // Don't increment i and continue in the loop continue; } } ++i; } } } else { Mutex::Locker locker(m_modules_mutex); collection::const_iterator pos, end = m_modules.end(); for (pos = m_modules.begin(); pos != end; ++pos) { (*pos)->FindFunctions(name, nullptr, name_type_mask, include_symbols, include_inlines, true, sc_list); } } return sc_list.GetSize() - old_size; }
void Symbol::SetReExportedSymbolName(const ConstString &name) { SetType(eSymbolTypeReExported); // For eSymbolTypeReExported, the "const char *" from a ConstString // is used as the offset in the address range base address. m_addr_range.GetBaseAddress().SetOffset((uintptr_t)name.GetCString()); }
size_t lldb_private::formatters::LibcxxStdUnorderedMapSyntheticFrontEnd::GetIndexOfChildWithName (const ConstString &name) { return ExtractIndexFromString(name.GetCString()); }
size_t Symtab::FindFunctionSymbols (const ConstString &name, uint32_t name_type_mask, SymbolContextList& sc_list) { size_t count = 0; std::vector<uint32_t> symbol_indexes; const char *name_cstr = name.GetCString(); // eFunctionNameTypeAuto should be pre-resolved by a call to Module::PrepareForFunctionNameLookup() assert ((name_type_mask & eFunctionNameTypeAuto) == 0); if (name_type_mask & (eFunctionNameTypeBase | eFunctionNameTypeFull)) { std::vector<uint32_t> temp_symbol_indexes; FindAllSymbolsWithNameAndType (name, eSymbolTypeAny, temp_symbol_indexes); unsigned temp_symbol_indexes_size = temp_symbol_indexes.size(); if (temp_symbol_indexes_size > 0) { Mutex::Locker locker (m_mutex); for (unsigned i = 0; i < temp_symbol_indexes_size; i++) { SymbolContext sym_ctx; sym_ctx.symbol = SymbolAtIndex (temp_symbol_indexes[i]); if (sym_ctx.symbol) { switch (sym_ctx.symbol->GetType()) { case eSymbolTypeCode: case eSymbolTypeResolver: symbol_indexes.push_back(temp_symbol_indexes[i]); break; default: break; } } } } } if (name_type_mask & eFunctionNameTypeBase) { // From mangled names we can't tell what is a basename and what // is a method name, so we just treat them the same if (!m_name_indexes_computed) InitNameIndexes(); if (!m_basename_to_index.IsEmpty()) { const UniqueCStringMap<uint32_t>::Entry *match; for (match = m_basename_to_index.FindFirstValueForName(name_cstr); match != NULL; match = m_basename_to_index.FindNextValueForName(match)) { symbol_indexes.push_back(match->value); } } } if (name_type_mask & eFunctionNameTypeMethod) { if (!m_name_indexes_computed) InitNameIndexes(); if (!m_method_to_index.IsEmpty()) { const UniqueCStringMap<uint32_t>::Entry *match; for (match = m_method_to_index.FindFirstValueForName(name_cstr); match != NULL; match = m_method_to_index.FindNextValueForName(match)) { symbol_indexes.push_back(match->value); } } } if (name_type_mask & eFunctionNameTypeSelector) { if (!m_name_indexes_computed) InitNameIndexes(); if (!m_selector_to_index.IsEmpty()) { const UniqueCStringMap<uint32_t>::Entry *match; for (match = m_selector_to_index.FindFirstValueForName(name_cstr); match != NULL; match = m_selector_to_index.FindNextValueForName(match)) { symbol_indexes.push_back(match->value); } } } if (!symbol_indexes.empty()) { std::sort(symbol_indexes.begin(), symbol_indexes.end()); symbol_indexes.erase(std::unique(symbol_indexes.begin(), symbol_indexes.end()), symbol_indexes.end()); count = symbol_indexes.size(); SymbolIndicesToSymbolContextList (symbol_indexes, sc_list); } return count; }