Skip to content

Commit b0a2868

Browse files
authored
Merge pull request #35 from access-softek/dil-local-vars-2
Update code to made upstream local variables PR.
2 parents 28ec8f5 + 6b0c3e7 commit b0a2868

File tree

8 files changed

+496
-590
lines changed

8 files changed

+496
-590
lines changed

lldb/include/lldb/ValueObject/DILAST.h

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
#include "llvm/ADT/APFloat.h"
1919
#include "llvm/ADT/APInt.h"
2020
#include "llvm/Support/Casting.h"
21+
#include "llvm/Support/Error.h"
22+
#include <cstdint>
2123
#include <memory>
2224
#include <optional>
2325
#include <string>
@@ -280,12 +282,11 @@ class StringLiteralNode : public ASTNode {
280282
class IdentifierNode : public ASTNode {
281283
public:
282284
IdentifierNode(uint32_t location, std::string name,
283-
lldb::DynamicValueType use_dynamic,
284285
std::unique_ptr<IdentifierInfo> identifier, bool is_rvalue,
285286
bool is_context_var)
286287
: ASTNode(location, NodeKind::eIdentifierNode), m_is_rvalue(is_rvalue),
287288
m_is_context_var(is_context_var), m_name(std::move(name)),
288-
m_identifier(std::move(identifier)), m_use_dynamic(use_dynamic) {}
289+
m_identifier(std::move(identifier)) {}
289290

290291
llvm::Expected<lldb::ValueObjectSP> Accept(Visitor *v) const override;
291292
bool is_rvalue() const override { return m_is_rvalue; }
@@ -297,7 +298,6 @@ class IdentifierNode : public ASTNode {
297298
return m_identifier->GetValue().get();
298299
}
299300

300-
lldb::DynamicValueType GetUseDynamic() const { return m_use_dynamic; }
301301
std::string GetName() const { return m_name; }
302302
const IdentifierInfo &info() const { return *m_identifier; }
303303

@@ -310,7 +310,6 @@ class IdentifierNode : public ASTNode {
310310
bool m_is_context_var;
311311
std::string m_name;
312312
std::unique_ptr<IdentifierInfo> m_identifier;
313-
lldb::DynamicValueType m_use_dynamic;
314313
};
315314

316315
class SizeOfNode : public ASTNode {

lldb/include/lldb/ValueObject/DILEval.h

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111

1212
#include "lldb/ValueObject/DILAST.h"
1313
#include "lldb/ValueObject/DILParser.h"
14+
#include "llvm/ADT/StringRef.h"
15+
#include "llvm/Support/Error.h"
1416
#include <memory>
1517
#include <vector>
1618

@@ -54,15 +56,14 @@ class Interpreter : Visitor {
5456
lldb::DynamicValueType use_dynamic,
5557
std::shared_ptr<StackFrame> frame_sp);
5658

57-
llvm::Expected<lldb::ValueObjectSP> DILEval(const ASTNode *tree,
58-
lldb::TargetSP target_sp);
59+
llvm::Expected<lldb::ValueObjectSP> Evaluate(const ASTNode *tree);
5960

6061
void SetContextVars(
6162
std::unordered_map<std::string, lldb::ValueObjectSP> context_vars);
6263

6364
protected:
64-
llvm::Expected<lldb::ValueObjectSP>
65-
DILEvalNode(const ASTNode *node, FlowAnalysis *flow = nullptr);
65+
llvm::Expected<lldb::ValueObjectSP> EvalNode(const ASTNode *node,
66+
FlowAnalysis *flow = nullptr);
6667

6768
lldb::ValueObjectSP EvaluateMemberOf(lldb::ValueObjectSP value,
6869
const std::vector<uint32_t> &path,

lldb/include/lldb/ValueObject/DILParser.h

Lines changed: 33 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,16 @@
1010
#define LLDB_VALUEOBJECT_DILPARSER_H
1111

1212
#include "lldb/Target/ExecutionContextScope.h"
13+
#include "lldb/Utility/DiagnosticsRendering.h"
1314
#include "lldb/Utility/Status.h"
1415
#include "lldb/ValueObject/DILAST.h"
1516
#include "lldb/ValueObject/DILLexer.h"
1617
#include "lldb/ValueObject/DILLiteralParsers.h"
18+
#include "llvm/Support/Error.h"
1719
#include <memory>
1820
#include <optional>
1921
#include <string>
22+
#include <system_error>
2023
#include <tuple>
2124
#include <vector>
2225

@@ -69,8 +72,30 @@ enum class ErrorCode : unsigned char {
6972
kUnknown,
7073
};
7174

72-
std::string FormatDiagnostics(llvm::StringRef input_expr,
73-
const std::string &message, uint32_t loc);
75+
// The following is modeled on class OptionParseError.
76+
class DILDiagnosticError
77+
: public llvm::ErrorInfo<DILDiagnosticError, DiagnosticError> {
78+
DiagnosticDetail m_detail;
79+
80+
public:
81+
using llvm::ErrorInfo<DILDiagnosticError, DiagnosticError>::ErrorInfo;
82+
DILDiagnosticError(DiagnosticDetail detail)
83+
: ErrorInfo(make_error_code(std::errc::invalid_argument)),
84+
m_detail(std::move(detail)) {}
85+
86+
DILDiagnosticError(llvm::StringRef expr, const std::string &message,
87+
uint32_t loc, uint16_t err_len);
88+
89+
std::unique_ptr<CloneableError> Clone() const override {
90+
return std::make_unique<DILDiagnosticError>(m_detail);
91+
}
92+
93+
llvm::ArrayRef<DiagnosticDetail> GetDetails() const override {
94+
return {m_detail};
95+
}
96+
97+
std::string message() const override { return m_detail.rendered; }
98+
};
7499

75100
Status SetUbStatus(ErrorCode code);
76101

@@ -170,9 +195,9 @@ class DILParser {
170195
std::shared_ptr<StackFrame> frame_sp,
171196
lldb::DynamicValueType use_dynamic, bool use_synthetic,
172197
bool fragile_ivar, bool check_ptr_vs_member,
173-
Status &error);
198+
llvm::Error &error);
174199

175-
llvm::Expected<ASTNodeUP> Run();
200+
ASTNodeUP Run();
176201

177202
ASTNodeUP ParseExpression();
178203
ASTNodeUP ParseAssignmentExpression();
@@ -227,9 +252,7 @@ class DILParser {
227252
bool is_src_literal_zero = false);
228253
ASTNodeUP InsertImplicitConversion(ASTNodeUP expr, CompilerType type);
229254

230-
void BailOut(ErrorCode error_code, const std::string &error, uint32_t loc);
231-
232-
void BailOut(Status error);
255+
void BailOut(const std::string &error, uint32_t loc, uint16_t err_len);
233256

234257
void Expect(Token::Kind kind);
235258

@@ -297,7 +320,8 @@ class DILParser {
297320
}
298321

299322
void TentativeParsingRollback(uint32_t saved_idx) {
300-
m_error.Clear();
323+
if (m_error)
324+
llvm::consumeError(std::move(m_error));
301325
m_dil_lexer.ResetTokenIdx(saved_idx);
302326
}
303327

@@ -312,7 +336,7 @@ class DILParser {
312336

313337
DILLexer m_dil_lexer;
314338
// Holds an error if it occures during parsing.
315-
Status &m_error;
339+
llvm::Error &m_error;
316340

317341
bool m_allow_side_effects = true;
318342

lldb/source/Target/StackFrame.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -558,7 +558,7 @@ ValueObjectSP StackFrame::DILGetValueForVariableExpressionPath(
558558
dil::Interpreter interpreter(target, var_expr, use_dynamic,
559559
shared_from_this());
560560

561-
auto valobj_or_error = interpreter.DILEval((*tree_or_error).get(), target);
561+
auto valobj_or_error = interpreter.Evaluate((*tree_or_error).get());
562562
if (!valobj_or_error) {
563563
error = Status::FromError(valobj_or_error.takeError());
564564
return ValueObjectSP();

0 commit comments

Comments
 (0)