1 /* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*- */
2 /*
3     plugin.c
4     Copyright (C) 2005 Sebastien Granjoux
5 
6     This program is free software; you can redistribute it and/or modify
7     it under the terms of the GNU General Public License as published by
8     the Free Software Foundation; either version 2 of the License, or
9     (at your option) any later version.
10 
11     This program as distributed in the hope that it will be useful,
12     but WITHOUT ANY WARRANTY; without even the implied warranty of
13     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14     GNU General Public License for more details.
15 
16     You should have received a copy of the GNU General Public License
17     along with this program; if not, write to the Free Software
18     Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
19 */
20 
21 /*
22  * Implement the IAnjutaDebugger interface.
23  */
24 
25 #include <config.h>
26 
27 /*#define DEBUG*/
28 #include <libanjuta/anjuta-debug.h>
29 
30 #include "plugin.h"
31 #include <glib.h>
32 #include <glib/gi18n.h>
33 #include <sys/types.h>
34 #include <sys/stat.h>
35 
36 #include "debugger.h"
37 #include "preferences.h"
38 
39 #include <libanjuta/interfaces/ianjuta-debugger.h>
40 #include <libanjuta/interfaces/ianjuta-debugger-breakpoint.h>
41 #include <libanjuta/interfaces/ianjuta-debugger-register.h>
42 #include <libanjuta/interfaces/ianjuta-debugger-memory.h>
43 #include <libanjuta/interfaces/ianjuta-debugger-instruction.h>
44 #include <libanjuta/interfaces/ianjuta-debugger-variable.h>
45 #include <libanjuta/interfaces/ianjuta-terminal.h>
46 #include <libanjuta/interfaces/ianjuta-preferences.h>
47 #include <libanjuta/anjuta-plugin.h>
48 #include <signal.h>
49 
50 /* Plugin type
51  *---------------------------------------------------------------------------*/
52 
53 struct _GdbPlugin
54 {
55 	AnjutaPlugin parent;
56 
57 	/* Debugger */
58 	Debugger *debugger;
59 
60 	/* Output callback data */
61 	IAnjutaDebuggerOutputCallback output_callback;
62 	gpointer output_user_data;
63 
64 	/* Log message window */
65 	IAnjutaMessageView *view;
66 
67 	/* Terminal */
68 	pid_t term_pid;
69 
70 	/* Pretty printer list */
71 	GList *pretty_printers;
72 };
73 
74 struct _GdbPluginClass
75 {
76 	AnjutaPluginClass parent_class;
77 };
78 
79 #define UNIMPLEMENTED  G_STMT_START { g_warning (G_STRLOC": unimplemented"); } G_STMT_END
80 
81 /* Terminal functions
82  *---------------------------------------------------------------------------*/
83 
84 #define PREF_SCHEMA "org.gnome.anjuta.plugins.run"
85 #define PREF_TERMINAL_COMMAND "terminal-command"
86 
87 static void
gdb_plugin_stop_terminal(GdbPlugin * plugin)88 gdb_plugin_stop_terminal (GdbPlugin* plugin)
89 {
90 	DEBUG_PRINT ("%s", "In function: gdb_plugin_stop_terminal()");
91 
92 	if (plugin->term_pid > 0) {
93 		kill (plugin->term_pid, SIGTERM);
94 		plugin->term_pid = -1;
95 	}
96 }
97 
98 static gchar*
gdb_plugin_start_terminal(GdbPlugin * plugin)99 gdb_plugin_start_terminal (GdbPlugin* plugin)
100 {
101 	gchar *file, *cmd;
102 	gchar *tty = NULL;
103 	IAnjutaTerminal *term;
104 
105 	DEBUG_PRINT ("In function: gdb_plugin_start_terminal() previous pid %d", plugin->term_pid);
106 
107 	/* Close previous terminal if needed */
108 	gdb_plugin_stop_terminal (plugin);
109 
110 	/* Check if anjuta launcher is here */
111 	if (anjuta_util_prog_is_installed ("anjuta-launcher", TRUE) == FALSE)
112 	{
113 		return NULL;
114 	}
115 
116 	file = anjuta_util_get_a_tmp_file();
117 	if (mkfifo (file, 0664) < 0)
118 	{
119 		anjuta_util_dialog_error (GTK_WINDOW (ANJUTA_PLUGIN (plugin)->shell),
120 					  _("Failed to create FIFO file named %s. The program will run without a terminal."), file);
121 		g_free (file);
122 
123 		return NULL;
124 	}
125 
126 	/* Launch terminal */
127 	cmd = g_strconcat ("anjuta-launcher --__debug_terminal ", file, NULL);
128 
129 	/* Get terminal plugin */
130 	term = anjuta_shell_get_interface (ANJUTA_PLUGIN (plugin)->shell, IAnjutaTerminal, NULL);
131 	if (term == NULL)
132 	{
133 		/* Use gnome terminal or another user defined one */
134 		GSettings* settings;
135 		gchar *term_cmd;
136 		gchar **argv;
137 
138 		settings = g_settings_new (PREF_SCHEMA);
139 
140 		term_cmd = g_settings_get_string (settings, PREF_TERMINAL_COMMAND);
141 		g_object_unref (settings);
142 		if (g_shell_parse_argv (term_cmd, NULL, &argv, NULL))
143 		{
144 			GPid gpid;
145 			gchar **arg;
146 
147 			/* Replace %s by command */
148 			for (arg = argv; *arg != NULL; arg++)
149 			{
150 				if (strcmp(*arg, "%s") == 0)
151 				{
152 					g_free (*arg);
153 					*arg = cmd;
154 				}
155 			}
156 
157 			if (g_spawn_async (NULL, argv, NULL, G_SPAWN_SEARCH_PATH, NULL, NULL, &gpid, NULL))
158 			{
159 				plugin->term_pid = gpid;
160 			}
161 			else
162 			{
163 				plugin->term_pid = -1;
164 			}
165 			g_strfreev (argv);
166 		}
167 		else
168 		{
169 			plugin->term_pid = -1;
170 		}
171 		g_free (term_cmd);
172 	}
173 	else
174 	{
175 		/* Use Anjuta terminal plugin */
176 		plugin->term_pid = ianjuta_terminal_execute_command (term, NULL, cmd, NULL, NULL);
177 		g_free (cmd);
178 	}
179 
180 	if (plugin->term_pid > 0)
181 	{
182 		/*
183 		 * Warning: call to fopen() may be blocked if the terminal is
184 		 * not properly started. I don't know how to handle this. May
185 		 * be opening as non-blocking will solve this .
186 		 */
187 		g_file_get_contents (file, &tty, NULL, NULL);  /* Ok, take the risk. */
188 		if (tty)
189 		{
190 			g_strchomp (tty);	/* anjuta_launcher add a end of line after the terminal name */
191 			if (strcmp(tty, "__ERROR__") == 0)
192 			{
193 				g_free (tty);
194 				tty = NULL;
195 			}
196 		}
197 	}
198 	remove (file);
199 	g_free (file);
200 
201 	if (tty == NULL)
202 	{
203 		anjuta_util_dialog_error (GTK_WINDOW (ANJUTA_PLUGIN (plugin)->shell),
204 					  _("Cannot start terminal for debugging."));
205 		gdb_plugin_stop_terminal (plugin);
206 	}
207 
208 	return tty;
209 }
210 
211 /* Private functions
212  *---------------------------------------------------------------------------*/
213 
214 static void
on_debugger_stopped(GdbPlugin * self,GError * err)215 on_debugger_stopped (GdbPlugin *self, GError *err)
216 {
217 	if (self->debugger != NULL)
218 	{
219 		g_signal_handlers_disconnect_by_func (self, G_CALLBACK (on_debugger_stopped), self);
220 		debugger_free (self->debugger);
221 		self->debugger = NULL;
222 		gdb_plugin_stop_terminal (self);
223 	}
224 }
225 
226 static void
gdb_plugin_initialize(GdbPlugin * this)227 gdb_plugin_initialize (GdbPlugin *this)
228 {
229 	GtkWindow *parent;
230 
231 	/* debugger can be not NULL, if initialize is called several times
232 	 * or if debugger_stopped signal has not been emitted */
233 	if (this->debugger != NULL)
234 	{
235 		on_debugger_stopped (this, NULL);
236 	}
237 
238 	parent = GTK_WINDOW (ANJUTA_PLUGIN (this)->shell);
239 	this->debugger = debugger_new (parent, G_OBJECT (this));
240 	g_signal_connect_swapped (this, "debugger-stopped", G_CALLBACK (on_debugger_stopped), this);
241 	debugger_set_output_callback (this->debugger, this->output_callback, this->output_user_data);
242 	if (this->view) debugger_set_log (this->debugger, this->view);
243 
244 	debugger_set_pretty_printers (this->debugger, this->pretty_printers);
245 }
246 
247 /* Helper functions
248  *---------------------------------------------------------------------------*/
249 
250 static gchar *
quote_expression(const gchar * expression)251 quote_expression (const gchar *expression) {
252 	GRegex *regex;
253 	gchar *aux, *aux2;
254 	gchar *quoted;
255 
256 	/* This part is for expressions with an actual \" inside */
257 	regex = g_regex_new ("\\\\\"", G_REGEX_MULTILINE, 0, NULL);
258 	aux = g_regex_replace_literal (regex, expression, -1, 0, "\\\\\\\"", 0, NULL);
259 	g_regex_unref (regex);
260 
261 	/* This part is for expressions with an " inside */
262 	regex = g_regex_new ("(?<!\\\\)\"", G_REGEX_MULTILINE, 0, NULL);
263 	aux2 = g_regex_replace_literal (regex, aux, -1, 0, "\\\"", 0, NULL);
264 	g_regex_unref (regex);
265 	g_free (aux);
266 
267 	/* Converts newlines in spaces */
268 	g_strdelimit (aux2, "\n", ' ');
269 	quoted = g_strconcat ("\"",aux2, "\"", NULL);
270 	g_free (aux2);
271 
272 	return quoted;
273 }
274 
275 /* Callback for saving session
276  *---------------------------------------------------------------------------*/
277 
278 static void
on_session_save(AnjutaShell * shell,AnjutaSessionPhase phase,AnjutaSession * session,GdbPlugin * this)279 on_session_save (AnjutaShell *shell, AnjutaSessionPhase phase, AnjutaSession *session, GdbPlugin *this)
280 {
281 	if (phase != ANJUTA_SESSION_PHASE_NORMAL)
282 		return;
283 
284 	gdb_save_pretty_printers (session, this->pretty_printers);
285 }
286 
on_session_load(AnjutaShell * shell,AnjutaSessionPhase phase,AnjutaSession * session,GdbPlugin * this)287 static void on_session_load (AnjutaShell *shell, AnjutaSessionPhase phase, AnjutaSession *session, GdbPlugin *this)
288 {
289 	if (phase != ANJUTA_SESSION_PHASE_NORMAL)
290 		return;
291 
292 	g_list_foreach (this->pretty_printers, (GFunc)gdb_pretty_printer_free, NULL);
293 	g_list_free (this->pretty_printers);
294 	this->pretty_printers = gdb_load_pretty_printers (session);
295 }
296 
297 /* AnjutaPlugin functions
298  *---------------------------------------------------------------------------*/
299 
300 static gboolean
gdb_plugin_activate_plugin(AnjutaPlugin * plugin)301 gdb_plugin_activate_plugin (AnjutaPlugin* plugin)
302 {
303 	GdbPlugin *this = ANJUTA_PLUGIN_GDB (plugin);
304 
305 	DEBUG_PRINT ("%s", "GDB: Activating Gdb plugin...");
306 	this->pretty_printers = NULL;
307 
308 	/* Connect to session signal */
309 	g_signal_connect (plugin->shell, "save-session",
310 					  G_CALLBACK (on_session_save), this);
311 	g_signal_connect (plugin->shell, "load-session",
312 					  G_CALLBACK (on_session_load), this);
313 
314 
315 	return TRUE;
316 }
317 
318 static gboolean
gdb_plugin_deactivate_plugin(AnjutaPlugin * plugin)319 gdb_plugin_deactivate_plugin (AnjutaPlugin* plugin)
320 {
321 	GdbPlugin *this = ANJUTA_PLUGIN_GDB (plugin);
322 
323 	DEBUG_PRINT ("%s", "GDB: Deactivating Gdb plugin...");
324 
325 	if (this->debugger != NULL)
326 	{
327 		debugger_free (this->debugger);
328 		this->debugger = NULL;
329 	}
330 
331 	g_list_foreach (this->pretty_printers, (GFunc)gdb_pretty_printer_free, NULL);
332 	g_list_free (this->pretty_printers);
333 	this->pretty_printers = NULL;
334 
335 	return TRUE;
336 }
337 
338 /* GObject functions
339  *---------------------------------------------------------------------------*/
340 
341 /* Used in dispose and finalize */
342 static gpointer parent_class;
343 
344 /* instance_init is the constructor. All functions should work after this
345  * call. */
346 
347 static void
gdb_plugin_instance_init(GObject * obj)348 gdb_plugin_instance_init (GObject* obj)
349 {
350 	GdbPlugin *this = ANJUTA_PLUGIN_GDB (obj);
351 
352 	this->debugger = NULL;
353 	this->output_callback = NULL;
354 	this->term_pid = 0;
355 }
356 
357 /* dispose is the first destruction step. It is used to unref object created
358  * with instance_init in order to break reference counting cycles. This
359  * function could be called several times. All function should still work
360  * after this call. It has to called its parents.*/
361 
362 static void
gdb_plugin_dispose(GObject * obj)363 gdb_plugin_dispose (GObject* obj)
364 {
365 	GdbPlugin *this = ANJUTA_PLUGIN_GDB (obj);
366 
367 	if (this->debugger != NULL)
368 	{
369 		debugger_free (this->debugger);
370 		this->debugger = NULL;
371 	}
372 	G_OBJECT_CLASS (parent_class)->dispose (obj);
373 }
374 
375 /* finalize is the last destruction step. It must free all memory allocated
376  * with instance_init. It is called only one time just before releasing all
377  * memory */
378 
379 static void
gdb_plugin_finalize(GObject * obj)380 gdb_plugin_finalize (GObject* obj)
381 {
382 	G_OBJECT_CLASS (parent_class)->finalize (obj);
383 }
384 
385 /* class_init intialize the class itself not the instance */
386 
387 static void
gdb_plugin_class_init(GObjectClass * klass)388 gdb_plugin_class_init (GObjectClass* klass)
389 {
390 	AnjutaPluginClass *plugin_class = ANJUTA_PLUGIN_CLASS (klass);
391 
392 	parent_class = g_type_class_peek_parent (klass);
393 
394 	plugin_class->activate = gdb_plugin_activate_plugin;
395 	plugin_class->deactivate = gdb_plugin_deactivate_plugin;
396 	klass->dispose = gdb_plugin_dispose;
397 	klass->finalize = gdb_plugin_finalize;
398 }
399 
400 /* Implementation of IAnjutaDebugger interface
401  *---------------------------------------------------------------------------*/
402 
403 static IAnjutaDebuggerState
idebugger_get_state(IAnjutaDebugger * plugin,GError ** err)404 idebugger_get_state (IAnjutaDebugger *plugin, GError **err)
405 {
406 	GdbPlugin *this = ANJUTA_PLUGIN_GDB (plugin);
407 
408 	if (this->debugger == NULL)
409 	{
410 		return IANJUTA_DEBUGGER_STOPPED;
411 	}
412 	else
413 	{
414 		return debugger_get_state (this->debugger);
415 	}
416 }
417 
418 
419 static gboolean
idebugger_load(IAnjutaDebugger * plugin,const gchar * file,const gchar * mime_type,const GList * search_dirs,GError ** err)420 idebugger_load (IAnjutaDebugger *plugin, const gchar *file, const gchar* mime_type,
421 				const GList *search_dirs, GError **err)
422 {
423 	GdbPlugin *this = ANJUTA_PLUGIN_GDB (plugin);
424 	gboolean is_libtool = FALSE;
425 
426 	/* Check allowed mime type */
427 	if (mime_type == NULL)
428 	{
429 		/* Hope that the target is supported */
430 	}
431 	else if ((strcmp (mime_type, "application/x-executable") == 0) ||
432 		(strcmp (mime_type, "application/x-sharedlib") == 0) ||
433 		(strcmp (mime_type, "application/octet-stream") == 0))
434 	{
435 		/* Supported target */
436 	}
437 	else if (strcmp (mime_type, "application/x-shellscript") == 0)
438 	{
439 		/* FIXME: We should really do more checks to confirm that
440 		 * this target is indeed libtool target
441 		 */
442 		is_libtool = TRUE;
443 	}
444 	else if (strcmp (mime_type, "application/x-core") == 0)
445 	{
446 		/* Supported target */
447 	}
448 	else
449 	{
450 		/* Not supported target */
451 		return TRUE;
452 	}
453 
454 	// Start debugger
455 	gdb_plugin_initialize (this);
456 
457 	return debugger_start (this->debugger, search_dirs, file, is_libtool);
458 }
459 
460 static gboolean
idebugger_unload(IAnjutaDebugger * plugin,GError ** err)461 idebugger_unload (IAnjutaDebugger *plugin, GError **err)
462 {
463 	GdbPlugin *this = ANJUTA_PLUGIN_GDB (plugin);
464 
465 	debugger_stop (this->debugger);
466 
467 	return TRUE;
468 }
469 
470 static gboolean
idebugger_set_working_directory(IAnjutaDebugger * plugin,const gchar * directory,GError ** err)471 idebugger_set_working_directory (IAnjutaDebugger *plugin, const gchar *directory, GError **err)
472 {
473 	GdbPlugin *self = ANJUTA_PLUGIN_GDB (plugin);
474 
475 	debugger_set_working_directory (self->debugger, directory);
476 
477 	return TRUE;
478 }
479 
480 static gboolean
idebugger_set_environment(IAnjutaDebugger * plugin,gchar ** variables,GError ** err)481 idebugger_set_environment (IAnjutaDebugger *plugin, gchar **variables, GError **err)
482 {
483 	GdbPlugin *self = ANJUTA_PLUGIN_GDB (plugin);
484 
485 	debugger_set_environment (self->debugger, variables);
486 
487 	return TRUE;
488 }
489 
490 static gboolean
idebugger_attach(IAnjutaDebugger * plugin,pid_t pid,const GList * search_dirs,GError ** err)491 idebugger_attach (IAnjutaDebugger *plugin, pid_t pid, const GList *search_dirs, GError **err)
492 {
493 	GdbPlugin *this = ANJUTA_PLUGIN_GDB (plugin);
494 
495 	// Start debugger
496 	gdb_plugin_initialize (this);
497 	debugger_start (this->debugger, search_dirs, NULL, FALSE);
498 	debugger_attach_process (this->debugger, pid);
499 
500 	return TRUE;
501 }
502 
503 static gboolean
idebugger_start(IAnjutaDebugger * plugin,const gchar * argument,gboolean terminal,gboolean stop,GError ** err)504 idebugger_start (IAnjutaDebugger *plugin, const gchar *argument, gboolean terminal, gboolean stop, GError **err)
505 {
506 	GdbPlugin *this = ANJUTA_PLUGIN_GDB (plugin);
507 	gchar *tty;
508 
509 	tty = terminal ? gdb_plugin_start_terminal (this) : NULL;
510 	debugger_start_program (this->debugger, NULL, argument, tty, stop);
511 	g_free (tty);
512 
513 	return TRUE;
514 }
515 
516 static gboolean
idebugger_connect(IAnjutaDebugger * plugin,const gchar * server,const gchar * argument,gboolean terminal,gboolean stop,GError ** err)517 idebugger_connect (IAnjutaDebugger *plugin, const gchar *server, const gchar *argument, gboolean terminal, gboolean stop, GError **err)
518 {
519 	GdbPlugin *this = ANJUTA_PLUGIN_GDB (plugin);
520 	gchar *tty;
521 
522 	tty = terminal ? gdb_plugin_start_terminal (this) : NULL;
523 	debugger_start_program (this->debugger, server, argument, tty, stop);
524 	g_free (tty);
525 
526 	return TRUE;
527 }
528 
529 static gboolean
idebugger_quit(IAnjutaDebugger * plugin,GError ** err)530 idebugger_quit (IAnjutaDebugger *plugin, GError **err)
531 {
532 	GdbPlugin *this = ANJUTA_PLUGIN_GDB (plugin);
533 
534 	if (!debugger_stop (this->debugger))
535 	{
536 		DEBUG_PRINT ("%s", "set error");
537 		g_set_error (err, IANJUTA_DEBUGGER_ERROR, IANJUTA_DEBUGGER_CANCEL, "Command cancelled by user");
538 
539 		return FALSE;
540 	}
541 	else
542 	{
543 		return TRUE;
544 	}
545 }
546 
547 static gboolean
idebugger_abort(IAnjutaDebugger * plugin,GError ** err)548 idebugger_abort (IAnjutaDebugger *plugin, GError **err)
549 {
550 	GdbPlugin *this = ANJUTA_PLUGIN_GDB (plugin);
551 
552 	DEBUG_PRINT ("%s", "idebugger abort\n");
553 	if (!debugger_abort (this->debugger))
554 	{
555 		g_set_error (err, IANJUTA_DEBUGGER_ERROR, IANJUTA_DEBUGGER_CANCEL, "Command cancelled by user");
556 
557 		return FALSE;
558 	}
559 	else
560 	{
561 		return TRUE;
562 	}
563 }
564 
565 static gboolean
idebugger_run(IAnjutaDebugger * plugin,GError ** err)566 idebugger_run (IAnjutaDebugger *plugin, GError **err)
567 {
568 	GdbPlugin *this = ANJUTA_PLUGIN_GDB (plugin);
569 
570 	debugger_run (this->debugger);
571 
572 	return TRUE;
573 }
574 
575 static gboolean
idebugger_step_in(IAnjutaDebugger * plugin,GError ** err)576 idebugger_step_in (IAnjutaDebugger *plugin, GError **err)
577 {
578 	GdbPlugin *this = ANJUTA_PLUGIN_GDB (plugin);
579 
580 	debugger_step_in (this->debugger);
581 
582 	return TRUE;
583 }
584 
585 static gboolean
idebugger_step_over(IAnjutaDebugger * plugin,GError ** err)586 idebugger_step_over (IAnjutaDebugger *plugin, GError **err)
587 {
588 	GdbPlugin *this = ANJUTA_PLUGIN_GDB (plugin);
589 
590 	debugger_step_over (this->debugger);
591 
592 	return TRUE;
593 }
594 
595 static gboolean
idebugger_run_to(IAnjutaDebugger * plugin,const gchar * file,gint line,GError ** err)596 idebugger_run_to (IAnjutaDebugger *plugin, const gchar* file,
597 						   gint line, GError **err)
598 {
599 	GdbPlugin *this = ANJUTA_PLUGIN_GDB (plugin);
600 
601 	debugger_run_to_position (this->debugger, file, line);
602 
603 	return TRUE;
604 }
605 
606 static gboolean
idebugger_step_out(IAnjutaDebugger * plugin,GError ** err)607 idebugger_step_out (IAnjutaDebugger *plugin, GError **err)
608 {
609 	GdbPlugin *this = ANJUTA_PLUGIN_GDB (plugin);
610 
611 	debugger_step_out (this->debugger);
612 
613 	return TRUE;
614 }
615 
616 static gboolean
idebugger_exit(IAnjutaDebugger * plugin,GError ** err)617 idebugger_exit (IAnjutaDebugger *plugin, GError **err)
618 {
619 	GdbPlugin *this = ANJUTA_PLUGIN_GDB (plugin);
620 
621 	debugger_stop_program (this->debugger);
622 
623 	return TRUE;
624 }
625 
626 static gboolean
idebugger_interrupt(IAnjutaDebugger * plugin,GError ** err)627 idebugger_interrupt (IAnjutaDebugger *plugin, GError **err)
628 {
629 	GdbPlugin *this = ANJUTA_PLUGIN_GDB (plugin);
630 
631 	debugger_interrupt (this->debugger);
632 
633 	return TRUE;
634 }
635 
636 static gboolean
idebugger_inspect(IAnjutaDebugger * plugin,const gchar * name,IAnjutaDebuggerGCharCallback callback,gpointer user_data,GError ** err)637 idebugger_inspect (IAnjutaDebugger *plugin, const gchar *name, IAnjutaDebuggerGCharCallback callback, gpointer user_data, GError **err)
638 {
639 	GdbPlugin *this = ANJUTA_PLUGIN_GDB (plugin);
640 
641 	debugger_evaluate (this->debugger, name, callback, user_data);
642 
643 	return TRUE;
644 }
645 
646 static gboolean
idebugger_evaluate(IAnjutaDebugger * plugin,const gchar * name,const gchar * value,IAnjutaDebuggerGCharCallback callback,gpointer user_data,GError ** err)647 idebugger_evaluate (IAnjutaDebugger *plugin, const gchar *name, const gchar *value, IAnjutaDebuggerGCharCallback callback, gpointer user_data, GError **err)
648 {
649 	GdbPlugin *this = ANJUTA_PLUGIN_GDB (plugin);
650 	gchar* buf;
651 
652 	buf = g_strconcat ("\"", name, " = ", value, "\"", NULL);
653 	debugger_evaluate (this->debugger, buf, callback, user_data);
654 	g_free (buf);
655 
656 	return TRUE;
657 }
658 
659 static gboolean
idebugger_send_command(IAnjutaDebugger * plugin,const gchar * command,GError ** err)660 idebugger_send_command (IAnjutaDebugger *plugin, const gchar* command, GError **err)
661 {
662 	GdbPlugin *this = ANJUTA_PLUGIN_GDB (plugin);
663 
664 	debugger_command (this->debugger, command, FALSE, NULL, NULL);
665 
666 	return TRUE;
667 }
668 
669 static gboolean
idebugger_print(IAnjutaDebugger * plugin,const gchar * variable,IAnjutaDebuggerGCharCallback callback,gpointer user_data,GError ** err)670 idebugger_print (IAnjutaDebugger *plugin, const gchar* variable, IAnjutaDebuggerGCharCallback callback, gpointer user_data, GError **err)
671 {
672 	GdbPlugin *this = ANJUTA_PLUGIN_GDB (plugin);
673 
674 	debugger_print (this->debugger, variable, callback, user_data);
675 
676 	return TRUE;
677 }
678 
679 static gboolean
idebugger_list_local(IAnjutaDebugger * plugin,IAnjutaDebuggerGListCallback callback,gpointer user_data,GError ** err)680 idebugger_list_local (IAnjutaDebugger *plugin, IAnjutaDebuggerGListCallback callback , gpointer user_data, GError **err)
681 {
682 	GdbPlugin *this = ANJUTA_PLUGIN_GDB (plugin);
683 
684 	debugger_list_local (this->debugger, callback, user_data);
685 
686 	return TRUE;
687 }
688 
689 static gboolean
idebugger_list_argument(IAnjutaDebugger * plugin,IAnjutaDebuggerGListCallback callback,gpointer user_data,GError ** err)690 idebugger_list_argument (IAnjutaDebugger *plugin, IAnjutaDebuggerGListCallback callback , gpointer user_data, GError **err)
691 {
692 	GdbPlugin *this = ANJUTA_PLUGIN_GDB (plugin);
693 
694 	debugger_list_argument (this->debugger, callback, user_data);
695 
696 	return TRUE;
697 }
698 
699 static gboolean
idebugger_info_signal(IAnjutaDebugger * plugin,IAnjutaDebuggerGListCallback callback,gpointer user_data,GError ** err)700 idebugger_info_signal (IAnjutaDebugger *plugin, IAnjutaDebuggerGListCallback callback , gpointer user_data, GError **err)
701 {
702 	GdbPlugin *this = ANJUTA_PLUGIN_GDB (plugin);
703 
704 	debugger_info_signal (this->debugger, callback, user_data);
705 
706 	return TRUE;
707 }
708 
709 static gboolean
idebugger_info_sharedlib(IAnjutaDebugger * plugin,IAnjutaDebuggerGListCallback callback,gpointer user_data,GError ** err)710 idebugger_info_sharedlib (IAnjutaDebugger *plugin, IAnjutaDebuggerGListCallback callback , gpointer user_data, GError **err)
711 {
712 	GdbPlugin *this = ANJUTA_PLUGIN_GDB (plugin);
713 
714 	debugger_info_sharedlib (this->debugger, callback, user_data);
715 
716 	return TRUE;
717 }
718 
719 static gboolean
idebugger_handle_signal(IAnjutaDebugger * plugin,const gchar * name,gboolean stop,gboolean print,gboolean ignore,GError ** err)720 idebugger_handle_signal (IAnjutaDebugger *plugin, const gchar* name, gboolean stop, gboolean print, gboolean ignore, GError **err)
721 {
722 	gchar* cmd;
723 	GdbPlugin *this = ANJUTA_PLUGIN_GDB (plugin);
724 
725 	cmd = g_strdup_printf("handle %s %sstop %sprint %spass", name, stop ? "" : "no", print ? "" : "no", ignore ? "" : "no");
726 	debugger_command (this->debugger, cmd, FALSE, NULL, NULL);
727 	g_free (cmd);
728 
729 	return TRUE;
730 }
731 
732 static gboolean
idebugger_info_frame(IAnjutaDebugger * plugin,guint frame,IAnjutaDebuggerGListCallback callback,gpointer user_data,GError ** err)733 idebugger_info_frame (IAnjutaDebugger *plugin, guint frame, IAnjutaDebuggerGListCallback callback , gpointer user_data, GError **err)
734 {
735 	UNIMPLEMENTED;
736 
737 	return FALSE;
738 }
739 
740 static gboolean
idebugger_info_args(IAnjutaDebugger * plugin,IAnjutaDebuggerGListCallback callback,gpointer user_data,GError ** err)741 idebugger_info_args (IAnjutaDebugger *plugin, IAnjutaDebuggerGListCallback callback , gpointer user_data, GError **err)
742 {
743 	UNIMPLEMENTED;
744 
745 	return FALSE;
746 }
747 
748 static gboolean
idebugger_info_target(IAnjutaDebugger * plugin,IAnjutaDebuggerGListCallback callback,gpointer user_data,GError ** err)749 idebugger_info_target (IAnjutaDebugger *plugin, IAnjutaDebuggerGListCallback callback , gpointer user_data, GError **err)
750 {
751 	UNIMPLEMENTED;
752 
753 	return FALSE;
754 }
755 
756 static gboolean
idebugger_info_program(IAnjutaDebugger * plugin,IAnjutaDebuggerGListCallback callback,gpointer user_data,GError ** err)757 idebugger_info_program (IAnjutaDebugger *plugin, IAnjutaDebuggerGListCallback callback , gpointer user_data, GError **err)
758 {
759 	UNIMPLEMENTED;
760 
761 	return FALSE;
762 }
763 
764 static gboolean
idebugger_info_udot(IAnjutaDebugger * plugin,IAnjutaDebuggerGListCallback callback,gpointer user_data,GError ** err)765 idebugger_info_udot (IAnjutaDebugger *plugin, IAnjutaDebuggerGListCallback callback , gpointer user_data, GError **err)
766 {
767 	UNIMPLEMENTED;
768 
769 	return FALSE;
770 }
771 
772 static gboolean
idebugger_info_variables(IAnjutaDebugger * plugin,IAnjutaDebuggerGListCallback callback,gpointer user_data,GError ** err)773 idebugger_info_variables (IAnjutaDebugger *plugin, IAnjutaDebuggerGListCallback callback , gpointer user_data, GError **err)
774 {
775 	UNIMPLEMENTED;
776 
777 	return FALSE;
778 }
779 
780 static gboolean
idebugger_set_frame(IAnjutaDebugger * plugin,guint frame,GError ** err)781 idebugger_set_frame (IAnjutaDebugger *plugin, guint frame, GError **err)
782 {
783 	GdbPlugin *this = ANJUTA_PLUGIN_GDB (plugin);
784 
785 	debugger_set_frame (this->debugger, frame);
786 
787 	return TRUE;
788 }
789 
790 static gboolean
idebugger_list_frame(IAnjutaDebugger * plugin,IAnjutaDebuggerGListCallback callback,gpointer user_data,GError ** err)791 idebugger_list_frame (IAnjutaDebugger *plugin, IAnjutaDebuggerGListCallback callback , gpointer user_data, GError **err)
792 {
793 	GdbPlugin *this = ANJUTA_PLUGIN_GDB (plugin);
794 
795 	debugger_list_frame (this->debugger, callback, user_data);
796 
797 	return TRUE;
798 }
799 
800 static gboolean
idebugger_set_thread(IAnjutaDebugger * plugin,gint thread,GError ** err)801 idebugger_set_thread (IAnjutaDebugger *plugin, gint thread, GError **err)
802 {
803 	GdbPlugin *this = ANJUTA_PLUGIN_GDB (plugin);
804 
805 	debugger_set_thread (this->debugger, thread);
806 
807 	return TRUE;
808 }
809 
810 static gboolean
idebugger_list_thread(IAnjutaDebugger * plugin,IAnjutaDebuggerGListCallback callback,gpointer user_data,GError ** err)811 idebugger_list_thread (IAnjutaDebugger *plugin, IAnjutaDebuggerGListCallback callback , gpointer user_data, GError **err)
812 {
813 	GdbPlugin *this = ANJUTA_PLUGIN_GDB (plugin);
814 
815 	debugger_list_thread (this->debugger, callback, user_data);
816 
817 	return TRUE;
818 }
819 
820 static gboolean
idebugger_info_thread(IAnjutaDebugger * plugin,gint thread,IAnjutaDebuggerGListCallback callback,gpointer user_data,GError ** err)821 idebugger_info_thread (IAnjutaDebugger *plugin, gint thread, IAnjutaDebuggerGListCallback callback , gpointer user_data, GError **err)
822 {
823 	GdbPlugin *this = ANJUTA_PLUGIN_GDB (plugin);
824 
825 	debugger_info_thread (this->debugger, thread, callback, user_data);
826 
827 	return TRUE;
828 }
829 
830 static gboolean
idebugger_run_from(IAnjutaDebugger * plugin,const gchar * file,gint line,GError ** err)831 idebugger_run_from (IAnjutaDebugger *plugin, const gchar *file, gint line, GError **err)
832 {
833 	GdbPlugin *this = ANJUTA_PLUGIN_GDB (plugin);
834 
835 	debugger_run_from_position (this->debugger, file, line);
836 
837 	return TRUE;
838 }
839 
840 static gboolean
idebugger_dump_stack_trace(IAnjutaDebugger * plugin,IAnjutaDebuggerGListCallback callback,gpointer user_data,GError ** err)841 idebugger_dump_stack_trace (IAnjutaDebugger *plugin, IAnjutaDebuggerGListCallback callback , gpointer user_data, GError **err)
842 {
843 	GdbPlugin *this = ANJUTA_PLUGIN_GDB (plugin);
844 
845 	debugger_dump_stack_trace (this->debugger, callback, user_data);
846 
847 	return TRUE;
848 }
849 
850 static gboolean
idebugger_callback(IAnjutaDebugger * plugin,IAnjutaDebuggerCallback callback,gpointer user_data,GError ** err)851 idebugger_callback (IAnjutaDebugger *plugin, IAnjutaDebuggerCallback callback , gpointer user_data, GError **err)
852 {
853 
854 	callback (NULL, user_data, NULL);
855 
856 	return TRUE;
857 }
858 
859 static void
idebugger_enable_log(IAnjutaDebugger * plugin,IAnjutaMessageView * log,GError ** err)860 idebugger_enable_log (IAnjutaDebugger *plugin, IAnjutaMessageView *log, GError **err)
861 {
862 	GdbPlugin *this = ANJUTA_PLUGIN_GDB (plugin);
863 
864 	this->view = log;
865 	if (this->debugger)
866 		debugger_set_log (this->debugger, log);
867 }
868 
869 static void
idebugger_disable_log(IAnjutaDebugger * plugin,GError ** err)870 idebugger_disable_log (IAnjutaDebugger *plugin, GError **err)
871 {
872 	GdbPlugin *this = ANJUTA_PLUGIN_GDB (plugin);
873 
874 	this->view = NULL;
875 	if (this->debugger)
876 		debugger_set_log (this->debugger, NULL);
877 }
878 
879 static void
idebugger_iface_init(IAnjutaDebuggerIface * iface)880 idebugger_iface_init (IAnjutaDebuggerIface *iface)
881 {
882 	iface->get_state = idebugger_get_state;
883 	iface->attach = idebugger_attach;
884 	iface->load = idebugger_load;
885 	iface->set_working_directory = idebugger_set_working_directory;
886 	iface->set_environment = idebugger_set_environment;
887 	iface->start = idebugger_start;
888 	iface->connect = idebugger_connect;
889 	iface->unload = idebugger_unload;
890 	iface->quit = idebugger_quit;
891 	iface->abort = idebugger_abort;
892 	iface->run = idebugger_run;
893 	iface->step_in = idebugger_step_in;
894 	iface->step_over = idebugger_step_over;
895 	iface->step_out = idebugger_step_out;
896 	iface->run_to = idebugger_run_to;
897 	iface->run_from = idebugger_run_from;
898 	iface->exit = idebugger_exit;
899 	iface->interrupt = idebugger_interrupt;
900 
901 	iface->inspect = idebugger_inspect;
902 	iface->evaluate = idebugger_evaluate;
903 
904 	iface->print = idebugger_print;
905 	iface->list_local = idebugger_list_local;
906 	iface->list_argument = idebugger_list_argument;
907 	iface->info_frame = idebugger_info_frame;
908 	iface->info_signal = idebugger_info_signal;
909 	iface->info_sharedlib = idebugger_info_sharedlib;
910 	iface->info_args = idebugger_info_args;
911 	iface->info_target = idebugger_info_target;
912 	iface->info_program = idebugger_info_program;
913 	iface->info_udot = idebugger_info_udot;
914 	iface->info_variables = idebugger_info_variables;
915 	iface->handle_signal = idebugger_handle_signal;
916 	iface->list_frame = idebugger_list_frame;
917 	iface->set_frame = idebugger_set_frame;
918 	iface->list_thread = idebugger_list_thread;
919 	iface->set_thread = idebugger_set_thread;
920 	iface->info_thread = idebugger_info_thread;
921 	iface->dump_stack_trace = idebugger_dump_stack_trace;
922 
923 	iface->send_command = idebugger_send_command;
924 
925 	iface->callback = idebugger_callback;
926 
927 	iface->enable_log = idebugger_enable_log;
928 	iface->disable_log = idebugger_disable_log;
929 }
930 
931 
932 /* Implementation of IAnjutaDebuggerBreakpoint interface
933  *---------------------------------------------------------------------------*/
934 
935 static gint
idebugger_breakpoint_implement(IAnjutaDebuggerBreakpoint * plugin,GError ** err)936 idebugger_breakpoint_implement (IAnjutaDebuggerBreakpoint *plugin, GError **err)
937 {
938 	/* gdb implement all interface methods */
939 	return IANJUTA_DEBUGGER_BREAKPOINT_SET_AT_ADDRESS
940 		| IANJUTA_DEBUGGER_BREAKPOINT_SET_AT_FUNCTION
941 		| IANJUTA_DEBUGGER_BREAKPOINT_ENABLE
942 		| IANJUTA_DEBUGGER_BREAKPOINT_IGNORE
943 		| IANJUTA_DEBUGGER_BREAKPOINT_CONDITION;
944 }
945 
946 static gboolean
idebugger_breakpoint_add_at_line(IAnjutaDebuggerBreakpoint * plugin,const gchar * file,guint line,IAnjutaDebuggerBreakpointCallback callback,gpointer user_data,GError ** err)947 idebugger_breakpoint_add_at_line (IAnjutaDebuggerBreakpoint *plugin, const gchar* file, guint line, IAnjutaDebuggerBreakpointCallback callback, gpointer user_data, GError **err)
948 {
949 	GdbPlugin *this = ANJUTA_PLUGIN_GDB (plugin);
950 
951 	debugger_add_breakpoint_at_line (this->debugger, file, line, callback, user_data);
952 
953 	return TRUE;
954 }
955 
956 static gboolean
idebugger_breakpoint_add_at_function(IAnjutaDebuggerBreakpoint * plugin,const gchar * file,const gchar * function,IAnjutaDebuggerBreakpointCallback callback,gpointer user_data,GError ** err)957 idebugger_breakpoint_add_at_function (IAnjutaDebuggerBreakpoint *plugin, const gchar* file, const gchar* function, IAnjutaDebuggerBreakpointCallback callback, gpointer user_data, GError **err)
958 {
959 	GdbPlugin *this = ANJUTA_PLUGIN_GDB (plugin);
960 
961 	debugger_add_breakpoint_at_function (this->debugger, *file == '\0' ? NULL : file, function, callback, user_data);
962 
963 	return TRUE;
964 }
965 
966 static gboolean
idebugger_breakpoint_add_at_address(IAnjutaDebuggerBreakpoint * plugin,gulong address,IAnjutaDebuggerBreakpointCallback callback,gpointer user_data,GError ** err)967 idebugger_breakpoint_add_at_address (IAnjutaDebuggerBreakpoint *plugin, gulong address, IAnjutaDebuggerBreakpointCallback callback, gpointer user_data, GError **err)
968 {
969 	GdbPlugin *this = ANJUTA_PLUGIN_GDB (plugin);
970 
971 	debugger_add_breakpoint_at_address (this->debugger, address, callback, user_data);
972 
973 	return TRUE;
974 }
975 
976 static gboolean
idebugger_breakpoint_enable(IAnjutaDebuggerBreakpoint * plugin,guint id,gboolean enable,IAnjutaDebuggerBreakpointCallback callback,gpointer user_data,GError ** err)977 idebugger_breakpoint_enable (IAnjutaDebuggerBreakpoint *plugin, guint id, gboolean enable, IAnjutaDebuggerBreakpointCallback callback, gpointer user_data, GError **err)
978 {
979 	GdbPlugin *this = ANJUTA_PLUGIN_GDB (plugin);
980 
981 	debugger_enable_breakpoint (this->debugger, id, enable, callback, user_data);
982 
983 	return TRUE;
984 }
985 
986 static gboolean
idebugger_breakpoint_ignore(IAnjutaDebuggerBreakpoint * plugin,guint id,guint ignore,IAnjutaDebuggerBreakpointCallback callback,gpointer user_data,GError ** err)987 idebugger_breakpoint_ignore (IAnjutaDebuggerBreakpoint *plugin, guint id, guint ignore, IAnjutaDebuggerBreakpointCallback callback, gpointer user_data, GError **err)
988 {
989 	GdbPlugin *this = ANJUTA_PLUGIN_GDB (plugin);
990 
991 	debugger_ignore_breakpoint (this->debugger, id, ignore, callback, user_data);
992 
993 	return TRUE;
994 }
995 
996 static gboolean
idebugger_breakpoint_condition(IAnjutaDebuggerBreakpoint * plugin,guint id,const gchar * condition,IAnjutaDebuggerBreakpointCallback callback,gpointer user_data,GError ** err)997 idebugger_breakpoint_condition (IAnjutaDebuggerBreakpoint *plugin, guint id, const gchar *condition, IAnjutaDebuggerBreakpointCallback callback, gpointer user_data, GError **err)
998 {
999 	GdbPlugin *this = ANJUTA_PLUGIN_GDB (plugin);
1000 
1001 	debugger_condition_breakpoint (this->debugger, id, condition, callback, user_data);
1002 
1003 	return TRUE;
1004 }
1005 
1006 static gboolean
idebugger_breakpoint_remove(IAnjutaDebuggerBreakpoint * plugin,guint id,IAnjutaDebuggerBreakpointCallback callback,gpointer user_data,GError ** err)1007 idebugger_breakpoint_remove (IAnjutaDebuggerBreakpoint *plugin, guint id, IAnjutaDebuggerBreakpointCallback callback, gpointer user_data, GError **err)
1008 {
1009 	GdbPlugin *this = ANJUTA_PLUGIN_GDB (plugin);
1010 
1011 	debugger_remove_breakpoint (this->debugger, id, callback, user_data);
1012 
1013 	return TRUE;
1014 }
1015 
1016 static gboolean
idebugger_breakpoint_list(IAnjutaDebuggerBreakpoint * plugin,IAnjutaDebuggerGListCallback callback,gpointer user_data,GError ** err)1017 idebugger_breakpoint_list (IAnjutaDebuggerBreakpoint *plugin, IAnjutaDebuggerGListCallback callback, gpointer user_data, GError **err)
1018 {
1019 	GdbPlugin *this = ANJUTA_PLUGIN_GDB (plugin);
1020 
1021 	debugger_list_breakpoint (this->debugger, callback, user_data);
1022 
1023 	return TRUE;
1024 }
1025 
1026 static void
idebugger_breakpoint_iface_init(IAnjutaDebuggerBreakpointIface * iface)1027 idebugger_breakpoint_iface_init (IAnjutaDebuggerBreakpointIface *iface)
1028 {
1029 	iface->implement_breakpoint = idebugger_breakpoint_implement;
1030 	iface->set_breakpoint_at_line = idebugger_breakpoint_add_at_line;
1031 	iface->clear_breakpoint = idebugger_breakpoint_remove;
1032 	iface->list_breakpoint = idebugger_breakpoint_list;
1033 	iface->set_breakpoint_at_address = idebugger_breakpoint_add_at_address;
1034 	iface->set_breakpoint_at_function = idebugger_breakpoint_add_at_function;
1035 	iface->enable_breakpoint = idebugger_breakpoint_enable;
1036 	iface->ignore_breakpoint = idebugger_breakpoint_ignore;
1037 	iface->condition_breakpoint = idebugger_breakpoint_condition;
1038 }
1039 
1040 /* Implementation of IAnjutaDebuggerRegister interface
1041  *---------------------------------------------------------------------------*/
1042 
1043 static gboolean
idebugger_register_list(IAnjutaDebuggerRegister * plugin,IAnjutaDebuggerGListCallback callback,gpointer user_data,GError ** err)1044 idebugger_register_list (IAnjutaDebuggerRegister *plugin, IAnjutaDebuggerGListCallback callback , gpointer user_data, GError **err)
1045 {
1046 	GdbPlugin *this = ANJUTA_PLUGIN_GDB (plugin);
1047 
1048 	debugger_list_register (this->debugger, callback, user_data);
1049 
1050 	return TRUE;
1051 }
1052 
1053 static gboolean
idebugger_register_update(IAnjutaDebuggerRegister * plugin,IAnjutaDebuggerGListCallback callback,gpointer user_data,GError ** err)1054 idebugger_register_update (IAnjutaDebuggerRegister *plugin, IAnjutaDebuggerGListCallback callback , gpointer user_data, GError **err)
1055 {
1056 	GdbPlugin *this = ANJUTA_PLUGIN_GDB (plugin);
1057 
1058 	debugger_update_register (this->debugger, callback, user_data);
1059 
1060 	return TRUE;
1061 }
1062 
1063 static gboolean
idebugger_register_write(IAnjutaDebuggerRegister * plugin,IAnjutaDebuggerRegisterData * value,GError ** err)1064 idebugger_register_write (IAnjutaDebuggerRegister *plugin, IAnjutaDebuggerRegisterData *value, GError **err)
1065 {
1066 	GdbPlugin *this = ANJUTA_PLUGIN_GDB (plugin);
1067 
1068 	debugger_write_register (this->debugger, value->name, value->value);
1069 
1070 	return TRUE;
1071 }
1072 
1073 static void
idebugger_register_iface_init(IAnjutaDebuggerRegisterIface * iface)1074 idebugger_register_iface_init (IAnjutaDebuggerRegisterIface *iface)
1075 {
1076 	iface->list_register = idebugger_register_list;
1077 	iface->update_register = idebugger_register_update;
1078 	iface->write_register = idebugger_register_write;
1079 }
1080 
1081 /* Implementation of IAnjutaDebuggerMemory interface
1082  *---------------------------------------------------------------------------*/
1083 
1084 static gboolean
idebugger_memory_inspect(IAnjutaDebuggerMemory * plugin,gulong address,guint length,IAnjutaDebuggerMemoryCallback callback,gpointer user_data,GError ** err)1085 idebugger_memory_inspect (IAnjutaDebuggerMemory *plugin, gulong address, guint length, IAnjutaDebuggerMemoryCallback callback , gpointer user_data, GError **err)
1086 {
1087 	GdbPlugin *this = ANJUTA_PLUGIN_GDB (plugin);
1088 
1089 	debugger_inspect_memory (this->debugger, address, length, callback, user_data);
1090 
1091 	return TRUE;
1092 }
1093 
1094 static void
idebugger_memory_iface_init(IAnjutaDebuggerMemoryIface * iface)1095 idebugger_memory_iface_init (IAnjutaDebuggerMemoryIface *iface)
1096 {
1097 	iface->inspect = idebugger_memory_inspect;
1098 }
1099 
1100 /* Implementation of IAnjutaDebuggerInstruction interface
1101  *---------------------------------------------------------------------------*/
1102 
1103 static gboolean
idebugger_instruction_disassemble(IAnjutaDebuggerInstruction * plugin,gulong address,guint length,IAnjutaDebuggerInstructionCallback callback,gpointer user_data,GError ** err)1104 idebugger_instruction_disassemble (IAnjutaDebuggerInstruction *plugin, gulong address, guint length, IAnjutaDebuggerInstructionCallback callback , gpointer user_data, GError **err)
1105 {
1106 	GdbPlugin *this = (GdbPlugin *)plugin;
1107 
1108 	debugger_disassemble (this->debugger, address, length, callback, user_data);
1109 
1110 	return TRUE;
1111 }
1112 
1113 static gboolean
idebugger_instruction_step_in(IAnjutaDebuggerInstruction * plugin,GError ** err)1114 idebugger_instruction_step_in (IAnjutaDebuggerInstruction *plugin, GError **err)
1115 {
1116 	GdbPlugin *this = ANJUTA_PLUGIN_GDB (plugin);
1117 
1118 	debugger_stepi_in (this->debugger);
1119 
1120 	return TRUE;
1121 }
1122 
1123 static gboolean
idebugger_instruction_step_over(IAnjutaDebuggerInstruction * plugin,GError ** err)1124 idebugger_instruction_step_over (IAnjutaDebuggerInstruction *plugin, GError **err)
1125 {
1126 	GdbPlugin *this = ANJUTA_PLUGIN_GDB (plugin);
1127 
1128 	debugger_stepi_over (this->debugger);
1129 
1130 	return TRUE;
1131 }
1132 
1133 static gboolean
idebugger_instruction_run_to_address(IAnjutaDebuggerInstruction * plugin,gulong address,GError ** err)1134 idebugger_instruction_run_to_address (IAnjutaDebuggerInstruction *plugin, gulong address, GError **err)
1135 {
1136 	GdbPlugin *this = ANJUTA_PLUGIN_GDB (plugin);
1137 
1138 	debugger_run_to_address (this->debugger, address);
1139 
1140 	return TRUE;
1141 }
1142 
1143 static gboolean
idebugger_instruction_run_from_address(IAnjutaDebuggerInstruction * plugin,gulong address,GError ** err)1144 idebugger_instruction_run_from_address (IAnjutaDebuggerInstruction *plugin, gulong address, GError **err)
1145 {
1146 	GdbPlugin *this = ANJUTA_PLUGIN_GDB (plugin);
1147 
1148 	debugger_run_from_address (this->debugger, address);
1149 
1150 	return TRUE;
1151 }
1152 
1153 static void
idebugger_instruction_iface_init(IAnjutaDebuggerInstructionIface * iface)1154 idebugger_instruction_iface_init (IAnjutaDebuggerInstructionIface *iface)
1155 {
1156 	iface->disassemble = idebugger_instruction_disassemble;
1157 	iface->step_in_instruction = idebugger_instruction_step_in;
1158 	iface->step_over_instruction = idebugger_instruction_step_over;
1159 	iface->run_to_address = idebugger_instruction_run_to_address;
1160 	iface->run_from_address = idebugger_instruction_run_from_address;
1161 }
1162 
1163 /* Implementation of IAnjutaDebuggerVariable interface
1164  *---------------------------------------------------------------------------*/
1165 
1166 static gboolean
idebugger_variable_destroy(IAnjutaDebuggerVariable * plugin,const gchar * name,GError ** error)1167 idebugger_variable_destroy (IAnjutaDebuggerVariable *plugin, const gchar *name, GError **error)
1168 {
1169 	GdbPlugin *gdb = ANJUTA_PLUGIN_GDB (plugin);
1170 	gchar *quoted;
1171 
1172 	quoted = quote_expression (name);
1173 	debugger_delete_variable (gdb->debugger, quoted);
1174 	g_free (quoted);
1175 
1176 	return TRUE;
1177 }
1178 
1179 static gboolean
idebugger_variable_evaluate(IAnjutaDebuggerVariable * plugin,const gchar * name,IAnjutaDebuggerGCharCallback callback,gpointer user_data,GError ** error)1180 idebugger_variable_evaluate (IAnjutaDebuggerVariable *plugin, const gchar *name, IAnjutaDebuggerGCharCallback callback , gpointer user_data, GError **error)
1181 {
1182 	GdbPlugin *gdb = ANJUTA_PLUGIN_GDB (plugin);
1183 
1184 	debugger_evaluate_variable (gdb->debugger, name, callback, user_data);
1185 
1186 	return TRUE;
1187 }
1188 
1189 static gboolean
idebugger_variable_assign(IAnjutaDebuggerVariable * plugin,const gchar * name,const gchar * value,GError ** error)1190 idebugger_variable_assign (IAnjutaDebuggerVariable *plugin, const gchar *name, const gchar *value, GError **error)
1191 {
1192 	GdbPlugin *gdb = ANJUTA_PLUGIN_GDB (plugin);
1193 	gchar *quoted;
1194 
1195 	quoted = quote_expression (name);
1196 	debugger_assign_variable (gdb->debugger, quoted, value);
1197 	g_free (quoted);
1198 
1199 	return TRUE;
1200 }
1201 
1202 static gboolean
idebugger_variable_list_children(IAnjutaDebuggerVariable * plugin,const gchar * name,guint from,IAnjutaDebuggerGListCallback callback,gpointer user_data,GError ** error)1203 idebugger_variable_list_children (IAnjutaDebuggerVariable *plugin, const gchar *name, guint from, IAnjutaDebuggerGListCallback callback , gpointer user_data, GError **error)
1204 {
1205 	GdbPlugin *gdb = ANJUTA_PLUGIN_GDB (plugin);
1206 	gchar *quoted;
1207 
1208 	quoted = quote_expression (name);
1209 	debugger_list_variable_children (gdb->debugger, quoted, from, callback, user_data);
1210 	g_free (quoted);
1211 
1212 	return TRUE;
1213 }
1214 
1215 static gboolean
idebugger_variable_create(IAnjutaDebuggerVariable * plugin,const gchar * name,IAnjutaDebuggerVariableCallback callback,gpointer user_data,GError ** error)1216 idebugger_variable_create (IAnjutaDebuggerVariable *plugin, const gchar *name, IAnjutaDebuggerVariableCallback callback , gpointer user_data, GError **error)
1217 {
1218 	GdbPlugin *gdb = ANJUTA_PLUGIN_GDB (plugin);
1219 	gchar *quoted;
1220 
1221 	quoted = quote_expression (name);
1222 	debugger_create_variable (gdb->debugger, quoted, callback, user_data);
1223 	g_free (quoted);
1224 
1225 	return TRUE;
1226 }
1227 
1228 static gboolean
idebugger_variable_update(IAnjutaDebuggerVariable * plugin,IAnjutaDebuggerGListCallback callback,gpointer user_data,GError ** error)1229 idebugger_variable_update (IAnjutaDebuggerVariable *plugin, IAnjutaDebuggerGListCallback callback , gpointer user_data, GError **error)
1230 {
1231 	GdbPlugin *gdb = ANJUTA_PLUGIN_GDB (plugin);
1232 
1233 	debugger_update_variable (gdb->debugger, callback, user_data);
1234 
1235 	return TRUE;
1236 }
1237 
1238 static void
idebugger_variable_iface_init(IAnjutaDebuggerVariableIface * iface)1239 idebugger_variable_iface_init (IAnjutaDebuggerVariableIface *iface)
1240 {
1241 	iface->destroy = idebugger_variable_destroy;
1242 	iface->evaluate = idebugger_variable_evaluate;
1243 	iface->assign = idebugger_variable_assign;
1244 	iface->list_children = idebugger_variable_list_children;
1245 	iface->create = idebugger_variable_create;
1246 	iface->update = idebugger_variable_update;
1247 }
1248 
1249 /* Implementation of IAnjutaPreference interface
1250  *---------------------------------------------------------------------------*/
1251 
1252 static void
ipreferences_merge(IAnjutaPreferences * ipref,AnjutaPreferences * prefs,GError ** error)1253 ipreferences_merge(IAnjutaPreferences* ipref, AnjutaPreferences* prefs, GError** error)
1254 {
1255 	gdb_merge_preferences (prefs, &(ANJUTA_PLUGIN_GDB (ipref)->pretty_printers));
1256 }
1257 
1258 static void
ipreferences_unmerge(IAnjutaPreferences * ipref,AnjutaPreferences * prefs,GError ** error)1259 ipreferences_unmerge(IAnjutaPreferences* ipref, AnjutaPreferences* prefs, GError** error)
1260 {
1261 	gdb_unmerge_preferences (prefs);
1262 }
1263 
1264 static void
ipreferences_iface_init(IAnjutaPreferencesIface * iface)1265 ipreferences_iface_init(IAnjutaPreferencesIface* iface)
1266 {
1267 	iface->merge = ipreferences_merge;
1268 	iface->unmerge = ipreferences_unmerge;
1269 }
1270 
1271 ANJUTA_PLUGIN_BEGIN (GdbPlugin, gdb_plugin);
1272 ANJUTA_PLUGIN_ADD_INTERFACE(idebugger, IANJUTA_TYPE_DEBUGGER);
1273 ANJUTA_PLUGIN_ADD_INTERFACE(idebugger_breakpoint, IANJUTA_TYPE_DEBUGGER_BREAKPOINT);
1274 ANJUTA_PLUGIN_ADD_INTERFACE(idebugger_register, IANJUTA_TYPE_DEBUGGER_REGISTER);
1275 ANJUTA_PLUGIN_ADD_INTERFACE(idebugger_memory, IANJUTA_TYPE_DEBUGGER_MEMORY);
1276 ANJUTA_PLUGIN_ADD_INTERFACE(idebugger_instruction, IANJUTA_TYPE_DEBUGGER_INSTRUCTION);
1277 ANJUTA_PLUGIN_ADD_INTERFACE(idebugger_variable, IANJUTA_TYPE_DEBUGGER_VARIABLE);
1278 ANJUTA_PLUGIN_ADD_INTERFACE (ipreferences, IANJUTA_TYPE_PREFERENCES);
1279 ANJUTA_PLUGIN_END;
1280 
1281 ANJUTA_SIMPLE_PLUGIN (GdbPlugin, gdb_plugin);
1282