1 /* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*- */
3 * debugger.c Copyright (C) 2000 Kh. Naba Kumar Singh
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License as published by the Free
7 * Software Foundation; either version 2 of the License, or (at your option)
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
12 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc., 59
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
26 #include <sys/types.h>
39 #include <libanjuta/anjuta-launcher.h>
40 #include <libanjuta/anjuta-debug.h>
41 #include <libanjuta/anjuta-marshal.h>
42 #include <libanjuta/interfaces/ianjuta-debugger-breakpoint.h>
43 #include <libanjuta/interfaces/ianjuta-debugger-register.h>
44 #include <libanjuta/interfaces/ianjuta-debugger-memory.h>
45 #include <libanjuta/interfaces/ianjuta-debugger-instruction.h>
46 #include <libanjuta/interfaces/ianjuta-debugger-variable.h>
49 #include "utilities.h"
51 #define ANJUTA_LOG_ENV "ANJUTA_LOG"
52 #define DEBUGGER_LOG_LEVEL 1
54 #define GDB_PROMPT "(gdb)"
55 #define FILE_BUFFER_SIZE 1024
56 #define GDB_PATH "gdb"
57 #define SUMMARY_MAX_LENGTH 90 /* Should be smaller than 4K to be displayed
58 * in GtkCellRendererCell */
63 DEBUGGER_RERUN_PROGRAM
68 PROGRAM_LOADED_SIGNAL
,
69 PROGRAM_RUNNING_SIGNAL
,
70 PROGRAM_EXITED_SIGNAL
,
71 PROGRAM_STOPPED_SIGNAL
,
72 RESULTS_ARRIVED_SIGNAL
,
73 LOCATION_CHANGED_SIGNAL
,
74 BREAKPOINT_CHANGED_SIGNAL
,
75 VARIABLE_CHANGED_SIGNAL
,
81 GtkWindow
*parent_win
;
83 IAnjutaDebuggerOutputCallback output_callback
;
84 gpointer output_user_data
;
88 gboolean prog_is_running
;
89 gboolean prog_is_attached
;
90 gboolean prog_is_loaded
;
91 gboolean debugger_is_started
;
92 guint debugger_is_busy
;
93 gint post_execution_flag
;
95 AnjutaLauncher
*launcher
;
103 gboolean solib_event
;
107 gboolean terminating
;
110 /* GDB command queue */
112 DebuggerCommand current_cmd
;
113 gboolean skip_next_prompt
;
114 gboolean command_output_sent
;
122 IAnjutaMessageView
*log
;
126 static gpointer parent_class
;
128 static void debugger_queue_clear (Debugger
*debugger
);
129 static void debugger_queue_execute_command (Debugger
*debugger
);
131 static void gdb_stdout_line_arrived (Debugger
*debugger
, const gchar
* line
);
132 static void gdb_stderr_line_arrived (Debugger
*debugger
, const gchar
* line
);
133 static void debugger_stdo_flush (Debugger
*debugger
);
134 static void debugger_stde_flush (Debugger
*debugger
);
135 static void on_gdb_output_arrived (AnjutaLauncher
*launcher
,
136 AnjutaLauncherOutputType output_type
,
137 const gchar
*chars
, gpointer data
);
138 static void on_gdb_terminated (AnjutaLauncher
*launcher
,
139 gint child_pid
, gint status
,
140 gulong t
, gpointer data
);
142 static void debugger_class_init (DebuggerClass
*klass
);
143 static void debugger_instance_init (Debugger
*debugger
);
145 typedef struct _GdbGListPacket
152 *---------------------------------------------------------------------------*/
154 typedef struct _GdbMessageCode GdbMessageCode
;
156 struct _GdbMessageCode
162 const static GdbMessageCode GdbErrorMessage
[] =
163 {{"mi_cmd_var_create: unable to create variable object",
164 IANJUTA_DEBUGGER_UNABLE_TO_CREATE_VARIABLE
},
165 {"Cannot access memory at address ",
166 IANJUTA_DEBUGGER_UNABLE_TO_ACCESS_MEMORY
},
167 {"No source file named ",
168 IANJUTA_DEBUGGER_UNABLE_TO_OPEN_FILE
},
172 gdb_match_error(const gchar
*message
)
174 const GdbMessageCode
* msg
;
176 for (msg
= GdbErrorMessage
; msg
->msg
!= NULL
; msg
++)
178 gsize len
= strlen (msg
->msg
);
180 if (!isspace (msg
->msg
[len
- 1]))
182 /* Match the whole string */
186 if (memcmp (msg
->msg
, message
, len
) == 0)
192 return IANJUTA_DEBUGGER_UNKNOWN_ERROR
;
196 debugger_message_view_append (Debugger
*debugger
, IAnjutaMessageViewType type
, const char *message
)
198 guint len
= strlen(message
);
199 gchar buf
[SUMMARY_MAX_LENGTH
];
200 const gchar
* summary
= message
;
201 const gchar
* detail
= "";
204 if (len
> SUMMARY_MAX_LENGTH
)
207 memcpy(buf
, message
, SUMMARY_MAX_LENGTH
- 4);
208 memcpy(buf
+ SUMMARY_MAX_LENGTH
- 4, "...", 4);
213 ianjuta_message_view_append (debugger
->priv
->log
, type
, summary
, detail
, NULL
);
217 debugger_initialize (Debugger
*debugger
)
219 const gchar
* anjuta_log
;
221 DEBUG_PRINT ("In function: debugger_init()");
223 debugger
->priv
= g_new0 (DebuggerPriv
, 1);
225 debugger
->priv
->output_callback
= NULL
;
226 debugger
->priv
->parent_win
= NULL
;
227 debugger
->priv
->search_dirs
= NULL
;
228 debugger
->priv
->launcher
= anjuta_launcher_new ();
230 debugger
->priv
->debugger_is_started
= FALSE
;
231 debugger
->priv
->prog_is_running
= FALSE
;
232 debugger
->priv
->debugger_is_busy
= 0;
233 debugger
->priv
->starting
= FALSE
;
234 debugger
->priv
->terminating
= FALSE
;
235 debugger
->priv
->skip_next_prompt
= FALSE
;
236 debugger
->priv
->command_output_sent
= FALSE
;
238 debugger
->priv
->current_cmd
.cmd
= NULL
;
239 debugger
->priv
->current_cmd
.parser
= NULL
;
241 debugger
->priv
->cmd_queqe
= NULL
;
242 debugger
->priv
->cli_lines
= NULL
;
243 debugger
->priv
->solib_event
= FALSE
;
245 debugger
->priv
->stdo_line
= g_string_sized_new (FILE_BUFFER_SIZE
);
246 g_string_assign (debugger
->priv
->stdo_line
, "");
247 debugger
->priv
->stdo_acc
= g_string_new ("");
249 debugger
->priv
->stde_line
= g_string_sized_new (FILE_BUFFER_SIZE
);
250 g_string_assign (debugger
->priv
->stde_line
, "");
252 debugger
->priv
->post_execution_flag
= DEBUGGER_NONE
;
254 anjuta_log
= g_getenv (ANJUTA_LOG_ENV
);
255 debugger
->priv
->gdb_log
= anjuta_log
&& (atoi(anjuta_log
) > DEBUGGER_LOG_LEVEL
);
259 debugger_instance_init (Debugger
*debugger
)
261 debugger_initialize (debugger
);
265 debugger_new (GtkWindow
*parent_win
, GObject
* instance
)
269 debugger
= g_object_new (DEBUGGER_TYPE
, NULL
);
270 debugger
->priv
->parent_win
= parent_win
;
271 debugger
->priv
->instance
= instance
;
277 debugger_free (Debugger
*debugger
)
279 g_return_if_fail (IS_DEBUGGER (debugger
));
281 g_object_unref (debugger
);
285 debugger_is_ready (Debugger
*debugger
)
287 g_return_val_if_fail (IS_DEBUGGER (debugger
), FALSE
);
288 return !debugger
->priv
->debugger_is_busy
;
292 debugger_program_is_running (Debugger
*debugger
)
294 g_return_val_if_fail (IS_DEBUGGER (debugger
), FALSE
);
295 return debugger
->priv
->prog_is_running
;
299 debugger_program_is_attached (Debugger
*debugger
)
301 g_return_val_if_fail (IS_DEBUGGER (debugger
), FALSE
);
302 return debugger
->priv
->prog_is_attached
;
306 debugger_program_is_loaded (Debugger
*debugger
)
308 g_return_val_if_fail (IS_DEBUGGER (debugger
), FALSE
);
309 return debugger
->priv
->prog_is_loaded
;
313 debugger_log_command (Debugger
*debugger
, const gchar
*command
)
318 if (debugger
->priv
->log
== NULL
) return;
322 str
= g_strdup (command
);
323 len
= strlen (command
);
325 /* Remove trailing carriage return */
326 if (str
[len
- 1] == '\n') str
[len
- 1] = '\0';
328 /* Log only MI command as other are echo */
330 DEBUG_PRINT ("GDB:> %s", str
);
332 if (debugger
->priv
->gdb_log
) g_message ("GDB:> %s", str
);
334 debugger_message_view_append (debugger
, IANJUTA_MESSAGE_VIEW_TYPE_NORMAL
, str
);
340 debugger_log_output (Debugger
*debugger
, const gchar
*line
)
344 IAnjutaMessageViewType type
;
347 if (debugger
->priv
->log
== NULL
) return;
349 type
= IANJUTA_MESSAGE_VIEW_TYPE_NORMAL
;
353 type
= IANJUTA_MESSAGE_VIEW_TYPE_INFO
;
359 /* Remove double quote if necessary */
360 if ((line
[1] == '\"') && (line
[len
- 1] == '\"')) start
++;
361 str
= g_strcompress (line
+ 2);
363 if (start
== line
+ 2)
369 /* Remove trailing carriage return */
370 if (str
[len
- 1] == '\n') str
[len
- 1] = '\0';
372 debugger_message_view_append (debugger
, type
, str
);
376 if (strncmp(line
+ 1, "error", 5) == 0)
378 debugger_message_view_append (debugger
, IANJUTA_MESSAGE_VIEW_TYPE_ERROR
, line
+ 1);
382 debugger_message_view_append (debugger
, IANJUTA_MESSAGE_VIEW_TYPE_WARNING
, line
+ 1);
386 debugger_message_view_append (debugger
, IANJUTA_MESSAGE_VIEW_TYPE_NORMAL
, line
+ 1);
389 debugger_message_view_append (debugger
, IANJUTA_MESSAGE_VIEW_TYPE_NORMAL
, line
);
395 debugger_emit_ready (Debugger
*debugger
)
397 if (!debugger
->priv
->debugger_is_busy
)
399 if (debugger
->priv
->loading
)
401 debugger
->priv
->starting
= FALSE
;
402 debugger
->priv
->loading
= FALSE
;
403 debugger
->priv
->exiting
= FALSE
;
404 debugger
->priv
->stopping
= FALSE
;
405 debugger
->priv
->solib_event
= FALSE
;
406 g_signal_emit_by_name (debugger
->priv
->instance
, "debugger-ready", IANJUTA_DEBUGGER_PROGRAM_LOADED
);
408 else if (debugger
->priv
->starting
)
410 debugger
->priv
->starting
= FALSE
;
411 debugger
->priv
->loading
= FALSE
;
412 debugger
->priv
->exiting
= FALSE
;
413 debugger
->priv
->stopping
= FALSE
;
414 debugger
->priv
->solib_event
= FALSE
;
415 g_signal_emit_by_name (debugger
->priv
->instance
, "debugger-ready", IANJUTA_DEBUGGER_STARTED
);
417 else if (debugger
->priv
->exiting
)
419 debugger
->priv
->exiting
= FALSE
;
420 debugger
->priv
->stopping
= FALSE
;
421 debugger
->priv
->solib_event
= FALSE
;
422 g_signal_emit_by_name (debugger
->priv
->instance
, "debugger-ready", IANJUTA_DEBUGGER_PROGRAM_LOADED
);
424 else if (debugger
->priv
->solib_event
)
426 debugger
->priv
->exiting
= FALSE
;
427 debugger
->priv
->stopping
= FALSE
;
428 debugger
->priv
->solib_event
= FALSE
;
429 g_signal_emit_by_name (debugger
->priv
->instance
, "sharedlib-event");
431 else if (debugger
->priv
->stopping
)
433 debugger
->priv
->exiting
= FALSE
;
434 debugger
->priv
->stopping
= FALSE
;
435 debugger
->priv
->solib_event
= FALSE
;
436 g_signal_emit_by_name (debugger
->priv
->instance
, "debugger-ready", IANJUTA_DEBUGGER_PROGRAM_STOPPED
);
440 if (debugger
->priv
->prog_is_running
|| debugger
->priv
->prog_is_attached
)
442 g_signal_emit_by_name (debugger
->priv
->instance
, "debugger-ready", IANJUTA_DEBUGGER_PROGRAM_STOPPED
);
444 else if (debugger
->priv
->prog_is_loaded
)
446 g_signal_emit_by_name (debugger
->priv
->instance
, "debugger-ready", IANJUTA_DEBUGGER_PROGRAM_LOADED
);
450 g_signal_emit_by_name (debugger
->priv
->instance
, "debugger-ready", IANJUTA_DEBUGGER_STARTED
);
457 debugger_get_state (Debugger
*debugger
)
459 if (debugger
->priv
->debugger_is_busy
)
461 return IANJUTA_DEBUGGER_BUSY
;
465 if (debugger
->priv
->prog_is_running
|| debugger
->priv
->prog_is_attached
)
467 return IANJUTA_DEBUGGER_PROGRAM_STOPPED
;
469 else if (debugger
->priv
->prog_is_loaded
)
471 return IANJUTA_DEBUGGER_PROGRAM_LOADED
;
473 else if (debugger
->priv
->debugger_is_started
)
475 return IANJUTA_DEBUGGER_STARTED
;
479 return IANJUTA_DEBUGGER_STOPPED
;
485 debugger_clear_buffers (Debugger
*debugger
)
487 DEBUG_PRINT ("In function: debugger_clear_buffers()");
489 /* Clear the output line buffer */
490 g_string_assign (debugger
->priv
->stdo_line
, "");
491 if (!debugger
->priv
->current_cmd
.keep_result
)
492 g_string_assign (debugger
->priv
->stdo_acc
, "");
494 /* Clear the error line buffer */
495 g_string_assign (debugger
->priv
->stde_line
, "");
497 /* Clear CLI output lines */
498 g_list_foreach (debugger
->priv
->cli_lines
, (GFunc
)g_free
, NULL
);
499 g_list_free (debugger
->priv
->cli_lines
);
500 debugger
->priv
->cli_lines
= NULL
;
503 static DebuggerCommand
*
504 debugger_queue_get_next_command (Debugger
*debugger
)
508 DEBUG_PRINT ("In function: debugger_get_next_command()");
510 if (debugger
->priv
->cmd_queqe
)
512 dc
= g_list_nth_data (debugger
->priv
->cmd_queqe
, 0);
513 debugger
->priv
->cmd_queqe
= g_list_remove (debugger
->priv
->cmd_queqe
, dc
);
521 debugger_queue_set_next_command (Debugger
*debugger
)
525 DEBUG_PRINT ("In function: debugger_set_next_command()");
527 dc
= debugger_queue_get_next_command (debugger
);
530 debugger
->priv
->current_cmd
.cmd
= NULL
;
531 debugger
->priv
->current_cmd
.parser
= NULL
;
532 debugger
->priv
->current_cmd
.callback
= NULL
;
533 debugger
->priv
->current_cmd
.user_data
= NULL
;
534 debugger
->priv
->current_cmd
.suppress_error
= FALSE
;
535 debugger
->priv
->current_cmd
.keep_result
= FALSE
;
539 g_free (debugger
->priv
->current_cmd
.cmd
);
540 debugger
->priv
->current_cmd
.cmd
= dc
->cmd
;
541 debugger
->priv
->current_cmd
.parser
= dc
->parser
;
542 debugger
->priv
->current_cmd
.callback
= dc
->callback
;
543 debugger
->priv
->current_cmd
.user_data
= dc
->user_data
;
544 debugger
->priv
->current_cmd
.suppress_error
= dc
->suppress_error
;
545 debugger
->priv
->current_cmd
.keep_result
= dc
->keep_result
;
552 debugger_queue_command (Debugger
*debugger
, const gchar
*cmd
,
553 gboolean suppress_error
, gboolean keep_result
,
554 DebuggerParserFunc parser
,
555 IAnjutaDebuggerCallback callback
, gpointer user_data
)
560 DEBUG_PRINT ("In function: debugger_queue_command (%s)", cmd
);
562 dc
= g_malloc (sizeof (DebuggerCommand
));
565 dc
->cmd
= g_strdup(cmd
);
567 dc
->callback
= callback
;
568 dc
->user_data
= user_data
;
569 dc
->suppress_error
= suppress_error
;
570 dc
->keep_result
= keep_result
;
572 debugger
->priv
->cmd_queqe
= g_list_append (debugger
->priv
->cmd_queqe
, dc
);
573 debugger_queue_execute_command (debugger
);
577 debugger_queue_clear (Debugger
*debugger
)
581 DEBUG_PRINT ("In function: debugger_queue_clear()");
583 node
= debugger
->priv
->cmd_queqe
;
586 g_free (((DebuggerCommand
*)node
->data
)->cmd
);
588 node
= g_list_next (node
);
590 g_list_free (debugger
->priv
->cmd_queqe
);
591 debugger
->priv
->cmd_queqe
= NULL
;
592 g_free (debugger
->priv
->current_cmd
.cmd
);
593 debugger
->priv
->current_cmd
.cmd
= NULL
;
594 debugger
->priv
->current_cmd
.parser
= NULL
;
595 debugger
->priv
->current_cmd
.callback
= NULL
;
596 debugger
->priv
->current_cmd
.user_data
= NULL
;
597 debugger
->priv
->current_cmd
.suppress_error
= FALSE
;
598 debugger
->priv
->current_cmd
.keep_result
= FALSE
;
599 debugger_clear_buffers (debugger
);
603 debugger_execute_command (Debugger
*debugger
, const gchar
*command
)
607 DEBUG_PRINT ("In function: debugger_execute_command(%s) %d\n",command
, debugger
->priv
->debugger_is_busy
);
608 debugger
->priv
->debugger_is_busy
++;
609 debugger
->priv
->command_output_sent
= FALSE
;
610 cmd
= g_strconcat (command
, "\n", NULL
);
611 debugger_log_command (debugger
, cmd
);
612 anjuta_launcher_send_stdin (debugger
->priv
->launcher
, cmd
);
617 debugger_queue_execute_command (Debugger
*debugger
)
619 DEBUG_PRINT ("In function: debugger_queue_execute_command()");
621 if (!debugger
->priv
->debugger_is_busy
&&
622 !debugger
->priv
->starting
&&
623 g_list_length (debugger
->priv
->cmd_queqe
) >= 1)
625 debugger_clear_buffers (debugger
);
626 if (debugger_queue_set_next_command (debugger
))
627 debugger_execute_command (debugger
, debugger
->priv
->current_cmd
.cmd
);
632 debugger_load_executable_finish (Debugger
*debugger
, const GDBMIValue
*mi_results
,
633 const GList
*cli_results
, GError
*error
)
635 DEBUG_PRINT ("Program loaded");
636 debugger
->priv
->prog_is_loaded
= TRUE
;
638 g_signal_emit_by_name (debugger
->priv
->instance
, "program-loaded");
642 debugger_load_executable (Debugger
*debugger
, const gchar
*prog
)
644 gchar
*command
, *dir
, *msg
;
646 g_return_if_fail (IS_DEBUGGER (debugger
));
647 g_return_if_fail (prog
!= NULL
);
649 DEBUG_PRINT ("In function: debugger_load_executable(%s)", prog
);
651 if (debugger
->priv
->output_callback
)
653 msg
= g_strconcat (_("Loading Executable: "), prog
, "\n", NULL
);
654 debugger
->priv
->output_callback (IANJUTA_DEBUGGER_OUTPUT
, msg
,
655 debugger
->priv
->output_user_data
);
659 command
= g_strconcat ("-file-exec-and-symbols ", prog
, NULL
);
660 dir
= g_path_get_dirname (prog
);
662 anjuta_set_execution_dir(dir);
665 debugger_queue_command (debugger
, command
, FALSE
, FALSE
, debugger_load_executable_finish
, NULL
, NULL
);
667 debugger
->priv
->starting
= TRUE
;
668 debugger
->priv
->terminating
= FALSE
;
672 debugger_load_core (Debugger
*debugger
, const gchar
*core
)
674 gchar
*command
, *dir
, *msg
;
676 g_return_if_fail (IS_DEBUGGER (debugger
));
677 g_return_if_fail (core
!= NULL
);
679 DEBUG_PRINT ("In function: debugger_load_core(%s)", core
);
681 if (debugger
->priv
->output_callback
)
683 msg
= g_strconcat (_("Loading Core: "), core
, "\n", NULL
);
684 debugger
->priv
->output_callback (IANJUTA_DEBUGGER_OUTPUT
, msg
,
685 debugger
->priv
->output_user_data
);
689 command
= g_strconcat ("core ", core
, NULL
);
690 dir
= g_path_get_dirname (core
);
691 debugger
->priv
->search_dirs
=
692 g_list_prepend (debugger
->priv
->search_dirs
, dir
);
693 debugger_queue_command (debugger
, command
, FALSE
, FALSE
, NULL
, NULL
, NULL
);
698 debugger_start (Debugger
*debugger
, const GList
*search_dirs
,
699 const gchar
*prog
, gboolean is_libtool_prog
)
701 gchar
*command_str
, *dir
, *tmp
, *text
, *msg
;
705 AnjutaLauncher
*launcher
;
706 GList
*dir_list
= NULL
;
709 DEBUG_PRINT ("In function: debugger_start(%s) libtool %d", prog
== NULL
? "(null)" : prog
, is_libtool_prog
);
711 if (anjuta_util_prog_is_installed ("gdb", TRUE
) == FALSE
)
714 debugger_queue_clear (debugger
);
716 tmp
= g_strconcat (PACKAGE_DATA_DIR
, "/", "gdb.init", NULL
);
717 if (g_file_test (tmp
, G_FILE_TEST_IS_REGULAR
) == FALSE
)
719 anjuta_util_dialog_error (debugger
->priv
->parent_win
,
720 _("Unable to find: %s.\n"
721 "Unable to initialize debugger.\n"
722 "Make sure Anjuta is installed correctly."),
729 /* Prepare source search directories */
732 exec_dir
= g_path_get_dirname (prog
);
736 dir
= g_strconcat (" -directory=", exec_dir
, NULL
);
737 dir_list
= g_list_prepend (dir_list
, exec_dir
);
741 dir
= g_strdup (" ");
748 if (strncmp (text
, "file://", 7) == 0)
754 g_warning ("Debugger source search uri '%s' is not a local uri", text
);
759 tmp
= g_strconcat (dir
, " -directory=", text
, NULL
);
763 dir_list
= g_list_prepend (dir_list
, g_strdup (text
));
767 g_warning ("Debugger source search dir '%s' is not absolute",
770 node
= g_list_next (node
);
773 /* Now save the dir list. Order is automatically revesed */
777 debugger
->priv
->search_dirs
=
778 g_list_prepend (debugger
->priv
->search_dirs
, node
->data
);
779 node
= g_list_next (node
);
781 g_list_free (dir_list
);
783 if (prog
&& strlen(prog
) > 0)
787 if (is_libtool_prog
== FALSE
)
789 command_str
= g_strdup_printf (GDB_PATH
" -f -n -i=mi2 %s %s "
790 "-x %s/gdb.init %s", dir
, term
== NULL
? "" : term
,
791 PACKAGE_DATA_DIR
, prog
);
795 command_str
= g_strdup_printf ("libtool --mode=execute " GDB_PATH
796 " -f -n -i=mi2 %s %s "
797 "-x %s/gdb.init %s", dir
, term
== NULL
? "" : term
,
798 PACKAGE_DATA_DIR
, prog
);
803 if (is_libtool_prog
== FALSE
)
805 command_str
= g_strdup_printf (GDB_PATH
" -f -n -i=mi2 %s %s "
806 "-x %s/gdb.init ", term
== NULL
? "" : term
,
807 dir
, PACKAGE_DATA_DIR
);
811 command_str
= g_strdup_printf ("libtool --mode=execute " GDB_PATH
812 " -f -n -i=mi2 %s %s -x "
814 dir
, term
== NULL
? "" : term
, PACKAGE_DATA_DIR
);
819 debugger
->priv
->starting
= TRUE
;
820 debugger
->priv
->terminating
= FALSE
;
821 debugger
->priv
->loading
= prog
!= NULL
? TRUE
: FALSE
;
822 debugger
->priv
->debugger_is_busy
= 1;
824 /* Prepare for launch. */
825 launcher
= debugger
->priv
->launcher
;
826 anjuta_launcher_set_terminate_on_exit (launcher
, TRUE
);
827 g_signal_connect (G_OBJECT (launcher
), "child-exited",
828 G_CALLBACK (on_gdb_terminated
), debugger
);
829 ret
= anjuta_launcher_execute (launcher
, command_str
,
830 on_gdb_output_arrived
, debugger
);
834 debugger
->priv
->debugger_is_started
= TRUE
;
835 debugger
->priv
->prog_is_loaded
= prog
!= NULL
;
837 anjuta_launcher_set_encoding (launcher
, "ISO-8859-1");
839 if (debugger
->priv
->output_callback
!= NULL
)
843 /* TODO anjuta_update_app_status (TRUE, _("Debugger")); */
844 debugger
->priv
->output_callback (IANJUTA_DEBUGGER_OUTPUT
,
845 _("Getting ready to start debugging "
847 debugger
->priv
->output_user_data
);
851 msg
= g_strconcat (_("Loading Executable: "), prog
, "\n", NULL
);
852 debugger
->priv
->output_callback (IANJUTA_DEBUGGER_OUTPUT
,
854 debugger
->priv
->output_user_data
);
859 debugger
->priv
->output_callback (IANJUTA_DEBUGGER_OUTPUT
,
860 _("No executable specified.\n"),
861 debugger
->priv
->output_user_data
);
862 debugger
->priv
->output_callback (IANJUTA_DEBUGGER_OUTPUT
,
863 _("Open an executable or attach "
864 "to a process to start "
866 debugger
->priv
->output_user_data
);
871 debugger
->priv
->output_callback (IANJUTA_DEBUGGER_OUTPUT
,
872 _("There was an error whilst "
873 "launching the debugger.\n"),
874 debugger
->priv
->output_user_data
);
875 debugger
->priv
->output_callback (IANJUTA_DEBUGGER_OUTPUT
,
876 _("Make sure 'gdb' is installed "
878 debugger
->priv
->output_user_data
);
881 g_free (command_str
);
887 gdb_stdout_line_arrived (Debugger
*debugger
, const gchar
* chars
)
893 if (chars
[i
] == '\n')
895 debugger_stdo_flush (debugger
);
899 g_string_append_c (debugger
->priv
->stdo_line
, chars
[i
]);
906 gdb_stderr_line_arrived (Debugger
*debugger
, const gchar
* chars
)
910 for (i
= 0; i
< strlen (chars
); i
++)
912 if (chars
[i
] == '\n')
913 debugger_stde_flush (debugger
);
915 g_string_append_c (debugger
->priv
->stde_line
, chars
[i
]);
920 on_gdb_output_arrived (AnjutaLauncher
*launcher
,
921 AnjutaLauncherOutputType output_type
,
922 const gchar
*chars
, gpointer data
)
924 Debugger
*debugger
= DEBUGGER (data
);
925 DEBUG_PRINT ("on gdb output arrived");
927 /* Do not emit signal when the debugger is destroyed */
928 if (debugger
->priv
->instance
== NULL
) return;
932 case ANJUTA_LAUNCHER_OUTPUT_STDERR
:
933 gdb_stderr_line_arrived (debugger
, chars
);
935 case ANJUTA_LAUNCHER_OUTPUT_STDOUT
:
936 gdb_stdout_line_arrived (debugger
, chars
);
944 debugger_handle_post_execution (Debugger
*debugger
)
946 switch (debugger
->priv
->post_execution_flag
)
951 DEBUG_PRINT ("debugger stop in handle post execution\n");
952 debugger_stop (debugger
);
954 case DEBUGGER_RERUN_PROGRAM
:
955 DEBUG_PRINT ("debugger run in handle post execution\n");
956 debugger_run (debugger
);
959 g_warning ("Execution should not reach here");
964 debugger_process_frame (Debugger
*debugger
, const GDBMIValue
*val
)
966 const GDBMIValue
*file
, *line
, *frame
, *addr
, *fullname
, *thread
;
967 const gchar
*file_str
= NULL
;
971 g_return_if_fail (val
!= NULL
);
973 thread
= gdbmi_value_hash_lookup (val
, "thread-id");
976 debugger
->priv
->current_thread
= strtoul (gdbmi_value_literal_get (thread
), NULL
, 0);
978 debugger
->priv
->current_frame
= 0;
980 frame
= gdbmi_value_hash_lookup (val
, "frame");
983 fullname
= gdbmi_value_hash_lookup (frame
, "fullname");
986 file_str
= gdbmi_value_literal_get (fullname
);
987 if (*file_str
== '\0') file_str
= NULL
;
991 file
= gdbmi_value_hash_lookup (frame
, "file");
994 file_str
= gdbmi_value_literal_get (file
);
995 if (*file_str
== '\0') file_str
= NULL
;
999 if (file_str
!= NULL
)
1001 line
= gdbmi_value_hash_lookup (frame
, "line");
1004 line_num
= strtoul (gdbmi_value_literal_get (line
), NULL
, 0);
1008 addr
= gdbmi_value_hash_lookup (frame
, "addr");
1011 addr_num
= strtoul (gdbmi_value_literal_get (addr
), NULL
, 0);
1013 debugger_program_moved (debugger
, file_str
, line_num
, addr_num
);
1018 gdb_parse_error (Debugger
*debugger
, const GDBMIValue
*mi_results
)
1020 const GDBMIValue
*message
;
1021 const gchar
*literal
;
1022 guint code
= IANJUTA_DEBUGGER_UNKNOWN_ERROR
;
1024 message
= gdbmi_value_hash_lookup (mi_results
, "msg");
1025 literal
= gdbmi_value_literal_get (message
);
1027 if ((mi_results
!= NULL
)
1028 && ((message
= gdbmi_value_hash_lookup (mi_results
, "msg")) != NULL
)
1029 && ((literal
= gdbmi_value_literal_get (message
)) != NULL
)
1030 && (*literal
!= '\0'))
1032 code
= gdb_match_error (literal
);
1033 DEBUG_PRINT ("error code %d", code
);
1037 /* No error message */
1038 literal
= "Error without a message";
1041 return g_error_new_literal (IANJUTA_DEBUGGER_ERROR
, code
, literal
);
1046 *---------------------------------------------------------------------------*/
1049 debugger_parse_output (Debugger
*debugger
)
1053 line
= debugger
->priv
->stdo_line
->str
;
1055 if (line
[0] == '\032' && line
[1] == '\032')
1060 gdb_util_parse_error_line (&(line
[2]), &filename
, &lineno
);
1063 debugger_program_moved (debugger
, filename
, lineno
, 0);
1072 len
= strlen (line
);
1073 if (line
[1] == '\"' && line
[strlen(line
) - 1] == '\"')
1076 /* Reserve space for an additional carriage return */
1077 line
[strlen(line
) - 1] = ' ';
1078 proper_msg
= g_strcompress (line
+ 1);
1079 len
= strlen (proper_msg
) - 1;
1080 proper_msg
[len
] = '\0';
1084 /* Reserve space for an additional carriage return */
1085 proper_msg
= g_strndup (line
, len
+ 1);
1088 if (strcmp(proper_msg
, "~Stopped due to shared library event\n") == 0)
1090 /* Recognize a solib event */
1091 debugger
->priv
->solib_event
= TRUE
;
1092 g_free (proper_msg
);
1094 else if (debugger
->priv
->current_cmd
.parser
)
1096 /* Save GDB CLI output */
1097 debugger
->priv
->cli_lines
= g_list_prepend (debugger
->priv
->cli_lines
,
1102 /* Discard CLI output */
1103 g_free (proper_msg
);
1109 debugger_parse_stopped (Debugger
*debugger
)
1111 gchar
*line
= debugger
->priv
->stdo_line
->str
;
1114 if (!debugger
->priv
->solib_event
)
1116 gboolean program_exited
= FALSE
;
1119 /* Check if program has exited */
1120 val
= gdbmi_value_parse (line
);
1123 const GDBMIValue
*reason
;
1124 const gchar
*str
= NULL
;
1126 debugger_process_frame (debugger
, val
);
1128 reason
= gdbmi_value_hash_lookup (val
, "reason");
1130 str
= gdbmi_value_literal_get (reason
);
1132 if (str
&& (strncmp (str
, "exited", 6) == 0))
1134 program_exited
= TRUE
;
1137 /* Emit signal received if necessary */
1138 if (str
&& strcmp (str
, "exited-signalled") == 0)
1140 const GDBMIValue
*signal_name
, *signal_meaning
;
1141 const gchar
*signal_str
, *signal_meaning_str
;
1143 signal_name
= gdbmi_value_hash_lookup (val
, "signal-name");
1144 signal_str
= gdbmi_value_literal_get (signal_name
);
1145 signal_meaning
= gdbmi_value_hash_lookup (val
, "signal-meaning");
1146 signal_meaning_str
= gdbmi_value_literal_get (signal_meaning
);
1147 g_signal_emit_by_name (debugger
->priv
->instance
, "signal-received", signal_str
, signal_meaning_str
);
1149 else if (str
&& strcmp (str
, "signal-received") == 0)
1151 const GDBMIValue
*signal_name
, *signal_meaning
;
1152 const gchar
*signal_str
, *signal_meaning_str
;
1154 signal_name
= gdbmi_value_hash_lookup (val
, "signal-name");
1155 signal_str
= gdbmi_value_literal_get (signal_name
);
1156 signal_meaning
= gdbmi_value_hash_lookup (val
, "signal-meaning");
1157 signal_meaning_str
= gdbmi_value_literal_get (signal_meaning
);
1159 g_signal_emit_by_name (debugger
->priv
->instance
, "signal-received", signal_str
, signal_meaning_str
);
1162 if (debugger
->priv
->output_callback
)
1164 if (str
&& strcmp (str
, "exited-normally") == 0)
1166 debugger
->priv
->output_callback (IANJUTA_DEBUGGER_OUTPUT
,
1167 _("Program exited normally\n"),
1168 debugger
->priv
->output_user_data
);
1170 else if (str
&& strcmp (str
, "exited") == 0)
1172 const GDBMIValue
*errcode
;
1173 const gchar
*errcode_str
;
1176 errcode
= gdbmi_value_hash_lookup (val
, "exit-code");
1177 errcode_str
= gdbmi_value_literal_get (errcode
);
1178 msg
= g_strdup_printf (_("Program exited with error code %s\n"),
1180 debugger
->priv
->output_callback (IANJUTA_DEBUGGER_OUTPUT
,
1181 msg
, debugger
->priv
->output_user_data
);
1184 else if (str
&& strcmp (str
, "breakpoint-hit") == 0)
1186 const GDBMIValue
*bkptno
;
1187 const gchar
*bkptno_str
;
1190 bkptno
= gdbmi_value_hash_lookup (val
, "bkptno");
1191 bkptno_str
= gdbmi_value_literal_get (bkptno
);
1193 msg
= g_strdup_printf (_("Breakpoint number %s hit\n"),
1195 debugger
->priv
->output_callback (IANJUTA_DEBUGGER_OUTPUT
,
1196 msg
, debugger
->priv
->output_user_data
);
1199 else if (str
&& strcmp (str
, "function-finished") == 0)
1201 debugger
->priv
->output_callback (IANJUTA_DEBUGGER_OUTPUT
,
1202 _("Function finished\n"),
1203 debugger
->priv
->output_user_data
);
1205 else if (str
&& strcmp (str
, "end-stepping-range") == 0)
1207 debugger
->priv
->output_callback (IANJUTA_DEBUGGER_OUTPUT
,
1208 _("Stepping finished\n"),
1209 debugger
->priv
->output_user_data
);
1211 else if (str
&& strcmp (str
, "location-reached") == 0)
1213 debugger
->priv
->output_callback (IANJUTA_DEBUGGER_OUTPUT
,
1214 _("Location reached\n"),
1215 debugger
->priv
->output_user_data
);
1222 debugger
->priv
->prog_is_running
= FALSE
;
1223 debugger
->priv
->prog_is_attached
= FALSE
;
1224 debugger_handle_post_execution (debugger
);
1225 debugger
->priv
->exiting
= TRUE
;
1229 // g_signal_emit_by_name (debugger->priv->instance, "program-stopped");
1230 debugger
->priv
->stopping
= TRUE
;
1233 debugger
->priv
->cli_lines
= g_list_reverse (debugger
->priv
->cli_lines
);
1234 if ((debugger
->priv
->current_cmd
.cmd
!= NULL
) &&
1235 (debugger
->priv
->current_cmd
.parser
!= NULL
))
1237 debugger
->priv
->current_cmd
.parser (debugger
, val
,
1238 debugger
->priv
->cli_lines
, FALSE
);
1239 debugger
->priv
->command_output_sent
= TRUE
;
1240 DEBUG_PRINT ("In function: Sending output...");
1244 gdbmi_value_free (val
);
1249 debugger_parse_prompt (Debugger
*debugger
)
1251 /* If the parser has not yet been called, call it now. */
1252 if (debugger
->priv
->command_output_sent
== FALSE
&&
1253 debugger
->priv
->current_cmd
.parser
)
1255 debugger
->priv
->current_cmd
.parser (debugger
, NULL
,
1256 debugger
->priv
->cli_lines
, FALSE
);
1257 debugger
->priv
->command_output_sent
= TRUE
;
1260 debugger
->priv
->debugger_is_busy
--;
1261 debugger_queue_execute_command (debugger
); /* Next command. Go. */
1262 debugger_emit_ready (debugger
);
1266 parse_breakpoint (IAnjutaDebuggerBreakpointItem
* bp
, const GDBMIValue
*brkpnt
)
1268 const GDBMIValue
*literal
;
1271 memset (bp
, 0, sizeof (*bp
));
1273 literal
= gdbmi_value_hash_lookup (brkpnt
, "number");
1276 value
= gdbmi_value_literal_get (literal
);
1277 bp
->id
= strtoul (value
, NULL
, 10);
1280 literal
= gdbmi_value_hash_lookup (brkpnt
, "fullname");
1281 if (literal
== NULL
) literal
= gdbmi_value_hash_lookup (brkpnt
, "file");
1284 value
= gdbmi_value_literal_get (literal
);
1285 bp
->file
= (gchar
*)value
;
1288 literal
= gdbmi_value_hash_lookup (brkpnt
, "line");
1291 value
= gdbmi_value_literal_get (literal
);
1292 bp
->line
= strtoul (value
, NULL
, 10);
1293 bp
->type
|= IANJUTA_DEBUGGER_BREAKPOINT_ON_LINE
;
1296 literal
= gdbmi_value_hash_lookup (brkpnt
, "type");
1299 value
= gdbmi_value_literal_get (literal
);
1302 literal
= gdbmi_value_hash_lookup (brkpnt
, "disp");
1305 value
= gdbmi_value_literal_get (literal
);
1306 if (strcmp (value
, "keep") == 0)
1308 bp
->type
|= IANJUTA_DEBUGGER_BREAKPOINT_WITH_TEMPORARY
;
1309 bp
->temporary
= FALSE
;
1311 else if ((strcmp (value
, "nokeep") == 0) || (strcmp (value
, "del") == 0))
1313 bp
->type
|= IANJUTA_DEBUGGER_BREAKPOINT_WITH_TEMPORARY
;
1314 bp
->temporary
= TRUE
;
1318 literal
= gdbmi_value_hash_lookup (brkpnt
, "enabled");
1321 value
= gdbmi_value_literal_get (literal
);
1322 if (strcmp (value
, "n") == 0)
1324 bp
->type
|= IANJUTA_DEBUGGER_BREAKPOINT_WITH_ENABLE
;
1327 else if (strcmp (value
, "y") == 0)
1329 bp
->type
|= IANJUTA_DEBUGGER_BREAKPOINT_WITH_ENABLE
;
1334 literal
= gdbmi_value_hash_lookup (brkpnt
, "addr");
1337 value
= gdbmi_value_literal_get (literal
);
1338 bp
->address
= strtoul (value
, NULL
, 16);
1339 bp
->type
|= IANJUTA_DEBUGGER_BREAKPOINT_ON_ADDRESS
;
1342 literal
= gdbmi_value_hash_lookup (brkpnt
, "func");
1345 value
= gdbmi_value_literal_get (literal
);
1346 bp
->function
= (gchar
*)value
;
1347 bp
->type
|= IANJUTA_DEBUGGER_BREAKPOINT_ON_FUNCTION
;
1350 literal
= gdbmi_value_hash_lookup (brkpnt
, "times");
1353 value
= gdbmi_value_literal_get (literal
);
1354 bp
->times
= strtoul (value
, NULL
, 10);
1355 bp
->type
|= IANJUTA_DEBUGGER_BREAKPOINT_WITH_TIME
;
1357 DEBUG_PRINT("parse time %d", bp
->times
);
1359 literal
= gdbmi_value_hash_lookup (brkpnt
, "ignore");
1362 value
= gdbmi_value_literal_get (literal
);
1363 bp
->ignore
= strtoul (value
, NULL
, 10);
1364 bp
->type
|= IANJUTA_DEBUGGER_BREAKPOINT_WITH_IGNORE
;
1367 literal
= gdbmi_value_hash_lookup (brkpnt
, "cond");
1370 value
= gdbmi_value_literal_get (literal
);
1371 bp
->condition
= (gchar
*)value
;
1372 bp
->type
|= IANJUTA_DEBUGGER_BREAKPOINT_WITH_CONDITION
;
1379 debugger_stdo_flush (Debugger
*debugger
)
1383 line
= debugger
->priv
->stdo_line
->str
;
1386 DEBUG_PRINT ("GDB:< %s", line
);
1388 if (debugger
->priv
->gdb_log
) g_message ("GDB:< %s", line
);
1390 debugger_log_output (debugger
, line
);
1391 if (strlen (line
) == 0)
1395 if (strncasecmp (line
, "^error", 6) == 0)
1397 /* GDB reported error */
1398 if ((debugger
->priv
->current_cmd
.keep_result
) || (debugger
->priv
->stdo_acc
->len
!= 0))
1400 /* Keep result for next command */
1402 if (debugger
->priv
->stdo_acc
->len
== 0)
1404 g_string_append (debugger
->priv
->stdo_acc
, line
);
1408 line
= strchr (line
, ',');
1411 g_string_append (debugger
->priv
->stdo_acc
, line
);
1414 line
= debugger
->priv
->stdo_acc
->str
;
1417 GDBMIValue
*val
= gdbmi_value_parse (line
);
1420 error
= gdb_parse_error (debugger
, val
);
1422 if (debugger
->priv
->current_cmd
.parser
!= NULL
)
1424 debugger
->priv
->current_cmd
.parser (debugger
, val
, debugger
->priv
->cli_lines
, error
);
1425 debugger
->priv
->command_output_sent
= TRUE
; }
1426 DEBUG_PRINT("GDB: error %s", error
->message
);
1429 anjuta_util_dialog_error (debugger->priv->parent_win, "%s", error->message);
1431 g_error_free (error
);
1432 gdbmi_value_free (val
);
1434 else if (strncasecmp(line
, "^running", 8) == 0)
1436 /* Program started running */
1437 debugger
->priv
->prog_is_running
= TRUE
;
1438 /* debugger->priv->skip_next_prompt = TRUE; Replaced by debugger_is_busy++ */
1439 debugger
->priv
->debugger_is_busy
++;
1440 g_signal_emit_by_name (debugger
->priv
->instance
, "program-running");
1442 else if (strncasecmp (line
, "*stopped", 8) == 0)
1444 /* Process has stopped */
1445 debugger_parse_stopped (debugger
);
1447 else if (strncasecmp (line
, "^done", 5) == 0)
1449 if ((debugger
->priv
->current_cmd
.keep_result
) || (debugger
->priv
->stdo_acc
->len
!= 0))
1451 /* Keep result for next command */
1453 if (debugger
->priv
->stdo_acc
->len
== 0)
1455 g_string_append (debugger
->priv
->stdo_acc
, line
);
1459 line
= strchr (line
, ',');
1462 g_string_append (debugger
->priv
->stdo_acc
, line
);
1465 line
= debugger
->priv
->stdo_acc
->str
;
1468 if (!debugger
->priv
->current_cmd
.keep_result
)
1470 /* GDB command has reported output */
1471 GDBMIValue
*val
= gdbmi_value_parse (line
);
1473 debugger
->priv
->cli_lines
= g_list_reverse (debugger
->priv
->cli_lines
);
1474 if ((debugger
->priv
->current_cmd
.cmd
!= NULL
) &&
1475 (debugger
->priv
->current_cmd
.parser
!= NULL
))
1477 debugger
->priv
->current_cmd
.parser (debugger
, val
,
1478 debugger
->priv
->cli_lines
, FALSE
);
1479 debugger
->priv
->command_output_sent
= TRUE
;
1480 DEBUG_PRINT ("In function: Sending output...");
1484 /*g_signal_emit_by_name (debugger, "results-arrived",
1485 debugger->priv->current_cmd.cmd, val);*/
1490 /*debugger_process_frame (debugger, val);*/
1491 gdbmi_value_free (val
);
1495 if (!debugger
->priv
->current_cmd
.keep_result
)
1497 g_string_assign (debugger
->priv
->stdo_acc
, "");
1500 else if (strncasecmp (line
, GDB_PROMPT
, strlen (GDB_PROMPT
)) == 0)
1502 debugger_parse_prompt (debugger
);
1506 debugger_parse_output (debugger
);
1509 /* Clear the line buffer */
1510 g_string_assign (debugger
->priv
->stdo_line
, "");
1514 debugger_stde_flush (Debugger
*debugger
)
1516 if ((debugger
->priv
->output_callback
) && (strlen (debugger
->priv
->stde_line
->str
) > 0))
1518 debugger
->priv
->output_callback (IANJUTA_DEBUGGER_ERROR_OUTPUT
,
1519 debugger
->priv
->stde_line
->str
,
1520 debugger
->priv
->output_user_data
);
1522 /* Clear the line buffer */
1523 g_string_assign (debugger
->priv
->stde_line
, "");
1527 on_gdb_terminated (AnjutaLauncher
*launcher
,
1528 gint child_pid
, gint status
, gulong t
,
1531 Debugger
*debugger
= DEBUGGER (data
);
1534 g_signal_handlers_disconnect_by_func (G_OBJECT (launcher
),
1535 G_CALLBACK (on_gdb_terminated
),
1538 DEBUG_PRINT ("In function: gdb_terminated()");
1540 /* Clear the command queue & Buffer */
1541 debugger_clear_buffers (debugger
);
1543 /* Good Bye message */
1544 /*if (!debugger->priv->terminating)
1546 anjuta_util_dialog_error (debugger->priv->parent_win,
1547 _("gdb terminated unexpectedly with status %d\n"), status);
1549 debugger
->priv
->prog_is_running
= FALSE
;
1550 debugger
->priv
->prog_is_attached
= FALSE
;
1551 debugger
->priv
->prog_is_loaded
= FALSE
;
1552 debugger
->priv
->debugger_is_busy
= 0;
1553 debugger
->priv
->skip_next_prompt
= FALSE
;
1554 if (!debugger
->priv
->terminating
)
1556 err
= g_error_new (IANJUTA_DEBUGGER_ERROR
,
1557 IANJUTA_DEBUGGER_OTHER_ERROR
,
1558 "gdb terminated with status %d", status
);
1560 debugger
->priv
->terminating
= FALSE
;
1561 debugger
->priv
->debugger_is_started
= FALSE
;
1562 if (debugger
->priv
->instance
)
1564 g_signal_emit_by_name (debugger
->priv
->instance
, "debugger-stopped", err
);
1566 if (err
!= NULL
) g_error_free (err
);
1570 debugger_stop_real (Debugger
*debugger
)
1572 DEBUG_PRINT ("In function: debugger_stop_real()");
1574 /* if program is attached - detach from it before quiting */
1575 if (debugger
->priv
->prog_is_attached
== TRUE
)
1576 debugger_queue_command (debugger
, "detach", FALSE
, FALSE
, NULL
, NULL
, NULL
);
1578 debugger
->priv
->terminating
= TRUE
;
1579 debugger_queue_command (debugger
, "-gdb-exit", FALSE
, FALSE
, NULL
, NULL
, NULL
);
1583 debugger_stop (Debugger
*debugger
)
1586 gboolean ret
= TRUE
;
1588 if (debugger
->priv
->prog_is_running
== TRUE
)
1593 if (debugger
->priv
->prog_is_attached
== TRUE
)
1594 mesg
= _("The program is attached.\n"
1595 "Do you still want to stop the debugger?");
1597 mesg
= _("The program is running.\n"
1598 "Do you still want to stop the debugger?");
1599 dialog
= gtk_message_dialog_new (debugger
->priv
->parent_win
,
1600 GTK_DIALOG_DESTROY_WITH_PARENT
,
1601 GTK_MESSAGE_QUESTION
,
1602 GTK_BUTTONS_NONE
, mesg
);
1603 gtk_dialog_add_buttons (GTK_DIALOG (dialog
),
1604 GTK_STOCK_CANCEL
, GTK_RESPONSE_NO
,
1605 GTK_STOCK_STOP
, GTK_RESPONSE_YES
,
1607 if (gtk_dialog_run (GTK_DIALOG (dialog
)) == GTK_RESPONSE_YES
)
1608 debugger_stop_real (debugger
);
1611 gtk_widget_destroy (dialog
);
1614 debugger_stop_real (debugger
);
1617 debugger_stop_real (debugger
);
1623 debugger_abort (Debugger
*debugger
)
1625 DEBUG_PRINT ("In function: debugger_abort()");
1628 if ((debugger
->priv
->prog_is_attached
== FALSE
) && (debugger
->priv
->inferior_pid
!= 0))
1630 kill (debugger
->priv
->inferior_pid
, SIGTERM
);
1631 debugger
->priv
->inferior_pid
= 0;
1635 debugger
->priv
->terminating
= TRUE
;
1636 g_signal_handlers_disconnect_by_func (G_OBJECT (debugger
->priv
->launcher
), G_CALLBACK (on_gdb_terminated
), debugger
);
1637 anjuta_launcher_reset (debugger
->priv
->launcher
);
1640 debugger_queue_clear (debugger
);
1641 g_list_foreach (debugger
->priv
->search_dirs
, (GFunc
)g_free
, NULL
);
1642 g_list_free (debugger
->priv
->search_dirs
);
1643 debugger
->priv
->search_dirs
= NULL
;
1645 /* Emit signal, state of the debugger must be DEBUGGER_STOPPED */
1646 debugger
->priv
->prog_is_running
= FALSE
;
1647 debugger
->priv
->prog_is_attached
= FALSE
;
1648 debugger
->priv
->prog_is_loaded
= FALSE
;
1649 debugger
->priv
->debugger_is_busy
= 0;
1650 debugger
->priv
->debugger_is_started
= FALSE
;
1651 if (debugger
->priv
->instance
!= NULL
)
1653 g_signal_emit_by_name (debugger
->priv
->instance
, "debugger-stopped", NULL
);
1654 debugger
->priv
->instance
= NULL
;
1661 debugger_get_source_path (Debugger
*debugger
, const gchar
*file
)
1666 if (g_path_is_absolute (file
))
1667 return g_strdup (file
);
1669 node
= debugger
->priv
->search_dirs
;
1672 path
= g_build_filename (node
->data
, file
, NULL
);
1673 if (g_file_test (path
, G_FILE_TEST_EXISTS
))
1677 node
= g_list_next (node
);
1682 /* The file could be found nowhere. Use current directory */
1684 cwd
= g_get_current_dir ();
1685 path
= g_build_filename (cwd
, file
, NULL
);
1692 debugger_set_output_callback (Debugger
*debugger
, IAnjutaDebuggerOutputCallback callback
, gpointer user_data
)
1694 debugger
->priv
->output_callback
= callback
;
1695 debugger
->priv
->output_user_data
= user_data
;
1699 debugger_program_moved (Debugger
*debugger
, const gchar
*file
,
1700 gint line
, gulong address
)
1704 if ((file
!= NULL
) && (*file
!= G_DIR_SEPARATOR
))
1706 src_path
= debugger_get_source_path (debugger
, file
);
1707 g_signal_emit_by_name (debugger
->priv
->instance
, "program-moved", debugger
->priv
->inferior_pid
, debugger
->priv
->current_thread
, address
, src_path
, line
);
1712 g_signal_emit_by_name (debugger
->priv
->instance
, "program-moved", debugger
->priv
->inferior_pid
, debugger
->priv
->current_thread
, address
, file
, line
);
1717 debugger_info_program_finish (Debugger
*debugger
, const GDBMIValue
*mi_results
,
1718 const GList
*cli_results
, GError
*error
)
1720 DEBUG_PRINT ("In function: debugger_info_program()");
1722 /* Hack: find message string giving inferior pid */
1723 while (cli_results
!= NULL
)
1727 child_proc
= strstr(cli_results
->data
, " child process ");
1728 if (child_proc
!= NULL
)
1730 debugger
->priv
->inferior_pid
= strtoul (child_proc
+ 15, NULL
, 10);
1733 cli_results
= g_list_next (cli_results
);
1738 debugger_start_program (Debugger
*debugger
, const gchar
* args
, const gchar
* tty
, gboolean stop
)
1742 DEBUG_PRINT ("In function: debugger_start_program()");
1744 g_return_if_fail (IS_DEBUGGER (debugger
));
1745 g_return_if_fail (debugger
->priv
->prog_is_running
== FALSE
);
1747 /* Without a terminal, the output of the debugged program
1751 cmd
= g_strdup_printf ("-inferior-tty-set %s", tty
);
1752 debugger_queue_command (debugger
, cmd
, FALSE
, FALSE
, NULL
, NULL
, NULL
);
1756 debugger
->priv
->inferior_pid
= 0;
1759 debugger_queue_command (debugger
, "-break-insert -t main", FALSE
, FALSE
, NULL
, NULL
, NULL
);
1761 if (args
&& (*args
))
1763 cmd
= g_strconcat ("-exec-arguments ", args
, NULL
);
1764 debugger_queue_command (debugger
, cmd
, FALSE
, FALSE
, NULL
, NULL
, NULL
);
1768 debugger_queue_command (debugger
, "-exec-run", FALSE
, FALSE
, NULL
, NULL
, NULL
);
1770 /* Get pid of program on next stop */
1771 debugger_queue_command (debugger
, "info program", FALSE
, FALSE
, debugger_info_program_finish
, NULL
, NULL
);
1772 debugger
->priv
->post_execution_flag
= DEBUGGER_NONE
;
1776 debugger_attach_process_finish (Debugger
*debugger
, const GDBMIValue
*mi_results
,
1777 const GList
*cli_results
, GError
*error
)
1779 DEBUG_PRINT ("Program attach finished");
1780 if (debugger
->priv
->output_callback
)
1782 debugger
->priv
->output_callback (IANJUTA_DEBUGGER_OUTPUT
,
1783 _("Program attached\n"),
1784 debugger
->priv
->output_user_data
);
1786 debugger
->priv
->prog_is_attached
= TRUE
;
1787 debugger
->priv
->prog_is_running
= TRUE
;
1788 //debugger_emit_status (debugger);
1792 debugger_attach_process_real (Debugger
*debugger
, pid_t pid
)
1796 DEBUG_PRINT ("In function: debugger_attach_process_real()");
1798 if (debugger
->priv
->output_callback
)
1800 buff
= g_strdup_printf (_("Attaching to process: %d...\n"), pid
);
1801 debugger
->priv
->output_callback (IANJUTA_DEBUGGER_OUTPUT
,
1802 buff
, debugger
->priv
->output_user_data
);
1806 debugger
->priv
->inferior_pid
= pid
;
1807 buff
= g_strdup_printf ("attach %d", pid
);
1808 debugger_queue_command (debugger
, buff
, FALSE
, FALSE
,
1809 debugger_attach_process_finish
, NULL
, NULL
);
1814 debugger_attach_process (Debugger
*debugger
, pid_t pid
)
1816 DEBUG_PRINT ("In function: debugger_attach_process()");
1818 g_return_if_fail (IS_DEBUGGER (debugger
));
1820 if (debugger
->priv
->prog_is_running
== TRUE
)
1822 // TODO: Dialog to be made HIG compliant.
1826 mesg
= _("A process is already running.\n"
1827 "Would you like to terminate it and attach the new process?"),
1828 dialog
= gtk_message_dialog_new (debugger
->priv
->parent_win
,
1829 GTK_DIALOG_DESTROY_WITH_PARENT
,
1830 GTK_MESSAGE_QUESTION
,
1831 GTK_BUTTONS_YES_NO
, mesg
);
1832 if (gtk_dialog_run (GTK_DIALOG (dialog
)) == GTK_RESPONSE_YES
)
1834 debugger_stop_program (debugger
);
1835 debugger_attach_process_real (debugger
, pid
);
1837 gtk_widget_destroy (dialog
);
1839 else if (getpid () == pid
||
1840 anjuta_launcher_get_child_pid (debugger
->priv
->launcher
) == pid
)
1842 anjuta_util_dialog_error (debugger
->priv
->parent_win
,
1843 _("Anjuta is unable to attach to itself."));
1847 debugger_attach_process_real (debugger
, pid
);
1851 debugger_restart_program (Debugger
*debugger
)
1853 DEBUG_PRINT ("In function: debugger_restart_program()");
1855 g_return_if_fail (debugger
->priv
->prog_is_attached
== FALSE
);
1858 debugger->priv->post_execution_flag = DEBUGGER_RERUN_PROGRAM;
1859 debugger_stop_program (debugger);
1861 debugger_put_cmd_in_queqe ("tbreak main", DB_CMD_NONE, NULL, NULL);
1862 debugger_put_cmd_in_queqe ("run >/dev/null 2>/dev/null", DB_CMD_ALL,
1864 debugger_put_cmd_in_queqe ("info program", DB_CMD_NONE,
1865 on_debugger_update_prog_status, NULL);
1866 debugger_put_cmd_in_queqe ("continue", DB_CMD_NONE, NULL, NULL);
1867 debugger_execute_cmd_in_queqe ();
1872 debugger_stop_program (Debugger
*debugger
)
1874 DEBUG_PRINT ("In function: debugger_stop_program()");
1876 g_return_if_fail (debugger
->priv
->prog_is_running
== TRUE
);
1878 if (debugger
->priv
->prog_is_attached
== TRUE
)
1879 debugger_queue_command (debugger
, "detach", FALSE
, FALSE
, NULL
, NULL
, NULL
);
1882 /* FIXME: Why doesn't -exec-abort work??? */
1883 /* debugger_queue_command (debugger, "-exec-abort", NULL, NULL); */
1884 debugger_queue_command (debugger
, "kill", FALSE
, FALSE
, NULL
, NULL
, NULL
);
1885 debugger
->priv
->prog_is_running
= FALSE
;
1886 debugger
->priv
->prog_is_attached
= FALSE
;
1887 g_signal_emit_by_name (debugger
->priv
->instance
, "program-exited");
1888 if (debugger
->priv
->output_callback
)
1890 debugger
->priv
->output_callback (IANJUTA_DEBUGGER_OUTPUT
,
1891 _("Program terminated\n"),
1892 debugger
->priv
->output_user_data
);
1894 debugger_handle_post_execution (debugger
);
1899 debugger_detach_process_finish (Debugger
*debugger
, const GDBMIValue
*mi_results
,
1900 const GList
*cli_results
, GError
*error
)
1902 DEBUG_PRINT ("Program detach finished");
1903 if (debugger
->priv
->output_callback
)
1905 debugger
->priv
->output_callback (IANJUTA_DEBUGGER_OUTPUT
,
1906 _("Program detached\n"),
1907 debugger
->priv
->output_user_data
);
1909 debugger
->priv
->prog_is_attached
= FALSE
;
1910 debugger
->priv
->prog_is_running
= FALSE
;
1911 g_signal_emit_by_name (debugger
->priv
->instance
, "program-exited");
1915 debugger_detach_process (Debugger
*debugger
)
1919 DEBUG_PRINT ("In function: debugger_detach_process()");
1921 g_return_if_fail (debugger
->priv
->prog_is_attached
== TRUE
);
1923 if (debugger
->priv
->output_callback
)
1925 buff
= g_strdup_printf (_("Detaching the process...\n"));
1926 debugger
->priv
->output_callback (IANJUTA_DEBUGGER_OUTPUT
,
1927 buff
, debugger
->priv
->output_user_data
);
1931 debugger_queue_command (debugger
, "detach", FALSE
, FALSE
,
1932 debugger_detach_process_finish
, NULL
, NULL
);
1933 debugger
->priv
->prog_is_attached
= FALSE
;
1937 debugger_interrupt (Debugger
*debugger
)
1939 DEBUG_PRINT ("In function: debugger_interrupt()");
1941 g_return_if_fail (IS_DEBUGGER (debugger
));
1942 g_return_if_fail (debugger
->priv
->prog_is_running
== TRUE
);
1944 if (debugger
->priv
->output_callback
)
1946 debugger
->priv
->output_callback (IANJUTA_DEBUGGER_OUTPUT
,
1947 _("Interrupting the process\n"),
1948 debugger
->priv
->output_user_data
);
1951 if (debugger
->priv
->inferior_pid
== 0)
1953 /* In case we do not have the inferior pid, send signal to gdb */
1954 anjuta_launcher_signal (debugger
->priv
->launcher
, SIGINT
);
1958 /* Send signal directly to inferior */
1959 kill (debugger
->priv
->inferior_pid
, SIGINT
);
1961 //g_signal_emit_by_name (debugger->priv->instance, "program-running");
1965 debugger_run (Debugger
*debugger
)
1967 DEBUG_PRINT ("In function: debugger_run()");
1969 g_return_if_fail (IS_DEBUGGER (debugger
));
1970 g_return_if_fail (debugger
->priv
->prog_is_running
== TRUE
);
1972 /* Program running - continue */
1973 debugger_queue_command (debugger
, "-exec-continue", FALSE
, FALSE
, NULL
, NULL
, NULL
);
1977 debugger_step_in (Debugger
*debugger
)
1979 DEBUG_PRINT ("In function: debugger_step_in()");
1981 g_return_if_fail (IS_DEBUGGER (debugger
));
1982 g_return_if_fail (debugger
->priv
->prog_is_running
== TRUE
);
1984 debugger_queue_command (debugger
, "-exec-step", FALSE
, FALSE
, NULL
, NULL
, NULL
);
1988 debugger_step_over (Debugger
*debugger
)
1990 DEBUG_PRINT ("In function: debugger_step_over()");
1992 g_return_if_fail (IS_DEBUGGER (debugger
));
1993 g_return_if_fail (debugger
->priv
->prog_is_running
== TRUE
);
1995 debugger_queue_command (debugger
, "-exec-next", FALSE
, FALSE
, NULL
, NULL
, NULL
);
1999 debugger_step_out (Debugger
*debugger
)
2001 DEBUG_PRINT ("In function: debugger_step_out()");
2003 g_return_if_fail (IS_DEBUGGER (debugger
));
2004 g_return_if_fail (debugger
->priv
->prog_is_running
== TRUE
);
2006 debugger_queue_command (debugger
, "-exec-finish", FALSE
, FALSE
, NULL
, NULL
, NULL
);
2010 debugger_stepi_in (Debugger
*debugger
)
2012 DEBUG_PRINT ("In function: debugger_step_in()");
2014 g_return_if_fail (IS_DEBUGGER (debugger
));
2015 g_return_if_fail (debugger
->priv
->prog_is_running
== TRUE
);
2017 debugger_queue_command (debugger
, "-exec-step-instruction", FALSE
, FALSE
, NULL
, NULL
, NULL
);
2021 debugger_stepi_over (Debugger
*debugger
)
2023 DEBUG_PRINT ("In function: debugger_step_over()");
2025 g_return_if_fail (IS_DEBUGGER (debugger
));
2026 g_return_if_fail (debugger
->priv
->prog_is_running
== TRUE
);
2028 debugger_queue_command (debugger
, "-exec-next-instruction", FALSE
, FALSE
, NULL
, NULL
, NULL
);
2032 debugger_run_to_location (Debugger
*debugger
, const gchar
*loc
)
2036 DEBUG_PRINT ("In function: debugger_run_to_location()");
2038 g_return_if_fail (IS_DEBUGGER (debugger
));
2039 g_return_if_fail (debugger
->priv
->prog_is_running
== TRUE
);
2041 buff
= g_strdup_printf ("-exec-until %s", loc
);
2042 debugger_queue_command (debugger
, buff
, FALSE
, FALSE
, NULL
, NULL
, NULL
);
2047 debugger_run_to_position (Debugger
*debugger
, const gchar
*file
, guint line
)
2051 DEBUG_PRINT ("In function: debugger_run_to_position()");
2053 g_return_if_fail (IS_DEBUGGER (debugger
));
2054 g_return_if_fail (debugger
->priv
->prog_is_running
== TRUE
);
2056 buff
= g_strdup_printf ("-break-insert -t %s:%d", file
, line
);
2057 debugger_queue_command (debugger
, buff
, FALSE
, FALSE
, NULL
, NULL
, NULL
);
2059 debugger_queue_command (debugger
, "-exec-continue", FALSE
, FALSE
, NULL
, NULL
, NULL
);
2063 debugger_run_to_address (Debugger
*debugger
, gulong address
)
2067 DEBUG_PRINT ("In function: debugger_run_to_address()");
2069 g_return_if_fail (IS_DEBUGGER (debugger
));
2070 g_return_if_fail (debugger
->priv
->prog_is_running
== TRUE
);
2072 buff
= g_strdup_printf ("-break-insert -t *0x%lx", address
);
2073 debugger_queue_command (debugger
, buff
, FALSE
, FALSE
, NULL
, NULL
, NULL
);
2075 debugger_queue_command (debugger
, "-exec-continue", FALSE
, FALSE
, NULL
, NULL
, NULL
);
2079 debugger_command (Debugger
*debugger
, const gchar
*command
,
2080 gboolean suppress_error
, DebuggerParserFunc parser
,
2083 if (strncasecmp (command
, "-exec-run",
2084 strlen ("-exec-run")) == 0 ||
2085 strncasecmp (command
, "run", strlen ("run")) == 0)
2087 /* FIXME: The user might have passed args to the command */
2088 debugger_run (debugger
);
2090 else if (strncasecmp (command
, "-exec-step",
2091 strlen ("-exec-step")) == 0 ||
2092 strncasecmp (command
, "step", strlen ("step")) == 0)
2094 debugger_step_in (debugger
);
2096 else if (strncasecmp (command
, "-exec-next",
2097 strlen ("-exec-next")) == 0 ||
2098 strncasecmp (command
, "next", strlen ("next")) == 0)
2100 debugger_step_over (debugger
);
2102 else if (strncasecmp (command
, "-exec-finish",
2103 strlen ("-exec-finish")) == 0 ||
2104 strncasecmp (command
, "finish", strlen ("finish")) == 0)
2106 debugger_step_out (debugger
);
2108 else if (strncasecmp (command
, "-exec-continue",
2109 strlen ("-exec-continue")) == 0 ||
2110 strncasecmp (command
, "continue", strlen ("continue")) == 0)
2112 debugger_run (debugger
);
2114 else if (strncasecmp (command
, "-exec-until",
2115 strlen ("-exec-until")) == 0 ||
2116 strncasecmp (command
, "until", strlen ("until")) == 0)
2118 debugger_run_to_location (debugger
, strchr (command
, ' '));
2120 else if (strncasecmp (command
, "-exec-abort",
2121 strlen ("-exec-abort")) == 0 ||
2122 strncasecmp (command
, "kill", strlen ("kill")) == 0)
2124 debugger_stop_program (debugger
);
2126 else if (strncasecmp (command
, "-target-attach",
2127 strlen ("-target-attach")) == 0 ||
2128 strncasecmp (command
, "attach", strlen ("attach")) == 0)
2131 gchar
*pid_str
= strchr (command
, ' ');
2133 pid
= atoi (pid_str
);
2134 debugger_attach_process (debugger
, pid
);
2136 else if (strncasecmp (command
, "-target-detach",
2137 strlen ("-target-detach")) == 0 ||
2138 strncasecmp (command
, "detach", strlen ("detach")) == 0)
2140 debugger_detach_process (debugger
);
2142 else if (strncasecmp (command
, "-file-exec-and-symbols",
2143 strlen ("-file-exec-and-symbols")) == 0 ||
2144 strncasecmp (command
, "file", strlen ("file")) == 0)
2146 debugger_load_executable (debugger
, strchr (command
, ' '));
2148 else if (strncasecmp (command
, "core", strlen ("core")) == 0)
2150 debugger_load_core (debugger
, strchr (command
, ' '));
2154 debugger_queue_command (debugger
, command
, suppress_error
, FALSE
,
2155 parser
, user_data
, NULL
);
2160 debugger_add_breakpoint_finish (Debugger
*debugger
, const GDBMIValue
*mi_results
, const GList
*cli_results
, GError
*error
)
2162 IAnjutaDebuggerBreakpointItem bp
;
2163 IAnjutaDebuggerCallback callback
= debugger
->priv
->current_cmd
.callback
;
2164 gpointer user_data
= debugger
->priv
->current_cmd
.user_data
;
2166 if ((error
!= NULL
) || (mi_results
== NULL
))
2168 /* Call callback in all case (useful for enable that doesn't return
2170 if (callback
!= NULL
)
2171 callback (NULL
, user_data
, error
);
2173 else if (callback
!= NULL
)
2175 const GDBMIValue
*brkpnt
;
2177 brkpnt
= gdbmi_value_hash_lookup (mi_results
, "bkpt");
2178 parse_breakpoint (&bp
, brkpnt
);
2180 /* Call callback in all case (useful for enable that doesn't return
2182 callback (&bp
, user_data
, error
);
2188 debugger_add_breakpoint_at_line (Debugger
*debugger
, const gchar
*file
, guint line
, IAnjutaDebuggerCallback callback
, gpointer user_data
)
2192 DEBUG_PRINT ("In function: debugger_add_breakpoint()");
2194 g_return_if_fail (IS_DEBUGGER (debugger
));
2196 buff
= g_strdup_printf ("-break-insert %s:%u", file
, line
);
2197 debugger_queue_command (debugger
, buff
, FALSE
, FALSE
, debugger_add_breakpoint_finish
, callback
, user_data
);
2202 debugger_add_breakpoint_at_function (Debugger
*debugger
, const gchar
*file
, const gchar
*function
, IAnjutaDebuggerCallback callback
, gpointer user_data
)
2206 DEBUG_PRINT ("In function: debugger_add_breakpoint()");
2208 g_return_if_fail (IS_DEBUGGER (debugger
));
2210 buff
= g_strdup_printf ("-break-insert %s%s%s", file
== NULL
? "" : file
, file
== NULL
? "" : ":" , function
);
2211 debugger_queue_command (debugger
, buff
, FALSE
, FALSE
, debugger_add_breakpoint_finish
, callback
, user_data
);
2216 debugger_add_breakpoint_at_address (Debugger
*debugger
, gulong address
, IAnjutaDebuggerCallback callback
, gpointer user_data
)
2220 DEBUG_PRINT ("In function: debugger_add_breakpoint()");
2222 g_return_if_fail (IS_DEBUGGER (debugger
));
2224 buff
= g_strdup_printf ("-break-insert *0x%lx", address
);
2225 debugger_queue_command (debugger
, buff
, FALSE
, FALSE
, debugger_add_breakpoint_finish
, callback
, user_data
);
2230 debugger_enable_breakpoint (Debugger
*debugger
, guint id
, gboolean enable
, IAnjutaDebuggerCallback callback
, gpointer user_data
)
2235 DEBUG_PRINT ("In function: debugger_enable_breakpoint()");
2237 g_return_if_fail (IS_DEBUGGER (debugger
));
2239 buff
= g_strdup_printf (enable
? "-break-enable %d" : "-break-disable %d",id
);
2240 debugger_queue_command (debugger
, buff
, FALSE
, FALSE
, debugger_add_breakpoint_finish
, callback
, user_data
);
2245 debugger_ignore_breakpoint (Debugger
*debugger
, guint id
, guint ignore
, IAnjutaDebuggerCallback callback
, gpointer user_data
)
2249 DEBUG_PRINT ("In function: debugger_ignore_breakpoint()");
2251 g_return_if_fail (IS_DEBUGGER (debugger
));
2253 buff
= g_strdup_printf ("-break-after %d %d", id
, ignore
);
2254 debugger_queue_command (debugger
, buff
, FALSE
, FALSE
, debugger_add_breakpoint_finish
, callback
, user_data
);
2259 debugger_condition_breakpoint (Debugger
*debugger
, guint id
, const gchar
*condition
, IAnjutaDebuggerCallback callback
, gpointer user_data
)
2263 DEBUG_PRINT ("In function: debugger_ignore_breakpoint()");
2265 g_return_if_fail (IS_DEBUGGER (debugger
));
2267 buff
= g_strdup_printf ("-break-condition %d %s", id
, condition
== NULL
? "" : condition
);
2268 debugger_queue_command (debugger
, buff
, FALSE
, FALSE
, debugger_add_breakpoint_finish
, callback
, user_data
);
2273 debugger_remove_breakpoint_finish (Debugger
*debugger
, const GDBMIValue
*mi_results
, const GList
*cli_results
, GError
*error
)
2275 IAnjutaDebuggerCallback callback
= debugger
->priv
->current_cmd
.callback
;
2276 gpointer user_data
= debugger
->priv
->current_cmd
.user_data
;
2277 IAnjutaDebuggerBreakpointItem bp
;
2279 bp
.type
= IANJUTA_DEBUGGER_BREAKPOINT_REMOVED
;
2280 bp
.id
= atoi (debugger
->priv
->current_cmd
.cmd
+ 14);
2281 if (callback
!= NULL
)
2282 callback (&bp
, user_data
, NULL
);
2286 debugger_remove_breakpoint (Debugger
*debugger
, guint id
, IAnjutaDebuggerCallback callback
, gpointer user_data
)
2290 DEBUG_PRINT ("In function: debugger_delete_breakpoint()");
2292 g_return_if_fail (IS_DEBUGGER (debugger
));
2294 buff
= g_strdup_printf ("-break-delete %d", id
);
2295 debugger_queue_command (debugger
, buff
, FALSE
, FALSE
, debugger_remove_breakpoint_finish
, callback
, user_data
);
2300 debugger_list_breakpoint_finish (Debugger
*debugger
, const GDBMIValue
*mi_results
, const GList
*cli_results
, GError
*error
)
2302 IAnjutaDebuggerCallback callback
= debugger
->priv
->current_cmd
.callback
;
2303 gpointer user_data
= debugger
->priv
->current_cmd
.user_data
;
2304 IAnjutaDebuggerBreakpointItem
* bp
;
2305 const GDBMIValue
*table
;
2308 if ((error
!= NULL
) || (mi_results
== NULL
))
2310 /* Call callback in all case (useful for enable that doesn't return
2312 if (callback
!= NULL
)
2313 callback (NULL
, user_data
, error
);
2316 table
= gdbmi_value_hash_lookup (mi_results
, "BreakpointTable");
2319 table
= gdbmi_value_hash_lookup (table
, "body");
2325 for (i
= 0; i
< gdbmi_value_get_size (table
); i
++)
2327 const GDBMIValue
*brkpnt
;
2329 bp
= g_new0 (IAnjutaDebuggerBreakpointItem
, 1);
2331 brkpnt
= gdbmi_value_list_get_nth (table
, i
);
2332 parse_breakpoint(bp
, brkpnt
);
2333 list
= g_list_prepend (list
, bp
);
2338 /* Call callback in all case (useful for enable that doesn't return
2340 if (callback
!= NULL
)
2342 list
= g_list_reverse (list
);
2343 callback (list
, user_data
, error
);
2346 g_list_foreach (list
, (GFunc
)g_free
, NULL
);
2351 debugger_list_breakpoint (Debugger
*debugger
, IAnjutaDebuggerCallback callback
, gpointer user_data
)
2353 DEBUG_PRINT ("In function: debugger_list_breakpoint()");
2355 g_return_if_fail (IS_DEBUGGER (debugger
));
2357 debugger_queue_command (debugger
, "-break-list", FALSE
, FALSE
, debugger_list_breakpoint_finish
, callback
, user_data
);
2361 debugger_print_finish (Debugger
*debugger
, const GDBMIValue
*mi_results
, const GList
*cli_results
, GError
*error
)
2366 IAnjutaDebuggerCallback callback
= debugger
->priv
->current_cmd
.callback
;
2367 gpointer user_data
= debugger
->priv
->current_cmd
.user_data
;
2370 list
= gdb_util_remove_blank_lines (cli_results
);
2371 if (g_list_length (list
) < 1)
2377 tmp
= strchr ((gchar
*) list
->data
, '=');
2381 ptr
= g_strdup (tmp
);
2382 for (node
= list
? list
->next
: NULL
; node
!= NULL
; node
= node
->next
)
2385 ptr
= g_strconcat (tmp
, (gchar
*) node
->data
, NULL
);
2390 callback (ptr
, user_data
, NULL
);
2395 debugger_print (Debugger
*debugger
, const gchar
* variable
, IAnjutaDebuggerCallback callback
, gpointer user_data
)
2399 DEBUG_PRINT ("In function: debugger_print()");
2401 g_return_if_fail (IS_DEBUGGER (debugger
));
2403 buff
= g_strdup_printf ("print %s", variable
);
2404 debugger_queue_command (debugger
, buff
, TRUE
, FALSE
, debugger_print_finish
, callback
, user_data
);
2409 debugger_evaluate_finish (Debugger
*debugger
, const GDBMIValue
*mi_results
, const GList
*cli_results
, GError
*error
)
2412 const GDBMIValue
*value
= NULL
;
2413 IAnjutaDebuggerCallback callback
= debugger
->priv
->current_cmd
.callback
;
2414 gpointer user_data
= debugger
->priv
->current_cmd
.user_data
;
2417 value
= gdbmi_value_hash_lookup (mi_results
, "value");
2419 /* Call user function */
2420 if (callback
!= NULL
)
2421 callback (value
== NULL
? "?" : (char *)gdbmi_value_literal_get (value
), user_data
, NULL
);
2425 debugger_evaluate (Debugger
*debugger
, const gchar
* name
, IAnjutaDebuggerCallback callback
, gpointer user_data
)
2428 DEBUG_PRINT ("In function: debugger_add_watch()");
2430 g_return_if_fail (IS_DEBUGGER (debugger
));
2432 buff
= g_strdup_printf ("-data-evaluate-expression %s", name
);
2433 debugger_queue_command (debugger
, buff
, TRUE
, FALSE
, debugger_evaluate_finish
, callback
, user_data
);
2438 debugger_list_local_finish (Debugger
*debugger
, const GDBMIValue
*mi_results
, const GList
*cli_results
, GError
*error
)
2441 const GDBMIValue
*local
, *var
, *frame
, *args
, *stack
;
2445 IAnjutaDebuggerCallback callback
= debugger
->priv
->current_cmd
.callback
;
2446 gpointer user_data
= debugger
->priv
->current_cmd
.user_data
;
2451 stack
= gdbmi_value_hash_lookup (mi_results
, "stack-args");
2454 frame
= gdbmi_value_list_get_nth (stack
, 0);
2457 args
= gdbmi_value_hash_lookup (frame
, "args");
2460 for (i
= 0; i
< gdbmi_value_get_size (args
); i
++)
2462 var
= gdbmi_value_list_get_nth (args
, i
);
2465 name
= gdbmi_value_literal_get (var
);
2466 list
= g_list_prepend (list
, (gchar
*)name
);
2474 /* List local variables */
2475 local
= gdbmi_value_hash_lookup (mi_results
, "locals");
2478 for (i
= 0; i
< gdbmi_value_get_size (local
); i
++)
2480 var
= gdbmi_value_list_get_nth (local
, i
);
2483 name
= gdbmi_value_literal_get (var
);
2484 list
= g_list_prepend (list
, (gchar
*)name
);
2488 list
= g_list_reverse (list
);
2489 callback (list
, user_data
, NULL
);
2494 debugger_list_local (Debugger
*debugger
, IAnjutaDebuggerCallback callback
, gpointer user_data
)
2497 DEBUG_PRINT ("In function: debugger_list_local()");
2499 g_return_if_fail (IS_DEBUGGER (debugger
));
2501 buff
= g_strdup_printf("-stack-list-arguments 0 %d %d", debugger
->priv
->current_frame
, debugger
->priv
->current_frame
);
2502 debugger_queue_command (debugger
, buff
, TRUE
, TRUE
, NULL
, NULL
, NULL
);
2504 debugger_queue_command (debugger
, "-stack-list-locals 0", TRUE
, FALSE
, debugger_list_local_finish
, callback
, user_data
);
2508 debugger_list_argument_finish (Debugger
*debugger
, const GDBMIValue
*mi_results
, const GList
*cli_results
, GError
*error
)
2511 const GDBMIValue
*frame
, *var
, *args
, *stack
;
2515 IAnjutaDebuggerCallback callback
= debugger
->priv
->current_cmd
.callback
;
2516 gpointer user_data
= debugger
->priv
->current_cmd
.user_data
;
2521 stack
= gdbmi_value_hash_lookup (mi_results
, "stack-args");
2524 frame
= gdbmi_value_list_get_nth (stack
, 0);
2527 args
= gdbmi_value_hash_lookup (frame
, "args");
2533 for (i
= 0; i
< gdbmi_value_get_size (args
); i
++)
2535 var
= gdbmi_value_list_get_nth (args
, i
);
2538 name
= gdbmi_value_literal_get (var
);
2539 list
= g_list_prepend (list
, (gchar
*)name
);
2543 list
= g_list_reverse (list
);
2544 callback (list
, user_data
, NULL
);
2549 debugger_list_argument (Debugger
*debugger
, IAnjutaDebuggerCallback callback
, gpointer user_data
)
2553 DEBUG_PRINT ("In function: debugger_list_argument()");
2555 g_return_if_fail (IS_DEBUGGER (debugger
));
2557 buff
= g_strdup_printf("-stack-list-arguments 0 %d %d", debugger
->priv
->current_frame
, debugger
->priv
->current_frame
);
2558 debugger_queue_command (debugger
, buff
, TRUE
, FALSE
, debugger_list_argument_finish
, callback
, user_data
);
2563 debugger_info_finish (Debugger
*debugger
, const GDBMIValue
*mi_results
, const GList
*cli_results
, GError
*error
)
2566 IAnjutaDebuggerCallback callback
= debugger
->priv
->current_cmd
.callback
;
2567 gpointer user_data
= debugger
->priv
->current_cmd
.user_data
;
2569 if (callback
!= NULL
)
2570 callback ((GList
*)cli_results
, user_data
, NULL
);
2574 debugger_info_frame (Debugger
*debugger
, guint frame
, IAnjutaDebuggerCallback callback
, gpointer user_data
)
2578 DEBUG_PRINT ("In function: debugger_info_frame()");
2580 g_return_if_fail (IS_DEBUGGER (debugger
));
2584 buff
= g_strdup_printf("info frame");
2588 buff
= g_strdup_printf ("info frame %d", frame
);
2590 debugger_queue_command (debugger
, buff
, TRUE
, FALSE
, (DebuggerParserFunc
)debugger_info_finish
, callback
, user_data
);
2595 debugger_info_signal (Debugger
*debugger
, IAnjutaDebuggerCallback callback
, gpointer user_data
)
2597 DEBUG_PRINT ("In function: debugger_info_signal()");
2599 g_return_if_fail (IS_DEBUGGER (debugger
));
2601 debugger_queue_command (debugger
, "info signals", TRUE
, FALSE
, (DebuggerParserFunc
)debugger_info_finish
, callback
, user_data
);
2605 debugger_info_sharedlib (Debugger
*debugger
, IAnjutaDebuggerCallback callback
, gpointer user_data
)
2609 DEBUG_PRINT ("In function: debugger_info_sharedlib()");
2611 g_return_if_fail (IS_DEBUGGER (debugger
));
2613 buff
= g_strdup_printf ("info sharedlib");
2614 debugger_queue_command (debugger
, buff
, TRUE
, FALSE
, (DebuggerParserFunc
)debugger_info_finish
, callback
, user_data
); g_free (buff
);
2618 debugger_info_args (Debugger
*debugger
, IAnjutaDebuggerCallback callback
, gpointer user_data
)
2620 DEBUG_PRINT ("In function: debugger_info_args()");
2622 g_return_if_fail (IS_DEBUGGER (debugger
));
2624 debugger_queue_command (debugger
, "info args", TRUE
, FALSE
, (DebuggerParserFunc
)debugger_info_finish
, callback
, user_data
);
2628 debugger_info_target (Debugger
*debugger
, IAnjutaDebuggerCallback callback
, gpointer user_data
)
2630 DEBUG_PRINT ("In function: debugger_info_target()");
2632 g_return_if_fail (IS_DEBUGGER (debugger
));
2634 debugger_queue_command (debugger
, "info target", TRUE
, FALSE
, (DebuggerParserFunc
)debugger_info_finish
, callback
, user_data
);
2638 debugger_info_program (Debugger
*debugger
, IAnjutaDebuggerCallback callback
, gpointer user_data
)
2640 DEBUG_PRINT ("In function: debugger_info_program()");
2642 g_return_if_fail (IS_DEBUGGER (debugger
));
2644 debugger_queue_command (debugger
, "info program", TRUE
, FALSE
, (DebuggerParserFunc
)debugger_info_finish
, callback
, user_data
);
2648 debugger_info_udot (Debugger
*debugger
, IAnjutaDebuggerCallback callback
, gpointer user_data
)
2650 DEBUG_PRINT ("In function: debugger_info_udot()");
2652 g_return_if_fail (IS_DEBUGGER (debugger
));
2654 debugger_queue_command (debugger
, "info udot", TRUE
, FALSE
, (DebuggerParserFunc
)debugger_info_finish
, callback
, user_data
);
2658 debugger_info_variables (Debugger
*debugger
, IAnjutaDebuggerCallback callback
, gpointer user_data
)
2660 DEBUG_PRINT ("In function: debugger_info_variables()");
2662 g_return_if_fail (IS_DEBUGGER (debugger
));
2664 debugger_queue_command (debugger
, "info variables", TRUE
, FALSE
, (DebuggerParserFunc
)debugger_info_finish
, callback
, user_data
);
2668 debugger_read_memory_finish (Debugger
*debugger
, const GDBMIValue
*mi_results
, const GList
*cli_results
, GError
*error
)
2671 const GDBMIValue
*literal
;
2672 const GDBMIValue
*mem
;
2679 IAnjutaDebuggerCallback callback
= debugger
->priv
->current_cmd
.callback
;
2680 gpointer user_data
= debugger
->priv
->current_cmd
.user_data
;
2681 IAnjutaDebuggerMemoryBlock read
= {0,};
2683 literal
= gdbmi_value_hash_lookup (mi_results
, "total-bytes");
2688 len
= strtoul (gdbmi_value_literal_get (literal
), NULL
, 10);
2689 data
= g_new (gchar
, len
* 2);
2690 memset (data
+ len
, 0, len
);
2692 literal
= gdbmi_value_hash_lookup (mi_results
, "addr");
2693 address
= strtoul (gdbmi_value_literal_get (literal
), NULL
, 0);
2697 mem
= gdbmi_value_hash_lookup (mi_results
, "memory");
2700 mem
= gdbmi_value_list_get_nth (mem
, 0);
2703 mem
= gdbmi_value_hash_lookup (mem
, "data");
2706 size
= gdbmi_value_get_size (mem
);
2711 if (size
< len
) len
= size
;
2712 for (i
= 0; i
< len
; i
++)
2714 literal
= gdbmi_value_list_get_nth (mem
, i
);
2718 value
= gdbmi_value_literal_get (literal
);
2719 *ptr
= strtoul (value
, &endptr
, 16);
2720 if ((*value
!= '\0') && (*endptr
== '\0'))
2728 read
.address
= address
;
2731 callback (&read
, user_data
, NULL
);
2737 callback (NULL
, user_data
, NULL
);
2742 debugger_inspect_memory (Debugger
*debugger
, gulong address
, guint length
, IAnjutaDebuggerCallback callback
, gpointer user_data
)
2746 DEBUG_PRINT ("In function: debugger_inspect_memory()");
2748 g_return_if_fail (IS_DEBUGGER (debugger
));
2750 buff
= g_strdup_printf ("-data-read-memory 0x%lx x 1 1 %d", address
, length
);
2751 debugger_queue_command (debugger
, buff
, FALSE
, FALSE
, debugger_read_memory_finish
, callback
, user_data
);
2756 debugger_disassemble_finish (Debugger
*debugger
, const GDBMIValue
*mi_results
, const GList
*cli_results
, GError
*error
)
2759 const GDBMIValue
*literal
;
2760 const GDBMIValue
*line
;
2761 const GDBMIValue
*mem
;
2764 IAnjutaDebuggerCallback callback
= debugger
->priv
->current_cmd
.callback
;
2765 gpointer user_data
= debugger
->priv
->current_cmd
.user_data
;
2766 IAnjutaDebuggerInstructionDisassembly
*read
= NULL
;
2771 callback (NULL
, user_data
, error
);
2777 mem
= gdbmi_value_hash_lookup (mi_results
, "asm_insns");
2782 size
= gdbmi_value_get_size (mem
);
2783 read
= (IAnjutaDebuggerInstructionDisassembly
*)g_malloc0(sizeof (IAnjutaDebuggerInstructionDisassembly
) + sizeof(IAnjutaDebuggerInstructionALine
) * size
);
2786 for (i
= 0; i
< size
; i
++)
2788 line
= gdbmi_value_list_get_nth (mem
, i
);
2792 literal
= gdbmi_value_hash_lookup (line
, "address");
2795 value
= gdbmi_value_literal_get (literal
);
2796 read
->data
[i
].address
= strtoul (value
, NULL
, 0);
2799 /* Get label if one exist */
2800 literal
= gdbmi_value_hash_lookup (line
, "offset");
2803 value
= gdbmi_value_literal_get (literal
);
2804 if ((value
!= NULL
) && (strtoul (value
, NULL
, 0) == 0))
2806 literal
= gdbmi_value_hash_lookup (line
, "func-name");
2809 read
->data
[i
].label
= gdbmi_value_literal_get (literal
);
2816 /* Get disassembly line */
2817 literal
= gdbmi_value_hash_lookup (line
, "inst");
2820 read
->data
[i
].text
= gdbmi_value_literal_get (literal
);
2825 /* Remove last line to mark end */
2826 read
->data
[i
- 1].text
= NULL
;
2828 callback (read
, user_data
, NULL
);
2834 callback (NULL
, user_data
, NULL
);
2839 debugger_disassemble (Debugger
*debugger
, gulong address
, guint length
, IAnjutaDebuggerCallback callback
, gpointer user_data
)
2844 DEBUG_PRINT ("In function: debugger_disassemble()");
2846 g_return_if_fail (IS_DEBUGGER (debugger
));
2849 /* Handle overflow */
2850 end
= (address
+ length
< address
) ? G_MAXULONG
: address
+ length
;
2851 buff
= g_strdup_printf ("-data-disassemble -s 0x%lx -e 0x%lx -- 0", address
, end
);
2852 debugger_queue_command (debugger
, buff
, FALSE
, FALSE
, debugger_disassemble_finish
, callback
, user_data
);
2857 parse_frame (IAnjutaDebuggerFrame
*frame
, const GDBMIValue
*frame_hash
)
2859 const GDBMIValue
*literal
;
2861 literal
= gdbmi_value_hash_lookup (frame_hash
, "level");
2863 frame
->level
= strtoul (gdbmi_value_literal_get (literal
), NULL
, 10);
2867 literal
= gdbmi_value_hash_lookup (frame_hash
, "fullname");
2868 if (literal
== NULL
)
2869 literal
= gdbmi_value_hash_lookup (frame_hash
, "file");
2871 frame
->file
= (gchar
*)gdbmi_value_literal_get (literal
);
2875 literal
= gdbmi_value_hash_lookup (frame_hash
, "line");
2877 frame
->line
= strtoul (gdbmi_value_literal_get (literal
), NULL
, 10);
2881 literal
= gdbmi_value_hash_lookup (frame_hash
, "func");
2883 frame
->function
= (gchar
*)gdbmi_value_literal_get (literal
);
2885 frame
->function
= NULL
;
2887 literal
= gdbmi_value_hash_lookup (frame_hash
, "from");
2889 frame
->library
= (gchar
*)gdbmi_value_literal_get (literal
);
2891 frame
->library
= NULL
;
2893 literal
= gdbmi_value_hash_lookup (frame_hash
, "addr");
2895 frame
->address
= strtoul (gdbmi_value_literal_get (literal
), NULL
, 16);
2903 add_frame (const GDBMIValue
*frame_hash
, GdbGListPacket
* pack
)
2905 IAnjutaDebuggerFrame
* frame
;
2907 frame
= g_new0 (IAnjutaDebuggerFrame
, 1);
2908 pack
->list
= g_list_prepend (pack
->list
, frame
);
2910 frame
->thread
= pack
->tag
;
2911 parse_frame (frame
, frame_hash
);
2915 set_func_args (const GDBMIValue
*frame_hash
, GList
** node
)
2918 const GDBMIValue
*literal
, *args_list
, *arg_hash
;
2921 IAnjutaDebuggerFrame
* frame
;
2923 literal
= gdbmi_value_hash_lookup (frame_hash
, "level");
2927 level
= gdbmi_value_literal_get (literal
);
2931 frame
= (IAnjutaDebuggerFrame
*)(*node
)->data
;
2933 args_list
= gdbmi_value_hash_lookup (frame_hash
, "args");
2936 args_str
= g_string_new ("(");
2937 for (i
= 0; i
< gdbmi_value_get_size (args_list
); i
++)
2939 const gchar
*name
, *value
;
2941 arg_hash
= gdbmi_value_list_get_nth (args_list
, i
);
2945 literal
= gdbmi_value_hash_lookup (arg_hash
, "name");
2948 name
= gdbmi_value_literal_get (literal
);
2952 literal
= gdbmi_value_hash_lookup (arg_hash
, "value");
2955 value
= gdbmi_value_literal_get (literal
);
2958 args_str
= g_string_append (args_str
, name
);
2959 args_str
= g_string_append (args_str
, "=");
2960 args_str
= g_string_append (args_str
, value
);
2961 if (i
< (gdbmi_value_get_size (args_list
) - 1))
2962 args_str
= g_string_append (args_str
, ", ");
2964 args_str
= g_string_append (args_str
, ")");
2965 frame
->args
= args_str
->str
;
2966 g_string_free (args_str
, FALSE
);
2968 *node
= g_list_next (*node
);
2972 debugger_stack_finish (Debugger
*debugger
, const GDBMIValue
*mi_results
, const GList
*cli_results
, GError
*error
)
2975 GdbGListPacket pack
= {NULL
, 0};
2977 const GDBMIValue
*stack_list
;
2978 IAnjutaDebuggerCallback callback
= debugger
->priv
->current_cmd
.callback
;
2979 gpointer user_data
= debugger
->priv
->current_cmd
.user_data
;
2984 stack_list
= gdbmi_value_hash_lookup (mi_results
, "stack");
2987 pack
.tag
= debugger
->priv
->current_thread
;
2988 gdbmi_value_foreach (stack_list
, (GFunc
)add_frame
, &pack
);
2993 pack
.list
= g_list_reverse (pack
.list
);
2994 node
= g_list_first (pack
.list
);
2995 stack_list
= gdbmi_value_hash_lookup (mi_results
, "stack-args");
2997 gdbmi_value_foreach (stack_list
, (GFunc
)set_func_args
, &node
);
2999 // Call call back function
3000 if (callback
!= NULL
)
3001 callback (pack
.list
, user_data
, NULL
);
3004 for (node
= g_list_first (pack
.list
); node
!= NULL
; node
= g_list_next (node
))
3006 g_free ((gchar
*)((IAnjutaDebuggerFrame
*)node
->data
)->args
);
3007 g_free (node
->data
);
3010 g_list_free (pack
.list
);
3014 // Call call back function
3015 if (callback
!= NULL
)
3016 callback (NULL
, user_data
, NULL
);
3021 debugger_list_frame (Debugger
*debugger
, IAnjutaDebuggerCallback callback
, gpointer user_data
)
3023 DEBUG_PRINT ("In function: debugger_list_frame()");
3025 g_return_if_fail (IS_DEBUGGER (debugger
));
3027 debugger_queue_command (debugger
, "-stack-list-frames", TRUE
, TRUE
, NULL
, NULL
, NULL
);
3028 debugger_queue_command (debugger
, "-stack-list-arguments 1", TRUE
, FALSE
, debugger_stack_finish
, callback
, user_data
);
3032 *---------------------------------------------------------------------------*/
3035 debugger_set_thread_finish (Debugger
*debugger
, const GDBMIValue
*mi_results
, const GList
*cli_results
, GError
*error
)
3037 const GDBMIValue
*literal
;
3040 if (mi_results
== NULL
) return;
3042 literal
= gdbmi_value_hash_lookup (mi_results
, "new-thread-id");
3043 if (literal
== NULL
) return;
3045 id
= strtoul (gdbmi_value_literal_get (literal
), NULL
, 10);
3046 if (id
== 0) return;
3048 debugger
->priv
->current_thread
= id
;
3049 g_signal_emit_by_name (debugger
->priv
->instance
, "frame-changed", 0, debugger
->priv
->current_thread
);
3055 debugger_set_thread (Debugger
*debugger
, gint thread
)
3059 DEBUG_PRINT ("In function: debugger_set_thread()");
3061 g_return_if_fail (IS_DEBUGGER (debugger
));
3063 buff
= g_strdup_printf ("-thread-select %d", thread
);
3065 debugger_queue_command (debugger
, buff
, FALSE
, FALSE
, (DebuggerParserFunc
)debugger_set_thread_finish
, NULL
, NULL
);
3070 add_thread_id (const GDBMIValue
*thread_hash
, GList
** list
)
3072 IAnjutaDebuggerFrame
* frame
;
3075 thread
= strtoul (gdbmi_value_literal_get (thread_hash
), NULL
, 10);
3076 if (thread
== 0) return;
3078 frame
= g_new0 (IAnjutaDebuggerFrame
, 1);
3079 *list
= g_list_prepend (*list
, frame
);
3081 frame
->thread
= thread
;
3085 debugger_list_thread_finish (Debugger
*debugger
, const GDBMIValue
*mi_results
, const GList
*cli_results
, GError
*error
)
3088 const GDBMIValue
*id_list
;
3089 gpointer user_data
= debugger
->priv
->current_cmd
.user_data
;
3090 IAnjutaDebuggerCallback callback
= debugger
->priv
->current_cmd
.callback
;
3091 GList
* thread_list
= NULL
;
3095 if (mi_results
== NULL
) break;
3097 id_list
= gdbmi_value_hash_lookup (mi_results
, "thread-ids");
3098 if (id_list
== NULL
) break;
3100 gdbmi_value_foreach (id_list
, (GFunc
)add_thread_id
, &thread_list
);
3101 thread_list
= g_list_reverse (thread_list
);
3105 if (callback
!= NULL
)
3106 callback (thread_list
, user_data
, error
);
3108 if (thread_list
!= NULL
)
3110 g_list_foreach (thread_list
, (GFunc
)g_free
, NULL
);
3111 g_list_free (thread_list
);
3116 debugger_list_thread (Debugger
*debugger
, IAnjutaDebuggerCallback callback
, gpointer user_data
)
3118 DEBUG_PRINT ("In function: debugger_list_thread()");
3120 g_return_if_fail (IS_DEBUGGER (debugger
));
3122 debugger_queue_command (debugger
, "-thread-list-ids", TRUE
, FALSE
, debugger_list_thread_finish
, callback
, user_data
);
3126 debugger_info_set_thread_finish (Debugger
*debugger
, const GDBMIValue
*mi_results
, const GList
*cli_results
, GError
*error
)
3128 const GDBMIValue
*literal
;
3131 if (mi_results
== NULL
) return;
3133 literal
= gdbmi_value_hash_lookup (mi_results
, "new-thread-id");
3134 if (literal
== NULL
) return;
3136 id
= strtoul (gdbmi_value_literal_get (literal
), NULL
, 10);
3137 if (id
== 0) return;
3139 debugger
->priv
->current_thread
= id
;
3140 /* Do not emit a signal notification as the current thread will
3141 * be restored when needed */
3147 debugger_info_thread_finish (Debugger
*debugger
, const GDBMIValue
*mi_results
, const GList
*cli_results
, GError
*error
)
3149 const GDBMIValue
*frame
;
3150 IAnjutaDebuggerFrame top_frame
;
3151 IAnjutaDebuggerFrame
*top
;
3152 IAnjutaDebuggerCallback callback
= debugger
->priv
->current_cmd
.callback
;
3153 gpointer user_data
= debugger
->priv
->current_cmd
.user_data
;
3157 DEBUG_PRINT("look for stack %p", mi_results
);
3158 if (mi_results
== NULL
) break;
3160 frame
= gdbmi_value_hash_lookup (mi_results
, "stack");
3161 if (frame
== NULL
) break;
3163 DEBUG_PRINT("get stack");
3165 frame
= gdbmi_value_list_get_nth (frame
, 0);
3166 if (frame
== NULL
) break;
3168 DEBUG_PRINT("get nth element");
3170 /*frame = gdbmi_value_hash_lookup (frame, "frame");
3171 DEBUG_PRINT("get frame %p", frame);
3172 if (frame == NULL) break;*/
3174 DEBUG_PRINT("get frame");
3177 top
->thread
= debugger
->priv
->current_thread
;
3179 parse_frame (top
, frame
);
3183 if (callback
!= NULL
)
3184 callback (top
, user_data
, error
);
3190 debugger_info_thread (Debugger
*debugger
, gint thread
, IAnjutaDebuggerCallback callback
, gpointer user_data
)
3195 DEBUG_PRINT ("In function: debugger_info_thread()");
3197 g_return_if_fail (IS_DEBUGGER (debugger
));
3199 orig_thread
= debugger
->priv
->current_thread
;
3200 buff
= g_strdup_printf ("-thread-select %d", thread
);
3201 debugger_queue_command (debugger
, buff
, FALSE
, FALSE
, (DebuggerParserFunc
)debugger_info_set_thread_finish
, NULL
, NULL
);
3203 debugger_queue_command (debugger
, "-stack-list-frames 0 0", FALSE
, FALSE
, (DebuggerParserFunc
)debugger_info_thread_finish
, callback
, user_data
);
3205 buff
= g_strdup_printf ("-thread-select %d", orig_thread
);
3206 debugger_queue_command (debugger
, buff
, FALSE
, FALSE
, (DebuggerParserFunc
)debugger_info_set_thread_finish
, NULL
, NULL
);
3211 add_register_name (const GDBMIValue
*reg_literal
, GList
** list
)
3213 IAnjutaDebuggerRegisterData
* reg
;
3214 GList
*prev
= *list
;
3216 reg
= g_new0 (IAnjutaDebuggerRegisterData
, 1);
3217 *list
= g_list_prepend (prev
, reg
);
3218 reg
->name
= (gchar
*)gdbmi_value_literal_get (reg_literal
);
3219 reg
->num
= prev
== NULL
? 0 : ((IAnjutaDebuggerRegisterData
*)prev
->data
)->num
+ 1;
3223 add_register_value (const GDBMIValue
*reg_hash
, GList
** list
)
3225 const GDBMIValue
*literal
;
3227 IAnjutaDebuggerRegisterData
* reg
;
3229 GList
* prev
= *list
;
3231 literal
= gdbmi_value_hash_lookup (reg_hash
, "number");
3234 val
= gdbmi_value_literal_get (literal
);
3235 num
= strtoul (val
, NULL
, 10);
3237 literal
= gdbmi_value_hash_lookup (reg_hash
, "value");
3241 reg
= g_new0 (IAnjutaDebuggerRegisterData
, 1);
3242 *list
= g_list_prepend (prev
, reg
);
3244 reg
->value
= (gchar
*)gdbmi_value_literal_get (literal
);
3248 debugger_register_name_finish (Debugger
*debugger
, const GDBMIValue
*mi_results
, const GList
*cli_results
, GError
*error
)
3253 const GDBMIValue
*reg_list
;
3254 IAnjutaDebuggerCallback callback
= debugger
->priv
->current_cmd
.callback
;
3255 gpointer user_data
= debugger
->priv
->current_cmd
.user_data
;
3260 reg_list
= gdbmi_value_hash_lookup (mi_results
, "register-names");
3262 gdbmi_value_foreach (reg_list
, (GFunc
)add_register_name
, &list
);
3263 list
= g_list_reverse (list
);
3265 // Call call back function
3266 if (callback
!= NULL
)
3267 callback (list
, user_data
, NULL
);
3270 for (node
= g_list_first (list
); node
!= NULL
; node
= g_list_next (node
))
3272 g_free (node
->data
);
3278 debugger_register_value_finish (Debugger
*debugger
, const GDBMIValue
*mi_results
, const GList
*cli_results
, GError
*error
)
3283 const GDBMIValue
*reg_list
;
3284 IAnjutaDebuggerCallback callback
= debugger
->priv
->current_cmd
.callback
;
3285 gpointer user_data
= debugger
->priv
->current_cmd
.user_data
;
3290 reg_list
= gdbmi_value_hash_lookup (mi_results
, "register-values");
3292 gdbmi_value_foreach (reg_list
, (GFunc
)add_register_value
, &list
);
3293 list
= g_list_reverse (list
);
3295 // Call call back function
3296 if (callback
!= NULL
)
3297 callback (list
, user_data
, NULL
);
3300 for (node
= g_list_first (list
); node
!= NULL
; node
= g_list_next (node
))
3302 g_free (node
->data
);
3308 debugger_list_register (Debugger
*debugger
, IAnjutaDebuggerCallback callback
, gpointer user_data
)
3310 DEBUG_PRINT ("In function: debugger_list_register()");
3312 g_return_if_fail (IS_DEBUGGER (debugger
));
3314 debugger_queue_command (debugger
, "-data-list-register-names", TRUE
, FALSE
, debugger_register_name_finish
, callback
, user_data
);
3318 debugger_update_register (Debugger
*debugger
, IAnjutaDebuggerCallback callback
, gpointer user_data
)
3320 DEBUG_PRINT ("In function: debugger_update_register()");
3322 g_return_if_fail (IS_DEBUGGER (debugger
));
3324 debugger_queue_command (debugger
, "-data-list-register-values r", TRUE
, FALSE
, (DebuggerParserFunc
)debugger_register_value_finish
, callback
, user_data
);
3328 debugger_write_register (Debugger
*debugger
, const gchar
*name
, const gchar
*value
)
3332 DEBUG_PRINT ("In function: debugger_write_register()");
3334 g_return_if_fail (IS_DEBUGGER (debugger
));
3336 buf
= g_strdup_printf ("-data-evaluate-expression \"$%s=%s\"", name
, value
);
3337 debugger_queue_command (debugger
, buf
, TRUE
, FALSE
, NULL
, NULL
, NULL
);
3342 debugger_set_frame_finish (Debugger
*debugger
, const GDBMIValue
*mi_results
, const GList
*cli_results
, GError
*error
)
3345 guint frame
= (guint
)debugger
->priv
->current_cmd
.user_data
;
3346 debugger
->priv
->current_frame
= frame
;
3348 g_signal_emit_by_name (debugger
->priv
->instance
, "frame-changed", frame
, debugger
->priv
->current_thread
);
3352 debugger_set_frame (Debugger
*debugger
, guint frame
)
3356 DEBUG_PRINT ("In function: debugger_set_frame()");
3358 g_return_if_fail (IS_DEBUGGER (debugger
));
3360 buff
= g_strdup_printf ("-stack-select-frame %d", frame
);
3362 debugger_queue_command (debugger
, buff
, FALSE
, FALSE
, (DebuggerParserFunc
)debugger_set_frame_finish
, NULL
, (gpointer
)frame
);
3367 debugger_set_log (Debugger
*debugger
, IAnjutaMessageView
*log
)
3369 debugger
->priv
->log
= log
;
3372 /* Variable objects functions
3373 *---------------------------------------------------------------------------*/
3376 debugger_delete_variable (Debugger
*debugger
, const gchar
* name
)
3380 DEBUG_PRINT ("In function: delete_variable()");
3382 g_return_if_fail (IS_DEBUGGER (debugger
));
3384 buff
= g_strdup_printf ("-var-delete %s", name
);
3385 debugger_queue_command (debugger
, buff
, FALSE
, FALSE
, NULL
, NULL
, NULL
);
3390 gdb_var_evaluate_expression (Debugger
*debugger
,
3391 const GDBMIValue
*mi_results
, const GList
*cli_results
,
3394 const gchar
*value
= NULL
;
3395 IAnjutaDebuggerCallback callback
= debugger
->priv
->current_cmd
.callback
;
3396 gpointer user_data
= debugger
->priv
->current_cmd
.user_data
;
3398 if (mi_results
!= NULL
)
3400 const GDBMIValue
*const gdbmi_value
=
3401 gdbmi_value_hash_lookup (mi_results
, "value");
3403 if (gdbmi_value
!= NULL
)
3404 value
= gdbmi_value_literal_get (gdbmi_value
);
3406 callback ((const gpointer
)value
, user_data
, NULL
);
3410 debugger_evaluate_variable (Debugger
*debugger
, const gchar
* name
, IAnjutaDebuggerCallback callback
, gpointer user_data
)
3414 DEBUG_PRINT ("In function: evaluate_variable()");
3416 g_return_if_fail (IS_DEBUGGER (debugger
));
3418 buff
= g_strdup_printf ("-var-evaluate-expression %s", name
);
3419 debugger_queue_command (debugger
, buff
, FALSE
, FALSE
, gdb_var_evaluate_expression
, callback
, user_data
);
3424 debugger_assign_variable (Debugger
*debugger
, const gchar
* name
, const gchar
*value
)
3428 DEBUG_PRINT ("In function: assign_variable()");
3430 g_return_if_fail (IS_DEBUGGER (debugger
));
3432 buff
= g_strdup_printf ("-var-assign %s %s", name
, value
);
3433 debugger_queue_command (debugger
, buff
, FALSE
, FALSE
, NULL
, NULL
, NULL
);
3438 gdb_var_list_children (Debugger
*debugger
,
3439 const GDBMIValue
*mi_results
, const GList
*cli_results
,
3443 IAnjutaDebuggerCallback callback
= debugger
->priv
->current_cmd
.callback
;
3444 gpointer user_data
= debugger
->priv
->current_cmd
.user_data
;
3446 if (mi_results
!= NULL
)
3448 const GDBMIValue
*literal
;
3449 const GDBMIValue
*children
;
3453 literal
= gdbmi_value_hash_lookup (mi_results
, "numchild");
3456 numchild
= strtoul(gdbmi_value_literal_get (literal
), NULL
, 0);
3457 children
= gdbmi_value_hash_lookup (mi_results
, "children");
3459 for(i
= 0 ; i
< numchild
; ++i
)
3461 const GDBMIValue
*const gdbmi_chl
=
3462 gdbmi_value_list_get_nth (children
, i
);
3463 IAnjutaDebuggerVariableObject
*var
;
3465 var
= g_new0 (IAnjutaDebuggerVariableObject
, 1);
3467 literal
= gdbmi_value_hash_lookup (gdbmi_chl
, "name");
3469 var
->name
= (gchar
*)gdbmi_value_literal_get (literal
);
3471 literal
= gdbmi_value_hash_lookup (gdbmi_chl
, "exp");
3473 var
->expression
= (gchar
*)gdbmi_value_literal_get(literal
);
3475 literal
= gdbmi_value_hash_lookup (gdbmi_chl
, "type");
3477 var
->type
= (gchar
*)gdbmi_value_literal_get(literal
);
3479 literal
= gdbmi_value_hash_lookup (gdbmi_chl
, "value");
3481 var
->value
= (gchar
*)gdbmi_value_literal_get(literal
);
3483 literal
= gdbmi_value_hash_lookup (gdbmi_chl
, "numchild");
3485 var
->children
= strtoul(gdbmi_value_literal_get(literal
), NULL
, 10);
3487 list
= g_list_prepend (list
, var
);
3489 list
= g_list_reverse (list
);
3492 callback (list
, user_data
, NULL
);
3493 g_list_foreach (list
, (GFunc
)g_free
, NULL
);
3497 void debugger_list_variable_children (Debugger
*debugger
, const gchar
* name
, IAnjutaDebuggerCallback callback
, gpointer user_data
)
3501 DEBUG_PRINT ("In function: list_variable_children()");
3503 g_return_if_fail (IS_DEBUGGER (debugger
));
3505 buff
= g_strdup_printf ("-var-list-children --all-values %s", name
);
3506 debugger_queue_command (debugger
, buff
, FALSE
, FALSE
, gdb_var_list_children
, callback
, user_data
);
3511 gdb_var_create (Debugger
*debugger
,
3512 const GDBMIValue
*mi_results
, const GList
*cli_results
,
3515 const GDBMIValue
* result
;
3516 IAnjutaDebuggerVariableObject var
= {0,};
3517 IAnjutaDebuggerCallback callback
= debugger
->priv
->current_cmd
.callback
;
3518 gpointer user_data
= debugger
->priv
->current_cmd
.user_data
;
3520 if ((error
== NULL
) && (mi_results
!= NULL
))
3522 result
= gdbmi_value_hash_lookup (mi_results
, "name");
3523 var
.name
= (gchar
*)gdbmi_value_literal_get(result
);
3525 result
= gdbmi_value_hash_lookup (mi_results
, "type");
3526 var
.type
= (gchar
*)gdbmi_value_literal_get (result
);
3528 result
= gdbmi_value_hash_lookup (mi_results
, "numchild");
3529 var
.children
= strtoul (gdbmi_value_literal_get(result
), NULL
, 10);
3531 callback (&var
, user_data
, error
);
3535 void debugger_create_variable (Debugger
*debugger
, const gchar
* name
, IAnjutaDebuggerCallback callback
, gpointer user_data
)
3539 DEBUG_PRINT ("In function: create_variable()");
3541 g_return_if_fail (IS_DEBUGGER (debugger
));
3543 buff
= g_strdup_printf ("-var-create - * %s", name
);
3544 debugger_queue_command (debugger
, buff
, FALSE
, FALSE
, gdb_var_create
, callback
, user_data
);
3549 gdb_var_update (Debugger
*debugger
,
3550 const GDBMIValue
*mi_results
, const GList
*cli_results
,
3554 glong idx
= 0, changed_count
= 0;
3555 const GDBMIValue
*const gdbmi_changelist
=
3556 gdbmi_value_hash_lookup (mi_results
, "changelist");
3557 IAnjutaDebuggerCallback callback
= debugger
->priv
->current_cmd
.callback
;
3558 gpointer user_data
= debugger
->priv
->current_cmd
.user_data
;
3561 changed_count
= gdbmi_value_get_size (gdbmi_changelist
);
3562 for(; idx
<changed_count
; ++idx
)
3564 const GDBMIValue
*const gdbmi_change
=
3565 gdbmi_value_list_get_nth (gdbmi_changelist
, idx
);
3566 const GDBMIValue
*gdbmi_val
=
3567 gdbmi_value_hash_lookup (gdbmi_change
, "in_scope");
3568 IAnjutaDebuggerVariableObject
*var
;
3570 if(0 != strcmp(gdbmi_value_literal_get(gdbmi_val
), "false"))
3572 gdbmi_val
= gdbmi_value_hash_lookup (gdbmi_change
, "name");
3573 var
= g_new0 (IAnjutaDebuggerVariableObject
, 1);
3574 var
->changed
= TRUE
;
3575 var
->name
= (gchar
*)gdbmi_value_literal_get(gdbmi_val
);
3577 list
= g_list_prepend (list
, var
);
3580 list
= g_list_reverse (list
);
3581 callback (list
, user_data
, NULL
);
3582 g_list_foreach (list
, (GFunc
)g_free
, NULL
);
3586 void debugger_update_variable (Debugger
*debugger
, IAnjutaDebuggerCallback callback
, gpointer user_data
)
3588 DEBUG_PRINT ("In function: update_variable()");
3590 g_return_if_fail (IS_DEBUGGER (debugger
));
3592 debugger_queue_command (debugger
, "-var-update *", FALSE
, FALSE
, gdb_var_update
, callback
, user_data
);
3596 debugger_get_type (void)
3598 static GType obj_type
= 0;
3602 static const GTypeInfo obj_info
=
3604 sizeof (DebuggerClass
),
3605 (GBaseInitFunc
) NULL
,
3606 (GBaseFinalizeFunc
) NULL
,
3607 (GClassInitFunc
) debugger_class_init
,
3608 (GClassFinalizeFunc
) NULL
,
3609 NULL
, /* class_data */
3611 0, /* n_preallocs */
3612 (GInstanceInitFunc
) debugger_instance_init
,
3613 NULL
/* value_table */
3615 obj_type
= g_type_register_static (G_TYPE_OBJECT
,
3616 "Debugger", &obj_info
, 0);
3622 debugger_dispose (GObject
*obj
)
3624 Debugger
*debugger
= DEBUGGER (obj
);
3626 DEBUG_PRINT ("In function: debugger_shutdown()");
3628 /* Do not emit signal when the debugger is destroyed */
3629 debugger
->priv
->instance
= NULL
;
3630 debugger_abort (debugger
);
3632 /* Good Bye message */
3633 if (debugger
->priv
->output_callback
)
3635 debugger
->priv
->output_callback (IANJUTA_DEBUGGER_OUTPUT
,
3636 "Debugging session completed.\n",
3637 debugger
->priv
->output_user_data
);
3640 if (debugger
->priv
->launcher
)
3642 anjuta_launcher_reset (debugger
->priv
->launcher
);
3643 g_object_unref (debugger
->priv
->launcher
);
3644 debugger
->priv
->launcher
= NULL
;
3647 GNOME_CALL_PARENT (G_OBJECT_CLASS
, dispose
, (obj
));
3651 debugger_finalize (GObject
*obj
)
3653 Debugger
*debugger
= DEBUGGER (obj
);
3654 g_string_free (debugger
->priv
->stdo_line
, TRUE
);
3655 g_string_free (debugger
->priv
->stdo_acc
, TRUE
);
3656 g_string_free (debugger
->priv
->stde_line
, TRUE
);
3657 g_free (debugger
->priv
);
3658 GNOME_CALL_PARENT (G_OBJECT_CLASS
, finalize
, (obj
));
3662 debugger_class_init (DebuggerClass
* klass
)
3664 GObjectClass
*object_class
;
3666 g_return_if_fail (klass
!= NULL
);
3667 object_class
= G_OBJECT_CLASS (klass
);
3669 DEBUG_PRINT ("Initializing debugger class");
3671 parent_class
= g_type_class_peek_parent (klass
);
3672 object_class
->dispose
= debugger_dispose
;
3673 object_class
->finalize
= debugger_finalize
;
3679 debugger_signal (const gchar
*sig
, gboolean show_msg
)
3681 /* eg:- "SIGTERM" */
3685 DEBUG_PRINT ("In function: debugger_signal()");
3687 if (debugger_is_active () == FALSE
)
3689 if (debugger
.prog_is_running
== FALSE
)
3691 if (debugger
.child_pid
< 1)
3693 DEBUG_PRINT ("Not sending signal - pid not known\n");
3699 buff
= g_strdup_printf (_("Sending signal %s to the process: %d"),
3700 sig
, (int) debugger
.child_pid
);
3701 gdb_util_append_message (ANJUTA_PLUGIN (debugger
.plugin
), buff
);
3705 if (debugger_is_ready ())
3707 cmd
= g_strconcat ("signal ", sig
, NULL
);
3708 stack_trace_set_frame (debugger
.stack
, 0);
3709 debugger_put_cmd_in_queqe (cmd
, DB_CMD_ALL
, NULL
, NULL
);
3710 debugger_put_cmd_in_queqe ("info program", DB_CMD_NONE
,
3711 on_debugger_update_prog_status
,
3714 debugger_execute_cmd_in_queqe ();
3721 parent
= GTK_WINDOW (ANJUTA_PLUGIN (debugger
.plugin
)->shell
);
3722 status
= gdb_util_kill_process (debugger
.child_pid
, sig
);
3723 if (status
!= 0 && show_msg
)
3724 anjuta_util_dialog_error (parent
,
3725 _("Error whilst signaling the process."));
3730 query_set_cmd (const gchar
*cmd
, gboolean state
)
3733 gchar
*tmp
= g_stpcpy (buffer
, cmd
);
3734 strcpy (tmp
, state
? "on" : "off");
3735 debugger_put_cmd_in_queqe (buffer
, DB_CMD_NONE
, NULL
, NULL
);
3739 query_set_verbose (gboolean state
)
3741 query_set_cmd ("set verbose ", state
);
3745 query_set_print_staticmembers (gboolean state
)
3747 query_set_cmd ("set print static-members ", state
);
3751 query_set_print_pretty (gboolean state
)
3753 query_set_cmd ("set print pretty ", state
);
3756 void debugger_query_evaluate_expr_tip (const gchar
*expr
,
3757 DebuggerCLIFunc parser
, gpointer data
)
3759 query_set_verbose (FALSE
);
3760 query_set_print_staticmembers (FALSE
);
3761 gchar
*printcmd
= g_strconcat ("print ", expr
, NULL
);
3762 debugger_put_cmd_in_queqe (printcmd
, DB_CMD_NONE
, parser
, data
);
3763 query_set_verbose (TRUE
);
3764 query_set_print_staticmembers (TRUE
);
3769 debugger_query_evaluate_expression (const gchar
*expr
, DebuggerFunc parser
,
3772 query_set_print_pretty (TRUE
);
3773 query_set_verbose (FALSE
);
3774 gchar
*printcmd
= g_strconcat ("print ", expr
, NULL
);
3775 debugger_put_cmd_in_queqe (printcmd
, DB_CMD_SE_MESG
| DB_CMD_SE_DIALOG
,
3777 query_set_print_pretty (FALSE
);
3778 query_set_verbose (TRUE
);