xref: /llvm-project/lldb/test/API/tools/lldb-dap/breakpoint/main.cpp (revision f175b9647ccdfd67300264b2d3bd76e6f9a3fb93)
1 #include <dlfcn.h>
2 #include <stdexcept>
3 #include <stdio.h>
4 
twelve(int i)5 int twelve(int i) {
6   return 12 + i; // break 12
7 }
8 
thirteen(int i)9 int thirteen(int i) {
10   return 13 + i; // break 13
11 }
12 
13 namespace a {
fourteen(int i)14 int fourteen(int i) {
15   return 14 + i; // break 14
16 }
17 } // namespace a
main(int argc,char const * argv[])18 int main(int argc, char const *argv[]) {
19 #if defined(__APPLE__)
20   const char *libother_name = "libother.dylib";
21 #else
22   const char *libother_name = "libother.so";
23 #endif
24 
25   void *handle = dlopen(libother_name, RTLD_NOW);
26   if (handle == nullptr) {
27     fprintf(stderr, "%s\n", dlerror());
28     exit(1);
29   }
30 
31   const char *message = "Hello from main!";
32   int (*foo)(int) = (int (*)(int))dlsym(handle, "foo");
33   if (foo == nullptr) {
34     fprintf(stderr, "%s\n", dlerror());
35     exit(2);
36   }
37   foo(12); // before loop
38 
39   for (int i = 0; i < 10; ++i) {
40     int x = twelve(i) + thirteen(i) + a::fourteen(i); // break loop
41   }
42   printf("%s\n", message);
43   try {
44     throw std::invalid_argument("throwing exception for testing");
45   } catch (...) {
46     puts("caught exception...");
47   }
48   return 0; // after loop
49 }
50