2 * Copyright (c) 1996-2004 Barton P. Miller
4 * We provide the Paradyn Parallel Performance Tools (below
5 * described as "Paradyn") on an AS IS basis, and do not warrant its
6 * validity or performance. We reserve the right to update, modify,
7 * or discontinue this software at any time. We shall have no
8 * obligation to supply such updates or modifications or any other
9 * form of support to you.
11 * This license is for research uses. For such uses, there is no
12 * charge. We define "research use" to mean you may freely use it
13 * inside your organization for whatever purposes you see fit. But you
14 * may not re-distribute Paradyn or parts of Paradyn, in any form
15 * source or binary (including derivatives), electronic or otherwise,
16 * to any other organization or entity without our permission.
18 * (for other uses, please contact us at paradyn@cs.wisc.edu)
20 * All warranties, including without limitation, any warranty of
21 * merchantability or fitness for a particular purpose, are hereby
24 * By your use of Paradyn, you understand and agree that we (or any
25 * other person or entity with proprietary rights in Paradyn) are
26 * under no obligation to provide either maintenance services,
27 * update services, notices of latent defects, or correction of
28 * defects for Paradyn.
30 * Even if advised of the possibility of such damages, under no
31 * circumstances shall we (or any other person or entity with
32 * proprietary rights in the software licensed hereunder) be liable
33 * to you or any third party for direct, indirect, or consequential
34 * damages of any character regardless of type of action, including,
35 * without limitation, loss of profits, loss of use, loss of good
36 * will, or computer failure or malfunction. You agree to indemnify
37 * us (and any other person or entity with proprietary rights in the
38 * software licensed hereunder) for any and all liability it may
39 * incur to third parties resulting from your use of Paradyn.
42 // $Id: test2_8.C,v 1.1 2008/10/30 19:20:29 legendre Exp $
45 * #Desc: BPatch_breakPointExpr
52 #include "BPatch_Vector.h"
53 #include "BPatch_thread.h"
54 #include "BPatch_snippet.h"
58 #include "dyninst_comp.h"
59 class test2_8_Mutator : public DyninstMutator {
65 virtual bool hasCustomExecutionPath() { return true; }
66 virtual test_results_t setup(ParameterDict ¶m);
67 virtual test_results_t executeTest();
69 extern "C" DLLEXPORT TestMutator *test2_8_factory() {
70 return new test2_8_Mutator();
74 // Start of test #8 - BPatch_breakPointExpr
76 // There are two parts to the mutator side of this test. The first part
77 // (test8a) inserts a BPatch_breakPointExpr into the entry point of
78 // the function test8_1. The secon pat (test8b) waits for this breakpoint
79 // to be reached. The first part is run before the processes is continued
80 // (i.e. just after process creation or attach).
82 int test2_8_Mutator::test8a() {
84 * Instrument a function with a BPatch_breakPointExpr.
87 BPatch_Vector<BPatch_function *> found_funcs;
88 const char *funcname = "test2_8_mutatee";
89 if ((NULL == appImage->findFunction(funcname, found_funcs, 1)) || !found_funcs.size()) {
90 logerror(" Unable to find function %s\n", funcname);
94 if (1 < found_funcs.size()) {
95 logerror("%s[%d]: WARNING : found %d functions named %s. Using the first.\n",
96 __FILE__, __LINE__, found_funcs.size(), funcname);
99 BPatch_Vector<BPatch_point *> *points = found_funcs[0]->findPoint(BPatch_entry);
101 if (points == NULL) {
102 logerror("**Failed** test #8 (BPatch_breakPointExpr)\n");
103 logerror(" unable to locate function \"%s\".\n", funcname);
107 BPatch_breakPointExpr bp;
109 if (appThread->insertSnippet(bp, *points) == NULL) {
110 logerror("**Failed** test #8 (BPatch_breakPointExpr)\n");
111 logerror(" unable to insert breakpoint snippet\n");
118 int test2_8_Mutator::test8b()
120 // Wait for process to finish
121 if (0 == waitUntilStopped(bpatch, appThread, 8, "BPatch_breakPointExpr")) {
122 // waitUntilStopped finished successfully
123 logerror("Passed test #8 (BPatch_breakPointExpr)\n");
126 // waitUntilStopped returned an error code, and already printed out an
127 // error message for us
132 test_results_t test2_8_Mutator::executeTest() {
133 // Insert a breakpoint into the mutatee
134 bpatch = BPatch::getBPatch();
136 if ( test8a() < 0 ) {
139 // Let the mutatee run until it hits the breakpoint.
140 appThread->continueExecution();
143 // Something went wrong in test8b. Probably we got the wrong signal code
147 // TODO set the variable test2_8_passed in the mutatee
148 BPatch_variableExpr *passed_expr =
149 appImage->findVariable("test2_8_passed");
150 if (passed_expr == NULL) {
151 logerror("**Failed** test #8 (BPatch_breakPointExpr)\n");
152 logerror(" Unable to locate test2_8_passed\n");
156 passed_expr->writeValue(&pvalue);
157 // Continue the mutatee from the breakpoint so it can exit
158 appThread->continueExecution();
163 // extern "C" TEST_DLL_EXPORT int test2_8_mutatorMAIN(ParameterDict ¶m)
164 test_results_t test2_8_Mutator::setup(ParameterDict ¶m) {
165 bool useAttach = param["useAttach"]->getInt();
166 bpatch = (BPatch *)(param["bpatch"]->getPtr());
168 appThread = (BPatch_thread *)(param["appThread"]->getPtr());
170 // Read the program's image and get an associated image object
171 appImage = appThread->getImage();
173 if ( ! signalAttached(appThread, appImage) ) {