Skip to content

Commit

Permalink
Revert "[lldb] Remove redundant .c_str() and .get() calls"
Browse files Browse the repository at this point in the history
  • Loading branch information
omjavaid committed Dec 19, 2022
1 parent 0fe37a7 commit 58e9cc1
Show file tree
Hide file tree
Showing 49 changed files with 113 additions and 99 deletions.
2 changes: 1 addition & 1 deletion lldb/include/lldb/Target/Process.h
Expand Up @@ -2704,7 +2704,7 @@ void PruneThreadPlans();
};

void SetNextEventAction(Process::NextEventAction *next_event_action) {
if (m_next_event_action_up)
if (m_next_event_action_up.get())
m_next_event_action_up->HandleBeingUnshipped();

m_next_event_action_up.reset(next_event_action);
Expand Down
2 changes: 1 addition & 1 deletion lldb/source/API/SBCommandReturnObject.cpp
Expand Up @@ -292,7 +292,7 @@ void SBCommandReturnObject::PutCString(const char *string, int len) {
return;
} else if (len > 0) {
std::string buffer(string, len);
ref().AppendMessage(buffer);
ref().AppendMessage(buffer.c_str());
} else
ref().AppendMessage(string);
}
Expand Down
2 changes: 1 addition & 1 deletion lldb/source/API/SBExpressionOptions.cpp
Expand Up @@ -254,5 +254,5 @@ EvaluateExpressionOptions *SBExpressionOptions::get() const {
}

EvaluateExpressionOptions &SBExpressionOptions::ref() const {
return *m_opaque_up;
return *(m_opaque_up.get());
}
4 changes: 2 additions & 2 deletions lldb/source/API/SBSourceManager.cpp
Expand Up @@ -88,14 +88,14 @@ SBSourceManager::SBSourceManager(const SBSourceManager &rhs) {
if (&rhs == this)
return;

m_opaque_up = std::make_unique<SourceManagerImpl>(*rhs.m_opaque_up);
m_opaque_up = std::make_unique<SourceManagerImpl>(*(rhs.m_opaque_up.get()));
}

const lldb::SBSourceManager &SBSourceManager::
operator=(const lldb::SBSourceManager &rhs) {
LLDB_INSTRUMENT_VA(this, rhs);

m_opaque_up = std::make_unique<SourceManagerImpl>(*rhs.m_opaque_up);
m_opaque_up = std::make_unique<SourceManagerImpl>(*(rhs.m_opaque_up.get()));
return *this;
}

Expand Down
2 changes: 1 addition & 1 deletion lldb/source/Breakpoint/BreakpointResolverScripted.cpp
Expand Up @@ -139,7 +139,7 @@ void BreakpointResolverScripted::GetDescription(Stream *s) {
short_help);
}
if (!short_help.empty())
s->PutCString(short_help);
s->PutCString(short_help.c_str());
else
s->Printf("python class = %s", m_class_name.c_str());
}
Expand Down
4 changes: 2 additions & 2 deletions lldb/source/Commands/CommandObjectBreakpoint.cpp
Expand Up @@ -130,10 +130,10 @@ class lldb_private::BreakpointOptionGroup : public OptionGroup {
m_bp_opts.SetThreadID(thread_id);
} break;
case 'T':
m_bp_opts.GetThreadSpec()->SetName(option_arg.str());
m_bp_opts.GetThreadSpec()->SetName(option_arg.str().c_str());
break;
case 'q':
m_bp_opts.GetThreadSpec()->SetQueueName(option_arg.str());
m_bp_opts.GetThreadSpec()->SetQueueName(option_arg.str().c_str());
break;
case 'x': {
uint32_t thread_index = UINT32_MAX;
Expand Down
2 changes: 1 addition & 1 deletion lldb/source/Commands/CommandObjectExpression.cpp
Expand Up @@ -477,7 +477,7 @@ void CommandObjectExpression::IOHandlerInputComplete(IOHandler &io_handler,

CommandReturnObject return_obj(
GetCommandInterpreter().GetDebugger().GetUseColor());
EvaluateExpression(line, *output_sp, *error_sp, return_obj);
EvaluateExpression(line.c_str(), *output_sp, *error_sp, return_obj);
if (output_sp)
output_sp->Flush();
if (error_sp)
Expand Down
10 changes: 5 additions & 5 deletions lldb/source/Commands/CommandObjectHelp.cpp
Expand Up @@ -145,15 +145,15 @@ bool CommandObjectHelp::DoExecute(Args &command, CommandReturnObject &result) {
return false;
} else if (!sub_cmd_obj) {
StreamString error_msg_stream;
GenerateAdditionalHelpAvenuesMessage(&error_msg_stream, cmd_string,
m_interpreter.GetCommandPrefix(),
sub_command);
GenerateAdditionalHelpAvenuesMessage(
&error_msg_stream, cmd_string.c_str(),
m_interpreter.GetCommandPrefix(), sub_command.c_str());
result.AppendError(error_msg_stream.GetString());
return false;
} else {
GenerateAdditionalHelpAvenuesMessage(
&result.GetOutputStream(), cmd_string,
m_interpreter.GetCommandPrefix(), sub_command);
&result.GetOutputStream(), cmd_string.c_str(),
m_interpreter.GetCommandPrefix(), sub_command.c_str());
result.GetOutputStream().Printf(
"\nThe closest match is '%s'. Help on it follows.\n\n",
sub_cmd_obj->GetCommandName().str().c_str());
Expand Down
2 changes: 1 addition & 1 deletion lldb/source/Commands/CommandObjectMultiword.cpp
Expand Up @@ -217,7 +217,7 @@ bool CommandObjectMultiword::Execute(const char *args_string,
}
}
error_msg.append("\n");
result.AppendRawError(error_msg);
result.AppendRawError(error_msg.c_str());
return false;
}

