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"
19 extern void sendMail(const char *messageContents);
21 void cb_console(const char *str, void *data)
23 printf("CONSOLE> %s\n",str);
26 /* Note that unlike what's documented in gdb docs it isn't usable. */
27 void cb_target(const char *str, void *data)
29 printf("TARGET> %s\n",str);
32 void cb_log(const char *str, void *data)
34 printf("LOG> %s\n",str);
37 void cb_to(const char *str, void *data)
42 void cb_from(const char *str, void *data)
44 printf("<< %s\n",str);
47 volatile int async_c=0;
49 void cb_async(mi_output *o, void *data)
56 void send_bug_mail(mi_stop* sr, mi_frames* f)
59 asprintf(&message, "Bug detected in file:%s\nfunction:%s\nline:%d\nreason:%s\nreceived signal:%s\n%s\n",
60 f->file, f->func, f->line, mi_reason_enum_to_str(sr->reason), sr->signal_name, sr->signal_meaning);
65 int wait_for_stop(mi_h *h)
71 while (!mi_get_response(h))
73 /* The end of the async. */
77 f = gmi_stack_info_frame(h);
84 printf("Error while waiting\n");
85 printf("mi_error: %d\nmi_error_from_gdb: %s\n",mi_error,mi_error_from_gdb);
91 int main(int argc, char *argv[])
93 mi_aux_term *xterm_tty=NULL;
94 const char* binaryName;
97 GNUNET_assert(NULL != binaryName);
99 /* This is like a file-handle for fopen.
100 Here we have all the state of gdb "connection". */
103 /* Connect to gdb child. */
104 h=mi_connect_local();
107 printf("Connect failed\n");
110 printf("Connected to gdb!\n");
112 /* Set all callbacks. */
113 mi_set_console_cb(h,cb_console,NULL);
114 mi_set_target_cb(h,cb_target,NULL);
115 mi_set_log_cb(h,cb_log,NULL);
116 mi_set_async_cb(h,cb_async,NULL);
117 mi_set_to_gdb_cb(h,cb_to,NULL);
118 mi_set_from_gdb_cb(h,cb_from,NULL);
120 /* Set the name of the child and the command line aguments. */
121 if (!gmi_set_exec(h, binaryName, NULL))
123 printf("Error setting exec y args\n");
128 /* Tell gdb to attach the child to a terminal. */
129 if (!gmi_target_terminal(h, ttyname(STDIN_FILENO)))
131 printf("Error selecting target terminal\n");
136 /* Run the program. */
137 if (!gmi_exec_run(h))
139 printf("Error in run!\n");
143 /* Here we should be stopped when the program crashes */
144 if (!wait_for_stop(h))
150 /* Continue execution. */
151 if (!gmi_exec_continue(h))
153 printf("Error in continue!\n");
157 /* Here we should be terminated. */
158 if (!wait_for_stop(h))
166 /* Close the connection. */
168 /* Wait 5 seconds and close the auxiliar terminal. */
169 printf("Waiting 5 seconds\n");
171 gmi_end_aux_term(xterm_tty);