50 lines · cpp
1#include <dlfcn.h>2#include <stdexcept>3#include <stdio.h>4 5int twelve(int i) {6 return 12 + i; // break 127}8 9int thirteen(int i) {10 return 13 + i; // break 1311}12 13namespace a {14int fourteen(int i) {15 return 14 + i; // break 1416}17} // namespace a18int main(int argc, char const *argv[]) {19#if defined(__APPLE__)20 const char *libother_name = "libother.dylib";21#else22 const char *libother_name = "libother.so";23#endif24 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 } // break non-breakpointable line37 foo(12); // before loop38 39 for (int i = 0; i < 10; ++i) {40 int x = twelve(i) + thirteen(i) + a::fourteen(i); // break loop41 }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 loop49}50