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