2 * debugger.c Copyright (C) 2000 Kh. Naba Kumar Singh
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms of the GNU General Public License as published by the Free
6 * Software Foundation; either version 2 of the License, or (at your option)
9 * This program is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
11 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * You should have received a copy of the GNU General Public License along
15 * with this program; if not, write to the Free Software Foundation, Inc., 59
16 * Temple Place, Suite 330, Boston, MA 02111-1307 USA
25 #include <sys/types.h>
38 #include <libanjuta/anjuta-launcher.h>
39 #include <libanjuta/anjuta-debug.h>
40 #include <libanjuta/anjuta-children.h>
41 #include <libanjuta/anjuta-marshal.h>
44 #include "utilities.h"
46 #define GDB_PROMPT "(gdb)"
47 #define PREF_TERMINAL_COMMAND "anjuta.command.terminal"
48 #define FILE_BUFFER_SIZE 1024
49 #define GDB_PATH "gdb"
54 DEBUGGER_RERUN_PROGRAM
59 PROGRAM_LOADED_SIGNAL
,
60 PROGRAM_RUNNING_SIGNAL
,
61 PROGRAM_EXITED_SIGNAL
,
62 PROGRAM_STOPPED_SIGNAL
,
63 RESULTS_ARRIVED_SIGNAL
,
64 LOCATION_CHANGED_SIGNAL
,
65 BREAKPOINT_CHANGED_SIGNAL
,
66 VARIABLE_CHANGED_SIGNAL
,
72 GtkWindow
*parent_win
;
74 IAnjutaDebuggerOutputCallback output_callback
;
75 gpointer output_user_data
;
79 gboolean prog_is_running
;
80 gboolean prog_is_attached
;
81 gboolean prog_is_loaded
;
82 guint debugger_is_busy
;
83 gint post_execution_flag
;
85 AnjutaLauncher
*launcher
;
100 /* GDB command queue */
102 DebuggerCommand current_cmd
;
103 gboolean skip_next_prompt
;
104 gboolean command_output_sent
;
106 gboolean term_is_running
;
109 gint gnome_terminal_type
;
113 IAnjutaMessageView
*log
;
116 gpointer parent_class
;
118 static gchar
*debugger_start_terminal (Debugger
*debugger
);
119 static void debugger_stop_terminal (Debugger
*debugger
);
121 static void debugger_queue_clear (Debugger
*debugger
);
122 static void debugger_queue_execute_command (Debugger
*debugger
);
124 static void gdb_stdout_line_arrived (Debugger
*debugger
, const gchar
* line
);
125 static void gdb_stderr_line_arrived (Debugger
*debugger
, const gchar
* line
);
126 static void debugger_stdo_flush (Debugger
*debugger
);
127 static void debugger_stde_flush (Debugger
*debugger
);
128 static void on_gdb_output_arrived (AnjutaLauncher
*launcher
,
129 AnjutaLauncherOutputType output_type
,
130 const gchar
*chars
, gpointer data
);
131 static void on_gdb_terminated (AnjutaLauncher
*launcher
,
132 gint child_pid
, gint status
,
133 gulong t
, gpointer data
);
135 static void debugger_class_init (DebuggerClass
*klass
);
136 static void debugger_instance_init (Debugger
*debugger
);
139 *---------------------------------------------------------------------------*/
141 typedef struct _GdbMessageCode GdbMessageCode
;
143 struct _GdbMessageCode
149 const static GdbMessageCode GdbErrorMessage
[] =
150 {{"mi_cmd_var_create: unable to create variable object",
151 IANJUTA_DEBUGGER_UNABLE_TO_CREATE_VARIABLE
},
152 {"Cannot access memory at address ",
153 IANJUTA_DEBUGGER_UNABLE_TO_ACCESS_MEMORY
},
157 gdb_match_error(const gchar
*message
)
162 for (msg
= GdbErrorMessage
; msg
->msg
!= NULL
; msg
++)
164 gsize len
= strlen (msg
->msg
);
166 if (!isspace (msg
->msg
[len
- 1]))
168 /* Match the whole string */
172 if (memcmp (msg
->msg
, message
, len
) == 0)
178 return IANJUTA_DEBUGGER_UNKNOWN_ERROR
;
182 debugger_initialize (Debugger
*debugger
)
184 DEBUG_PRINT ("In function: debugger_init()");
186 debugger
->priv
= g_new0 (DebuggerPriv
, 1);
188 debugger
->priv
->output_callback
= NULL
;
189 debugger
->priv
->parent_win
= NULL
;
190 debugger
->priv
->search_dirs
= NULL
;
191 debugger
->priv
->launcher
= anjuta_launcher_new ();
193 debugger
->priv
->prog_is_running
= FALSE
;
194 debugger
->priv
->debugger_is_busy
= 0;
195 debugger
->priv
->starting
= FALSE
;
196 debugger
->priv
->terminating
= FALSE
;
197 debugger
->priv
->skip_next_prompt
= FALSE
;
198 debugger
->priv
->command_output_sent
= FALSE
;
200 strcpy (debugger
->priv
->current_cmd
.cmd
, "");
201 debugger
->priv
->current_cmd
.parser
= NULL
;
203 debugger
->priv
->cmd_queqe
= NULL
;
204 debugger
->priv
->cli_lines
= NULL
;
205 debugger
->priv
->solib_event
= FALSE
;
207 debugger
->priv
->stdo_line
= g_string_sized_new (FILE_BUFFER_SIZE
);
208 g_string_assign (debugger
->priv
->stdo_line
, "");
209 debugger
->priv
->stdo_acc
= g_string_new ("");
211 debugger
->priv
->stde_line
= g_string_sized_new (FILE_BUFFER_SIZE
);
212 g_string_assign (debugger
->priv
->stde_line
, "");
214 debugger
->priv
->term_is_running
= FALSE
;
215 debugger
->priv
->term_pid
= -1;
217 debugger
->priv
->post_execution_flag
= DEBUGGER_NONE
;
218 debugger
->priv
->gnome_terminal_type
= gdb_util_check_gnome_terminal();
220 DEBUG_PRINT ("gnome-terminal type %d found.",
221 debugger
->priv
->gnome_terminal_type
);
225 debugger_instance_init (Debugger
*debugger
)
227 debugger_initialize (debugger
);
231 debugger_new (GtkWindow
*parent_win
, GObject
* instance
)
235 debugger
= g_object_new (DEBUGGER_TYPE
, NULL
);
236 debugger
->priv
->parent_win
= parent_win
;
237 debugger
->priv
->instance
= instance
;
238 g_object_add_weak_pointer (instance
, (gpointer
*)&debugger
->priv
->instance
);
244 debugger_free (Debugger
*debugger
)
246 g_return_if_fail (IS_DEBUGGER (debugger
));
248 g_object_unref (debugger
);
252 debugger_is_ready (Debugger
*debugger
)
254 g_return_val_if_fail (IS_DEBUGGER (debugger
), FALSE
);
255 return !debugger
->priv
->debugger_is_busy
;
259 debugger_program_is_running (Debugger
*debugger
)
261 g_return_val_if_fail (IS_DEBUGGER (debugger
), FALSE
);
262 return debugger
->priv
->prog_is_running
;
266 debugger_program_is_attached (Debugger
*debugger
)
268 g_return_val_if_fail (IS_DEBUGGER (debugger
), FALSE
);
269 return debugger
->priv
->prog_is_attached
;
273 debugger_program_is_loaded (Debugger
*debugger
)
275 g_return_val_if_fail (IS_DEBUGGER (debugger
), FALSE
);
276 return debugger
->priv
->prog_is_loaded
;
280 debugger_log_command (Debugger
*debugger
, const gchar
*command
)
285 if (debugger
->priv
->log
== NULL
) return;
289 str
= g_strdup (command
);
290 len
= strlen (command
);
292 /* Remove trailing carriage return */
293 if (str
[len
- 1] == '\n') str
[len
- 1] = '\0';
295 /* Log only MI command as other are echo */
296 DEBUG_PRINT ("Cmd: %s", str
);
297 ianjuta_message_view_append (debugger
->priv
->log
, IANJUTA_MESSAGE_VIEW_TYPE_NORMAL
, str
, "", NULL
);
303 debugger_log_output (Debugger
*debugger
, const gchar
*line
)
307 IAnjutaMessageViewType type
;
310 if (debugger
->priv
->log
== NULL
) return;
312 type
= IANJUTA_MESSAGE_VIEW_TYPE_NORMAL
;
316 type
= IANJUTA_MESSAGE_VIEW_TYPE_INFO
;
322 /* Remove double quote if necessary */
323 if ((line
[1] == '\"') && (line
[len
- 1] == '\"')) start
++;
324 str
= g_strcompress (line
+ 2);
326 if (start
== line
+ 2)
332 /* Remove trailing carriage return */
333 if (str
[len
- 1] == '\n') str
[len
- 1] = '\0';
335 ianjuta_message_view_append (debugger
->priv
->log
, type
, str
, "", NULL
);
339 if (strncmp(line
+ 1, "error", 5) == 0)
341 ianjuta_message_view_append (debugger
->priv
->log
, IANJUTA_MESSAGE_VIEW_TYPE_ERROR
, line
+ 1, "", NULL
);
345 ianjuta_message_view_append (debugger
->priv
->log
, IANJUTA_MESSAGE_VIEW_TYPE_WARNING
, line
+ 1, "", NULL
);
349 ianjuta_message_view_append (debugger
->priv
->log
, IANJUTA_MESSAGE_VIEW_TYPE_NORMAL
, line
+ 1, "", NULL
);
352 ianjuta_message_view_append (debugger
->priv
->log
, IANJUTA_MESSAGE_VIEW_TYPE_NORMAL
, line
, "", NULL
);
358 debugger_emit_status (Debugger
*debugger
)
360 if (!debugger
->priv
->debugger_is_busy
)
362 if (debugger
->priv
->loading
)
364 debugger
->priv
->starting
= FALSE
;
365 debugger
->priv
->loading
= FALSE
;
366 debugger
->priv
->exiting
= FALSE
;
367 debugger
->priv
->stopping
= FALSE
;
368 debugger
->priv
->solib_event
= FALSE
;
369 g_signal_emit_by_name (debugger
->priv
->instance
, "program-loaded");
371 else if (debugger
->priv
->starting
)
373 debugger
->priv
->starting
= FALSE
;
374 debugger
->priv
->loading
= FALSE
;
375 debugger
->priv
->exiting
= FALSE
;
376 debugger
->priv
->stopping
= FALSE
;
377 debugger
->priv
->solib_event
= FALSE
;
378 g_signal_emit_by_name (debugger
->priv
->instance
, "debugger-started");
380 else if (debugger
->priv
->exiting
)
382 debugger
->priv
->exiting
= FALSE
;
383 debugger
->priv
->stopping
= FALSE
;
384 debugger
->priv
->solib_event
= FALSE
;
385 g_signal_emit_by_name (debugger
->priv
->instance
, "program-exited");
387 else if (debugger
->priv
->solib_event
)
389 debugger
->priv
->exiting
= FALSE
;
390 debugger
->priv
->stopping
= FALSE
;
391 debugger
->priv
->solib_event
= FALSE
;
392 g_signal_emit_by_name (debugger
->priv
->instance
, "sharedlib-event");
394 else if (debugger
->priv
->stopping
)
396 debugger
->priv
->exiting
= FALSE
;
397 debugger
->priv
->stopping
= FALSE
;
398 debugger
->priv
->solib_event
= FALSE
;
399 g_signal_emit_by_name (debugger
->priv
->instance
, "program-stopped");
403 if (debugger
->priv
->prog_is_running
|| debugger
->priv
->prog_is_attached
)
405 g_signal_emit_by_name (debugger
->priv
->instance
, "debugger-ready", IANJUTA_DEBUGGER_PROGRAM_STOPPED
);
407 else if (debugger
->priv
->prog_is_loaded
)
409 g_signal_emit_by_name (debugger
->priv
->instance
, "debugger-ready", IANJUTA_DEBUGGER_PROGRAM_LOADED
);
413 g_signal_emit_by_name (debugger
->priv
->instance
, "debugger-ready", IANJUTA_DEBUGGER_STARTED
);
419 IAnjutaDebuggerStatus
420 debugger_get_status (Debugger
*debugger
)
422 if (debugger
->priv
->debugger_is_busy
)
424 return IANJUTA_DEBUGGER_BUSY
;
428 if (debugger
->priv
->prog_is_running
|| debugger
->priv
->prog_is_attached
)
430 return IANJUTA_DEBUGGER_PROGRAM_STOPPED
;
432 else if (debugger
->priv
->prog_is_loaded
)
434 return IANJUTA_DEBUGGER_PROGRAM_LOADED
;
438 return IANJUTA_DEBUGGER_STARTED
;
444 debugger_clear_buffers (Debugger
*debugger
)
446 DEBUG_PRINT ("In function: debugger_clear_buffers()");
448 /* Clear the output line buffer */
449 g_string_assign (debugger
->priv
->stdo_line
, "");
450 if (!debugger
->priv
->current_cmd
.keep_result
)
451 g_string_assign (debugger
->priv
->stdo_acc
, "");
453 /* Clear the error line buffer */
454 g_string_assign (debugger
->priv
->stde_line
, "");
456 /* Clear CLI output lines */
457 g_list_foreach (debugger
->priv
->cli_lines
, (GFunc
)g_free
, NULL
);
458 g_list_free (debugger
->priv
->cli_lines
);
459 debugger
->priv
->cli_lines
= NULL
;
462 static DebuggerCommand
*
463 debugger_queue_get_next_command (Debugger
*debugger
)
467 DEBUG_PRINT ("In function: debugger_get_next_command()");
469 if (debugger
->priv
->cmd_queqe
)
471 dc
= g_list_nth_data (debugger
->priv
->cmd_queqe
, 0);
472 debugger
->priv
->cmd_queqe
= g_list_remove (debugger
->priv
->cmd_queqe
, dc
);
480 debugger_queue_set_next_command (Debugger
*debugger
)
484 DEBUG_PRINT ("In function: debugger_set_next_command()");
486 dc
= debugger_queue_get_next_command (debugger
);
489 strcpy (debugger
->priv
->current_cmd
.cmd
, "");
490 debugger
->priv
->current_cmd
.parser
= NULL
;
491 debugger
->priv
->current_cmd
.callback
= NULL
;
492 debugger
->priv
->current_cmd
.user_data
= NULL
;
493 debugger
->priv
->current_cmd
.suppress_error
= FALSE
;
494 debugger
->priv
->current_cmd
.keep_result
= FALSE
;
501 strcpy (debugger
->priv
->current_cmd
.cmd
, dc
->cmd
);
502 debugger
->priv
->current_cmd
.parser
= dc
->parser
;
503 debugger
->priv
->current_cmd
.callback
= dc
->callback
;
504 debugger
->priv
->current_cmd
.user_data
= dc
->user_data
;
505 debugger
->priv
->current_cmd
.suppress_error
= dc
->suppress_error
;
506 debugger
->priv
->current_cmd
.keep_result
= dc
->keep_result
;
513 debugger_queue_command (Debugger
*debugger
, const gchar
*cmd
,
514 gboolean suppress_error
, gboolean keep_result
,
515 DebuggerParserFunc parser
,
516 IAnjutaDebuggerCallback callback
, gpointer user_data
)
521 DEBUG_PRINT ("In function: debugger_queue_command (%s)", cmd
);
523 dc
= g_malloc (sizeof (DebuggerCommand
));
526 strcpy (dc
->cmd
, cmd
);
528 dc
->callback
= callback
;
529 dc
->user_data
= user_data
;
530 dc
->suppress_error
= suppress_error
;
531 dc
->keep_result
= keep_result
;
533 debugger
->priv
->cmd_queqe
= g_list_append (debugger
->priv
->cmd_queqe
, dc
);
534 if (!debugger
->priv
->debugger_is_busy
&&
535 g_list_length (debugger
->priv
->cmd_queqe
) >= 1)
537 debugger_queue_execute_command (debugger
);
542 debugger_queue_clear (Debugger
*debugger
)
546 DEBUG_PRINT ("In function: debugger_queue_clear()");
548 node
= debugger
->priv
->cmd_queqe
;
552 node
= g_list_next (node
);
554 g_list_free (debugger
->priv
->cmd_queqe
);
555 debugger
->priv
->cmd_queqe
= NULL
;
556 strcpy (debugger
->priv
->current_cmd
.cmd
, "");
557 debugger
->priv
->current_cmd
.parser
= NULL
;
558 debugger
->priv
->current_cmd
.callback
= NULL
;
559 debugger
->priv
->current_cmd
.user_data
= NULL
;
560 debugger
->priv
->current_cmd
.suppress_error
= FALSE
;
561 debugger
->priv
->current_cmd
.keep_result
= FALSE
;
562 debugger_clear_buffers (debugger
);
566 debugger_execute_command (Debugger
*debugger
, const gchar
*command
)
570 DEBUG_PRINT ("In function: debugger_execute_command(%s) %d\n",command
, debugger
->priv
->debugger_is_busy
);
571 debugger
->priv
->debugger_is_busy
++;
572 debugger
->priv
->command_output_sent
= FALSE
;
573 cmd
= g_strconcat (command
, "\n", NULL
);
574 debugger_log_command (debugger
, cmd
);
575 anjuta_launcher_send_stdin (debugger
->priv
->launcher
, cmd
);
580 debugger_queue_execute_command (Debugger
*debugger
)
582 DEBUG_PRINT ("In function: debugger_queue_execute_command()");
584 debugger_clear_buffers (debugger
);
585 if (debugger_queue_set_next_command (debugger
))
586 // if (strlen (debugger->priv->current_cmd.cmd))
587 debugger_execute_command (debugger
, debugger
->priv
->current_cmd
.cmd
);
591 debugger_load_executable_finish (Debugger
*debugger
, const GDBMIValue
*mi_results
,
592 const GList
*cli_results
, GError
*error
)
594 DEBUG_PRINT ("Program loaded");
595 debugger
->priv
->prog_is_loaded
= TRUE
;
597 g_signal_emit_by_name (debugger
->priv
->instance
, "program-loaded");
601 debugger_load_executable (Debugger
*debugger
, const gchar
*prog
)
603 gchar
*command
, *dir
, *msg
;
605 g_return_if_fail (IS_DEBUGGER (debugger
));
606 g_return_if_fail (prog
!= NULL
);
608 DEBUG_PRINT ("In function: debugger_load_executable(%s)", prog
);
610 if (debugger
->priv
->output_callback
)
612 msg
= g_strconcat (_("Loading Executable: "), prog
, "\n", NULL
);
613 debugger
->priv
->output_callback (IANJUTA_DEBUGGER_OUTPUT
, msg
,
614 debugger
->priv
->output_user_data
);
618 command
= g_strconcat ("-file-exec-and-symbols ", prog
, NULL
);
619 dir
= g_path_get_dirname (prog
);
621 anjuta_set_execution_dir(dir);
624 debugger_queue_command (debugger
, command
, FALSE
, FALSE
, debugger_load_executable_finish
, NULL
, NULL
);
626 debugger
->priv
->starting
= TRUE
;
627 debugger
->priv
->terminating
= FALSE
;
631 debugger_load_core (Debugger
*debugger
, const gchar
*core
)
633 gchar
*command
, *dir
, *msg
;
635 g_return_if_fail (IS_DEBUGGER (debugger
));
636 g_return_if_fail (core
!= NULL
);
638 DEBUG_PRINT ("In function: debugger_load_core(%s)", core
);
640 if (debugger
->priv
->output_callback
)
642 msg
= g_strconcat (_("Loading Core: "), core
, "\n", NULL
);
643 debugger
->priv
->output_callback (IANJUTA_DEBUGGER_OUTPUT
, msg
,
644 debugger
->priv
->output_user_data
);
648 command
= g_strconcat ("core ", core
, NULL
);
649 dir
= g_path_get_dirname (core
);
650 debugger
->priv
->search_dirs
=
651 g_list_prepend (debugger
->priv
->search_dirs
, dir
);
652 debugger_queue_command (debugger
, command
, FALSE
, FALSE
, NULL
, NULL
, NULL
);
657 debugger_start (Debugger
*debugger
, const GList
*search_dirs
,
658 const gchar
*prog
, gboolean is_libtool_prog
,
661 gchar
*command_str
, *dir
, *tmp
, *text
, *msg
;
665 AnjutaLauncher
*launcher
;
666 GList
*dir_list
= NULL
;
669 DEBUG_PRINT ("In function: debugger_start(%s) libtool %d", prog
== NULL
? "(null)" : prog
, is_libtool_prog
);
671 /* Without a terminal, the output of the debugged program
675 term
= debugger_start_terminal (debugger
);
678 tmp
= g_strconcat (" -tty=", term
, NULL
);
684 if (anjuta_util_prog_is_installed ("gdb", TRUE
) == FALSE
)
687 debugger_queue_clear (debugger
);
689 tmp
= g_strconcat (PACKAGE_DATA_DIR
, "/", "gdb.init", NULL
);
690 if (g_file_test (tmp
, G_FILE_TEST_IS_REGULAR
) == FALSE
)
692 anjuta_util_dialog_error (debugger
->priv
->parent_win
,
693 _("Unable to find: %s.\n"
694 "Unable to initialize debugger.\n"
695 "Make sure Anjuta is installed correctly."),
702 /* Prepare source search directories */
705 exec_dir
= g_path_get_dirname (prog
);
709 dir
= g_strconcat (" -directory=", exec_dir
, NULL
);
710 dir_list
= g_list_prepend (dir_list
, exec_dir
);
714 dir
= g_strdup (" ");
721 if (strncmp (text
, "file://", 7) == 0)
727 g_warning ("Debugger source search uri '%s' is not a local uri", text
);
732 tmp
= g_strconcat (dir
, " -directory=", text
, NULL
);
736 dir_list
= g_list_prepend (dir_list
, g_strdup (text
));
740 g_warning ("Debugger source search dir '%s' is not absolute",
743 node
= g_list_next (node
);
746 /* Now save the dir list. Order is automatically revesed */
750 debugger
->priv
->search_dirs
=
751 g_list_prepend (debugger
->priv
->search_dirs
, node
->data
);
752 node
= g_list_next (node
);
754 g_list_free (dir_list
);
756 if (prog
&& strlen(prog
) > 0)
760 if (is_libtool_prog
== FALSE
)
762 command_str
= g_strdup_printf (GDB_PATH
" -f -n -i=mi2 %s %s "
763 "-x %s/gdb.init %s", dir
, term
== NULL
? "" : term
,
764 PACKAGE_DATA_DIR
, prog
);
768 command_str
= g_strdup_printf ("libtool --mode=execute " GDB_PATH
769 " -f -n -i=mi2 %s %s "
770 "-x %s/gdb.init %s", dir
, term
== NULL
? "" : term
,
771 PACKAGE_DATA_DIR
, prog
);
776 if (is_libtool_prog
== FALSE
)
778 command_str
= g_strdup_printf (GDB_PATH
" -f -n -i=mi2 %s %s "
779 "-x %s/gdb.init ", term
== NULL
? "" : term
,
780 dir
, PACKAGE_DATA_DIR
);
784 command_str
= g_strdup_printf ("libtool --mode=execute " GDB_PATH
785 " -f -n -i=mi2 %s %s -x "
787 dir
, term
== NULL
? "" : term
, PACKAGE_DATA_DIR
);
792 debugger
->priv
->starting
= TRUE
;
793 debugger
->priv
->terminating
= FALSE
;
794 debugger
->priv
->loading
= prog
!= NULL
? TRUE
: FALSE
;
795 debugger
->priv
->debugger_is_busy
= 1;
797 /* Prepare for launch. */
798 launcher
= debugger
->priv
->launcher
;
799 anjuta_launcher_set_terminate_on_exit (launcher
, TRUE
);
800 g_signal_connect (G_OBJECT (launcher
), "child-exited",
801 G_CALLBACK (on_gdb_terminated
), debugger
);
802 ret
= anjuta_launcher_execute (launcher
, command_str
,
803 on_gdb_output_arrived
, debugger
);
806 debugger
->priv
->prog_is_loaded
= prog
!= NULL
;
807 anjuta_launcher_set_encoding (launcher
, "ISO-8859-1");
809 if (debugger
->priv
->output_callback
!= NULL
)
813 /* TODO anjuta_update_app_status (TRUE, _("Debugger")); */
814 debugger
->priv
->output_callback (IANJUTA_DEBUGGER_OUTPUT
,
815 _("Getting ready to start debugging "
817 debugger
->priv
->output_user_data
);
821 msg
= g_strconcat (_("Loading Executable: "), prog
, "\n", NULL
);
822 debugger
->priv
->output_callback (IANJUTA_DEBUGGER_OUTPUT
,
824 debugger
->priv
->output_user_data
);
829 debugger
->priv
->output_callback (IANJUTA_DEBUGGER_OUTPUT
,
830 _("No executable specified.\n"),
831 debugger
->priv
->output_user_data
);
832 debugger
->priv
->output_callback (IANJUTA_DEBUGGER_OUTPUT
,
833 _("Open an executable or attach "
834 "to a process to start "
836 debugger
->priv
->output_user_data
);
841 debugger
->priv
->output_callback (IANJUTA_DEBUGGER_OUTPUT
,
842 _("There was an error whilst "
843 "launching the debugger.\n"),
844 debugger
->priv
->output_user_data
);
845 debugger
->priv
->output_callback (IANJUTA_DEBUGGER_OUTPUT
,
846 _("Make sure 'gdb' is installed "
848 debugger
->priv
->output_user_data
);
851 g_free (command_str
);
857 gdb_stdout_line_arrived (Debugger
*debugger
, const gchar
* chars
)
863 if (chars
[i
] == '\n')
865 debugger_stdo_flush (debugger
);
869 g_string_append_c (debugger
->priv
->stdo_line
, chars
[i
]);
876 gdb_stderr_line_arrived (Debugger
*debugger
, const gchar
* chars
)
880 for (i
= 0; i
< strlen (chars
); i
++)
882 if (chars
[i
] == '\n')
883 debugger_stde_flush (debugger
);
885 g_string_append_c (debugger
->priv
->stde_line
, chars
[i
]);
890 on_gdb_output_arrived (AnjutaLauncher
*launcher
,
891 AnjutaLauncherOutputType output_type
,
892 const gchar
*chars
, gpointer data
)
894 Debugger
*debugger
= DEBUGGER (data
);
895 DEBUG_PRINT ("on gdb output arrived");
899 case ANJUTA_LAUNCHER_OUTPUT_STDERR
:
900 gdb_stderr_line_arrived (debugger
, chars
);
902 case ANJUTA_LAUNCHER_OUTPUT_STDOUT
:
903 gdb_stdout_line_arrived (debugger
, chars
);
911 debugger_handle_post_execution (Debugger
*debugger
)
913 switch (debugger
->priv
->post_execution_flag
)
918 DEBUG_PRINT ("debugger stop in handle post execution\n");
919 debugger_stop (debugger
);
921 case DEBUGGER_RERUN_PROGRAM
:
922 DEBUG_PRINT ("debugger run in handle post execution\n");
923 debugger_run (debugger
);
926 g_warning ("Execution should not reach here");
931 debugger_process_frame (Debugger
*debugger
, const GDBMIValue
*val
)
933 const GDBMIValue
*file
, *line
, *frame
, *addr
, *fullname
;
934 const gchar
*file_str
, *fullname_str
;
941 g_return_if_fail (val
!= NULL
);
943 file
= gdbmi_value_hash_lookup (val
, "file");
944 line
= gdbmi_value_hash_lookup (val
, "line");
945 frame
= gdbmi_value_hash_lookup (val
, "frame");
946 addr
= gdbmi_value_hash_lookup (val
, "addr");
947 fullname
= gdbmi_value_hash_lookup (val
, "fullname");
951 file_str
= gdbmi_value_literal_get (file
);
952 line_num
= atoi(gdbmi_value_literal_get (line
));
954 fullname_str
= fullname
? gdbmi_value_literal_get (fullname
) : NULL
;
955 addr_num
= addr
? strtoul (gdbmi_value_literal_get (addr
), NULL
, 0) : 0;
957 debugger_change_location (debugger
, fullname_str
? fullname_str
: file_str
,
962 file
= gdbmi_value_hash_lookup (frame
, "file");
963 line
= gdbmi_value_hash_lookup (frame
, "line");
964 fullname
= gdbmi_value_hash_lookup (frame
, "fullname");
966 fullname_str
= fullname
? gdbmi_value_literal_get (fullname
) : NULL
;
968 addr_num
= addr
? strtoul (gdbmi_value_literal_get (addr
), NULL
, 0) : 0;
969 file_str
= file
? gdbmi_value_literal_get (file
) : NULL
;
970 line_num
= line
? atoi(gdbmi_value_literal_get (line
)) : 0;
971 debugger_change_location (debugger
, fullname_str
? fullname_str
: file_str
,
977 gdb_parse_error (Debugger
*debugger
, const GDBMIValue
*mi_results
)
979 const GDBMIValue
*message
;
980 const gchar
*literal
;
981 guint code
= IANJUTA_DEBUGGER_UNKNOWN_ERROR
;
983 message
= gdbmi_value_hash_lookup (mi_results
, "msg");
984 literal
= gdbmi_value_literal_get (message
);
986 if ((mi_results
!= NULL
)
987 && ((message
= gdbmi_value_hash_lookup (mi_results
, "msg")) != NULL
)
988 && ((literal
= gdbmi_value_literal_get (message
)) != NULL
)
989 && (*literal
!= '\0'))
991 code
= gdb_match_error (literal
);
992 DEBUG_PRINT ("error code %d", code
);
996 /* No error message */
997 literal
= "Error without a message";
1000 return g_error_new_literal (IANJUTA_DEBUGGER_ERROR
, code
, literal
);
1005 *---------------------------------------------------------------------------*/
1008 debugger_parse_output (Debugger
*debugger
)
1012 line
= debugger
->priv
->stdo_line
->str
;
1014 if (line
[0] == '\032' && line
[1] == '\032')
1019 gdb_util_parse_error_line (&(line
[2]), &filename
, &lineno
);
1022 debugger_change_location (debugger
, filename
, lineno
, NULL
);
1031 len
= strlen (line
);
1032 if (line
[1] == '\"' && line
[strlen(line
) - 1] == '\"')
1035 /* Reserve space for an additional carriage return */
1036 line
[strlen(line
) - 1] = ' ';
1037 proper_msg
= g_strcompress (line
+ 1);
1038 len
= strlen (proper_msg
) - 1;
1039 proper_msg
[len
] = '\0';
1043 /* Reserve space for an additional carriage return */
1044 proper_msg
= g_strndup (line
, len
+ 1);
1047 if (strcmp(proper_msg
, "~Stopped due to shared library event\n") == 0)
1049 /* Recognize a solib event */
1050 debugger
->priv
->solib_event
= TRUE
;
1051 g_free (proper_msg
);
1053 else if (debugger
->priv
->current_cmd
.parser
)
1055 /* Save GDB CLI output */
1056 debugger
->priv
->cli_lines
= g_list_prepend (debugger
->priv
->cli_lines
,
1061 /* Discard CLI output */
1062 g_free (proper_msg
);
1068 debugger_parse_stopped (Debugger
*debugger
)
1070 gchar
*line
= debugger
->priv
->stdo_line
->str
;
1073 if (!debugger
->priv
->solib_event
)
1075 gboolean program_exited
= FALSE
;
1078 /* Check if program has exited */
1079 val
= gdbmi_value_parse (line
);
1082 const GDBMIValue
*reason
;
1083 const gchar
*str
= NULL
;
1085 debugger_process_frame (debugger
, val
);
1087 reason
= gdbmi_value_hash_lookup (val
, "reason");
1089 str
= gdbmi_value_literal_get (reason
);
1091 if (str
&& (strncmp (str
, "exited", 6) == 0))
1093 program_exited
= TRUE
;
1096 if (debugger
->priv
->output_callback
)
1098 if (str
&& strcmp (str
, "exited-normally") == 0)
1100 debugger
->priv
->output_callback (IANJUTA_DEBUGGER_OUTPUT
,
1101 _("Program exited normally\n"),
1102 debugger
->priv
->output_user_data
);
1104 else if (str
&& strcmp (str
, "exited") == 0)
1106 const GDBMIValue
*errcode
;
1107 const gchar
*errcode_str
;
1110 errcode
= gdbmi_value_hash_lookup (val
, "exit-code");
1111 errcode_str
= gdbmi_value_literal_get (errcode
);
1112 msg
= g_strdup_printf (_("Program exited with error code %s\n"),
1114 debugger
->priv
->output_callback (IANJUTA_DEBUGGER_OUTPUT
,
1115 msg
, debugger
->priv
->output_user_data
);
1118 else if (str
&& strcmp (str
, "exited-signalled") == 0)
1120 const GDBMIValue
*signal_name
, *signal_meaning
;
1121 const gchar
*signal_str
, *signal_meaning_str
;
1124 signal_name
= gdbmi_value_hash_lookup (val
, "signal-name");
1125 signal_str
= gdbmi_value_literal_get (signal_name
);
1126 signal_meaning
= gdbmi_value_hash_lookup (val
,
1128 signal_meaning_str
= gdbmi_value_literal_get (signal_meaning
);
1129 msg
= g_strdup_printf (_("Program received signal %s (%s) and exited\n"),
1130 signal_str
, signal_meaning_str
);
1131 debugger
->priv
->output_callback (IANJUTA_DEBUGGER_OUTPUT
,
1132 msg
, debugger
->priv
->output_user_data
);
1135 else if (str
&& strcmp (str
, "signal-received") == 0)
1137 const GDBMIValue
*signal_name
, *signal_meaning
;
1138 const gchar
*signal_str
, *signal_meaning_str
;
1141 signal_name
= gdbmi_value_hash_lookup (val
, "signal-name");
1142 signal_str
= gdbmi_value_literal_get (signal_name
);
1143 signal_meaning
= gdbmi_value_hash_lookup (val
,
1145 signal_meaning_str
= gdbmi_value_literal_get (signal_meaning
);
1147 msg
= g_strdup_printf (_("Program received signal %s (%s)\n"),
1148 signal_str
, signal_meaning_str
);
1149 debugger
->priv
->output_callback (IANJUTA_DEBUGGER_OUTPUT
,
1150 msg
, debugger
->priv
->output_user_data
);
1153 else if (str
&& strcmp (str
, "breakpoint-hit") == 0)
1155 const GDBMIValue
*bkptno
;
1156 const gchar
*bkptno_str
;
1159 bkptno
= gdbmi_value_hash_lookup (val
, "bkptno");
1160 bkptno_str
= gdbmi_value_literal_get (bkptno
);
1162 msg
= g_strdup_printf (_("Breakpoint number %s hit\n"),
1164 debugger
->priv
->output_callback (IANJUTA_DEBUGGER_OUTPUT
,
1165 msg
, debugger
->priv
->output_user_data
);
1168 else if (str
&& strcmp (str
, "function-finished") == 0)
1170 debugger
->priv
->output_callback (IANJUTA_DEBUGGER_OUTPUT
,
1171 _("Function finished\n"),
1172 debugger
->priv
->output_user_data
);
1174 else if (str
&& strcmp (str
, "end-stepping-range") == 0)
1176 debugger
->priv
->output_callback (IANJUTA_DEBUGGER_OUTPUT
,
1177 _("Stepping finished\n"),
1178 debugger
->priv
->output_user_data
);
1180 else if (str
&& strcmp (str
, "location-reached") == 0)
1182 debugger
->priv
->output_callback (IANJUTA_DEBUGGER_OUTPUT
,
1183 _("Location reached\n"),
1184 debugger
->priv
->output_user_data
);
1191 debugger
->priv
->prog_is_running
= FALSE
;
1192 debugger
->priv
->prog_is_attached
= FALSE
;
1193 DEBUG_PRINT ("stop terminal in parse stopped");
1194 debugger_stop_terminal (debugger
);
1195 // g_signal_emit_by_name (debugger->priv->instance, "program-exited");
1196 debugger_handle_post_execution (debugger
);
1197 debugger
->priv
->exiting
= TRUE
;
1201 // g_signal_emit_by_name (debugger->priv->instance, "program-stopped");
1202 debugger
->priv
->stopping
= TRUE
;
1205 debugger
->priv
->cli_lines
= g_list_reverse (debugger
->priv
->cli_lines
);
1206 if (debugger
->priv
->current_cmd
.cmd
[0] != '\0' &&
1207 debugger
->priv
->current_cmd
.parser
!= NULL
)
1209 debugger
->priv
->current_cmd
.parser (debugger
, val
,
1210 debugger
->priv
->cli_lines
, FALSE
);
1211 debugger
->priv
->command_output_sent
= TRUE
;
1212 DEBUG_PRINT ("In function: Sending output...");
1216 gdbmi_value_free (val
);
1221 debugger_parse_prompt (Debugger
*debugger
)
1223 /* If the parser has not yet been called, call it now. */
1224 if (debugger
->priv
->command_output_sent
== FALSE
&&
1225 debugger
->priv
->current_cmd
.parser
)
1227 debugger
->priv
->current_cmd
.parser (debugger
, NULL
,
1228 debugger
->priv
->cli_lines
, FALSE
);
1229 debugger
->priv
->command_output_sent
= TRUE
;
1232 debugger
->priv
->debugger_is_busy
--;
1234 if (!debugger
->priv
->debugger_is_busy
&&
1235 g_list_length (debugger
->priv
->cmd_queqe
) >= 1)
1237 debugger_queue_execute_command (debugger
); /* Next command. Go. */
1239 debugger_emit_status (debugger
);
1242 if (debugger
->priv
->skip_next_prompt
)
1244 // Gdb is running in synchronous mode
1245 // new command are accepted only after executing
1247 debugger
->priv
->skip_next_prompt
= FALSE
;
1251 if (debugger
->priv
->starting
)
1253 debugger
->priv
->starting
= FALSE
;
1254 /* Debugger has just started */
1255 if (debugger
->priv
->output_callback
)
1257 debugger
->priv
->output_callback (IANJUTA_DEBUGGER_OUTPUT
,
1258 _("Debugger is ready.\n"),
1259 debugger
->priv
->output_user_data
);
1261 g_signal_emit_by_name (debugger
->priv
->instance
, "debugger-started");
1265 debugger
->priv
->debugger_is_busy
--;
1267 if (strcmp (debugger
->priv
->current_cmd
.cmd
, "-exec-run") == 0 &&
1268 debugger
->priv
->prog_is_running
== FALSE
)
1270 /* Program has failed to run */
1271 debugger_stop_terminal (debugger
);
1274 /* If the parser has not yet been called, call it now. */
1275 if (debugger
->priv
->command_output_sent
== FALSE
&&
1276 debugger
->priv
->current_cmd
.parser
)
1278 debugger
->priv
->current_cmd
.parser (debugger
, NULL
,
1279 debugger
->priv
->cli_lines
,
1280 debugger
->priv
->current_cmd
.callback
,
1281 debugger
->priv
->current_cmd
.user_data
);
1282 debugger
->priv
->command_output_sent
= TRUE
;
1286 if (!debugger
->priv
->debugger_is_busy
&&
1287 g_list_length (debugger
->priv
->cmd_queqe
) >= 1)
1289 static int ctag
= 0;
1291 debugger_queue_execute_command (debugger
); /* Next command. Go. */
1293 debugger_emit_status (debugger
);
1300 debugger_stdo_flush (Debugger
*debugger
)
1304 line
= debugger
->priv
->stdo_line
->str
;
1306 DEBUG_PRINT ("Log: %s\n", line
);
1307 debugger_log_output (debugger
, line
);
1308 if (strlen (line
) == 0)
1312 if (strncasecmp (line
, "^error", 6) == 0)
1314 /* GDB reported error */
1315 if (debugger
->priv
->current_cmd
.suppress_error
== FALSE
)
1317 GDBMIValue
*val
= gdbmi_value_parse (line
);
1320 error
= gdb_parse_error (debugger
, val
);
1322 if (debugger
->priv
->current_cmd
.parser
!= NULL
)
1324 debugger
->priv
->current_cmd
.parser (debugger
, val
, debugger
->priv
->cli_lines
, error
);
1325 debugger
->priv
->command_output_sent
= TRUE
; }
1328 anjuta_util_dialog_error (debugger
->priv
->parent_win
,
1332 g_error_free (error
);
1333 gdbmi_value_free (val
);
1336 else if (strncasecmp(line
, "^running", 8) == 0)
1338 /* Program started running */
1339 debugger
->priv
->prog_is_running
= TRUE
;
1340 /* debugger->priv->skip_next_prompt = TRUE; Replaced by debugger_is_busy++ */
1341 debugger
->priv
->debugger_is_busy
++;
1342 g_signal_emit_by_name (debugger
->priv
->instance
, "program-running");
1344 else if (strncasecmp (line
, "*stopped", 8) == 0)
1346 /* Process has stopped */
1347 debugger_parse_stopped (debugger
);
1349 else if (strncasecmp (line
, "^done", 5) == 0)
1351 if ((debugger
->priv
->current_cmd
.keep_result
) || (debugger
->priv
->stdo_acc
->len
!= 0))
1353 /* Keep result for next command */
1355 if (debugger
->priv
->stdo_acc
->len
== 0)
1357 g_string_append (debugger
->priv
->stdo_acc
, line
);
1361 line
= strchr (line
, ',');
1364 g_string_append (debugger
->priv
->stdo_acc
, line
);
1367 line
= debugger
->priv
->stdo_acc
->str
;
1370 if (!debugger
->priv
->current_cmd
.keep_result
)
1372 /* GDB command has reported output */
1373 GDBMIValue
*val
= gdbmi_value_parse (line
);
1375 debugger
->priv
->cli_lines
= g_list_reverse (debugger
->priv
->cli_lines
);
1376 if (debugger
->priv
->current_cmd
.cmd
[0] != '\0' &&
1377 debugger
->priv
->current_cmd
.parser
!= NULL
)
1379 debugger
->priv
->current_cmd
.parser (debugger
, val
,
1380 debugger
->priv
->cli_lines
, FALSE
);
1381 debugger
->priv
->command_output_sent
= TRUE
;
1382 DEBUG_PRINT ("In function: Sending output...");
1386 /*g_signal_emit_by_name (debugger, "results-arrived",
1387 debugger->priv->current_cmd.cmd, val);*/
1392 debugger_process_frame (debugger
, val
);
1393 gdbmi_value_free (val
);
1397 if (!debugger
->priv
->current_cmd
.keep_result
)
1399 g_string_assign (debugger
->priv
->stdo_acc
, "");
1402 else if (strncasecmp (line
, GDB_PROMPT
, strlen (GDB_PROMPT
)) == 0)
1404 debugger_parse_prompt (debugger
);
1408 debugger_parse_output (debugger
);
1411 /* Clear the line buffer */
1412 g_string_assign (debugger
->priv
->stdo_line
, "");
1416 debugger_stde_flush (Debugger
*debugger
)
1418 if ((debugger
->priv
->output_callback
) && (strlen (debugger
->priv
->stde_line
->str
) > 0))
1420 debugger
->priv
->output_callback (IANJUTA_DEBUGGER_ERROR_OUTPUT
,
1421 debugger
->priv
->stde_line
->str
,
1422 debugger
->priv
->output_user_data
);
1424 /* Clear the line buffer */
1425 g_string_assign (debugger
->priv
->stde_line
, "");
1429 on_gdb_terminated (AnjutaLauncher
*launcher
,
1430 gint child_pid
, gint status
, gulong t
,
1433 Debugger
*debugger
= DEBUGGER (data
);
1435 g_signal_handlers_disconnect_by_func (G_OBJECT (launcher
),
1436 G_CALLBACK (on_gdb_terminated
),
1439 DEBUG_PRINT ("In function: gdb_terminated()");
1441 /* Clear the command queue & Buffer */
1442 debugger_clear_buffers (debugger
);
1443 //debugger_stop_terminal (debugger);
1445 /* Good Bye message */
1446 if (!debugger
->priv
->terminating
)
1448 anjuta_util_dialog_error (debugger
->priv
->parent_win
,
1449 _("gdb terminated unexpectedly with status %d\n"), status
);
1451 debugger_stop_terminal (debugger
);
1452 debugger
->priv
->prog_is_running
= FALSE
;
1453 debugger
->priv
->term_is_running
= FALSE
;
1454 debugger
->priv
->term_pid
= -1;
1455 debugger
->priv
->debugger_is_busy
= 0;
1456 debugger
->priv
->skip_next_prompt
= FALSE
;
1457 debugger
->priv
->terminating
= FALSE
;
1458 if (debugger
->priv
->instance
)
1459 g_signal_emit_by_name (debugger
->priv
->instance
, "debugger-stopped");
1463 debugger_stop_real (Debugger
*debugger
)
1465 DEBUG_PRINT ("In function: debugger_stop_real()");
1467 /* if program is attached - detach from it before quiting */
1468 if (debugger
->priv
->prog_is_attached
== TRUE
)
1469 debugger_queue_command (debugger
, "detach", FALSE
, FALSE
, NULL
, NULL
, NULL
);
1471 debugger_stop_terminal (debugger
);
1472 debugger
->priv
->terminating
= TRUE
;
1473 debugger_queue_command (debugger
, "-gdb-exit", FALSE
, FALSE
, NULL
, NULL
, NULL
);
1477 debugger_stop (Debugger
*debugger
)
1479 gboolean ret
= TRUE
;
1481 if (debugger
->priv
->prog_is_running
== TRUE
)
1486 if (debugger
->priv
->prog_is_attached
== TRUE
)
1487 mesg
= _("The program is attached.\n"
1488 "Do you still want to stop the debugger?");
1490 mesg
= _("The program is running.\n"
1491 "Do you still want to stop the debugger?");
1492 dialog
= gtk_message_dialog_new (debugger
->priv
->parent_win
,
1493 GTK_DIALOG_DESTROY_WITH_PARENT
,
1494 GTK_MESSAGE_QUESTION
,
1495 GTK_BUTTONS_NONE
, mesg
);
1496 gtk_dialog_add_buttons (GTK_DIALOG (dialog
),
1497 GTK_STOCK_CANCEL
, GTK_RESPONSE_NO
,
1498 GTK_STOCK_STOP
, GTK_RESPONSE_YES
,
1500 if (gtk_dialog_run (GTK_DIALOG (dialog
)) == GTK_RESPONSE_YES
)
1501 debugger_stop_real (debugger
);
1504 gtk_widget_destroy (dialog
);
1507 debugger_stop_real (debugger
);
1512 debugger_abort (Debugger
*debugger
)
1514 DEBUG_PRINT ("In function: debugger_abort()");
1517 debugger_stop_terminal (debugger
);
1518 debugger
->priv
->terminating
= TRUE
;
1521 anjuta_launcher_reset (debugger
->priv
->launcher
);
1524 if ((debugger
->priv
->prog_is_attached
== FALSE
) && (debugger
->priv
->inferior_pid
!= 0))
1526 kill (debugger
->priv
->inferior_pid
, SIGTERM
);
1530 debugger_queue_clear (debugger
);
1531 g_list_foreach (debugger
->priv
->search_dirs
, (GFunc
)g_free
, NULL
);
1532 g_list_free (debugger
->priv
->search_dirs
);
1533 debugger
->priv
->search_dirs
= NULL
;
1536 if (debugger
->priv
->instance
!= NULL
)
1538 /* Signal end of debugger */
1539 g_signal_emit_by_name (debugger
->priv
->instance
, "debugger-stopped");
1541 g_object_remove_weak_pointer (debugger
->priv
->instance
, (gpointer
*)&debugger
->priv
->instance
);
1542 debugger
->priv
->instance
= NULL
;
1549 on_debugger_terminal_terminated (int status
, gpointer user_data
)
1551 Debugger
*debugger
= DEBUGGER (user_data
);
1553 DEBUG_PRINT ("In function: on_debugger_terminal_terminated()");
1555 debugger
->priv
->term_is_running
= FALSE
;
1556 debugger
->priv
->term_pid
= -1;
1558 if (debugger
->priv
->prog_is_running
)
1559 debugger_stop_program (debugger
);
1563 debugger_get_source_path (Debugger
*debugger
, const gchar
*file
)
1568 if (g_path_is_absolute (file
))
1569 return g_strdup (file
);
1571 node
= debugger
->priv
->search_dirs
;
1574 path
= g_build_filename (node
->data
, file
, NULL
);
1575 if (g_file_test (path
, G_FILE_TEST_EXISTS
))
1579 node
= g_list_next (node
);
1584 /* The file could be found nowhere. Use current directory */
1586 cwd
= g_get_current_dir ();
1587 path
= g_build_filename (cwd
, file
, NULL
);
1594 debugger_set_output_callback (Debugger
*debugger
, IAnjutaDebuggerOutputCallback callback
, gpointer user_data
)
1596 debugger
->priv
->output_callback
= callback
;
1597 debugger
->priv
->output_user_data
= user_data
;
1601 debugger_change_location (Debugger
*debugger
, const gchar
*file
,
1602 gint line
, const gchar
*address
)
1606 if ((file
!= NULL
) && (*file
!= G_DIR_SEPARATOR
))
1608 src_path
= debugger_get_source_path (debugger
, file
);
1609 g_signal_emit_by_name (debugger
->priv
->instance
, "location-changed", src_path
, line
, address
);
1614 g_signal_emit_by_name (debugger
->priv
->instance
, "location-changed", file
, line
, address
);
1619 debugger_start_terminal (Debugger
*debugger
)
1621 gchar
*file
, *cmd
, *encoded_cmd
;
1622 gchar dev_name
[100];
1629 DEBUG_PRINT ("In function: debugger_start_terminal()");
1631 if (debugger
->priv
->prog_is_running
== TRUE
)
1633 if (debugger
->priv
->term_is_running
== TRUE
)
1635 if (anjuta_util_prog_is_installed ("anjuta_launcher", TRUE
) == FALSE
)
1639 file
= anjuta_util_get_a_tmp_file ();
1641 while (g_file_test (file
, G_FILE_TEST_IS_REGULAR
))
1644 file
= anjuta_util_get_a_tmp_file ();
1648 if (mkfifo (file
, 0664) < 0)
1651 debugger
->priv
->term_is_running
= TRUE
;
1652 cmd
= g_strconcat ("anjuta_launcher --__debug_terminal ", file
, NULL
);
1653 encoded_cmd
= anjuta_util_escape_quotes (cmd
);
1656 cmd
= g_strdup ("gnome-terminal -e \"%s\"");
1660 if (strstr (cmd
, "%s") != NULL
)
1662 final_cmd
= g_strdup_printf (cmd
, encoded_cmd
);
1666 final_cmd
= g_strconcat (cmd
, " ", encoded_cmd
, NULL
);
1671 g_free (encoded_cmd
);
1673 args
= anjuta_util_parse_args_from_string (cmd
);
1675 /* Fix gnome-terminal1 and gnome-terminal2 confusion */
1676 if (g_list_length(args
) > 0 &&
1677 strcmp ((gchar
*)args
->data
, "gnome-terminal") == 0)
1680 node
= g_list_next(args
);
1681 /* Terminal command is gnome-terminal */
1682 if (debugger
->priv
->gnome_terminal_type
== 1) {
1683 /* Remove any --disable-factory option, if present */
1685 if (strcmp ((gchar
*)args
->data
, "--disable-factory") == 0) {
1686 g_free (node
->data
);
1687 args
= g_list_remove (args
, node
);
1690 node
= g_list_next (node
);
1692 } else if (debugger
->priv
->gnome_terminal_type
== 2) {
1693 /* Add --disable-factory option, if not present */
1696 if (strcmp ((gchar
*)args
->data
, "--disable-factory") == 0) {
1700 node
= g_list_next (node
);
1703 gchar
* arg
= g_strdup ("--disable-factory");
1704 args
= g_list_insert (args
, arg
, 1);
1709 DEBUG_PRINT ("Terminal command: [%s]\n", cmd
);
1713 /* Rearrange the args to be passed to fork */
1717 argv
[idx
++] = (gchar
*)node
->data
;
1718 node
= g_list_next (node
);
1727 g_print ("%d) [%s]\n", i
++, (char*)node
->data
);
1728 node
= g_list_next (node
);
1737 /* With this command SIGCHILD is not emitted */
1738 /* pid = gnome_execute_async (app->dirs->home, 6, av); */
1739 /* so using fork instead */
1740 if ((pid
= fork ()) == 0)
1742 execvp (argv
[0], argv
);
1743 g_error (_("Cannot execute gnome-terminal"));
1745 g_list_foreach (args
, (GFunc
)g_free
, NULL
);
1748 debugger
->priv
->term_pid
= pid
;
1751 DEBUG_PRINT ("terminal pid = %d\n", pid
);
1752 anjuta_children_register (pid
, on_debugger_terminal_terminated
, debugger
);
1755 * May be the terminal is not started properly.
1756 * Callback will reset this flag
1758 if (debugger
->priv
->term_is_running
== FALSE
)
1762 * Warning: call to fopen() may be blocked if the terminal is not properly started.
1763 * I don't know how to handle this. May be opening as non-blocking will solve this .
1765 fp
= fopen (file
, "r"); /* Ok, take the risk. */
1769 if (fscanf (fp
, "%s", dev_name
) < 1)
1773 if (strcmp (dev_name
, "__ERROR__") == 0)
1776 return g_strdup (dev_name
);
1778 anjuta_util_dialog_error (debugger
->priv
->parent_win
,
1779 _("Cannot start terminal for debugging."));
1780 debugger_stop_terminal (debugger
);
1787 debugger_stop_terminal (Debugger
*debugger
)
1789 DEBUG_PRINT ("In function: debugger_stop_terminal()");
1791 if (debugger
->priv
->term_is_running
== FALSE
)
1793 if (debugger
->priv
->term_pid
> 0) {
1794 anjuta_children_unregister (debugger
->priv
->term_pid
);
1795 if (kill (debugger
->priv
->term_pid
, SIGTERM
) == -1) {
1798 g_warning ("Invalid signal applied to kill");
1801 g_warning ("No such pid [%d] or process has already died",
1802 debugger
->priv
->term_pid
);
1805 g_warning ("No permission to send signal to the process");
1808 g_warning ("Unknow error while kill");
1812 debugger
->priv
->term_pid
= -1;
1813 debugger
->priv
->term_is_running
= FALSE
;
1817 debugger_info_program_finish (Debugger
*debugger
, const GDBMIValue
*mi_results
,
1818 const GList
*cli_results
, GError
*error
)
1820 DEBUG_PRINT ("In function: debugger_info_program()");
1822 /* Hack: find message string giving inferior pid */
1823 while (cli_results
!= NULL
)
1827 child_proc
= strstr(cli_results
->data
, " child process ");
1828 if (child_proc
!= NULL
)
1830 debugger
->priv
->inferior_pid
= strtoul (child_proc
+ 15, NULL
, 10);
1833 cli_results
= g_list_next (cli_results
);
1838 debugger_start_program (Debugger
*debugger
, const gchar
* args
)
1842 DEBUG_PRINT ("In function: debugger_start_program()");
1844 g_return_if_fail (IS_DEBUGGER (debugger
));
1845 g_return_if_fail (debugger
->priv
->prog_is_running
== FALSE
);
1847 debugger
->priv
->inferior_pid
= 0;
1848 debugger_queue_command (debugger
, "-break-insert -t main", FALSE
, FALSE
, NULL
, NULL
, NULL
);
1849 if (args
&& (*args
))
1851 cmd
= g_strconcat ("-exec-arguments ", args
, NULL
);
1852 debugger_queue_command (debugger
, cmd
, FALSE
, FALSE
, NULL
, NULL
, NULL
);
1856 debugger_queue_command (debugger
, "-exec-run", FALSE
, FALSE
, NULL
, NULL
, NULL
);
1858 /* Get pid of program on next stop */
1859 debugger_queue_command (debugger
, "info program", FALSE
, FALSE
, debugger_info_program_finish
, NULL
, NULL
);
1860 debugger
->priv
->post_execution_flag
= DEBUGGER_NONE
;
1864 debugger_attach_process_finish (Debugger
*debugger
, const GDBMIValue
*mi_results
,
1865 const GList
*cli_results
, GError
*error
)
1867 DEBUG_PRINT ("Program attach finished");
1868 if (debugger
->priv
->output_callback
)
1870 debugger
->priv
->output_callback (IANJUTA_DEBUGGER_OUTPUT
,
1871 _("Program attached\n"),
1872 debugger
->priv
->output_user_data
);
1874 debugger
->priv
->prog_is_attached
= TRUE
;
1875 debugger
->priv
->prog_is_running
= TRUE
;
1876 g_signal_emit_by_name (debugger
->priv
->instance
, "program-exited");
1880 debugger_attach_process_real (Debugger
*debugger
, pid_t pid
)
1884 DEBUG_PRINT ("In function: debugger_attach_process_real()");
1886 if (debugger
->priv
->output_callback
)
1888 buff
= g_strdup_printf (_("Attaching to process: %d...\n"), pid
);
1889 debugger
->priv
->output_callback (IANJUTA_DEBUGGER_OUTPUT
,
1890 buff
, debugger
->priv
->output_user_data
);
1894 debugger
->priv
->inferior_pid
= pid
;
1895 buff
= g_strdup_printf ("attach %d", pid
);
1896 debugger_queue_command (debugger
, buff
, FALSE
, FALSE
,
1897 debugger_attach_process_finish
, NULL
, NULL
);
1902 debugger_attach_process (Debugger
*debugger
, pid_t pid
)
1904 DEBUG_PRINT ("In function: debugger_attach_process()");
1906 g_return_if_fail (IS_DEBUGGER (debugger
));
1908 if (debugger
->priv
->prog_is_running
== TRUE
)
1910 // TODO: Dialog to be made HIG compliant.
1914 mesg
= _("A process is already running.\n"
1915 "Would you like to terminate it and attach the new process?"),
1916 dialog
= gtk_message_dialog_new (debugger
->priv
->parent_win
,
1917 GTK_DIALOG_DESTROY_WITH_PARENT
,
1918 GTK_MESSAGE_QUESTION
,
1919 GTK_BUTTONS_YES_NO
, mesg
);
1920 if (gtk_dialog_run (GTK_DIALOG (dialog
)) == GTK_RESPONSE_YES
)
1922 debugger_stop_program (debugger
);
1923 debugger_attach_process_real (debugger
, pid
);
1925 gtk_widget_destroy (dialog
);
1927 else if (getpid () == pid
||
1928 anjuta_launcher_get_child_pid (debugger
->priv
->launcher
) == pid
)
1930 anjuta_util_dialog_error (debugger
->priv
->parent_win
,
1931 _("Anjuta is unable to attach to itself."));
1935 debugger_attach_process_real (debugger
, pid
);
1939 debugger_restart_program (Debugger
*debugger
)
1941 DEBUG_PRINT ("In function: debugger_restart_program()");
1943 g_return_if_fail (debugger
->priv
->prog_is_attached
== FALSE
);
1946 debugger->priv->post_execution_flag = DEBUGGER_RERUN_PROGRAM;
1947 debugger_stop_program (debugger);
1949 debugger_put_cmd_in_queqe ("tbreak main", DB_CMD_NONE, NULL, NULL);
1950 debugger_put_cmd_in_queqe ("run >/dev/null 2>/dev/null", DB_CMD_ALL,
1952 debugger_put_cmd_in_queqe ("info program", DB_CMD_NONE,
1953 on_debugger_update_prog_status, NULL);
1954 debugger_put_cmd_in_queqe ("continue", DB_CMD_NONE, NULL, NULL);
1955 debugger_execute_cmd_in_queqe ();
1960 debugger_stop_program (Debugger
*debugger
)
1962 DEBUG_PRINT ("In function: debugger_stop_program()");
1964 g_return_if_fail (debugger
->priv
->prog_is_running
== TRUE
);
1966 if (debugger
->priv
->prog_is_attached
== TRUE
)
1967 debugger_queue_command (debugger
, "detach", FALSE
, FALSE
, NULL
, NULL
, NULL
);
1970 /* FIXME: Why doesn't -exec-abort work??? */
1971 /* debugger_queue_command (debugger, "-exec-abort", NULL, NULL); */
1972 debugger_queue_command (debugger
, "kill", FALSE
, FALSE
, NULL
, NULL
, NULL
);
1973 debugger
->priv
->prog_is_running
= FALSE
;
1974 debugger
->priv
->prog_is_attached
= FALSE
;
1975 DEBUG_PRINT ("stop terminal in stop program");
1976 debugger_stop_terminal (debugger
);
1977 g_signal_emit_by_name (debugger
->priv
->instance
, "program-exited");
1978 if (debugger
->priv
->output_callback
)
1980 debugger
->priv
->output_callback (IANJUTA_DEBUGGER_OUTPUT
,
1981 _("Program terminated\n"),
1982 debugger
->priv
->output_user_data
);
1984 debugger_handle_post_execution (debugger
);
1989 debugger_detach_process_finish (Debugger
*debugger
, const GDBMIValue
*mi_results
,
1990 const GList
*cli_results
, GError
*error
)
1992 DEBUG_PRINT ("Program detach finished");
1993 if (debugger
->priv
->output_callback
)
1995 debugger
->priv
->output_callback (IANJUTA_DEBUGGER_OUTPUT
,
1996 _("Program detached\n"),
1997 debugger
->priv
->output_user_data
);
1999 debugger
->priv
->prog_is_attached
= FALSE
;
2000 debugger
->priv
->prog_is_running
= FALSE
;
2001 g_signal_emit_by_name (debugger
->priv
->instance
, "program-exited");
2005 debugger_detach_process (Debugger
*debugger
)
2009 DEBUG_PRINT ("In function: debugger_detach_process()");
2011 g_return_if_fail (debugger
->priv
->prog_is_attached
== TRUE
);
2013 if (debugger
->priv
->output_callback
)
2015 buff
= g_strdup_printf (_("Detaching the process...\n"));
2016 debugger
->priv
->output_callback (IANJUTA_DEBUGGER_OUTPUT
,
2017 buff
, debugger
->priv
->output_user_data
);
2021 debugger_queue_command (debugger
, "detach", FALSE
, FALSE
,
2022 debugger_detach_process_finish
, NULL
, NULL
);
2023 debugger
->priv
->prog_is_attached
= FALSE
;
2027 debugger_interrupt (Debugger
*debugger
)
2029 DEBUG_PRINT ("In function: debugger_interrupt()");
2031 g_return_if_fail (IS_DEBUGGER (debugger
));
2032 g_return_if_fail (debugger
->priv
->prog_is_running
== TRUE
);
2034 if (debugger
->priv
->output_callback
)
2036 debugger
->priv
->output_callback (IANJUTA_DEBUGGER_OUTPUT
,
2037 _("Interrupting the process\n"),
2038 debugger
->priv
->output_user_data
);
2041 if (debugger
->priv
->inferior_pid
== 0)
2043 /* In case we do not have the inferior pid, send signal to gdb */
2044 anjuta_launcher_signal (debugger
->priv
->launcher
, SIGINT
);
2048 /* Send signal directly to inferior */
2049 kill (debugger
->priv
->inferior_pid
, SIGINT
);
2051 //g_signal_emit_by_name (debugger->priv->instance, "program-running");
2055 debugger_run (Debugger
*debugger
)
2057 DEBUG_PRINT ("In function: debugger_run()");
2059 g_return_if_fail (IS_DEBUGGER (debugger
));
2060 g_return_if_fail (debugger
->priv
->prog_is_running
== TRUE
);
2062 /* Program running - continue */
2063 debugger_queue_command (debugger
, "-exec-continue", FALSE
, FALSE
, NULL
, NULL
, NULL
);
2067 debugger_step_in (Debugger
*debugger
)
2069 DEBUG_PRINT ("In function: debugger_step_in()");
2071 g_return_if_fail (IS_DEBUGGER (debugger
));
2072 g_return_if_fail (debugger
->priv
->prog_is_running
== TRUE
);
2074 debugger_queue_command (debugger
, "-exec-step", FALSE
, FALSE
, NULL
, NULL
, NULL
);
2078 debugger_step_over (Debugger
*debugger
)
2080 DEBUG_PRINT ("In function: debugger_step_over()");
2082 g_return_if_fail (IS_DEBUGGER (debugger
));
2083 g_return_if_fail (debugger
->priv
->prog_is_running
== TRUE
);
2085 debugger_queue_command (debugger
, "-exec-next", FALSE
, FALSE
, NULL
, NULL
, NULL
);
2089 debugger_step_out (Debugger
*debugger
)
2091 DEBUG_PRINT ("In function: debugger_step_out()");
2093 g_return_if_fail (IS_DEBUGGER (debugger
));
2094 g_return_if_fail (debugger
->priv
->prog_is_running
== TRUE
);
2096 debugger_queue_command (debugger
, "-exec-finish", FALSE
, FALSE
, NULL
, NULL
, NULL
);
2100 debugger_run_to_location (Debugger
*debugger
, const gchar
*loc
)
2104 DEBUG_PRINT ("In function: debugger_run_to_location()");
2106 g_return_if_fail (IS_DEBUGGER (debugger
));
2107 g_return_if_fail (debugger
->priv
->prog_is_running
== TRUE
);
2109 buff
= g_strdup_printf ("-exec-until %s", loc
);
2110 debugger_queue_command (debugger
, buff
, FALSE
, FALSE
, NULL
, NULL
, NULL
);
2115 debugger_run_to_position (Debugger
*debugger
, const gchar
*file
, guint line
)
2119 DEBUG_PRINT ("In function: debugger_run_to_position()");
2121 g_return_if_fail (IS_DEBUGGER (debugger
));
2122 g_return_if_fail (debugger
->priv
->prog_is_running
== TRUE
);
2124 buff
= g_strdup_printf ("-exec-until %s:%d", file
, line
);
2125 debugger_queue_command (debugger
, buff
, FALSE
, FALSE
, NULL
, NULL
, NULL
);
2130 debugger_command (Debugger
*debugger
, const gchar
*command
,
2131 gboolean suppress_error
, DebuggerParserFunc parser
,
2134 if (strncasecmp (command
, "-exec-run",
2135 strlen ("-exec-run")) == 0 ||
2136 strncasecmp (command
, "run", strlen ("run")) == 0)
2138 /* FIXME: The user might have passed args to the command */
2139 debugger_run (debugger
);
2141 else if (strncasecmp (command
, "-exec-step",
2142 strlen ("-exec-step")) == 0 ||
2143 strncasecmp (command
, "step", strlen ("step")) == 0)
2145 debugger_step_in (debugger
);
2147 else if (strncasecmp (command
, "-exec-next",
2148 strlen ("-exec-next")) == 0 ||
2149 strncasecmp (command
, "next", strlen ("next")) == 0)
2151 debugger_step_over (debugger
);
2153 else if (strncasecmp (command
, "-exec-finish",
2154 strlen ("-exec-finish")) == 0 ||
2155 strncasecmp (command
, "finish", strlen ("finish")) == 0)
2157 debugger_step_out (debugger
);
2159 else if (strncasecmp (command
, "-exec-continue",
2160 strlen ("-exec-continue")) == 0 ||
2161 strncasecmp (command
, "continue", strlen ("continue")) == 0)
2163 debugger_run (debugger
);
2165 else if (strncasecmp (command
, "-exec-until",
2166 strlen ("-exec-until")) == 0 ||
2167 strncasecmp (command
, "until", strlen ("until")) == 0)
2169 debugger_run_to_location (debugger
, strchr (command
, ' '));
2171 else if (strncasecmp (command
, "-exec-abort",
2172 strlen ("-exec-abort")) == 0 ||
2173 strncasecmp (command
, "kill", strlen ("kill")) == 0)
2175 debugger_stop_program (debugger
);
2177 else if (strncasecmp (command
, "-target-attach",
2178 strlen ("-target-attach")) == 0 ||
2179 strncasecmp (command
, "attach", strlen ("attach")) == 0)
2182 gchar
*pid_str
= strchr (command
, ' ');
2184 pid
= atoi (pid_str
);
2185 debugger_attach_process (debugger
, pid
);
2187 else if (strncasecmp (command
, "-target-detach",
2188 strlen ("-target-detach")) == 0 ||
2189 strncasecmp (command
, "detach", strlen ("detach")) == 0)
2191 debugger_detach_process (debugger
);
2193 else if (strncasecmp (command
, "-file-exec-and-symbols",
2194 strlen ("-file-exec-and-symbols")) == 0 ||
2195 strncasecmp (command
, "file", strlen ("file")) == 0)
2197 debugger_load_executable (debugger
, strchr (command
, ' '));
2199 else if (strncasecmp (command
, "core", strlen ("core")) == 0)
2201 debugger_load_core (debugger
, strchr (command
, ' '));
2205 debugger_queue_command (debugger
, command
, suppress_error
, FALSE
,
2206 parser
, user_data
, NULL
);
2211 debugger_add_breakpoint_finish (Debugger
*debugger
, const GDBMIValue
*mi_results
, const GList
*cli_results
, GError
*error
)
2213 const GDBMIValue
*brkpnt
;
2214 const GDBMIValue
*literal
;
2216 IAnjutaDebuggerBreakpoint bp
;
2217 IAnjutaDebuggerCallback callback
= debugger
->priv
->current_cmd
.callback
;
2218 gpointer user_data
= debugger
->priv
->current_cmd
.user_data
;
2220 memset (&bp
, 0, sizeof (bp
));
2222 bp
.enable
= IANJUTA_DEBUGGER_UNDEFINED
;
2223 bp
.keep
= IANJUTA_DEBUGGER_UNDEFINED
;
2224 if (mi_results
== NULL
)
2226 if (strncmp((const gchar
*)cli_results
->data
,"&No source file named ", 22) == 0)
2228 /* Breakpoint cannot be set, dynamic library not loaded ? */
2230 /* Useful for enable that doesn't return anything */
2231 if (callback
!= NULL
)
2232 callback (NULL
, user_data
, NULL
);
2236 brkpnt
= gdbmi_value_hash_lookup (mi_results
, "bkpt");
2238 literal
= gdbmi_value_hash_lookup (brkpnt
, "number");
2241 value
= gdbmi_value_literal_get (literal
);
2242 bp
.id
= strtoul (value
, NULL
, 10);
2245 literal
= gdbmi_value_hash_lookup (brkpnt
, "file");
2248 value
= gdbmi_value_literal_get (literal
);
2249 bp
.file
= (gchar
*)value
;
2252 literal
= gdbmi_value_hash_lookup (brkpnt
, "line");
2255 value
= gdbmi_value_literal_get (literal
);
2256 bp
.line
= strtoul (value
, NULL
, 10);
2259 literal
= gdbmi_value_hash_lookup (brkpnt
, "type");
2262 value
= gdbmi_value_literal_get (literal
);
2265 literal
= gdbmi_value_hash_lookup (brkpnt
, "disp");
2268 value
= gdbmi_value_literal_get (literal
);
2269 if (strcmp (value
, "keep") == 0)
2271 bp
.keep
= IANJUTA_DEBUGGER_YES
;
2273 else if (strcmp (value
, "nokeep") == 0)
2275 bp
.keep
= IANJUTA_DEBUGGER_NO
;
2279 literal
= gdbmi_value_hash_lookup (brkpnt
, "enabled");
2282 value
= gdbmi_value_literal_get (literal
);
2283 if (strcmp (value
, "n") == 0)
2285 bp
.enable
= IANJUTA_DEBUGGER_NO
;
2287 else if (strcmp (value
, "y") == 0)
2289 bp
.enable
= IANJUTA_DEBUGGER_YES
;
2293 literal
= gdbmi_value_hash_lookup (brkpnt
, "addr");
2296 value
= gdbmi_value_literal_get (literal
);
2297 bp
.address
= strtoul (value
, NULL
, 16);
2300 literal
= gdbmi_value_hash_lookup (brkpnt
, "func");
2303 value
= gdbmi_value_literal_get (literal
);
2304 bp
.function
= (gchar
*)value
;
2307 literal
= gdbmi_value_hash_lookup (brkpnt
, "times");
2310 value
= gdbmi_value_literal_get (literal
);
2311 bp
.times
= strtoul (value
, NULL
, 10);
2315 bp
.times
= G_MAXUINT32
;
2317 literal
= gdbmi_value_hash_lookup (brkpnt
, "ignore");
2320 value
= gdbmi_value_literal_get (literal
);
2321 bp
.ignore
= strtoul (value
, NULL
, 10);
2325 bp
.ignore
= G_MAXUINT32
;
2328 literal
= gdbmi_value_hash_lookup (brkpnt
, "cond");
2331 value
= gdbmi_value_literal_get (literal
);
2334 /* Call callback in all case (useful for enable that doesn't return
2336 if (callback
!= NULL
)
2337 callback (&bp
, user_data
, NULL
);
2342 debugger_add_breakpoint_at_line (Debugger
*debugger
, const gchar
*file
, guint line
, IAnjutaDebuggerCallback callback
, gpointer user_data
)
2346 DEBUG_PRINT ("In function: debugger_add_breakpoint()");
2348 g_return_if_fail (IS_DEBUGGER (debugger
));
2350 buff
= g_strdup_printf ("-break-insert %s:%u", file
, line
);
2351 debugger_queue_command (debugger
, buff
, FALSE
, FALSE
, debugger_add_breakpoint_finish
, callback
, user_data
);
2356 debugger_add_breakpoint_at_function (Debugger
*debugger
, const gchar
*file
, const gchar
*function
, IAnjutaDebuggerCallback callback
, gpointer user_data
)
2360 DEBUG_PRINT ("In function: debugger_add_breakpoint()");
2362 g_return_if_fail (IS_DEBUGGER (debugger
));
2364 buff
= g_strdup_printf ("-break-insert %s%s%s", file
== NULL
? "" : file
, file
== NULL
? "" : ":" , function
);
2365 debugger_queue_command (debugger
, buff
, FALSE
, FALSE
, debugger_add_breakpoint_finish
, callback
, user_data
);
2370 debugger_add_breakpoint_at_address (Debugger
*debugger
, guint address
, IAnjutaDebuggerCallback callback
, gpointer user_data
)
2374 DEBUG_PRINT ("In function: debugger_add_breakpoint()");
2376 g_return_if_fail (IS_DEBUGGER (debugger
));
2378 buff
= g_strdup_printf ("-break-insert *0x%x", address
);
2379 debugger_queue_command (debugger
, buff
, FALSE
, FALSE
, debugger_add_breakpoint_finish
, callback
, user_data
);
2384 debugger_enable_breakpoint (Debugger
*debugger
, guint id
, gboolean enable
, IAnjutaDebuggerCallback callback
, gpointer user_data
)
2389 DEBUG_PRINT ("In function: debugger_enable_breakpoint()");
2391 g_return_if_fail (IS_DEBUGGER (debugger
));
2393 buff
= g_strdup_printf (enable
? "-break-enable %d" : "-break-disable %d",id
);
2394 debugger_queue_command (debugger
, buff
, FALSE
, FALSE
, debugger_add_breakpoint_finish
, callback
, user_data
);
2399 debugger_ignore_breakpoint (Debugger
*debugger
, guint id
, guint ignore
, IAnjutaDebuggerCallback callback
, gpointer user_data
)
2403 DEBUG_PRINT ("In function: debugger_ignore_breakpoint()");
2405 g_return_if_fail (IS_DEBUGGER (debugger
));
2407 buff
= g_strdup_printf ("-break-after %d %d", id
, ignore
);
2408 debugger_queue_command (debugger
, buff
, FALSE
, FALSE
, debugger_add_breakpoint_finish
, callback
, user_data
);
2413 debugger_condition_breakpoint (Debugger
*debugger
, guint id
, const gchar
*condition
, IAnjutaDebuggerCallback callback
, gpointer user_data
)
2417 DEBUG_PRINT ("In function: debugger_ignore_breakpoint()");
2419 g_return_if_fail (IS_DEBUGGER (debugger
));
2421 buff
= g_strdup_printf ("-break-condition %d %s", id
, condition
);
2422 debugger_queue_command (debugger
, buff
, FALSE
, FALSE
, debugger_add_breakpoint_finish
, callback
, user_data
);
2427 debugger_remove_breakpoint_finish (Debugger
*debugger
, const GDBMIValue
*mi_results
, const GList
*cli_results
, GError
*error
)
2429 IAnjutaDebuggerCallback callback
= debugger
->priv
->current_cmd
.callback
;
2430 gpointer user_data
= debugger
->priv
->current_cmd
.user_data
;
2432 if (callback
!= NULL
)
2433 callback (NULL
, user_data
, NULL
);
2437 debugger_remove_breakpoint (Debugger
*debugger
, guint id
, IAnjutaDebuggerCallback callback
, gpointer user_data
)
2441 DEBUG_PRINT ("In function: debugger_delete_breakpoint()");
2443 g_return_if_fail (IS_DEBUGGER (debugger
));
2445 buff
= g_strdup_printf ("-break-delete %d", id
);
2446 debugger_queue_command (debugger
, buff
, FALSE
, FALSE
, debugger_remove_breakpoint_finish
, callback
, user_data
);
2451 debugger_print_finish (Debugger
*debugger
, const GDBMIValue
*mi_results
, const GList
*cli_results
, GError
*error
)
2456 IAnjutaDebuggerCallback callback
= debugger
->priv
->current_cmd
.callback
;
2457 gpointer user_data
= debugger
->priv
->current_cmd
.user_data
;
2460 list
= gdb_util_remove_blank_lines (cli_results
);
2461 if (g_list_length (list
) < 1)
2467 tmp
= strchr ((gchar
*) list
->data
, '=');
2471 ptr
= g_strdup (tmp
);
2472 for (node
= list
? list
->next
: NULL
; node
!= NULL
; node
= node
->next
)
2475 ptr
= g_strconcat (tmp
, (gchar
*) node
->data
, NULL
);
2480 callback (ptr
, user_data
, NULL
);
2485 debugger_print (Debugger
*debugger
, const gchar
* variable
, IAnjutaDebuggerCallback callback
, gpointer user_data
)
2489 DEBUG_PRINT ("In function: debugger_print()");
2491 g_return_if_fail (IS_DEBUGGER (debugger
));
2493 buff
= g_strdup_printf ("print %s", variable
);
2494 debugger_queue_command (debugger
, buff
, TRUE
, FALSE
, debugger_print_finish
, callback
, user_data
);
2499 debugger_evaluate_finish (Debugger
*debugger
, const GDBMIValue
*mi_results
, const GList
*cli_results
, GError
*error
)
2502 const GDBMIValue
*value
= NULL
;
2503 IAnjutaDebuggerCallback callback
= debugger
->priv
->current_cmd
.callback
;
2504 gpointer user_data
= debugger
->priv
->current_cmd
.user_data
;
2507 value
= gdbmi_value_hash_lookup (mi_results
, "value");
2509 /* Call user function */
2510 if (callback
!= NULL
)
2511 callback (value
== NULL
? "?" : (char *)gdbmi_value_literal_get (value
), user_data
, NULL
);
2515 debugger_evaluate (Debugger
*debugger
, const gchar
* name
, IAnjutaDebuggerCallback callback
, gpointer user_data
)
2518 DEBUG_PRINT ("In function: debugger_add_watch()");
2520 g_return_if_fail (IS_DEBUGGER (debugger
));
2522 buff
= g_strdup_printf ("-data-evaluate-expression %s", name
);
2523 debugger_queue_command (debugger
, buff
, TRUE
, FALSE
, debugger_evaluate_finish
, callback
, user_data
);
2528 debugger_list_local_finish (Debugger
*debugger
, const GDBMIValue
*mi_results
, const GList
*cli_results
, GError
*error
)
2531 const GDBMIValue
*local
, *var
, *frame
, *args
, *stack
;
2535 IAnjutaDebuggerCallback callback
= debugger
->priv
->current_cmd
.callback
;
2536 gpointer user_data
= debugger
->priv
->current_cmd
.user_data
;
2541 stack
= gdbmi_value_hash_lookup (mi_results
, "stack-args");
2544 frame
= gdbmi_value_list_get_nth (stack
, 0);
2547 args
= gdbmi_value_hash_lookup (frame
, "args");
2550 for (i
= 0; i
< gdbmi_value_get_size (args
); i
++)
2552 var
= gdbmi_value_list_get_nth (args
, i
);
2555 name
= gdbmi_value_literal_get (var
);
2556 list
= g_list_prepend (list
, (gchar
*)name
);
2564 /* List local variables */
2565 local
= gdbmi_value_hash_lookup (mi_results
, "locals");
2568 for (i
= 0; i
< gdbmi_value_get_size (local
); i
++)
2570 var
= gdbmi_value_list_get_nth (local
, i
);
2573 name
= gdbmi_value_literal_get (var
);
2574 list
= g_list_prepend (list
, (gchar
*)name
);
2578 list
= g_list_reverse (list
);
2579 callback (list
, user_data
, NULL
);
2584 debugger_list_local (Debugger
*debugger
, IAnjutaDebuggerCallback callback
, gpointer user_data
)
2586 DEBUG_PRINT ("In function: debugger_list_local()");
2588 g_return_if_fail (IS_DEBUGGER (debugger
));
2590 debugger_queue_command (debugger
, "-stack-list-arguments 0 0 0", TRUE
, TRUE
, NULL
, NULL
, NULL
);
2591 debugger_queue_command (debugger
, "-stack-list-locals 0", TRUE
, FALSE
, debugger_list_local_finish
, callback
, user_data
);
2595 debugger_list_argument_finish (Debugger
*debugger
, const GDBMIValue
*mi_results
, const GList
*cli_results
, GError
*error
)
2598 const GDBMIValue
*frame
, *var
, *args
, *stack
;
2602 IAnjutaDebuggerCallback callback
= debugger
->priv
->current_cmd
.callback
;
2603 gpointer user_data
= debugger
->priv
->current_cmd
.user_data
;
2608 stack
= gdbmi_value_hash_lookup (mi_results
, "stack-args");
2611 frame
= gdbmi_value_list_get_nth (stack
, 0);
2614 args
= gdbmi_value_hash_lookup (frame
, "args");
2620 for (i
= 0; i
< gdbmi_value_get_size (args
); i
++)
2622 var
= gdbmi_value_list_get_nth (args
, i
);
2625 name
= gdbmi_value_literal_get (var
);
2626 list
= g_list_prepend (list
, (gchar
*)name
);
2630 list
= g_list_reverse (list
);
2631 callback (list
, user_data
, NULL
);
2636 debugger_list_argument (Debugger
*debugger
, IAnjutaDebuggerCallback callback
, gpointer user_data
)
2638 DEBUG_PRINT ("In function: debugger_list_argument()");
2640 g_return_if_fail (IS_DEBUGGER (debugger
));
2642 debugger_queue_command (debugger
, "-stack-list-argument 0 0 0", TRUE
, FALSE
, debugger_list_argument_finish
, callback
, user_data
);
2646 debugger_info_finish (Debugger
*debugger
, const GDBMIValue
*mi_results
, const GList
*cli_results
, GError
*error
)
2649 IAnjutaDebuggerCallback callback
= debugger
->priv
->current_cmd
.callback
;
2650 gpointer user_data
= debugger
->priv
->current_cmd
.user_data
;
2652 if (callback
!= NULL
)
2653 callback ((GList
*)cli_results
, user_data
, NULL
);
2657 debugger_info_frame (Debugger
*debugger
, guint frame
, IAnjutaDebuggerCallback callback
, gpointer user_data
)
2661 DEBUG_PRINT ("In function: debugger_info_frame()");
2663 g_return_if_fail (IS_DEBUGGER (debugger
));
2667 buff
= g_strdup_printf("info frame");
2671 buff
= g_strdup_printf ("info frame %d", frame
);
2673 debugger_queue_command (debugger
, buff
, TRUE
, FALSE
, (DebuggerParserFunc
)debugger_info_finish
, callback
, user_data
);
2678 debugger_info_signal (Debugger
*debugger
, IAnjutaDebuggerCallback callback
, gpointer user_data
)
2680 DEBUG_PRINT ("In function: debugger_info_signal()");
2682 g_return_if_fail (IS_DEBUGGER (debugger
));
2684 debugger_queue_command (debugger
, "info signals", TRUE
, FALSE
, (DebuggerParserFunc
)debugger_info_finish
, callback
, user_data
);
2688 debugger_info_sharedlib (Debugger
*debugger
, IAnjutaDebuggerCallback callback
, gpointer user_data
)
2692 DEBUG_PRINT ("In function: debugger_info_sharedlib()");
2694 g_return_if_fail (IS_DEBUGGER (debugger
));
2696 buff
= g_strdup_printf ("info sharedlib");
2697 debugger_queue_command (debugger
, buff
, TRUE
, FALSE
, (DebuggerParserFunc
)debugger_info_finish
, callback
, user_data
); g_free (buff
);
2701 debugger_info_args (Debugger
*debugger
, IAnjutaDebuggerCallback callback
, gpointer user_data
)
2703 DEBUG_PRINT ("In function: debugger_info_args()");
2705 g_return_if_fail (IS_DEBUGGER (debugger
));
2707 debugger_queue_command (debugger
, "info args", TRUE
, FALSE
, (DebuggerParserFunc
)debugger_info_finish
, callback
, user_data
);
2711 debugger_info_target (Debugger
*debugger
, IAnjutaDebuggerCallback callback
, gpointer user_data
)
2713 DEBUG_PRINT ("In function: debugger_info_target()");
2715 g_return_if_fail (IS_DEBUGGER (debugger
));
2717 debugger_queue_command (debugger
, "info target", TRUE
, FALSE
, (DebuggerParserFunc
)debugger_info_finish
, callback
, user_data
);
2721 debugger_info_program (Debugger
*debugger
, IAnjutaDebuggerCallback callback
, gpointer user_data
)
2723 DEBUG_PRINT ("In function: debugger_info_program()");
2725 g_return_if_fail (IS_DEBUGGER (debugger
));
2727 debugger_queue_command (debugger
, "info program", TRUE
, FALSE
, (DebuggerParserFunc
)debugger_info_finish
, callback
, user_data
);
2731 debugger_info_udot (Debugger
*debugger
, IAnjutaDebuggerCallback callback
, gpointer user_data
)
2733 DEBUG_PRINT ("In function: debugger_info_udot()");
2735 g_return_if_fail (IS_DEBUGGER (debugger
));
2737 debugger_queue_command (debugger
, "info udot", TRUE
, FALSE
, (DebuggerParserFunc
)debugger_info_finish
, callback
, user_data
);
2741 debugger_info_threads (Debugger
*debugger
, IAnjutaDebuggerCallback callback
, gpointer user_data
)
2743 DEBUG_PRINT ("In function: debugger_info_threads()");
2745 g_return_if_fail (IS_DEBUGGER (debugger
));
2747 debugger_queue_command (debugger
, "info threads", TRUE
, FALSE
, (DebuggerParserFunc
)debugger_info_finish
, callback
, user_data
);
2751 debugger_info_variables (Debugger
*debugger
, IAnjutaDebuggerCallback callback
, gpointer user_data
)
2753 DEBUG_PRINT ("In function: debugger_info_variables()");
2755 g_return_if_fail (IS_DEBUGGER (debugger
));
2757 debugger_queue_command (debugger
, "info variables", TRUE
, FALSE
, (DebuggerParserFunc
)debugger_info_finish
, callback
, user_data
);
2761 debugger_read_memory_finish (Debugger
*debugger
, const GDBMIValue
*mi_results
, const GList
*cli_results
, GError
*error
)
2764 const GDBMIValue
*literal
;
2765 const GDBMIValue
*mem
;
2772 IAnjutaDebuggerCallback callback
= debugger
->priv
->current_cmd
.callback
;
2773 gpointer user_data
= debugger
->priv
->current_cmd
.user_data
;
2774 IAnjutaDebuggerMemory read
= {0,};
2776 literal
= gdbmi_value_hash_lookup (mi_results
, "total-bytes");
2781 len
= strtoul (gdbmi_value_literal_get (literal
), NULL
, 10);
2782 data
= g_new (gchar
, len
* 2);
2783 memset (data
+ len
, 0, len
);
2785 literal
= gdbmi_value_hash_lookup (mi_results
, "addr");
2786 address
= (char *)strtoul (gdbmi_value_literal_get (literal
), NULL
, 0);
2790 mem
= gdbmi_value_hash_lookup (mi_results
, "memory");
2793 mem
= gdbmi_value_list_get_nth (mem
, 0);
2796 mem
= gdbmi_value_hash_lookup (mem
, "data");
2799 size
= gdbmi_value_get_size (mem
);
2804 if (size
< len
) len
= size
;
2805 for (i
= 0; i
< len
; i
++)
2807 literal
= gdbmi_value_list_get_nth (mem
, i
);
2811 value
= gdbmi_value_literal_get (literal
);
2812 *ptr
= strtoul (value
, &endptr
, 16);
2813 if ((*value
!= '\0') && (*endptr
== '\0'))
2821 read
.address
= address
;
2824 callback (&read
, user_data
, NULL
);
2830 callback (NULL
, user_data
, NULL
);
2835 debugger_inspect_memory (Debugger
*debugger
, guint address
, guint length
, IAnjutaDebuggerCallback callback
, gpointer user_data
)
2839 DEBUG_PRINT ("In function: debugger_inspect_memory()");
2841 g_return_if_fail (IS_DEBUGGER (debugger
));
2843 buff
= g_strdup_printf ("-data-read-memory 0x%x x 1 1 %d", address
, length
);
2844 debugger_queue_command (debugger
, buff
, FALSE
, FALSE
, debugger_read_memory_finish
, callback
, user_data
);
2849 debugger_disassemble_finish (Debugger
*debugger
, const GDBMIValue
*mi_results
, const GList
*cli_results
, GError
*error
)
2852 const GDBMIValue
*literal
;
2853 const GDBMIValue
*line
;
2854 const GDBMIValue
*mem
;
2857 IAnjutaDebuggerCallback callback
= debugger
->priv
->current_cmd
.callback
;
2858 gpointer user_data
= debugger
->priv
->current_cmd
.user_data
;
2859 IAnjutaDebuggerDisassembly
*read
= NULL
;
2864 callback (NULL
, user_data
, error
);
2870 mem
= gdbmi_value_hash_lookup (mi_results
, "asm_insns");
2875 size
= gdbmi_value_get_size (mem
);
2876 read
= (IAnjutaDebuggerDisassembly
*)g_malloc0(sizeof (IAnjutaDebuggerDisassembly
) + sizeof(IAnjutaDebuggerALine
) * size
);
2879 for (i
= 0; i
< size
; i
++)
2881 line
= gdbmi_value_list_get_nth (mem
, i
);
2885 literal
= gdbmi_value_hash_lookup (line
, "address");
2888 value
= gdbmi_value_literal_get (literal
);
2889 read
->data
[i
].address
= strtoul (value
, NULL
, 0);
2892 /* Get disassembly line */
2893 literal
= gdbmi_value_hash_lookup (line
, "inst");
2896 read
->data
[i
].text
= gdbmi_value_literal_get (literal
);
2901 /* Remove last line to mark end */
2902 read
->data
[i
- 1].text
= NULL
;
2904 callback (read
, user_data
, NULL
);
2910 callback (NULL
, user_data
, NULL
);
2915 debugger_disassemble (Debugger
*debugger
, guint address
, guint length
, IAnjutaDebuggerCallback callback
, gpointer user_data
)
2920 DEBUG_PRINT ("In function: debugger_disassemble()");
2922 g_return_if_fail (IS_DEBUGGER (debugger
));
2925 /* Handle overflow */
2926 if (address
+ length
< address
) length
= G_MAXUINT
- address
;
2927 buff
= g_strdup_printf ("-data-disassemble -s 0x%x -e 0x%x -- 0", address
, address
+ length
);
2928 debugger_queue_command (debugger
, buff
, FALSE
, FALSE
, debugger_disassemble_finish
, callback
, user_data
);
2933 add_frame (const GDBMIValue
*frame_hash
, GList
** stack
)
2935 const GDBMIValue
*literal
;
2936 IAnjutaDebuggerFrame
* frame
;
2938 frame
= g_new0 (IAnjutaDebuggerFrame
, 1);
2939 *stack
= g_list_prepend (*stack
, frame
);
2941 literal
= gdbmi_value_hash_lookup (frame_hash
, "level");
2943 frame
->level
= strtoul (gdbmi_value_literal_get (literal
), NULL
, 10);
2945 literal
= gdbmi_value_hash_lookup (frame_hash
, "fullname");
2946 if (literal
== NULL
)
2947 literal
= gdbmi_value_hash_lookup (frame_hash
, "file");
2949 frame
->file
= (gchar
*)gdbmi_value_literal_get (literal
);
2951 literal
= gdbmi_value_hash_lookup (frame_hash
, "line");
2953 frame
->line
= strtoul (gdbmi_value_literal_get (literal
), NULL
, 10);
2955 literal
= gdbmi_value_hash_lookup (frame_hash
, "func");
2957 frame
->function
= (gchar
*)gdbmi_value_literal_get (literal
);
2959 literal
= gdbmi_value_hash_lookup (frame_hash
, "addr");
2961 frame
->address
= strtoul (gdbmi_value_literal_get (literal
), NULL
, 16);
2966 set_func_args (const GDBMIValue
*frame_hash
, GList
** node
)
2969 const GDBMIValue
*literal
, *args_list
, *arg_hash
;
2972 IAnjutaDebuggerFrame
* frame
;
2974 literal
= gdbmi_value_hash_lookup (frame_hash
, "level");
2978 level
= gdbmi_value_literal_get (literal
);
2982 frame
= (IAnjutaDebuggerFrame
*)(*node
)->data
;
2984 args_list
= gdbmi_value_hash_lookup (frame_hash
, "args");
2987 args_str
= g_string_new ("(");
2988 for (i
= 0; i
< gdbmi_value_get_size (args_list
); i
++)
2990 const gchar
*name
, *value
;
2992 arg_hash
= gdbmi_value_list_get_nth (args_list
, i
);
2996 literal
= gdbmi_value_hash_lookup (arg_hash
, "name");
2999 name
= gdbmi_value_literal_get (literal
);
3003 literal
= gdbmi_value_hash_lookup (arg_hash
, "value");
3006 value
= gdbmi_value_literal_get (literal
);
3009 args_str
= g_string_append (args_str
, name
);
3010 args_str
= g_string_append (args_str
, "=");
3011 args_str
= g_string_append (args_str
, value
);
3012 if (i
< (gdbmi_value_get_size (args_list
) - 1))
3013 args_str
= g_string_append (args_str
, ", ");
3015 args_str
= g_string_append (args_str
, ")");
3016 frame
->args
= args_str
->str
;
3017 g_string_free (args_str
, FALSE
);
3019 *node
= g_list_next (*node
);
3023 debugger_stack_finish (Debugger
*debugger
, const GDBMIValue
*mi_results
, const GList
*cli_results
, GError
*error
)
3026 GList
* stack
= NULL
;
3028 const GDBMIValue
*stack_list
;
3029 IAnjutaDebuggerCallback callback
= debugger
->priv
->current_cmd
.callback
;
3030 gpointer user_data
= debugger
->priv
->current_cmd
.user_data
;
3035 stack_list
= gdbmi_value_hash_lookup (mi_results
, "stack");
3037 gdbmi_value_foreach (stack_list
, (GFunc
)add_frame
, &stack
);
3041 stack
= g_list_reverse (stack
);
3042 node
= g_list_first (stack
);
3043 stack_list
= gdbmi_value_hash_lookup (mi_results
, "stack-args");
3045 gdbmi_value_foreach (stack_list
, (GFunc
)set_func_args
, &node
);
3047 // Call call back function
3048 if (callback
!= NULL
)
3049 callback (stack
, user_data
, NULL
);
3052 for (node
= g_list_first (stack
); node
!= NULL
; node
= g_list_next (node
))
3054 g_free ((gchar
*)((IAnjutaDebuggerFrame
*)node
->data
)->args
);
3055 g_free (node
->data
);
3058 g_list_free (stack
);
3062 // Call call back function
3063 if (callback
!= NULL
)
3064 callback (NULL
, user_data
, NULL
);
3069 debugger_list_frame (Debugger
*debugger
, IAnjutaDebuggerCallback callback
, gpointer user_data
)
3071 DEBUG_PRINT ("In function: debugger_list_frame()");
3073 g_return_if_fail (IS_DEBUGGER (debugger
));
3075 debugger_queue_command (debugger
, "-stack-list-frames", TRUE
, TRUE
, NULL
, NULL
, NULL
);
3076 debugger_queue_command (debugger
, "-stack-list-arguments 1", TRUE
, FALSE
, debugger_stack_finish
, callback
, user_data
);
3080 add_register_name (const GDBMIValue
*reg_literal
, GList
** list
)
3082 IAnjutaDebuggerRegister
* reg
;
3083 GList
*prev
= *list
;
3085 reg
= g_new0 (IAnjutaDebuggerRegister
, 1);
3086 *list
= g_list_prepend (prev
, reg
);
3087 reg
->name
= (gchar
*)gdbmi_value_literal_get (reg_literal
);
3088 reg
->num
= prev
== NULL
? 0 : ((IAnjutaDebuggerRegister
*)prev
->data
)->num
+ 1;
3092 add_register_value (const GDBMIValue
*reg_hash
, GList
** list
)
3094 const GDBMIValue
*literal
;
3096 IAnjutaDebuggerRegister
* reg
;
3098 GList
* prev
= *list
;
3100 literal
= gdbmi_value_hash_lookup (reg_hash
, "number");
3103 val
= gdbmi_value_literal_get (literal
);
3104 num
= strtoul (val
, NULL
, 10);
3106 literal
= gdbmi_value_hash_lookup (reg_hash
, "value");
3110 reg
= g_new0 (IAnjutaDebuggerRegister
, 1);
3111 *list
= g_list_prepend (prev
, reg
);
3113 reg
->value
= (gchar
*)gdbmi_value_literal_get (literal
);
3117 debugger_register_name_finish (Debugger
*debugger
, const GDBMIValue
*mi_results
, const GList
*cli_results
, GError
*error
)
3122 const GDBMIValue
*reg_list
;
3123 IAnjutaDebuggerCallback callback
= debugger
->priv
->current_cmd
.callback
;
3124 gpointer user_data
= debugger
->priv
->current_cmd
.user_data
;
3129 reg_list
= gdbmi_value_hash_lookup (mi_results
, "register-names");
3131 gdbmi_value_foreach (reg_list
, (GFunc
)add_register_name
, &list
);
3132 list
= g_list_reverse (list
);
3134 // Call call back function
3135 if (callback
!= NULL
)
3136 callback (list
, user_data
, NULL
);
3139 for (node
= g_list_first (list
); node
!= NULL
; node
= g_list_next (node
))
3141 g_free (node
->data
);
3147 debugger_register_value_finish (Debugger
*debugger
, const GDBMIValue
*mi_results
, const GList
*cli_results
, GError
*error
)
3152 const GDBMIValue
*reg_list
;
3153 IAnjutaDebuggerCallback callback
= debugger
->priv
->current_cmd
.callback
;
3154 gpointer user_data
= debugger
->priv
->current_cmd
.user_data
;
3159 reg_list
= gdbmi_value_hash_lookup (mi_results
, "register-values");
3161 gdbmi_value_foreach (reg_list
, (GFunc
)add_register_value
, &list
);
3162 list
= g_list_reverse (list
);
3164 // Call call back function
3165 if (callback
!= NULL
)
3166 callback (list
, user_data
, NULL
);
3169 for (node
= g_list_first (list
); node
!= NULL
; node
= g_list_next (node
))
3171 g_free (node
->data
);
3177 debugger_list_register (Debugger
*debugger
, IAnjutaDebuggerCallback callback
, gpointer user_data
)
3179 DEBUG_PRINT ("In function: debugger_list_register()");
3181 g_return_if_fail (IS_DEBUGGER (debugger
));
3183 debugger_queue_command (debugger
, "-data-list-register-names", TRUE
, FALSE
, debugger_register_name_finish
, callback
, user_data
);
3187 debugger_update_register (Debugger
*debugger
, IAnjutaDebuggerCallback callback
, gpointer user_data
)
3189 DEBUG_PRINT ("In function: debugger_update_register()");
3191 g_return_if_fail (IS_DEBUGGER (debugger
));
3193 debugger_queue_command (debugger
, "-data-list-register-values r", TRUE
, FALSE
, (DebuggerParserFunc
)debugger_register_value_finish
, callback
, user_data
);
3197 debugger_write_register (Debugger
*debugger
, const gchar
*name
, const gchar
*value
)
3201 DEBUG_PRINT ("In function: debugger_write_register()");
3203 g_return_if_fail (IS_DEBUGGER (debugger
));
3205 buf
= g_strdup_printf ("-data-evaluate-expression \"$%s=%s\"", name
, value
);
3206 debugger_queue_command (debugger
, buf
, TRUE
, FALSE
, NULL
, NULL
, NULL
);
3211 debugger_set_frame_finish (Debugger
*debugger
, const GDBMIValue
*mi_results
, const GList
*cli_results
, GError
*error
)
3214 guint frame
= (guint
)debugger
->priv
->current_cmd
.user_data
;
3216 g_signal_emit_by_name (debugger
->priv
->instance
, "frame-changed", frame
);
3220 debugger_set_frame (Debugger
*debugger
, guint frame
)
3224 DEBUG_PRINT ("In function: debugger_set_frame()");
3226 g_return_if_fail (IS_DEBUGGER (debugger
));
3228 buff
= g_strdup_printf ("-stack-select-frame %d", frame
);
3230 debugger_queue_command (debugger
, buff
, FALSE
, FALSE
, (DebuggerParserFunc
)debugger_set_frame_finish
, NULL
, (gpointer
)frame
);
3235 debugger_set_log (Debugger
*debugger
, IAnjutaMessageView
*log
)
3237 debugger
->priv
->log
= log
;
3240 /* Variable objects functions
3241 *---------------------------------------------------------------------------*/
3244 debugger_delete_variable (Debugger
*debugger
, const gchar
* name
)
3248 DEBUG_PRINT ("In function: delete_variable()");
3250 g_return_if_fail (IS_DEBUGGER (debugger
));
3252 buff
= g_strdup_printf ("-var-delete %s", name
);
3253 debugger_queue_command (debugger
, buff
, FALSE
, FALSE
, NULL
, NULL
, NULL
);
3258 gdb_var_evaluate_expression (Debugger
*debugger
,
3259 const GDBMIValue
*mi_results
, const GList
*cli_results
,
3262 const gchar
*value
= NULL
;
3263 IAnjutaDebuggerCallback callback
= debugger
->priv
->current_cmd
.callback
;
3264 gpointer user_data
= debugger
->priv
->current_cmd
.user_data
;
3266 if (mi_results
!= NULL
)
3268 const GDBMIValue
*const gdbmi_value
=
3269 gdbmi_value_hash_lookup (mi_results
, "value");
3271 if (gdbmi_value
!= NULL
)
3272 value
= gdbmi_value_literal_get (gdbmi_value
);
3274 callback ((const gpointer
)value
, user_data
, NULL
);
3278 debugger_evaluate_variable (Debugger
*debugger
, const gchar
* name
, IAnjutaDebuggerCallback callback
, gpointer user_data
)
3282 DEBUG_PRINT ("In function: evaluate_variable()");
3284 g_return_if_fail (IS_DEBUGGER (debugger
));
3286 buff
= g_strdup_printf ("-var-evaluate-expression %s", name
);
3287 debugger_queue_command (debugger
, buff
, FALSE
, FALSE
, gdb_var_evaluate_expression
, callback
, user_data
);
3292 debugger_assign_variable (Debugger
*debugger
, const gchar
* name
, const gchar
*value
)
3296 DEBUG_PRINT ("In function: assign_variable()");
3298 g_return_if_fail (IS_DEBUGGER (debugger
));
3300 buff
= g_strdup_printf ("-var-assign %s %s", name
, value
);
3301 debugger_queue_command (debugger
, buff
, FALSE
, FALSE
, NULL
, NULL
, NULL
);
3306 gdb_var_list_children (Debugger
*debugger
,
3307 const GDBMIValue
*mi_results
, const GList
*cli_results
,
3311 IAnjutaDebuggerCallback callback
= debugger
->priv
->current_cmd
.callback
;
3312 gpointer user_data
= debugger
->priv
->current_cmd
.user_data
;
3314 if (mi_results
!= NULL
)
3316 const GDBMIValue
*literal
;
3317 const GDBMIValue
*children
;
3321 literal
= gdbmi_value_hash_lookup (mi_results
, "numchild");
3324 numchild
= strtoul(gdbmi_value_literal_get (literal
), NULL
, 0);
3325 children
= gdbmi_value_hash_lookup (mi_results
, "children");
3327 for(i
= 0 ; i
< numchild
; ++i
)
3329 const GDBMIValue
*const gdbmi_chl
=
3330 gdbmi_value_list_get_nth (children
, i
);
3331 IAnjutaDebuggerVariable
*var
;
3333 var
= g_new0 (IAnjutaDebuggerVariable
, 1);
3335 literal
= gdbmi_value_hash_lookup (gdbmi_chl
, "name");
3337 var
->name
= (gchar
*)gdbmi_value_literal_get (literal
);
3339 literal
= gdbmi_value_hash_lookup (gdbmi_chl
, "exp");
3341 var
->expression
= (gchar
*)gdbmi_value_literal_get(literal
);
3343 literal
= gdbmi_value_hash_lookup (gdbmi_chl
, "type");
3345 var
->type
= (gchar
*)gdbmi_value_literal_get(literal
);
3347 literal
= gdbmi_value_hash_lookup (gdbmi_chl
, "value");
3349 var
->value
= (gchar
*)gdbmi_value_literal_get(literal
);
3351 literal
= gdbmi_value_hash_lookup (gdbmi_chl
, "numchild");
3353 var
->children
= strtoul(gdbmi_value_literal_get(literal
), NULL
, 10);
3355 list
= g_list_prepend (list
, var
);
3357 list
= g_list_reverse (list
);
3360 callback (list
, user_data
, NULL
);
3361 g_list_foreach (list
, (GFunc
)g_free
, NULL
);
3365 void debugger_list_variable_children (Debugger
*debugger
, const gchar
* name
, IAnjutaDebuggerCallback callback
, gpointer user_data
)
3369 DEBUG_PRINT ("In function: list_variable_children()");
3371 g_return_if_fail (IS_DEBUGGER (debugger
));
3373 buff
= g_strdup_printf ("-var-list-children --all-values %s", name
);
3374 debugger_queue_command (debugger
, buff
, FALSE
, FALSE
, gdb_var_list_children
, callback
, user_data
);
3379 gdb_var_create (Debugger
*debugger
,
3380 const GDBMIValue
*mi_results
, const GList
*cli_results
,
3383 const GDBMIValue
* result
;
3384 IAnjutaDebuggerVariable var
= {0,};
3385 IAnjutaDebuggerCallback callback
= debugger
->priv
->current_cmd
.callback
;
3386 gpointer user_data
= debugger
->priv
->current_cmd
.user_data
;
3388 if ((error
== NULL
) && (mi_results
!= NULL
))
3390 result
= gdbmi_value_hash_lookup (mi_results
, "name");
3391 var
.name
= (gchar
*)gdbmi_value_literal_get(result
);
3393 result
= gdbmi_value_hash_lookup (mi_results
, "type");
3394 var
.type
= (gchar
*)gdbmi_value_literal_get (result
);
3396 result
= gdbmi_value_hash_lookup (mi_results
, "numchild");
3397 var
.children
= strtoul (gdbmi_value_literal_get(result
), NULL
, 10);
3399 callback (&var
, user_data
, error
);
3403 void debugger_create_variable (Debugger
*debugger
, const gchar
* name
, IAnjutaDebuggerCallback callback
, gpointer user_data
)
3407 DEBUG_PRINT ("In function: create_variable()");
3409 g_return_if_fail (IS_DEBUGGER (debugger
));
3411 buff
= g_strdup_printf ("-var-create - * %s", name
);
3412 debugger_queue_command (debugger
, buff
, FALSE
, FALSE
, gdb_var_create
, callback
, user_data
);
3417 gdb_var_update (Debugger
*debugger
,
3418 const GDBMIValue
*mi_results
, const GList
*cli_results
,
3422 glong idx
= 0, changed_count
= 0;
3423 const GDBMIValue
*const gdbmi_changelist
=
3424 gdbmi_value_hash_lookup (mi_results
, "changelist");
3425 IAnjutaDebuggerCallback callback
= debugger
->priv
->current_cmd
.callback
;
3426 gpointer user_data
= debugger
->priv
->current_cmd
.user_data
;
3429 changed_count
= gdbmi_value_get_size (gdbmi_changelist
);
3430 for(; idx
<changed_count
; ++idx
)
3432 const GDBMIValue
*const gdbmi_change
=
3433 gdbmi_value_list_get_nth (gdbmi_changelist
, idx
);
3434 const GDBMIValue
*gdbmi_val
=
3435 gdbmi_value_hash_lookup (gdbmi_change
, "in_scope");
3436 IAnjutaDebuggerVariable
*var
;
3438 if(0 != strcmp(gdbmi_value_literal_get(gdbmi_val
), "false"))
3440 gdbmi_val
= gdbmi_value_hash_lookup (gdbmi_change
, "name");
3441 var
= g_new0 (IAnjutaDebuggerVariable
, 1);
3442 var
->changed
= TRUE
;
3443 var
->name
= (gchar
*)gdbmi_value_literal_get(gdbmi_val
);
3445 list
= g_list_prepend (list
, var
);
3448 list
= g_list_reverse (list
);
3449 callback (list
, user_data
, NULL
);
3450 g_list_foreach (list
, (GFunc
)g_free
, NULL
);
3454 void debugger_update_variable (Debugger
*debugger
, IAnjutaDebuggerCallback callback
, gpointer user_data
)
3456 DEBUG_PRINT ("In function: update_variable()");
3458 g_return_if_fail (IS_DEBUGGER (debugger
));
3460 debugger_queue_command (debugger
, "-var-update *", FALSE
, FALSE
, gdb_var_update
, callback
, user_data
);
3464 debugger_get_type (void)
3466 static GType obj_type
= 0;
3470 static const GTypeInfo obj_info
=
3472 sizeof (DebuggerClass
),
3473 (GBaseInitFunc
) NULL
,
3474 (GBaseFinalizeFunc
) NULL
,
3475 (GClassInitFunc
) debugger_class_init
,
3476 (GClassFinalizeFunc
) NULL
,
3477 NULL
, /* class_data */
3479 0, /* n_preallocs */
3480 (GInstanceInitFunc
) debugger_instance_init
,
3481 NULL
/* value_table */
3483 obj_type
= g_type_register_static (G_TYPE_OBJECT
,
3484 "Debugger", &obj_info
, 0);
3490 debugger_dispose (GObject
*obj
)
3492 Debugger
*debugger
= DEBUGGER (obj
);
3494 DEBUG_PRINT ("In function: debugger_shutdown()");
3496 debugger_abort (debugger
);
3498 /* Good Bye message */
3499 if (debugger
->priv
->output_callback
)
3501 debugger
->priv
->output_callback (IANJUTA_DEBUGGER_OUTPUT
,
3502 "Debugging session completed.\n",
3503 debugger
->priv
->output_user_data
);
3506 if (debugger
->priv
->launcher
)
3508 anjuta_launcher_reset (debugger
->priv
->launcher
);
3509 g_object_unref (debugger
->priv
->launcher
);
3510 debugger
->priv
->launcher
= NULL
;
3513 GNOME_CALL_PARENT (G_OBJECT_CLASS
, dispose
, (obj
));
3517 debugger_finalize (GObject
*obj
)
3519 Debugger
*debugger
= DEBUGGER (obj
);
3520 g_string_free (debugger
->priv
->stdo_line
, TRUE
);
3521 g_string_free (debugger
->priv
->stdo_acc
, TRUE
);
3522 g_string_free (debugger
->priv
->stde_line
, TRUE
);
3523 g_free (debugger
->priv
);
3524 GNOME_CALL_PARENT (G_OBJECT_CLASS
, finalize
, (obj
));
3528 debugger_class_init (DebuggerClass
* klass
)
3530 GObjectClass
*object_class
;
3532 g_return_if_fail (klass
!= NULL
);
3533 object_class
= G_OBJECT_CLASS (klass
);
3535 DEBUG_PRINT ("Initializing debugger class");
3537 parent_class
= g_type_class_peek_parent (klass
);
3538 object_class
->dispose
= debugger_dispose
;
3539 object_class
->finalize
= debugger_finalize
;
3545 debugger_signal (const gchar
*sig
, gboolean show_msg
)
3547 /* eg:- "SIGTERM" */
3551 DEBUG_PRINT ("In function: debugger_signal()");
3553 if (debugger_is_active () == FALSE
)
3555 if (debugger
.prog_is_running
== FALSE
)
3557 if (debugger
.child_pid
< 1)
3559 DEBUG_PRINT ("Not sending signal - pid not known\n");
3565 buff
= g_strdup_printf (_("Sending signal %s to the process: %d"),
3566 sig
, (int) debugger
.child_pid
);
3567 gdb_util_append_message (ANJUTA_PLUGIN (debugger
.plugin
), buff
);
3571 if (debugger_is_ready ())
3573 cmd
= g_strconcat ("signal ", sig
, NULL
);
3574 stack_trace_set_frame (debugger
.stack
, 0);
3575 debugger_put_cmd_in_queqe (cmd
, DB_CMD_ALL
, NULL
, NULL
);
3576 debugger_put_cmd_in_queqe ("info program", DB_CMD_NONE
,
3577 on_debugger_update_prog_status
,
3580 debugger_execute_cmd_in_queqe ();
3587 parent
= GTK_WINDOW (ANJUTA_PLUGIN (debugger
.plugin
)->shell
);
3588 status
= gdb_util_kill_process (debugger
.child_pid
, sig
);
3589 if (status
!= 0 && show_msg
)
3590 anjuta_util_dialog_error (parent
,
3591 _("Error whilst signaling the process."));
3596 query_set_cmd (const gchar
*cmd
, gboolean state
)
3599 gchar
*tmp
= g_stpcpy (buffer
, cmd
);
3600 strcpy (tmp
, state
? "on" : "off");
3601 debugger_put_cmd_in_queqe (buffer
, DB_CMD_NONE
, NULL
, NULL
);
3605 query_set_verbose (gboolean state
)
3607 query_set_cmd ("set verbose ", state
);
3611 query_set_print_staticmembers (gboolean state
)
3613 query_set_cmd ("set print static-members ", state
);
3617 query_set_print_pretty (gboolean state
)
3619 query_set_cmd ("set print pretty ", state
);
3622 void debugger_query_evaluate_expr_tip (const gchar
*expr
,
3623 DebuggerCLIFunc parser
, gpointer data
)
3625 query_set_verbose (FALSE
);
3626 query_set_print_staticmembers (FALSE
);
3627 gchar
*printcmd
= g_strconcat ("print ", expr
, NULL
);
3628 debugger_put_cmd_in_queqe (printcmd
, DB_CMD_NONE
, parser
, data
);
3629 query_set_verbose (TRUE
);
3630 query_set_print_staticmembers (TRUE
);
3635 debugger_query_evaluate_expression (const gchar
*expr
, DebuggerFunc parser
,
3638 query_set_print_pretty (TRUE
);
3639 query_set_verbose (FALSE
);
3640 gchar
*printcmd
= g_strconcat ("print ", expr
, NULL
);
3641 debugger_put_cmd_in_queqe (printcmd
, DB_CMD_SE_MESG
| DB_CMD_SE_DIALOG
,
3643 query_set_print_pretty (FALSE
);
3644 query_set_verbose (TRUE
);