Skip to content

Commit dae9cb9

Browse files
committed
apply lldb-wasm.patch from wamr
wamr commit b75ae3363da4da7039faec62decd14b6b07f666e
1 parent 75e33f7 commit dae9cb9

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

55 files changed

+3440
-1782
lines changed

lldb/include/lldb/Core/Module.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141

4242
namespace lldb_private {
4343
class CompilerDeclContext;
44+
class DWARFEvaluatorFactory;
4445
class Function;
4546
class Log;
4647
class ObjectFile;
@@ -859,6 +860,8 @@ class Module : public std::enable_shared_from_this<Module>,
859860
/// Update the ArchSpec to a more specific variant.
860861
bool MergeArchitecture(const ArchSpec &arch_spec);
861862

863+
DWARFEvaluatorFactory *GetDWARFExpressionEvaluatorFactory();
864+
862865
/// \class LookupInfo Module.h "lldb/Core/Module.h"
863866
/// A class that encapsulates name lookup information.
864867
///
@@ -985,6 +988,8 @@ class Module : public std::enable_shared_from_this<Module>,
985988
m_first_file_changed_log : 1; /// See if the module was modified after it
986989
/// was initially opened.
987990

991+
std::unique_ptr<DWARFEvaluatorFactory> m_dwarf_evaluator_factory;
992+
988993
/// Resolve a file or load virtual address.
989994
///
990995
/// Tries to resolve \a vm_addr as a file address (if \a

lldb/include/lldb/Core/PluginManager.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -508,6 +508,17 @@ class PluginManager {
508508
static bool CreateSettingForStructuredDataPlugin(
509509
Debugger &debugger, const lldb::OptionValuePropertiesSP &properties_sp,
510510
ConstString description, bool is_global_property);
511+
512+
// DWARFEvaluatorFactory
513+
static bool
514+
RegisterPlugin(ConstString name, const char *description,
515+
DWARFEvaluatorFactoryCreateInstance create_callback);
516+
517+
static bool
518+
UnregisterPlugin(DWARFEvaluatorFactoryCreateInstance create_callback);
519+
520+
static DWARFEvaluatorFactoryCreateInstance
521+
GetDWARFEvaluatorFactoryCreateCallbackAtIndex(uint32_t idx);
511522
};
512523

513524
} // namespace lldb_private
Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
//===-- DWARFEvaluator.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_EXPRESSION_DWARFEVALUATOR_H
10+
#define LLDB_EXPRESSION_DWARFEVALUATOR_H
11+
12+
#include "lldb/lldb-private.h"
13+
#include <vector>
14+
15+
namespace lldb_private {
16+
17+
class DWARFExpression;
18+
19+
/// \class DWARFEvaluator DWARFEvaluator.h
20+
/// "lldb/Expression/DWARFEvaluator.h" Evaluates DWARF opcodes.
21+
///
22+
class DWARFEvaluator {
23+
public:
24+
/// Crates a DWARF location expression evaluator
25+
///
26+
/// \param[in] dwarf_expression
27+
/// The DWARF expression to evaluate.
28+
///
29+
/// \param[in] exe_ctx
30+
/// The execution context in which to evaluate the location
31+
/// expression. The location expression may access the target's
32+
/// memory, especially if it comes from the expression parser.
33+
///
34+
/// \param[in] reg_ctx
35+
/// An optional parameter which provides a RegisterContext for use
36+
/// when evaluating the expression (i.e. for fetching register values).
37+
/// Normally this will come from the ExecutionContext's StackFrame but
38+
/// in the case where an expression needs to be evaluated while building
39+
/// the stack frame list, this short-cut is available.
40+
///
41+
/// \param[in] initial_value_ptr
42+
/// A value to put on top of the interpreter stack before evaluating
43+
/// the expression, if the expression is parametrized. Can be NULL.
44+
///
45+
/// \param[in] object_address_ptr
46+
///
47+
DWARFEvaluator(const DWARFExpression &dwarf_expression,
48+
ExecutionContext *exe_ctx, RegisterContext *reg_ctx,
49+
const Value *initial_value_ptr,
50+
const Value *object_address_ptr);
51+
52+
/// DWARFEvaluator protocol.
53+
/// \{
54+
55+
/// Evaluate the DWARF location expression
56+
///
57+
/// \param[in] result
58+
/// A value into which the result of evaluating the expression is
59+
/// to be placed.
60+
///
61+
/// \param[in] error_ptr
62+
/// If non-NULL, used to report errors in expression evaluation.
63+
///
64+
/// \return
65+
/// True on success; false otherwise. If error_ptr is non-NULL,
66+
/// details of the failure are provided through it.
67+
virtual bool Evaluate(Value &result, Status *error_ptr);
68+
69+
/// Evaluate the DWARF location expression with the opcodes specified.
70+
///
71+
/// \param[in] opcodes
72+
/// The DWARF opcodes to evaluate.
73+
///
74+
/// \param[in] result
75+
/// A value into which the result of evaluating the expression is
76+
/// to be placed.
77+
///
78+
/// \param[in] error_ptr
79+
/// If non-NULL, used to report errors in expression evaluation.
80+
///
81+
/// \return
82+
/// True on success; false otherwise. If error_ptr is non-NULL,
83+
/// details of the failure are provided through it.
84+
virtual bool Evaluate(const DataExtractor &opcodes, Value &result,
85+
Status *error_ptr);
86+
87+
/// Evaluates a specific DWARF opcode in the context of a DWARF expression
88+
virtual bool Evaluate(const uint8_t op, Process *process, StackFrame *frame,
89+
std::vector<Value> &stack, const DataExtractor &opcodes,
90+
lldb::offset_t &offset, Value &pieces,
91+
uint64_t &op_piece_offset, Log *log, Status *error_ptr);
92+
93+
/// \}
94+
95+
protected:
96+
const DWARFExpression &m_dwarf_expression;
97+
ExecutionContext *m_exe_ctx;
98+
RegisterContext *m_reg_ctx;
99+
const Value *m_initial_value_ptr;
100+
const Value *m_object_address_ptr;
101+
102+
private:
103+
DWARFEvaluator(const DWARFEvaluator &);
104+
const DWARFEvaluator &operator=(const DWARFEvaluator &) = delete;
105+
106+
};
107+
108+
} // namespace lldb_private
109+
110+
#endif // LLDB_EXPRESSION_DWARFEVALUATOR_H
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
//===-- DWARFEvaluatorFactory.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_EXPRESSION_DWARFEVALUATORFACTORY_H
10+
#define LLDB_EXPRESSION_DWARFEVALUATORFACTORY_H
11+
12+
#include "lldb/Core/PluginInterface.h"
13+
#include "lldb/Utility/ConstString.h"
14+
#include "lldb/lldb-private.h"
15+
16+
class DWARFUnit;
17+
18+
namespace lldb_private {
19+
20+
class DWARFEvaluator;
21+
class DWARFExpression;
22+
23+
/// \class DWARFEvaluatorFactory DWARFEvaluatorFactory.h
24+
/// "lldb/Expression/DWARFEvaluatorFactory.h" Factory class that allows the
25+
/// registration of platform-specific DWARF expression evaluators, used to
26+
/// handle platform-specific DWARF opcodes.
27+
class DWARFEvaluatorFactory : public PluginInterface {
28+
public:
29+
static std::unique_ptr<DWARFEvaluatorFactory> FindPlugin(Module *module);
30+
31+
/// PluginInterface protocol.
32+
/// \{
33+
ConstString GetPluginName() override;
34+
35+
uint32_t GetPluginVersion() override { return 1; }
36+
/// \}
37+
38+
DWARFEvaluatorFactory() {}
39+
40+
/// DWARFEvaluatorFactory protocol.
41+
/// \{
42+
virtual std::unique_ptr<DWARFEvaluator>
43+
CreateDWARFEvaluator(const DWARFExpression &dwarf_expression,
44+
ExecutionContext *exe_ctx, RegisterContext *reg_ctx,
45+
const Value *initial_value_ptr,
46+
const Value *object_address_ptr);
47+
/// \}
48+
49+
private:
50+
DWARFEvaluatorFactory(const DWARFEvaluatorFactory &);
51+
const DWARFEvaluatorFactory &operator=(const DWARFEvaluatorFactory &) = delete;
52+
};
53+
54+
} // namespace lldb_private
55+
56+
#endif // LLDB_EXPRESSION_DWARFEVALUATORFACTORY_H