Expand Down
2 changes: 1 addition & 1 deletion lldb/source/Commands/CommandObjectTarget.cpp
Expand Up @@ -390,7 +390,7 @@ class CommandObjectTargetCreate : public CommandObjectParsed {
module_sp->SetSymbolFileFileSpec(symfile);
if (remote_file) {
std::string remote_path = remote_file.GetPath();
target_sp->SetArg0(remote_path);
target_sp->SetArg0(remote_path.c_str());
module_sp->SetPlatformFileSpec(remote_file);
}
}
Expand Down
2 changes: 1 addition & 1 deletion lldb/source/Commands/CommandObjectThread.cpp
Expand Up @@ -1710,7 +1710,7 @@ class CommandObjectThreadJump : public CommandObjectParsed {
}

if (!warnings.empty())
result.AppendWarning(warnings);
result.AppendWarning(warnings.c_str());
}

result.SetStatus(eReturnStatusSuccessFinishResult);
Expand Down
2 changes: 1 addition & 1 deletion lldb/source/Core/Disassembler.cpp
Expand Up @@ -1129,7 +1129,7 @@ Disassembler::Disassembler(const ArchSpec &arch, const char *flavor)
thumb_arch_name.erase(0, 3);
thumb_arch_name.insert(0, "thumb");
}
m_arch.SetTriple(thumb_arch_name);
m_arch.SetTriple(thumb_arch_name.c_str());
}
}

