Fix a Gtk warning when checking path input in the log viewer.
[anjuta-git-plugin.git] / plugins / gdb / plugin.c
blobffe21f08b2b1b680d84df14db952864bc2f3b078
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, GFile* file,
467 gint line, GError **err)
469 GdbPlugin *this = ANJUTA_PLUGIN_GDB (plugin);
470 gchar* path = g_file_get_path (file);
472 debugger_run_to_position (this->debugger, path, line);
474 return TRUE;
477 static gboolean
478 idebugger_step_out (IAnjutaDebugger *plugin, GError **err)
480 GdbPlugin *this = ANJUTA_PLUGIN_GDB (plugin);
482 debugger_step_out (this->debugger);
484 return TRUE;
487 static gboolean
488 idebugger_exit (IAnjutaDebugger *plugin, GError **err)
490 GdbPlugin *this = ANJUTA_PLUGIN_GDB (plugin);
492 debugger_stop_program (this->debugger);
494 return TRUE;
497 static gboolean
498 idebugger_interrupt (IAnjutaDebugger *plugin, GError **err)
500 GdbPlugin *this = ANJUTA_PLUGIN_GDB (plugin);
502 debugger_interrupt (this->debugger);
504 return TRUE;
507 static gboolean
508 idebugger_inspect (IAnjutaDebugger *plugin, const gchar *name, IAnjutaDebuggerCallback callback, gpointer user_data, GError **err)
510 GdbPlugin *this = ANJUTA_PLUGIN_GDB (plugin);
512 debugger_evaluate (this->debugger, name, callback, user_data);
514 return TRUE;
517 static gboolean
518 idebugger_evaluate (IAnjutaDebugger *plugin, const gchar *name, const gchar *value, IAnjutaDebuggerCallback callback, gpointer user_data, GError **err)
520 GdbPlugin *this = ANJUTA_PLUGIN_GDB (plugin);
521 gchar* buf;
523 buf = g_strconcat ("\"", name, " = ", value, "\"", NULL);
524 debugger_evaluate (this->debugger, buf, callback, user_data);
525 g_free (buf);
527 return TRUE;
530 static gboolean
531 idebugger_send_command (IAnjutaDebugger *plugin, const gchar* command, GError **err)
533 GdbPlugin *this = ANJUTA_PLUGIN_GDB (plugin);
535 debugger_command (this->debugger, command, FALSE, NULL, NULL);
537 return TRUE;
540 static gboolean
541 idebugger_print (IAnjutaDebugger *plugin, const gchar* variable, IAnjutaDebuggerCallback callback, gpointer user_data, GError **err)
543 GdbPlugin *this = ANJUTA_PLUGIN_GDB (plugin);
545 debugger_print (this->debugger, variable, callback, user_data);
547 return TRUE;
550 static gboolean
551 idebugger_list_local (IAnjutaDebugger *plugin, IAnjutaDebuggerCallback callback , gpointer user_data, GError **err)
553 GdbPlugin *this = ANJUTA_PLUGIN_GDB (plugin);
555 debugger_list_local (this->debugger, callback, user_data);
557 return TRUE;
560 static gboolean
561 idebugger_list_argument (IAnjutaDebugger *plugin, IAnjutaDebuggerCallback callback , gpointer user_data, GError **err)
563 GdbPlugin *this = ANJUTA_PLUGIN_GDB (plugin);
565 debugger_list_argument (this->debugger, callback, user_data);
567 return TRUE;
570 static gboolean
571 idebugger_info_signal (IAnjutaDebugger *plugin, IAnjutaDebuggerCallback callback , gpointer user_data, GError **err)
573 GdbPlugin *this = ANJUTA_PLUGIN_GDB (plugin);
575 debugger_info_signal (this->debugger, callback, user_data);
577 return TRUE;
580 static gboolean
581 idebugger_info_sharedlib (IAnjutaDebugger *plugin, IAnjutaDebuggerCallback callback , gpointer user_data, GError **err)
583 GdbPlugin *this = ANJUTA_PLUGIN_GDB (plugin);
585 debugger_info_sharedlib (this->debugger, callback, user_data);
587 return TRUE;
590 static gboolean
591 idebugger_handle_signal (IAnjutaDebugger *plugin, const gchar* name, gboolean stop, gboolean print, gboolean ignore, GError **err)
593 gchar* cmd;
594 GdbPlugin *this = ANJUTA_PLUGIN_GDB (plugin);
596 cmd = g_strdup_printf("handle %s %sstop %sprint %spass", name, stop ? "" : "no", print ? "" : "no", ignore ? "" : "no");
597 debugger_command (this->debugger, cmd, FALSE, NULL, NULL);
598 g_free (cmd);
600 return TRUE;
603 static gboolean
604 idebugger_info_frame (IAnjutaDebugger *plugin, guint frame, IAnjutaDebuggerCallback callback , gpointer user_data, GError **err)
606 GdbPlugin *this = ANJUTA_PLUGIN_GDB (plugin);
608 debugger_info_frame (this->debugger, frame, callback, user_data);
610 return TRUE;
613 static gboolean
614 idebugger_info_args (IAnjutaDebugger *plugin, IAnjutaDebuggerCallback callback , gpointer user_data, GError **err)
616 GdbPlugin *this = ANJUTA_PLUGIN_GDB (plugin);
618 debugger_info_args (this->debugger, callback, user_data);
620 return TRUE;
623 static gboolean
624 idebugger_info_target (IAnjutaDebugger *plugin, IAnjutaDebuggerCallback callback , gpointer user_data, GError **err)
626 GdbPlugin *this = ANJUTA_PLUGIN_GDB (plugin);
628 debugger_info_target (this->debugger, callback, user_data);
630 return TRUE;
633 static gboolean
634 idebugger_info_program (IAnjutaDebugger *plugin, IAnjutaDebuggerCallback callback , gpointer user_data, GError **err)
636 GdbPlugin *this = ANJUTA_PLUGIN_GDB (plugin);
638 debugger_info_program (this->debugger, callback, user_data);
640 return TRUE;
643 static gboolean
644 idebugger_info_udot (IAnjutaDebugger *plugin, IAnjutaDebuggerCallback callback , gpointer user_data, GError **err)
646 GdbPlugin *this = ANJUTA_PLUGIN_GDB (plugin);
648 debugger_info_udot (this->debugger, callback, user_data);
650 return TRUE;
653 static gboolean
654 idebugger_info_variables (IAnjutaDebugger *plugin, IAnjutaDebuggerCallback callback , gpointer user_data, GError **err)
656 GdbPlugin *this = ANJUTA_PLUGIN_GDB (plugin);
658 debugger_info_variables (this->debugger, callback, user_data);
660 return TRUE;
663 static gboolean
664 idebugger_set_frame (IAnjutaDebugger *plugin, guint frame, GError **err)
666 GdbPlugin *this = ANJUTA_PLUGIN_GDB (plugin);
668 debugger_set_frame (this->debugger, frame);
670 return TRUE;
673 static gboolean
674 idebugger_list_frame (IAnjutaDebugger *plugin, IAnjutaDebuggerCallback callback , gpointer user_data, GError **err)
676 GdbPlugin *this = ANJUTA_PLUGIN_GDB (plugin);
678 debugger_list_frame (this->debugger, callback, user_data);
680 return TRUE;
683 static gboolean
684 idebugger_set_thread (IAnjutaDebugger *plugin, gint thread, GError **err)
686 GdbPlugin *this = ANJUTA_PLUGIN_GDB (plugin);
688 debugger_set_thread (this->debugger, thread);
690 return TRUE;
693 static gboolean
694 idebugger_list_thread (IAnjutaDebugger *plugin, IAnjutaDebuggerCallback callback , gpointer user_data, GError **err)
696 GdbPlugin *this = ANJUTA_PLUGIN_GDB (plugin);
698 debugger_list_thread (this->debugger, callback, user_data);
700 return TRUE;
703 static gboolean
704 idebugger_info_thread (IAnjutaDebugger *plugin, gint thread, IAnjutaDebuggerCallback callback , gpointer user_data, GError **err)
706 GdbPlugin *this = ANJUTA_PLUGIN_GDB (plugin);
708 debugger_info_thread (this->debugger, thread, callback, user_data);
710 return TRUE;
713 static gboolean
714 idebugger_list_register (IAnjutaDebugger *plugin, IAnjutaDebuggerCallback callback , gpointer user_data, GError **err)
716 //GdbPlugin *this = ANJUTA_PLUGIN_GDB (plugin);
718 //debugger_list_register (this->debugger, callback, user_data);
720 return TRUE;
723 static gboolean
724 idebugger_callback (IAnjutaDebugger *plugin, IAnjutaDebuggerCallback callback , gpointer user_data, GError **err)
727 callback (NULL, user_data, NULL);
729 return TRUE;
732 static void
733 idebugger_enable_log (IAnjutaDebugger *plugin, IAnjutaMessageView *log, GError **err)
735 GdbPlugin *this = ANJUTA_PLUGIN_GDB (plugin);
737 this->view = log;
738 if (this->debugger)
739 debugger_set_log (this->debugger, log);
742 static void
743 idebugger_disable_log (IAnjutaDebugger *plugin, GError **err)
745 GdbPlugin *this = ANJUTA_PLUGIN_GDB (plugin);
747 this->view = NULL;
748 if (this->debugger)
749 debugger_set_log (this->debugger, NULL);
752 static void
753 idebugger_iface_init (IAnjutaDebuggerIface *iface)
755 iface->get_state = idebugger_get_state;
756 iface->attach = idebugger_attach;
757 iface->load = idebugger_load;
758 iface->set_working_directory = idebugger_set_working_directory;
759 iface->set_environment = idebugger_set_environment;
760 iface->start = idebugger_start;
761 iface->unload = idebugger_unload;
762 iface->quit = idebugger_quit;
763 iface->abort = idebugger_abort;
764 iface->run = idebugger_run;
765 iface->step_in = idebugger_step_in;
766 iface->step_over = idebugger_step_over;
767 iface->step_out = idebugger_step_out;
768 iface->run_to = idebugger_run_to;
769 iface->exit = idebugger_exit;
770 iface->interrupt = idebugger_interrupt;
772 iface->inspect = idebugger_inspect;
773 iface->evaluate = idebugger_evaluate;
775 iface->print = idebugger_print;
776 iface->list_local = idebugger_list_local;
777 iface->list_argument = idebugger_list_argument;
778 iface->info_frame = idebugger_info_frame;
779 iface->info_signal = idebugger_info_signal;
780 iface->info_sharedlib = idebugger_info_sharedlib;
781 iface->info_args = idebugger_info_args;
782 iface->info_target = idebugger_info_target;
783 iface->info_program = idebugger_info_program;
784 iface->info_udot = idebugger_info_udot;
785 iface->info_variables = idebugger_info_variables;
786 iface->handle_signal = idebugger_handle_signal;
787 iface->list_frame = idebugger_list_frame;
788 iface->set_frame = idebugger_set_frame;
789 iface->list_thread = idebugger_list_thread;
790 iface->set_thread = idebugger_set_thread;
791 iface->info_thread = idebugger_info_thread;
792 iface->list_register = idebugger_list_register;
794 iface->send_command = idebugger_send_command;
796 iface->callback = idebugger_callback;
798 iface->enable_log = idebugger_enable_log;
799 iface->disable_log = idebugger_disable_log;
803 /* Implementation of IAnjutaDebuggerBreakpoint interface
804 *---------------------------------------------------------------------------*/
806 static gint
807 idebugger_breakpoint_implement (IAnjutaDebuggerBreakpoint *plugin, GError **err)
809 /* gdb implement all interface methods */
810 return IANJUTA_DEBUGGER_BREAKPOINT_SET_AT_ADDRESS
811 | IANJUTA_DEBUGGER_BREAKPOINT_SET_AT_FUNCTION
812 | IANJUTA_DEBUGGER_BREAKPOINT_ENABLE
813 | IANJUTA_DEBUGGER_BREAKPOINT_IGNORE
814 | IANJUTA_DEBUGGER_BREAKPOINT_CONDITION;
817 static gboolean
818 idebugger_breakpoint_add_at_line (IAnjutaDebuggerBreakpoint *plugin, const gchar* file, guint line, IAnjutaDebuggerCallback callback, gpointer user_data, GError **err)
820 GdbPlugin *this = ANJUTA_PLUGIN_GDB (plugin);
822 debugger_add_breakpoint_at_line (this->debugger, file, line, callback, user_data);
824 return TRUE;
827 static gboolean
828 idebugger_breakpoint_add_at_function (IAnjutaDebuggerBreakpoint *plugin, const gchar* file, const gchar* function, IAnjutaDebuggerCallback callback, gpointer user_data, GError **err)
830 GdbPlugin *this = ANJUTA_PLUGIN_GDB (plugin);
832 debugger_add_breakpoint_at_function (this->debugger, *file == '\0' ? NULL : file, function, callback, user_data);
834 return TRUE;
837 static gboolean
838 idebugger_breakpoint_add_at_address (IAnjutaDebuggerBreakpoint *plugin, gulong address, IAnjutaDebuggerCallback callback, gpointer user_data, GError **err)
840 GdbPlugin *this = ANJUTA_PLUGIN_GDB (plugin);
842 debugger_add_breakpoint_at_address (this->debugger, address, callback, user_data);
844 return TRUE;
847 static gboolean
848 idebugger_breakpoint_enable (IAnjutaDebuggerBreakpoint *plugin, guint id, gboolean enable, IAnjutaDebuggerCallback callback, gpointer user_data, GError **err)
850 GdbPlugin *this = ANJUTA_PLUGIN_GDB (plugin);
852 debugger_enable_breakpoint (this->debugger, id, enable, callback, user_data);
854 return TRUE;
857 static gboolean
858 idebugger_breakpoint_ignore (IAnjutaDebuggerBreakpoint *plugin, guint id, guint ignore, IAnjutaDebuggerCallback callback, gpointer user_data, GError **err)
860 GdbPlugin *this = ANJUTA_PLUGIN_GDB (plugin);
862 debugger_ignore_breakpoint (this->debugger, id, ignore, callback, user_data);
864 return TRUE;
867 static gboolean
868 idebugger_breakpoint_condition (IAnjutaDebuggerBreakpoint *plugin, guint id, const gchar *condition, IAnjutaDebuggerCallback callback, gpointer user_data, GError **err)
870 GdbPlugin *this = ANJUTA_PLUGIN_GDB (plugin);
872 debugger_condition_breakpoint (this->debugger, id, condition, callback, user_data);
874 return TRUE;
877 static gboolean
878 idebugger_breakpoint_remove (IAnjutaDebuggerBreakpoint *plugin, guint id, IAnjutaDebuggerCallback callback, gpointer user_data, GError **err)
880 GdbPlugin *this = ANJUTA_PLUGIN_GDB (plugin);
882 debugger_remove_breakpoint (this->debugger, id, callback, user_data);
884 return TRUE;
887 static gboolean
888 idebugger_breakpoint_list (IAnjutaDebuggerBreakpoint *plugin, IAnjutaDebuggerCallback callback, gpointer user_data, GError **err)
890 GdbPlugin *this = ANJUTA_PLUGIN_GDB (plugin);
892 debugger_list_breakpoint (this->debugger, callback, user_data);
894 return TRUE;
897 static void
898 idebugger_breakpoint_iface_init (IAnjutaDebuggerBreakpointIface *iface)
900 iface->implement = idebugger_breakpoint_implement;
901 iface->set_at_line = idebugger_breakpoint_add_at_line;
902 iface->clear = idebugger_breakpoint_remove;
903 iface->list = idebugger_breakpoint_list;
904 iface->set_at_address = idebugger_breakpoint_add_at_address;
905 iface->set_at_function = idebugger_breakpoint_add_at_function;
906 iface->enable = idebugger_breakpoint_enable;
907 iface->ignore = idebugger_breakpoint_ignore;
908 iface->condition = idebugger_breakpoint_condition;
911 /* Implementation of IAnjutaDebuggerRegister interface
912 *---------------------------------------------------------------------------*/
914 static gboolean
915 idebugger_register_list (IAnjutaDebuggerRegister *plugin, IAnjutaDebuggerCallback callback , gpointer user_data, GError **err)
917 GdbPlugin *this = ANJUTA_PLUGIN_GDB (plugin);
919 debugger_list_register (this->debugger, callback, user_data);
921 return TRUE;
924 static gboolean
925 idebugger_register_update (IAnjutaDebuggerRegister *plugin, IAnjutaDebuggerCallback callback , gpointer user_data, GError **err)
927 GdbPlugin *this = ANJUTA_PLUGIN_GDB (plugin);
929 debugger_update_register (this->debugger, callback, user_data);
931 return TRUE;
934 static gboolean
935 idebugger_register_write (IAnjutaDebuggerRegister *plugin, IAnjutaDebuggerRegisterData *value, GError **err)
937 GdbPlugin *this = ANJUTA_PLUGIN_GDB (plugin);
939 debugger_write_register (this->debugger, value->name, value->value);
941 return TRUE;
944 static void
945 idebugger_register_iface_init (IAnjutaDebuggerRegisterIface *iface)
947 iface->list = idebugger_register_list;
948 iface->update = idebugger_register_update;
949 iface->write = idebugger_register_write;
952 /* Implementation of IAnjutaDebuggerMemory interface
953 *---------------------------------------------------------------------------*/
955 static gboolean
956 idebugger_memory_inspect (IAnjutaDebuggerMemory *plugin, gulong address, guint length, IAnjutaDebuggerCallback callback , gpointer user_data, GError **err)
958 GdbPlugin *this = ANJUTA_PLUGIN_GDB (plugin);
960 debugger_inspect_memory (this->debugger, address, length, callback, user_data);
962 return TRUE;
965 static void
966 idebugger_memory_iface_init (IAnjutaDebuggerMemoryIface *iface)
968 iface->inspect = idebugger_memory_inspect;
971 /* Implementation of IAnjutaDebuggerInstruction interface
972 *---------------------------------------------------------------------------*/
974 static gboolean
975 idebugger_instruction_disassemble (IAnjutaDebuggerInstruction *plugin, gulong address, guint length, IAnjutaDebuggerCallback callback , gpointer user_data, GError **err)
977 GdbPlugin *this = (GdbPlugin *)plugin;
979 debugger_disassemble (this->debugger, address, length, callback, user_data);
981 return TRUE;
984 static gboolean
985 idebugger_instruction_step_in (IAnjutaDebuggerInstruction *plugin, GError **err)
987 GdbPlugin *this = ANJUTA_PLUGIN_GDB (plugin);
989 debugger_stepi_in (this->debugger);
991 return TRUE;
994 static gboolean
995 idebugger_instruction_step_over (IAnjutaDebuggerInstruction *plugin, GError **err)
997 GdbPlugin *this = ANJUTA_PLUGIN_GDB (plugin);
999 debugger_stepi_over (this->debugger);
1001 return TRUE;
1004 static gboolean
1005 idebugger_instruction_run_to_address (IAnjutaDebuggerInstruction *plugin, gulong address, GError **err)
1007 GdbPlugin *this = ANJUTA_PLUGIN_GDB (plugin);
1009 debugger_run_to_address (this->debugger, address);
1011 return TRUE;
1014 static void
1015 idebugger_instruction_iface_init (IAnjutaDebuggerInstructionIface *iface)
1017 iface->disassemble = idebugger_instruction_disassemble;
1018 iface->step_in = idebugger_instruction_step_in;
1019 iface->step_over = idebugger_instruction_step_over;
1020 iface->run_to_address = idebugger_instruction_run_to_address;
1023 /* Implementation of IAnjutaDebuggerVariable interface
1024 *---------------------------------------------------------------------------*/
1026 static gboolean
1027 idebugger_variable_destroy (IAnjutaDebuggerVariable *plugin, const gchar *name, GError **error)
1029 GdbPlugin *gdb = ANJUTA_PLUGIN_GDB (plugin);
1031 debugger_delete_variable (gdb->debugger, name);
1033 return TRUE;
1036 static gboolean
1037 idebugger_variable_evaluate (IAnjutaDebuggerVariable *plugin, const gchar *name, IAnjutaDebuggerCallback callback , gpointer user_data, GError **error)
1039 GdbPlugin *gdb = ANJUTA_PLUGIN_GDB (plugin);
1041 debugger_evaluate_variable (gdb->debugger, name, callback, user_data);
1043 return TRUE;
1046 static gboolean
1047 idebugger_variable_assign (IAnjutaDebuggerVariable *plugin, const gchar *name, const gchar *value, GError **error)
1049 GdbPlugin *gdb = ANJUTA_PLUGIN_GDB (plugin);
1051 debugger_assign_variable (gdb->debugger, name, value);
1053 return TRUE;
1056 static gboolean
1057 idebugger_variable_list_children (IAnjutaDebuggerVariable *plugin, const gchar *name, IAnjutaDebuggerCallback callback , gpointer user_data, GError **error)
1059 GdbPlugin *gdb = ANJUTA_PLUGIN_GDB (plugin);
1061 debugger_list_variable_children (gdb->debugger, name, callback, user_data);
1063 return TRUE;
1066 static gboolean
1067 idebugger_variable_create (IAnjutaDebuggerVariable *plugin, const gchar *name, IAnjutaDebuggerCallback callback , gpointer user_data, GError **error)
1069 GdbPlugin *gdb = ANJUTA_PLUGIN_GDB (plugin);
1071 debugger_create_variable (gdb->debugger, name, callback, user_data);
1073 return TRUE;
1076 static gboolean
1077 idebugger_variable_update (IAnjutaDebuggerVariable *plugin, IAnjutaDebuggerCallback callback , gpointer user_data, GError **error)
1079 GdbPlugin *gdb = ANJUTA_PLUGIN_GDB (plugin);
1081 debugger_update_variable (gdb->debugger, callback, user_data);
1083 return TRUE;
1086 static void
1087 idebugger_variable_iface_init (IAnjutaDebuggerVariableIface *iface)
1089 iface->destroy = idebugger_variable_destroy;
1090 iface->evaluate = idebugger_variable_evaluate;
1091 iface->assign = idebugger_variable_assign;
1092 iface->list_children = idebugger_variable_list_children;
1093 iface->create = idebugger_variable_create;
1094 iface->update = idebugger_variable_update;
1097 ANJUTA_PLUGIN_BEGIN (GdbPlugin, gdb_plugin);
1098 ANJUTA_PLUGIN_ADD_INTERFACE(idebugger, IANJUTA_TYPE_DEBUGGER);
1099 ANJUTA_PLUGIN_ADD_INTERFACE(idebugger_breakpoint, IANJUTA_TYPE_DEBUGGER_BREAKPOINT);
1100 ANJUTA_PLUGIN_ADD_INTERFACE(idebugger_register, IANJUTA_TYPE_DEBUGGER_REGISTER);
1101 ANJUTA_PLUGIN_ADD_INTERFACE(idebugger_memory, IANJUTA_TYPE_DEBUGGER_MEMORY);
1102 ANJUTA_PLUGIN_ADD_INTERFACE(idebugger_instruction, IANJUTA_TYPE_DEBUGGER_INSTRUCTION);
1103 ANJUTA_PLUGIN_ADD_INTERFACE(idebugger_variable, IANJUTA_TYPE_DEBUGGER_VARIABLE);
1104 ANJUTA_PLUGIN_END;
1106 ANJUTA_SIMPLE_PLUGIN (GdbPlugin, gdb_plugin);