• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /**
2  * Copyright (c) 2024 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  * http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #ifndef PANDA_TOOLING_INSPECTOR_EVALUATION_EVALUATION_ENGINE_H
17 #define PANDA_TOOLING_INSPECTOR_EVALUATION_EVALUATION_ENGINE_H
18 
19 #include "include/managed_thread.h"
20 #include "include/object_header.h"
21 #include "include/tooling/debug_interface.h"
22 
23 namespace ark::tooling::inspector {
24 class EvaluationEngine {
25 public:
26     EvaluationEngine() = default;
27 
28     NO_COPY_SEMANTIC(EvaluationEngine);
29     NO_MOVE_SEMANTIC(EvaluationEngine);
30 
31     virtual ~EvaluationEngine() = default;
32 
33     virtual Expected<std::pair<TypedValue, ObjectHeader *>, Error> EvaluateExpression(uint32_t frameNumber,
34                                                                                       const ExpressionWrapper &bytecode,
35                                                                                       Method **method) = 0;
36 };
37 
38 /// @brief Class provides debugger-based evaluation within the given application thread.
39 class PtThreadEvaluationEngine : public EvaluationEngine {
40 public:
PtThreadEvaluationEngine(DebugInterface * debugger,ManagedThread * thread)41     explicit PtThreadEvaluationEngine(DebugInterface *debugger, ManagedThread *thread)
42         : debugger_(debugger), thread_(thread)
43     {
44         ASSERT(debugger_ != nullptr);
45         ASSERT(thread_ != nullptr);
46     }
47 
48     NO_COPY_SEMANTIC(PtThreadEvaluationEngine);
49     NO_MOVE_SEMANTIC(PtThreadEvaluationEngine);
50 
51     ~PtThreadEvaluationEngine() override = default;
52 
GetManagedThread()53     ManagedThread *GetManagedThread()
54     {
55         return thread_;
56     }
57 
IsEvaluating()58     bool IsEvaluating() const
59     {
60         return evaluating_;
61     }
62 
63     /**
64      * @brief Evaluates the given bytecode expression.
65      * @param frameNumber frame depth to evaluate expression in.
66      * @param bytecode fragment with expression.
67      * @param method pointer either providing the previously loaded method or used for storing the expression method.
68      * @returns pair of result and raised exception or an error.
69      */
70     Expected<std::pair<TypedValue, ObjectHeader *>, Error> EvaluateExpression(uint32_t frameNumber,
71                                                                               const ExpressionWrapper &bytecode,
72                                                                               Method **method) final;
73 
74 private:
75     DebugInterface *debugger_;
76     ManagedThread *thread_;
77     bool evaluating_ {false};
78 };
79 }  // namespace ark::tooling::inspector
80 
81 #endif  // PANDA_TOOLING_INSPECTOR_EVALUATION_EVALUATION_ENGINE_H
82