Skip to content

Commit b82e193

Browse files
committed
Factor out expression result error strings.
(cherry picked from commit b8f0ca0) Conflicts: lldb/source/Interpreter/CommandInterpreter.cpp
1 parent 2fc9188 commit b82e193

File tree

5 files changed

+68
-46
lines changed

5 files changed

+68
-46
lines changed
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
//===-- ErrorMessages.h -----------------------------------------*- C++ -*-===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
9+
#ifndef LLDB_UTILITY_ERROR_MESSAGES_H
10+
#define LLDB_UTILITY_ERROR_MESSAGES_H
11+
12+
#include "lldb/lldb-defines.h"
13+
#include "lldb/lldb-enumerations.h"
14+
#include <string>
15+
16+
namespace lldb_private {
17+
18+
/// Produce a human-readable rendition of an ExpressionResults value.
19+
std::string toString(lldb::ExpressionResults e);
20+
21+
} // namespace lldb_private
22+
#endif

lldb/source/Interpreter/CommandInterpreter.cpp

Lines changed: 3 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
#include "lldb/Core/Debugger.h"
4949
#include "lldb/Core/PluginManager.h"
5050
#include "lldb/Core/StreamFile.h"
51+
#include "lldb/Utility/ErrorMessages.h"
5152
#include "lldb/Utility/LLDBLog.h"
5253
#include "lldb/Utility/Log.h"
5354
#include "lldb/Utility/State.h"
@@ -1836,51 +1837,8 @@ CommandInterpreter::PreprocessToken(std::string &expr_str) {
18361837
error = expr_result_valobj_sp->GetError();
18371838

18381839
if (error.Success()) {
1839-
switch (expr_result) {
1840-
case eExpressionSetupError:
1841-
error.SetErrorStringWithFormat(
1842-
"expression setup error for the expression '%s'", expr_str.c_str());
1843-
break;
1844-
case eExpressionParseError:
1845-
error.SetErrorStringWithFormat(
1846-
"expression parse error for the expression '%s'", expr_str.c_str());
1847-
break;
1848-
case eExpressionResultUnavailable:
1849-
error.SetErrorStringWithFormat(
1850-
"expression error fetching result for the expression '%s'",
1851-
expr_str.c_str());
1852-
break;
1853-
case eExpressionCompleted:
1854-
break;
1855-
case eExpressionDiscarded:
1856-
error.SetErrorStringWithFormat(
1857-
"expression discarded for the expression '%s'", expr_str.c_str());
1858-
break;
1859-
case eExpressionInterrupted:
1860-
error.SetErrorStringWithFormat(
1861-
"expression interrupted for the expression '%s'", expr_str.c_str());
1862-
break;
1863-
case eExpressionHitBreakpoint:
1864-
error.SetErrorStringWithFormat(
1865-
"expression hit breakpoint for the expression '%s'",
1866-
expr_str.c_str());
1867-
break;
1868-
case eExpressionTimedOut:
1869-
error.SetErrorStringWithFormat(
1870-
"expression timed out for the expression '%s'", expr_str.c_str());
1871-
break;
1872-
case eExpressionStoppedForDebug:
1873-
error.SetErrorStringWithFormat("expression stop at entry point "
1874-
"for debugging for the "
1875-
"expression '%s'",
1876-
expr_str.c_str());
1877-
break;
1878-
case eExpressionThreadVanished:
1879-
error.SetErrorStringWithFormat(
1880-
"expression thread vanished for the expression '%s'",
1881-
expr_str.c_str());
1882-
break;
1883-
}
1840+
std::string result = lldb_private::toString(expr_result);
1841+
error.SetErrorString(result + "for the expression '" + expr_str + "'");
18841842
}
18851843
return error;
18861844
}

lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntime.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
#include "lldb/Target/Target.h"
3232
#include "lldb/Target/Thread.h"
3333
#include "lldb/Utility/ConstString.h"
34+
#include "lldb/Utility/ErrorMessages.h"
3435
#include "lldb/Utility/LLDBLog.h"
3536
#include "lldb/Utility/Log.h"
3637
#include "lldb/Utility/Scalar.h"
@@ -201,7 +202,7 @@ AppleObjCRuntime::GetObjectDescription(Stream &strm, Value &value,
201202
exe_ctx, &wrapper_struct_addr, options, diagnostics, ret);
202203
if (results != eExpressionCompleted)
203204
return llvm::createStringError(
204-
"Error evaluating Print Object function: %d.\n", results);
205+
"could not evaluate print object function: " + toString(results));
205206

206207
addr_t result_ptr = ret.GetScalar().ULongLong(LLDB_INVALID_ADDRESS);
207208

lldb/source/Utility/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ add_lldb_library(lldbUtility NO_INTERNAL_DEPENDENCIES
3838
DataExtractor.cpp
3939
Diagnostics.cpp
4040
Environment.cpp
41+
ErrorMessages.cpp
4142
Event.cpp
4243
FileSpec.cpp
4344
FileSpecList.cpp

lldb/source/Utility/ErrorMessages.cpp

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
//===-- ErrorMessages.cpp -------------------------------------------------===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
9+
#include "lldb/Utility/ErrorMessages.h"
10+
#include "llvm/Support/ErrorHandling.h"
11+
12+
namespace lldb_private {
13+
14+
std::string toString(lldb::ExpressionResults e) {
15+
switch (e) {
16+
case lldb::eExpressionSetupError:
17+
return "expression setup error";
18+
case lldb::eExpressionParseError:
19+
return "expression parse error";
20+
case lldb::eExpressionResultUnavailable:
21+
return "expression error";
22+
case lldb::eExpressionCompleted:
23+
return "expression completed successfully";
24+
case lldb::eExpressionDiscarded:
25+
return "expression discarded";
26+
case lldb::eExpressionInterrupted:
27+
return "expression interrupted";
28+
case lldb::eExpressionHitBreakpoint:
29+
return "expression hit breakpoint";
30+
case lldb::eExpressionTimedOut:
31+
return "expression timed out";
32+
case lldb::eExpressionStoppedForDebug:
33+
return "expression stop at entry point for debugging";
34+
case lldb::eExpressionThreadVanished:
35+
return "expression thread vanished";
36+
}
37+
llvm_unreachable("unhandled enumerator");
38+
}
39+
40+
} // namespace lldb_private

0 commit comments

Comments
 (0)