1#include "dylib.h"
2#include <limits.h>
3#include <stdio.h>
4#include <stdlib.h>
5#include <string.h>
6
7int main(int argc, char const *argv[]) {
8 const char *a_name = "loadunload_a";
9 const char *c_name = "loadunload_c";
10 void *a_dylib_handle = NULL;
11 void *c_dylib_handle = NULL; // Set break point at this line for test_lldb_process_load_and_unload_commands().
12 int (*a_function)(void);
13
14 a_dylib_handle = dylib_open(a_name);
15 if (a_dylib_handle == NULL) {
16 fprintf(stderr, "%s\n", dylib_last_error());
17 exit(status: 1);
18 }
19
20 a_function = (int (*)())dylib_get_symbol(a_dylib_handle, "a_function");
21 if (a_function == NULL) {
22 fprintf(stderr, "%s\n", dylib_last_error());
23 exit(status: 2);
24 }
25 printf(format: "First time around, got: %d\n", a_function());
26 dylib_close(a_dylib_handle);
27
28 c_dylib_handle = dylib_open(c_name);
29 if (c_dylib_handle == NULL) {
30 fprintf(stderr, "%s\n", dylib_last_error());
31 exit(status: 3);
32 }
33 a_function = (int (*)())dylib_get_symbol(c_dylib_handle, "c_function");
34 if (a_function == NULL) {
35 fprintf(stderr, "%s\n", dylib_last_error());
36 exit(status: 4);
37 }
38
39 a_dylib_handle = dylib_open(a_name);
40 if (a_dylib_handle == NULL) {
41 fprintf(stderr, "%s\n", dylib_last_error());
42 exit(status: 5);
43 }
44
45 a_function = (int (*)())dylib_get_symbol(a_dylib_handle, "a_function");
46 if (a_function == NULL) {
47 fprintf(stderr, "%s\n", dylib_last_error());
48 exit(status: 6);
49 }
50 printf(format: "Second time around, got: %d\n", a_function());
51 dylib_close(a_dylib_handle);
52
53 int LLDB_DYLIB_IMPORT d_function(void);
54 printf(format: "d_function returns: %d\n", d_function());
55
56 return 0;
57}
58

source code of lldb/test/API/functionalities/load_unload/main.cpp