diff options
author | Safey A.Halim <safey.allah@gmail.com> | 2011-02-04 11:47:20 +0000 |
---|---|---|
committer | Safey A.Halim <safey.allah@gmail.com> | 2011-02-04 11:47:20 +0000 |
commit | a75c70e3dc0ade30cc805c05d44b0659311a7d2e (patch) | |
tree | 5e7e32081fdc63ff624eda6a5cbf9b4f80b29415 /src/monkey | |
parent | 147120e1546dc0b12821338d393570b2818a41f5 (diff) | |
download | gnunet-a75c70e3dc0ade30cc805c05d44b0659311a7d2e.tar.gz gnunet-a75c70e3dc0ade30cc805c05d44b0659311a7d2e.zip |
Monkey Action API.
Diffstat (limited to 'src/monkey')
-rw-r--r-- | src/monkey/action_api.c | 187 | ||||
-rw-r--r-- | src/monkey/gdbmi.h | 5 | ||||
-rw-r--r-- | src/monkey/gnunet-monkey.c | 173 | ||||
-rw-r--r-- | src/monkey/gnunet_monkey_action.h | 24 |
4 files changed, 300 insertions, 89 deletions
diff --git a/src/monkey/action_api.c b/src/monkey/action_api.c index c1f39e788..6c7441ad7 100644 --- a/src/monkey/action_api.c +++ b/src/monkey/action_api.c | |||
@@ -26,16 +26,101 @@ | |||
26 | #include "platform.h" | 26 | #include "platform.h" |
27 | #include "gnunet_common.h" | 27 | #include "gnunet_common.h" |
28 | #include "gnunet_monkey_action.h" | 28 | #include "gnunet_monkey_action.h" |
29 | #include <libesmtp.h> | ||
29 | 30 | ||
30 | 31 | ||
31 | int GNUNET_MONKEY_ACTION_report_file() | 32 | #define DEBUG_MODE_GDB 0 |
33 | #define DEBUG_MODE_VALGRIND 1 | ||
34 | #define DEBUG_MODE_REPORT_READY 2 | ||
35 | |||
36 | extern void sendMail (const char *messageContents); | ||
37 | |||
38 | |||
39 | static int async_c=0; | ||
40 | |||
41 | |||
42 | static void cb_console(const char *str, void *data) | ||
43 | { | ||
44 | printf("CONSOLE> %s\n",str); | ||
45 | } | ||
46 | |||
47 | |||
48 | /* Note that unlike what's documented in gdb docs it isn't usable. */ | ||
49 | static void cb_target(const char *str, void *data) | ||
50 | { | ||
51 | printf("TARGET> %s\n",str); | ||
52 | } | ||
53 | |||
54 | |||
55 | static void cb_log(const char *str, void *data) | ||
56 | { | ||
57 | printf("LOG> %s\n",str); | ||
58 | } | ||
59 | |||
60 | |||
61 | static void cb_to(const char *str, void *data) | ||
62 | { | ||
63 | printf(">> %s",str); | ||
64 | } | ||
65 | |||
66 | |||
67 | static void cb_from(const char *str, void *data) | ||
68 | { | ||
69 | printf("<< %s\n",str); | ||
70 | } | ||
71 | |||
72 | |||
73 | static void cb_async(mi_output *o, void *data) | ||
74 | { | ||
75 | printf("ASYNC\n"); | ||
76 | async_c++; | ||
77 | } | ||
78 | |||
79 | |||
80 | static int wait_for_stop(mi_h *h) | ||
81 | { | ||
82 | int res=1; | ||
83 | mi_stop *sr; | ||
84 | mi_frames *f; | ||
85 | |||
86 | while (!mi_get_response(h)) | ||
87 | usleep(1000); | ||
88 | /* The end of the async. */ | ||
89 | sr=mi_res_stop(h); | ||
90 | if (sr) | ||
91 | { | ||
92 | f = gmi_stack_info_frame(h); | ||
93 | if (NULL == f) | ||
94 | printf("f is NULL!\n"); | ||
95 | if (NULL == f) | ||
96 | GNUNET_break(0); | ||
97 | |||
98 | mi_free_stop(sr); | ||
99 | res = 0; | ||
100 | } | ||
101 | else | ||
102 | { | ||
103 | res=0; | ||
104 | } | ||
105 | return res; | ||
106 | } | ||
107 | |||
108 | |||
109 | int GNUNET_MONKEY_ACTION_report_file(struct GNUNET_MONKEY_ACTION_Context* cntxt, const char* dumpFileName) | ||
32 | { | 110 | { |
111 | FILE* file = fopen(dumpFileName, "w"); | ||
112 | GNUNET_assert(NULL != file); | ||
113 | fprintf(file,"%s", cntxt->debug_report); | ||
114 | fclose(file); | ||
33 | return GNUNET_OK; | 115 | return GNUNET_OK; |
34 | } | 116 | } |
35 | 117 | ||
36 | 118 | ||
37 | int GNUNET_MONKEY_ACTION_report_email() | 119 | int GNUNET_MONKEY_ACTION_report_email(struct GNUNET_MONKEY_ACTION_Context* cntxt) |
38 | { | 120 | { |
121 | if (cntxt->debug_mode == DEBUG_MODE_REPORT_READY) | ||
122 | sendMail(cntxt->debug_report); | ||
123 | |||
39 | return GNUNET_OK; | 124 | return GNUNET_OK; |
40 | } | 125 | } |
41 | 126 | ||
@@ -47,8 +132,104 @@ int GNUNET_MONKEY_ACTION_rerun_with_valgrind() | |||
47 | } | 132 | } |
48 | 133 | ||
49 | 134 | ||
50 | int GNUNET_MONKEY_ACTION_rerun_with_gdb() | 135 | int GNUNET_MONKEY_ACTION_rerun_with_gdb(struct GNUNET_MONKEY_ACTION_Context* cntxt) |
136 | { | ||
137 | cntxt->debug_mode = DEBUG_MODE_GDB; | ||
138 | mi_aux_term *xterm_tty=NULL; | ||
139 | |||
140 | /* This is like a file-handle for fopen. | ||
141 | Here we have all the state of gdb "connection". */ | ||
142 | mi_h *h; | ||
143 | |||
144 | /* Connect to gdb child. */ | ||
145 | h = mi_connect_local(); | ||
146 | if (!h) | ||
147 | { | ||
148 | printf("Connect failed\n"); | ||
149 | return GNUNET_NO; | ||
150 | } | ||
151 | printf("Connected to gdb!\n"); | ||
152 | |||
153 | /* Set all callbacks. */ | ||
154 | mi_set_console_cb(h,cb_console,NULL); | ||
155 | mi_set_target_cb(h,cb_target,NULL); | ||
156 | mi_set_log_cb(h,cb_log,NULL); | ||
157 | mi_set_async_cb(h,cb_async,NULL); | ||
158 | mi_set_to_gdb_cb(h,cb_to,NULL); | ||
159 | mi_set_from_gdb_cb(h,cb_from,NULL); | ||
160 | |||
161 | /* Set the name of the child and the command line aguments. */ | ||
162 | if (!gmi_set_exec(h, cntxt->binary_name, NULL)) | ||
163 | { | ||
164 | printf("Error setting exec y args\n"); | ||
165 | mi_disconnect(h); | ||
166 | return GNUNET_NO; | ||
167 | } | ||
168 | |||
169 | /* Tell gdb to attach the child to a terminal. */ | ||
170 | if (!gmi_target_terminal(h, ttyname(STDIN_FILENO))) | ||
171 | { | ||
172 | printf("Error selecting target terminal\n"); | ||
173 | mi_disconnect(h); | ||
174 | return GNUNET_NO; | ||
175 | } | ||
176 | |||
177 | /* Run the program. */ | ||
178 | if (!gmi_exec_run(h)) | ||
179 | { | ||
180 | printf("Error in run!\n"); | ||
181 | mi_disconnect(h); | ||
182 | return GNUNET_NO; | ||
183 | } | ||
184 | /* Here we should be stopped when the program crashes */ | ||
185 | if (!wait_for_stop(h)) | ||
186 | { | ||
187 | mi_disconnect(h); | ||
188 | return GNUNET_NO; | ||
189 | } | ||
190 | |||
191 | /* Continue execution. */ | ||
192 | if (!gmi_exec_continue(h)) | ||
193 | { | ||
194 | printf("Error in continue!\n"); | ||
195 | mi_disconnect(h); | ||
196 | return GNUNET_NO; | ||
197 | } | ||
198 | /* Here we should be terminated. */ | ||
199 | if (!wait_for_stop(h)) | ||
200 | { | ||
201 | mi_disconnect(h); | ||
202 | return GNUNET_NO; | ||
203 | } | ||
204 | |||
205 | /* Exit from gdb. */ | ||
206 | gmi_gdb_exit(h); | ||
207 | /* Close the connection. */ | ||
208 | mi_disconnect(h); | ||
209 | /* Wait 5 seconds and close the auxiliar terminal. */ | ||
210 | printf("Waiting 5 seconds\n"); | ||
211 | sleep(5); | ||
212 | gmi_end_aux_term(xterm_tty); | ||
213 | |||
214 | return GNUNET_OK; | ||
215 | } | ||
216 | |||
217 | |||
218 | int GNUNET_MONKEY_ACTION_format_report(struct GNUNET_MONKEY_ACTION_Context* cntxt) | ||
51 | { | 219 | { |
220 | switch (cntxt->debug_mode) { | ||
221 | case DEBUG_MODE_GDB: | ||
222 | GNUNET_asprintf(&cntxt->debug_report, | ||
223 | "Bug detected in file:%s\nfunction:%s\nline:%d\nreason:%s\nreceived signal:%s\n%s\n", | ||
224 | cntxt->gdb_frames->file, cntxt->gdb_frames->func, cntxt->gdb_frames->line, mi_reason_enum_to_str(cntxt->gdb_stop_reason->reason), cntxt->gdb_stop_reason->signal_name, cntxt->gdb_stop_reason->signal_meaning); | ||
225 | break; | ||
226 | case DEBUG_MODE_VALGRIND: | ||
227 | break; | ||
228 | default: | ||
229 | break; | ||
230 | } | ||
231 | |||
232 | cntxt->debug_mode = DEBUG_MODE_REPORT_READY; | ||
52 | return GNUNET_OK; | 233 | return GNUNET_OK; |
53 | } | 234 | } |
54 | 235 | ||
diff --git a/src/monkey/gdbmi.h b/src/monkey/gdbmi.h index eac429411..c03d09b61 100644 --- a/src/monkey/gdbmi.h +++ b/src/monkey/gdbmi.h | |||
@@ -8,6 +8,9 @@ | |||
8 | 8 | ||
9 | ***************************************************************************/ | 9 | ***************************************************************************/ |
10 | 10 | ||
11 | #ifndef GDBMI_H | ||
12 | #define GDBMI_H | ||
13 | |||
11 | #ifdef __cplusplus | 14 | #ifdef __cplusplus |
12 | extern "C" | 15 | extern "C" |
13 | { | 16 | { |
@@ -710,4 +713,4 @@ int gmi_var_list_children(mi_h *h, mi_gvar *var); | |||
710 | } | 713 | } |
711 | #endif | 714 | #endif |
712 | 715 | ||
713 | 716 | #endif | |
diff --git a/src/monkey/gnunet-monkey.c b/src/monkey/gnunet-monkey.c index 61579817d..13bd71e84 100644 --- a/src/monkey/gnunet-monkey.c +++ b/src/monkey/gnunet-monkey.c | |||
@@ -17,6 +17,7 @@ | |||
17 | #include "gnunet_common.h" | 17 | #include "gnunet_common.h" |
18 | #include "gnunet_getopt_lib.h" | 18 | #include "gnunet_getopt_lib.h" |
19 | #include "gnunet_program_lib.h" | 19 | #include "gnunet_program_lib.h" |
20 | #include "gnunet_monkey_action.h" | ||
20 | 21 | ||
21 | extern void sendMail (const char *messageContents); | 22 | extern void sendMail (const char *messageContents); |
22 | static const char* mode; | 23 | static const char* mode; |
@@ -128,88 +129,96 @@ run (void *cls, | |||
128 | const char *cfgfile, | 129 | const char *cfgfile, |
129 | const struct GNUNET_CONFIGURATION_Handle *c) | 130 | const struct GNUNET_CONFIGURATION_Handle *c) |
130 | { | 131 | { |
131 | mi_aux_term *xterm_tty=NULL; | 132 | struct GNUNET_MONKEY_ACTION_Context* cntxt = |
132 | 133 | GNUNET_malloc(sizeof(struct GNUNET_MONKEY_ACTION_Context)); | |
133 | /* This is like a file-handle for fopen. | 134 | cntxt->binary_name = binaryName; |
134 | Here we have all the state of gdb "connection". */ | 135 | if (GNUNET_OK == GNUNET_MONKEY_ACTION_rerun_with_gdb(cntxt)) { |
135 | mi_h *h; | 136 | GNUNET_MONKEY_ACTION_format_report(cntxt); |
136 | 137 | GNUNET_MONKEY_ACTION_report_file(cntxt, dumpFileName); | |
137 | /* Connect to gdb child. */ | 138 | } |
138 | h=mi_connect_local(); | 139 | |
139 | if (!h) | 140 | // mi_aux_term *xterm_tty=NULL; |
140 | { | 141 | // |
141 | printf("Connect failed\n"); | 142 | // /* This is like a file-handle for fopen. |
142 | ret = 1; | 143 | // Here we have all the state of gdb "connection". */ |
143 | return; | 144 | // mi_h *h; |
144 | } | 145 | // |
145 | printf("Connected to gdb!\n"); | 146 | // /* Connect to gdb child. */ |
146 | 147 | // h=mi_connect_local(); | |
147 | /* Set all callbacks. */ | 148 | // if (!h) |
148 | mi_set_console_cb(h,cb_console,NULL); | 149 | // { |
149 | mi_set_target_cb(h,cb_target,NULL); | 150 | // printf("Connect failed\n"); |
150 | mi_set_log_cb(h,cb_log,NULL); | 151 | // ret = 1; |
151 | mi_set_async_cb(h,cb_async,NULL); | 152 | // return; |
152 | mi_set_to_gdb_cb(h,cb_to,NULL); | 153 | // } |
153 | mi_set_from_gdb_cb(h,cb_from,NULL); | 154 | // printf("Connected to gdb!\n"); |
154 | 155 | // | |
155 | /* Set the name of the child and the command line aguments. */ | 156 | // /* Set all callbacks. */ |
156 | if (!gmi_set_exec(h, binaryName, NULL)) | 157 | // mi_set_console_cb(h,cb_console,NULL); |
157 | { | 158 | // mi_set_target_cb(h,cb_target,NULL); |
158 | printf("Error setting exec y args\n"); | 159 | // mi_set_log_cb(h,cb_log,NULL); |
159 | mi_disconnect(h); | 160 | // mi_set_async_cb(h,cb_async,NULL); |
160 | ret = 1; | 161 | // mi_set_to_gdb_cb(h,cb_to,NULL); |
161 | return; | 162 | // mi_set_from_gdb_cb(h,cb_from,NULL); |
162 | } | 163 | // |
163 | 164 | // /* Set the name of the child and the command line aguments. */ | |
164 | /* Tell gdb to attach the child to a terminal. */ | 165 | // if (!gmi_set_exec(h, binaryName, NULL)) |
165 | if (!gmi_target_terminal(h, ttyname(STDIN_FILENO))) | 166 | // { |
166 | { | 167 | // printf("Error setting exec y args\n"); |
167 | printf("Error selecting target terminal\n"); | 168 | // mi_disconnect(h); |
168 | mi_disconnect(h); | 169 | // ret = 1; |
169 | ret = 1; | 170 | // return; |
170 | return; | 171 | // } |
171 | } | 172 | // |
172 | 173 | // /* Tell gdb to attach the child to a terminal. */ | |
173 | /* Run the program. */ | 174 | // if (!gmi_target_terminal(h, ttyname(STDIN_FILENO))) |
174 | if (!gmi_exec_run(h)) | 175 | // { |
175 | { | 176 | // printf("Error selecting target terminal\n"); |
176 | printf("Error in run!\n"); | 177 | // mi_disconnect(h); |
177 | mi_disconnect(h); | 178 | // ret = 1; |
178 | ret = 1; | 179 | // return; |
179 | return; | 180 | // } |
180 | } | 181 | // |
181 | /* Here we should be stopped when the program crashes */ | 182 | // /* Run the program. */ |
182 | if (!wait_for_stop(h)) | 183 | // if (!gmi_exec_run(h)) |
183 | { | 184 | // { |
184 | mi_disconnect(h); | 185 | // printf("Error in run!\n"); |
185 | ret = 1; | 186 | // mi_disconnect(h); |
186 | return; | 187 | // ret = 1; |
187 | } | 188 | // return; |
188 | 189 | // } | |
189 | /* Continue execution. */ | 190 | // /* Here we should be stopped when the program crashes */ |
190 | if (!gmi_exec_continue(h)) | 191 | // if (!wait_for_stop(h)) |
191 | { | 192 | // { |
192 | printf("Error in continue!\n"); | 193 | // mi_disconnect(h); |
193 | mi_disconnect(h); | 194 | // ret = 1; |
194 | ret = 1; | 195 | // return; |
195 | return; | 196 | // } |
196 | } | 197 | // |
197 | /* Here we should be terminated. */ | 198 | // /* Continue execution. */ |
198 | if (!wait_for_stop(h)) | 199 | // if (!gmi_exec_continue(h)) |
199 | { | 200 | // { |
200 | mi_disconnect(h); | 201 | // printf("Error in continue!\n"); |
201 | ret = 1; | 202 | // mi_disconnect(h); |
202 | return; | 203 | // ret = 1; |
203 | } | 204 | // return; |
204 | 205 | // } | |
205 | /* Exit from gdb. */ | 206 | // /* Here we should be terminated. */ |
206 | gmi_gdb_exit(h); | 207 | // if (!wait_for_stop(h)) |
207 | /* Close the connection. */ | 208 | // { |
208 | mi_disconnect(h); | 209 | // mi_disconnect(h); |
209 | /* Wait 5 seconds and close the auxiliar terminal. */ | 210 | // ret = 1; |
210 | printf("Waiting 5 seconds\n"); | 211 | // return; |
211 | sleep(5); | 212 | // } |
212 | gmi_end_aux_term(xterm_tty); | 213 | // |
214 | // /* Exit from gdb. */ | ||
215 | // gmi_gdb_exit(h); | ||
216 | // /* Close the connection. */ | ||
217 | // mi_disconnect(h); | ||
218 | // /* Wait 5 seconds and close the auxiliar terminal. */ | ||
219 | // printf("Waiting 5 seconds\n"); | ||
220 | // sleep(5); | ||
221 | // gmi_end_aux_term(xterm_tty); | ||
213 | } | 222 | } |
214 | 223 | ||
215 | 224 | ||
diff --git a/src/monkey/gnunet_monkey_action.h b/src/monkey/gnunet_monkey_action.h index da8f85396..8430c9f88 100644 --- a/src/monkey/gnunet_monkey_action.h +++ b/src/monkey/gnunet_monkey_action.h | |||
@@ -26,6 +26,8 @@ | |||
26 | #ifndef GNUNET_MONKEY_ACTION_H | 26 | #ifndef GNUNET_MONKEY_ACTION_H |
27 | #define GNUNET_MONKEY_ACTION_H | 27 | #define GNUNET_MONKEY_ACTION_H |
28 | 28 | ||
29 | #include "gdbmi.h" | ||
30 | |||
29 | #ifdef __cplusplus | 31 | #ifdef __cplusplus |
30 | extern "C" | 32 | extern "C" |
31 | { | 33 | { |
@@ -34,10 +36,26 @@ extern "C" | |||
34 | #endif | 36 | #endif |
35 | #endif | 37 | #endif |
36 | 38 | ||
37 | int GNUNET_MONKEY_ACTION_report_file(); | 39 | |
38 | int GNUNET_MONKEY_ACTION_report_email(); | 40 | /** |
41 | * Context for the Action API | ||
42 | */ | ||
43 | struct GNUNET_MONKEY_ACTION_Context | ||
44 | { | ||
45 | const char* binary_name; | ||
46 | int debug_mode; | ||
47 | char* debug_report; | ||
48 | |||
49 | /* gdb debugging attributes */ | ||
50 | mi_stop* gdb_stop_reason; | ||
51 | mi_frames* gdb_frames; | ||
52 | }; | ||
53 | |||
54 | int GNUNET_MONKEY_ACTION_report_file(struct GNUNET_MONKEY_ACTION_Context* cntxt, const char* dumpFileName); | ||
55 | int GNUNET_MONKEY_ACTION_report_email(struct GNUNET_MONKEY_ACTION_Context* cntxt); | ||
39 | int GNUNET_MONKEY_ACTION_rerun_with_valgrind(); | 56 | int GNUNET_MONKEY_ACTION_rerun_with_valgrind(); |
40 | int GNUNET_MONKEY_ACTION_rerun_with_gdb(); | 57 | int GNUNET_MONKEY_ACTION_rerun_with_gdb(struct GNUNET_MONKEY_ACTION_Context* cntxt); |
58 | int GNUNET_MONKEY_ACTION_format_report(struct GNUNET_MONKEY_ACTION_Context* cntxt); | ||
41 | int GNUNET_MONKEY_ACTION_check_bug_redundancy(); | 59 | int GNUNET_MONKEY_ACTION_check_bug_redundancy(); |
42 | 60 | ||
43 | 61 | ||