Added byline
[anjuta.git] / plugins / gdb / plugin.c
blob526ec403d8788325b65495563e67b8072f6fad34
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"
31 #include <glib.h>
32 #include <glib/gi18n.h>
33 #include <sys/types.h>
34 #include <sys/stat.h>
36 #include "debugger.h"
37 #include "preferences.h"
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>
50 /* Plugin type
51 *---------------------------------------------------------------------------*/
53 struct _GdbPlugin
55 AnjutaPlugin parent;
57 /* Debugger */
58 Debugger *debugger;
60 /* Output callback data */
61 IAnjutaDebuggerOutputCallback output_callback;
62 gpointer output_user_data;
64 /* Log message window */
65 IAnjutaMessageView *view;
67 /* Terminal */
68 pid_t term_pid;
70 /* Pretty printer list */
71 GList *pretty_printers;
74 struct _GdbPluginClass
76 AnjutaPluginClass parent_class;
79 #define UNIMPLEMENTED G_STMT_START { g_warning (G_STRLOC": unimplemented"); } G_STMT_END
81 /* Terminal functions
82 *---------------------------------------------------------------------------*/
84 #define PREF_SCHEMA "org.gnome.anjuta.plugins.run"
85 #define PREF_TERMINAL_COMMAND "terminal-command"
87 static void
88 gdb_plugin_stop_terminal (GdbPlugin* plugin)
90 DEBUG_PRINT ("%s", "In function: gdb_plugin_stop_terminal()");
92 if (plugin->term_pid > 0) {
93 kill (plugin->term_pid, SIGTERM);
94 plugin->term_pid = -1;
98 static gchar*
99 gdb_plugin_start_terminal (GdbPlugin* plugin)
101 gchar *file, *cmd;
102 gchar *tty = NULL;
103 IAnjutaTerminal *term;
105 DEBUG_PRINT ("In function: gdb_plugin_start_terminal() previous pid %d", plugin->term_pid);
107 /* Close previous terminal if needed */
108 gdb_plugin_stop_terminal (plugin);
110 /* Check if anjuta launcher is here */
111 if (anjuta_util_prog_is_installed ("anjuta-launcher", TRUE) == FALSE)
113 return NULL;
116 file = anjuta_util_get_a_tmp_file();
117 if (mkfifo (file, 0664) < 0)
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);
123 return NULL;
126 /* Launch terminal */
127 cmd = g_strconcat ("anjuta-launcher --__debug_terminal ", file, NULL);
129 /* Get terminal plugin */
130 term = anjuta_shell_get_interface (ANJUTA_PLUGIN (plugin)->shell, IAnjutaTerminal, NULL);
131 if (term == NULL)
133 /* Use gnome terminal or another user defined one */
134 GSettings* settings;
135 gchar *term_cmd;
136 gchar **argv;
138 settings = g_settings_new (PREF_SCHEMA);
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))
144 GPid gpid;
145 gchar **arg;
147 /* Replace %s by command */
148 for (arg = argv; *arg != NULL; arg++)
150 if (strcmp(*arg, "%s") == 0)
152 g_free (*arg);
153 *arg = cmd;
157 if (g_spawn_async (NULL, argv, NULL, G_SPAWN_SEARCH_PATH, NULL, NULL, &gpid, NULL))
159 plugin->term_pid = gpid;
161 else
163 plugin->term_pid = -1;
165 g_strfreev (argv);
167 else
169 plugin->term_pid = -1;
171 g_free (term_cmd);
173 else
175 /* Use Anjuta terminal plugin */
176 plugin->term_pid = ianjuta_terminal_execute_command (term, NULL, cmd, NULL, NULL);
177 g_free (cmd);
180 if (plugin->term_pid > 0)
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 .
187 g_file_get_contents (file, &tty, NULL, NULL); /* Ok, take the risk. */
188 if (tty)
190 g_strchomp (tty); /* anjuta_launcher add a end of line after the terminal name */
191 if (strcmp(tty, "__ERROR__") == 0)
193 g_free (tty);
194 tty = NULL;
198 remove (file);
199 g_free (file);
201 if (tty == NULL)
203 anjuta_util_dialog_error (GTK_WINDOW (ANJUTA_PLUGIN (plugin)->shell),
204 _("Cannot start terminal for debugging."));
205 gdb_plugin_stop_terminal (plugin);
208 return tty;
211 /* Private functions
212 *---------------------------------------------------------------------------*/
214 static void
215 on_debugger_stopped (GdbPlugin *self, GError *err)
217 if (self->debugger != NULL)
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);
226 static void
227 gdb_plugin_initialize (GdbPlugin *this)
229 GtkWindow *parent;
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)
235 on_debugger_stopped (this, NULL);
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);
244 debugger_set_pretty_printers (this->debugger, this->pretty_printers);
247 /* Helper functions
248 *---------------------------------------------------------------------------*/
250 static gchar *
251 quote_expression (const gchar *expression) {
252 GRegex *regex;
253 gchar *aux, *aux2;
254 gchar *quoted;
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);
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);
267 /* Converts newlines in spaces */
268 g_strdelimit (aux2, "\n", ' ');
269 quoted = g_strconcat ("\"",aux2, "\"", NULL);
270 g_free (aux2);
272 return quoted;
275 /* Callback for saving session
276 *---------------------------------------------------------------------------*/
278 static void
279 on_session_save (AnjutaShell *shell, AnjutaSessionPhase phase, AnjutaSession *session, GdbPlugin *this)
281 if (phase != ANJUTA_SESSION_PHASE_NORMAL)
282 return;
284 gdb_save_pretty_printers (session, this->pretty_printers);
287 static void on_session_load (AnjutaShell *shell, AnjutaSessionPhase phase, AnjutaSession *session, GdbPlugin *this)
289 if (phase != ANJUTA_SESSION_PHASE_NORMAL)
290 return;
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);
297 /* AnjutaPlugin functions
298 *---------------------------------------------------------------------------*/
300 static gboolean
301 gdb_plugin_activate_plugin (AnjutaPlugin* plugin)
303 GdbPlugin *this = ANJUTA_PLUGIN_GDB (plugin);
305 DEBUG_PRINT ("%s", "GDB: Activating Gdb plugin...");
306 this->pretty_printers = NULL;
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);
315 return TRUE;
318 static gboolean
319 gdb_plugin_deactivate_plugin (AnjutaPlugin* plugin)
321 GdbPlugin *this = ANJUTA_PLUGIN_GDB (plugin);
323 DEBUG_PRINT ("%s", "GDB: Deactivating Gdb plugin...");
325 if (this->debugger != NULL)
327 debugger_free (this->debugger);
328 this->debugger = NULL;
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;
335 return TRUE;
338 /* GObject functions
339 *---------------------------------------------------------------------------*/
341 /* Used in dispose and finalize */
342 static gpointer parent_class;
344 /* instance_init is the constructor. All functions should work after this
345 * call. */
347 static void
348 gdb_plugin_instance_init (GObject* obj)
350 GdbPlugin *this = ANJUTA_PLUGIN_GDB (obj);
352 this->debugger = NULL;
353 this->output_callback = NULL;
354 this->term_pid = 0;
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.*/
362 static void
363 gdb_plugin_dispose (GObject* obj)
365 GdbPlugin *this = ANJUTA_PLUGIN_GDB (obj);
367 if (this->debugger != NULL)
369 debugger_free (this->debugger);
370 this->debugger = NULL;
372 G_OBJECT_CLASS (parent_class)->dispose (obj);
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 */
379 static void
380 gdb_plugin_finalize (GObject* obj)
382 G_OBJECT_CLASS (parent_class)->finalize (obj);
385 /* class_init intialize the class itself not the instance */
387 static void
388 gdb_plugin_class_init (GObjectClass* klass)
390 AnjutaPluginClass *plugin_class = ANJUTA_PLUGIN_CLASS (klass);
392 parent_class = g_type_class_peek_parent (klass);
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;
400 /* Implementation of IAnjutaDebugger interface
401 *---------------------------------------------------------------------------*/
403 static IAnjutaDebuggerState
404 idebugger_get_state (IAnjutaDebugger *plugin, GError **err)
406 GdbPlugin *this = ANJUTA_PLUGIN_GDB (plugin);
408 if (this->debugger == NULL)
410 return IANJUTA_DEBUGGER_STOPPED;
412 else
414 return debugger_get_state (this->debugger);
419 static gboolean
420 idebugger_load (IAnjutaDebugger *plugin, const gchar *file, const gchar* mime_type,
421 const GList *search_dirs, GError **err)
423 GdbPlugin *this = ANJUTA_PLUGIN_GDB (plugin);
424 gboolean is_libtool = FALSE;
426 /* Check allowed mime type */
427 if (mime_type == NULL)
429 /* Hope that the target is supported */
431 else if ((strcmp (mime_type, "application/x-executable") == 0) ||
432 (strcmp (mime_type, "application/octet-stream") == 0))
434 /* Supported target */
436 else if (strcmp (mime_type, "application/x-shellscript") == 0)
438 /* FIXME: We should really do more checks to confirm that
439 * this target is indeed libtool target
441 is_libtool = TRUE;
443 else if (strcmp (mime_type, "application/x-core") == 0)
445 /* Supported target */
447 else
449 /* Not supported target */
450 return TRUE;
453 // Start debugger
454 gdb_plugin_initialize (this);
456 return debugger_start (this->debugger, search_dirs, file, is_libtool);
459 static gboolean
460 idebugger_unload (IAnjutaDebugger *plugin, GError **err)
462 GdbPlugin *this = ANJUTA_PLUGIN_GDB (plugin);
464 debugger_stop (this->debugger);
466 return TRUE;
469 static gboolean
470 idebugger_set_working_directory (IAnjutaDebugger *plugin, const gchar *directory, GError **err)
472 GdbPlugin *self = ANJUTA_PLUGIN_GDB (plugin);
474 debugger_set_working_directory (self->debugger, directory);
476 return TRUE;
479 static gboolean
480 idebugger_set_environment (IAnjutaDebugger *plugin, gchar **variables, GError **err)
482 GdbPlugin *self = ANJUTA_PLUGIN_GDB (plugin);
484 debugger_set_environment (self->debugger, variables);
486 return TRUE;
489 static gboolean
490 idebugger_attach (IAnjutaDebugger *plugin, pid_t pid, const GList *search_dirs, GError **err)
492 GdbPlugin *this = ANJUTA_PLUGIN_GDB (plugin);
494 // Start debugger
495 gdb_plugin_initialize (this);
496 debugger_start (this->debugger, search_dirs, NULL, FALSE);
497 debugger_attach_process (this->debugger, pid);
499 return TRUE;
502 static gboolean
503 idebugger_start (IAnjutaDebugger *plugin, const gchar *argument, gboolean terminal, gboolean stop, GError **err)
505 GdbPlugin *this = ANJUTA_PLUGIN_GDB (plugin);
506 gchar *tty;
508 tty = terminal ? gdb_plugin_start_terminal (this) : NULL;
509 debugger_start_program (this->debugger, NULL, argument, tty, stop);
510 g_free (tty);
512 return TRUE;
515 static gboolean
516 idebugger_connect (IAnjutaDebugger *plugin, const gchar *server, const gchar *argument, gboolean terminal, gboolean stop, GError **err)
518 GdbPlugin *this = ANJUTA_PLUGIN_GDB (plugin);
519 gchar *tty;
521 tty = terminal ? gdb_plugin_start_terminal (this) : NULL;
522 debugger_start_program (this->debugger, server, argument, tty, stop);
523 g_free (tty);
525 return TRUE;
528 static gboolean
529 idebugger_quit (IAnjutaDebugger *plugin, GError **err)
531 GdbPlugin *this = ANJUTA_PLUGIN_GDB (plugin);
533 if (!debugger_stop (this->debugger))
535 DEBUG_PRINT ("%s", "set error");
536 g_set_error (err, IANJUTA_DEBUGGER_ERROR, IANJUTA_DEBUGGER_CANCEL, "Command cancelled by user");
538 return FALSE;
540 else
542 return TRUE;
546 static gboolean
547 idebugger_abort (IAnjutaDebugger *plugin, GError **err)
549 GdbPlugin *this = ANJUTA_PLUGIN_GDB (plugin);
551 DEBUG_PRINT ("%s", "idebugger abort\n");
552 if (!debugger_abort (this->debugger))
554 g_set_error (err, IANJUTA_DEBUGGER_ERROR, IANJUTA_DEBUGGER_CANCEL, "Command cancelled by user");
556 return FALSE;
558 else
560 return TRUE;
564 static gboolean
565 idebugger_run (IAnjutaDebugger *plugin, GError **err)
567 GdbPlugin *this = ANJUTA_PLUGIN_GDB (plugin);
569 debugger_run (this->debugger);
571 return TRUE;
574 static gboolean
575 idebugger_step_in (IAnjutaDebugger *plugin, GError **err)
577 GdbPlugin *this = ANJUTA_PLUGIN_GDB (plugin);
579 debugger_step_in (this->debugger);
581 return TRUE;
584 static gboolean
585 idebugger_step_over (IAnjutaDebugger *plugin, GError **err)
587 GdbPlugin *this = ANJUTA_PLUGIN_GDB (plugin);
589 debugger_step_over (this->debugger);
591 return TRUE;
594 static gboolean
595 idebugger_run_to (IAnjutaDebugger *plugin, const gchar* file,
596 gint line, GError **err)
598 GdbPlugin *this = ANJUTA_PLUGIN_GDB (plugin);
600 debugger_run_to_position (this->debugger, file, line);
602 return TRUE;
605 static gboolean
606 idebugger_step_out (IAnjutaDebugger *plugin, GError **err)
608 GdbPlugin *this = ANJUTA_PLUGIN_GDB (plugin);
610 debugger_step_out (this->debugger);
612 return TRUE;
615 static gboolean
616 idebugger_exit (IAnjutaDebugger *plugin, GError **err)
618 GdbPlugin *this = ANJUTA_PLUGIN_GDB (plugin);
620 debugger_stop_program (this->debugger);
622 return TRUE;
625 static gboolean
626 idebugger_interrupt (IAnjutaDebugger *plugin, GError **err)
628 GdbPlugin *this = ANJUTA_PLUGIN_GDB (plugin);
630 debugger_interrupt (this->debugger);
632 return TRUE;
635 static gboolean
636 idebugger_inspect (IAnjutaDebugger *plugin, const gchar *name, IAnjutaDebuggerGCharCallback callback, gpointer user_data, GError **err)
638 GdbPlugin *this = ANJUTA_PLUGIN_GDB (plugin);
640 debugger_evaluate (this->debugger, name, callback, user_data);
642 return TRUE;
645 static gboolean
646 idebugger_evaluate (IAnjutaDebugger *plugin, const gchar *name, const gchar *value, IAnjutaDebuggerGCharCallback callback, gpointer user_data, GError **err)
648 GdbPlugin *this = ANJUTA_PLUGIN_GDB (plugin);
649 gchar* buf;
651 buf = g_strconcat ("\"", name, " = ", value, "\"", NULL);
652 debugger_evaluate (this->debugger, buf, callback, user_data);
653 g_free (buf);
655 return TRUE;
658 static gboolean
659 idebugger_send_command (IAnjutaDebugger *plugin, const gchar* command, GError **err)
661 GdbPlugin *this = ANJUTA_PLUGIN_GDB (plugin);
663 debugger_command (this->debugger, command, FALSE, NULL, NULL);
665 return TRUE;
668 static gboolean
669 idebugger_print (IAnjutaDebugger *plugin, const gchar* variable, IAnjutaDebuggerGCharCallback callback, gpointer user_data, GError **err)
671 GdbPlugin *this = ANJUTA_PLUGIN_GDB (plugin);
673 debugger_print (this->debugger, variable, callback, user_data);
675 return TRUE;
678 static gboolean
679 idebugger_list_local (IAnjutaDebugger *plugin, IAnjutaDebuggerGListCallback callback , gpointer user_data, GError **err)
681 GdbPlugin *this = ANJUTA_PLUGIN_GDB (plugin);
683 debugger_list_local (this->debugger, callback, user_data);
685 return TRUE;
688 static gboolean
689 idebugger_list_argument (IAnjutaDebugger *plugin, IAnjutaDebuggerGListCallback callback , gpointer user_data, GError **err)
691 GdbPlugin *this = ANJUTA_PLUGIN_GDB (plugin);
693 debugger_list_argument (this->debugger, callback, user_data);
695 return TRUE;
698 static gboolean
699 idebugger_info_signal (IAnjutaDebugger *plugin, IAnjutaDebuggerGListCallback callback , gpointer user_data, GError **err)
701 GdbPlugin *this = ANJUTA_PLUGIN_GDB (plugin);
703 debugger_info_signal (this->debugger, callback, user_data);
705 return TRUE;
708 static gboolean
709 idebugger_info_sharedlib (IAnjutaDebugger *plugin, IAnjutaDebuggerGListCallback callback , gpointer user_data, GError **err)
711 GdbPlugin *this = ANJUTA_PLUGIN_GDB (plugin);
713 debugger_info_sharedlib (this->debugger, callback, user_data);
715 return TRUE;
718 static gboolean
719 idebugger_handle_signal (IAnjutaDebugger *plugin, const gchar* name, gboolean stop, gboolean print, gboolean ignore, GError **err)
721 gchar* cmd;
722 GdbPlugin *this = ANJUTA_PLUGIN_GDB (plugin);
724 cmd = g_strdup_printf("handle %s %sstop %sprint %spass", name, stop ? "" : "no", print ? "" : "no", ignore ? "" : "no");
725 debugger_command (this->debugger, cmd, FALSE, NULL, NULL);
726 g_free (cmd);
728 return TRUE;
731 static gboolean
732 idebugger_info_frame (IAnjutaDebugger *plugin, guint frame, IAnjutaDebuggerGListCallback callback , gpointer user_data, GError **err)
734 UNIMPLEMENTED;
736 return FALSE;
739 static gboolean
740 idebugger_info_args (IAnjutaDebugger *plugin, IAnjutaDebuggerGListCallback callback , gpointer user_data, GError **err)
742 UNIMPLEMENTED;
744 return FALSE;
747 static gboolean
748 idebugger_info_target (IAnjutaDebugger *plugin, IAnjutaDebuggerGListCallback callback , gpointer user_data, GError **err)
750 UNIMPLEMENTED;
752 return FALSE;
755 static gboolean
756 idebugger_info_program (IAnjutaDebugger *plugin, IAnjutaDebuggerGListCallback callback , gpointer user_data, GError **err)
758 UNIMPLEMENTED;
760 return FALSE;
763 static gboolean
764 idebugger_info_udot (IAnjutaDebugger *plugin, IAnjutaDebuggerGListCallback callback , gpointer user_data, GError **err)
766 UNIMPLEMENTED;
768 return FALSE;
771 static gboolean
772 idebugger_info_variables (IAnjutaDebugger *plugin, IAnjutaDebuggerGListCallback callback , gpointer user_data, GError **err)
774 UNIMPLEMENTED;
776 return FALSE;
779 static gboolean
780 idebugger_set_frame (IAnjutaDebugger *plugin, guint frame, GError **err)
782 GdbPlugin *this = ANJUTA_PLUGIN_GDB (plugin);
784 debugger_set_frame (this->debugger, frame);
786 return TRUE;
789 static gboolean
790 idebugger_list_frame (IAnjutaDebugger *plugin, IAnjutaDebuggerGListCallback callback , gpointer user_data, GError **err)
792 GdbPlugin *this = ANJUTA_PLUGIN_GDB (plugin);
794 debugger_list_frame (this->debugger, callback, user_data);
796 return TRUE;
799 static gboolean
800 idebugger_set_thread (IAnjutaDebugger *plugin, gint thread, GError **err)
802 GdbPlugin *this = ANJUTA_PLUGIN_GDB (plugin);
804 debugger_set_thread (this->debugger, thread);
806 return TRUE;
809 static gboolean
810 idebugger_list_thread (IAnjutaDebugger *plugin, IAnjutaDebuggerGListCallback callback , gpointer user_data, GError **err)
812 GdbPlugin *this = ANJUTA_PLUGIN_GDB (plugin);
814 debugger_list_thread (this->debugger, callback, user_data);
816 return TRUE;
819 static gboolean
820 idebugger_info_thread (IAnjutaDebugger *plugin, gint thread, IAnjutaDebuggerGListCallback callback , gpointer user_data, GError **err)
822 GdbPlugin *this = ANJUTA_PLUGIN_GDB (plugin);
824 debugger_info_thread (this->debugger, thread, callback, user_data);
826 return TRUE;
829 static gboolean
830 idebugger_run_from (IAnjutaDebugger *plugin, const gchar *file, gint line, GError **err)
832 GdbPlugin *this = ANJUTA_PLUGIN_GDB (plugin);
834 debugger_run_from_position (this->debugger, file, line);
836 return TRUE;
839 static gboolean
840 idebugger_dump_stack_trace (IAnjutaDebugger *plugin, IAnjutaDebuggerGListCallback callback , gpointer user_data, GError **err)
842 GdbPlugin *this = ANJUTA_PLUGIN_GDB (plugin);
844 debugger_dump_stack_trace (this->debugger, callback, user_data);
846 return TRUE;
849 static gboolean
850 idebugger_callback (IAnjutaDebugger *plugin, IAnjutaDebuggerCallback callback , gpointer user_data, GError **err)
853 callback (NULL, user_data, NULL);
855 return TRUE;
858 static void
859 idebugger_enable_log (IAnjutaDebugger *plugin, IAnjutaMessageView *log, GError **err)
861 GdbPlugin *this = ANJUTA_PLUGIN_GDB (plugin);
863 this->view = log;
864 if (this->debugger)
865 debugger_set_log (this->debugger, log);
868 static void
869 idebugger_disable_log (IAnjutaDebugger *plugin, GError **err)
871 GdbPlugin *this = ANJUTA_PLUGIN_GDB (plugin);
873 this->view = NULL;
874 if (this->debugger)
875 debugger_set_log (this->debugger, NULL);
878 static void
879 idebugger_iface_init (IAnjutaDebuggerIface *iface)
881 iface->get_state = idebugger_get_state;
882 iface->attach = idebugger_attach;
883 iface->load = idebugger_load;
884 iface->set_working_directory = idebugger_set_working_directory;
885 iface->set_environment = idebugger_set_environment;
886 iface->start = idebugger_start;
887 iface->connect = idebugger_connect;
888 iface->unload = idebugger_unload;
889 iface->quit = idebugger_quit;
890 iface->abort = idebugger_abort;
891 iface->run = idebugger_run;
892 iface->step_in = idebugger_step_in;
893 iface->step_over = idebugger_step_over;
894 iface->step_out = idebugger_step_out;
895 iface->run_to = idebugger_run_to;
896 iface->run_from = idebugger_run_from;
897 iface->exit = idebugger_exit;
898 iface->interrupt = idebugger_interrupt;
900 iface->inspect = idebugger_inspect;
901 iface->evaluate = idebugger_evaluate;
903 iface->print = idebugger_print;
904 iface->list_local = idebugger_list_local;
905 iface->list_argument = idebugger_list_argument;
906 iface->info_frame = idebugger_info_frame;
907 iface->info_signal = idebugger_info_signal;
908 iface->info_sharedlib = idebugger_info_sharedlib;
909 iface->info_args = idebugger_info_args;
910 iface->info_target = idebugger_info_target;
911 iface->info_program = idebugger_info_program;
912 iface->info_udot = idebugger_info_udot;
913 iface->info_variables = idebugger_info_variables;
914 iface->handle_signal = idebugger_handle_signal;
915 iface->list_frame = idebugger_list_frame;
916 iface->set_frame = idebugger_set_frame;
917 iface->list_thread = idebugger_list_thread;
918 iface->set_thread = idebugger_set_thread;
919 iface->info_thread = idebugger_info_thread;
920 iface->dump_stack_trace = idebugger_dump_stack_trace;
922 iface->send_command = idebugger_send_command;
924 iface->callback = idebugger_callback;
926 iface->enable_log = idebugger_enable_log;
927 iface->disable_log = idebugger_disable_log;
931 /* Implementation of IAnjutaDebuggerBreakpoint interface
932 *---------------------------------------------------------------------------*/
934 static gint
935 idebugger_breakpoint_implement (IAnjutaDebuggerBreakpoint *plugin, GError **err)
937 /* gdb implement all interface methods */
938 return IANJUTA_DEBUGGER_BREAKPOINT_SET_AT_ADDRESS
939 | IANJUTA_DEBUGGER_BREAKPOINT_SET_AT_FUNCTION
940 | IANJUTA_DEBUGGER_BREAKPOINT_ENABLE
941 | IANJUTA_DEBUGGER_BREAKPOINT_IGNORE
942 | IANJUTA_DEBUGGER_BREAKPOINT_CONDITION;
945 static gboolean
946 idebugger_breakpoint_add_at_line (IAnjutaDebuggerBreakpoint *plugin, const gchar* file, guint line, IAnjutaDebuggerBreakpointCallback callback, gpointer user_data, GError **err)
948 GdbPlugin *this = ANJUTA_PLUGIN_GDB (plugin);
950 debugger_add_breakpoint_at_line (this->debugger, file, line, callback, user_data);
952 return TRUE;
955 static gboolean
956 idebugger_breakpoint_add_at_function (IAnjutaDebuggerBreakpoint *plugin, const gchar* file, const gchar* function, IAnjutaDebuggerBreakpointCallback callback, gpointer user_data, GError **err)
958 GdbPlugin *this = ANJUTA_PLUGIN_GDB (plugin);
960 debugger_add_breakpoint_at_function (this->debugger, *file == '\0' ? NULL : file, function, callback, user_data);
962 return TRUE;
965 static gboolean
966 idebugger_breakpoint_add_at_address (IAnjutaDebuggerBreakpoint *plugin, gulong address, IAnjutaDebuggerBreakpointCallback callback, gpointer user_data, GError **err)
968 GdbPlugin *this = ANJUTA_PLUGIN_GDB (plugin);
970 debugger_add_breakpoint_at_address (this->debugger, address, callback, user_data);
972 return TRUE;
975 static gboolean
976 idebugger_breakpoint_enable (IAnjutaDebuggerBreakpoint *plugin, guint id, gboolean enable, IAnjutaDebuggerBreakpointCallback callback, gpointer user_data, GError **err)
978 GdbPlugin *this = ANJUTA_PLUGIN_GDB (plugin);
980 debugger_enable_breakpoint (this->debugger, id, enable, callback, user_data);
982 return TRUE;
985 static gboolean
986 idebugger_breakpoint_ignore (IAnjutaDebuggerBreakpoint *plugin, guint id, guint ignore, IAnjutaDebuggerBreakpointCallback callback, gpointer user_data, GError **err)
988 GdbPlugin *this = ANJUTA_PLUGIN_GDB (plugin);
990 debugger_ignore_breakpoint (this->debugger, id, ignore, callback, user_data);
992 return TRUE;
995 static gboolean
996 idebugger_breakpoint_condition (IAnjutaDebuggerBreakpoint *plugin, guint id, const gchar *condition, IAnjutaDebuggerBreakpointCallback callback, gpointer user_data, GError **err)
998 GdbPlugin *this = ANJUTA_PLUGIN_GDB (plugin);
1000 debugger_condition_breakpoint (this->debugger, id, condition, callback, user_data);
1002 return TRUE;
1005 static gboolean
1006 idebugger_breakpoint_remove (IAnjutaDebuggerBreakpoint *plugin, guint id, IAnjutaDebuggerBreakpointCallback callback, gpointer user_data, GError **err)
1008 GdbPlugin *this = ANJUTA_PLUGIN_GDB (plugin);
1010 debugger_remove_breakpoint (this->debugger, id, callback, user_data);
1012 return TRUE;
1015 static gboolean
1016 idebugger_breakpoint_list (IAnjutaDebuggerBreakpoint *plugin, IAnjutaDebuggerGListCallback callback, gpointer user_data, GError **err)
1018 GdbPlugin *this = ANJUTA_PLUGIN_GDB (plugin);
1020 debugger_list_breakpoint (this->debugger, callback, user_data);
1022 return TRUE;
1025 static void
1026 idebugger_breakpoint_iface_init (IAnjutaDebuggerBreakpointIface *iface)
1028 iface->implement_breakpoint = idebugger_breakpoint_implement;
1029 iface->set_breakpoint_at_line = idebugger_breakpoint_add_at_line;
1030 iface->clear_breakpoint = idebugger_breakpoint_remove;
1031 iface->list_breakpoint = idebugger_breakpoint_list;
1032 iface->set_breakpoint_at_address = idebugger_breakpoint_add_at_address;
1033 iface->set_breakpoint_at_function = idebugger_breakpoint_add_at_function;
1034 iface->enable_breakpoint = idebugger_breakpoint_enable;
1035 iface->ignore_breakpoint = idebugger_breakpoint_ignore;
1036 iface->condition_breakpoint = idebugger_breakpoint_condition;
1039 /* Implementation of IAnjutaDebuggerRegister interface
1040 *---------------------------------------------------------------------------*/
1042 static gboolean
1043 idebugger_register_list (IAnjutaDebuggerRegister *plugin, IAnjutaDebuggerGListCallback callback , gpointer user_data, GError **err)
1045 GdbPlugin *this = ANJUTA_PLUGIN_GDB (plugin);
1047 debugger_list_register (this->debugger, callback, user_data);
1049 return TRUE;
1052 static gboolean
1053 idebugger_register_update (IAnjutaDebuggerRegister *plugin, IAnjutaDebuggerGListCallback callback , gpointer user_data, GError **err)
1055 GdbPlugin *this = ANJUTA_PLUGIN_GDB (plugin);
1057 debugger_update_register (this->debugger, callback, user_data);
1059 return TRUE;
1062 static gboolean
1063 idebugger_register_write (IAnjutaDebuggerRegister *plugin, IAnjutaDebuggerRegisterData *value, GError **err)
1065 GdbPlugin *this = ANJUTA_PLUGIN_GDB (plugin);
1067 debugger_write_register (this->debugger, value->name, value->value);
1069 return TRUE;
1072 static void
1073 idebugger_register_iface_init (IAnjutaDebuggerRegisterIface *iface)
1075 iface->list_register = idebugger_register_list;
1076 iface->update_register = idebugger_register_update;
1077 iface->write_register = idebugger_register_write;
1080 /* Implementation of IAnjutaDebuggerMemory interface
1081 *---------------------------------------------------------------------------*/
1083 static gboolean
1084 idebugger_memory_inspect (IAnjutaDebuggerMemory *plugin, gulong address, guint length, IAnjutaDebuggerMemoryCallback callback , gpointer user_data, GError **err)
1086 GdbPlugin *this = ANJUTA_PLUGIN_GDB (plugin);
1088 debugger_inspect_memory (this->debugger, address, length, callback, user_data);
1090 return TRUE;
1093 static void
1094 idebugger_memory_iface_init (IAnjutaDebuggerMemoryIface *iface)
1096 iface->inspect = idebugger_memory_inspect;
1099 /* Implementation of IAnjutaDebuggerInstruction interface
1100 *---------------------------------------------------------------------------*/
1102 static gboolean
1103 idebugger_instruction_disassemble (IAnjutaDebuggerInstruction *plugin, gulong address, guint length, IAnjutaDebuggerInstructionCallback callback , gpointer user_data, GError **err)
1105 GdbPlugin *this = (GdbPlugin *)plugin;
1107 debugger_disassemble (this->debugger, address, length, callback, user_data);
1109 return TRUE;
1112 static gboolean
1113 idebugger_instruction_step_in (IAnjutaDebuggerInstruction *plugin, GError **err)
1115 GdbPlugin *this = ANJUTA_PLUGIN_GDB (plugin);
1117 debugger_stepi_in (this->debugger);
1119 return TRUE;
1122 static gboolean
1123 idebugger_instruction_step_over (IAnjutaDebuggerInstruction *plugin, GError **err)
1125 GdbPlugin *this = ANJUTA_PLUGIN_GDB (plugin);
1127 debugger_stepi_over (this->debugger);
1129 return TRUE;
1132 static gboolean
1133 idebugger_instruction_run_to_address (IAnjutaDebuggerInstruction *plugin, gulong address, GError **err)
1135 GdbPlugin *this = ANJUTA_PLUGIN_GDB (plugin);
1137 debugger_run_to_address (this->debugger, address);
1139 return TRUE;
1142 static gboolean
1143 idebugger_instruction_run_from_address (IAnjutaDebuggerInstruction *plugin, gulong address, GError **err)
1145 GdbPlugin *this = ANJUTA_PLUGIN_GDB (plugin);
1147 debugger_run_from_address (this->debugger, address);
1149 return TRUE;
1152 static void
1153 idebugger_instruction_iface_init (IAnjutaDebuggerInstructionIface *iface)
1155 iface->disassemble = idebugger_instruction_disassemble;
1156 iface->step_in_instruction = idebugger_instruction_step_in;
1157 iface->step_over_instruction = idebugger_instruction_step_over;
1158 iface->run_to_address = idebugger_instruction_run_to_address;
1159 iface->run_from_address = idebugger_instruction_run_from_address;
1162 /* Implementation of IAnjutaDebuggerVariable interface
1163 *---------------------------------------------------------------------------*/
1165 static gboolean
1166 idebugger_variable_destroy (IAnjutaDebuggerVariable *plugin, const gchar *name, GError **error)
1168 GdbPlugin *gdb = ANJUTA_PLUGIN_GDB (plugin);
1169 gchar *quoted;
1171 quoted = quote_expression (name);
1172 debugger_delete_variable (gdb->debugger, quoted);
1173 g_free (quoted);
1175 return TRUE;
1178 static gboolean
1179 idebugger_variable_evaluate (IAnjutaDebuggerVariable *plugin, const gchar *name, IAnjutaDebuggerGCharCallback callback , gpointer user_data, GError **error)
1181 GdbPlugin *gdb = ANJUTA_PLUGIN_GDB (plugin);
1183 debugger_evaluate_variable (gdb->debugger, name, callback, user_data);
1185 return TRUE;
1188 static gboolean
1189 idebugger_variable_assign (IAnjutaDebuggerVariable *plugin, const gchar *name, const gchar *value, GError **error)
1191 GdbPlugin *gdb = ANJUTA_PLUGIN_GDB (plugin);
1192 gchar *quoted;
1194 quoted = quote_expression (name);
1195 debugger_assign_variable (gdb->debugger, quoted, value);
1196 g_free (quoted);
1198 return TRUE;
1201 static gboolean
1202 idebugger_variable_list_children (IAnjutaDebuggerVariable *plugin, const gchar *name, guint from, IAnjutaDebuggerGListCallback callback , gpointer user_data, GError **error)
1204 GdbPlugin *gdb = ANJUTA_PLUGIN_GDB (plugin);
1205 gchar *quoted;
1207 quoted = quote_expression (name);
1208 debugger_list_variable_children (gdb->debugger, quoted, from, callback, user_data);
1209 g_free (quoted);
1211 return TRUE;
1214 static gboolean
1215 idebugger_variable_create (IAnjutaDebuggerVariable *plugin, const gchar *name, IAnjutaDebuggerVariableCallback callback , gpointer user_data, GError **error)
1217 GdbPlugin *gdb = ANJUTA_PLUGIN_GDB (plugin);
1218 gchar *quoted;
1220 quoted = quote_expression (name);
1221 debugger_create_variable (gdb->debugger, quoted, callback, user_data);
1222 g_free (quoted);
1224 return TRUE;
1227 static gboolean
1228 idebugger_variable_update (IAnjutaDebuggerVariable *plugin, IAnjutaDebuggerGListCallback callback , gpointer user_data, GError **error)
1230 GdbPlugin *gdb = ANJUTA_PLUGIN_GDB (plugin);
1232 debugger_update_variable (gdb->debugger, callback, user_data);
1234 return TRUE;
1237 static void
1238 idebugger_variable_iface_init (IAnjutaDebuggerVariableIface *iface)
1240 iface->destroy = idebugger_variable_destroy;
1241 iface->evaluate = idebugger_variable_evaluate;
1242 iface->assign = idebugger_variable_assign;
1243 iface->list_children = idebugger_variable_list_children;
1244 iface->create = idebugger_variable_create;
1245 iface->update = idebugger_variable_update;
1248 /* Implementation of IAnjutaPreference interface
1249 *---------------------------------------------------------------------------*/
1251 static void
1252 ipreferences_merge(IAnjutaPreferences* ipref, AnjutaPreferences* prefs, GError** error)
1254 gdb_merge_preferences (prefs, &(ANJUTA_PLUGIN_GDB (ipref)->pretty_printers));
1257 static void
1258 ipreferences_unmerge(IAnjutaPreferences* ipref, AnjutaPreferences* prefs, GError** error)
1260 gdb_unmerge_preferences (prefs);
1263 static void
1264 ipreferences_iface_init(IAnjutaPreferencesIface* iface)
1266 iface->merge = ipreferences_merge;
1267 iface->unmerge = ipreferences_unmerge;
1270 ANJUTA_PLUGIN_BEGIN (GdbPlugin, gdb_plugin);
1271 ANJUTA_PLUGIN_ADD_INTERFACE(idebugger, IANJUTA_TYPE_DEBUGGER);
1272 ANJUTA_PLUGIN_ADD_INTERFACE(idebugger_breakpoint, IANJUTA_TYPE_DEBUGGER_BREAKPOINT);
1273 ANJUTA_PLUGIN_ADD_INTERFACE(idebugger_register, IANJUTA_TYPE_DEBUGGER_REGISTER);
1274 ANJUTA_PLUGIN_ADD_INTERFACE(idebugger_memory, IANJUTA_TYPE_DEBUGGER_MEMORY);
1275 ANJUTA_PLUGIN_ADD_INTERFACE(idebugger_instruction, IANJUTA_TYPE_DEBUGGER_INSTRUCTION);
1276 ANJUTA_PLUGIN_ADD_INTERFACE(idebugger_variable, IANJUTA_TYPE_DEBUGGER_VARIABLE);
1277 ANJUTA_PLUGIN_ADD_INTERFACE (ipreferences, IANJUTA_TYPE_PREFERENCES);
1278 ANJUTA_PLUGIN_END;
1280 ANJUTA_SIMPLE_PLUGIN (GdbPlugin, gdb_plugin);