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