const ConstString & Host::GetOSString() { static ConstString g_os_string; if (!g_os_string) { #if defined (__APPLE__) g_os_string.SetCString("darwin"); #elif defined (__linux__) g_os_string.SetCString("linux"); #endif } return g_os_string; }
SBTypeMember SBType::GetFieldAtIndex (uint32_t idx) { SBTypeMember sb_type_member; if (IsValid()) { ClangASTType this_type (m_opaque_sp->GetClangASTType (false)); if (this_type.IsValid()) { uint64_t bit_offset = 0; uint32_t bitfield_bit_size = 0; bool is_bitfield = false; std::string name_sstr; ClangASTType field_type (this_type.GetFieldAtIndex (idx, name_sstr, &bit_offset, &bitfield_bit_size, &is_bitfield)); if (field_type.IsValid()) { ConstString name; if (!name_sstr.empty()) name.SetCString(name_sstr.c_str()); sb_type_member.reset (new TypeMemberImpl (TypeImplSP (new TypeImpl(field_type)), bit_offset, name, bitfield_bit_size, is_bitfield)); } } } return sb_type_member; }
const Property * OptionValueProperties::GetPropertyAtPath (const ExecutionContext *exe_ctx, bool will_modify, const char *name) const { const Property *property = NULL; if (name && name[0]) { const char *sub_name = NULL; ConstString key; size_t key_len = ::strcspn (name, ".[{"); if (name[key_len]) { key.SetCStringWithLength (name, key_len); sub_name = name + key_len; } else key.SetCString (name); property = GetProperty (exe_ctx, will_modify, key); if (sub_name && property) { if (sub_name[0] == '.') { OptionValueProperties *sub_properties = property->GetValue()->GetAsProperties(); if (sub_properties) return sub_properties->GetPropertyAtPath(exe_ctx, will_modify, sub_name + 1); } property = NULL; } } return property; }
const ConstString & Host::GetOSString() { static ConstString g_os_string; if (!g_os_string) { #if defined (__APPLE__) const ArchSpec &host_arch = GetArchitecture (eSystemDefaultArchitecture); const llvm::StringRef &str_ref = host_arch.GetTriple().getOSName(); g_os_string.SetCStringWithLength(str_ref.data(), str_ref.size()); #elif defined (__linux__) g_os_string.SetCString("linux"); #elif defined (__FreeBSD__) g_os_string.SetCString("freebsd"); #endif } return g_os_string; }
const ConstString & Host::GetVendorString() { static ConstString g_vendor; if (!g_vendor) { #if defined (__APPLE__) char ostype[64]; size_t len = sizeof(ostype); if (::sysctlbyname("kern.ostype", &ostype, &len, NULL, 0) == 0) g_vendor.SetCString (ostype); else g_vendor.SetCString("apple"); #elif defined (__linux__) g_vendor.SetCString("gnu"); #endif } return g_vendor; }
SyntheticChildrenFrontEnd * lldb_private::formatters::LibCxxVectorIteratorSyntheticFrontEndCreator( CXXSyntheticChildren *, lldb::ValueObjectSP valobj_sp) { static ConstString g_item_name; if (!g_item_name) g_item_name.SetCString("__i"); return (valobj_sp ? new VectorIteratorSyntheticFrontEnd(valobj_sp, g_item_name) : nullptr); }
SyntheticChildrenFrontEnd* lldb_private::formatters::LibStdcppVectorIteratorSyntheticFrontEndCreator (CXXSyntheticChildren*, lldb::ValueObjectSP valobj_sp) { static ConstString g_item_name; if (!g_item_name) g_item_name.SetCString("_M_current"); if (!valobj_sp) return NULL; return (new VectorIteratorSyntheticFrontEnd(valobj_sp,g_item_name)); }
const ConstString & Host::GetTargetTriple() { static ConstString g_host_triple; if (!(g_host_triple)) { const ArchSpec &host_arch = GetArchitecture (eSystemDefaultArchitecture); g_host_triple.SetCString(host_arch.GetTriple().getTriple().c_str()); } return g_host_triple; }
static bool FindFunctionInModule (ConstString &mangled_name, llvm::Module *module, const char *orig_name) { for (llvm::Module::iterator fi = module->getFunctionList().begin(), fe = module->getFunctionList().end(); fi != fe; ++fi) { if (fi->getName().str().find(orig_name) != std::string::npos) { mangled_name.SetCString(fi->getName().str().c_str()); return true; } } return false; }
bool ObjectFile::SplitArchivePathWithObject (const char *path_with_object, FileSpec &archive_file, ConstString &archive_object) { RegularExpression g_object_regex("(.*)\\(([^\\)]+)\\)$"); if (g_object_regex.Execute (path_with_object, 2)) { std::string path; std::string obj; if (g_object_regex.GetMatchAtIndex (path_with_object, 1, path) && g_object_regex.GetMatchAtIndex (path_with_object, 2, obj)) { archive_file.SetFile (path.c_str(), false); archive_object.SetCString(obj.c_str()); return true; } } return false; }
bool PathMappingList::ReverseRemapPath(const ConstString &path, ConstString &new_path) const { const char *path_cstr = path.GetCString(); if (!path_cstr) return false; for (const auto &it : m_pairs) { // FIXME: This should be using FileSpec API's to do the path appending. const size_t prefixLen = it.second.GetLength(); if (::strncmp(it.second.GetCString(), path_cstr, prefixLen) == 0) { std::string new_path_str(it.first.GetCString()); new_path_str.append(path.GetCString() + prefixLen); new_path.SetCString(new_path_str.c_str()); return true; } } return false; }
bool PathMappingList::RemapPath (const ConstString &path, ConstString &new_path) const { 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.GetCString(), 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; }
ConstString Mangled::GetDisplayDemangledName (lldb::LanguageType language) const { ConstString demangled; if (m_mangled) { do { const char* mangled = m_mangled.GetCString(); if (mangled) { if (SwiftLanguageRuntime::IsSwiftMangledName(mangled)) { auto display_cache = ::GetDisplayDemangledNamesCache(); if (display_cache && display_cache->Lookup(mangled, demangled) && demangled) break; std::function<std::string(const ConstString&)> demangler_call = [] (const ConstString& mangled) -> std::string { swift::Demangle::DemangleOptions options(swift::Demangle::DemangleOptions::SimplifiedUIDemangleOptions()); return swift::Demangle::demangleSymbolAsString(mangled.GetCString(), mangled.GetLength(), options); }; std::string demangled_std = demangler_call(m_mangled); if (!demangled_std.empty()) { demangled.SetCString(demangled_std.c_str()); display_cache->Insert(mangled, demangled); break; } } } } while(0); } if (!demangled) demangled = GetDemangledName(language); return demangled ? demangled : m_mangled; }
bool ObjectFile::SplitArchivePathWithObject(const char *path_with_object, FileSpec &archive_file, ConstString &archive_object, bool must_exist) { RegularExpression g_object_regex(llvm::StringRef("(.*)\\(([^\\)]+)\\)$")); RegularExpression::Match regex_match(2); if (g_object_regex.Execute(llvm::StringRef::withNullAsEmpty(path_with_object), ®ex_match)) { std::string path; std::string obj; if (regex_match.GetMatchAtIndex(path_with_object, 1, path) && regex_match.GetMatchAtIndex(path_with_object, 2, obj)) { archive_file.SetFile(path.c_str(), false); archive_object.SetCString(obj.c_str()); if (must_exist && !archive_file.Exists()) return false; return true; } } return false; }
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; }
const ConstString & Host::GetTargetTriple() { static ConstString g_host_triple; if (!(g_host_triple)) { StreamString triple; triple.Printf("%s-%s-%s", GetArchitecture().GetArchitectureName(), GetVendorString().AsCString(), GetOSString().AsCString()); std::transform (triple.GetString().begin(), triple.GetString().end(), triple.GetString().begin(), ::tolower); g_host_triple.SetCString(triple.GetString().c_str()); } return g_host_triple; }
lldb::OptionValueSP OptionValueProperties::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 = NULL; ConstString key; size_t key_len = ::strcspn (name, ".[{"); if (name[key_len]) { key.SetCStringWithLength (name, key_len); sub_name = name + key_len; } else key.SetCString (name); value_sp = GetValueForKey (exe_ctx, key, will_modify); if (sub_name && value_sp) { switch (sub_name[0]) { case '.': return value_sp->GetSubValue (exe_ctx, sub_name + 1, will_modify, error); case '{': // Predicate matching for predicates like // "<setting-name>{<predicate>}" // strings are parsed by the current OptionValueProperties subclass // to mean whatever they want to. For instance a subclass of // OptionValueProperties for a lldb_private::Target might implement: // "target.run-args{arch==i386}" -- only set run args if the arch is i386 // "target.run-args{path=/tmp/a/b/c/a.out}" -- only set run args if the path matches // "target.run-args{basename==test&&arch==x86_64}" -- only set run args if exectable basename is "test" and arch is "x86_64" if (sub_name[1]) { const char *predicate_start = sub_name + 1; const char *predicate_end = strchr(predicate_start, '}'); if (predicate_end) { std::string predicate(predicate_start, predicate_end); if (PredicateMatches(exe_ctx, predicate.c_str())) { if (predicate_end[1]) { // Still more subvalue string to evaluate return value_sp->GetSubValue (exe_ctx, predicate_end + 1, will_modify, error); } else { // We have a match! break; } } } } // Predicate didn't match or wasn't correctly formed value_sp.reset(); break; case '[': // Array or dictionary access for subvalues like: // "[12]" -- access 12th array element // "['hello']" -- dictionary access of key named hello return value_sp->GetSubValue (exe_ctx, sub_name, will_modify, error); default: value_sp.reset(); break; } } } return value_sp; }
bool Host::GetLLDBPath (PathType path_type, FileSpec &file_spec) { // To get paths related to LLDB we get the path to the executable that // contains this function. On MacOSX this will be "LLDB.framework/.../LLDB", // on linux this is assumed to be the "lldb" main executable. If LLDB on // linux is actually in a shared library (lldb.so??) then this function will // need to be modified to "do the right thing". switch (path_type) { case ePathTypeLLDBShlibDir: { static ConstString g_lldb_so_dir; if (!g_lldb_so_dir) { FileSpec lldb_file_spec (Host::GetModuleFileSpecForHostAddress ((void *)Host::GetLLDBPath)); g_lldb_so_dir = lldb_file_spec.GetDirectory(); } file_spec.GetDirectory() = g_lldb_so_dir; return file_spec.GetDirectory(); } break; case ePathTypeSupportExecutableDir: { static ConstString g_lldb_support_exe_dir; if (!g_lldb_support_exe_dir) { FileSpec lldb_file_spec; if (GetLLDBPath (ePathTypeLLDBShlibDir, lldb_file_spec)) { char raw_path[PATH_MAX]; char resolved_path[PATH_MAX]; lldb_file_spec.GetPath(raw_path, sizeof(raw_path)); #if defined (__APPLE__) char *framework_pos = ::strstr (raw_path, "LLDB.framework"); if (framework_pos) { framework_pos += strlen("LLDB.framework"); #if !defined (__arm__) ::strncpy (framework_pos, "/Resources", PATH_MAX - (framework_pos - raw_path)); #endif } #endif FileSpec::Resolve (raw_path, resolved_path, sizeof(resolved_path)); g_lldb_support_exe_dir.SetCString(resolved_path); } } file_spec.GetDirectory() = g_lldb_support_exe_dir; return file_spec.GetDirectory(); } break; case ePathTypeHeaderDir: { static ConstString g_lldb_headers_dir; if (!g_lldb_headers_dir) { #if defined (__APPLE__) FileSpec lldb_file_spec; if (GetLLDBPath (ePathTypeLLDBShlibDir, lldb_file_spec)) { char raw_path[PATH_MAX]; char resolved_path[PATH_MAX]; lldb_file_spec.GetPath(raw_path, sizeof(raw_path)); char *framework_pos = ::strstr (raw_path, "LLDB.framework"); if (framework_pos) { framework_pos += strlen("LLDB.framework"); ::strncpy (framework_pos, "/Headers", PATH_MAX - (framework_pos - raw_path)); } FileSpec::Resolve (raw_path, resolved_path, sizeof(resolved_path)); g_lldb_headers_dir.SetCString(resolved_path); } #else // TODO: Anyone know how we can determine this for linux? Other systems?? g_lldb_headers_dir.SetCString ("/opt/local/include/lldb"); #endif } file_spec.GetDirectory() = g_lldb_headers_dir; return file_spec.GetDirectory(); } break; case ePathTypePythonDir: { // TODO: Anyone know how we can determine this for linux? Other systems? // For linux we are currently assuming the location of the lldb // binary that contains this function is the directory that will // contain lldb.so, lldb.py and embedded_interpreter.py... static ConstString g_lldb_python_dir; if (!g_lldb_python_dir) { FileSpec lldb_file_spec; if (GetLLDBPath (ePathTypeLLDBShlibDir, lldb_file_spec)) { char raw_path[PATH_MAX]; char resolved_path[PATH_MAX]; lldb_file_spec.GetPath(raw_path, sizeof(raw_path)); #if defined (__APPLE__) char *framework_pos = ::strstr (raw_path, "LLDB.framework"); if (framework_pos) { framework_pos += strlen("LLDB.framework"); ::strncpy (framework_pos, "/Resources/Python", PATH_MAX - (framework_pos - raw_path)); } #endif FileSpec::Resolve (raw_path, resolved_path, sizeof(resolved_path)); g_lldb_python_dir.SetCString(resolved_path); } } file_spec.GetDirectory() = g_lldb_python_dir; return file_spec.GetDirectory(); } break; case ePathTypeLLDBSystemPlugins: // System plug-ins directory { #if defined (__APPLE__) static ConstString g_lldb_system_plugin_dir; static bool g_lldb_system_plugin_dir_located = false; if (!g_lldb_system_plugin_dir_located) { g_lldb_system_plugin_dir_located = true; FileSpec lldb_file_spec; if (GetLLDBPath (ePathTypeLLDBShlibDir, lldb_file_spec)) { char raw_path[PATH_MAX]; char resolved_path[PATH_MAX]; lldb_file_spec.GetPath(raw_path, sizeof(raw_path)); char *framework_pos = ::strstr (raw_path, "LLDB.framework"); if (framework_pos) { framework_pos += strlen("LLDB.framework"); ::strncpy (framework_pos, "/Resources/PlugIns", PATH_MAX - (framework_pos - raw_path)); FileSpec::Resolve (raw_path, resolved_path, sizeof(resolved_path)); g_lldb_system_plugin_dir.SetCString(resolved_path); } return false; } } if (g_lldb_system_plugin_dir) { file_spec.GetDirectory() = g_lldb_system_plugin_dir; return true; } #endif // TODO: where would system LLDB plug-ins be located on linux? Other systems? return false; } break; case ePathTypeLLDBUserPlugins: // User plug-ins directory { #if defined (__APPLE__) static ConstString g_lldb_user_plugin_dir; if (!g_lldb_user_plugin_dir) { char user_plugin_path[PATH_MAX]; if (FileSpec::Resolve ("~/Library/Application Support/LLDB/PlugIns", user_plugin_path, sizeof(user_plugin_path))) { g_lldb_user_plugin_dir.SetCString(user_plugin_path); } } file_spec.GetDirectory() = g_lldb_user_plugin_dir; return file_spec.GetDirectory(); #endif // TODO: where would user LLDB plug-ins be located on linux? Other systems? return false; } default: assert (!"Unhandled PathType"); break; } return false; }
lldb::TypeSP DWARFASTParserJava::ParseClassTypeFromDIE(const DWARFDIE &die, bool &is_new_type) { SymbolFileDWARF *dwarf = die.GetDWARF(); dwarf->m_die_to_type[die.GetDIE()] = DIE_IS_BEING_PARSED; Declaration decl; ConstString name; ConstString linkage_name; bool is_forward_declaration = false; uint32_t byte_size = 0; DWARFAttributes attributes; const size_t num_attributes = die.GetAttributes(attributes); for (uint32_t i = 0; i < num_attributes; ++i) { DWARFFormValue form_value; dw_attr_t attr = attributes.AttributeAtIndex(i); if (attributes.ExtractFormValueAtIndex(i, form_value)) { switch (attr) { case DW_AT_name: name.SetCString(form_value.AsCString()); break; case DW_AT_declaration: is_forward_declaration = form_value.Boolean(); break; case DW_AT_byte_size: byte_size = form_value.Unsigned(); break; case DW_AT_linkage_name: linkage_name.SetCString(form_value.AsCString()); break; default: assert(false && "Unsupported attribute for DW_TAG_class_type"); } } } UniqueDWARFASTType unique_ast_entry; if (name) { std::string qualified_name; if (die.GetQualifiedName(qualified_name)) { name.SetCString(qualified_name.c_str()); if (dwarf->GetUniqueDWARFASTTypeMap().Find(name, die, Declaration(), -1, unique_ast_entry)) { if (unique_ast_entry.m_type_sp) { dwarf->GetDIEToType()[die.GetDIE()] = unique_ast_entry.m_type_sp.get(); is_new_type = false; return unique_ast_entry.m_type_sp; } } } } if (is_forward_declaration) { DWARFDeclContext die_decl_ctx; die.GetDWARFDeclContext(die_decl_ctx); TypeSP type_sp = dwarf->FindDefinitionTypeForDWARFDeclContext(die_decl_ctx); if (type_sp) { // We found a real definition for this type elsewhere so lets use it dwarf->GetDIEToType()[die.GetDIE()] = type_sp.get(); is_new_type = false; return type_sp; } } CompilerType compiler_type(&m_ast, dwarf->GetForwardDeclDieToClangType().lookup(die.GetDIE())); if (!compiler_type) compiler_type = m_ast.CreateObjectType(name, linkage_name, byte_size); is_new_type = true; TypeSP type_sp(new Type(die.GetID(), dwarf, name, -1, // byte size isn't specified nullptr, LLDB_INVALID_UID, Type::eEncodingIsUID, &decl, compiler_type, Type::eResolveStateForward)); // Add our type to the unique type map unique_ast_entry.m_type_sp = type_sp; unique_ast_entry.m_die = die; unique_ast_entry.m_declaration = decl; unique_ast_entry.m_byte_size = -1; dwarf->GetUniqueDWARFASTTypeMap().Insert(name, unique_ast_entry); if (!is_forward_declaration) { // Leave this as a forward declaration until we need to know the details of the type dwarf->GetForwardDeclDieToClangType()[die.GetDIE()] = compiler_type.GetOpaqueQualType(); dwarf->GetForwardDeclClangTypeToDie()[compiler_type.GetOpaqueQualType()] = die.GetDIERef(); } return type_sp; }