Updated Spanish translation
[anjuta-git-plugin.git] / plugins / gdb / plugin.c
blob46fbe0c26fe998c49badb78a9ca2e71b4bc37ffe
1 /* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*- */
2 /*
3 plugin.c
4 Copyright (C) 2005 Sebastien Granjoux
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.
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.
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
22 * Implement the IAnjutaDebugger interface.
25 #include <config.h>
27 /*#define DEBUG*/
28 #include <libanjuta/anjuta-debug.h>
30 #include "plugin.h"
32 #include "debugger.h"
34 #include <libanjuta/interfaces/ianjuta-debugger.h>
35 #include <libanjuta/interfaces/ianjuta-debugger-breakpoint.h>
36 #include <libanjuta/interfaces/ianjuta-debugger-register.h>
37 #include <libanjuta/interfaces/ianjuta-debugger-memory.h>
38 #include <libanjuta/interfaces/ianjuta-debugger-instruction.h>
39 #include <libanjuta/interfaces/ianjuta-debugger-variable.h>
40 #include <libanjuta/interfaces/ianjuta-terminal.h>
41 #include <libanjuta/anjuta-plugin.h>
42 #include <signal.h>
44 /* Plugin type
45 *---------------------------------------------------------------------------*/
47 struct _GdbPlugin
49 AnjutaPlugin parent;
51 /* Debugger */
52 Debugger *debugger;
54 /* Output callback data */
55 IAnjutaDebuggerOutputCallback output_callback;
56 gpointer output_user_data;
58 /* Log message window */
59 IAnjutaMessageView *view;
61 /* Terminal */
62 pid_t term_pid;
65 struct _GdbPluginClass
67 AnjutaPluginClass parent_class;
70 /* Terminal functions
71 *---------------------------------------------------------------------------*/
73 static void
74 gdb_plugin_stop_terminal (GdbPlugin* plugin)
76 DEBUG_PRINT ("In function: gdb_plugin_stop_terminal()");
78 if (plugin->term_pid > 0) {
79 kill (plugin->term_pid, SIGTERM);
80 plugin->term_pid = -1;
84 static gchar*
85 gdb_plugin_start_terminal (GdbPlugin* plugin)
87 gchar *file, *cmd;
88 gchar *tty = NULL;
89 IAnjutaTerminal *term;
91 DEBUG_PRINT ("In function: gdb_plugin_start_terminal() previous pid %d", plugin->term_pid);
93 /* Close previous terminal if needed */
94 gdb_plugin_stop_terminal (plugin);
96 /* Get terminal plugin */
97 term = anjuta_shell_get_interface (ANJUTA_PLUGIN (plugin)->shell, IAnjutaTerminal, NULL);
98 if (term == NULL)
101 anjuta_util_dialog_error (GTK_WINDOW (ANJUTA_PLUGIN (plugin)->shell),
102 _("Anjuta terminal plugin is not installed. The program will be run without a terminal."));
104 return NULL;
107 /* Check if anjuta launcher is here */
108 if (anjuta_util_prog_is_installed ("anjuta_launcher", TRUE) == FALSE)
110 return NULL;
113 file = anjuta_util_get_a_tmp_file();
114 if (mkfifo (file, 0664) < 0)
116 anjuta_util_dialog_error (GTK_WINDOW (ANJUTA_PLUGIN (plugin)->shell),
117 _("Failed to create fifo file named %s. The program will run without a terminal."), file);
118 g_free (file);
120 return NULL;
123 /* Launch terminal */
124 cmd = g_strconcat ("anjuta_launcher --__debug_terminal ", file, NULL);
125 plugin->term_pid = ianjuta_terminal_execute_command (term, NULL, cmd, NULL, NULL);
126 g_free (cmd);
128 if (plugin->term_pid > 0)
131 * Warning: call to fopen() may be blocked if the terminal is
132 * not properly started. I don't know how to handle this. May
133 * be opening as non-blocking will solve this .
135 g_file_get_contents (file, &tty, NULL, NULL); /* Ok, take the risk. */
136 if (tty)
138 g_strchomp (tty); /* anjuta_launcher add a end of line after the terminal name */
139 if (strcmp(tty, "__ERROR__") == 0)
141 g_free (tty);
142 tty = NULL;
146 remove (file);
147 g_free (file);
149 if (tty == NULL)
151 anjuta_util_dialog_error (GTK_WINDOW (ANJUTA_PLUGIN (plugin)->shell),
152 _("Cannot start terminal for debugging."));
153 gdb_plugin_stop_terminal (plugin);
156 return tty;
159 /* Private functions
160 *---------------------------------------------------------------------------*/
162 static void
163 on_debugger_stopped (GdbPlugin *self, GError *err)
165 if (self->debugger != NULL)
167 g_signal_handlers_disconnect_by_func (self, G_CALLBACK (on_debugger_stopped), self);
168 debugger_free (self->debugger);
169 self->debugger = NULL;
170 gdb_plugin_stop_terminal (self);
174 static void
175 gdb_plugin_initialize (GdbPlugin *this)
177 GtkWindow *parent;
179 /* debugger can be not NULL, if initialize is called several times
180 * or if debugger_stopped signal has not been emitted */
181 if (this->debugger != NULL)
183 on_debugger_stopped (this, NULL);
186 parent = GTK_WINDOW (ANJUTA_PLUGIN (this)->shell);
187 this->debugger = debugger_new (parent, G_OBJECT (this));
188 g_signal_connect_swapped (this, "debugger-stopped", G_CALLBACK (on_debugger_stopped), this);
189 debugger_set_output_callback (this->debugger, this->output_callback, this->output_user_data);
190 if (this->view) debugger_set_log (this->debugger, this->view);
193 /* AnjutaPlugin functions
194 *---------------------------------------------------------------------------*/
196 static gboolean
197 gdb_plugin_activate_plugin (AnjutaPlugin* plugin)
199 /* GdbPlugin *this = ANJUTA_PLUGIN_GDB (plugin); */
201 DEBUG_PRINT ("GDB: Activating Gdb plugin...");
203 return TRUE;
206 static gboolean
207 gdb_plugin_deactivate_plugin (AnjutaPlugin* plugin)
209 GdbPlugin *this = ANJUTA_PLUGIN_GDB (plugin);
211 DEBUG_PRINT ("GDB: Deactivating Gdb plugin...");
213 if (this->debugger != NULL)
215 debugger_free (this->debugger);
216 this->debugger = NULL;
219 return TRUE;
222 /* GObject functions
223 *---------------------------------------------------------------------------*/
225 /* Used in dispose and finalize */
226 static gpointer parent_class;
228 /* instance_init is the constructor. All functions should work after this
229 * call. */
231 static void
232 gdb_plugin_instance_init (GObject* obj)
234 GdbPlugin *this = ANJUTA_PLUGIN_GDB (obj);
236 this->debugger = NULL;
237 this->output_callback = NULL;
238 this->term_pid = 0;
241 /* dispose is the first destruction step. It is used to unref object created
242 * with instance_init in order to break reference counting cycles. This
243 * function could be called several times. All function should still work
244 * after this call. It has to called its parents.*/
246 static void
247 gdb_plugin_dispose (GObject* obj)
249 GdbPlugin *this = ANJUTA_PLUGIN_GDB (obj);
251 if (this->debugger != NULL)
253 debugger_free (this->debugger);
254 this->debugger = NULL;
256 G_OBJECT_CLASS (parent_class)->dispose (obj);
259 /* finalize is the last destruction step. It must free all memory allocated
260 * with instance_init. It is called only one time just before releasing all
261 * memory */
263 static void
264 gdb_plugin_finalize (GObject* obj)
266 G_OBJECT_CLASS (parent_class)->finalize (obj);
269 /* class_init intialize the class itself not the instance */
271 static void
272 gdb_plugin_class_init (GObjectClass* klass)
274 AnjutaPluginClass *plugin_class = ANJUTA_PLUGIN_CLASS (klass);
276 parent_class = g_type_class_peek_parent (klass);
278 plugin_class->activate = gdb_plugin_activate_plugin;
279 plugin_class->deactivate = gdb_plugin_deactivate_plugin;
280 klass->dispose = gdb_plugin_dispose;
281 klass->finalize = gdb_plugin_finalize;
284 /* Implementation of IAnjutaDebugger interface
285 *---------------------------------------------------------------------------*/
287 static IAnjutaDebuggerState
288 idebugger_get_state (IAnjutaDebugger *plugin, GError **err)
290 GdbPlugin *this = ANJUTA_PLUGIN_GDB (plugin);
292 if (this->debugger == NULL)
294 return IANJUTA_DEBUGGER_STOPPED;
296 else
298 return debugger_get_state (this->debugger);
303 static gboolean
304 idebugger_load (IAnjutaDebugger *plugin, const gchar *file, const gchar* mime_type,
305 const GList *search_dirs, GError **err)
307 GdbPlugin *this = ANJUTA_PLUGIN_GDB (plugin);
308 gboolean is_libtool = FALSE;
310 /* Check allowed mime type */
311 if (mime_type == NULL)
313 /* Hope that the target is supported */
315 else if ((strcmp (mime_type, "application/x-executable") == 0) ||
316 (strcmp (mime_type, "application/octet-stream") == 0))
318 /* Supported target */
320 else if (strcmp (mime_type, "application/x-shellscript") == 0)
322 /* FIXME: We should really do more checks to confirm that
323 * this target is indeed libtool target
325 is_libtool = TRUE;
327 else if (strcmp (mime_type, "application/x-core") == 0)
329 /* Supported target */
331 else
333 /* Not supported target */
334 return TRUE;
337 // Start debugger
338 gdb_plugin_initialize (this);
340 return debugger_start (this->debugger, search_dirs, file, is_libtool);
343 static gboolean
344 idebugger_unload (IAnjutaDebugger *plugin, GError **err)
346 GdbPlugin *this = ANJUTA_PLUGIN_GDB (plugin);
348 debugger_stop (this->debugger);
350 return TRUE;
353 static gboolean
354 idebugger_set_working_directory (IAnjutaDebugger *plugin, const gchar *directory, GError **err)
356 GdbPlugin *self = ANJUTA_PLUGIN_GDB (plugin);
358 debugger_set_working_directory (self->debugger, directory);
360 return TRUE;
363 static gboolean
364 idebugger_set_environment (IAnjutaDebugger *plugin, gchar **variables, GError **err)
366 GdbPlugin *self = ANJUTA_PLUGIN_GDB (plugin);
368 debugger_set_environment (self->debugger, variables);
370 return TRUE;
373 static gboolean
374 idebugger_attach (IAnjutaDebugger *plugin, pid_t pid, const GList *search_dirs, GError **err)
376 GdbPlugin *this = ANJUTA_PLUGIN_GDB (plugin);
378 // Start debugger
379 gdb_plugin_initialize (this);
380 debugger_start (this->debugger, search_dirs, NULL, FALSE);
381 debugger_attach_process (this->debugger, pid);
383 return TRUE;
386 static gboolean
387 idebugger_start (IAnjutaDebugger *plugin, const gchar *argument, gboolean terminal, gboolean stop, GError **err)
389 GdbPlugin *this = ANJUTA_PLUGIN_GDB (plugin);
390 gchar *tty;
392 tty = terminal ? gdb_plugin_start_terminal (this) : NULL;
393 debugger_start_program (this->debugger, argument, tty, stop);
394 g_free (tty);
396 return TRUE;
399 static gboolean
400 idebugger_quit (IAnjutaDebugger *plugin, GError **err)
402 GdbPlugin *this = ANJUTA_PLUGIN_GDB (plugin);
404 if (!debugger_stop (this->debugger))
406 DEBUG_PRINT ("set error");
407 g_set_error (err, IANJUTA_DEBUGGER_ERROR, IANJUTA_DEBUGGER_CANCEL, "Command cancelled by user");
409 return FALSE;
411 else
413 return TRUE;
417 static gboolean
418 idebugger_abort (IAnjutaDebugger *plugin, GError **err)
420 GdbPlugin *this = ANJUTA_PLUGIN_GDB (plugin);
422 DEBUG_PRINT ("idebugger abort\n");
423 if (!debugger_abort (this->debugger))
425 g_set_error (err, IANJUTA_DEBUGGER_ERROR, IANJUTA_DEBUGGER_CANCEL, "Command cancelled by user");
427 return FALSE;
429 else
431 return TRUE;
435 static gboolean
436 idebugger_run (IAnjutaDebugger *plugin, GError **err)
438 GdbPlugin *this = ANJUTA_PLUGIN_GDB (plugin);
440 debugger_run (this->debugger);
442 return TRUE;
445 static gboolean
446 idebugger_step_in (IAnjutaDebugger *plugin, GError **err)
448 GdbPlugin *this = ANJUTA_PLUGIN_GDB (plugin);
450 debugger_step_in (this->debugger);
452 return TRUE;
455 static gboolean
456 idebugger_step_over (IAnjutaDebugger *plugin, GError **err)
458 GdbPlugin *this = ANJUTA_PLUGIN_GDB (plugin);
460 debugger_step_over (this->debugger);
462 return TRUE;
465 static gboolean
466 idebugger_run_to (IAnjutaDebugger *plugin, const gchar *file,
467 gint line, GError **err)
469 GdbPlugin *this = ANJUTA_PLUGIN_GDB (plugin);
471 debugger_run_to_position (this->debugger, file, line);
473 return TRUE;
476 static gboolean
477 idebugger_step_out (IAnjutaDebugger *plugin, GError **err)
479 GdbPlugin *this = ANJUTA_PLUGIN_GDB (plugin);
481 debugger_step_out (this->debugger);
483 return TRUE;
486 static gboolean
487 idebugger_exit (IAnjutaDebugger *plugin, GError **err)
489 GdbPlugin *this = ANJUTA_PLUGIN_GDB (plugin);
491 debugger_stop_program (this->debugger);
493 return TRUE;
496 static gboolean
497 idebugger_interrupt (IAnjutaDebugger *plugin, GError **err)
499 GdbPlugin *this = ANJUTA_PLUGIN_GDB (plugin);
501 debugger_interrupt (this->debugger);
503 return TRUE;
506 static gboolean
507 idebugger_inspect (IAnjutaDebugger *plugin, const gchar *name, IAnjutaDebuggerCallback callback, gpointer user_data, GError **err)
509 GdbPlugin *this = ANJUTA_PLUGIN_GDB (plugin);
511 debugger_evaluate (this->debugger, name, callback, user_data);
513 return TRUE;
516 static gboolean
517 idebugger_evaluate (IAnjutaDebugger *plugin, const gchar *name, const gchar *value, IAnjutaDebuggerCallback callback, gpointer user_data, GError **err)
519 GdbPlugin *this = ANJUTA_PLUGIN_GDB (plugin);
520 gchar* buf;
522 buf = g_strconcat ("\"", name, " = ", value, "\"", NULL);
523 debugger_evaluate (this->debugger, buf, callback, user_data);
524 g_free (buf);
526 return TRUE;
529 static gboolean
530 idebugger_send_command (IAnjutaDebugger *plugin, const gchar* command, GError **err)
532 GdbPlugin *this = ANJUTA_PLUGIN_GDB (plugin);
534 debugger_command (this->debugger, command, FALSE, NULL, NULL);
536 return TRUE;
539 static gboolean
540 idebugger_print (IAnjutaDebugger *plugin, const gchar* variable, IAnjutaDebuggerCallback callback, gpointer user_data, GError **err)
542 GdbPlugin *this = ANJUTA_PLUGIN_GDB (plugin);
544 debugger_print (this->debugger, variable, callback, user_data);
546 return TRUE;
549 static gboolean
550 idebugger_list_local (IAnjutaDebugger *plugin, IAnjutaDebuggerCallback callback , gpointer user_data, GError **err)
552 GdbPlugin *this = ANJUTA_PLUGIN_GDB (plugin);
554 debugger_list_local (this->debugger, callback, user_data);
556 return TRUE;
559 static gboolean
560 idebugger_list_argument (IAnjutaDebugger *plugin, IAnjutaDebuggerCallback callback , gpointer user_data, GError **err)
562 GdbPlugin *this = ANJUTA_PLUGIN_GDB (plugin);
564 debugger_list_argument (this->debugger, callback, user_data);
566 return TRUE;
569 static gboolean
570 idebugger_info_signal (IAnjutaDebugger *plugin, IAnjutaDebuggerCallback callback , gpointer user_data, GError **err)
572 GdbPlugin *this = ANJUTA_PLUGIN_GDB (plugin);
574 debugger_info_signal (this->debugger, callback, user_data);
576 return TRUE;
579 static gboolean
580 idebugger_info_sharedlib (IAnjutaDebugger *plugin, IAnjutaDebuggerCallback callback , gpointer user_data, GError **err)
582 GdbPlugin *this = ANJUTA_PLUGIN_GDB (plugin);
584 debugger_info_sharedlib (this->debugger, callback, user_data);
586 return TRUE;
589 static gboolean
590 idebugger_handle_signal (IAnjutaDebugger *plugin, const gchar* name, gboolean stop, gboolean print, gboolean ignore, GError **err)
592 gchar* cmd;
593 GdbPlugin *this = ANJUTA_PLUGIN_GDB (plugin);
595 cmd = g_strdup_printf("handle %s %sstop %sprint %spass", name, stop ? "" : "no", print ? "" : "no", ignore ? "" : "no");
596 debugger_command (this->debugger, cmd, FALSE, NULL, NULL);
597 g_free (cmd);
599 return TRUE;
602 static gboolean
603 idebugger_info_frame (IAnjutaDebugger *plugin, guint frame, IAnjutaDebuggerCallback callback , gpointer user_data, GError **err)
605 GdbPlugin *this = ANJUTA_PLUGIN_GDB (plugin);
607 debugger_info_frame (this->debugger, frame, callback, user_data);
609 return TRUE;
612 static gboolean
613 idebugger_info_args (IAnjutaDebugger *plugin, IAnjutaDebuggerCallback callback , gpointer user_data, GError **err)
615 GdbPlugin *this = ANJUTA_PLUGIN_GDB (plugin);
617 debugger_info_args (this->debugger, callback, user_data);
619 return TRUE;
622 static gboolean
623 idebugger_info_target (IAnjutaDebugger *plugin, IAnjutaDebuggerCallback callback , gpointer user_data, GError **err)
625 GdbPlugin *this = ANJUTA_PLUGIN_GDB (plugin);
627 debugger_info_target (this->debugger, callback, user_data);
629 return TRUE;
632 static gboolean
633 idebugger_info_program (IAnjutaDebugger *plugin, IAnjutaDebuggerCallback callback , gpointer user_data, GError **err)
635 GdbPlugin *this = ANJUTA_PLUGIN_GDB (plugin);
637 debugger_info_program (this->debugger, callback, user_data);
639 return TRUE;
642 static gboolean
643 idebugger_info_udot (IAnjutaDebugger *plugin, IAnjutaDebuggerCallback callback , gpointer user_data, GError **err)
645 GdbPlugin *this = ANJUTA_PLUGIN_GDB (plugin);
647 debugger_info_udot (this->debugger, callback, user_data);
649 return TRUE;
652 static gboolean
653 idebugger_info_variables (IAnjutaDebugger *plugin, IAnjutaDebuggerCallback callback , gpointer user_data, GError **err)
655 GdbPlugin *this = ANJUTA_PLUGIN_GDB (plugin);
657 debugger_info_variables (this->debugger, callback, user_data);
659 return TRUE;
662 static gboolean
663 idebugger_set_frame (IAnjutaDebugger *plugin, guint frame, GError **err)
665 GdbPlugin *this = ANJUTA_PLUGIN_GDB (plugin);
667 debugger_set_frame (this->debugger, frame);
669 return TRUE;
672 static gboolean
673 idebugger_list_frame (IAnjutaDebugger *plugin, IAnjutaDebuggerCallback callback , gpointer user_data, GError **err)
675 GdbPlugin *this = ANJUTA_PLUGIN_GDB (plugin);
677 debugger_list_frame (this->debugger, callback, user_data);
679 return TRUE;
682 static gboolean
683 idebugger_set_thread (IAnjutaDebugger *plugin, gint thread, GError **err)
685 GdbPlugin *this = ANJUTA_PLUGIN_GDB (plugin);
687 debugger_set_thread (this->debugger, thread);
689 return TRUE;
692 static gboolean
693 idebugger_list_thread (IAnjutaDebugger *plugin, IAnjutaDebuggerCallback callback , gpointer user_data, GError **err)
695 GdbPlugin *this = ANJUTA_PLUGIN_GDB (plugin);
697 debugger_list_thread (this->debugger, callback, user_data);
699 return TRUE;
702 static gboolean
703 idebugger_info_thread (IAnjutaDebugger *plugin, gint thread, IAnjutaDebuggerCallback callback , gpointer user_data, GError **err)
705 GdbPlugin *this = ANJUTA_PLUGIN_GDB (plugin);
707 debugger_info_thread (this->debugger, thread, callback, user_data);
709 return TRUE;
712 static gboolean
713 idebugger_list_register (IAnjutaDebugger *plugin, IAnjutaDebuggerCallback callback , gpointer user_data, GError **err)
715 //GdbPlugin *this = ANJUTA_PLUGIN_GDB (plugin);
717 //debugger_list_register (this->debugger, callback, user_data);
719 return TRUE;
722 static gboolean
723 idebugger_callback (IAnjutaDebugger *plugin, IAnjutaDebuggerCallback callback , gpointer user_data, GError **err)
726 callback (NULL, user_data, NULL);
728 return TRUE;
731 static void
732 idebugger_enable_log (IAnjutaDebugger *plugin, IAnjutaMessageView *log, GError **err)
734 GdbPlugin *this = ANJUTA_PLUGIN_GDB (plugin);
736 this->view = log;
737 if (this->debugger)
738 debugger_set_log (this->debugger, log);
741 static void
742 idebugger_disable_log (IAnjutaDebugger *plugin, GError **err)
744 GdbPlugin *this = ANJUTA_PLUGIN_GDB (plugin);
746 this->view = NULL;
747 if (this->debugger)
748 debugger_set_log (this->debugger, NULL);
751 static void
752 idebugger_iface_init (IAnjutaDebuggerIface *iface)
754 iface->get_state = idebugger_get_state;
755 iface->attach = idebugger_attach;
756 iface->load = idebugger_load;
757 iface->set_working_directory = idebugger_set_working_directory;
758 iface->set_environment = idebugger_set_environment;
759 iface->start = idebugger_start;
760 iface->unload = idebugger_unload;
761 iface->quit = idebugger_quit;
762 iface->abort = idebugger_abort;
763 iface->run = idebugger_run;
764 iface->step_in = idebugger_step_in;
765 iface->step_over = idebugger_step_over;
766 iface->step_out = idebugger_step_out;
767 iface->run_to = idebugger_run_to;
768 iface->exit = idebugger_exit;
769 iface->interrupt = idebugger_interrupt;
771 iface->inspect = idebugger_inspect;
772 iface->evaluate = idebugger_evaluate;
774 iface->print = idebugger_print;
775 iface->list_local = idebugger_list_local;
776 iface->list_argument = idebugger_list_argument;
777 iface->info_frame = idebugger_info_frame;
778 iface->info_signal = idebugger_info_signal;
779 iface->info_sharedlib = idebugger_info_sharedlib;
780 iface->info_args = idebugger_info_args;
781 iface->info_target = idebugger_info_target;
782 iface->info_program = idebugger_info_program;
783 iface->info_udot = idebugger_info_udot;
784 iface->info_variables = idebugger_info_variables;
785 iface->handle_signal = idebugger_handle_signal;
786 iface->list_frame = idebugger_list_frame;
787 iface->set_frame = idebugger_set_frame;
788 iface->list_thread = idebugger_list_thread;
789 iface->set_thread = idebugger_set_thread;
790 iface->info_thread = idebugger_info_thread;
791 iface->list_register = idebugger_list_register;
793 iface->send_command = idebugger_send_command;
795 iface->callback = idebugger_callback;
797 iface->enable_log = idebugger_enable_log;
798 iface->disable_log = idebugger_disable_log;
802 /* Implementation of IAnjutaDebuggerBreakpoint interface
803 *---------------------------------------------------------------------------*/
805 static gint
806 idebugger_breakpoint_implement (IAnjutaDebuggerBreakpoint *plugin, GError **err)
808 /* gdb implement all interface methods */
809 return IANJUTA_DEBUGGER_BREAKPOINT_SET_AT_ADDRESS
810 | IANJUTA_DEBUGGER_BREAKPOINT_SET_AT_FUNCTION
811 | IANJUTA_DEBUGGER_BREAKPOINT_ENABLE
812 | IANJUTA_DEBUGGER_BREAKPOINT_IGNORE
813 | IANJUTA_DEBUGGER_BREAKPOINT_CONDITION;
816 static gboolean
817 idebugger_breakpoint_add_at_line (IAnjutaDebuggerBreakpoint *plugin, const gchar* file, guint line, IAnjutaDebuggerCallback callback, gpointer user_data, GError **err)
819 GdbPlugin *this = ANJUTA_PLUGIN_GDB (plugin);
821 debugger_add_breakpoint_at_line (this->debugger, file, line, callback, user_data);
823 return TRUE;
826 static gboolean
827 idebugger_breakpoint_add_at_function (IAnjutaDebuggerBreakpoint *plugin, const gchar* file, const gchar* function, IAnjutaDebuggerCallback callback, gpointer user_data, GError **err)
829 GdbPlugin *this = ANJUTA_PLUGIN_GDB (plugin);
831 debugger_add_breakpoint_at_function (this->debugger, *file == '\0' ? NULL : file, function, callback, user_data);
833 return TRUE;
836 static gboolean
837 idebugger_breakpoint_add_at_address (IAnjutaDebuggerBreakpoint *plugin, gulong address, IAnjutaDebuggerCallback callback, gpointer user_data, GError **err)
839 GdbPlugin *this = ANJUTA_PLUGIN_GDB (plugin);
841 debugger_add_breakpoint_at_address (this->debugger, address, callback, user_data);
843 return TRUE;
846 static gboolean
847 idebugger_breakpoint_enable (IAnjutaDebuggerBreakpoint *plugin, guint id, gboolean enable, IAnjutaDebuggerCallback callback, gpointer user_data, GError **err)
849 GdbPlugin *this = ANJUTA_PLUGIN_GDB (plugin);
851 debugger_enable_breakpoint (this->debugger, id, enable, callback, user_data);
853 return TRUE;
856 static gboolean
857 idebugger_breakpoint_ignore (IAnjutaDebuggerBreakpoint *plugin, guint id, guint ignore, IAnjutaDebuggerCallback callback, gpointer user_data, GError **err)
859 GdbPlugin *this = ANJUTA_PLUGIN_GDB (plugin);
861 debugger_ignore_breakpoint (this->debugger, id, ignore, callback, user_data);
863 return TRUE;
866 static gboolean
867 idebugger_breakpoint_condition (IAnjutaDebuggerBreakpoint *plugin, guint id, const gchar *condition, IAnjutaDebuggerCallback callback, gpointer user_data, GError **err)
869 GdbPlugin *this = ANJUTA_PLUGIN_GDB (plugin);
871 debugger_condition_breakpoint (this->debugger, id, condition, callback, user_data);
873 return TRUE;
876 static gboolean
877 idebugger_breakpoint_remove (IAnjutaDebuggerBreakpoint *plugin, guint id, IAnjutaDebuggerCallback callback, gpointer user_data, GError **err)
879 GdbPlugin *this = ANJUTA_PLUGIN_GDB (plugin);
881 debugger_remove_breakpoint (this->debugger, id, callback, user_data);
883 return TRUE;
886 static gboolean
887 idebugger_breakpoint_list (IAnjutaDebuggerBreakpoint *plugin, IAnjutaDebuggerCallback callback, gpointer user_data, GError **err)
889 GdbPlugin *this = ANJUTA_PLUGIN_GDB (plugin);
891 debugger_list_breakpoint (this->debugger, callback, user_data);
893 return TRUE;
896 static void
897 idebugger_breakpoint_iface_init (IAnjutaDebuggerBreakpointIface *iface)
899 iface->implement = idebugger_breakpoint_implement;
900 iface->set_at_line = idebugger_breakpoint_add_at_line;
901 iface->clear = idebugger_breakpoint_remove;
902 iface->list = idebugger_breakpoint_list;
903 iface->set_at_address = idebugger_breakpoint_add_at_address;
904 iface->set_at_function = idebugger_breakpoint_add_at_function;
905 iface->enable = idebugger_breakpoint_enable;
906 iface->ignore = idebugger_breakpoint_ignore;
907 iface->condition = idebugger_breakpoint_condition;
910 /* Implementation of IAnjutaDebuggerRegister interface
911 *---------------------------------------------------------------------------*/
913 static gboolean
914 idebugger_register_list (IAnjutaDebuggerRegister *plugin, IAnjutaDebuggerCallback callback , gpointer user_data, GError **err)
916 GdbPlugin *this = ANJUTA_PLUGIN_GDB (plugin);
918 debugger_list_register (this->debugger, callback, user_data);
920 return TRUE;
923 static gboolean
924 idebugger_register_update (IAnjutaDebuggerRegister *plugin, IAnjutaDebuggerCallback callback , gpointer user_data, GError **err)
926 GdbPlugin *this = ANJUTA_PLUGIN_GDB (plugin);
928 debugger_update_register (this->debugger, callback, user_data);
930 return TRUE;
933 static gboolean
934 idebugger_register_write (IAnjutaDebuggerRegister *plugin, IAnjutaDebuggerRegisterData *value, GError **err)
936 GdbPlugin *this = ANJUTA_PLUGIN_GDB (plugin);
938 debugger_write_register (this->debugger, value->name, value->value);
940 return TRUE;
943 static void
944 idebugger_register_iface_init (IAnjutaDebuggerRegisterIface *iface)
946 iface->list = idebugger_register_list;
947 iface->update = idebugger_register_update;
948 iface->write = idebugger_register_write;
951 /* Implementation of IAnjutaDebuggerMemory interface
952 *---------------------------------------------------------------------------*/
954 static gboolean
955 idebugger_memory_inspect (IAnjutaDebuggerMemory *plugin, gulong address, guint length, IAnjutaDebuggerCallback callback , gpointer user_data, GError **err)
957 GdbPlugin *this = ANJUTA_PLUGIN_GDB (plugin);
959 debugger_inspect_memory (this->debugger, address, length, callback, user_data);
961 return TRUE;
964 static void
965 idebugger_memory_iface_init (IAnjutaDebuggerMemoryIface *iface)
967 iface->inspect = idebugger_memory_inspect;
970 /* Implementation of IAnjutaDebuggerInstruction interface
971 *---------------------------------------------------------------------------*/
973 static gboolean
974 idebugger_instruction_disassemble (IAnjutaDebuggerInstruction *plugin, gulong address, guint length, IAnjutaDebuggerCallback callback , gpointer user_data, GError **err)
976 GdbPlugin *this = (GdbPlugin *)plugin;
978 debugger_disassemble (this->debugger, address, length, callback, user_data);
980 return TRUE;
983 static gboolean
984 idebugger_instruction_step_in (IAnjutaDebuggerInstruction *plugin, GError **err)
986 GdbPlugin *this = ANJUTA_PLUGIN_GDB (plugin);
988 debugger_stepi_in (this->debugger);
990 return TRUE;
993 static gboolean
994 idebugger_instruction_step_over (IAnjutaDebuggerInstruction *plugin, GError **err)
996 GdbPlugin *this = ANJUTA_PLUGIN_GDB (plugin);
998 debugger_stepi_over (this->debugger);
1000 return TRUE;
1003 static gboolean
1004 idebugger_instruction_run_to_address (IAnjutaDebuggerInstruction *plugin, gulong address, GError **err)
1006 GdbPlugin *this = ANJUTA_PLUGIN_GDB (plugin);
1008 debugger_run_to_address (this->debugger, address);
1010 return TRUE;
1013 static void
1014 idebugger_instruction_iface_init (IAnjutaDebuggerInstructionIface *iface)
1016 iface->disassemble = idebugger_instruction_disassemble;
1017 iface->step_in = idebugger_instruction_step_in;
1018 iface->step_over = idebugger_instruction_step_over;
1019 iface->run_to_address = idebugger_instruction_run_to_address;
1022 /* Implementation of IAnjutaDebuggerVariable interface
1023 *---------------------------------------------------------------------------*/
1025 static gboolean
1026 idebugger_variable_destroy (IAnjutaDebuggerVariable *plugin, const gchar *name, GError **error)
1028 GdbPlugin *gdb = ANJUTA_PLUGIN_GDB (plugin);
1030 debugger_delete_variable (gdb->debugger, name);
1032 return TRUE;
1035 static gboolean
1036 idebugger_variable_evaluate (IAnjutaDebuggerVariable *plugin, const gchar *name, IAnjutaDebuggerCallback callback , gpointer user_data, GError **error)
1038 GdbPlugin *gdb = ANJUTA_PLUGIN_GDB (plugin);
1040 debugger_evaluate_variable (gdb->debugger, name, callback, user_data);
1042 return TRUE;
1045 static gboolean
1046 idebugger_variable_assign (IAnjutaDebuggerVariable *plugin, const gchar *name, const gchar *value, GError **error)
1048 GdbPlugin *gdb = ANJUTA_PLUGIN_GDB (plugin);
1050 debugger_assign_variable (gdb->debugger, name, value);
1052 return TRUE;
1055 static gboolean
1056 idebugger_variable_list_children (IAnjutaDebuggerVariable *plugin, const gchar *name, IAnjutaDebuggerCallback callback , gpointer user_data, GError **error)
1058 GdbPlugin *gdb = ANJUTA_PLUGIN_GDB (plugin);
1060 debugger_list_variable_children (gdb->debugger, name, callback, user_data);
1062 return TRUE;
1065 static gboolean
1066 idebugger_variable_create (IAnjutaDebuggerVariable *plugin, const gchar *name, IAnjutaDebuggerCallback callback , gpointer user_data, GError **error)
1068 GdbPlugin *gdb = ANJUTA_PLUGIN_GDB (plugin);
1070 debugger_create_variable (gdb->debugger, name, callback, user_data);
1072 return TRUE;
1075 static gboolean
1076 idebugger_variable_update (IAnjutaDebuggerVariable *plugin, IAnjutaDebuggerCallback callback , gpointer user_data, GError **error)
1078 GdbPlugin *gdb = ANJUTA_PLUGIN_GDB (plugin);
1080 debugger_update_variable (gdb->debugger, callback, user_data);
1082 return TRUE;
1085 static void
1086 idebugger_variable_iface_init (IAnjutaDebuggerVariableIface *iface)
1088 iface->destroy = idebugger_variable_destroy;
1089 iface->evaluate = idebugger_variable_evaluate;
1090 iface->assign = idebugger_variable_assign;
1091 iface->list_children = idebugger_variable_list_children;
1092 iface->create = idebugger_variable_create;
1093 iface->update = idebugger_variable_update;
1096 ANJUTA_PLUGIN_BEGIN (GdbPlugin, gdb_plugin);
1097 ANJUTA_PLUGIN_ADD_INTERFACE(idebugger, IANJUTA_TYPE_DEBUGGER);
1098 ANJUTA_PLUGIN_ADD_INTERFACE(idebugger_breakpoint, IANJUTA_TYPE_DEBUGGER_BREAKPOINT);
1099 ANJUTA_PLUGIN_ADD_INTERFACE(idebugger_register, IANJUTA_TYPE_DEBUGGER_REGISTER);
1100 ANJUTA_PLUGIN_ADD_INTERFACE(idebugger_memory, IANJUTA_TYPE_DEBUGGER_MEMORY);
1101 ANJUTA_PLUGIN_ADD_INTERFACE(idebugger_instruction, IANJUTA_TYPE_DEBUGGER_INSTRUCTION);
1102 ANJUTA_PLUGIN_ADD_INTERFACE(idebugger_variable, IANJUTA_TYPE_DEBUGGER_VARIABLE);
1103 ANJUTA_PLUGIN_END;
1105 ANJUTA_SIMPLE_PLUGIN (GdbPlugin, gdb_plugin);