3 // Utility functions for use by the dyninst API test programs.
8 #if defined(sparc_sun_sunos4_1_3) || defined(sparc_sun_solaris2_4)
11 #ifdef i386_unknown_nt4_0
12 #define WIN32_LEAN_AND_MEAN
17 #include "BPatch_Vector.h"
18 #include "BPatch_thread.h"
22 // Wait for the mutatee to stop.
24 void waitUntilStopped(BPatch_thread *appThread, int testnum, char *testname)
26 while (!appThread->isStopped() && !appThread->isTerminated())
27 waitForStatusChange();
29 if (!appThread->isStopped()) {
30 printf("**Failed test #%d (%s)\n", testnum, testname);
31 printf(" process did not signal mutator via stop\n");
34 #ifdef i386_unknown_nt4_0
35 else if (appThread->stopSignal() != SIGTRAP) {
36 printf("**Failed test #%d (%s)\n", testnum, testname);
37 printf(" process stopped on signal %d, not SIGTRAP\n",
38 appThread->stopSignal());
42 else if (appThread->stopSignal() != SIGSTOP) {
43 printf("**Failed test #%d (%s)\n", testnum, testname);
44 printf(" process stopped on signal %d, not SIGSTOP\n",
45 appThread->stopSignal());
53 // Signal the child that we've attached. The child contains a function
54 // "checkIfAttached" which simply returns the value of the global variable
55 // "isAttached." We add instrumentation to "checkIfAttached" to set
58 void signalAttached(BPatch_thread *appThread, BPatch_image *appImage)
60 BPatch_variableExpr *isAttached = appImage->findVariable("isAttached");
61 if (isAttached == NULL) {
62 printf("*ERROR*: unable to start tests because variable \"isAttached\" could not be found in the child process\n");
66 BPatch_arithExpr setAttached(BPatch_assign, *isAttached,
69 // Find the point(s) we'll be instrumenting
70 BPatch_Vector<BPatch_point *> *points =
71 appImage->findProcedurePoint("checkIfAttached", BPatch_entry);
73 fprintf(stderr, "*ERROR*: unable to start tests because the entry point to the function \"checkIfAttached\" could not be located\n");
77 if (appThread->insertSnippet(setAttached, *points) == NULL) {
78 fprintf(stderr, "*ERROR*: unable to start tests because the entry point to the function \"checkIfAttached\" could not be instrumented\n");
85 // Create a new process and return its process id. If process creation
86 // fails, this function returns -1.
88 int startNewProcess(char *pathname, char *argv[])
90 #ifdef i386_unknown_nt4_0
91 char child_args[1024];
92 strcpy(child_args, "");
93 if (argv[0] != NULL) {
94 strcpy(child_args, pathname);
95 for (int i = 1; argv[i] != NULL; i++) {
96 strcat(child_args, " ");
97 strcat(child_args, argv[i]);
102 memset(&si, 0, sizeof(STARTUPINFO));
103 si.cb = sizeof(STARTUPINFO);
104 PROCESS_INFORMATION pi;
105 if (!CreateProcess(pathname, // application name
106 child_args, // command line
107 NULL, // security attributes
108 NULL, // thread security attributes
109 FALSE, // inherit handles
111 NULL, // environment,
112 NULL, // current directory
118 return pi.dwProcessId;
123 execv(pathname, argv);
125 } else if (pid < 0) {