1*e0dbd025SPavel Labath #include "dylib.h"
299451b44SJordan Rupprecht #include <limits.h>
3*e0dbd025SPavel Labath #include <stdio.h>
499451b44SJordan Rupprecht #include <stdlib.h>
5*e0dbd025SPavel Labath #include <string.h>
699451b44SJordan Rupprecht
main(int argc,char const * argv[])7*e0dbd025SPavel Labath int main(int argc, char const *argv[]) {
8*e0dbd025SPavel Labath const char *a_name = "loadunload_a";
9*e0dbd025SPavel Labath const char *c_name = "loadunload_c";
1099451b44SJordan Rupprecht void *a_dylib_handle = NULL;
11*e0dbd025SPavel Labath void *c_dylib_handle = NULL; // Set break point at this line for test_lldb_process_load_and_unload_commands().
1299451b44SJordan Rupprecht int (*a_function)(void);
1399451b44SJordan Rupprecht
14*e0dbd025SPavel Labath a_dylib_handle = dylib_open(a_name);
15*e0dbd025SPavel Labath if (a_dylib_handle == NULL) {
16*e0dbd025SPavel Labath fprintf(stderr, "%s\n", dylib_last_error());
1799451b44SJordan Rupprecht exit(1);
1899451b44SJordan Rupprecht }
1999451b44SJordan Rupprecht
20*e0dbd025SPavel Labath a_function = (int (*)())dylib_get_symbol(a_dylib_handle, "a_function");
21*e0dbd025SPavel Labath if (a_function == NULL) {
22*e0dbd025SPavel Labath fprintf(stderr, "%s\n", dylib_last_error());
2399451b44SJordan Rupprecht exit(2);
2499451b44SJordan Rupprecht }
2599451b44SJordan Rupprecht printf("First time around, got: %d\n", a_function());
26*e0dbd025SPavel Labath dylib_close(a_dylib_handle);
2799451b44SJordan Rupprecht
28*e0dbd025SPavel Labath c_dylib_handle = dylib_open(c_name);
29*e0dbd025SPavel Labath if (c_dylib_handle == NULL) {
30*e0dbd025SPavel Labath fprintf(stderr, "%s\n", dylib_last_error());
3199451b44SJordan Rupprecht exit(3);
3299451b44SJordan Rupprecht }
33*e0dbd025SPavel Labath a_function = (int (*)())dylib_get_symbol(c_dylib_handle, "c_function");
34*e0dbd025SPavel Labath if (a_function == NULL) {
35*e0dbd025SPavel Labath fprintf(stderr, "%s\n", dylib_last_error());
3699451b44SJordan Rupprecht exit(4);
3799451b44SJordan Rupprecht }
3899451b44SJordan Rupprecht
39*e0dbd025SPavel Labath a_dylib_handle = dylib_open(a_name);
40*e0dbd025SPavel Labath if (a_dylib_handle == NULL) {
41*e0dbd025SPavel Labath fprintf(stderr, "%s\n", dylib_last_error());
4299451b44SJordan Rupprecht exit(5);
4399451b44SJordan Rupprecht }
4499451b44SJordan Rupprecht
45*e0dbd025SPavel Labath a_function = (int (*)())dylib_get_symbol(a_dylib_handle, "a_function");
46*e0dbd025SPavel Labath if (a_function == NULL) {
47*e0dbd025SPavel Labath fprintf(stderr, "%s\n", dylib_last_error());
4899451b44SJordan Rupprecht exit(6);
4999451b44SJordan Rupprecht }
5099451b44SJordan Rupprecht printf("Second time around, got: %d\n", a_function());
51*e0dbd025SPavel Labath dylib_close(a_dylib_handle);
5299451b44SJordan Rupprecht
53*e0dbd025SPavel Labath int LLDB_DYLIB_IMPORT d_function(void);
5499451b44SJordan Rupprecht printf("d_function returns: %d\n", d_function());
5599451b44SJordan Rupprecht
5699451b44SJordan Rupprecht return 0;
5799451b44SJordan Rupprecht }
58