Debian Codegraph @

stapdyn/mutator.h

raw
1 // stapdyn mutator functions
2 // Copyright (C) 2012-2013 Red Hat Inc.
3 //
4 // This file is part of systemtap, and is free software. You can
5 // redistribute it and/or modify it under the terms of the GNU General
6 // Public License (GPL); either version 2, or (at your option) any
7 // later version.
8
9 #ifndef MUTATOR_H
10 #define MUTATOR_H
11
12 #include <memory>
13 #include <string>
14 #include <vector>
15
16 #include <dyninst/BPatch.h>
17 #include <dyninst/BPatch_module.h>
18 #include <dyninst/BPatch_process.h>
19 #include <dyninst/BPatch_thread.h>
20
21 #include "dynprobe.h"
22 #include "dynutil.h"
23 #include "mutatee.h"
24 extern "C" {
25 #include "../runtime/dyninst/stapdyn.h"
26 }
27
28
29 // The mutator drives all instrumentation.
30 class mutator {
31 private:
32 BPatch patch;
33
34 void* module; // the locally dlopened probe module
35 std::string module_name; // the filename of the probe module
36 std::vector<std::string> modoptions; // custom globals from -G option
37 std::string module_shmem; // the global name of this module's shared memory
38 std::vector<dynprobe_target> targets; // the probe targets in the module
39
40 std::vector<std::shared_ptr<mutatee> > mutatees; // all attached target processes
41 std::shared_ptr<mutatee> target_mutatee; // the main target process we created or attached
42 bool p_target_created; // we only kill and wait on the target we created
43 bool p_target_error; // indicates whether the target exited non-zero;
44
45 sigset_t signals_received; // record all signals we've caught
46
47 // disable implicit constructors by not implementing these
48 mutator (const mutator& other);
49 mutator& operator= (const mutator& other);
50
51 // Initialize the module global variables
52 bool init_modoptions();
53
54 // Initialize the session attributes
55 void init_session_attributes();
56
57 // Initialize the module session
58 bool run_module_init();
59
60 // Shutdown the module session
61 bool run_module_exit();
62
63 // Check the status of all mutatees
64 bool update_mutatees();
65
66 // Do probes matching 'flag' exist?
67 bool matching_probes_exist(uint64_t flag);
68
69 // Find a mutatee which matches the given process, else return NULL
70 std::shared_ptr<mutatee> find_mutatee(BPatch_process* process);
71
72 // Stashed utrace probe enter function pointer.
73 decltype(&enter_dyninst_utrace_probe) utrace_enter_fn;
74 public:
75
76 mutator (const std::string& module_name,
77 std::vector<std::string>& module_options);
78 ~mutator ();
79
80 // Load the stap module and initialize all probe info.
81 bool load ();
82
83 // Create a new process with the given command line.
84 bool create_process(const std::string& command);
85
86 // Attach to a specific existing process.
87 bool attach_process(BPatch_process* process);
88 bool attach_process(pid_t pid);
89
90 // Start the actual systemtap session!
91 bool run ();
92
93 // Get the final exit status of this mutator
94 int exit_status();
95
96 // Callback to respond to dynamically loaded libraries.
97 // Check if it matches our targets, and instrument accordingly.
98 void dynamic_library_callback(BPatch_thread *thread,
99 BPatch_object *object,
100 bool load);
101
102 // Callback to respond to post fork events. Check if it matches
103 // our targets, and handle accordingly.
104 void post_fork_callback(BPatch_thread *parent, BPatch_thread *child);
105 void exec_callback(BPatch_thread *thread);
106 void exit_callback(BPatch_thread *thread, BPatch_exitType type);
107
108 void thread_create_callback(BPatch_process *proc, BPatch_thread *thread);
109 void thread_destroy_callback(BPatch_process *proc, BPatch_thread *thread);
110
111 // Callback to respond to signals.
112 void signal_callback(int signal);
113 };
114
115
116 #endif // MUTATOR_H
117
118 /* vim: set sw=2 ts=8 cino=>4,n-2,{2,^-2,t0,(0,u0,w1,M1 : */