lldb/include/lldb/Expression/DWARFExpression.h

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,10 @@ class DWARFExpression {
120120

121121
void SetModule(const lldb::ModuleSP &module) { m_module_wp = module; }
122122

123+
lldb::ModuleSP GetModule() const { return m_module_wp.lock(); }
124+
125+
const DWARFUnit *GetDWARFCompileUnit() const { return m_dwarf_cu; }
126+
123127
bool ContainsThreadLocalStorage() const;
124128

125129
bool LinkThreadLocalStorage(
@@ -140,7 +144,7 @@ class DWARFExpression {
140144
lldb::addr_t func_file_addr);
141145

142146
/// Return the call-frame-info style register kind
143-
int GetRegisterKind();
147+
lldb::RegisterKind GetRegisterKind() const;
144148

145149
/// Set the call-frame-info style register kind
146150
///
@@ -219,6 +223,9 @@ class DWARFExpression {
219223

220224
bool MatchesOperand(StackFrame &frame, const Instruction::Operand &op);
221225

226+
static lldb::addr_t ReadAddressFromDebugAddrSection(const DWARFUnit *dwarf_cu,
227+
uint32_t index);
228+
222229
llvm::Optional<DataExtractor>
223230
GetLocationExpression(lldb::addr_t load_function_start,
224231
lldb::addr_t addr) const;

lldb/include/lldb/Target/Process.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1434,7 +1434,7 @@ class Process : public std::enable_shared_from_this<Process>,
14341434
/// vm_addr, \a buf, and \a size updated appropriately. Zero is
14351435
/// returned in the case of an error.
14361436
virtual size_t ReadMemory(lldb::addr_t vm_addr, void *buf, size_t size,
1437-
Status &error);
1437+
Status &error, ExecutionContext *exe_ctx = nullptr);
14381438

14391439
/// Read of memory from a process.
14401440
///

lldb/include/lldb/Target/ProcessTrace.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ class ProcessTrace : public PostMortemProcess {
5959
bool WarnBeforeDetach() const override { return false; }
6060

6161
size_t ReadMemory(lldb::addr_t addr, void *buf, size_t size,
62-
Status &error) override;
62+
Status &error, ExecutionContext *exe_ctx = nullptr) override;
6363

6464
size_t DoReadMemory(lldb::addr_t addr, void *buf, size_t size,
6565
Status &error) override;

lldb/include/lldb/lldb-forward.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ class Disassembler;
7474
class DumpValueObjectOptions;
7575
class DynamicCheckerFunctions;
7676
class DynamicLoader;
77+
class DWARFEvaluatorFactory;
7778
class Editline;
7879
class EmulateInstruction;
7980
class Environment;

lldb/include/lldb/lldb-private-interfaces.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,8 @@ typedef lldb::REPLSP (*REPLCreateInstance)(Status &error,
113113
const char *repl_options);
114114
typedef int (*ComparisonFunction)(const void *, const void *);
115115
typedef void (*DebuggerInitializeCallback)(Debugger &debugger);
116+
typedef DWARFEvaluatorFactory *(*DWARFEvaluatorFactoryCreateInstance)(
117+
Module *module);
116118
/// Trace
117119
/// \{
118120
typedef llvm::Expected<lldb::TraceSP> (*TraceCreateInstanceForSessionFile)(

lldb/source/Core/Module.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#include "lldb/Core/ModuleSpec.h"
1717
#include "lldb/Core/SearchFilter.h"
1818
#include "lldb/Core/Section.h"
19+
#include "lldb/Expression/DWARFEvaluatorFactory.h"
1920
#include "lldb/Host/FileSystem.h"
2021
#include "lldb/Host/Host.h"
2122
#include "lldb/Host/HostInfo.h"
@@ -1659,3 +1660,9 @@ bool Module::GetIsDynamicLinkEditor() {
16591660

16601661
return false;
16611662
}
1663+
1664+
DWARFEvaluatorFactory *Module::GetDWARFExpressionEvaluatorFactory() {
1665+
if (!m_dwarf_evaluator_factory)
1666+
m_dwarf_evaluator_factory = DWARFEvaluatorFactory::FindPlugin(this);
1667+
return m_dwarf_evaluator_factory.get();
1668+
}

0 commit comments

Comments
 (0)