Adding error message when shmat fails - naim
[dyninst.git] / paradyn / h / dyninstRPC.I
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 #define MetStyleEventCounter    0
44 #define MetStyleSampledFunction 1
45
46 #include "util/h/Types.h"
47 #include "util/h/aggregation.h"
48 #include "paradyn/src/met/mdl.h"
49
50 $remote
51 struct batch_buffer_entry {
52    int mid;
53    double startTimeStamp;
54    double endTimeStamp;
55    double value;
56    u_int weight;
57    bool  internal_met; 
58
59 $ignore
60    batch_buffer_entry &operator=(const batch_buffer_entry &src) {
61       mid = src.mid;
62       startTimeStamp = src.startTimeStamp;
63       endTimeStamp = src.endTimeStamp;
64       value = src.value;
65       weight = src.weight;
66       internal_met = src.internal_met;
67       return *this;
68    }
69 $ignore
70 };
71
72 // trace data streams
73 $remote
74 struct trace_batch_buffer_entry {
75    int mid;
76    u_int length;
77    byteArray traceRecord;
78
79 $ignore
80    trace_batch_buffer_entry &operator=(const trace_batch_buffer_entry &src) {
81       mid = src.mid;
82       length = src.length;
83       traceRecord = src.traceRecord;
84       return *this;
85    }
86 $ignore
87 };
88
89 /* used by paradynd to inform a change in the status of an application. */
90 // typedef enum { procPaused, procExited } processStatus_t;
91 #define procPaused 0
92 #define procExited 1
93 typedef u_int processStatus_t;
94
95 $remote
96 abstract class mdl_expr {
97 $ignore
98 public:
99   virtual ~mdl_expr();
100   virtual bool apply(mdl_var &ret) = 0;
101   virtual bool mk_list(vector<string> &funcs) = 0;
102 #ifdef NO_MDL_PRINT
103   virtual void print(ostream& os) = 0;
104 #endif
105 $ignore
106 };
107
108 $remote
109 class mdl_v_expr : mdl_expr {
110   string var_;
111   vector<string> fields_;
112   vector<mdl_expr*> *args_;
113   int literal_;
114   u_int arg_;
115   mdl_expr *left_;
116   mdl_expr *right_;
117   u_int type_;
118   vector<u_int> type_walk;
119   bool do_type_walk_;
120   bool ok_;
121   u_int res_type_;
122
123 $ignore
124 public:
125   mdl_v_expr(string var, vector<string> fields);
126   mdl_v_expr(string func_name, vector<mdl_expr*> *args);
127   mdl_v_expr(int int_literal);
128   mdl_v_expr(string string_lit);
129   mdl_v_expr(u_int bin_op, mdl_expr *left, mdl_expr *right);
130   mdl_v_expr(string var, u_int array_index);
131   ~mdl_v_expr();
132   bool apply(mdl_var &ret);
133   bool mk_list(vector<string> &funcs);
134 #ifdef NO_MDL_PRINT
135   virtual void print(ostream& os) {
136     os << "MDL_V_EXPR: var=" << var_ << " res_type=" << res_type_ << " do_type_walk="
137       << do_type_walk_;
138     unsigned size = fields_.size(), index;
139     if (size) {
140       os << "Fields: ";
141       for (index=0; index<size; index++) {
142         os << fields_[index] << " ";
143       }
144       os << endl;
145     }
146   }
147 #endif
148
149 $ignore
150 };
151
152 $remote
153 abstract class mdl_rand {
154 $ignore
155 public:
156   virtual ~mdl_rand() {}
157   virtual bool apply(AstNode *&) = 0;
158 $ignore
159 };
160
161 $remote
162 class mdl_instr_rand: mdl_rand {
163   u_int type_;
164   u_int val_;
165   string name_;
166   vector<mdl_rand *> args_;
167 $ignore
168 public:
169   mdl_instr_rand(u_int type);
170   mdl_instr_rand(u_int type, u_int val);
171   mdl_instr_rand(u_int type, string name);
172   mdl_instr_rand(u_int type, string name, vector<mdl_instr_rand *>args);
173   ~mdl_instr_rand();
174   virtual bool apply(AstNode *&);
175 $ignore
176 };
177
178 $remote
179 class mdl_instr_req {
180   u_int type_;
181   mdl_instr_rand *rand_;
182   string timer_counter_name_;
183
184 $ignore
185 public:
186   // start and stop timers, read symbol
187   mdl_instr_req(u_int type, string name);
188
189   // for counters
190   mdl_instr_req(mdl_instr_rand *arg, u_int type, string obj_name);
191
192   // for calls
193   mdl_instr_req(u_int type, mdl_instr_rand *rand);
194
195  ~mdl_instr_req();
196
197    bool apply(AstNode *&mn, AstNode *pred, bool mn_initialized);
198 $ignore
199 };
200
201 $remote
202 class mdl_icode {
203   mdl_instr_rand *if_op1_;
204   mdl_instr_rand *if_op2_;
205   u_int bin_op_;
206   bool use_if_;
207   mdl_instr_req *req_;
208
209 $ignore
210 public:
211   mdl_icode(mdl_instr_rand *iop1, mdl_instr_rand *iop2,
212             u_int bop, bool use, mdl_instr_req *r);
213   ~mdl_icode();
214    bool apply(AstNode *&mn, bool mn_initialized);
215 $ignore
216 };
217
218 $remote
219 abstract class mdl_stmt {
220 $ignore
221 public:
222   virtual ~mdl_stmt() { }
223   virtual bool apply(metricDefinitionNode *mn, vector<dataReqNode*>& flags) = 0;
224   virtual bool mk_list(vector<string> &funcs) = 0;
225 #ifdef NO_MDL_PRINT
226   virtual void print(ostream& os) = 0;
227 #endif
228 $ignore
229 };
230
231 $remote
232 class mdl_list_stmt : mdl_stmt {
233   u_int type_;
234   string id_;
235   vector<string> *elements_;
236   bool is_lib_;
237   vector<string> *flavor_;
238
239 $ignore
240 public:
241   mdl_list_stmt(u_int type, string ident, vector<string> *elems,
242                 bool is_lib, vector<string> *flavor);
243   virtual ~mdl_list_stmt();
244   virtual bool apply(metricDefinitionNode *mn, vector<dataReqNode*>& flags);
245   virtual bool mk_list(vector<string> &funcs);
246 #ifdef NO_MDL_PRINT
247   virtual void print(ostream&) { }
248 #endif
249
250 $ignore
251 };
252
253 $remote
254 class mdl_for_stmt : mdl_stmt {
255   mdl_stmt *for_body_;
256   string index_name_;
257   mdl_expr *list_expr_;
258
259 $ignore
260 public:
261   mdl_for_stmt(string index_name, mdl_expr *list_exp, mdl_stmt *body);
262   virtual ~mdl_for_stmt();
263   virtual bool apply(metricDefinitionNode *mn, vector<dataReqNode*>& flags);
264   virtual bool mk_list(vector<string> &funcs);
265 #ifdef NO_MDL_PRINT
266   virtual void print(ostream&) { }
267 #endif
268
269 $ignore
270 };
271
272 $remote
273 class mdl_if_stmt : mdl_stmt {
274   mdl_expr *expr_;
275   mdl_stmt *body_;
276
277 $ignore
278 public:
279   mdl_if_stmt(mdl_expr *expr, mdl_stmt *body);
280   virtual ~mdl_if_stmt();
281   virtual bool apply(metricDefinitionNode *mn, vector<dataReqNode*>& flags);
282   virtual bool mk_list(vector<string> &funcs);
283 #ifdef NO_MDL_PRINT
284   virtual void print(ostream&) { }
285 #endif
286
287 $ignore
288 };
289
290 $remote
291 class mdl_seq_stmt : mdl_stmt {
292   vector<mdl_stmt*> *stmts_;
293
294 $ignore
295 public:
296   mdl_seq_stmt(vector<mdl_stmt*> *stmts);
297   virtual ~mdl_seq_stmt();
298   virtual bool apply(metricDefinitionNode *mn, vector<dataReqNode*>& flags);
299   virtual bool mk_list(vector<string> &funcs);
300 #ifdef NO_MDL_PRINT
301   virtual void print(ostream&) { }
302 #endif
303
304 $ignore
305 };
306
307 $remote
308 class mdl_instr_stmt : mdl_stmt {
309   u_int position_; // append or prepend
310   mdl_expr *point_expr_; // e.g. $start.entry.  Can be a fn entry, exit, or call site.
311   vector<mdl_icode*> *icode_reqs_; // the instrumentation code itself
312   u_int where_instr_; // preInsn or postInsn
313   bool constrained_; // if not true, no constraints will be applied
314
315 $ignore
316 public:
317   mdl_instr_stmt(u_int pos, mdl_expr *point_expr, vector<mdl_icode*> *i_reqs,
318                  unsigned where_instr, bool constrained);
319   virtual ~mdl_instr_stmt();
320   virtual bool apply(metricDefinitionNode *mn, vector<dataReqNode*>& flags);
321   virtual bool mk_list(vector<string> &funcs);
322 #ifdef NO_MDL_PRINT
323   virtual void print(ostream& os) {
324     os << "MDL_INSTR_STMT: constrained=" << constrained_ << " ";
325     point_expr_->print(os);
326   }
327 #endif
328
329 $ignore
330 };
331
332 $remote 
333 class mdl_constraint {
334   string id_;
335   vector<string> *match_path_;
336   vector<mdl_stmt*> *stmts_;
337   bool replace_;
338   u_int data_type_;
339   u_int hierarchy_;
340   u_int type_;
341
342 $ignore
343 public:
344   mdl_constraint(string id, vector<string> *match_path,
345                  vector<mdl_stmt*> *stmts, bool replace, u_int d_type,
346                  bool& error);
347   ~mdl_constraint();
348   bool apply(metricDefinitionNode *mn, dataReqNode *&flag,
349              vector<string>& resource, process *proc, bool computingCost);
350   bool mk_list(vector<string> &funcs);
351
352 #ifdef NO_MDL_PRINT
353    friend ostream& operator<< (ostream& os, const mdl_constraint& cons) {
354      os << "\nConstraint: " << cons.id_ << " ";
355      unsigned size, index;
356      if (cons.match_path_) {
357        size = cons.match_path_->size();
358        for (index=0; index<size; index++) os << (*cons.match_path_)[index] << "/";
359        os << endl;
360      }
361      os << "Replace=" << cons.replace_ << " Data_type=" << cons.data_type_ << " Hierarchy=" 
362        << cons.hierarchy_ << " Type=" << cons.type_ << endl;
363     if (cons.stmts_) {
364       size = cons.stmts_->size();
365       os << "Statements\n";
366       for (index=0; index<size; index++) {
367         (*cons.stmts_)[index]->print(os);
368         os << " ";
369       }
370     }
371     return os;
372    }
373 #endif
374
375 $ignore
376 };
377
378 $remote
379 class mdl_metric {
380   string id_;
381   string name_;
382   string units_;
383   u_int agg_op_; // avg, sum, min, or max
384   u_int style_;  // currently, always EventCounter
385   u_int type_;   // counter, processTimer, or wallTimer
386   vector<mdl_stmt*> *stmts_; // for "base is <type_> { ... } (is this correct?)
387   vector<string> *flavors_; // which flavors this metric is valid for
388   vector<mdl_constraint*> *constraints_;
389   vector<string> *temp_ctr_; // temporary counters
390   bool developerMode_;
391   int unitstype_; // normalized, unnormalized, or sampled
392
393 $ignore
394 public:
395   mdl_metric(string id, string name, string units,
396              u_int agg, u_int style, u_int type,
397              vector<mdl_stmt*> *mv, vector<string> *flavs, 
398              vector<mdl_constraint*> *cons,
399              vector<string> *temp_c, bool developerMode,int unitstype);
400   ~mdl_metric();
401 #ifdef NO_MDL_PRINT
402   friend ostream& operator<< (ostream &os, const mdl_metric& met) {
403     os << "\nMetric: " << met.id_ << " " << met.name_ << " agg_op=" << met.agg_op_ << " style=" 
404       << met.style_ << " type=" << met.type_ << endl;
405     unsigned size, index;
406     if (met.stmts_) {
407       size = met.stmts_->size();
408       os << "Statements\n";
409       for (index=0; index<size; index++) {
410         (*met.stmts_)[index]->print(os);
411          os << " ";
412       }
413     }
414     if (met.constraints_) {
415       size = met.constraints_->size();
416       os << "Constraints\n";
417       for (index=0; index<size; index++) {
418         os << *((*met.constraints_)[index]) << " ";
419       }
420     }
421     return os;
422   }
423 #endif
424   metricDefinitionNode *apply(vector< vector<string> >&focus, 
425                               string& flat_name,
426                               vector<process *> procs,
427                               bool replace_components_if_present,
428                               bool computingCost);
429 $ignore
430 };
431
432 /* descriptive information about a metric */
433 $remote struct metricInfo { 
434     string name;
435     int style;
436     int aggregate;
437     string units;
438     bool developerMode;
439     int unitstype;
440     u_int handle;  // this is currently ignored by the daemons 
441 };
442
443 $remote struct focusStruct {
444   vector<u_int> focus;
445 };
446
447 $remote struct resourceInfoCallbackStruct {
448    u_int temporaryId;
449    vector<string> resource_name;
450    string abstraction;
451    u_int type;
452 };
453
454 /*
455  * Create a paradynd process.
456  *
457  */
458 int createDaemon(string machine,
459                  string login,
460                  string name,
461                  vector<string> argv);
462
463
464 $remote dynRPC {
465     $base 4000;
466     $version 52;
467
468     //
469     // Define a program to run. 
470     // argv: the command and arguments
471     // dir: working directory where program will run.
472     int addExecutable(vector<string> argv, string dir);
473
474     //
475     // Connect up with a running program (not possible on all platforms).
476     // 'path' gives the full path name to the executable, used only to read
477     // the symbol table.
478     // values for 'afterAttach': 1 --> pause, 2 --> run, 0 --> leave as is
479     //
480     bool attach(string path, int pid, int afterAttach);
481
482     //
483     // Start an application running (This starts the actual execution).
484     //
485     bool startProgram(int program);
486
487     //
488     //   Stop a process
489     //
490     bool pauseProgram(int program);
491
492     //
493     //   Stop all processes associted with the application.
494     //
495     bool pauseApplication();
496
497     //
498     // Continue a paused process
499     //
500     void continueProgram(int program);
501
502     //
503     // Continue all of the processes
504     //
505     void continueApplication();
506
507     //
508     // Disconnect the tool from the process.
509     //    pause - leave the process in a stopped state.
510     //
511     //
512     bool detachProgram(int program, bool pause);
513
514     //
515     // Called by paradynd when a new process starts up.  Specifically, paradynd
516     // calls it when it detects that the new program has finished running
517     // its DYNINST().
518     //
519     // If the state of the appl as a whole is 'running' then we (paradyn) will
520     // issue an igen call to continue this new process; otherwise, we'll leave it
521     // paused.
522     //
523     $upcall $async void newProgramCallbackFunc( int pid, 
524                                                 vector<string> argv, 
525                                                 string machine,
526                                                 bool calledFromExec,
527                                                 bool wantToInitiallyRun);
528     //
529     // Message display with "error" visual characteristics
530     // and lookup in error database for explanation. This function
531     // calls showError function in UIM class
532     //
533     $upcall $async void showErrorCallback (int errCode,
534                                            string errString,
535                                            string hostName);
536
537    // batch the samples (paradynd-->paradyn) to get better performance
538    // the functionality is essentially the same as the 
539    // sampleDataCallbackFunc, which is now obsolete
540
541    $virtual $upcall $async
542    void batchSampleDataCallbackFunc(int program,
543                                     vector<batch_buffer_entry> theBatchBuffer);
544
545    // batch the traces (paradynd-->paradyn) to get better performance
546    // the functionality is essentially the same as the 
547    // batchSampleDataCallbackFunc, which is now obsolete
548
549    $virtual $upcall $async
550    void batchTraceDataCallbackFunc(int program,
551                                     vector<trace_batch_buffer_entry> theTraceBatchBuffer);
552
553    //
554    // XXXX - Hack this should be generalized into a vector.
555    //
556    $virtual $upcall $async void cpDataCallbackFunc(int program,
557                                                       double timeStamp,
558                                                       int context,
559                                                       double total,
560                                                       double share);
561
562    // 
563    // Handler that reports the initial time for which a daemon reports a sample
564    // The earliest (absolute) initial time will become the base time (0)
565    //
566    $virtual $upcall $async void firstSampleCallback(int program,
567                                                     double time);
568
569     //
570     // Handler that gets called when a new resource is defined.
571     //
572     // temporaryId      - daemon generated resource id (it will become the 
573     //                          permanent id, unless there are conflicts
574     //                          with id's generated by another daemon)
575     // resource_name    - name of resource, divided into parts
576     // abstraction      - abstraction to which it belongs     
577     // type             - the MDL type for this resource (MDL_T_STRING, etc.)
578     // 
579     $virtual $upcall $async void resourceInfoCallback(u_int temporaryId, 
580                                              vector<string> resource_name,
581                                              string abstraction, u_int type);
582
583     $virtual $upcall $async void severalResourceInfoCallback(vector<resourceInfoCallbackStruct>);
584
585    //
586     // Handler that gets called when a new memory is defined.
587     //
588     // data_structure   - name of memory chunk, divided into blks
589     // virtual_address  - start address of the memory chunk
590     // memory_size      - size of the memory chunk
591     // blk_size         - block size
592     $upcall $async void memoryInfoCallback(int program,
593                                            string data_structure,
594                                            int virtual_address,
595                                            u_int memory_size,
596                                            u_int blk_size) ;
597
598     // In case there are conflicts between the resource Id's generated by
599     // the daemons, paradyn generates a new Id and report it to the daemon.
600     $async void resourceInfoResponse(vector<u_int> temporaryIds,
601                                      vector<u_int>resourceIds);
602
603
604     // The ids that will be used to represent memory resources
605     // see memoryInfoCallback
606     $async void memoryInfoResponse(string data_structure,
607                                    int virtual_address,
608                                    u_int memory_size,
609                                    u_int blk_size,
610                                    vector<u_int> resource_ids) ;
611
612     $async void memoryRangeSelected(string flat, int min, int max) ;
613
614     $virtual $upcall $async void resourceBatchMode(bool);
615
616     //
617     // Handler that gets called when new mapping data is collected.
618     //
619     $upcall $async void mappingInfoCallback(int program, 
620                                             string abstraction, 
621                                             string type, 
622                                             string key,
623                                             string value);
624
625     // Upcall for a new metric being defined.
626     //
627     $upcall $async void newMetricCallback(metricInfo info); 
628
629     void setSampleRate(double sampleInterval);
630
631     //
632     // tell dyninst to ignore this resource for instrumentation.
633     //    Currently this only applies to programs, modules, and procedures.
634     //    False - suppress
635     //    True - enable
636     //
637     bool setTracking(u_int resource_id, bool);
638
639     //
640     // Routines to control data collection on a performanceStream.
641     //
642     // resourceList     - a list of resources
643     // metric   - what metric to collect data for
644     //
645     $async void enableDataCollection(vector<focusStruct> focus, 
646                                       vector<string> metric,
647                                       vector<u_int> mi_ids, 
648                                       u_int daemon_id,
649                                       u_int request_id);
650     //
651     // synchronous enable call, for propogating metrics
652     //
653     int enableDataCollection2(vector<u_int> focus, string metric, int id);
654
655     //
656     // Upcall to tell paradyn that all daemons are ready after a metric 
657     // enable request
658     //
659     $upcall $async void enableDataCallback(u_int daemon_id, 
660                                            vector<int> return_id,
661                                            vector<u_int> mi_ids,
662                                            u_int request_id);
663     //
664     // Upcall to tell paradyn that all daemons are ready after computing 
665     // the value for predicted data cost
666     //    id: an identifier for the request
667     //  client_id: an id passed by calling thread
668     //
669     $upcall $async void getPredictedDataCostCallback(u_int id,
670                                                      u_int req_id,
671                                                      float val,
672                                                      u_int clientID);
673
674     //
675     // stop collecting data for the named mi.
676     //     mi           - a metricInstance returned by enableDataCollection.
677     //
678     $async void disableDataCollection(int mi);
679
680     // 
681     // called by a daemon when there is no more data to be sent for a metric
682     // instance, because all processes have exited.
683     $virtual $upcall $async void endOfDataCollection(int mi);
684
685     //
686     // Return the expected cost of collecting performance data for a single
687     //    metric at a given focus.  The value returned is the fraction of
688     //    perturbation expected (i.e. 0.10 == 10% slow down expected).
689     //    id: an identifier for the request
690     //  client_id: an id passed by calling thread
691     //
692     $async void getPredictedDataCost(u_int id,
693                                      u_int req_id,
694                                      vector<u_int> focus, 
695                                      string metric,
696                                      u_int clientID);
697
698     //
699     // Get the static configuration information.
700     //
701     vector<metricInfo> getAvailableMetrics();
702
703     //
704     // Create a new resource.
705     //
706     void addResource(u_int parent, u_int id, string name, u_int type);
707
708     //
709     // stdio or stderr from an application.
710     //
711     $upcall $async void applicationIO(int pid, int len, string line);
712
713     //
714     // stdio or stderr from an application.
715     //
716     $virtual $upcall $async void reportStatus(string line);
717
718     //
719     // Debugger style calls.
720     //
721     //
722     string getStatus(int pid);
723     void coreProcess(int pid);
724
725     //
726     // For paradynd's that may get started, but not by paradyn
727     // This allows them to report system information
728     // flavor = programming environment {"pvm", "cm5", ... }
729     $virtual $upcall $async void reportSelf(string machine, 
730                                             string program, 
731                                             int pid,
732                                             string flavor);
733
734     //
735     // this call is used by paradynd to inform paradyn of a change in
736     // the status of a process -- the process stops (due to a signal), 
737     // or the process exits
738     //
739     $virtual $upcall $async void processStatus(int pid, u_int procstat);
740
741     //
742     // For timing and other measurements of paradynd
743     //
744     void printStats();
745
746     // MDL methods
747     $async void send_metrics(vector<mdl_metric*> *);
748     $async void send_constraints(vector<mdl_constraint*>*);
749     $async void send_stmts(vector<mdl_stmt*> *);
750     $async void send_libs(vector<string>*);
751     $async void send_no_libs();
752
753     // get the current wall clock time of the daemon to adjust for clock differences
754     double getTime();
755
756 };