Skip to content

Commit b8f0ca0

Browse files
committed
Factor out expression result error strings.
1 parent f900644 commit b8f0ca0

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/Host/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"
@@ -1817,51 +1818,8 @@ CommandInterpreter::PreprocessToken(std::string &expr_str) {
18171818
error = expr_result_valobj_sp->GetError();
18181819

18191820
if (error.Success()) {
1820-
switch (expr_result) {
1821-
case eExpressionSetupError:
1822-
error.SetErrorStringWithFormat(
1823-
"expression setup error for the expression '%s'", expr_str.c_str());
1824-
break;
1825-
case eExpressionParseError:
1826-
error.SetErrorStringWithFormat(
1827-
"expression parse error for the expression '%s'", expr_str.c_str());
1828-
break;
1829-
case eExpressionResultUnavailable:
1830-
error.SetErrorStringWithFormat(
1831-
"expression error fetching result for the expression '%s'",
1832-
expr_str.c_str());
1833-
break;
1834-
case eExpressionCompleted:
1835-
break;
1836-
case eExpressionDiscarded:
1837-
error.SetErrorStringWithFormat(
1838-
"expression discarded for the expression '%s'", expr_str.c_str());
1839-
break;
1840-
case eExpressionInterrupted:
1841-
error.SetErrorStringWithFormat(
1842-
"expression interrupted for the expression '%s'", expr_str.c_str());
1843-
break;
1844-
case eExpressionHitBreakpoint:
1845-
error.SetErrorStringWithFormat(
1846-
"expression hit breakpoint for the expression '%s'",
1847-
expr_str.c_str());
1848-
break;
1849-
case eExpressionTimedOut:
1850-
error.SetErrorStringWithFormat(
1851-
"expression timed out for the expression '%s'", expr_str.c_str());
1852-
break;
1853-
case eExpressionStoppedForDebug:
1854-
error.SetErrorStringWithFormat("expression stop at entry point "
1855-
"for debugging for the "
1856-
"expression '%s'",
1857-
expr_str.c_str());
1858-
break;
1859-
case eExpressionThreadVanished:
1860-
error.SetErrorStringWithFormat(
1861-
"expression thread vanished for the expression '%s'",
1862-
expr_str.c_str());
1863-
break;
1864-
}
1821+
std::string result = lldb_private::toString(expr_result);
1822+
error.SetErrorString(result + "for the expression '" + expr_str + "'");
18651823
}
18661824
return error;
18671825
}

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
@@ -39,6 +39,7 @@ add_lldb_library(lldbUtility NO_INTERNAL_DEPENDENCIES
3939
DataExtractor.cpp
4040
Diagnostics.cpp
4141
Environment.cpp
42+
ErrorMessages.cpp
4243
Event.cpp
4344
FileSpec.cpp
4445
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)