xref: /llvm-project/lldb/test/API/macosx/find-dsym/bundle-with-dot-in-filename/main.c (revision 37ec83fcfc6c7915c51268f578b8e0dadb54c1cf)
199451b44SJordan Rupprecht #include <dlfcn.h>
299451b44SJordan Rupprecht #include <unistd.h>
399451b44SJordan Rupprecht #include <stdlib.h>
4*37ec83fcSJonas Devlieghere #include <stdio.h>
599451b44SJordan Rupprecht 
699451b44SJordan Rupprecht int setup_is_complete = 0;
799451b44SJordan Rupprecht 
main(int argc,const char ** argv)8*37ec83fcSJonas Devlieghere int main(int argc, const char** argv)
999451b44SJordan Rupprecht {
1099451b44SJordan Rupprecht 
1199451b44SJordan Rupprecht     void *handle = dlopen ("com.apple.sbd.xpc/com.apple.sbd", RTLD_NOW);
1299451b44SJordan Rupprecht     if (handle)
1399451b44SJordan Rupprecht     {
1499451b44SJordan Rupprecht         if (dlsym(handle, "foo"))
1599451b44SJordan Rupprecht         {
1699451b44SJordan Rupprecht             system ("/bin/rm -rf com.apple.sbd.xpc com.apple.sbd.xpc.dSYM");
17*37ec83fcSJonas Devlieghere 
18*37ec83fcSJonas Devlieghere             FILE *fp = fopen (argv[1], "w");
19*37ec83fcSJonas Devlieghere             fclose (fp);
2099451b44SJordan Rupprecht             setup_is_complete = 1;
2199451b44SJordan Rupprecht 
2299451b44SJordan Rupprecht             // At this point we want lldb to attach to the process.  If lldb attaches
2399451b44SJordan Rupprecht             // before we've removed the dlopen'ed bundle, lldb will find the bundle
2499451b44SJordan Rupprecht             // at its actual filepath and not have to do any tricky work, invalidating
2599451b44SJordan Rupprecht             // the test.
2699451b44SJordan Rupprecht 
2799451b44SJordan Rupprecht             for (int loop_limiter = 0; loop_limiter < 100; loop_limiter++)
2899451b44SJordan Rupprecht                 sleep (1);
2999451b44SJordan Rupprecht         }
3099451b44SJordan Rupprecht     }
3199451b44SJordan Rupprecht     return 0;
3299451b44SJordan Rupprecht }
33