1 /**[txh]********************************************************************
3 Copyright (c) 2004 by Salvador E. Tropea.
4 Covered by the GPL license.
7 X11 example/test of the libmigdb.
8 Run it from an X11 terminal (xterm, Eterm, etc.).
10 ***************************************************************************/
13 #include <unistd.h> //usleep
17 #include "gnunet_common.h"
20 extern void sendMail (const char *messageContents);
22 void cb_console(const char *str, void *data)
24 printf("CONSOLE> %s\n",str);
27 /* Note that unlike what's documented in gdb docs it isn't usable. */
28 void cb_target(const char *str, void *data)
30 printf("TARGET> %s\n",str);
33 void cb_log(const char *str, void *data)
35 printf("LOG> %s\n",str);
38 void cb_to(const char *str, void *data)
43 void cb_from(const char *str, void *data)
45 printf("<< %s\n",str);
48 volatile int async_c=0;
50 void cb_async(mi_output *o, void *data)
57 void send_bug_mail(mi_stop* sr, mi_frames* f)
60 asprintf(&message, "Bug detected in file:%s\nfunction:%s\nline:%d\nreason:%s\nreceived signal:%s\n%s\n",
61 f->file, f->func, f->line, mi_reason_enum_to_str(sr->reason), sr->signal_name, sr->signal_meaning);
66 int wait_for_stop(mi_h *h)
72 while (!mi_get_response(h))
74 /* The end of the async. */
78 f = gmi_stack_info_frame(h);
85 printf("Error while waiting\n");
86 printf("mi_error: %d\nmi_error_from_gdb: %s\n",mi_error,mi_error_from_gdb);
92 int main(int argc, char *argv[])
94 mi_aux_term *xterm_tty=NULL;
95 const char* binaryName;
98 GNUNET_assert(NULL != binaryName);
100 /* This is like a file-handle for fopen.
101 Here we have all the state of gdb "connection". */
104 /* Connect to gdb child. */
105 h=mi_connect_local();
108 printf("Connect failed\n");
111 printf("Connected to gdb!\n");
113 /* Set all callbacks. */
114 mi_set_console_cb(h,cb_console,NULL);
115 mi_set_target_cb(h,cb_target,NULL);
116 mi_set_log_cb(h,cb_log,NULL);
117 mi_set_async_cb(h,cb_async,NULL);
118 mi_set_to_gdb_cb(h,cb_to,NULL);
119 mi_set_from_gdb_cb(h,cb_from,NULL);
121 /* Set the name of the child and the command line aguments. */
122 if (!gmi_set_exec(h, binaryName, NULL))
124 printf("Error setting exec y args\n");
129 /* Tell gdb to attach the child to a terminal. */
130 if (!gmi_target_terminal(h, ttyname(STDIN_FILENO)))
132 printf("Error selecting target terminal\n");
137 /* Run the program. */
138 if (!gmi_exec_run(h))
140 printf("Error in run!\n");
144 /* Here we should be stopped when the program crashes */
145 if (!wait_for_stop(h))
151 /* Continue execution. */
152 if (!gmi_exec_continue(h))
154 printf("Error in continue!\n");
158 /* Here we should be terminated. */
159 if (!wait_for_stop(h))
167 /* Close the connection. */
169 /* Wait 5 seconds and close the auxiliar terminal. */
170 printf("Waiting 5 seconds\n");
172 gmi_end_aux_term(xterm_tty);