• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /**
2  * Copyright (c) 2022-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_OBJECT_REPOSITORY_H
17 #define PANDA_TOOLING_INSPECTOR_OBJECT_REPOSITORY_H
18 
19 #include "libpandabase/os/mutex.h"
20 #include "runtime/handle_scope.h"
21 #include "runtime/include/tooling/debug_interface.h"
22 #include "runtime/include/typed_value.h"
23 #include "runtime/tooling/inspector/types/numeric_id.h"
24 #include "runtime/tooling/inspector/types/property_descriptor.h"
25 
26 namespace ark::tooling::inspector {
27 /**
28  * All manipulations with an object repository should be made
29  * on the corresponding application thread with mutator lock held
30  */
31 
32 class ObjectRepository {
33 public:
34     explicit ObjectRepository();
35     ~ObjectRepository() = default;
36 
37     NO_COPY_SEMANTIC(ObjectRepository);
38     NO_MOVE_SEMANTIC(ObjectRepository);
39 
40     RemoteObject CreateGlobalObject();
41     RemoteObject CreateFrameObject(const PtFrame &frame, const std::map<std::string, TypedValue> &locals,
42                                    std::optional<RemoteObject> &objThis);
43     RemoteObject CreateObject(TypedValue value);
44 
45     std::vector<PropertyDescriptor> GetProperties(RemoteObjectId id, bool generatePreview);
46 
47 private:
48     static constexpr RemoteObjectId GLOBAL_OBJECT_ID = 0;
49 
50     RemoteObject CreateObject(coretypes::TaggedValue value);
51     RemoteObject CreateObject(ObjectHeader *object);
52     std::vector<PropertyDescriptor> GetProperties(RemoteObjectId id);
53 
54     std::unique_ptr<InspectorExtension> extension_;
55     HandleScope<ObjectHeader *> scope_;
56     RemoteObjectId counter_ {GLOBAL_OBJECT_ID + 1};
57     std::map<RemoteObjectId, std::vector<PropertyDescriptor>> frames_;
58     std::map<RemoteObjectId, VMHandle<ObjectHeader>> objects_;
59 };
60 }  // namespace ark::tooling::inspector
61 
62 #endif  // PANDA_TOOLING_INSPECTOR_OBJECT_REPOSITORY_H
63