[Lldb-commits] [lldb] r286730 - Make DiagnosticsManager functions take StringRefs.
Zachary Turner via lldb-commits
lldb-commits at lists.llvm.org
Sat Nov 12 11:12:57 PST 2016
Author: zturner
Date: Sat Nov 12 13:12:56 2016
New Revision: 286730
URL: http://llvm.org/viewvc/llvm-project?rev=286730&view=rev
Log:
Make DiagnosticsManager functions take StringRefs.
Modified:
lldb/trunk/include/lldb/Expression/DiagnosticManager.h
lldb/trunk/source/Expression/DiagnosticManager.cpp
lldb/trunk/source/Expression/FunctionCaller.cpp
lldb/trunk/source/Expression/LLVMUserExpression.cpp
lldb/trunk/source/Plugins/ExpressionParser/Clang/ClangExpressionParser.cpp
lldb/trunk/source/Plugins/ExpressionParser/Clang/ClangFunctionCaller.cpp
lldb/trunk/source/Plugins/ExpressionParser/Clang/ClangUserExpression.cpp
lldb/trunk/source/Plugins/ExpressionParser/Clang/ClangUtilityFunction.cpp
lldb/trunk/source/Plugins/ExpressionParser/Go/GoUserExpression.cpp
lldb/trunk/source/Target/Process.cpp
Modified: lldb/trunk/include/lldb/Expression/DiagnosticManager.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Expression/DiagnosticManager.h?rev=286730&r1=286729&r2=286730&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Expression/DiagnosticManager.h (original)
+++ lldb/trunk/include/lldb/Expression/DiagnosticManager.h Sat Nov 12 13:12:56 2016
@@ -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);
}
}
Modified: lldb/trunk/source/Expression/DiagnosticManager.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Expression/DiagnosticManager.cpp?rev=286730&r1=286729&r2=286730&view=diff
==============================================================================
--- lldb/trunk/source/Expression/DiagnosticManager.cpp (original)
+++ lldb/trunk/source/Expression/DiagnosticManager.cpp Sat Nov 12 13:12:56 2016
@@ -67,15 +67,15 @@ size_t DiagnosticManager::Printf(Diagnos
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();
}
Modified: lldb/trunk/source/Expression/FunctionCaller.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Expression/FunctionCaller.cpp?rev=286730&r1=286729&r2=286730&view=diff
==============================================================================
--- lldb/trunk/source/Expression/FunctionCaller.cpp (original)
+++ lldb/trunk/source/Expression/FunctionCaller.cpp Sat Nov 12 13:12:56 2016
@@ -1,5 +1,4 @@
-//===-- FunctionCaller.cpp ---------------------------------------*- C++
-//-*-===//
+//===-- FunctionCaller.cpp ---------------------------------------*- C++-*-===//
//
// The LLVM Compiler Infrastructure
//
@@ -130,9 +129,9 @@ bool FunctionCaller::WriteFunctionArgume
// 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::GetTh
// 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;
Modified: lldb/trunk/source/Expression/LLVMUserExpression.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Expression/LLVMUserExpression.cpp?rev=286730&r1=286729&r2=286730&view=diff
==============================================================================
--- lldb/trunk/source/Expression/LLVMUserExpression.cpp (original)
+++ lldb/trunk/source/Expression/LLVMUserExpression.cpp Sat Nov 12 13:12:56 2016
@@ -97,7 +97,7 @@ LLVMUserExpression::DoExecute(Diagnostic
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(Diagnostic
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(Diagnostic
"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(Diagnostic
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(Diagnostic
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::PrepareToExecut
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;
Modified: lldb/trunk/source/Plugins/ExpressionParser/Clang/ClangExpressionParser.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/ExpressionParser/Clang/ClangExpressionParser.cpp?rev=286730&r1=286729&r2=286730&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/ExpressionParser/Clang/ClangExpressionParser.cpp (original)
+++ lldb/trunk/source/Plugins/ExpressionParser/Clang/ClangExpressionParser.cpp Sat Nov 12 13:12:56 2016
@@ -624,8 +624,8 @@ unsigned ClangExpressionParser::Parse(Di
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());
}
Modified: lldb/trunk/source/Plugins/ExpressionParser/Clang/ClangFunctionCaller.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/ExpressionParser/Clang/ClangFunctionCaller.cpp?rev=286730&r1=286729&r2=286730&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/ExpressionParser/Clang/ClangFunctionCaller.cpp (original)
+++ lldb/trunk/source/Plugins/ExpressionParser/Clang/ClangFunctionCaller.cpp Sat Nov 12 13:12:56 2016
@@ -203,8 +203,8 @@ ClangFunctionCaller::CompileFunction(lld
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;
}
Modified: lldb/trunk/source/Plugins/ExpressionParser/Clang/ClangUserExpression.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/ExpressionParser/Clang/ClangUserExpression.cpp?rev=286730&r1=286729&r2=286730&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/ExpressionParser/Clang/ClangUserExpression.cpp (original)
+++ lldb/trunk/source/Plugins/ExpressionParser/Clang/ClangUserExpression.cpp Sat Nov 12 13:12:56 2016
@@ -325,21 +325,21 @@ bool ClangUserExpression::Parse(Diagnost
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(Diagnost
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(Diagnost
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(Diagnost
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(Diagnost
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(Diagnost
"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(E
} 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;
Modified: lldb/trunk/source/Plugins/ExpressionParser/Clang/ClangUtilityFunction.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/ExpressionParser/Clang/ClangUtilityFunction.cpp?rev=286730&r1=286729&r2=286730&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/ExpressionParser/Clang/ClangUtilityFunction.cpp (original)
+++ lldb/trunk/source/Plugins/ExpressionParser/Clang/ClangUtilityFunction.cpp Sat Nov 12 13:12:56 2016
@@ -1,5 +1,4 @@
-//===-- ClangUserExpression.cpp -------------------------------------*- C++
-//-*-===//
+//===-- ClangUserExpression.cpp ----------------------------------*- C++-*-===//
//
// The LLVM Compiler Infrastructure
//
@@ -63,8 +62,8 @@ ClangUtilityFunction::~ClangUtilityFunct
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(Diagn
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(Diagn
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(Diagn
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;
}
Modified: lldb/trunk/source/Plugins/ExpressionParser/Go/GoUserExpression.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/ExpressionParser/Go/GoUserExpression.cpp?rev=286730&r1=286729&r2=286730&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/ExpressionParser/Go/GoUserExpression.cpp (original)
+++ lldb/trunk/source/Plugins/ExpressionParser/Go/GoUserExpression.cpp Sat Nov 12 13:12:56 2016
@@ -216,7 +216,7 @@ bool GoUserExpression::Parse(DiagnosticM
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(DiagnosticMa
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(DiagnosticMa
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));
Modified: lldb/trunk/source/Target/Process.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Target/Process.cpp?rev=286730&r1=286729&r2=286730&view=diff
==============================================================================
--- lldb/trunk/source/Target/Process.cpp (original)
+++ lldb/trunk/source/Target/Process.cpp Sat Nov 12 13:12:56 2016
@@ -4815,29 +4815,29 @@ Process::RunThreadPlan(ExecutionContext
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
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
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
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
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
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;
More information about the lldb-commits
mailing list