| // Copyright 2018 The Fuchsia Authors. All rights reserved. | |
| // Use of this source code is governed by a BSD-style license that can be | |
| // found in the LICENSE file. | |
| #ifndef SRC_DEVELOPER_DEBUG_ZXDB_EXPR_EVAL_CONTEXT_H_ | |
| #define SRC_DEVELOPER_DEBUG_ZXDB_EXPR_EVAL_CONTEXT_H_ | |
| #include "lib/fit/function.h" | |
| #include "src/developer/debug/zxdb/expr/eval_callback.h" | |
| #include "src/developer/debug/zxdb/expr/expr_language.h" | |
| #include "src/developer/debug/zxdb/expr/expr_value.h" | |
| #include "src/developer/debug/zxdb/expr/name_lookup.h" | |
| #include "src/developer/debug/zxdb/expr/parsed_identifier.h" | |
| #include "src/developer/debug/zxdb/expr/resolve_type.h" | |
| #include "src/developer/debug/zxdb/expr/vector_register_format.h" | |
| #include "src/developer/debug/zxdb/symbols/location.h" | |
| #include "src/developer/debug/zxdb/symbols/symbol_data_provider.h" | |
| #include "src/lib/fxl/memory/ref_counted.h" | |
| namespace zxdb { | |
| class Err; | |
| class PrettyTypeManager; | |
| class Symbol; | |
| class SymbolDataProvider; | |
| class Value; | |
| class Variable; | |
| // Interface used by expression evaluation to communicate with the outside world. This provides | |
| // access to the variables currently in scope. | |
| // | |
| // PASSING CONVENTION | |
| // | |
| // Prefer to pass EvalContext function parameters as: | |
| // const fxl::RefPtr<EvalContext>& context | |
| // The advantage is that this will avoid an atomic refcount in most cases, but still is | |
| // automatically ref-ed when bound in a lambda. | |
| class EvalContext : public fxl::RefCountedThreadSafe<EvalContext> { | |
| public: | |
| // Returns the language associated with the expression. | |
| virtual ExprLanguage GetLanguage() const = 0; | |
| // Returns a context for looking up names. | |
| virtual FindNameContext GetFindNameContext() const = 0; | |
| // Issues the callback with the value of the given named value in the context of the current | |
| // expression evaluation. This will handle things like implicit |this| members in addition to | |
| // normal local variables. | |
| // | |
| // The callback also returns the Symbol associated with the variable it found. This can be used | |
| // for diagnostics. It is possible for the symbol to be valid but the err to be set if the symbol | |
| // was found but it could not be evaluated. | |
| // | |
| // The callback may be issued asynchronously in the future if communication with the remote | |
| // debugged application is required. The callback may be issued reentrantly for synchronously | |
| // available data. | |
| // | |
| // If the EvalContext is destroyed before the data is ready, the callback will not be issued. | |
| virtual void GetNamedValue(const ParsedIdentifier& identifier, EvalCallback cb) const = 0; | |
| // Like GetNamedValue() but takes an already-identified Variable. | |
| // | |
| // This will handle extern variables and will resolve them. In this case the EvalCallback's | |
| // variable will be the resolved extern one. Otherwise it will be the input Value. | |
| // | |
| // The value is normally a Variable but it can also be an extern DataMember (which will transform | |
| // into a Variable when the extern is resolved). | |
| virtual void GetVariableValue(fxl::RefPtr<Value> variable, EvalCallback cb) const = 0; | |
| // Convenience wrapper around the toplevel GetConcreteType() that uses the FindNameContext() | |
| // from this class. | |
| inline fxl::RefPtr<Type> GetConcreteType(const Type* type) const { | |
| return zxdb::GetConcreteType(GetFindNameContext(), type); | |
| } | |
| // May return null (ProcessSymbols are destroyed with the process, and the EvalContext is | |
| // refcounted and can outlive it). | |
| virtual const ProcessSymbols* GetProcessSymbols() const = 0; | |
| virtual fxl::RefPtr<SymbolDataProvider> GetDataProvider() = 0; | |
| // Returns a callback the parser can use to lookup names. | |
| // | |
| // It is assumed this callback is used for parsing and discarded rather than stored since it may | |
| // have references back the eval context. | |
| virtual NameLookupCallback GetSymbolNameLookupCallback() = 0; | |
| // Returns a symbolized (if possible) location for the given address. | |
| virtual Location GetLocationForAddress(uint64_t address) const = 0; | |
| virtual const PrettyTypeManager& GetPrettyTypeManager() const = 0; | |
| // Returns the format to be used for converting vector registers to values. | |
| virtual VectorRegisterFormat GetVectorRegisterFormat() const = 0; | |
| // Returns true if base classes should automatically be promoted to derived classes when pointer | |
| // and references are dereferences. | |
| virtual bool ShouldPromoteToDerived() const = 0; | |
| protected: | |
| // Only RefPtr should be destructing this class. | |
| FRIEND_REF_COUNTED_THREAD_SAFE(EvalContext); | |
| virtual ~EvalContext() = default; | |
| }; | |
| } // namespace zxdb | |
| #endif // SRC_DEVELOPER_DEBUG_ZXDB_EXPR_EVAL_CONTEXT_H_ |