[lldb] Remove unnecessary calls to ConstString::AsCString (NFC) (#190298)
Replace calls to `ConstString::AsCString` with `ConstString::GetString(Ref)` where appropriate. Assisted-by: Claude Code
This commit is contained in:
parent
7edf8a7b51
commit
fd68fa98fc
@ -58,7 +58,7 @@ class TypeMatcher {
|
||||
if (type.IsEmpty())
|
||||
return type;
|
||||
|
||||
llvm::StringRef type_lexer(type.AsCString());
|
||||
llvm::StringRef type_lexer(type);
|
||||
|
||||
type_lexer.consume_front("class ");
|
||||
type_lexer.consume_front("enum ");
|
||||
|
||||
@ -618,7 +618,7 @@ void BreakpointLocation::GetDescription(Stream *s,
|
||||
sc.function->GetMangled().GetMangledName()) {
|
||||
s->EOL();
|
||||
s->Indent("mangled function = ");
|
||||
s->PutCString(mangled_name.AsCString());
|
||||
s->PutCString(mangled_name);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -503,8 +503,8 @@ bool Address::Dump(Stream *s, ExecutionContextScope *exe_scope, DumpStyle style,
|
||||
const Symbol *symbol =
|
||||
symtab->FindSymbolContainingFileAddress(file_Addr);
|
||||
if (symbol) {
|
||||
const char *symbol_name = symbol->GetName().AsCString();
|
||||
if (symbol_name) {
|
||||
llvm::StringRef symbol_name = symbol->GetName().GetStringRef();
|
||||
if (!symbol_name.empty()) {
|
||||
s->PutCStringColorHighlighted(symbol_name, settings);
|
||||
addr_t delta =
|
||||
file_Addr - symbol->GetAddressRef().GetFileAddress();
|
||||
|
||||
@ -413,7 +413,7 @@ VariableAnnotator::AnnotateStructured(Instruction &inst) {
|
||||
|
||||
const Declaration &decl = v->GetDeclaration();
|
||||
if (decl.GetFile()) {
|
||||
decl_file = decl.GetFile().GetFilename().AsCString();
|
||||
decl_file = decl.GetFile().GetFilename().GetString();
|
||||
if (decl.GetLine() > 0)
|
||||
decl_line = decl.GetLine();
|
||||
}
|
||||
|
||||
@ -566,8 +566,7 @@ ConstString Mangled::GetBaseName() const {
|
||||
if (!demangled_name)
|
||||
return {};
|
||||
|
||||
const char *name_str = demangled_name.AsCString();
|
||||
const auto &range = demangled_info->BasenameRange;
|
||||
return ConstString(
|
||||
llvm::StringRef(name_str + range.first, range.second - range.first));
|
||||
demangled_name.GetStringRef().slice(range.first, range.second));
|
||||
}
|
||||
|
||||
@ -796,8 +796,8 @@ bool ValueObjectPrinter::PrintChildrenOneLiner(bool hide_names) {
|
||||
m_stream->PutCString(", ");
|
||||
did_print_children = true;
|
||||
if (!hide_names) {
|
||||
const char *name = child_sp.get()->GetName().AsCString();
|
||||
if (name && *name) {
|
||||
llvm::StringRef name = child_sp.get()->GetName().GetStringRef();
|
||||
if (!name.empty()) {
|
||||
m_stream->PutCString(name);
|
||||
m_stream->PutCString(" = ");
|
||||
}
|
||||
|
||||
@ -656,7 +656,7 @@ void DYLDRendezvous::UpdateFileSpecIfNecessary(SOEntry &entry) {
|
||||
Status region_status =
|
||||
m_process->GetMemoryRegionInfo(entry.dyn_addr, region);
|
||||
if (!region.GetName().IsEmpty())
|
||||
entry.file_spec.SetFile(region.GetName().AsCString(),
|
||||
entry.file_spec.SetFile(region.GetName().GetStringRef(),
|
||||
FileSpec::Style::native);
|
||||
}
|
||||
}
|
||||
|
||||
@ -1472,7 +1472,7 @@ void ClangExpressionDeclMap::FindExternalVisibleDecls(
|
||||
|
||||
if (data_symbol) {
|
||||
std::string warning("got name from symbols: ");
|
||||
warning.append(name.AsCString());
|
||||
warning.append(name.GetStringRef());
|
||||
const unsigned diag_id =
|
||||
m_ast_context->getDiagnostics().getCustomDiagID(
|
||||
clang::DiagnosticsEngine::Level::Warning, "%0");
|
||||
@ -1825,7 +1825,8 @@ void ClangExpressionDeclMap::AddOneFunction(NameSearchContext &context,
|
||||
Type *function_type = function->GetType();
|
||||
|
||||
const auto lang = function->GetCompileUnit()->GetLanguage();
|
||||
const auto name = function->GetMangled().GetMangledName().AsCString();
|
||||
const llvm::StringRef name =
|
||||
function->GetMangled().GetMangledName().GetStringRef();
|
||||
const bool extern_c =
|
||||
(Language::LanguageIsC(lang) && !Mangled::IsMangledName(name)) ||
|
||||
(Language::LanguageIsObjC(lang) &&
|
||||
|
||||
@ -1262,7 +1262,7 @@ size_t AppleObjCRuntimeV2::GetByteOffsetForIvar(CompilerType &parent_ast_type,
|
||||
// Make the objective C V2 mangled name for the ivar offset from the class
|
||||
// name and ivar name
|
||||
std::string buffer("OBJC_IVAR_$_");
|
||||
buffer.append(class_name.AsCString());
|
||||
buffer.append(class_name.GetStringRef());
|
||||
buffer.push_back('.');
|
||||
buffer.append(ivar_name);
|
||||
ConstString ivar_const_str(buffer.c_str());
|
||||
|
||||
@ -2216,7 +2216,7 @@ std::shared_ptr<ObjectFileELF> ObjectFileELF::GetGnuDebugDataObjectFile() {
|
||||
if (err) {
|
||||
GetModule()->ReportWarning(
|
||||
"An error occurred while decompression the section {0}: {1}",
|
||||
section->GetName().AsCString(), llvm::toString(std::move(err)).c_str());
|
||||
section->GetName(), llvm::toString(std::move(err)).c_str());
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
@ -3043,7 +3043,7 @@ unsigned ObjectFileELF::ApplyRelocations(
|
||||
for (unsigned i = 0; i < num_relocations; ++i) {
|
||||
if (!rel.Parse(rel_data, &offset)) {
|
||||
GetModule()->ReportError(".rel{0}[{1:d}] failed to parse relocation",
|
||||
rel_section->GetName().AsCString(), i);
|
||||
rel_section->GetName(), i);
|
||||
break;
|
||||
}
|
||||
const Symbol *symbol = nullptr;
|
||||
@ -3058,8 +3058,7 @@ unsigned ObjectFileELF::ApplyRelocations(
|
||||
case R_ARM_REL32:
|
||||
GetModule()->ReportError("unsupported AArch32 relocation:"
|
||||
" .rel{0}[{1}], type {2}",
|
||||
rel_section->GetName().AsCString(), i,
|
||||
reloc_type(rel));
|
||||
rel_section->GetName(), i, reloc_type(rel));
|
||||
break;
|
||||
default:
|
||||
assert(false && "unexpected relocation type");
|
||||
@ -3088,16 +3087,15 @@ unsigned ObjectFileELF::ApplyRelocations(
|
||||
*dst = value;
|
||||
} else {
|
||||
GetModule()->ReportError(".rel{0}[{1}] unknown symbol id: {2:d}",
|
||||
rel_section->GetName().AsCString(), i,
|
||||
reloc_symbol(rel));
|
||||
rel_section->GetName(), i,
|
||||
reloc_symbol(rel));
|
||||
}
|
||||
break;
|
||||
case R_386_NONE:
|
||||
case R_386_PC32:
|
||||
GetModule()->ReportError("unsupported i386 relocation:"
|
||||
" .rel{0}[{1}], type {2}",
|
||||
rel_section->GetName().AsCString(), i,
|
||||
reloc_type(rel));
|
||||
rel_section->GetName(), i, reloc_type(rel));
|
||||
break;
|
||||
default:
|
||||
assert(false && "unexpected relocation type");
|
||||
|
||||
@ -3808,9 +3808,11 @@ void ObjectFileMachO::ParseSymtab(Symtab &symtab) {
|
||||
// This is usually the second N_SO entry that contains just the
|
||||
// filename, so here we combine it with the first one if we are
|
||||
// minimizing the symbol table
|
||||
const char *so_path =
|
||||
sym[sym_idx - 1].GetMangled().GetDemangledName().AsCString();
|
||||
if (so_path && so_path[0]) {
|
||||
llvm::StringRef so_path = sym[sym_idx - 1]
|
||||
.GetMangled()
|
||||
.GetDemangledName()
|
||||
.GetStringRef();
|
||||
if (!so_path.empty()) {
|
||||
std::string full_so_path(so_path);
|
||||
const size_t double_slash_pos = full_so_path.find("//");
|
||||
if (double_slash_pos != std::string::npos) {
|
||||
|
||||
@ -611,7 +611,7 @@ void PlatformDarwinKernel::AddKextToMap(PlatformDarwinKernel *thisp,
|
||||
bool PlatformDarwinKernel::KextHasdSYMSibling(
|
||||
const FileSpec &kext_bundle_filepath) {
|
||||
FileSpec dsym_fspec = kext_bundle_filepath;
|
||||
std::string filename = dsym_fspec.GetFilename().AsCString();
|
||||
std::string filename = dsym_fspec.GetFilename().GetString();
|
||||
filename += ".dSYM";
|
||||
dsym_fspec.SetFilename(filename);
|
||||
if (FileSystem::Instance().IsDirectory(dsym_fspec)) {
|
||||
@ -648,7 +648,7 @@ bool PlatformDarwinKernel::KextHasdSYMSibling(
|
||||
// /dir/dir/mach.development.t7004.dSYM
|
||||
bool PlatformDarwinKernel::KernelHasdSYMSibling(const FileSpec &kernel_binary) {
|
||||
FileSpec kernel_dsym = kernel_binary;
|
||||
std::string filename = kernel_binary.GetFilename().AsCString();
|
||||
std::string filename = kernel_binary.GetFilename().GetString();
|
||||
filename += ".dSYM";
|
||||
kernel_dsym.SetFilename(filename);
|
||||
return FileSystem::Instance().IsDirectory(kernel_dsym);
|
||||
|
||||
@ -1619,7 +1619,7 @@ bool SymbolFileDWARF::CompleteType(CompilerType &compiler_type) {
|
||||
GetObjectFile()->GetModule()->LogMessageVerboseBacktrace(
|
||||
log, "{0:x8}: {1} ({2}) '{3}' resolving forward declaration...",
|
||||
def_die.GetID(), DW_TAG_value_to_name(def_die.Tag()), def_die.Tag(),
|
||||
type->GetName().AsCString());
|
||||
type->GetName().GetStringRef());
|
||||
assert(compiler_type);
|
||||
return dwarf_ast->CompleteTypeFromDWARF(def_die, type, compiler_type);
|
||||
}
|
||||
|
||||
@ -345,8 +345,8 @@ void SymbolFileDWARFDebugMap::InitOSO() {
|
||||
if (so_symbol && oso_symbol &&
|
||||
so_symbol->GetType() == eSymbolTypeSourceFile &&
|
||||
oso_symbol->GetType() == eSymbolTypeObjectFile) {
|
||||
m_compile_unit_infos[i].so_file.SetFile(so_symbol->GetName().AsCString(),
|
||||
FileSpec::Style::native);
|
||||
m_compile_unit_infos[i].so_file.SetFile(
|
||||
so_symbol->GetName().GetStringRef(), FileSpec::Style::native);
|
||||
m_compile_unit_infos[i].oso_path = oso_symbol->GetName();
|
||||
m_compile_unit_infos[i].oso_mod_time =
|
||||
llvm::sys::toTimePoint(oso_symbol->GetIntegerValue(0));
|
||||
|
||||
@ -401,7 +401,7 @@ static bool LookForDsymNextToExecutablePath(const ModuleSpec &mod_spec,
|
||||
FileSpec dsym_directory = exec_fspec;
|
||||
dsym_directory.RemoveLastPathComponent();
|
||||
|
||||
std::string dsym_filename = filename.AsCString();
|
||||
std::string dsym_filename = filename.GetString();
|
||||
dsym_filename += ".dSYM";
|
||||
dsym_directory.AppendPathComponent(dsym_filename);
|
||||
dsym_directory.AppendPathComponent("Contents");
|
||||
@ -442,7 +442,7 @@ static bool LookForDsymNextToExecutablePath(const ModuleSpec &mod_spec,
|
||||
// See if we have a .dSYM.yaa next to this executable path.
|
||||
FileSpec dsym_yaa_fspec = exec_fspec;
|
||||
dsym_yaa_fspec.RemoveLastPathComponent();
|
||||
std::string dsym_yaa_filename = filename.AsCString();
|
||||
std::string dsym_yaa_filename = filename.GetString();
|
||||
dsym_yaa_filename += ".dSYM.yaa";
|
||||
dsym_yaa_fspec.AppendPathComponent(dsym_yaa_filename);
|
||||
|
||||
|
||||
@ -201,7 +201,7 @@ std::optional<FileSpec> SymbolLocatorDefault::LocateExecutableSymbolFile(
|
||||
// Some debug files may stored in the module directory like this:
|
||||
// /usr/lib/debug/usr/lib/library.so.debug
|
||||
if (!file_dir.IsEmpty())
|
||||
files.push_back(dirname + file_dir.AsCString() + "/" +
|
||||
files.push_back(dirname + file_dir.GetString() + "/" +
|
||||
symbol_file_spec.GetFilename().GetCString());
|
||||
}
|
||||
|
||||
|
||||
@ -272,7 +272,7 @@ BuildModulesSection(Process &process, FileSpec directory) {
|
||||
FileSpec path_to_copy_module = directory;
|
||||
path_to_copy_module.AppendPathComponent("modules");
|
||||
path_to_copy_module.AppendPathComponent(system_path);
|
||||
sys::fs::create_directories(path_to_copy_module.GetDirectory().AsCString());
|
||||
sys::fs::create_directories(path_to_copy_module.GetDirectory());
|
||||
|
||||
if (std::error_code ec =
|
||||
llvm::sys::fs::copy_file(file, path_to_copy_module.GetPath()))
|
||||
|
||||
@ -8602,7 +8602,7 @@ void TypeSystemClang::DumpFromSymbolFile(Stream &s,
|
||||
if (symbol_name != type->GetName().GetStringRef())
|
||||
continue;
|
||||
|
||||
s << type->GetName().AsCString() << "\n";
|
||||
s << type->GetName() << "\n";
|
||||
|
||||
CompilerType full_type = type->GetFullCompilerType();
|
||||
if (clang::TagDecl *tag_decl = GetAsTagDecl(full_type)) {
|
||||
|
||||
@ -89,9 +89,9 @@ void InlineFunctionInfo::DumpStopContext(Stream *s) const {
|
||||
// s->Indent("[inlined] ");
|
||||
s->Indent();
|
||||
if (m_mangled)
|
||||
s->PutCString(m_mangled.GetName().AsCString());
|
||||
s->PutCString(m_mangled.GetName());
|
||||
else
|
||||
s->PutCString(m_name.AsCString());
|
||||
s->PutCString(m_name);
|
||||
}
|
||||
|
||||
ConstString InlineFunctionInfo::GetName() const {
|
||||
|
||||
@ -922,7 +922,7 @@ Mangled SymbolContext::GetPossiblyInlinedFunctionName() const {
|
||||
|
||||
// Sometimes an inline frame may not have mangling information,
|
||||
// but does have a valid name.
|
||||
return Mangled{inline_info->GetName().AsCString()};
|
||||
return Mangled{inline_info->GetName()};
|
||||
}
|
||||
|
||||
//
|
||||
|
||||
@ -596,7 +596,7 @@ static void PrivateAutoComplete(
|
||||
|
||||
if (variable_list) {
|
||||
for (const VariableSP &var_sp : *variable_list)
|
||||
request.AddCompletion(var_sp->GetName().AsCString());
|
||||
request.AddCompletion(var_sp->GetName());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -139,8 +139,8 @@ Status CreateHostSysRootModuleLink(const FileSpec &root_dir_spec,
|
||||
DecrementRefExistingModule(root_dir_spec, sysroot_module_path_spec);
|
||||
}
|
||||
|
||||
Status error = MakeDirectory(
|
||||
FileSpec(sysroot_module_path_spec.GetDirectory().AsCString()));
|
||||
Status error =
|
||||
MakeDirectory(FileSpec(sysroot_module_path_spec.GetDirectory()));
|
||||
if (error.Fail())
|
||||
return error;
|
||||
|
||||
|
||||
@ -1896,7 +1896,7 @@ uint32_t Platform::LoadImage(lldb_private::Process *process,
|
||||
// Only local file was specified. Install it to the current working
|
||||
// directory.
|
||||
FileSpec target_file = GetWorkingDirectory();
|
||||
target_file.AppendPathComponent(local_file.GetFilename().AsCString());
|
||||
target_file.AppendPathComponent(local_file.GetFilename());
|
||||
if (IsRemote() || local_file != target_file) {
|
||||
error = Install(local_file, target_file);
|
||||
if (error.Fail())
|
||||
|
||||
@ -923,7 +923,7 @@ void Target::ApplyNameToBreakpoints(BreakpointName &bp_name) {
|
||||
void Target::GetBreakpointNames(std::vector<std::string> &names) {
|
||||
names.clear();
|
||||
for (const auto& bp_name_entry : m_breakpoint_names) {
|
||||
names.push_back(bp_name_entry.first.AsCString());
|
||||
names.push_back(bp_name_entry.first.GetString());
|
||||
}
|
||||
llvm::sort(names);
|
||||
}
|
||||
|
||||
@ -113,7 +113,7 @@ Trace::LoadPostMortemTraceFromFile(Debugger &debugger,
|
||||
|
||||
return Trace::FindPluginForPostMortemProcess(
|
||||
debugger, *session_file,
|
||||
trace_description_file.GetDirectory().AsCString());
|
||||
trace_description_file.GetDirectory().GetStringRef());
|
||||
}
|
||||
|
||||
Expected<lldb::TraceSP> Trace::FindPluginForPostMortemProcess(
|
||||
|
||||
@ -245,7 +245,7 @@ private:
|
||||
else if (!sc.function && !sc.symbol)
|
||||
m_s << module_name << "`(none)";
|
||||
else
|
||||
m_s << module_name << "`" << sc.GetFunctionName().AsCString();
|
||||
m_s << module_name << "`" << sc.GetFunctionName();
|
||||
}
|
||||
|
||||
void DumpFunctionCallTree(const TraceDumper::FunctionCall &function_call) {
|
||||
|
||||
@ -1064,7 +1064,7 @@ Interpreter::Visit(const BitFieldExtractionNode &node) {
|
||||
std::string message = llvm::formatv(
|
||||
"bitfield range {0}:{1} is not valid for \"({2}) {3}\"", first_index,
|
||||
last_index, base->GetTypeName().AsCString("<invalid type>"),
|
||||
base->GetName().AsCString());
|
||||
base->GetName().GetStringRef());
|
||||
return llvm::make_error<DILDiagnosticError>(m_expr, message,
|
||||
node.GetLocation());
|
||||
}
|
||||
|
||||
@ -767,8 +767,7 @@ Error opts::symbols::verify(lldb_private::Module &Module) {
|
||||
if (!comp_unit)
|
||||
return make_string_error("Cannot parse compile unit {0}.", i);
|
||||
|
||||
outs() << "Processing '"
|
||||
<< comp_unit->GetPrimaryFile().GetFilename().AsCString()
|
||||
outs() << "Processing '" << comp_unit->GetPrimaryFile().GetFilename()
|
||||
<< "' compile unit.\n";
|
||||
|
||||
LineTable *lt = comp_unit->GetLineTable();
|
||||
|
||||
@ -758,7 +758,7 @@ TEST_F(TestTypeSystemClang, TemplateArguments) {
|
||||
CompilerType double_type(m_ast->weak_from_this(),
|
||||
m_ast->getASTContext().DoubleTy.getAsOpaquePtr());
|
||||
for (CompilerType t : {type, typedef_type, auto_type}) {
|
||||
SCOPED_TRACE(t.GetTypeName().AsCString());
|
||||
SCOPED_TRACE(t.GetTypeName().GetString());
|
||||
|
||||
const bool expand_pack = false;
|
||||
EXPECT_EQ(
|
||||
|
||||
@ -307,7 +307,7 @@ DWARF:
|
||||
lldb::TypeSP type =
|
||||
tester.GetParser().ParseTypeFromDWARF(sc, func, &new_type);
|
||||
found_function_types.push_back(
|
||||
type->GetForwardCompilerType().GetTypeName().AsCString());
|
||||
type->GetForwardCompilerType().GetTypeName().GetString());
|
||||
}
|
||||
|
||||
// Compare the parsed function types against the expected list of types.
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user