#include "lldb/lldb-defines.h"
#include "lldb/lldb-types.h"
+#include "llvm/ADT/StringRef.h"
+
#include <string>
#include <vector>
}
}
- 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) {}
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);
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(
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);
}
}
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();
}
-//===-- FunctionCaller.cpp ---------------------------------------*- C++
-//-*-===//
+//===-- FunctionCaller.cpp ---------------------------------------*- C++-*-===//
//
// The LLVM Compiler Infrastructure
//
// 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;
}
// 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;
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;
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;
}
"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()) ||
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"
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;
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;
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());
}
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;
}
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());
}
////////////////////////////////////
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;
}
}
Target *target = exe_ctx.GetTargetPtr();
if (!target) {
- diagnostic_manager.PutCString(eDiagnosticSeverityError, "invalid target");
+ diagnostic_manager.PutString(eDiagnosticSeverityError, "invalid target");
return false;
}
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");
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;
}
}
"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;
}
}
} 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;
-//===-- ClangUserExpression.cpp -------------------------------------*- C++
-//-*-===//
+//===-- ClangUserExpression.cpp ----------------------------------*- C++-*-===//
//
// The LLVM Compiler Infrastructure
//
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;
}
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;
}
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;
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;
}
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");
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;
}
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));
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;
}
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;
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;
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;
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.");
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;