1*37f5703cSAndroid Build Coastguard Worker /*
2*37f5703cSAndroid Build Coastguard Worker * Copyright 2011, Google LLC
3*37f5703cSAndroid Build Coastguard Worker *
4*37f5703cSAndroid Build Coastguard Worker * Redistribution and use in source and binary forms, with or without
5*37f5703cSAndroid Build Coastguard Worker * modification, are permitted provided that the following conditions are
6*37f5703cSAndroid Build Coastguard Worker * met:
7*37f5703cSAndroid Build Coastguard Worker *
8*37f5703cSAndroid Build Coastguard Worker * * Redistributions of source code must retain the above copyright
9*37f5703cSAndroid Build Coastguard Worker * notice, this list of conditions and the following disclaimer.
10*37f5703cSAndroid Build Coastguard Worker * * Redistributions in binary form must reproduce the above
11*37f5703cSAndroid Build Coastguard Worker * copyright notice, this list of conditions and the following disclaimer
12*37f5703cSAndroid Build Coastguard Worker * in the documentation and/or other materials provided with the
13*37f5703cSAndroid Build Coastguard Worker * distribution.
14*37f5703cSAndroid Build Coastguard Worker * * Neither the name of Google LLC nor the names of its
15*37f5703cSAndroid Build Coastguard Worker * contributors may be used to endorse or promote products derived from
16*37f5703cSAndroid Build Coastguard Worker * this software without specific prior written permission.
17*37f5703cSAndroid Build Coastguard Worker *
18*37f5703cSAndroid Build Coastguard Worker * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19*37f5703cSAndroid Build Coastguard Worker * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20*37f5703cSAndroid Build Coastguard Worker * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21*37f5703cSAndroid Build Coastguard Worker * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22*37f5703cSAndroid Build Coastguard Worker * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23*37f5703cSAndroid Build Coastguard Worker * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24*37f5703cSAndroid Build Coastguard Worker * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25*37f5703cSAndroid Build Coastguard Worker * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26*37f5703cSAndroid Build Coastguard Worker * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27*37f5703cSAndroid Build Coastguard Worker * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28*37f5703cSAndroid Build Coastguard Worker * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29*37f5703cSAndroid Build Coastguard Worker */
30*37f5703cSAndroid Build Coastguard Worker
31*37f5703cSAndroid Build Coastguard Worker #include <stdio.h>
32*37f5703cSAndroid Build Coastguard Worker #include <dlfcn.h>
33*37f5703cSAndroid Build Coastguard Worker
34*37f5703cSAndroid Build Coastguard Worker typedef struct InlineOperation {
35*37f5703cSAndroid Build Coastguard Worker void * func;
36*37f5703cSAndroid Build Coastguard Worker const char* classDescriptor;
37*37f5703cSAndroid Build Coastguard Worker const char* methodName;
38*37f5703cSAndroid Build Coastguard Worker const char* methodSignature;
39*37f5703cSAndroid Build Coastguard Worker } InlineOperation;
40*37f5703cSAndroid Build Coastguard Worker
41*37f5703cSAndroid Build Coastguard Worker typedef const InlineOperation* (*dvmGetInlineOpsTablePtr)();
42*37f5703cSAndroid Build Coastguard Worker typedef int (*dvmGetInlineOpsTableLengthPtr)();
43*37f5703cSAndroid Build Coastguard Worker
main(int argc,char ** argv)44*37f5703cSAndroid Build Coastguard Worker void main(int argc, char **argv) {
45*37f5703cSAndroid Build Coastguard Worker int i;
46*37f5703cSAndroid Build Coastguard Worker
47*37f5703cSAndroid Build Coastguard Worker void *libdvm = dlopen("libdvm.so", RTLD_LAZY);
48*37f5703cSAndroid Build Coastguard Worker
49*37f5703cSAndroid Build Coastguard Worker if (libdvm == NULL) {
50*37f5703cSAndroid Build Coastguard Worker printf("Failed to load libdvm: %s\n", dlerror());
51*37f5703cSAndroid Build Coastguard Worker return;
52*37f5703cSAndroid Build Coastguard Worker }
53*37f5703cSAndroid Build Coastguard Worker
54*37f5703cSAndroid Build Coastguard Worker dvmGetInlineOpsTablePtr dvmGetInlineOpsTable = dlsym(libdvm, "dvmGetInlineOpsTable");
55*37f5703cSAndroid Build Coastguard Worker
56*37f5703cSAndroid Build Coastguard Worker if (dvmGetInlineOpsTable == NULL) {
57*37f5703cSAndroid Build Coastguard Worker // clear the error, and retry with the c++ mangled name
58*37f5703cSAndroid Build Coastguard Worker dlerror();
59*37f5703cSAndroid Build Coastguard Worker dvmGetInlineOpsTable = dlsym(libdvm, "_Z20dvmGetInlineOpsTablev");
60*37f5703cSAndroid Build Coastguard Worker }
61*37f5703cSAndroid Build Coastguard Worker
62*37f5703cSAndroid Build Coastguard Worker if (dvmGetInlineOpsTable == NULL) {
63*37f5703cSAndroid Build Coastguard Worker printf("Failed to load dvmGetInlineOpsTable: %s\n", dlerror());
64*37f5703cSAndroid Build Coastguard Worker dlclose(libdvm);
65*37f5703cSAndroid Build Coastguard Worker return;
66*37f5703cSAndroid Build Coastguard Worker }
67*37f5703cSAndroid Build Coastguard Worker
68*37f5703cSAndroid Build Coastguard Worker dvmGetInlineOpsTableLengthPtr dvmGetInlineOpsTableLength = dlsym(libdvm, "dvmGetInlineOpsTableLength");
69*37f5703cSAndroid Build Coastguard Worker
70*37f5703cSAndroid Build Coastguard Worker if (dvmGetInlineOpsTableLength == NULL) {
71*37f5703cSAndroid Build Coastguard Worker // clear the error, and retry with the c++ mangled name
72*37f5703cSAndroid Build Coastguard Worker dlerror();
73*37f5703cSAndroid Build Coastguard Worker dvmGetInlineOpsTableLength = dlsym(libdvm, "_Z26dvmGetInlineOpsTableLengthv");
74*37f5703cSAndroid Build Coastguard Worker }
75*37f5703cSAndroid Build Coastguard Worker
76*37f5703cSAndroid Build Coastguard Worker if (dvmGetInlineOpsTableLength == NULL) {
77*37f5703cSAndroid Build Coastguard Worker printf("Failed to load dvmGetInlineOpsTableLength: %s\n", dlerror());
78*37f5703cSAndroid Build Coastguard Worker dlclose(libdvm);
79*37f5703cSAndroid Build Coastguard Worker return;
80*37f5703cSAndroid Build Coastguard Worker }
81*37f5703cSAndroid Build Coastguard Worker
82*37f5703cSAndroid Build Coastguard Worker const InlineOperation *inlineTable = dvmGetInlineOpsTable();
83*37f5703cSAndroid Build Coastguard Worker int length = dvmGetInlineOpsTableLength();
84*37f5703cSAndroid Build Coastguard Worker
85*37f5703cSAndroid Build Coastguard Worker for (i=0; i<length; i++) {
86*37f5703cSAndroid Build Coastguard Worker InlineOperation *item = &inlineTable[i];
87*37f5703cSAndroid Build Coastguard Worker
88*37f5703cSAndroid Build Coastguard Worker printf("%s->%s%s\n", item->classDescriptor, item->methodName, item->methodSignature);
89*37f5703cSAndroid Build Coastguard Worker }
90*37f5703cSAndroid Build Coastguard Worker
91*37f5703cSAndroid Build Coastguard Worker dlclose(libdvm);
92*37f5703cSAndroid Build Coastguard Worker return;
93*37f5703cSAndroid Build Coastguard Worker }