xref: /llvm-project/lldb/test/API/tools/lldb-dap/breakpoint/main.cpp (revision f175b9647ccdfd67300264b2d3bd76e6f9a3fb93)
101263c6cSJonas Devlieghere #include <dlfcn.h>
201263c6cSJonas Devlieghere #include <stdexcept>
301263c6cSJonas Devlieghere #include <stdio.h>
401263c6cSJonas Devlieghere 
twelve(int i)501263c6cSJonas Devlieghere int twelve(int i) {
601263c6cSJonas Devlieghere   return 12 + i; // break 12
701263c6cSJonas Devlieghere }
801263c6cSJonas Devlieghere 
thirteen(int i)901263c6cSJonas Devlieghere int thirteen(int i) {
1001263c6cSJonas Devlieghere   return 13 + i; // break 13
1101263c6cSJonas Devlieghere }
1201263c6cSJonas Devlieghere 
1301263c6cSJonas Devlieghere namespace a {
fourteen(int i)1401263c6cSJonas Devlieghere int fourteen(int i) {
1501263c6cSJonas Devlieghere   return 14 + i; // break 14
1601263c6cSJonas Devlieghere }
1701263c6cSJonas Devlieghere } // namespace a
main(int argc,char const * argv[])1801263c6cSJonas Devlieghere int main(int argc, char const *argv[]) {
1901263c6cSJonas Devlieghere #if defined(__APPLE__)
2001263c6cSJonas Devlieghere   const char *libother_name = "libother.dylib";
2101263c6cSJonas Devlieghere #else
2201263c6cSJonas Devlieghere   const char *libother_name = "libother.so";
2301263c6cSJonas Devlieghere #endif
2401263c6cSJonas Devlieghere 
2501263c6cSJonas Devlieghere   void *handle = dlopen(libother_name, RTLD_NOW);
2601263c6cSJonas Devlieghere   if (handle == nullptr) {
2701263c6cSJonas Devlieghere     fprintf(stderr, "%s\n", dlerror());
2801263c6cSJonas Devlieghere     exit(1);
2901263c6cSJonas Devlieghere   }
3001263c6cSJonas Devlieghere 
31*f175b964Sjeffreytan81   const char *message = "Hello from main!";
3201263c6cSJonas Devlieghere   int (*foo)(int) = (int (*)(int))dlsym(handle, "foo");
3301263c6cSJonas Devlieghere   if (foo == nullptr) {
3401263c6cSJonas Devlieghere     fprintf(stderr, "%s\n", dlerror());
3501263c6cSJonas Devlieghere     exit(2);
3601263c6cSJonas Devlieghere   }
3701263c6cSJonas Devlieghere   foo(12); // before loop
3801263c6cSJonas Devlieghere 
3901263c6cSJonas Devlieghere   for (int i = 0; i < 10; ++i) {
4001263c6cSJonas Devlieghere     int x = twelve(i) + thirteen(i) + a::fourteen(i); // break loop
4101263c6cSJonas Devlieghere   }
42*f175b964Sjeffreytan81   printf("%s\n", message);
4301263c6cSJonas Devlieghere   try {
4401263c6cSJonas Devlieghere     throw std::invalid_argument("throwing exception for testing");
4501263c6cSJonas Devlieghere   } catch (...) {
4601263c6cSJonas Devlieghere     puts("caught exception...");
4701263c6cSJonas Devlieghere   }
4801263c6cSJonas Devlieghere   return 0; // after loop
4901263c6cSJonas Devlieghere }
50