blob: b1dd9ce47dda18cc17bd3ea0743c367772ae2dab [file] [log] [blame]
Loganf7f0ac52011-01-07 03:53:43 +08001/*
2 * Copyright 2010, The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
Loganf7f0ac52011-01-07 03:53:43 +080017#include "ScriptCached.h"
18
19#include <bcc/bcc_cache.h>
20
21#include "ContextManager.h"
Logan4dcd6792011-02-28 05:12:00 +080022#include "DebugHelper.h"
Loganf7f0ac52011-01-07 03:53:43 +080023
Logan856ceb22011-01-07 05:21:26 +080024#include <stdlib.h>
25
Loganf7f0ac52011-01-07 03:53:43 +080026namespace bcc {
27
28ScriptCached::~ScriptCached() {
29 // Deallocate the bcc script context
30 if (mContext) {
Logan1dc63142011-02-25 17:14:51 +080031 ContextManager::get().deallocateContext(mContext);
Loganf7f0ac52011-01-07 03:53:43 +080032 }
33
34 // Deallocate string pool, exported var list, exported func list
35 if (mpStringPoolRaw) { free(mpStringPoolRaw); }
36 if (mpExportVars) { free(mpExportVars); }
37 if (mpExportFuncs) { free(mpExportFuncs); }
Stephen Hines071288a2011-01-27 14:38:26 -080038 if (mpObjectSlotList) { free(mpObjectSlotList); }
Loganf7f0ac52011-01-07 03:53:43 +080039}
40
Loganbe79ada2011-01-13 01:33:45 +080041void ScriptCached::getExportVarList(size_t varListSize, void **varList) {
42 if (varList) {
43 size_t varCount = getExportVarCount();
Loganf7f0ac52011-01-07 03:53:43 +080044
Loganbe79ada2011-01-13 01:33:45 +080045 if (varCount > varListSize) {
46 varCount = varListSize;
Loganf7f0ac52011-01-07 03:53:43 +080047 }
Loganbe79ada2011-01-13 01:33:45 +080048
49 memcpy(varList, mpExportVars->cached_addr_list, sizeof(void *) * varCount);
Loganf7f0ac52011-01-07 03:53:43 +080050 }
51}
52
53
Loganbe79ada2011-01-13 01:33:45 +080054void ScriptCached::getExportFuncList(size_t funcListSize, void **funcList) {
55 if (funcList) {
56 size_t funcCount = getExportFuncCount();
Loganf7f0ac52011-01-07 03:53:43 +080057
Loganbe79ada2011-01-13 01:33:45 +080058 if (funcCount > funcListSize) {
59 funcCount = funcListSize;
Loganf7f0ac52011-01-07 03:53:43 +080060 }
Loganbe79ada2011-01-13 01:33:45 +080061
62 memcpy(funcList, mpExportFuncs->cached_addr_list,
63 sizeof(void *) * funcCount);
Loganf7f0ac52011-01-07 03:53:43 +080064 }
65}
66
67
Loganbe79ada2011-01-13 01:33:45 +080068void ScriptCached::getPragmaList(size_t pragmaListSize,
69 char const **keyList,
70 char const **valueList) {
71 size_t pragmaCount = getPragmaCount();
Loganf7f0ac52011-01-07 03:53:43 +080072
Loganbe79ada2011-01-13 01:33:45 +080073 if (pragmaCount > pragmaListSize) {
74 pragmaCount = pragmaListSize;
75 }
Loganf7f0ac52011-01-07 03:53:43 +080076
Loganbe79ada2011-01-13 01:33:45 +080077 if (keyList) {
78 for (size_t i = 0; i < pragmaCount; ++i) {
79 *keyList++ = mPragmas[i].first;
80 }
81 }
Loganf7f0ac52011-01-07 03:53:43 +080082
Loganbe79ada2011-01-13 01:33:45 +080083 if (valueList) {
84 for (size_t i = 0; i < pragmaCount; ++i) {
85 *valueList++ = mPragmas[i].second;
Loganf7f0ac52011-01-07 03:53:43 +080086 }
87 }
88}
89
90
Stephen Hines071288a2011-01-27 14:38:26 -080091void ScriptCached::getObjectSlotList(size_t objectSlotListSize,
92 uint32_t *objectSlotList) {
93 if (objectSlotList) {
94 size_t objectSlotCount = getObjectSlotCount();
95
96 if (objectSlotCount > objectSlotListSize) {
97 objectSlotCount = objectSlotListSize;
98 }
99
100 memcpy(objectSlotList, mpObjectSlotList->object_slot_list,
101 sizeof(uint32_t) * objectSlotCount);
102 }
103}
104
105
Loganf7f0ac52011-01-07 03:53:43 +0800106void *ScriptCached::lookup(const char *name) {
Logan216ec712011-01-07 12:12:31 +0800107 FuncTable::const_iterator I = mFunctions.find(name);
108 return (I == mFunctions.end()) ? NULL : I->second.first;
Loganf7f0ac52011-01-07 03:53:43 +0800109}
110
111
Loganf340bf72011-01-14 17:51:40 +0800112void ScriptCached::getFuncInfoList(size_t funcInfoListSize,
113 FuncInfo *funcInfoList) {
114 if (funcInfoList) {
Loganbe79ada2011-01-13 01:33:45 +0800115 size_t funcCount = getFuncCount();
Loganf7f0ac52011-01-07 03:53:43 +0800116
Loganf340bf72011-01-14 17:51:40 +0800117 if (funcCount > funcInfoListSize) {
118 funcCount = funcInfoListSize;
Loganbe79ada2011-01-13 01:33:45 +0800119 }
120
Loganf340bf72011-01-14 17:51:40 +0800121 FuncInfo *info = funcInfoList;
Logan216ec712011-01-07 12:12:31 +0800122 for (FuncTable::const_iterator
123 I = mFunctions.begin(), E = mFunctions.end();
Loganf340bf72011-01-14 17:51:40 +0800124 I != E && funcCount > 0; ++I, ++info, --funcCount) {
125 info->name = I->first.c_str();
126 info->addr = I->second.first;
127 info->size = I->second.second;
Logan216ec712011-01-07 12:12:31 +0800128 }
Loganf7f0ac52011-01-07 03:53:43 +0800129 }
130}
131
132
Loganf7f0ac52011-01-07 03:53:43 +0800133} // namespace bcc