blob: 183e552be37fc201a939b27eaabd23bdca8c030a [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
17#define LOG_TAG "bcc"
18#include <cutils/log.h>
19
20#include "ScriptCached.h"
21
22#include <bcc/bcc_cache.h>
23
24#include "ContextManager.h"
Loganf7f0ac52011-01-07 03:53:43 +080025
Logan856ceb22011-01-07 05:21:26 +080026#include <stdlib.h>
27
Loganf7f0ac52011-01-07 03:53:43 +080028namespace bcc {
29
30ScriptCached::~ScriptCached() {
31 // Deallocate the bcc script context
32 if (mContext) {
Logan1dc63142011-02-25 17:14:51 +080033 ContextManager::get().deallocateContext(mContext);
Loganf7f0ac52011-01-07 03:53:43 +080034 }
35
36 // Deallocate string pool, exported var list, exported func list
37 if (mpStringPoolRaw) { free(mpStringPoolRaw); }
38 if (mpExportVars) { free(mpExportVars); }
39 if (mpExportFuncs) { free(mpExportFuncs); }
Stephen Hines071288a2011-01-27 14:38:26 -080040 if (mpObjectSlotList) { free(mpObjectSlotList); }
Loganf7f0ac52011-01-07 03:53:43 +080041}
42
Loganbe79ada2011-01-13 01:33:45 +080043void ScriptCached::getExportVarList(size_t varListSize, void **varList) {
44 if (varList) {
45 size_t varCount = getExportVarCount();
Loganf7f0ac52011-01-07 03:53:43 +080046
Loganbe79ada2011-01-13 01:33:45 +080047 if (varCount > varListSize) {
48 varCount = varListSize;
Loganf7f0ac52011-01-07 03:53:43 +080049 }
Loganbe79ada2011-01-13 01:33:45 +080050
51 memcpy(varList, mpExportVars->cached_addr_list, sizeof(void *) * varCount);
Loganf7f0ac52011-01-07 03:53:43 +080052 }
53}
54
55
Loganbe79ada2011-01-13 01:33:45 +080056void ScriptCached::getExportFuncList(size_t funcListSize, void **funcList) {
57 if (funcList) {
58 size_t funcCount = getExportFuncCount();
Loganf7f0ac52011-01-07 03:53:43 +080059
Loganbe79ada2011-01-13 01:33:45 +080060 if (funcCount > funcListSize) {
61 funcCount = funcListSize;
Loganf7f0ac52011-01-07 03:53:43 +080062 }
Loganbe79ada2011-01-13 01:33:45 +080063
64 memcpy(funcList, mpExportFuncs->cached_addr_list,
65 sizeof(void *) * funcCount);
Loganf7f0ac52011-01-07 03:53:43 +080066 }
67}
68
69
Loganbe79ada2011-01-13 01:33:45 +080070void ScriptCached::getPragmaList(size_t pragmaListSize,
71 char const **keyList,
72 char const **valueList) {
73 size_t pragmaCount = getPragmaCount();
Loganf7f0ac52011-01-07 03:53:43 +080074
Loganbe79ada2011-01-13 01:33:45 +080075 if (pragmaCount > pragmaListSize) {
76 pragmaCount = pragmaListSize;
77 }
Loganf7f0ac52011-01-07 03:53:43 +080078
Loganbe79ada2011-01-13 01:33:45 +080079 if (keyList) {
80 for (size_t i = 0; i < pragmaCount; ++i) {
81 *keyList++ = mPragmas[i].first;
82 }
83 }
Loganf7f0ac52011-01-07 03:53:43 +080084
Loganbe79ada2011-01-13 01:33:45 +080085 if (valueList) {
86 for (size_t i = 0; i < pragmaCount; ++i) {
87 *valueList++ = mPragmas[i].second;
Loganf7f0ac52011-01-07 03:53:43 +080088 }
89 }
90}
91
92
Stephen Hines071288a2011-01-27 14:38:26 -080093void ScriptCached::getObjectSlotList(size_t objectSlotListSize,
94 uint32_t *objectSlotList) {
95 if (objectSlotList) {
96 size_t objectSlotCount = getObjectSlotCount();
97
98 if (objectSlotCount > objectSlotListSize) {
99 objectSlotCount = objectSlotListSize;
100 }
101
102 memcpy(objectSlotList, mpObjectSlotList->object_slot_list,
103 sizeof(uint32_t) * objectSlotCount);
104 }
105}
106
107
Loganf7f0ac52011-01-07 03:53:43 +0800108void *ScriptCached::lookup(const char *name) {
Logan216ec712011-01-07 12:12:31 +0800109 FuncTable::const_iterator I = mFunctions.find(name);
110 return (I == mFunctions.end()) ? NULL : I->second.first;
Loganf7f0ac52011-01-07 03:53:43 +0800111}
112
113
Loganf340bf72011-01-14 17:51:40 +0800114void ScriptCached::getFuncInfoList(size_t funcInfoListSize,
115 FuncInfo *funcInfoList) {
116 if (funcInfoList) {
Loganbe79ada2011-01-13 01:33:45 +0800117 size_t funcCount = getFuncCount();
Loganf7f0ac52011-01-07 03:53:43 +0800118
Loganf340bf72011-01-14 17:51:40 +0800119 if (funcCount > funcInfoListSize) {
120 funcCount = funcInfoListSize;
Loganbe79ada2011-01-13 01:33:45 +0800121 }
122
Loganf340bf72011-01-14 17:51:40 +0800123 FuncInfo *info = funcInfoList;
Logan216ec712011-01-07 12:12:31 +0800124 for (FuncTable::const_iterator
125 I = mFunctions.begin(), E = mFunctions.end();
Loganf340bf72011-01-14 17:51:40 +0800126 I != E && funcCount > 0; ++I, ++info, --funcCount) {
127 info->name = I->first.c_str();
128 info->addr = I->second.first;
129 info->size = I->second.second;
Logan216ec712011-01-07 12:12:31 +0800130 }
Loganf7f0ac52011-01-07 03:53:43 +0800131 }
132}
133
134
Loganf7f0ac52011-01-07 03:53:43 +0800135} // namespace bcc