Expand Down
8 changes: 4 additions & 4 deletions lldb/source/Core/FormatEntity.cpp
Expand Up @@ -629,9 +629,9 @@ static ValueObjectSP ExpandIndexedExpression(ValueObject *valobj, size_t index,
ValueObject::ExpressionPathAftermath what_next =
(deref_pointer ? ValueObject::eExpressionPathAftermathDereference
: ValueObject::eExpressionPathAftermathNothing);
ValueObjectSP item =
valobj->GetValueForExpressionPath(ptr_deref_buffer, &reason_to_stop,
&final_value_type, options, &what_next);
ValueObjectSP item = valobj->GetValueForExpressionPath(
ptr_deref_buffer.c_str(), &reason_to_stop, &final_value_type, options,
&what_next);
if (!item) {
LLDB_LOGF(log,
"[ExpandIndexedExpression] ERROR: why stopping = %d,"
Expand Down Expand Up @@ -765,7 +765,7 @@ static bool DumpValue(Stream &s, const SymbolContext *sc,

target =
valobj
->GetValueForExpressionPath(expr_path, &reason_to_stop,
->GetValueForExpressionPath(expr_path.c_str(), &reason_to_stop,
&final_value_type, options, &what_next)
.get();

Expand Down
2 changes: 1 addition & 1 deletion lldb/source/Core/IOHandlerCursesGUI.cpp
Expand Up @@ -3838,7 +3838,7 @@ class CommonCompletionSearcherDelegate : public SearcherDelegate {

void UpdateMatches(const std::string &text) override {
CompletionResult result;
CompletionRequest request(text, text.size(), result);
CompletionRequest request(text.c_str(), text.size(), result);
CommandCompletions::InvokeCommonCompletionCallbacks(
m_debugger.GetCommandInterpreter(), m_completion_mask, request,
nullptr);
Expand Down
7 changes: 4 additions & 3 deletions lldb/source/Expression/REPL.cpp
Expand Up @@ -336,9 +336,10 @@ void REPL::IOHandlerInputComplete(IOHandler &io_handler, std::string &code) {
const char *expr_prefix = nullptr;
lldb::ValueObjectSP result_valobj_sp;
Status error;
lldb::ExpressionResults execution_results = UserExpression::Evaluate(
exe_ctx, expr_options, code, expr_prefix, result_valobj_sp, error,
nullptr); // fixed expression
lldb::ExpressionResults execution_results =
UserExpression::Evaluate(exe_ctx, expr_options, code.c_str(),
expr_prefix, result_valobj_sp, error,
nullptr); // fixed expression

// CommandInterpreter &ci = debugger.GetCommandInterpreter();

Expand Down
11 changes: 7 additions & 4 deletions lldb/source/Interpreter/CommandInterpreter.cpp
Expand Up @@ -1501,7 +1501,8 @@ CommandObject *CommandInterpreter::GetCommandObjectForCommand(
else if (cmd_obj->IsMultiwordObject()) {
// Our current object is a multi-word object; see if the cmd_word is a
// valid sub-command for our object.
CommandObject *sub_cmd_obj = cmd_obj->GetSubcommandObject(cmd_word);
CommandObject *sub_cmd_obj =
cmd_obj->GetSubcommandObject(cmd_word.c_str());
if (sub_cmd_obj)
cmd_obj = sub_cmd_obj;
else // cmd_word was not a valid sub-command word, so we are done
Expand Down Expand Up @@ -1765,8 +1766,9 @@ Status CommandInterpreter::PreprocessCommand(std::string &command) {
options.SetTryAllThreads(true);
options.SetTimeout(std::nullopt);

ExpressionResults expr_result = target.EvaluateExpression(
expr_str, exe_ctx.GetFramePtr(), expr_result_valobj_sp, options);
ExpressionResults expr_result =
target.EvaluateExpression(expr_str.c_str(), exe_ctx.GetFramePtr(),
expr_result_valobj_sp, options);

if (expr_result == eExpressionCompleted) {
Scalar scalar;
Expand Down Expand Up @@ -3408,7 +3410,8 @@ CommandInterpreter::ResolveCommandImpl(std::string &command_line,
}
} else {
if (cmd_obj->IsMultiwordObject()) {
CommandObject *sub_cmd_obj = cmd_obj->GetSubcommandObject(next_word);
CommandObject *sub_cmd_obj =
cmd_obj->GetSubcommandObject(next_word.c_str());
if (sub_cmd_obj) {
// The subcommand's name includes the parent command's name, so
// restart rather than append to the revised_command_line.
Expand Down
2 changes: 1 addition & 1 deletion lldb/source/Interpreter/OptionArgParser.cpp
Expand Up @@ -222,7 +222,7 @@ lldb::addr_t OptionArgParser::ToAddress(const ExecutionContext *exe_ctx,
std::string str_offset = matches[3].str();
if (!llvm::StringRef(str_offset).getAsInteger(0, offset)) {
Status error;
addr = ToAddress(exe_ctx, name, LLDB_INVALID_ADDRESS, &error);
addr = ToAddress(exe_ctx, name.c_str(), LLDB_INVALID_ADDRESS, &error);
if (addr != LLDB_INVALID_ADDRESS) {
if (sign[0] == '+')
return addr + offset;
Expand Down
2 changes: 1 addition & 1 deletion lldb/source/Interpreter/OptionValueArch.cpp
Expand Up @@ -45,7 +45,7 @@ Status OptionValueArch::SetValueFromString(llvm::StringRef value,
case eVarSetOperationReplace:
case eVarSetOperationAssign: {
std::string value_str = value.trim().str();
if (m_current_value.SetTriple(value_str)) {
if (m_current_value.SetTriple(value_str.c_str())) {
m_value_was_set = true;
NotifyValueChanged();
} else
Expand Down
2 changes: 1 addition & 1 deletion lldb/source/Interpreter/ScriptInterpreter.cpp
Expand Up @@ -82,7 +82,7 @@ ScriptInterpreter::GetDataExtractorFromSBData(const lldb::SBData &data) const {
Status
ScriptInterpreter::GetStatusFromSBError(const lldb::SBError &error) const {
if (error.m_opaque_up)
return *error.m_opaque_up;
return *error.m_opaque_up.get();

return Status();
}
Expand Down
Expand Up @@ -644,7 +644,7 @@ bool DynamicLoaderDarwinKernel::KextImageInfo::ReadMemoryModule(
if (m_load_address == LLDB_INVALID_ADDRESS)
return false;

FileSpec file_spec(m_name);
FileSpec file_spec(m_name.c_str());

llvm::MachO::mach_header mh;
size_t size_to_read = 512;
Expand Down Expand Up @@ -785,7 +785,7 @@ bool DynamicLoaderDarwinKernel::KextImageInfo::LoadImageUsingMemoryModule(
PlatformDarwinKernel::GetPluginNameStatic());
if (platform_sp->GetPluginName() == g_platform_name.GetStringRef()) {
ModuleSpec kext_bundle_module_spec(module_spec);
FileSpec kext_filespec(m_name);
FileSpec kext_filespec(m_name.c_str());
FileSpecList search_paths = target.GetExecutableSearchPaths();
kext_bundle_module_spec.GetFileSpec() = kext_filespec;
platform_sp->GetSharedModule(kext_bundle_module_spec, process,
Expand Down
Expand Up @@ -116,7 +116,7 @@ std::shared_ptr<ClangModulesDeclVendor>
ClangPersistentVariables::GetClangModulesDeclVendor() {
if (!m_modules_decl_vendor_sp) {
m_modules_decl_vendor_sp.reset(
ClangModulesDeclVendor::Create(*m_target_sp));
ClangModulesDeclVendor::Create(*m_target_sp.get()));
}
return m_modules_decl_vendor_sp;
}
Expand Down
Expand Up @@ -117,7 +117,7 @@ clang::NamedDecl *NameSearchContext::AddFunDecl(const CompilerType &type,
// will crash in clang.
clang::OverloadedOperatorKind op_kind = clang::NUM_OVERLOADED_OPERATORS;
if (func_proto_type &&
TypeSystemClang::IsOperator(decl_name.getAsString(), op_kind)) {
TypeSystemClang::IsOperator(decl_name.getAsString().c_str(), op_kind)) {
if (!TypeSystemClang::CheckOverloadedOperatorKindParameterCount(
false, op_kind, func_proto_type->getNumParams()))
return nullptr;
Expand Down
Expand Up @@ -211,7 +211,7 @@ CreateStackTrace(ValueObjectSP o,
const std::string &trace_item_name = ".trace") {
auto trace_sp = std::make_shared<StructuredData::Array>();
ValueObjectSP trace_value_object =
o->GetValueForExpressionPath(trace_item_name);
o->GetValueForExpressionPath(trace_item_name.c_str());
size_t count = trace_value_object->GetNumChildren();
for (size_t j = 0; j < count; j++) {
addr_t trace_addr =
Expand All @@ -230,10 +230,11 @@ static StructuredData::ArraySP ConvertToStructuredArray(
const StructuredData::DictionarySP &dict)> const
&callback) {
auto array_sp = std::make_shared<StructuredData::Array>();
unsigned int count = return_value_sp->GetValueForExpressionPath(count_name)
->GetValueAsUnsigned(0);
unsigned int count =
return_value_sp->GetValueForExpressionPath(count_name.c_str())
->GetValueAsUnsigned(0);
ValueObjectSP objects =
return_value_sp->GetValueForExpressionPath(items_name);
return_value_sp->GetValueForExpressionPath(items_name.c_str());
for (unsigned int i = 0; i < count; i++) {
ValueObjectSP o = objects->GetChildAtIndex(i, true);
auto dict_sp = std::make_shared<StructuredData::Dictionary>();
Expand All @@ -248,8 +249,9 @@ static StructuredData::ArraySP ConvertToStructuredArray(
static std::string RetrieveString(ValueObjectSP return_value_sp,
ProcessSP process_sp,
const std::string &expression_path) {
addr_t ptr = return_value_sp->GetValueForExpressionPath(expression_path)
->GetValueAsUnsigned(0);
addr_t ptr =
return_value_sp->GetValueForExpressionPath(expression_path.c_str())
->GetValueAsUnsigned(0);
std::string str;
Status error;
process_sp->ReadCStringFromMemory(ptr, str, error);
Expand Down
Expand Up @@ -88,7 +88,7 @@ t;
static addr_t RetrieveUnsigned(ValueObjectSP return_value_sp,
ProcessSP process_sp,
const std::string &expression_path) {
return return_value_sp->GetValueForExpressionPath(expression_path)
return return_value_sp->GetValueForExpressionPath(expression_path.c_str())
->GetValueAsUnsigned(0);
}

Expand Down
6 changes: 3 additions & 3 deletions lldb/source/Plugins/Language/ObjC/Cocoa.cpp
Expand Up @@ -381,12 +381,12 @@ static void NSNumber_FormatInt128(ValueObject &valobj, Stream &stream,
}
}

stream.PutCString(prefix);
stream.PutCString(prefix.c_str());
const int radix = 10;
const bool isSigned = true;
std::string str = llvm::toString(value, radix, isSigned);
stream.PutCString(str);
stream.PutCString(suffix);
stream.PutCString(str.c_str());
stream.PutCString(suffix.c_str());
}

static void NSNumber_FormatFloat(ValueObject &valobj, Stream &stream,
Expand Down
7 changes: 4 additions & 3 deletions lldb/source/Plugins/MemoryHistory/asan/MemoryHistoryASan.cpp
Expand Up @@ -101,8 +101,9 @@ static void CreateHistoryThreadFromValueObject(ProcessSP process_sp,
std::string trace_path = "." + std::string(type) + "_trace";

ValueObjectSP count_sp =
return_value_sp->GetValueForExpressionPath(count_path);
ValueObjectSP tid_sp = return_value_sp->GetValueForExpressionPath(tid_path);
return_value_sp->GetValueForExpressionPath(count_path.c_str());
ValueObjectSP tid_sp =
return_value_sp->GetValueForExpressionPath(tid_path.c_str());

if (!count_sp || !tid_sp)
return;
Expand All @@ -114,7 +115,7 @@ static void CreateHistoryThreadFromValueObject(ProcessSP process_sp,
return;

ValueObjectSP trace_sp =
return_value_sp->GetValueForExpressionPath(trace_path);
return_value_sp->GetValueForExpressionPath(trace_path.c_str());

if (!trace_sp)
return;
Expand Down
5 changes: 3 additions & 2 deletions lldb/source/Plugins/Platform/Android/AdbClient.cpp
Expand Up @@ -134,7 +134,7 @@ Status AdbClient::Connect() {
port = env_port;
}
std::string uri = "connect://127.0.0.1:" + port;
m_conn->Connect(uri, &error);
m_conn->Connect(uri.c_str(), &error);

return error;
}
Expand Down Expand Up @@ -304,7 +304,8 @@ Status AdbClient::GetResponseError(const char *response_id) {
std::vector<char> error_message;
auto error = ReadMessage(error_message);
if (error.Success())
error.SetErrorString(std::string(&error_message[0], error_message.size()));
error.SetErrorString(
std::string(&error_message[0], error_message.size()).c_str());

return error;
}
Expand Down
Expand Up @@ -95,8 +95,8 @@ bool PlatformAndroidRemoteGDBServer::LaunchGDBServer(lldb::pid_t &pid,
if (gdbstub_port)
local_port = std::stoi(gdbstub_port);

auto error =
MakeConnectURL(pid, local_port, remote_port, socket_name, connect_url);
auto error = MakeConnectURL(pid, local_port, remote_port, socket_name.c_str(),
connect_url);
if (error.Success() && log)
LLDB_LOGF(log, "gdbserver connect URL: %s", connect_url.c_str());

Expand Down
4 changes: 2 additions & 2 deletions lldb/source/Plugins/Platform/MacOSX/PlatformDarwinDevice.cpp
Expand Up @@ -86,7 +86,7 @@ bool PlatformDarwinDevice::UpdateSDKDirectoryInfosIfNeeded() {
llvm::StringRef dirname = GetDeviceSupportDirectoryName();
std::string local_sdk_cache_str = "~/Library/Developer/Xcode/";
local_sdk_cache_str += std::string(dirname);
FileSpec local_sdk_cache(local_sdk_cache_str);
FileSpec local_sdk_cache(local_sdk_cache_str.c_str());
FileSystem::Instance().Resolve(local_sdk_cache);
if (FileSystem::Instance().Exists(local_sdk_cache)) {
if (log) {
Expand Down Expand Up @@ -231,7 +231,7 @@ const char *PlatformDarwinDevice::GetDeviceSupportDirectory() {
if (m_device_support_directory.empty()) {
if (FileSpec fspec = HostInfo::GetXcodeDeveloperDirectory()) {
m_device_support_directory = fspec.GetPath();
m_device_support_directory.append(platform_dir);
m_device_support_directory.append(platform_dir.c_str());
} else {
// Assign a single NULL character so we know we tried to find the device
// support directory and we don't keep trying to find it over and over.
Expand Down

0 comments on commit 58e9cc1

Please sign in to comment.