based on process::pdFlavor, set initial inst accordingly.
[dyninst.git] / paradynd / src / init-sunos.C
1 /*
2  * Copyright (c) 1996 Barton P. Miller
3  * 
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.
10  * 
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.
17  * 
18  * (for other uses, please contact us at paradyn@cs.wisc.edu)
19  * 
20  * All warranties, including without limitation, any warranty of
21  * merchantability or fitness for a particular purpose, are hereby
22  * excluded.
23  * 
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.
29  * 
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.
40  */
41
42 /*
43  * $Log: init-sunos.C,v $
44  * Revision 1.17  1997/03/23 16:53:11  zhichen
45  * based on process::pdFlavor, set initial inst accordingly.
46  *
47  * Revision 1.16  1997/02/21 20:15:47  naim
48  * Moving files from paradynd to dyninstAPI + eliminating references to
49  * dataReqNode from the ast class. This is the first pre-dyninstAPI commit! - naim
50  *
51  * Revision 1.15  1997/01/27 19:40:41  naim
52  * Part of the base instrumentation for supporting multithreaded applications
53  * (vectors of counter/timers) implemented for all current platforms +
54  * different bug fixes - naim
55  *
56  * Revision 1.14  1996/12/11 17:02:48  mjrg
57  * fixed problems with handling of fork and exec
58  *
59  * Revision 1.13  1996/11/14 14:27:00  naim
60  * Changing AstNodes back to pointers to improve performance - naim
61  *
62  * Revision 1.12  1996/10/31 08:44:32  tamches
63  * in initOS(), main no longer calls DYNINSTinit
64  *
65  * Revision 1.11  1996/09/26 18:58:32  newhall
66  * added support for instrumenting dynamic executables on sparc-solaris
67  * platform
68  *
69  * Revision 1.10  1996/08/16 21:18:44  tamches
70  * updated copyright for release 1.1
71  *
72  * Revision 1.9  1996/08/12 16:27:16  mjrg
73  * Code cleanup: removed cm5 kludges and some unused code
74  *
75  * Revision 1.8  1996/05/08 23:54:45  mjrg
76  * added support for handling fork and exec by an application
77  * use /proc instead of ptrace on solaris
78  * removed warnings
79  *
80  * Revision 1.7  1996/03/20 17:02:44  mjrg
81  * Added multiple arguments to calls.
82  * Instrument pvm_send instead of pvm_recv to get tags.
83  *
84  * Revision 1.6  1996/03/01 22:31:59  mjrg
85  * Replaced calls at the exit point by a call to DYNINSTexit
86  *
87  * Revision 1.5  1995/12/15 22:26:48  mjrg
88  * Merged paradynd and paradyndPVM
89  * Get module name for functions from symbol table in solaris
90  * Fixed code generation for multiple instrumentation statements
91  * Changed syntax of MDL resource lists
92  *
93  * Revision 1.4  1995/08/24  15:03:54  hollings
94  * AIX/SP-2 port (including option for split instruction/data heaps)
95  * Tracing of rexec (correctly spawns a paradynd if needed)
96  * Added rtinst function to read getrusage stats (can now be used in metrics)
97  * Critical Path
98  * Improved Error reporting in MDL sematic checks
99  * Fixed MDL Function call statement
100  * Fixed bugs in TK usage (strings passed where UID expected)
101  *
102  */
103
104 #include "paradynd/src/metric.h"
105 #include "paradynd/src/internalMetrics.h"
106 #include "dyninstAPI/src/inst.h"
107 #include "paradynd/src/init.h"
108 #include "dyninstAPI/src/ast.h"
109 #include "dyninstAPI/src/util.h"
110 #include "dyninstAPI/src/os.h"
111
112 // NOTE - the tagArg integer number starting with 0.  
113 static AstNode *tagArg = new AstNode(AstNode::Param, (void *) 1);
114 static AstNode *cmdArg = new AstNode(AstNode::Param, (void *) 4);
115 static AstNode *tidArg = new AstNode(AstNode::Param, (void *) 0);
116 static AstNode *retVal = new AstNode(AstNode::ReturnVal, (void *) 0);
117 #if defined(MT_THREAD)
118 static AstNode *THRidArg = new AstNode(AstNode::Param, (void *) 5);
119 #endif
120
121 bool initOS() {
122
123 //  initialRequests += new instMapping("main", "DYNINSTinit", FUNC_ENTRY);
124 // (obsoleted by installBootstrapInst() --ari)
125
126
127   initialRequests += new instMapping("main", "DYNINSTexit", FUNC_EXIT);
128
129   initialRequests += new instMapping(EXIT_NAME, "DYNINSTexit", FUNC_ENTRY);
130   if(process::pdFlavor != string("cow"))
131   {
132         initialRequests += new instMapping("fork", "DYNINSTfork", 
133                                      FUNC_EXIT|FUNC_ARG, retVal);
134
135         initialRequests += new instMapping("_libc_fork", "DYNINSTfork", 
136                                      FUNC_EXIT|FUNC_ARG, retVal);
137   }
138 #if defined(MT_THREAD)
139   initialRequests += new instMapping("MY_thr_create", "DYNINSTthreadCreate", 
140                                      FUNC_EXIT|FUNC_ARG, THRidArg);
141 #endif
142
143   if(process::pdFlavor != string("cow"))
144   {
145         initialRequests += new instMapping("execve", "DYNINSTexec",
146                                      FUNC_ENTRY|FUNC_ARG, tidArg);
147         initialRequests += new instMapping("execve", "DYNINSTexecFailed", FUNC_EXIT);
148         initialRequests += new instMapping("_execve", "DYNINSTexec",
149                                      FUNC_ENTRY|FUNC_ARG, tidArg);
150         initialRequests += new instMapping("_execve", "DYNINSTexecFailed", FUNC_EXIT);
151   }
152
153 #ifndef SHM_SAMPLING
154   initialRequests += new instMapping("DYNINSTsampleValues", "DYNINSTreportNewTags",
155                                  FUNC_ENTRY);
156 #endif
157
158   if(process::pdFlavor != string("cow"))
159   {
160         initialRequests += new instMapping("rexec", "DYNINSTrexec",
161                                  FUNC_ENTRY|FUNC_ARG, cmdArg);
162   }
163 //   initialRequests += new instMapping("PROCEDURE_LINKAGE_TABLE","DYNINSTdynlinker",FUNC_ENTRY);
164
165
166 #ifdef PARADYND_PVM
167   char *doPiggy;
168
169   initialRequests += new instMapping("pvm_send", "DYNINSTrecordTag",
170                                  FUNC_ENTRY|FUNC_ARG, tagArg);
171
172   // kludge to get Critical Path to work.
173   // XXX - should be tunable constant.
174   doPiggy = getenv("DYNINSTdoPiggy");
175   if (doPiggy) {
176       initialRequests += new instMapping("main", "DYNINSTpvmPiggyInit", FUNC_ENTRY);
177       initialRequests+= new instMapping("pvm_send", "DYNINSTpvmPiggySend",
178                            FUNC_ENTRY|FUNC_ARG, tidArg);
179       initialRequests += new instMapping("pvm_recv", "DYNINSTpvmPiggyRecv", FUNC_EXIT);
180       initialRequests += new instMapping("pvm_mcast", "DYNINSTpvmPiggyMcast",
181                            FUNC_ENTRY|FUNC_ARG, tidArg);
182   }
183 #endif
184
185   return true;
186 };