Make DiagnosticsManager functions take StringRefs.

llvm-svn: 286730
This commit is contained in:
Zachary Turner 2016-11-12 19:12:56 +00:00
parent 43400b4c06
commit e2411fabda
10 changed files with 76 additions and 76 deletions

View File

@ -13,6 +13,8 @@
#include "lldb/lldb-defines.h"
#include "lldb/lldb-types.h"
#include "llvm/ADT/StringRef.h"
#include <string>
#include <vector>
@ -55,7 +57,7 @@ public:
}
}
Diagnostic(const char *message, DiagnosticSeverity severity,
Diagnostic(llvm::StringRef message, DiagnosticSeverity severity,
DiagnosticOrigin origin, uint32_t compiler_id)
: m_message(message), m_severity(severity), m_origin(origin),
m_compiler_id(compiler_id) {}
@ -72,9 +74,10 @@ public:
uint32_t GetCompilerID() const { return m_compiler_id; }
const char *GetMessage() const { return m_message.c_str(); }
llvm::StringRef GetMessage() const { return m_message; }
void AppendMessage(const char *message, bool precede_with_newline = true) {
void AppendMessage(llvm::StringRef message,
bool precede_with_newline = true) {
if (precede_with_newline)
m_message.push_back('\n');
m_message.append(message);
@ -114,7 +117,7 @@ public:
return false;
}
void AddDiagnostic(const char *message, DiagnosticSeverity severity,
void AddDiagnostic(llvm::StringRef message, DiagnosticSeverity severity,
DiagnosticOrigin origin,
uint32_t compiler_id = LLDB_INVALID_COMPILER_ID) {
m_diagnostics.push_back(
@ -127,11 +130,11 @@ public:
size_t Printf(DiagnosticSeverity severity, const char *format, ...)
__attribute__((format(printf, 3, 4)));
size_t PutCString(DiagnosticSeverity severity, const char *cstr);
size_t PutString(DiagnosticSeverity severity, llvm::StringRef str);
void AppendMessageToDiagnostic(const char *cstr) {
if (m_diagnostics.size()) {
m_diagnostics.back()->AppendMessage(cstr);
void AppendMessageToDiagnostic(llvm::StringRef str) {
if (!m_diagnostics.empty()) {
m_diagnostics.back()->AppendMessage(str);
}
}

View File

@ -67,15 +67,15 @@ size_t DiagnosticManager::Printf(DiagnosticSeverity severity,
size_t result = ss.PrintfVarArg(format, args);
va_end(args);
AddDiagnostic(ss.GetData(), severity, eDiagnosticOriginLLDB);
AddDiagnostic(ss.GetString(), severity, eDiagnosticOriginLLDB);
return result;
}
size_t DiagnosticManager::PutCString(DiagnosticSeverity severity,
const char *cstr) {
if (!cstr)
size_t DiagnosticManager::PutString(DiagnosticSeverity severity,
llvm::StringRef str) {
if (str.empty())
return 0;
AddDiagnostic(cstr, severity, eDiagnosticOriginLLDB);
return strlen(cstr);
AddDiagnostic(str, severity, eDiagnosticOriginLLDB);
return str.size();
}

View File

@ -1,5 +1,4 @@
//===-- FunctionCaller.cpp ---------------------------------------*- C++
//-*-===//
//===-- FunctionCaller.cpp ---------------------------------------*- C++-*-===//
//
// The LLVM Compiler Infrastructure
//
@ -130,9 +129,9 @@ bool FunctionCaller::WriteFunctionArguments(
// All the information to reconstruct the struct is provided by the
// StructExtractor.
if (!m_struct_valid) {
diagnostic_manager.PutCString(eDiagnosticSeverityError,
"Argument information was not correctly "
"parsed, so the function cannot be called.");
diagnostic_manager.PutString(eDiagnosticSeverityError,
"Argument information was not correctly "
"parsed, so the function cannot be called.");
return false;
}
@ -243,7 +242,7 @@ lldb::ThreadPlanSP FunctionCaller::GetThreadPlanToCallFunction(
// FIXME: Use the errors Stream for better error reporting.
Thread *thread = exe_ctx.GetThreadPtr();
if (thread == NULL) {
diagnostic_manager.PutCString(
diagnostic_manager.PutString(
eDiagnosticSeverityError,
"Can't call a function without a valid thread.");
return NULL;

View File

@ -97,7 +97,7 @@ LLVMUserExpression::DoExecute(DiagnosticManager &diagnostic_manager,
llvm::Function *function = m_execution_unit_sp->GetFunction();
if (!module || !function) {
diagnostic_manager.PutCString(
diagnostic_manager.PutString(
eDiagnosticSeverityError,
"supposed to interpret, but nothing is there");
return lldb::eExpressionSetupError;
@ -153,7 +153,7 @@ LLVMUserExpression::DoExecute(DiagnosticManager &diagnostic_manager,
StreamString ss;
if (!call_plan_sp || !call_plan_sp->ValidatePlan(&ss)) {
diagnostic_manager.PutCString(eDiagnosticSeverityError, ss.GetData());
diagnostic_manager.PutString(eDiagnosticSeverityError, ss.GetData());
return lldb::eExpressionSetupError;
}
@ -198,8 +198,8 @@ LLVMUserExpression::DoExecute(DiagnosticManager &diagnostic_manager,
"Execution was interrupted, reason: %s.",
error_desc);
else
diagnostic_manager.PutCString(eDiagnosticSeverityError,
"Execution was interrupted.");
diagnostic_manager.PutString(eDiagnosticSeverityError,
"Execution was interrupted.");
if ((execution_result == lldb::eExpressionInterrupted &&
options.DoesUnwindOnError()) ||
@ -220,7 +220,7 @@ LLVMUserExpression::DoExecute(DiagnosticManager &diagnostic_manager,
return execution_result;
} else if (execution_result == lldb::eExpressionStoppedForDebug) {
diagnostic_manager.PutCString(
diagnostic_manager.PutString(
eDiagnosticSeverityRemark,
"Execution was halted at the first instruction of the expression "
"function because \"debug\" was requested.\n"
@ -243,7 +243,7 @@ LLVMUserExpression::DoExecute(DiagnosticManager &diagnostic_manager,
return lldb::eExpressionResultUnavailable;
}
} else {
diagnostic_manager.PutCString(
diagnostic_manager.PutString(
eDiagnosticSeverityError,
"Expression can't be run, because there is no JIT compiled function");
return lldb::eExpressionSetupError;
@ -298,7 +298,7 @@ bool LLVMUserExpression::PrepareToExecuteJITExpression(
lldb::StackFrameSP frame;
if (!LockAndCheckContext(exe_ctx, target, process, frame)) {
diagnostic_manager.PutCString(
diagnostic_manager.PutString(
eDiagnosticSeverityError,
"The context has changed before we could JIT the expression!");
return false;

View File

@ -624,8 +624,8 @@ unsigned ClangExpressionParser::Parse(DiagnosticManager &diagnostic_manager) {
if (m_pp_callbacks && m_pp_callbacks->hasErrors()) {
num_errors++;
diagnostic_manager.PutCString(eDiagnosticSeverityError,
"while importing modules:");
diagnostic_manager.PutString(eDiagnosticSeverityError,
"while importing modules:");
diagnostic_manager.AppendMessageToDiagnostic(
m_pp_callbacks->getErrorString().c_str());
}

View File

@ -203,8 +203,8 @@ ClangFunctionCaller::CompileFunction(lldb::ThreadSP thread_to_use_sp,
num_errors = m_parser->Parse(diagnostic_manager);
} else {
diagnostic_manager.PutCString(eDiagnosticSeverityError,
"no process - unable to inject function");
diagnostic_manager.PutString(eDiagnosticSeverityError,
"no process - unable to inject function");
num_errors = 1;
}

View File

@ -325,21 +325,21 @@ bool ClangUserExpression::Parse(DiagnosticManager &diagnostic_manager,
lldb::eLanguageTypeC)) {
m_result_delegate.RegisterPersistentState(persistent_state);
} else {
diagnostic_manager.PutCString(
diagnostic_manager.PutString(
eDiagnosticSeverityError,
"couldn't start parsing (no persistent data)");
return false;
}
} else {
diagnostic_manager.PutCString(eDiagnosticSeverityError,
"error: couldn't start parsing (no target)");
diagnostic_manager.PutString(eDiagnosticSeverityError,
"error: couldn't start parsing (no target)");
return false;
}
ScanContext(exe_ctx, err);
if (!err.Success()) {
diagnostic_manager.PutCString(eDiagnosticSeverityWarning, err.AsCString());
diagnostic_manager.PutString(eDiagnosticSeverityWarning, err.AsCString());
}
////////////////////////////////////
@ -400,8 +400,8 @@ bool ClangUserExpression::Parse(DiagnosticManager &diagnostic_manager,
if (!source_code->GetText(m_transformed_text, lang_type, m_in_static_method,
exe_ctx)) {
diagnostic_manager.PutCString(eDiagnosticSeverityError,
"couldn't construct expression body");
diagnostic_manager.PutString(eDiagnosticSeverityError,
"couldn't construct expression body");
return false;
}
}
@ -416,7 +416,7 @@ bool ClangUserExpression::Parse(DiagnosticManager &diagnostic_manager,
Target *target = exe_ctx.GetTargetPtr();
if (!target) {
diagnostic_manager.PutCString(eDiagnosticSeverityError, "invalid target");
diagnostic_manager.PutString(eDiagnosticSeverityError, "invalid target");
return false;
}
@ -443,7 +443,7 @@ bool ClangUserExpression::Parse(DiagnosticManager &diagnostic_manager,
OnExit on_exit([this]() { ResetDeclMap(); });
if (!DeclMap()->WillParse(exe_ctx, m_materializer_ap.get())) {
diagnostic_manager.PutCString(
diagnostic_manager.PutString(
eDiagnosticSeverityError,
"current process state is unsuitable for expression parsing");
@ -508,10 +508,10 @@ bool ClangUserExpression::Parse(DiagnosticManager &diagnostic_manager,
if (!jit_error.Success()) {
const char *error_cstr = jit_error.AsCString();
if (error_cstr && error_cstr[0])
diagnostic_manager.PutCString(eDiagnosticSeverityError, error_cstr);
diagnostic_manager.PutString(eDiagnosticSeverityError, error_cstr);
else
diagnostic_manager.PutCString(eDiagnosticSeverityError,
"expression can't be interpreted or run");
diagnostic_manager.PutString(eDiagnosticSeverityError,
"expression can't be interpreted or run");
return false;
}
}
@ -527,8 +527,8 @@ bool ClangUserExpression::Parse(DiagnosticManager &diagnostic_manager,
"couldn't run static initializers: %s\n",
error_cstr);
else
diagnostic_manager.PutCString(eDiagnosticSeverityError,
"couldn't run static initializers\n");
diagnostic_manager.PutString(eDiagnosticSeverityError,
"couldn't run static initializers\n");
return false;
}
}
@ -597,7 +597,7 @@ bool ClangUserExpression::AddArguments(ExecutionContext &exe_ctx,
} else if (m_in_objectivec_method) {
object_name.SetCString("self");
} else {
diagnostic_manager.PutCString(
diagnostic_manager.PutString(
eDiagnosticSeverityError,
"need object pointer but don't know the language");
return false;

View File

@ -1,5 +1,4 @@
//===-- ClangUserExpression.cpp -------------------------------------*- C++
//-*-===//
//===-- ClangUserExpression.cpp ----------------------------------*- C++-*-===//
//
// The LLVM Compiler Infrastructure
//
@ -63,8 +62,8 @@ ClangUtilityFunction::~ClangUtilityFunction() {}
bool ClangUtilityFunction::Install(DiagnosticManager &diagnostic_manager,
ExecutionContext &exe_ctx) {
if (m_jit_start_addr != LLDB_INVALID_ADDRESS) {
diagnostic_manager.PutCString(eDiagnosticSeverityWarning,
"already installed");
diagnostic_manager.PutString(eDiagnosticSeverityWarning,
"already installed");
return false;
}
@ -75,14 +74,14 @@ bool ClangUtilityFunction::Install(DiagnosticManager &diagnostic_manager,
Target *target = exe_ctx.GetTargetPtr();
if (!target) {
diagnostic_manager.PutCString(eDiagnosticSeverityError, "invalid target");
diagnostic_manager.PutString(eDiagnosticSeverityError, "invalid target");
return false;
}
Process *process = exe_ctx.GetProcessPtr();
if (!process) {
diagnostic_manager.PutCString(eDiagnosticSeverityError, "invalid process");
diagnostic_manager.PutString(eDiagnosticSeverityError, "invalid process");
return false;
}
@ -95,7 +94,7 @@ bool ClangUtilityFunction::Install(DiagnosticManager &diagnostic_manager,
ResetDeclMap(exe_ctx, keep_result_in_memory);
if (!DeclMap()->WillParse(exe_ctx, NULL)) {
diagnostic_manager.PutCString(
diagnostic_manager.PutString(
eDiagnosticSeverityError,
"current process state is unsuitable for expression parsing");
return false;
@ -159,8 +158,8 @@ bool ClangUtilityFunction::Install(DiagnosticManager &diagnostic_manager,
if (error_cstr && error_cstr[0]) {
diagnostic_manager.Printf(eDiagnosticSeverityError, "%s", error_cstr);
} else {
diagnostic_manager.PutCString(eDiagnosticSeverityError,
"expression can't be interpreted or run");
diagnostic_manager.PutString(eDiagnosticSeverityError,
"expression can't be interpreted or run");
}
return false;
}

View File

@ -216,7 +216,7 @@ bool GoUserExpression::Parse(DiagnosticManager &diagnostic_manager,
return true;
const char *error_cstr = m_interpreter->error().AsCString();
if (error_cstr && error_cstr[0])
diagnostic_manager.PutCString(eDiagnosticSeverityError, error_cstr);
diagnostic_manager.PutString(eDiagnosticSeverityError, error_cstr);
else
diagnostic_manager.Printf(eDiagnosticSeverityError,
"expression can't be interpreted or run");
@ -245,8 +245,8 @@ GoUserExpression::DoExecute(DiagnosticManager &diagnostic_manager,
log->Printf("== [GoUserExpression::Evaluate] Expression may not run, "
"but is not constant ==");
diagnostic_manager.PutCString(eDiagnosticSeverityError,
"expression needed to run but couldn't");
diagnostic_manager.PutString(eDiagnosticSeverityError,
"expression needed to run but couldn't");
return execution_results;
}
@ -260,10 +260,10 @@ GoUserExpression::DoExecute(DiagnosticManager &diagnostic_manager,
if (!result_val_sp) {
const char *error_cstr = err.AsCString();
if (error_cstr && error_cstr[0])
diagnostic_manager.PutCString(eDiagnosticSeverityError, error_cstr);
diagnostic_manager.PutString(eDiagnosticSeverityError, error_cstr);
else
diagnostic_manager.PutCString(eDiagnosticSeverityError,
"expression can't be interpreted or run");
diagnostic_manager.PutString(eDiagnosticSeverityError,
"expression can't be interpreted or run");
return lldb::eExpressionDiscarded;
}
result.reset(new ExpressionVariable(ExpressionVariable::eKindGo));

View File

@ -4815,29 +4815,29 @@ Process::RunThreadPlan(ExecutionContext &exe_ctx,
std::lock_guard<std::mutex> run_thread_plan_locker(m_run_thread_plan_lock);
if (!thread_plan_sp) {
diagnostic_manager.PutCString(
diagnostic_manager.PutString(
eDiagnosticSeverityError,
"RunThreadPlan called with empty thread plan.");
return eExpressionSetupError;
}
if (!thread_plan_sp->ValidatePlan(nullptr)) {
diagnostic_manager.PutCString(
diagnostic_manager.PutString(
eDiagnosticSeverityError,
"RunThreadPlan called with an invalid thread plan.");
return eExpressionSetupError;
}
if (exe_ctx.GetProcessPtr() != this) {
diagnostic_manager.PutCString(eDiagnosticSeverityError,
"RunThreadPlan called on wrong process.");
diagnostic_manager.PutString(eDiagnosticSeverityError,
"RunThreadPlan called on wrong process.");
return eExpressionSetupError;
}
Thread *thread = exe_ctx.GetThreadPtr();
if (thread == nullptr) {
diagnostic_manager.PutCString(eDiagnosticSeverityError,
"RunThreadPlan called with invalid thread.");
diagnostic_manager.PutString(eDiagnosticSeverityError,
"RunThreadPlan called with invalid thread.");
return eExpressionSetupError;
}
@ -4864,7 +4864,7 @@ Process::RunThreadPlan(ExecutionContext &exe_ctx,
thread_plan_sp->SetOkayToDiscard(false);
if (m_private_state.GetValue() != eStateStopped) {
diagnostic_manager.PutCString(
diagnostic_manager.PutString(
eDiagnosticSeverityError,
"RunThreadPlan called while the private state was not stopped.");
return eExpressionSetupError;
@ -5028,10 +5028,10 @@ Process::RunThreadPlan(ExecutionContext &exe_ctx,
uint64_t computed_one_thread_timeout;
if (option_one_thread_timeout != 0) {
if (timeout_usec < option_one_thread_timeout) {
diagnostic_manager.PutCString(eDiagnosticSeverityError,
"RunThreadPlan called without one "
"thread timeout greater than total "
"timeout");
diagnostic_manager.PutString(eDiagnosticSeverityError,
"RunThreadPlan called without one "
"thread timeout greater than total "
"timeout");
return eExpressionSetupError;
}
computed_one_thread_timeout = option_one_thread_timeout;
@ -5060,7 +5060,7 @@ Process::RunThreadPlan(ExecutionContext &exe_ctx,
Event *other_events = listener_sp->PeekAtNextEvent();
if (other_events != nullptr) {
diagnostic_manager.PutCString(
diagnostic_manager.PutString(
eDiagnosticSeverityError,
"RunThreadPlan called with pending events on the queue.");
return eExpressionSetupError;
@ -5237,9 +5237,8 @@ Process::RunThreadPlan(ExecutionContext &exe_ctx,
const bool use_run_lock = false;
Halt(clear_thread_plans, use_run_lock);
return_value = eExpressionInterrupted;
diagnostic_manager.PutCString(
eDiagnosticSeverityRemark,
"execution halted by user interrupt.");
diagnostic_manager.PutString(eDiagnosticSeverityRemark,
"execution halted by user interrupt.");
if (log)
log->Printf("Process::RunThreadPlan(): Got interrupted by "
"eBroadcastBitInterrupted, exiting.");
@ -5350,7 +5349,7 @@ Process::RunThreadPlan(ExecutionContext &exe_ctx,
if (stop_state == eStateExited)
event_to_broadcast_sp = event_sp;
diagnostic_manager.PutCString(
diagnostic_manager.PutString(
eDiagnosticSeverityError,
"execution stopped with unexpected state.");
return_value = eExpressionInterrupted;