summaryrefslogtreecommitdiffstats
path: root/lldb/test/load_unload/main.c
diff options
context:
space:
mode:
Diffstat (limited to 'lldb/test/load_unload/main.c')
-rw-r--r--lldb/test/load_unload/main.c72
1 files changed, 72 insertions, 0 deletions
diff --git a/lldb/test/load_unload/main.c b/lldb/test/load_unload/main.c
new file mode 100644
index 00000000000..9d2882540e3
--- /dev/null
+++ b/lldb/test/load_unload/main.c
@@ -0,0 +1,72 @@
+//===-- main.c --------------------------------------------------*- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+#include <stdio.h>
+#include <dlfcn.h>
+#include <limits.h>
+#include <string.h>
+#include <unistd.h>
+#include <libgen.h>
+#include <stdlib.h>
+
+int
+main (int argc, char const *argv[])
+{
+ const char *a_name = "@executable_path/liba.dylib";
+ const char *c_name = "@executable_path/libc.dylib";
+ void *a_dylib_handle = NULL;
+ void *c_dylib_handle = NULL;
+ int (*a_function) (void);
+
+ a_dylib_handle = dlopen (a_name, RTLD_NOW);
+ if (a_dylib_handle == NULL)
+ {
+ fprintf (stderr, "%s\n", dlerror());
+ exit (1);
+ }
+
+ a_function = (int (*) ()) dlsym (a_dylib_handle, "a_function");
+ if (a_function == NULL)
+ {
+ fprintf (stderr, "%s\n", dlerror());
+ exit (2);
+ }
+ printf ("First time around, got: %d\n", a_function ());
+ dlclose (a_dylib_handle);
+
+ c_dylib_handle = dlopen (c_name, RTLD_NOW);
+ if (c_dylib_handle == NULL)
+ {
+ fprintf (stderr, "%s\n", dlerror());
+ exit (3);
+ }
+ a_function = (int (*) ()) dlsym (c_dylib_handle, "c_function");
+ if (a_function == NULL)
+ {
+ fprintf (stderr, "%s\n", dlerror());
+ exit (4);
+ }
+
+ a_dylib_handle = dlopen (a_name, RTLD_NOW);
+ if (a_dylib_handle == NULL)
+ {
+ fprintf (stderr, "%s\n", dlerror());
+ exit (5);
+ }
+
+ a_function = (int (*) ()) dlsym (a_dylib_handle, "a_function");
+ if (a_function == NULL)
+ {
+ fprintf (stderr, "%s\n", dlerror());
+ exit (6);
+ }
+ printf ("Second time around, got: %d\n", a_function ());
+ dlclose (a_dylib_handle);
+
+ return 0;
+}
OpenPOWER on IntegriCloud