xref: /llvm-project/lldb/test/API/functionalities/dyld-exec-linux/main.cpp (revision 879a47a55ffb94976cbac1d191ef53be135d86a7)
1*879a47a5SGreg Clayton #include <unistd.h>
2*879a47a5SGreg Clayton 
main(int argc,const char * argv[],const char * envp[])3*879a47a5SGreg Clayton int main(int argc, const char *argv[], const char *envp[]) {
4*879a47a5SGreg Clayton   if (argc == 2) {
5*879a47a5SGreg Clayton     // If we have two arguments the first is the path to this executable,
6*879a47a5SGreg Clayton     // the second is the path to the linux dynamic loader that we should
7*879a47a5SGreg Clayton     // exec with. We want to re-run this problem under the dynamic loader
8*879a47a5SGreg Clayton     // and make sure we can hit the breakpoint in the "else".
9*879a47a5SGreg Clayton     const char *interpreter = argv[1];
10*879a47a5SGreg Clayton     const char *this_program = argv[0];
11*879a47a5SGreg Clayton     const char *exec_argv[3] = {interpreter, this_program, nullptr};
12*879a47a5SGreg Clayton     execve(interpreter, (char *const *)exec_argv, (char *const *)envp);
13*879a47a5SGreg Clayton   }
14*879a47a5SGreg Clayton   // Break here
15*879a47a5SGreg Clayton   return 0;
16*879a47a5SGreg Clayton }
17