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 static gchar
* gdb_quote (const gchar
*unquoted_string
)
157 g_return_val_if_fail (unquoted_string
!= NULL
, NULL
);
160 p
= strpbrk (unquoted_string
, "\"\\");
163 /* No need to quote anything */
164 return g_strdup (unquoted_string
);
170 dest
= g_string_new_len (unquoted_string
, p
- unquoted_string
);
173 g_string_append_c (dest
, '\\');
175 p
= strpbrk (unquoted_string
+ 1, "\"\\");
178 g_string_append (dest
, unquoted_string
);
183 g_string_append_len (dest
, unquoted_string
, p
- unquoted_string
);
186 return g_string_free (dest
, FALSE
);
190 typedef struct _GdbMessageCode GdbMessageCode
;
192 struct _GdbMessageCode
198 const static GdbMessageCode GdbErrorMessage
[] =
199 {{"mi_cmd_var_create: unable to create variable object",
200 IANJUTA_DEBUGGER_UNABLE_TO_CREATE_VARIABLE
},
201 {"Cannot access memory at address ",
202 IANJUTA_DEBUGGER_UNABLE_TO_ACCESS_MEMORY
},
203 {"No source file named ",
204 IANJUTA_DEBUGGER_UNABLE_TO_OPEN_FILE
},
205 {"No executable file specified.",
206 IANJUTA_DEBUGGER_PROGRAM_NOT_FOUND
},
210 gdb_match_error(const gchar
*message
)
212 const GdbMessageCode
* msg
;
214 for (msg
= GdbErrorMessage
; msg
->msg
!= NULL
; msg
++)
216 gsize len
= strlen (msg
->msg
);
218 if (memcmp (msg
->msg
, message
, len
) == 0)
224 return IANJUTA_DEBUGGER_UNKNOWN_ERROR
;
228 debugger_message_view_append (Debugger
*debugger
, IAnjutaMessageViewType type
, const char *message
)
230 guint len
= strlen(message
);
231 gchar buf
[SUMMARY_MAX_LENGTH
];
232 const gchar
* summary
= message
;
233 const gchar
* detail
= "";
236 if (len
> SUMMARY_MAX_LENGTH
)
239 memcpy(buf
, message
, SUMMARY_MAX_LENGTH
- 4);
240 memcpy(buf
+ SUMMARY_MAX_LENGTH
- 4, "...", 4);
245 ianjuta_message_view_append (debugger
->priv
->log
, type
, summary
, detail
, NULL
);
249 debugger_initialize (Debugger
*debugger
)
251 const gchar
* anjuta_log
;
253 DEBUG_PRINT ("In function: debugger_init()");
255 debugger
->priv
= g_new0 (DebuggerPriv
, 1);
257 debugger
->priv
->output_callback
= NULL
;
258 debugger
->priv
->parent_win
= NULL
;
259 debugger
->priv
->search_dirs
= NULL
;
260 debugger
->priv
->launcher
= anjuta_launcher_new ();
262 debugger
->priv
->debugger_is_started
= FALSE
;
263 debugger
->priv
->prog_is_running
= FALSE
;
264 debugger
->priv
->debugger_is_busy
= 0;
265 debugger
->priv
->starting
= FALSE
;
266 debugger
->priv
->terminating
= FALSE
;
267 debugger
->priv
->skip_next_prompt
= FALSE
;
268 debugger
->priv
->command_output_sent
= FALSE
;
270 debugger
->priv
->current_cmd
.cmd
= NULL
;
271 debugger
->priv
->current_cmd
.parser
= NULL
;
273 debugger
->priv
->cmd_queqe
= NULL
;
274 debugger
->priv
->cli_lines
= NULL
;
275 debugger
->priv
->solib_event
= FALSE
;
277 debugger
->priv
->stdo_line
= g_string_sized_new (FILE_BUFFER_SIZE
);
278 g_string_assign (debugger
->priv
->stdo_line
, "");
279 debugger
->priv
->stdo_acc
= g_string_new ("");
281 debugger
->priv
->stde_line
= g_string_sized_new (FILE_BUFFER_SIZE
);
282 g_string_assign (debugger
->priv
->stde_line
, "");
284 debugger
->priv
->post_execution_flag
= DEBUGGER_NONE
;
286 anjuta_log
= g_getenv (ANJUTA_LOG_ENV
);
287 debugger
->priv
->gdb_log
= anjuta_log
&& (atoi(anjuta_log
) > DEBUGGER_LOG_LEVEL
);
291 debugger_instance_init (Debugger
*debugger
)
293 debugger_initialize (debugger
);
297 debugger_new (GtkWindow
*parent_win
, GObject
* instance
)
301 debugger
= g_object_new (DEBUGGER_TYPE
, NULL
);
302 debugger
->priv
->parent_win
= parent_win
;
303 debugger
->priv
->instance
= instance
;
309 debugger_free (Debugger
*debugger
)
311 g_return_if_fail (IS_DEBUGGER (debugger
));
313 g_object_unref (debugger
);
317 debugger_is_ready (Debugger
*debugger
)
319 g_return_val_if_fail (IS_DEBUGGER (debugger
), FALSE
);
320 return !debugger
->priv
->debugger_is_busy
;
324 debugger_program_is_running (Debugger
*debugger
)
326 g_return_val_if_fail (IS_DEBUGGER (debugger
), FALSE
);
327 return debugger
->priv
->prog_is_running
;
331 debugger_program_is_attached (Debugger
*debugger
)
333 g_return_val_if_fail (IS_DEBUGGER (debugger
), FALSE
);
334 return debugger
->priv
->prog_is_attached
;
338 debugger_program_is_loaded (Debugger
*debugger
)
340 g_return_val_if_fail (IS_DEBUGGER (debugger
), FALSE
);
341 return debugger
->priv
->prog_is_loaded
;
345 debugger_log_command (Debugger
*debugger
, const gchar
*command
)
350 if (debugger
->priv
->log
== NULL
) return;
354 str
= g_strdup (command
);
355 len
= strlen (command
);
357 /* Remove trailing carriage return */
358 if (str
[len
- 1] == '\n') str
[len
- 1] = '\0';
360 /* Log only MI command as other are echo */
362 DEBUG_PRINT ("GDB:> %s", str
);
364 if (debugger
->priv
->gdb_log
) g_message ("GDB:> %s", str
);
366 debugger_message_view_append (debugger
, IANJUTA_MESSAGE_VIEW_TYPE_NORMAL
, str
);
372 debugger_log_output (Debugger
*debugger
, const gchar
*line
)
376 IAnjutaMessageViewType type
;
379 if (debugger
->priv
->log
== NULL
) return;
381 type
= IANJUTA_MESSAGE_VIEW_TYPE_NORMAL
;
385 type
= IANJUTA_MESSAGE_VIEW_TYPE_INFO
;
391 /* Remove double quote if necessary */
392 if ((line
[1] == '\"') && (line
[len
- 1] == '\"')) start
++;
393 str
= g_strcompress (line
+ 2);
395 if (start
== line
+ 2)
401 /* Remove trailing carriage return */
402 if (str
[len
- 1] == '\n') str
[len
- 1] = '\0';
404 debugger_message_view_append (debugger
, type
, str
);
408 if (strncmp(line
+ 1, "error", 5) == 0)
410 debugger_message_view_append (debugger
, IANJUTA_MESSAGE_VIEW_TYPE_ERROR
, line
+ 1);
414 debugger_message_view_append (debugger
, IANJUTA_MESSAGE_VIEW_TYPE_WARNING
, line
+ 1);
418 debugger_message_view_append (debugger
, IANJUTA_MESSAGE_VIEW_TYPE_NORMAL
, line
+ 1);
421 debugger_message_view_append (debugger
, IANJUTA_MESSAGE_VIEW_TYPE_NORMAL
, line
);
427 debugger_emit_ready (Debugger
*debugger
)
429 if (!debugger
->priv
->debugger_is_busy
)
431 if (debugger
->priv
->loading
)
433 debugger
->priv
->starting
= FALSE
;
434 debugger
->priv
->loading
= FALSE
;
435 debugger
->priv
->exiting
= FALSE
;
436 debugger
->priv
->stopping
= FALSE
;
437 debugger
->priv
->solib_event
= FALSE
;
438 g_signal_emit_by_name (debugger
->priv
->instance
, "debugger-ready", IANJUTA_DEBUGGER_PROGRAM_LOADED
);
440 else if (debugger
->priv
->starting
)
442 debugger
->priv
->starting
= FALSE
;
443 debugger
->priv
->loading
= FALSE
;
444 debugger
->priv
->exiting
= FALSE
;
445 debugger
->priv
->stopping
= FALSE
;
446 debugger
->priv
->solib_event
= FALSE
;
447 g_signal_emit_by_name (debugger
->priv
->instance
, "debugger-ready", IANJUTA_DEBUGGER_STARTED
);
449 else if (debugger
->priv
->exiting
)
451 debugger
->priv
->exiting
= FALSE
;
452 debugger
->priv
->stopping
= FALSE
;
453 debugger
->priv
->solib_event
= FALSE
;
454 g_signal_emit_by_name (debugger
->priv
->instance
, "debugger-ready", IANJUTA_DEBUGGER_PROGRAM_LOADED
);
456 else if (debugger
->priv
->solib_event
)
458 debugger
->priv
->exiting
= FALSE
;
459 debugger
->priv
->stopping
= FALSE
;
460 debugger
->priv
->solib_event
= FALSE
;
461 g_signal_emit_by_name (debugger
->priv
->instance
, "sharedlib-event");
463 else if (debugger
->priv
->stopping
)
465 debugger
->priv
->exiting
= FALSE
;
466 debugger
->priv
->stopping
= FALSE
;
467 debugger
->priv
->solib_event
= FALSE
;
468 g_signal_emit_by_name (debugger
->priv
->instance
, "debugger-ready", IANJUTA_DEBUGGER_PROGRAM_STOPPED
);
472 if (debugger
->priv
->prog_is_running
|| debugger
->priv
->prog_is_attached
)
474 g_signal_emit_by_name (debugger
->priv
->instance
, "debugger-ready", IANJUTA_DEBUGGER_PROGRAM_STOPPED
);
476 else if (debugger
->priv
->prog_is_loaded
)
478 g_signal_emit_by_name (debugger
->priv
->instance
, "debugger-ready", IANJUTA_DEBUGGER_PROGRAM_LOADED
);
482 g_signal_emit_by_name (debugger
->priv
->instance
, "debugger-ready", IANJUTA_DEBUGGER_STARTED
);
489 debugger_get_state (Debugger
*debugger
)
491 if (debugger
->priv
->debugger_is_busy
)
493 return IANJUTA_DEBUGGER_BUSY
;
497 if (debugger
->priv
->prog_is_running
|| debugger
->priv
->prog_is_attached
)
499 return IANJUTA_DEBUGGER_PROGRAM_STOPPED
;
501 else if (debugger
->priv
->prog_is_loaded
)
503 return IANJUTA_DEBUGGER_PROGRAM_LOADED
;
505 else if (debugger
->priv
->debugger_is_started
)
507 return IANJUTA_DEBUGGER_STARTED
;
511 return IANJUTA_DEBUGGER_STOPPED
;
517 debugger_clear_buffers (Debugger
*debugger
)
519 DEBUG_PRINT ("In function: debugger_clear_buffers()");
521 /* Clear the output line buffer */
522 g_string_assign (debugger
->priv
->stdo_line
, "");
523 if (!debugger
->priv
->current_cmd
.keep_result
)
524 g_string_assign (debugger
->priv
->stdo_acc
, "");
526 /* Clear the error line buffer */
527 g_string_assign (debugger
->priv
->stde_line
, "");
529 /* Clear CLI output lines */
530 g_list_foreach (debugger
->priv
->cli_lines
, (GFunc
)g_free
, NULL
);
531 g_list_free (debugger
->priv
->cli_lines
);
532 debugger
->priv
->cli_lines
= NULL
;
535 static DebuggerCommand
*
536 debugger_queue_get_next_command (Debugger
*debugger
)
540 DEBUG_PRINT ("In function: debugger_get_next_command()");
542 if (debugger
->priv
->cmd_queqe
)
544 dc
= g_list_nth_data (debugger
->priv
->cmd_queqe
, 0);
545 debugger
->priv
->cmd_queqe
= g_list_remove (debugger
->priv
->cmd_queqe
, dc
);
553 debugger_queue_set_next_command (Debugger
*debugger
)
557 DEBUG_PRINT ("In function: debugger_set_next_command()");
559 dc
= debugger_queue_get_next_command (debugger
);
562 debugger
->priv
->current_cmd
.cmd
= NULL
;
563 debugger
->priv
->current_cmd
.parser
= NULL
;
564 debugger
->priv
->current_cmd
.callback
= NULL
;
565 debugger
->priv
->current_cmd
.user_data
= NULL
;
566 debugger
->priv
->current_cmd
.suppress_error
= FALSE
;
567 debugger
->priv
->current_cmd
.keep_result
= FALSE
;
571 g_free (debugger
->priv
->current_cmd
.cmd
);
572 debugger
->priv
->current_cmd
.cmd
= dc
->cmd
;
573 debugger
->priv
->current_cmd
.parser
= dc
->parser
;
574 debugger
->priv
->current_cmd
.callback
= dc
->callback
;
575 debugger
->priv
->current_cmd
.user_data
= dc
->user_data
;
576 debugger
->priv
->current_cmd
.suppress_error
= dc
->suppress_error
;
577 debugger
->priv
->current_cmd
.keep_result
= dc
->keep_result
;
584 debugger_queue_command (Debugger
*debugger
, const gchar
*cmd
,
585 gboolean suppress_error
, gboolean keep_result
,
586 DebuggerParserFunc parser
,
587 IAnjutaDebuggerCallback callback
, gpointer user_data
)
592 DEBUG_PRINT ("In function: debugger_queue_command (%s)", cmd
);
594 dc
= g_malloc (sizeof (DebuggerCommand
));
597 dc
->cmd
= g_strdup(cmd
);
599 dc
->callback
= callback
;
600 dc
->user_data
= user_data
;
601 dc
->suppress_error
= suppress_error
;
602 dc
->keep_result
= keep_result
;
604 debugger
->priv
->cmd_queqe
= g_list_append (debugger
->priv
->cmd_queqe
, dc
);
605 debugger_queue_execute_command (debugger
);
609 debugger_queue_clear (Debugger
*debugger
)
613 DEBUG_PRINT ("In function: debugger_queue_clear()");
615 node
= debugger
->priv
->cmd_queqe
;
618 g_free (((DebuggerCommand
*)node
->data
)->cmd
);
620 node
= g_list_next (node
);
622 g_list_free (debugger
->priv
->cmd_queqe
);
623 debugger
->priv
->cmd_queqe
= NULL
;
624 g_free (debugger
->priv
->current_cmd
.cmd
);
625 debugger
->priv
->current_cmd
.cmd
= NULL
;
626 debugger
->priv
->current_cmd
.parser
= NULL
;
627 debugger
->priv
->current_cmd
.callback
= NULL
;
628 debugger
->priv
->current_cmd
.user_data
= NULL
;
629 debugger
->priv
->current_cmd
.suppress_error
= FALSE
;
630 debugger
->priv
->current_cmd
.keep_result
= FALSE
;
631 debugger_clear_buffers (debugger
);
635 debugger_execute_command (Debugger
*debugger
, const gchar
*command
)
639 DEBUG_PRINT ("In function: debugger_execute_command(%s) %d\n",command
, debugger
->priv
->debugger_is_busy
);
640 debugger
->priv
->debugger_is_busy
++;
641 debugger
->priv
->command_output_sent
= FALSE
;
642 cmd
= g_strconcat (command
, "\n", NULL
);
643 debugger_log_command (debugger
, cmd
);
644 anjuta_launcher_send_stdin (debugger
->priv
->launcher
, cmd
);
649 debugger_queue_execute_command (Debugger
*debugger
)
651 DEBUG_PRINT ("In function: debugger_queue_execute_command()");
653 if (!debugger
->priv
->debugger_is_busy
&&
654 !debugger
->priv
->starting
&&
655 g_list_length (debugger
->priv
->cmd_queqe
) >= 1)
657 debugger_clear_buffers (debugger
);
658 if (debugger_queue_set_next_command (debugger
))
659 debugger_execute_command (debugger
, debugger
->priv
->current_cmd
.cmd
);
664 debugger_load_executable_finish (Debugger
*debugger
, const GDBMIValue
*mi_results
,
665 const GList
*cli_results
, GError
*error
)
667 DEBUG_PRINT ("Program loaded");
668 debugger
->priv
->prog_is_loaded
= TRUE
;
670 g_signal_emit_by_name (debugger
->priv
->instance
, "program-loaded");
674 debugger_load_executable (Debugger
*debugger
, const gchar
*prog
)
676 gchar
*command
, *dir
, *msg
;
678 g_return_if_fail (IS_DEBUGGER (debugger
));
679 g_return_if_fail (prog
!= NULL
);
681 DEBUG_PRINT ("In function: debugger_load_executable(%s)", prog
);
683 if (debugger
->priv
->output_callback
)
685 msg
= g_strconcat (_("Loading Executable: "), prog
, "\n", NULL
);
686 debugger
->priv
->output_callback (IANJUTA_DEBUGGER_OUTPUT
, msg
,
687 debugger
->priv
->output_user_data
);
691 command
= g_strconcat ("-file-exec-and-symbols ", prog
, NULL
);
692 dir
= g_path_get_dirname (prog
);
694 anjuta_set_execution_dir(dir);
697 debugger_queue_command (debugger
, command
, FALSE
, FALSE
, debugger_load_executable_finish
, NULL
, NULL
);
699 debugger
->priv
->starting
= TRUE
;
700 debugger
->priv
->terminating
= FALSE
;
704 debugger_load_core (Debugger
*debugger
, const gchar
*core
)
706 gchar
*command
, *dir
, *msg
;
708 g_return_if_fail (IS_DEBUGGER (debugger
));
709 g_return_if_fail (core
!= NULL
);
711 DEBUG_PRINT ("In function: debugger_load_core(%s)", core
);
713 if (debugger
->priv
->output_callback
)
715 msg
= g_strconcat (_("Loading Core: "), core
, "\n", NULL
);
716 debugger
->priv
->output_callback (IANJUTA_DEBUGGER_OUTPUT
, msg
,
717 debugger
->priv
->output_user_data
);
721 command
= g_strconcat ("core ", core
, NULL
);
722 dir
= g_path_get_dirname (core
);
723 debugger
->priv
->search_dirs
=
724 g_list_prepend (debugger
->priv
->search_dirs
, dir
);
725 debugger_queue_command (debugger
, command
, FALSE
, FALSE
, NULL
, NULL
, NULL
);
730 debugger_start (Debugger
*debugger
, const GList
*search_dirs
,
731 const gchar
*prog
, gboolean is_libtool_prog
)
733 gchar
*command_str
, *dir
, *tmp
, *text
, *msg
;
737 AnjutaLauncher
*launcher
;
738 GList
*dir_list
= NULL
;
741 DEBUG_PRINT ("In function: debugger_start(%s) libtool %d", prog
== NULL
? "(null)" : prog
, is_libtool_prog
);
743 if (anjuta_util_prog_is_installed ("gdb", TRUE
) == FALSE
)
746 debugger_queue_clear (debugger
);
748 tmp
= g_strconcat (PACKAGE_DATA_DIR
, "/", "gdb.init", NULL
);
749 if (g_file_test (tmp
, G_FILE_TEST_IS_REGULAR
) == FALSE
)
751 anjuta_util_dialog_error (debugger
->priv
->parent_win
,
752 _("Unable to find: %s.\n"
753 "Unable to initialize debugger.\n"
754 "Make sure Anjuta is installed correctly."),
761 /* Prepare source search directories */
764 exec_dir
= g_path_get_dirname (prog
);
768 gchar
*quoted_exec_dir
= gdb_quote (exec_dir
);
769 dir
= g_strconcat (" -directory=\"", quoted_exec_dir
, "\"", NULL
);
770 g_free (quoted_exec_dir
);
771 dir_list
= g_list_prepend (dir_list
, exec_dir
);
775 dir
= g_strdup (" ");
782 if (strncmp (text
, "file://", 7) == 0)
788 g_warning ("Debugger source search uri '%s' is not a local uri", text
);
793 tmp
= g_strconcat (dir
, " -directory=", text
, NULL
);
797 dir_list
= g_list_prepend (dir_list
, g_strdup (text
));
801 g_warning ("Debugger source search dir '%s' is not absolute",
804 node
= g_list_next (node
);
807 /* Now save the dir list. Order is automatically revesed */
811 debugger
->priv
->search_dirs
=
812 g_list_prepend (debugger
->priv
->search_dirs
, node
->data
);
813 node
= g_list_next (node
);
815 g_list_free (dir_list
);
817 if (prog
&& strlen(prog
) > 0)
819 gchar
*quoted_prog
= gdb_quote (prog
);
822 if (is_libtool_prog
== FALSE
)
824 command_str
= g_strdup_printf (GDB_PATH
" -f -n -i=mi2 %s %s "
825 "-x %s/gdb.init \"%s\"", dir
, term
== NULL
? "" : term
,
826 PACKAGE_DATA_DIR
, quoted_prog
);
830 command_str
= g_strdup_printf ("libtool --mode=execute " GDB_PATH
831 " -f -n -i=mi2 %s %s "
832 "-x %s/gdb.init \"%s\"", dir
, term
== NULL
? "" : term
,
833 PACKAGE_DATA_DIR
, quoted_prog
);
835 g_free (quoted_prog
);
839 if (is_libtool_prog
== FALSE
)
841 command_str
= g_strdup_printf (GDB_PATH
" -f -n -i=mi2 %s %s "
842 "-x %s/gdb.init ", term
== NULL
? "" : term
,
843 dir
, PACKAGE_DATA_DIR
);
847 command_str
= g_strdup_printf ("libtool --mode=execute " GDB_PATH
848 " -f -n -i=mi2 %s %s -x "
850 dir
, term
== NULL
? "" : term
, PACKAGE_DATA_DIR
);
855 debugger
->priv
->starting
= TRUE
;
856 debugger
->priv
->terminating
= FALSE
;
857 debugger
->priv
->loading
= prog
!= NULL
? TRUE
: FALSE
;
858 debugger
->priv
->debugger_is_busy
= 1;
860 /* Prepare for launch. */
861 launcher
= debugger
->priv
->launcher
;
862 anjuta_launcher_set_terminate_on_exit (launcher
, TRUE
);
863 g_signal_connect (G_OBJECT (launcher
), "child-exited",
864 G_CALLBACK (on_gdb_terminated
), debugger
);
865 ret
= anjuta_launcher_execute (launcher
, command_str
,
866 on_gdb_output_arrived
, debugger
);
870 debugger
->priv
->debugger_is_started
= TRUE
;
871 debugger
->priv
->prog_is_loaded
= prog
!= NULL
;
873 anjuta_launcher_set_encoding (launcher
, "ISO-8859-1");
875 if (debugger
->priv
->output_callback
!= NULL
)
879 /* TODO anjuta_update_app_status (TRUE, _("Debugger")); */
880 debugger
->priv
->output_callback (IANJUTA_DEBUGGER_OUTPUT
,
881 _("Getting ready to start debugging "
883 debugger
->priv
->output_user_data
);
887 msg
= g_strconcat (_("Loading Executable: "), prog
, "\n", NULL
);
888 debugger
->priv
->output_callback (IANJUTA_DEBUGGER_OUTPUT
,
890 debugger
->priv
->output_user_data
);
895 debugger
->priv
->output_callback (IANJUTA_DEBUGGER_OUTPUT
,
896 _("No executable specified.\n"),
897 debugger
->priv
->output_user_data
);
898 debugger
->priv
->output_callback (IANJUTA_DEBUGGER_OUTPUT
,
899 _("Open an executable or attach "
900 "to a process to start "
902 debugger
->priv
->output_user_data
);
907 debugger
->priv
->output_callback (IANJUTA_DEBUGGER_OUTPUT
,
908 _("There was an error whilst "
909 "launching the debugger.\n"),
910 debugger
->priv
->output_user_data
);
911 debugger
->priv
->output_callback (IANJUTA_DEBUGGER_OUTPUT
,
912 _("Make sure 'gdb' is installed "
914 debugger
->priv
->output_user_data
);
917 g_free (command_str
);
923 gdb_stdout_line_arrived (Debugger
*debugger
, const gchar
* chars
)
929 if (chars
[i
] == '\n')
931 debugger_stdo_flush (debugger
);
935 g_string_append_c (debugger
->priv
->stdo_line
, chars
[i
]);
942 gdb_stderr_line_arrived (Debugger
*debugger
, const gchar
* chars
)
946 for (i
= 0; i
< strlen (chars
); i
++)
948 if (chars
[i
] == '\n')
949 debugger_stde_flush (debugger
);
951 g_string_append_c (debugger
->priv
->stde_line
, chars
[i
]);
956 on_gdb_output_arrived (AnjutaLauncher
*launcher
,
957 AnjutaLauncherOutputType output_type
,
958 const gchar
*chars
, gpointer data
)
960 Debugger
*debugger
= DEBUGGER (data
);
961 DEBUG_PRINT ("on gdb output arrived");
963 /* Do not emit signal when the debugger is destroyed */
964 if (debugger
->priv
->instance
== NULL
) return;
968 case ANJUTA_LAUNCHER_OUTPUT_STDERR
:
969 gdb_stderr_line_arrived (debugger
, chars
);
971 case ANJUTA_LAUNCHER_OUTPUT_STDOUT
:
972 gdb_stdout_line_arrived (debugger
, chars
);
980 debugger_handle_post_execution (Debugger
*debugger
)
982 switch (debugger
->priv
->post_execution_flag
)
987 DEBUG_PRINT ("debugger stop in handle post execution\n");
988 debugger_stop (debugger
);
990 case DEBUGGER_RERUN_PROGRAM
:
991 DEBUG_PRINT ("debugger run in handle post execution\n");
992 debugger_run (debugger
);
995 g_warning ("Execution should not reach here");
1000 debugger_process_frame (Debugger
*debugger
, const GDBMIValue
*val
)
1002 const GDBMIValue
*file
, *line
, *frame
, *addr
, *fullname
, *thread
;
1003 const gchar
*file_str
= NULL
;
1005 gulong addr_num
= 0;
1007 g_return_if_fail (val
!= NULL
);
1009 thread
= gdbmi_value_hash_lookup (val
, "thread-id");
1012 debugger
->priv
->current_thread
= strtoul (gdbmi_value_literal_get (thread
), NULL
, 0);
1014 debugger
->priv
->current_frame
= 0;
1016 frame
= gdbmi_value_hash_lookup (val
, "frame");
1019 fullname
= gdbmi_value_hash_lookup (frame
, "fullname");
1022 file_str
= gdbmi_value_literal_get (fullname
);
1023 if (*file_str
== '\0') file_str
= NULL
;
1027 file
= gdbmi_value_hash_lookup (frame
, "file");
1030 file_str
= gdbmi_value_literal_get (file
);
1031 if (*file_str
== '\0') file_str
= NULL
;
1035 if (file_str
!= NULL
)
1037 line
= gdbmi_value_hash_lookup (frame
, "line");
1040 line_num
= strtoul (gdbmi_value_literal_get (line
), NULL
, 0);
1044 addr
= gdbmi_value_hash_lookup (frame
, "addr");
1047 addr_num
= strtoul (gdbmi_value_literal_get (addr
), NULL
, 0);
1049 debugger_program_moved (debugger
, file_str
, line_num
, addr_num
);
1054 gdb_parse_error (Debugger
*debugger
, const GDBMIValue
*mi_results
)
1056 const GDBMIValue
*message
;
1057 const gchar
*literal
;
1058 guint code
= IANJUTA_DEBUGGER_UNKNOWN_ERROR
;
1060 message
= gdbmi_value_hash_lookup (mi_results
, "msg");
1061 literal
= gdbmi_value_literal_get (message
);
1063 if ((mi_results
!= NULL
)
1064 && ((message
= gdbmi_value_hash_lookup (mi_results
, "msg")) != NULL
)
1065 && ((literal
= gdbmi_value_literal_get (message
)) != NULL
)
1066 && (*literal
!= '\0'))
1068 code
= gdb_match_error (literal
);
1069 DEBUG_PRINT ("error code %d", code
);
1073 /* No error message */
1074 literal
= "Error without a message";
1077 return g_error_new_literal (IANJUTA_DEBUGGER_ERROR
, code
, literal
);
1082 *---------------------------------------------------------------------------*/
1085 debugger_parse_output (Debugger
*debugger
)
1089 line
= debugger
->priv
->stdo_line
->str
;
1091 if (line
[0] == '\032' && line
[1] == '\032')
1096 gdb_util_parse_error_line (&(line
[2]), &filename
, &lineno
);
1099 debugger_program_moved (debugger
, filename
, lineno
, 0);
1108 len
= strlen (line
);
1109 if (line
[1] == '\"' && line
[strlen(line
) - 1] == '\"')
1112 /* Reserve space for an additional carriage return */
1113 line
[strlen(line
) - 1] = ' ';
1114 proper_msg
= g_strcompress (line
+ 1);
1115 len
= strlen (proper_msg
) - 1;
1116 proper_msg
[len
] = '\0';
1120 /* Reserve space for an additional carriage return */
1121 proper_msg
= g_strndup (line
, len
+ 1);
1124 if (strcmp(proper_msg
, "~Stopped due to shared library event\n") == 0)
1126 /* Recognize a solib event */
1127 debugger
->priv
->solib_event
= TRUE
;
1128 g_free (proper_msg
);
1130 else if (debugger
->priv
->current_cmd
.parser
)
1132 /* Save GDB CLI output */
1133 debugger
->priv
->cli_lines
= g_list_prepend (debugger
->priv
->cli_lines
,
1138 /* Discard CLI output */
1139 g_free (proper_msg
);
1145 debugger_parse_stopped (Debugger
*debugger
)
1147 gchar
*line
= debugger
->priv
->stdo_line
->str
;
1150 if (!debugger
->priv
->solib_event
)
1152 gboolean program_exited
= FALSE
;
1155 /* Check if program has exited */
1156 val
= gdbmi_value_parse (line
);
1159 const GDBMIValue
*reason
;
1160 const gchar
*str
= NULL
;
1162 debugger_process_frame (debugger
, val
);
1164 reason
= gdbmi_value_hash_lookup (val
, "reason");
1166 str
= gdbmi_value_literal_get (reason
);
1168 if (str
&& (strncmp (str
, "exited", 6) == 0))
1170 program_exited
= TRUE
;
1173 /* Emit signal received if necessary */
1174 if (str
&& strcmp (str
, "exited-signalled") == 0)
1176 const GDBMIValue
*signal_name
, *signal_meaning
;
1177 const gchar
*signal_str
, *signal_meaning_str
;
1179 signal_name
= gdbmi_value_hash_lookup (val
, "signal-name");
1180 signal_str
= gdbmi_value_literal_get (signal_name
);
1181 signal_meaning
= gdbmi_value_hash_lookup (val
, "signal-meaning");
1182 signal_meaning_str
= gdbmi_value_literal_get (signal_meaning
);
1183 g_signal_emit_by_name (debugger
->priv
->instance
, "signal-received", signal_str
, signal_meaning_str
);
1185 else if (str
&& strcmp (str
, "signal-received") == 0)
1187 const GDBMIValue
*signal_name
, *signal_meaning
;
1188 const gchar
*signal_str
, *signal_meaning_str
;
1190 signal_name
= gdbmi_value_hash_lookup (val
, "signal-name");
1191 signal_str
= gdbmi_value_literal_get (signal_name
);
1192 signal_meaning
= gdbmi_value_hash_lookup (val
, "signal-meaning");
1193 signal_meaning_str
= gdbmi_value_literal_get (signal_meaning
);
1195 g_signal_emit_by_name (debugger
->priv
->instance
, "signal-received", signal_str
, signal_meaning_str
);
1198 if (debugger
->priv
->output_callback
)
1200 if (str
&& strcmp (str
, "exited-normally") == 0)
1202 debugger
->priv
->output_callback (IANJUTA_DEBUGGER_OUTPUT
,
1203 _("Program exited normally\n"),
1204 debugger
->priv
->output_user_data
);
1206 else if (str
&& strcmp (str
, "exited") == 0)
1208 const GDBMIValue
*errcode
;
1209 const gchar
*errcode_str
;
1212 errcode
= gdbmi_value_hash_lookup (val
, "exit-code");
1213 errcode_str
= gdbmi_value_literal_get (errcode
);
1214 msg
= g_strdup_printf (_("Program exited with error code %s\n"),
1216 debugger
->priv
->output_callback (IANJUTA_DEBUGGER_OUTPUT
,
1217 msg
, debugger
->priv
->output_user_data
);
1220 else if (str
&& strcmp (str
, "breakpoint-hit") == 0)
1222 const GDBMIValue
*bkptno
;
1223 const gchar
*bkptno_str
;
1226 bkptno
= gdbmi_value_hash_lookup (val
, "bkptno");
1227 bkptno_str
= gdbmi_value_literal_get (bkptno
);
1228 /* The program has reached one breakpoint and will stop */
1229 msg
= g_strdup_printf (_("Breakpoint number %s hit\n"),
1231 debugger
->priv
->output_callback (IANJUTA_DEBUGGER_OUTPUT
,
1232 msg
, debugger
->priv
->output_user_data
);
1235 else if (str
&& strcmp (str
, "function-finished") == 0)
1237 debugger
->priv
->output_callback (IANJUTA_DEBUGGER_OUTPUT
,
1238 _("Function finished\n"),
1239 debugger
->priv
->output_user_data
);
1241 else if (str
&& strcmp (str
, "end-stepping-range") == 0)
1243 debugger
->priv
->output_callback (IANJUTA_DEBUGGER_OUTPUT
,
1244 _("Stepping finished\n"),
1245 debugger
->priv
->output_user_data
);
1247 else if (str
&& strcmp (str
, "location-reached") == 0)
1249 debugger
->priv
->output_callback (IANJUTA_DEBUGGER_OUTPUT
,
1250 _("Location reached\n"),
1251 debugger
->priv
->output_user_data
);
1258 debugger
->priv
->prog_is_running
= FALSE
;
1259 debugger
->priv
->prog_is_attached
= FALSE
;
1260 debugger_handle_post_execution (debugger
);
1261 debugger
->priv
->exiting
= TRUE
;
1265 // g_signal_emit_by_name (debugger->priv->instance, "program-stopped");
1266 debugger
->priv
->stopping
= TRUE
;
1269 debugger
->priv
->cli_lines
= g_list_reverse (debugger
->priv
->cli_lines
);
1270 if ((debugger
->priv
->current_cmd
.cmd
!= NULL
) &&
1271 (debugger
->priv
->current_cmd
.parser
!= NULL
))
1273 debugger
->priv
->current_cmd
.parser (debugger
, val
,
1274 debugger
->priv
->cli_lines
, FALSE
);
1275 debugger
->priv
->command_output_sent
= TRUE
;
1276 DEBUG_PRINT ("In function: Sending output...");
1280 gdbmi_value_free (val
);
1285 debugger_parse_prompt (Debugger
*debugger
)
1287 /* If the parser has not yet been called, call it now. */
1288 if (debugger
->priv
->command_output_sent
== FALSE
&&
1289 debugger
->priv
->current_cmd
.parser
)
1291 debugger
->priv
->current_cmd
.parser (debugger
, NULL
,
1292 debugger
->priv
->cli_lines
, FALSE
);
1293 debugger
->priv
->command_output_sent
= TRUE
;
1296 debugger
->priv
->debugger_is_busy
--;
1297 debugger_queue_execute_command (debugger
); /* Next command. Go. */
1298 debugger_emit_ready (debugger
);
1302 parse_breakpoint (IAnjutaDebuggerBreakpointItem
* bp
, const GDBMIValue
*brkpnt
)
1304 const GDBMIValue
*literal
;
1307 memset (bp
, 0, sizeof (*bp
));
1309 literal
= gdbmi_value_hash_lookup (brkpnt
, "number");
1312 value
= gdbmi_value_literal_get (literal
);
1313 bp
->id
= strtoul (value
, NULL
, 10);
1316 literal
= gdbmi_value_hash_lookup (brkpnt
, "fullname");
1317 if (literal
== NULL
) literal
= gdbmi_value_hash_lookup (brkpnt
, "file");
1320 value
= gdbmi_value_literal_get (literal
);
1321 bp
->file
= (gchar
*)value
;
1324 literal
= gdbmi_value_hash_lookup (brkpnt
, "line");
1327 value
= gdbmi_value_literal_get (literal
);
1328 bp
->line
= strtoul (value
, NULL
, 10);
1329 bp
->type
|= IANJUTA_DEBUGGER_BREAKPOINT_ON_LINE
;
1332 literal
= gdbmi_value_hash_lookup (brkpnt
, "type");
1335 value
= gdbmi_value_literal_get (literal
);
1338 literal
= gdbmi_value_hash_lookup (brkpnt
, "disp");
1341 value
= gdbmi_value_literal_get (literal
);
1342 if (strcmp (value
, "keep") == 0)
1344 bp
->type
|= IANJUTA_DEBUGGER_BREAKPOINT_WITH_TEMPORARY
;
1345 bp
->temporary
= FALSE
;
1347 else if ((strcmp (value
, "nokeep") == 0) || (strcmp (value
, "del") == 0))
1349 bp
->type
|= IANJUTA_DEBUGGER_BREAKPOINT_WITH_TEMPORARY
;
1350 bp
->temporary
= TRUE
;
1354 literal
= gdbmi_value_hash_lookup (brkpnt
, "enabled");
1357 value
= gdbmi_value_literal_get (literal
);
1358 if (strcmp (value
, "n") == 0)
1360 bp
->type
|= IANJUTA_DEBUGGER_BREAKPOINT_WITH_ENABLE
;
1363 else if (strcmp (value
, "y") == 0)
1365 bp
->type
|= IANJUTA_DEBUGGER_BREAKPOINT_WITH_ENABLE
;
1370 literal
= gdbmi_value_hash_lookup (brkpnt
, "addr");
1373 value
= gdbmi_value_literal_get (literal
);
1374 bp
->address
= strtoul (value
, NULL
, 16);
1375 bp
->type
|= IANJUTA_DEBUGGER_BREAKPOINT_ON_ADDRESS
;
1378 literal
= gdbmi_value_hash_lookup (brkpnt
, "func");
1381 value
= gdbmi_value_literal_get (literal
);
1382 bp
->function
= (gchar
*)value
;
1383 bp
->type
|= IANJUTA_DEBUGGER_BREAKPOINT_ON_FUNCTION
;
1386 literal
= gdbmi_value_hash_lookup (brkpnt
, "times");
1389 value
= gdbmi_value_literal_get (literal
);
1390 bp
->times
= strtoul (value
, NULL
, 10);
1391 bp
->type
|= IANJUTA_DEBUGGER_BREAKPOINT_WITH_TIME
;
1393 DEBUG_PRINT("parse time %d", bp
->times
);
1395 literal
= gdbmi_value_hash_lookup (brkpnt
, "ignore");
1398 value
= gdbmi_value_literal_get (literal
);
1399 bp
->ignore
= strtoul (value
, NULL
, 10);
1400 bp
->type
|= IANJUTA_DEBUGGER_BREAKPOINT_WITH_IGNORE
;
1403 literal
= gdbmi_value_hash_lookup (brkpnt
, "cond");
1406 value
= gdbmi_value_literal_get (literal
);
1407 bp
->condition
= (gchar
*)value
;
1408 bp
->type
|= IANJUTA_DEBUGGER_BREAKPOINT_WITH_CONDITION
;
1415 debugger_stdo_flush (Debugger
*debugger
)
1419 line
= debugger
->priv
->stdo_line
->str
;
1422 DEBUG_PRINT ("GDB:< %s", line
);
1424 if (debugger
->priv
->gdb_log
) g_message ("GDB:< %s", line
);
1426 debugger_log_output (debugger
, line
);
1427 if (strlen (line
) == 0)
1431 if (strncasecmp (line
, "^error", 6) == 0)
1433 /* GDB reported error */
1434 if ((debugger
->priv
->current_cmd
.keep_result
) || (debugger
->priv
->stdo_acc
->len
!= 0))
1436 /* Keep result for next command */
1438 if (debugger
->priv
->stdo_acc
->len
== 0)
1440 g_string_append (debugger
->priv
->stdo_acc
, line
);
1444 line
= strchr (line
, ',');
1447 g_string_append (debugger
->priv
->stdo_acc
, line
);
1450 line
= debugger
->priv
->stdo_acc
->str
;
1453 GDBMIValue
*val
= gdbmi_value_parse (line
);
1456 error
= gdb_parse_error (debugger
, val
);
1458 /* Trap state error */
1459 if ((error
!= NULL
) && (error
->code
== IANJUTA_DEBUGGER_PROGRAM_NOT_FOUND
))
1461 debugger
->priv
->prog_is_running
= FALSE
;
1462 debugger
->priv
->prog_is_attached
= FALSE
;
1463 debugger
->priv
->prog_is_loaded
= FALSE
;
1466 if (debugger
->priv
->current_cmd
.parser
!= NULL
)
1468 debugger
->priv
->current_cmd
.parser (debugger
, val
, debugger
->priv
->cli_lines
, error
);
1469 debugger
->priv
->command_output_sent
= TRUE
; }
1470 DEBUG_PRINT("GDB: error %s", error
->message
);
1473 anjuta_util_dialog_error (debugger->priv->parent_win, "%s", error->message);
1475 g_error_free (error
);
1476 gdbmi_value_free (val
);
1478 else if (strncasecmp(line
, "^running", 8) == 0)
1480 /* Program started running */
1481 debugger
->priv
->prog_is_running
= TRUE
;
1482 /* debugger->priv->skip_next_prompt = TRUE; Replaced by debugger_is_busy++ */
1483 debugger
->priv
->debugger_is_busy
++;
1484 g_signal_emit_by_name (debugger
->priv
->instance
, "program-running");
1486 else if (strncasecmp (line
, "*stopped", 8) == 0)
1488 /* Process has stopped */
1489 debugger_parse_stopped (debugger
);
1491 else if (strncasecmp (line
, "^done", 5) == 0)
1493 if ((debugger
->priv
->current_cmd
.keep_result
) || (debugger
->priv
->stdo_acc
->len
!= 0))
1495 /* Keep result for next command */
1497 if (debugger
->priv
->stdo_acc
->len
== 0)
1499 g_string_append (debugger
->priv
->stdo_acc
, line
);
1503 line
= strchr (line
, ',');
1506 g_string_append (debugger
->priv
->stdo_acc
, line
);
1509 line
= debugger
->priv
->stdo_acc
->str
;
1512 if (!debugger
->priv
->current_cmd
.keep_result
)
1514 /* GDB command has reported output */
1515 GDBMIValue
*val
= gdbmi_value_parse (line
);
1517 debugger
->priv
->cli_lines
= g_list_reverse (debugger
->priv
->cli_lines
);
1518 if ((debugger
->priv
->current_cmd
.cmd
!= NULL
) &&
1519 (debugger
->priv
->current_cmd
.parser
!= NULL
))
1521 debugger
->priv
->current_cmd
.parser (debugger
, val
,
1522 debugger
->priv
->cli_lines
, FALSE
);
1523 debugger
->priv
->command_output_sent
= TRUE
;
1524 DEBUG_PRINT ("In function: Sending output...");
1528 /*g_signal_emit_by_name (debugger, "results-arrived",
1529 debugger->priv->current_cmd.cmd, val);*/
1534 /*debugger_process_frame (debugger, val);*/
1535 gdbmi_value_free (val
);
1539 if (!debugger
->priv
->current_cmd
.keep_result
)
1541 g_string_assign (debugger
->priv
->stdo_acc
, "");
1544 else if (strncasecmp (line
, GDB_PROMPT
, strlen (GDB_PROMPT
)) == 0)
1546 debugger_parse_prompt (debugger
);
1550 debugger_parse_output (debugger
);
1553 /* Clear the line buffer */
1554 g_string_assign (debugger
->priv
->stdo_line
, "");
1558 debugger_stde_flush (Debugger
*debugger
)
1560 if ((debugger
->priv
->output_callback
) && (strlen (debugger
->priv
->stde_line
->str
) > 0))
1562 debugger
->priv
->output_callback (IANJUTA_DEBUGGER_ERROR_OUTPUT
,
1563 debugger
->priv
->stde_line
->str
,
1564 debugger
->priv
->output_user_data
);
1566 /* Clear the line buffer */
1567 g_string_assign (debugger
->priv
->stde_line
, "");
1571 on_gdb_terminated (AnjutaLauncher
*launcher
,
1572 gint child_pid
, gint status
, gulong t
,
1575 Debugger
*debugger
= DEBUGGER (data
);
1578 g_signal_handlers_disconnect_by_func (G_OBJECT (launcher
),
1579 G_CALLBACK (on_gdb_terminated
),
1582 DEBUG_PRINT ("In function: gdb_terminated()");
1584 /* Clear the command queue & Buffer */
1585 debugger_clear_buffers (debugger
);
1587 /* Good Bye message */
1588 /*if (!debugger->priv->terminating)
1590 anjuta_util_dialog_error (debugger->priv->parent_win,
1591 _("gdb terminated unexpectedly with status %d\n"), status);
1593 debugger
->priv
->prog_is_running
= FALSE
;
1594 debugger
->priv
->prog_is_attached
= FALSE
;
1595 debugger
->priv
->prog_is_loaded
= FALSE
;
1596 debugger
->priv
->debugger_is_busy
= 0;
1597 debugger
->priv
->skip_next_prompt
= FALSE
;
1598 if (!debugger
->priv
->terminating
)
1600 err
= g_error_new (IANJUTA_DEBUGGER_ERROR
,
1601 IANJUTA_DEBUGGER_OTHER_ERROR
,
1602 "gdb terminated with status %d", status
);
1604 debugger
->priv
->terminating
= FALSE
;
1605 debugger
->priv
->debugger_is_started
= FALSE
;
1606 if (debugger
->priv
->instance
)
1608 g_signal_emit_by_name (debugger
->priv
->instance
, "debugger-stopped", err
);
1610 if (err
!= NULL
) g_error_free (err
);
1614 debugger_stop_real (Debugger
*debugger
)
1616 DEBUG_PRINT ("In function: debugger_stop_real()");
1618 /* if program is attached - detach from it before quiting */
1619 if (debugger
->priv
->prog_is_attached
== TRUE
)
1621 debugger_detach_process(debugger
);
1624 debugger
->priv
->terminating
= TRUE
;
1625 debugger_queue_command (debugger
, "-gdb-exit", FALSE
, FALSE
, NULL
, NULL
, NULL
);
1629 debugger_stop (Debugger
*debugger
)
1632 gboolean ret
= TRUE
;
1634 if (debugger
->priv
->prog_is_running
== TRUE
)
1639 if (debugger
->priv
->prog_is_attached
== TRUE
)
1640 mesg
= _("The program is attached.\n"
1641 "Do you still want to stop the debugger?");
1643 mesg
= _("The program is running.\n"
1644 "Do you still want to stop the debugger?");
1645 dialog
= gtk_message_dialog_new (debugger
->priv
->parent_win
,
1646 GTK_DIALOG_DESTROY_WITH_PARENT
,
1647 GTK_MESSAGE_QUESTION
,
1648 GTK_BUTTONS_NONE
, mesg
);
1649 gtk_dialog_add_buttons (GTK_DIALOG (dialog
),
1650 GTK_STOCK_CANCEL
, GTK_RESPONSE_NO
,
1651 GTK_STOCK_STOP
, GTK_RESPONSE_YES
,
1653 if (gtk_dialog_run (GTK_DIALOG (dialog
)) == GTK_RESPONSE_YES
)
1654 debugger_stop_real (debugger
);
1657 gtk_widget_destroy (dialog
);
1660 debugger_stop_real (debugger
);
1663 debugger_stop_real (debugger
);
1669 debugger_abort (Debugger
*debugger
)
1671 DEBUG_PRINT ("In function: debugger_abort()");
1674 if ((debugger
->priv
->prog_is_attached
== FALSE
) && (debugger
->priv
->inferior_pid
!= 0))
1676 kill (debugger
->priv
->inferior_pid
, SIGTERM
);
1677 debugger
->priv
->inferior_pid
= 0;
1681 debugger
->priv
->terminating
= TRUE
;
1682 g_signal_handlers_disconnect_by_func (G_OBJECT (debugger
->priv
->launcher
), G_CALLBACK (on_gdb_terminated
), debugger
);
1683 anjuta_launcher_reset (debugger
->priv
->launcher
);
1686 debugger_queue_clear (debugger
);
1687 g_list_foreach (debugger
->priv
->search_dirs
, (GFunc
)g_free
, NULL
);
1688 g_list_free (debugger
->priv
->search_dirs
);
1689 debugger
->priv
->search_dirs
= NULL
;
1691 /* Emit signal, state of the debugger must be DEBUGGER_STOPPED */
1692 debugger
->priv
->prog_is_running
= FALSE
;
1693 debugger
->priv
->prog_is_attached
= FALSE
;
1694 debugger
->priv
->inferior_pid
= 0;
1695 debugger
->priv
->prog_is_loaded
= FALSE
;
1696 debugger
->priv
->debugger_is_busy
= 0;
1697 debugger
->priv
->debugger_is_started
= FALSE
;
1698 if (debugger
->priv
->instance
!= NULL
)
1700 g_signal_emit_by_name (debugger
->priv
->instance
, "debugger-stopped", NULL
);
1701 debugger
->priv
->instance
= NULL
;
1708 debugger_get_source_path (Debugger
*debugger
, const gchar
*file
)
1713 if (g_path_is_absolute (file
))
1714 return g_strdup (file
);
1716 node
= debugger
->priv
->search_dirs
;
1719 path
= g_build_filename (node
->data
, file
, NULL
);
1720 if (g_file_test (path
, G_FILE_TEST_EXISTS
))
1724 node
= g_list_next (node
);
1729 /* The file could be found nowhere. Use current directory */
1731 cwd
= g_get_current_dir ();
1732 path
= g_build_filename (cwd
, file
, NULL
);
1739 debugger_set_output_callback (Debugger
*debugger
, IAnjutaDebuggerOutputCallback callback
, gpointer user_data
)
1741 debugger
->priv
->output_callback
= callback
;
1742 debugger
->priv
->output_user_data
= user_data
;
1746 debugger_program_moved (Debugger
*debugger
, const gchar
*file
,
1747 gint line
, gulong address
)
1751 if ((file
!= NULL
) && (*file
!= G_DIR_SEPARATOR
))
1753 src_path
= debugger_get_source_path (debugger
, file
);
1754 g_signal_emit_by_name (debugger
->priv
->instance
, "program-moved", debugger
->priv
->inferior_pid
, debugger
->priv
->current_thread
, address
, src_path
, line
);
1759 g_signal_emit_by_name (debugger
->priv
->instance
, "program-moved", debugger
->priv
->inferior_pid
, debugger
->priv
->current_thread
, address
, file
, line
);
1764 debugger_info_program_finish (Debugger
*debugger
, const GDBMIValue
*mi_results
,
1765 const GList
*cli_results
, GError
*error
)
1767 DEBUG_PRINT ("In function: debugger_info_program()");
1769 /* Hack: find message string giving inferior pid */
1770 while (cli_results
!= NULL
)
1774 child_proc
= strstr(cli_results
->data
, " child process ");
1775 if (child_proc
!= NULL
)
1777 debugger
->priv
->inferior_pid
= strtoul (child_proc
+ 15, NULL
, 10);
1780 cli_results
= g_list_next (cli_results
);
1785 debugger_start_program (Debugger
*debugger
, const gchar
* args
, const gchar
* tty
, gboolean stop
)
1789 DEBUG_PRINT ("In function: debugger_start_program()");
1791 g_return_if_fail (IS_DEBUGGER (debugger
));
1792 g_return_if_fail (debugger
->priv
->prog_is_running
== FALSE
);
1794 /* Without a terminal, the output of the debugged program
1798 cmd
= g_strdup_printf ("-inferior-tty-set %s", tty
);
1799 debugger_queue_command (debugger
, cmd
, FALSE
, FALSE
, NULL
, NULL
, NULL
);
1803 debugger
->priv
->inferior_pid
= 0;
1806 debugger_queue_command (debugger
, "-break-insert -t main", FALSE
, FALSE
, NULL
, NULL
, NULL
);
1808 if (args
&& (*args
))
1810 cmd
= g_strconcat ("-exec-arguments ", args
, NULL
);
1811 debugger_queue_command (debugger
, cmd
, FALSE
, FALSE
, NULL
, NULL
, NULL
);
1815 debugger_queue_command (debugger
, "-exec-run", FALSE
, FALSE
, NULL
, NULL
, NULL
);
1817 /* Get pid of program on next stop */
1818 debugger_queue_command (debugger
, "info program", FALSE
, FALSE
, debugger_info_program_finish
, NULL
, NULL
);
1819 debugger
->priv
->post_execution_flag
= DEBUGGER_NONE
;
1823 debugger_attach_process_finish (Debugger
*debugger
, const GDBMIValue
*mi_results
,
1824 const GList
*cli_results
, GError
*error
)
1826 DEBUG_PRINT ("Program attach finished");
1827 if (debugger
->priv
->output_callback
)
1829 debugger
->priv
->output_callback (IANJUTA_DEBUGGER_OUTPUT
,
1830 _("Program attached\n"),
1831 debugger
->priv
->output_user_data
);
1833 debugger
->priv
->prog_is_attached
= TRUE
;
1834 debugger
->priv
->prog_is_running
= TRUE
;
1835 /* It is not really a shared lib event, but it allows to restart
1836 * the program after setting breakpoints. It is better to restart
1837 * it because we don't have the normal stop frame that tell where
1838 * the program is stopped */
1839 debugger
->priv
->solib_event
= TRUE
;
1843 debugger_attach_process_real (Debugger
*debugger
, pid_t pid
)
1847 DEBUG_PRINT ("In function: debugger_attach_process_real()");
1849 if (debugger
->priv
->output_callback
)
1851 buff
= g_strdup_printf (_("Attaching to process: %d...\n"), pid
);
1852 debugger
->priv
->output_callback (IANJUTA_DEBUGGER_OUTPUT
,
1853 buff
, debugger
->priv
->output_user_data
);
1857 debugger
->priv
->inferior_pid
= pid
;
1858 buff
= g_strdup_printf ("attach %d", pid
);
1859 debugger_queue_command (debugger
, buff
, FALSE
, FALSE
,
1860 debugger_attach_process_finish
, NULL
, NULL
);
1865 debugger_attach_process (Debugger
*debugger
, pid_t pid
)
1867 DEBUG_PRINT ("In function: debugger_attach_process()");
1869 g_return_if_fail (IS_DEBUGGER (debugger
));
1871 if (debugger
->priv
->prog_is_running
== TRUE
)
1873 // TODO: Dialog to be made HIG compliant.
1877 mesg
= _("A process is already running.\n"
1878 "Would you like to terminate it and attach the new process?"),
1879 dialog
= gtk_message_dialog_new (debugger
->priv
->parent_win
,
1880 GTK_DIALOG_DESTROY_WITH_PARENT
,
1881 GTK_MESSAGE_QUESTION
,
1882 GTK_BUTTONS_YES_NO
, mesg
);
1883 if (gtk_dialog_run (GTK_DIALOG (dialog
)) == GTK_RESPONSE_YES
)
1885 debugger_stop_program (debugger
);
1886 debugger_attach_process_real (debugger
, pid
);
1888 gtk_widget_destroy (dialog
);
1890 else if (getpid () == pid
||
1891 anjuta_launcher_get_child_pid (debugger
->priv
->launcher
) == pid
)
1893 anjuta_util_dialog_error (debugger
->priv
->parent_win
,
1894 _("Anjuta is unable to attach to itself."));
1898 debugger_attach_process_real (debugger
, pid
);
1902 debugger_restart_program (Debugger
*debugger
)
1904 DEBUG_PRINT ("In function: debugger_restart_program()");
1906 g_return_if_fail (debugger
->priv
->prog_is_attached
== FALSE
);
1909 debugger->priv->post_execution_flag = DEBUGGER_RERUN_PROGRAM;
1910 debugger_stop_program (debugger);
1912 debugger_put_cmd_in_queqe ("tbreak main", DB_CMD_NONE, NULL, NULL);
1913 debugger_put_cmd_in_queqe ("run >/dev/null 2>/dev/null", DB_CMD_ALL,
1915 debugger_put_cmd_in_queqe ("info program", DB_CMD_NONE,
1916 on_debugger_update_prog_status, NULL);
1917 debugger_put_cmd_in_queqe ("continue", DB_CMD_NONE, NULL, NULL);
1918 debugger_execute_cmd_in_queqe ();
1923 debugger_stop_program (Debugger
*debugger
)
1925 DEBUG_PRINT ("In function: debugger_stop_program()");
1927 g_return_if_fail (debugger
->priv
->prog_is_running
== TRUE
);
1929 if (debugger
->priv
->prog_is_attached
== TRUE
)
1931 debugger_detach_process (debugger
);
1935 /* FIXME: Why doesn't -exec-abort work??? */
1936 /* debugger_queue_command (debugger, "-exec-abort", NULL, NULL); */
1937 debugger_queue_command (debugger
, "kill", FALSE
, FALSE
, NULL
, NULL
, NULL
);
1938 debugger
->priv
->prog_is_running
= FALSE
;
1939 debugger
->priv
->prog_is_attached
= FALSE
;
1940 g_signal_emit_by_name (debugger
->priv
->instance
, "program-exited");
1941 if (debugger
->priv
->output_callback
)
1943 debugger
->priv
->output_callback (IANJUTA_DEBUGGER_OUTPUT
,
1944 _("Program terminated\n"),
1945 debugger
->priv
->output_user_data
);
1947 debugger_handle_post_execution (debugger
);
1952 debugger_detach_process_finish (Debugger
*debugger
, const GDBMIValue
*mi_results
,
1953 const GList
*cli_results
, GError
*error
)
1955 DEBUG_PRINT ("Program detach finished");
1956 if (debugger
->priv
->output_callback
)
1958 debugger
->priv
->output_callback (IANJUTA_DEBUGGER_OUTPUT
,
1959 _("Program detached\n"),
1960 debugger
->priv
->output_user_data
);
1962 debugger
->priv
->inferior_pid
= 0;
1963 debugger
->priv
->prog_is_attached
= FALSE
;
1964 debugger
->priv
->prog_is_running
= FALSE
;
1965 g_signal_emit_by_name (debugger
->priv
->instance
, "program-exited");
1969 debugger_detach_process (Debugger
*debugger
)
1973 DEBUG_PRINT ("In function: debugger_detach_process()");
1975 g_return_if_fail (debugger
->priv
->prog_is_attached
== TRUE
);
1977 if (debugger
->priv
->output_callback
)
1979 buff
= g_strdup_printf (_("Detaching the process...\n"));
1980 debugger
->priv
->output_callback (IANJUTA_DEBUGGER_OUTPUT
,
1981 buff
, debugger
->priv
->output_user_data
);
1985 debugger_queue_command (debugger
, "detach", FALSE
, FALSE
,
1986 debugger_detach_process_finish
, NULL
, NULL
);
1990 debugger_interrupt (Debugger
*debugger
)
1992 DEBUG_PRINT ("In function: debugger_interrupt()");
1994 g_return_if_fail (IS_DEBUGGER (debugger
));
1995 g_return_if_fail (debugger
->priv
->prog_is_running
== TRUE
);
1997 if (debugger
->priv
->output_callback
)
1999 debugger
->priv
->output_callback (IANJUTA_DEBUGGER_OUTPUT
,
2000 _("Interrupting the process\n"),
2001 debugger
->priv
->output_user_data
);
2004 if (debugger
->priv
->inferior_pid
== 0)
2006 /* In case we do not have the inferior pid, send signal to gdb */
2007 anjuta_launcher_signal (debugger
->priv
->launcher
, SIGINT
);
2011 /* Send signal directly to inferior */
2012 kill (debugger
->priv
->inferior_pid
, SIGINT
);
2014 //g_signal_emit_by_name (debugger->priv->instance, "program-running");
2018 debugger_run (Debugger
*debugger
)
2020 DEBUG_PRINT ("In function: debugger_run()");
2022 g_return_if_fail (IS_DEBUGGER (debugger
));
2023 g_return_if_fail (debugger
->priv
->prog_is_running
== TRUE
);
2025 /* Program running - continue */
2026 debugger_queue_command (debugger
, "-exec-continue", FALSE
, FALSE
, NULL
, NULL
, NULL
);
2030 debugger_step_in (Debugger
*debugger
)
2032 DEBUG_PRINT ("In function: debugger_step_in()");
2034 g_return_if_fail (IS_DEBUGGER (debugger
));
2035 g_return_if_fail (debugger
->priv
->prog_is_running
== TRUE
);
2037 debugger_queue_command (debugger
, "-exec-step", FALSE
, FALSE
, NULL
, NULL
, NULL
);
2041 debugger_step_over (Debugger
*debugger
)
2043 DEBUG_PRINT ("In function: debugger_step_over()");
2045 g_return_if_fail (IS_DEBUGGER (debugger
));
2046 g_return_if_fail (debugger
->priv
->prog_is_running
== TRUE
);
2048 debugger_queue_command (debugger
, "-exec-next", FALSE
, FALSE
, NULL
, NULL
, NULL
);
2052 debugger_step_out (Debugger
*debugger
)
2054 DEBUG_PRINT ("In function: debugger_step_out()");
2056 g_return_if_fail (IS_DEBUGGER (debugger
));
2057 g_return_if_fail (debugger
->priv
->prog_is_running
== TRUE
);
2059 debugger_queue_command (debugger
, "-exec-finish", FALSE
, FALSE
, NULL
, NULL
, NULL
);
2063 debugger_stepi_in (Debugger
*debugger
)
2065 DEBUG_PRINT ("In function: debugger_step_in()");
2067 g_return_if_fail (IS_DEBUGGER (debugger
));
2068 g_return_if_fail (debugger
->priv
->prog_is_running
== TRUE
);
2070 debugger_queue_command (debugger
, "-exec-step-instruction", FALSE
, FALSE
, NULL
, NULL
, NULL
);
2074 debugger_stepi_over (Debugger
*debugger
)
2076 DEBUG_PRINT ("In function: debugger_step_over()");
2078 g_return_if_fail (IS_DEBUGGER (debugger
));
2079 g_return_if_fail (debugger
->priv
->prog_is_running
== TRUE
);
2081 debugger_queue_command (debugger
, "-exec-next-instruction", FALSE
, FALSE
, NULL
, NULL
, NULL
);
2085 debugger_run_to_location (Debugger
*debugger
, const gchar
*loc
)
2089 DEBUG_PRINT ("In function: debugger_run_to_location()");
2091 g_return_if_fail (IS_DEBUGGER (debugger
));
2092 g_return_if_fail (debugger
->priv
->prog_is_running
== TRUE
);
2094 buff
= g_strdup_printf ("-exec-until %s", loc
);
2095 debugger_queue_command (debugger
, buff
, FALSE
, FALSE
, NULL
, NULL
, NULL
);
2100 debugger_run_to_position (Debugger
*debugger
, const gchar
*file
, guint line
)
2105 DEBUG_PRINT ("In function: debugger_run_to_position()");
2107 g_return_if_fail (IS_DEBUGGER (debugger
));
2108 g_return_if_fail (debugger
->priv
->prog_is_running
== TRUE
);
2110 quoted_file
= gdb_quote (file
);
2111 buff
= g_strdup_printf ("-break-insert -t \"\\\"%s\\\":%u\"", quoted_file
, line
);
2112 g_free (quoted_file
);
2113 debugger_queue_command (debugger
, buff
, FALSE
, FALSE
, NULL
, NULL
, NULL
);
2115 debugger_queue_command (debugger
, "-exec-continue", FALSE
, FALSE
, NULL
, NULL
, NULL
);
2119 debugger_run_to_address (Debugger
*debugger
, gulong address
)
2123 DEBUG_PRINT ("In function: debugger_run_to_address()");
2125 g_return_if_fail (IS_DEBUGGER (debugger
));
2126 g_return_if_fail (debugger
->priv
->prog_is_running
== TRUE
);
2128 buff
= g_strdup_printf ("-break-insert -t *0x%lx", address
);
2129 debugger_queue_command (debugger
, buff
, FALSE
, FALSE
, NULL
, NULL
, NULL
);
2131 debugger_queue_command (debugger
, "-exec-continue", FALSE
, FALSE
, NULL
, NULL
, NULL
);
2135 debugger_command (Debugger
*debugger
, const gchar
*command
,
2136 gboolean suppress_error
, DebuggerParserFunc parser
,
2139 if (strncasecmp (command
, "-exec-run",
2140 strlen ("-exec-run")) == 0 ||
2141 strncasecmp (command
, "run", strlen ("run")) == 0)
2143 /* FIXME: The user might have passed args to the command */
2144 debugger_run (debugger
);
2146 else if (strncasecmp (command
, "-exec-step",
2147 strlen ("-exec-step")) == 0 ||
2148 strncasecmp (command
, "step", strlen ("step")) == 0)
2150 debugger_step_in (debugger
);
2152 else if (strncasecmp (command
, "-exec-next",
2153 strlen ("-exec-next")) == 0 ||
2154 strncasecmp (command
, "next", strlen ("next")) == 0)
2156 debugger_step_over (debugger
);
2158 else if (strncasecmp (command
, "-exec-finish",
2159 strlen ("-exec-finish")) == 0 ||
2160 strncasecmp (command
, "finish", strlen ("finish")) == 0)
2162 debugger_step_out (debugger
);
2164 else if (strncasecmp (command
, "-exec-continue",
2165 strlen ("-exec-continue")) == 0 ||
2166 strncasecmp (command
, "continue", strlen ("continue")) == 0)
2168 debugger_run (debugger
);
2170 else if (strncasecmp (command
, "-exec-until",
2171 strlen ("-exec-until")) == 0 ||
2172 strncasecmp (command
, "until", strlen ("until")) == 0)
2174 debugger_run_to_location (debugger
, strchr (command
, ' '));
2176 else if (strncasecmp (command
, "-exec-abort",
2177 strlen ("-exec-abort")) == 0 ||
2178 strncasecmp (command
, "kill", strlen ("kill")) == 0)
2180 debugger_stop_program (debugger
);
2182 else if (strncasecmp (command
, "-target-attach",
2183 strlen ("-target-attach")) == 0 ||
2184 strncasecmp (command
, "attach", strlen ("attach")) == 0)
2187 gchar
*pid_str
= strchr (command
, ' ');
2189 pid
= atoi (pid_str
);
2190 debugger_attach_process (debugger
, pid
);
2192 else if (strncasecmp (command
, "-target-detach",
2193 strlen ("-target-detach")) == 0 ||
2194 strncasecmp (command
, "detach", strlen ("detach")) == 0)
2196 debugger_detach_process (debugger
);
2198 else if (strncasecmp (command
, "-file-exec-and-symbols",
2199 strlen ("-file-exec-and-symbols")) == 0 ||
2200 strncasecmp (command
, "file", strlen ("file")) == 0)
2202 debugger_load_executable (debugger
, strchr (command
, ' '));
2204 else if (strncasecmp (command
, "core", strlen ("core")) == 0)
2206 debugger_load_core (debugger
, strchr (command
, ' '));
2210 debugger_queue_command (debugger
, command
, suppress_error
, FALSE
,
2211 parser
, user_data
, NULL
);
2216 debugger_add_breakpoint_finish (Debugger
*debugger
, const GDBMIValue
*mi_results
, const GList
*cli_results
, GError
*error
)
2218 IAnjutaDebuggerBreakpointItem bp
;
2219 IAnjutaDebuggerCallback callback
= debugger
->priv
->current_cmd
.callback
;
2220 gpointer user_data
= debugger
->priv
->current_cmd
.user_data
;
2222 if ((error
!= NULL
) || (mi_results
== NULL
))
2224 /* Call callback in all case (useful for enable that doesn't return
2226 if (callback
!= NULL
)
2227 callback (NULL
, user_data
, error
);
2229 else if (callback
!= NULL
)
2231 const GDBMIValue
*brkpnt
;
2233 brkpnt
= gdbmi_value_hash_lookup (mi_results
, "bkpt");
2234 parse_breakpoint (&bp
, brkpnt
);
2236 /* Call callback in all case (useful for enable that doesn't return
2238 callback (&bp
, user_data
, error
);
2244 debugger_add_breakpoint_at_line (Debugger
*debugger
, const gchar
*file
, guint line
, IAnjutaDebuggerCallback callback
, gpointer user_data
)
2249 DEBUG_PRINT ("In function: debugger_add_breakpoint()");
2251 g_return_if_fail (IS_DEBUGGER (debugger
));
2253 quoted_file
= gdb_quote (file
);
2255 buff
= g_strdup_printf ("-break-insert \"\\\"%s\\\":%u\"", quoted_file
, line
);
2256 g_free (quoted_file
);
2257 debugger_queue_command (debugger
, buff
, FALSE
, FALSE
, debugger_add_breakpoint_finish
, callback
, user_data
);
2262 debugger_add_breakpoint_at_function (Debugger
*debugger
, const gchar
*file
, const gchar
*function
, IAnjutaDebuggerCallback callback
, gpointer user_data
)
2266 DEBUG_PRINT ("In function: debugger_add_breakpoint()");
2268 g_return_if_fail (IS_DEBUGGER (debugger
));
2270 buff
= g_strdup_printf ("-break-insert %s%s%s", file
== NULL
? "" : file
, file
== NULL
? "" : ":" , function
);
2271 debugger_queue_command (debugger
, buff
, FALSE
, FALSE
, debugger_add_breakpoint_finish
, callback
, user_data
);
2276 debugger_add_breakpoint_at_address (Debugger
*debugger
, gulong address
, IAnjutaDebuggerCallback callback
, gpointer user_data
)
2280 DEBUG_PRINT ("In function: debugger_add_breakpoint()");
2282 g_return_if_fail (IS_DEBUGGER (debugger
));
2284 buff
= g_strdup_printf ("-break-insert *0x%lx", address
);
2285 debugger_queue_command (debugger
, buff
, FALSE
, FALSE
, debugger_add_breakpoint_finish
, callback
, user_data
);
2290 debugger_enable_breakpoint (Debugger
*debugger
, guint id
, gboolean enable
, IAnjutaDebuggerCallback callback
, gpointer user_data
)
2295 DEBUG_PRINT ("In function: debugger_enable_breakpoint()");
2297 g_return_if_fail (IS_DEBUGGER (debugger
));
2299 buff
= g_strdup_printf (enable
? "-break-enable %d" : "-break-disable %d",id
);
2300 debugger_queue_command (debugger
, buff
, FALSE
, FALSE
, debugger_add_breakpoint_finish
, callback
, user_data
);
2305 debugger_ignore_breakpoint (Debugger
*debugger
, guint id
, guint ignore
, IAnjutaDebuggerCallback callback
, gpointer user_data
)
2309 DEBUG_PRINT ("In function: debugger_ignore_breakpoint()");
2311 g_return_if_fail (IS_DEBUGGER (debugger
));
2313 buff
= g_strdup_printf ("-break-after %d %d", id
, ignore
);
2314 debugger_queue_command (debugger
, buff
, FALSE
, FALSE
, debugger_add_breakpoint_finish
, callback
, user_data
);
2319 debugger_condition_breakpoint (Debugger
*debugger
, guint id
, const gchar
*condition
, IAnjutaDebuggerCallback callback
, gpointer user_data
)
2323 DEBUG_PRINT ("In function: debugger_ignore_breakpoint()");
2325 g_return_if_fail (IS_DEBUGGER (debugger
));
2327 buff
= g_strdup_printf ("-break-condition %d %s", id
, condition
== NULL
? "" : condition
);
2328 debugger_queue_command (debugger
, buff
, FALSE
, FALSE
, debugger_add_breakpoint_finish
, callback
, user_data
);
2333 debugger_remove_breakpoint_finish (Debugger
*debugger
, const GDBMIValue
*mi_results
, const GList
*cli_results
, GError
*error
)
2335 IAnjutaDebuggerCallback callback
= debugger
->priv
->current_cmd
.callback
;
2336 gpointer user_data
= debugger
->priv
->current_cmd
.user_data
;
2337 IAnjutaDebuggerBreakpointItem bp
;
2339 bp
.type
= IANJUTA_DEBUGGER_BREAKPOINT_REMOVED
;
2340 bp
.id
= atoi (debugger
->priv
->current_cmd
.cmd
+ 14);
2341 if (callback
!= NULL
)
2342 callback (&bp
, user_data
, NULL
);
2346 debugger_remove_breakpoint (Debugger
*debugger
, guint id
, IAnjutaDebuggerCallback callback
, gpointer user_data
)
2350 DEBUG_PRINT ("In function: debugger_delete_breakpoint()");
2352 g_return_if_fail (IS_DEBUGGER (debugger
));
2354 buff
= g_strdup_printf ("-break-delete %d", id
);
2355 debugger_queue_command (debugger
, buff
, FALSE
, FALSE
, debugger_remove_breakpoint_finish
, callback
, user_data
);
2360 debugger_list_breakpoint_finish (Debugger
*debugger
, const GDBMIValue
*mi_results
, const GList
*cli_results
, GError
*error
)
2362 IAnjutaDebuggerCallback callback
= debugger
->priv
->current_cmd
.callback
;
2363 gpointer user_data
= debugger
->priv
->current_cmd
.user_data
;
2364 IAnjutaDebuggerBreakpointItem
* bp
;
2365 const GDBMIValue
*table
;
2368 if ((error
!= NULL
) || (mi_results
== NULL
))
2370 /* Call callback in all case (useful for enable that doesn't return
2372 if (callback
!= NULL
)
2373 callback (NULL
, user_data
, error
);
2376 table
= gdbmi_value_hash_lookup (mi_results
, "BreakpointTable");
2379 table
= gdbmi_value_hash_lookup (table
, "body");
2385 for (i
= 0; i
< gdbmi_value_get_size (table
); i
++)
2387 const GDBMIValue
*brkpnt
;
2389 bp
= g_new0 (IAnjutaDebuggerBreakpointItem
, 1);
2391 brkpnt
= gdbmi_value_list_get_nth (table
, i
);
2392 parse_breakpoint(bp
, brkpnt
);
2393 list
= g_list_prepend (list
, bp
);
2398 /* Call callback in all case (useful for enable that doesn't return
2400 if (callback
!= NULL
)
2402 list
= g_list_reverse (list
);
2403 callback (list
, user_data
, error
);
2406 g_list_foreach (list
, (GFunc
)g_free
, NULL
);
2411 debugger_list_breakpoint (Debugger
*debugger
, IAnjutaDebuggerCallback callback
, gpointer user_data
)
2413 DEBUG_PRINT ("In function: debugger_list_breakpoint()");
2415 g_return_if_fail (IS_DEBUGGER (debugger
));
2417 debugger_queue_command (debugger
, "-break-list", FALSE
, FALSE
, debugger_list_breakpoint_finish
, callback
, user_data
);
2421 debugger_print_finish (Debugger
*debugger
, const GDBMIValue
*mi_results
, const GList
*cli_results
, GError
*error
)
2426 IAnjutaDebuggerCallback callback
= debugger
->priv
->current_cmd
.callback
;
2427 gpointer user_data
= debugger
->priv
->current_cmd
.user_data
;
2430 list
= gdb_util_remove_blank_lines (cli_results
);
2431 if (g_list_length (list
) < 1)
2437 tmp
= strchr ((gchar
*) list
->data
, '=');
2441 ptr
= g_strdup (tmp
);
2442 for (node
= list
? list
->next
: NULL
; node
!= NULL
; node
= node
->next
)
2445 ptr
= g_strconcat (tmp
, (gchar
*) node
->data
, NULL
);
2450 callback (ptr
, user_data
, NULL
);
2455 debugger_print (Debugger
*debugger
, const gchar
* variable
, IAnjutaDebuggerCallback callback
, gpointer user_data
)
2459 DEBUG_PRINT ("In function: debugger_print()");
2461 g_return_if_fail (IS_DEBUGGER (debugger
));
2463 buff
= g_strdup_printf ("print %s", variable
);
2464 debugger_queue_command (debugger
, buff
, TRUE
, FALSE
, debugger_print_finish
, callback
, user_data
);
2469 debugger_evaluate_finish (Debugger
*debugger
, const GDBMIValue
*mi_results
, const GList
*cli_results
, GError
*error
)
2472 const GDBMIValue
*value
= NULL
;
2473 IAnjutaDebuggerCallback callback
= debugger
->priv
->current_cmd
.callback
;
2474 gpointer user_data
= debugger
->priv
->current_cmd
.user_data
;
2477 value
= gdbmi_value_hash_lookup (mi_results
, "value");
2479 /* Call user function */
2480 if (callback
!= NULL
)
2481 callback (value
== NULL
? "?" : (char *)gdbmi_value_literal_get (value
), user_data
, NULL
);
2485 debugger_evaluate (Debugger
*debugger
, const gchar
* name
, IAnjutaDebuggerCallback callback
, gpointer user_data
)
2488 DEBUG_PRINT ("In function: debugger_add_watch()");
2490 g_return_if_fail (IS_DEBUGGER (debugger
));
2492 buff
= g_strdup_printf ("-data-evaluate-expression %s", name
);
2493 debugger_queue_command (debugger
, buff
, TRUE
, FALSE
, debugger_evaluate_finish
, callback
, user_data
);
2498 debugger_list_local_finish (Debugger
*debugger
, const GDBMIValue
*mi_results
, const GList
*cli_results
, GError
*error
)
2501 const GDBMIValue
*local
, *var
, *frame
, *args
, *stack
;
2505 IAnjutaDebuggerCallback callback
= debugger
->priv
->current_cmd
.callback
;
2506 gpointer user_data
= debugger
->priv
->current_cmd
.user_data
;
2511 stack
= gdbmi_value_hash_lookup (mi_results
, "stack-args");
2514 frame
= gdbmi_value_list_get_nth (stack
, 0);
2517 args
= gdbmi_value_hash_lookup (frame
, "args");
2520 for (i
= 0; i
< gdbmi_value_get_size (args
); i
++)
2522 var
= gdbmi_value_list_get_nth (args
, i
);
2525 name
= gdbmi_value_literal_get (var
);
2526 list
= g_list_prepend (list
, (gchar
*)name
);
2534 /* List local variables */
2535 local
= gdbmi_value_hash_lookup (mi_results
, "locals");
2538 for (i
= 0; i
< gdbmi_value_get_size (local
); i
++)
2540 var
= gdbmi_value_list_get_nth (local
, i
);
2543 name
= gdbmi_value_literal_get (var
);
2544 list
= g_list_prepend (list
, (gchar
*)name
);
2548 list
= g_list_reverse (list
);
2549 callback (list
, user_data
, NULL
);
2554 debugger_list_local (Debugger
*debugger
, IAnjutaDebuggerCallback callback
, gpointer user_data
)
2557 DEBUG_PRINT ("In function: debugger_list_local()");
2559 g_return_if_fail (IS_DEBUGGER (debugger
));
2561 buff
= g_strdup_printf("-stack-list-arguments 0 %d %d", debugger
->priv
->current_frame
, debugger
->priv
->current_frame
);
2562 debugger_queue_command (debugger
, buff
, TRUE
, TRUE
, NULL
, NULL
, NULL
);
2564 debugger_queue_command (debugger
, "-stack-list-locals 0", TRUE
, FALSE
, debugger_list_local_finish
, callback
, user_data
);
2568 debugger_list_argument_finish (Debugger
*debugger
, const GDBMIValue
*mi_results
, const GList
*cli_results
, GError
*error
)
2571 const GDBMIValue
*frame
, *var
, *args
, *stack
;
2575 IAnjutaDebuggerCallback callback
= debugger
->priv
->current_cmd
.callback
;
2576 gpointer user_data
= debugger
->priv
->current_cmd
.user_data
;
2581 stack
= gdbmi_value_hash_lookup (mi_results
, "stack-args");
2584 frame
= gdbmi_value_list_get_nth (stack
, 0);
2587 args
= gdbmi_value_hash_lookup (frame
, "args");
2593 for (i
= 0; i
< gdbmi_value_get_size (args
); i
++)
2595 var
= gdbmi_value_list_get_nth (args
, i
);
2598 name
= gdbmi_value_literal_get (var
);
2599 list
= g_list_prepend (list
, (gchar
*)name
);
2603 list
= g_list_reverse (list
);
2604 callback (list
, user_data
, NULL
);
2609 debugger_list_argument (Debugger
*debugger
, IAnjutaDebuggerCallback callback
, gpointer user_data
)
2613 DEBUG_PRINT ("In function: debugger_list_argument()");
2615 g_return_if_fail (IS_DEBUGGER (debugger
));
2617 buff
= g_strdup_printf("-stack-list-arguments 0 %d %d", debugger
->priv
->current_frame
, debugger
->priv
->current_frame
);
2618 debugger_queue_command (debugger
, buff
, TRUE
, FALSE
, debugger_list_argument_finish
, callback
, user_data
);
2623 debugger_info_finish (Debugger
*debugger
, const GDBMIValue
*mi_results
, const GList
*cli_results
, GError
*error
)
2626 IAnjutaDebuggerCallback callback
= debugger
->priv
->current_cmd
.callback
;
2627 gpointer user_data
= debugger
->priv
->current_cmd
.user_data
;
2629 if (callback
!= NULL
)
2630 callback ((GList
*)cli_results
, user_data
, NULL
);
2634 debugger_info_frame (Debugger
*debugger
, guint frame
, IAnjutaDebuggerCallback callback
, gpointer user_data
)
2638 DEBUG_PRINT ("In function: debugger_info_frame()");
2640 g_return_if_fail (IS_DEBUGGER (debugger
));
2644 buff
= g_strdup_printf("info frame");
2648 buff
= g_strdup_printf ("info frame %d", frame
);
2650 debugger_queue_command (debugger
, buff
, TRUE
, FALSE
, (DebuggerParserFunc
)debugger_info_finish
, callback
, user_data
);
2655 debugger_info_signal (Debugger
*debugger
, IAnjutaDebuggerCallback callback
, gpointer user_data
)
2657 DEBUG_PRINT ("In function: debugger_info_signal()");
2659 g_return_if_fail (IS_DEBUGGER (debugger
));
2661 debugger_queue_command (debugger
, "info signals", TRUE
, FALSE
, (DebuggerParserFunc
)debugger_info_finish
, callback
, user_data
);
2665 debugger_info_sharedlib (Debugger
*debugger
, IAnjutaDebuggerCallback callback
, gpointer user_data
)
2669 DEBUG_PRINT ("In function: debugger_info_sharedlib()");
2671 g_return_if_fail (IS_DEBUGGER (debugger
));
2673 buff
= g_strdup_printf ("info sharedlib");
2674 debugger_queue_command (debugger
, buff
, TRUE
, FALSE
, (DebuggerParserFunc
)debugger_info_finish
, callback
, user_data
); g_free (buff
);
2678 debugger_info_args (Debugger
*debugger
, IAnjutaDebuggerCallback callback
, gpointer user_data
)
2680 DEBUG_PRINT ("In function: debugger_info_args()");
2682 g_return_if_fail (IS_DEBUGGER (debugger
));
2684 debugger_queue_command (debugger
, "info args", TRUE
, FALSE
, (DebuggerParserFunc
)debugger_info_finish
, callback
, user_data
);
2688 debugger_info_target (Debugger
*debugger
, IAnjutaDebuggerCallback callback
, gpointer user_data
)
2690 DEBUG_PRINT ("In function: debugger_info_target()");
2692 g_return_if_fail (IS_DEBUGGER (debugger
));
2694 debugger_queue_command (debugger
, "info target", TRUE
, FALSE
, (DebuggerParserFunc
)debugger_info_finish
, callback
, user_data
);
2698 debugger_info_program (Debugger
*debugger
, IAnjutaDebuggerCallback callback
, gpointer user_data
)
2700 DEBUG_PRINT ("In function: debugger_info_program()");
2702 g_return_if_fail (IS_DEBUGGER (debugger
));
2704 debugger_queue_command (debugger
, "info program", TRUE
, FALSE
, (DebuggerParserFunc
)debugger_info_finish
, callback
, user_data
);
2708 debugger_info_udot (Debugger
*debugger
, IAnjutaDebuggerCallback callback
, gpointer user_data
)
2710 DEBUG_PRINT ("In function: debugger_info_udot()");
2712 g_return_if_fail (IS_DEBUGGER (debugger
));
2714 debugger_queue_command (debugger
, "info udot", TRUE
, FALSE
, (DebuggerParserFunc
)debugger_info_finish
, callback
, user_data
);
2718 debugger_info_variables (Debugger
*debugger
, IAnjutaDebuggerCallback callback
, gpointer user_data
)
2720 DEBUG_PRINT ("In function: debugger_info_variables()");
2722 g_return_if_fail (IS_DEBUGGER (debugger
));
2724 debugger_queue_command (debugger
, "info variables", TRUE
, FALSE
, (DebuggerParserFunc
)debugger_info_finish
, callback
, user_data
);
2728 debugger_read_memory_finish (Debugger
*debugger
, const GDBMIValue
*mi_results
, const GList
*cli_results
, GError
*error
)
2731 const GDBMIValue
*literal
;
2732 const GDBMIValue
*mem
;
2739 IAnjutaDebuggerCallback callback
= debugger
->priv
->current_cmd
.callback
;
2740 gpointer user_data
= debugger
->priv
->current_cmd
.user_data
;
2741 IAnjutaDebuggerMemoryBlock read
= {0,};
2743 literal
= gdbmi_value_hash_lookup (mi_results
, "total-bytes");
2748 len
= strtoul (gdbmi_value_literal_get (literal
), NULL
, 10);
2749 data
= g_new (gchar
, len
* 2);
2750 memset (data
+ len
, 0, len
);
2752 literal
= gdbmi_value_hash_lookup (mi_results
, "addr");
2753 address
= strtoul (gdbmi_value_literal_get (literal
), NULL
, 0);
2757 mem
= gdbmi_value_hash_lookup (mi_results
, "memory");
2760 mem
= gdbmi_value_list_get_nth (mem
, 0);
2763 mem
= gdbmi_value_hash_lookup (mem
, "data");
2766 size
= gdbmi_value_get_size (mem
);
2771 if (size
< len
) len
= size
;
2772 for (i
= 0; i
< len
; i
++)
2774 literal
= gdbmi_value_list_get_nth (mem
, i
);
2778 value
= gdbmi_value_literal_get (literal
);
2779 *ptr
= strtoul (value
, &endptr
, 16);
2780 if ((*value
!= '\0') && (*endptr
== '\0'))
2788 read
.address
= address
;
2791 callback (&read
, user_data
, NULL
);
2797 callback (NULL
, user_data
, NULL
);
2802 debugger_inspect_memory (Debugger
*debugger
, gulong address
, guint length
, IAnjutaDebuggerCallback callback
, gpointer user_data
)
2806 DEBUG_PRINT ("In function: debugger_inspect_memory()");
2808 g_return_if_fail (IS_DEBUGGER (debugger
));
2810 buff
= g_strdup_printf ("-data-read-memory 0x%lx x 1 1 %d", address
, length
);
2811 debugger_queue_command (debugger
, buff
, FALSE
, FALSE
, debugger_read_memory_finish
, callback
, user_data
);
2816 debugger_disassemble_finish (Debugger
*debugger
, const GDBMIValue
*mi_results
, const GList
*cli_results
, GError
*error
)
2819 const GDBMIValue
*literal
;
2820 const GDBMIValue
*line
;
2821 const GDBMIValue
*mem
;
2824 IAnjutaDebuggerCallback callback
= debugger
->priv
->current_cmd
.callback
;
2825 gpointer user_data
= debugger
->priv
->current_cmd
.user_data
;
2826 IAnjutaDebuggerInstructionDisassembly
*read
= NULL
;
2831 callback (NULL
, user_data
, error
);
2837 mem
= gdbmi_value_hash_lookup (mi_results
, "asm_insns");
2842 size
= gdbmi_value_get_size (mem
);
2843 read
= (IAnjutaDebuggerInstructionDisassembly
*)g_malloc0(sizeof (IAnjutaDebuggerInstructionDisassembly
) + sizeof(IAnjutaDebuggerInstructionALine
) * size
);
2846 for (i
= 0; i
< size
; i
++)
2848 line
= gdbmi_value_list_get_nth (mem
, i
);
2852 literal
= gdbmi_value_hash_lookup (line
, "address");
2855 value
= gdbmi_value_literal_get (literal
);
2856 read
->data
[i
].address
= strtoul (value
, NULL
, 0);
2859 /* Get label if one exist */
2860 literal
= gdbmi_value_hash_lookup (line
, "offset");
2863 value
= gdbmi_value_literal_get (literal
);
2864 if ((value
!= NULL
) && (strtoul (value
, NULL
, 0) == 0))
2866 literal
= gdbmi_value_hash_lookup (line
, "func-name");
2869 read
->data
[i
].label
= gdbmi_value_literal_get (literal
);
2876 /* Get disassembly line */
2877 literal
= gdbmi_value_hash_lookup (line
, "inst");
2880 read
->data
[i
].text
= gdbmi_value_literal_get (literal
);
2885 /* Remove last line to mark end */
2886 read
->data
[i
- 1].text
= NULL
;
2888 callback (read
, user_data
, NULL
);
2894 callback (NULL
, user_data
, NULL
);
2899 debugger_disassemble (Debugger
*debugger
, gulong address
, guint length
, IAnjutaDebuggerCallback callback
, gpointer user_data
)
2904 DEBUG_PRINT ("In function: debugger_disassemble()");
2906 g_return_if_fail (IS_DEBUGGER (debugger
));
2909 /* Handle overflow */
2910 end
= (address
+ length
< address
) ? G_MAXULONG
: address
+ length
;
2911 buff
= g_strdup_printf ("-data-disassemble -s 0x%lx -e 0x%lx -- 0", address
, end
);
2912 debugger_queue_command (debugger
, buff
, FALSE
, FALSE
, debugger_disassemble_finish
, callback
, user_data
);
2917 parse_frame (IAnjutaDebuggerFrame
*frame
, const GDBMIValue
*frame_hash
)
2919 const GDBMIValue
*literal
;
2921 literal
= gdbmi_value_hash_lookup (frame_hash
, "level");
2923 frame
->level
= strtoul (gdbmi_value_literal_get (literal
), NULL
, 10);
2927 literal
= gdbmi_value_hash_lookup (frame_hash
, "fullname");
2928 if (literal
== NULL
)
2929 literal
= gdbmi_value_hash_lookup (frame_hash
, "file");
2931 frame
->file
= (gchar
*)gdbmi_value_literal_get (literal
);
2935 literal
= gdbmi_value_hash_lookup (frame_hash
, "line");
2937 frame
->line
= strtoul (gdbmi_value_literal_get (literal
), NULL
, 10);
2941 literal
= gdbmi_value_hash_lookup (frame_hash
, "func");
2943 frame
->function
= (gchar
*)gdbmi_value_literal_get (literal
);
2945 frame
->function
= NULL
;
2947 literal
= gdbmi_value_hash_lookup (frame_hash
, "from");
2949 frame
->library
= (gchar
*)gdbmi_value_literal_get (literal
);
2951 frame
->library
= NULL
;
2953 literal
= gdbmi_value_hash_lookup (frame_hash
, "addr");
2955 frame
->address
= strtoul (gdbmi_value_literal_get (literal
), NULL
, 16);
2963 add_frame (const GDBMIValue
*frame_hash
, GdbGListPacket
* pack
)
2965 IAnjutaDebuggerFrame
* frame
;
2967 frame
= g_new0 (IAnjutaDebuggerFrame
, 1);
2968 pack
->list
= g_list_prepend (pack
->list
, frame
);
2970 frame
->thread
= pack
->tag
;
2971 parse_frame (frame
, frame_hash
);
2975 set_func_args (const GDBMIValue
*frame_hash
, GList
** node
)
2978 const GDBMIValue
*literal
, *args_list
, *arg_hash
;
2981 IAnjutaDebuggerFrame
* frame
;
2983 literal
= gdbmi_value_hash_lookup (frame_hash
, "level");
2987 level
= gdbmi_value_literal_get (literal
);
2991 frame
= (IAnjutaDebuggerFrame
*)(*node
)->data
;
2993 args_list
= gdbmi_value_hash_lookup (frame_hash
, "args");
2996 args_str
= g_string_new ("(");
2997 for (i
= 0; i
< gdbmi_value_get_size (args_list
); i
++)
2999 const gchar
*name
, *value
;
3001 arg_hash
= gdbmi_value_list_get_nth (args_list
, i
);
3005 literal
= gdbmi_value_hash_lookup (arg_hash
, "name");
3008 name
= gdbmi_value_literal_get (literal
);
3012 literal
= gdbmi_value_hash_lookup (arg_hash
, "value");
3015 value
= gdbmi_value_literal_get (literal
);
3018 args_str
= g_string_append (args_str
, name
);
3019 args_str
= g_string_append (args_str
, "=");
3020 args_str
= g_string_append (args_str
, value
);
3021 if (i
< (gdbmi_value_get_size (args_list
) - 1))
3022 args_str
= g_string_append (args_str
, ", ");
3024 args_str
= g_string_append (args_str
, ")");
3025 frame
->args
= args_str
->str
;
3026 g_string_free (args_str
, FALSE
);
3028 *node
= g_list_next (*node
);
3032 debugger_stack_finish (Debugger
*debugger
, const GDBMIValue
*mi_results
, const GList
*cli_results
, GError
*error
)
3035 GdbGListPacket pack
= {NULL
, 0};
3037 const GDBMIValue
*stack_list
;
3038 IAnjutaDebuggerCallback callback
= debugger
->priv
->current_cmd
.callback
;
3039 gpointer user_data
= debugger
->priv
->current_cmd
.user_data
;
3044 stack_list
= gdbmi_value_hash_lookup (mi_results
, "stack");
3047 pack
.tag
= debugger
->priv
->current_thread
;
3048 gdbmi_value_foreach (stack_list
, (GFunc
)add_frame
, &pack
);
3053 pack
.list
= g_list_reverse (pack
.list
);
3054 node
= g_list_first (pack
.list
);
3055 stack_list
= gdbmi_value_hash_lookup (mi_results
, "stack-args");
3057 gdbmi_value_foreach (stack_list
, (GFunc
)set_func_args
, &node
);
3059 // Call call back function
3060 if (callback
!= NULL
)
3061 callback (pack
.list
, user_data
, NULL
);
3064 for (node
= g_list_first (pack
.list
); node
!= NULL
; node
= g_list_next (node
))
3066 g_free ((gchar
*)((IAnjutaDebuggerFrame
*)node
->data
)->args
);
3067 g_free (node
->data
);
3070 g_list_free (pack
.list
);
3074 // Call call back function
3075 if (callback
!= NULL
)
3076 callback (NULL
, user_data
, NULL
);
3081 debugger_list_frame (Debugger
*debugger
, IAnjutaDebuggerCallback callback
, gpointer user_data
)
3083 DEBUG_PRINT ("In function: debugger_list_frame()");
3085 g_return_if_fail (IS_DEBUGGER (debugger
));
3087 debugger_queue_command (debugger
, "-stack-list-frames", TRUE
, TRUE
, NULL
, NULL
, NULL
);
3088 debugger_queue_command (debugger
, "-stack-list-arguments 1", TRUE
, FALSE
, debugger_stack_finish
, callback
, user_data
);
3092 *---------------------------------------------------------------------------*/
3095 debugger_set_thread_finish (Debugger
*debugger
, const GDBMIValue
*mi_results
, const GList
*cli_results
, GError
*error
)
3097 const GDBMIValue
*literal
;
3100 if (mi_results
== NULL
) return;
3102 literal
= gdbmi_value_hash_lookup (mi_results
, "new-thread-id");
3103 if (literal
== NULL
) return;
3105 id
= strtoul (gdbmi_value_literal_get (literal
), NULL
, 10);
3106 if (id
== 0) return;
3108 debugger
->priv
->current_thread
= id
;
3109 g_signal_emit_by_name (debugger
->priv
->instance
, "frame-changed", 0, debugger
->priv
->current_thread
);
3115 debugger_set_thread (Debugger
*debugger
, gint thread
)
3119 DEBUG_PRINT ("In function: debugger_set_thread()");
3121 g_return_if_fail (IS_DEBUGGER (debugger
));
3123 buff
= g_strdup_printf ("-thread-select %d", thread
);
3125 debugger_queue_command (debugger
, buff
, FALSE
, FALSE
, (DebuggerParserFunc
)debugger_set_thread_finish
, NULL
, NULL
);
3130 add_thread_id (const GDBMIValue
*thread_hash
, GList
** list
)
3132 IAnjutaDebuggerFrame
* frame
;
3135 thread
= strtoul (gdbmi_value_literal_get (thread_hash
), NULL
, 10);
3136 if (thread
== 0) return;
3138 frame
= g_new0 (IAnjutaDebuggerFrame
, 1);
3139 *list
= g_list_prepend (*list
, frame
);
3141 frame
->thread
= thread
;
3145 debugger_list_thread_finish (Debugger
*debugger
, const GDBMIValue
*mi_results
, const GList
*cli_results
, GError
*error
)
3148 const GDBMIValue
*id_list
;
3149 gpointer user_data
= debugger
->priv
->current_cmd
.user_data
;
3150 IAnjutaDebuggerCallback callback
= debugger
->priv
->current_cmd
.callback
;
3151 GList
* thread_list
= NULL
;
3155 if (mi_results
== NULL
) break;
3157 id_list
= gdbmi_value_hash_lookup (mi_results
, "thread-ids");
3158 if (id_list
== NULL
) break;
3160 gdbmi_value_foreach (id_list
, (GFunc
)add_thread_id
, &thread_list
);
3161 thread_list
= g_list_reverse (thread_list
);
3165 if (callback
!= NULL
)
3166 callback (thread_list
, user_data
, error
);
3168 if (thread_list
!= NULL
)
3170 g_list_foreach (thread_list
, (GFunc
)g_free
, NULL
);
3171 g_list_free (thread_list
);
3176 debugger_list_thread (Debugger
*debugger
, IAnjutaDebuggerCallback callback
, gpointer user_data
)
3178 DEBUG_PRINT ("In function: debugger_list_thread()");
3180 g_return_if_fail (IS_DEBUGGER (debugger
));
3182 debugger_queue_command (debugger
, "-thread-list-ids", TRUE
, FALSE
, debugger_list_thread_finish
, callback
, user_data
);
3186 debugger_info_set_thread_finish (Debugger
*debugger
, const GDBMIValue
*mi_results
, const GList
*cli_results
, GError
*error
)
3188 const GDBMIValue
*literal
;
3191 if (mi_results
== NULL
) return;
3193 literal
= gdbmi_value_hash_lookup (mi_results
, "new-thread-id");
3194 if (literal
== NULL
) return;
3196 id
= strtoul (gdbmi_value_literal_get (literal
), NULL
, 10);
3197 if (id
== 0) return;
3199 debugger
->priv
->current_thread
= id
;
3200 /* Do not emit a signal notification as the current thread will
3201 * be restored when needed */
3207 debugger_info_thread_finish (Debugger
*debugger
, const GDBMIValue
*mi_results
, const GList
*cli_results
, GError
*error
)
3209 const GDBMIValue
*frame
;
3210 IAnjutaDebuggerFrame top_frame
;
3211 IAnjutaDebuggerFrame
*top
;
3212 IAnjutaDebuggerCallback callback
= debugger
->priv
->current_cmd
.callback
;
3213 gpointer user_data
= debugger
->priv
->current_cmd
.user_data
;
3217 DEBUG_PRINT("look for stack %p", mi_results
);
3218 if (mi_results
== NULL
) break;
3220 frame
= gdbmi_value_hash_lookup (mi_results
, "stack");
3221 if (frame
== NULL
) break;
3223 DEBUG_PRINT("get stack");
3225 frame
= gdbmi_value_list_get_nth (frame
, 0);
3226 if (frame
== NULL
) break;
3228 DEBUG_PRINT("get nth element");
3230 /*frame = gdbmi_value_hash_lookup (frame, "frame");
3231 DEBUG_PRINT("get frame %p", frame);
3232 if (frame == NULL) break;*/
3234 DEBUG_PRINT("get frame");
3237 top
->thread
= debugger
->priv
->current_thread
;
3239 parse_frame (top
, frame
);
3243 if (callback
!= NULL
)
3244 callback (top
, user_data
, error
);
3250 debugger_info_thread (Debugger
*debugger
, gint thread
, IAnjutaDebuggerCallback callback
, gpointer user_data
)
3255 DEBUG_PRINT ("In function: debugger_info_thread()");
3257 g_return_if_fail (IS_DEBUGGER (debugger
));
3259 orig_thread
= debugger
->priv
->current_thread
;
3260 buff
= g_strdup_printf ("-thread-select %d", thread
);
3261 debugger_queue_command (debugger
, buff
, FALSE
, FALSE
, (DebuggerParserFunc
)debugger_info_set_thread_finish
, NULL
, NULL
);
3263 debugger_queue_command (debugger
, "-stack-list-frames 0 0", FALSE
, FALSE
, (DebuggerParserFunc
)debugger_info_thread_finish
, callback
, user_data
);
3265 buff
= g_strdup_printf ("-thread-select %d", orig_thread
);
3266 debugger_queue_command (debugger
, buff
, FALSE
, FALSE
, (DebuggerParserFunc
)debugger_info_set_thread_finish
, NULL
, NULL
);
3271 add_register_name (const GDBMIValue
*reg_literal
, GList
** list
)
3273 IAnjutaDebuggerRegisterData
* reg
;
3274 GList
*prev
= *list
;
3276 reg
= g_new0 (IAnjutaDebuggerRegisterData
, 1);
3277 *list
= g_list_prepend (prev
, reg
);
3278 reg
->name
= (gchar
*)gdbmi_value_literal_get (reg_literal
);
3279 reg
->num
= prev
== NULL
? 0 : ((IAnjutaDebuggerRegisterData
*)prev
->data
)->num
+ 1;
3283 add_register_value (const GDBMIValue
*reg_hash
, GList
** list
)
3285 const GDBMIValue
*literal
;
3287 IAnjutaDebuggerRegisterData
* reg
;
3289 GList
* prev
= *list
;
3291 literal
= gdbmi_value_hash_lookup (reg_hash
, "number");
3294 val
= gdbmi_value_literal_get (literal
);
3295 num
= strtoul (val
, NULL
, 10);
3297 literal
= gdbmi_value_hash_lookup (reg_hash
, "value");
3301 reg
= g_new0 (IAnjutaDebuggerRegisterData
, 1);
3302 *list
= g_list_prepend (prev
, reg
);
3304 reg
->value
= (gchar
*)gdbmi_value_literal_get (literal
);
3308 debugger_register_name_finish (Debugger
*debugger
, const GDBMIValue
*mi_results
, const GList
*cli_results
, GError
*error
)
3313 const GDBMIValue
*reg_list
;
3314 IAnjutaDebuggerCallback callback
= debugger
->priv
->current_cmd
.callback
;
3315 gpointer user_data
= debugger
->priv
->current_cmd
.user_data
;
3320 reg_list
= gdbmi_value_hash_lookup (mi_results
, "register-names");
3322 gdbmi_value_foreach (reg_list
, (GFunc
)add_register_name
, &list
);
3323 list
= g_list_reverse (list
);
3325 // Call call back function
3326 if (callback
!= NULL
)
3327 callback (list
, user_data
, NULL
);
3330 for (node
= g_list_first (list
); node
!= NULL
; node
= g_list_next (node
))
3332 g_free (node
->data
);
3338 debugger_register_value_finish (Debugger
*debugger
, const GDBMIValue
*mi_results
, const GList
*cli_results
, GError
*error
)
3343 const GDBMIValue
*reg_list
;
3344 IAnjutaDebuggerCallback callback
= debugger
->priv
->current_cmd
.callback
;
3345 gpointer user_data
= debugger
->priv
->current_cmd
.user_data
;
3350 reg_list
= gdbmi_value_hash_lookup (mi_results
, "register-values");
3352 gdbmi_value_foreach (reg_list
, (GFunc
)add_register_value
, &list
);
3353 list
= g_list_reverse (list
);
3355 // Call call back function
3356 if (callback
!= NULL
)
3357 callback (list
, user_data
, NULL
);
3360 for (node
= g_list_first (list
); node
!= NULL
; node
= g_list_next (node
))
3362 g_free (node
->data
);
3368 debugger_list_register (Debugger
*debugger
, IAnjutaDebuggerCallback callback
, gpointer user_data
)
3370 DEBUG_PRINT ("In function: debugger_list_register()");
3372 g_return_if_fail (IS_DEBUGGER (debugger
));
3374 debugger_queue_command (debugger
, "-data-list-register-names", TRUE
, FALSE
, debugger_register_name_finish
, callback
, user_data
);
3378 debugger_update_register (Debugger
*debugger
, IAnjutaDebuggerCallback callback
, gpointer user_data
)
3380 DEBUG_PRINT ("In function: debugger_update_register()");
3382 g_return_if_fail (IS_DEBUGGER (debugger
));
3384 debugger_queue_command (debugger
, "-data-list-register-values r", TRUE
, FALSE
, (DebuggerParserFunc
)debugger_register_value_finish
, callback
, user_data
);
3388 debugger_write_register (Debugger
*debugger
, const gchar
*name
, const gchar
*value
)
3392 DEBUG_PRINT ("In function: debugger_write_register()");
3394 g_return_if_fail (IS_DEBUGGER (debugger
));
3396 buf
= g_strdup_printf ("-data-evaluate-expression \"$%s=%s\"", name
, value
);
3397 debugger_queue_command (debugger
, buf
, TRUE
, FALSE
, NULL
, NULL
, NULL
);
3402 debugger_set_frame_finish (Debugger
*debugger
, const GDBMIValue
*mi_results
, const GList
*cli_results
, GError
*error
)
3405 guint frame
= (guint
)debugger
->priv
->current_cmd
.user_data
;
3406 debugger
->priv
->current_frame
= frame
;
3408 g_signal_emit_by_name (debugger
->priv
->instance
, "frame-changed", frame
, debugger
->priv
->current_thread
);
3412 debugger_set_frame (Debugger
*debugger
, guint frame
)
3416 DEBUG_PRINT ("In function: debugger_set_frame()");
3418 g_return_if_fail (IS_DEBUGGER (debugger
));
3420 buff
= g_strdup_printf ("-stack-select-frame %d", frame
);
3422 debugger_queue_command (debugger
, buff
, FALSE
, FALSE
, (DebuggerParserFunc
)debugger_set_frame_finish
, NULL
, (gpointer
)frame
);
3427 debugger_set_log (Debugger
*debugger
, IAnjutaMessageView
*log
)
3429 debugger
->priv
->log
= log
;
3432 /* Variable objects functions
3433 *---------------------------------------------------------------------------*/
3436 debugger_delete_variable (Debugger
*debugger
, const gchar
* name
)
3440 DEBUG_PRINT ("In function: delete_variable()");
3442 g_return_if_fail (IS_DEBUGGER (debugger
));
3444 buff
= g_strdup_printf ("-var-delete %s", name
);
3445 debugger_queue_command (debugger
, buff
, FALSE
, FALSE
, NULL
, NULL
, NULL
);
3450 gdb_var_evaluate_expression (Debugger
*debugger
,
3451 const GDBMIValue
*mi_results
, const GList
*cli_results
,
3454 const gchar
*value
= NULL
;
3455 IAnjutaDebuggerCallback callback
= debugger
->priv
->current_cmd
.callback
;
3456 gpointer user_data
= debugger
->priv
->current_cmd
.user_data
;
3458 if (mi_results
!= NULL
)
3460 const GDBMIValue
*const gdbmi_value
=
3461 gdbmi_value_hash_lookup (mi_results
, "value");
3463 if (gdbmi_value
!= NULL
)
3464 value
= gdbmi_value_literal_get (gdbmi_value
);
3466 callback ((const gpointer
)value
, user_data
, NULL
);
3470 debugger_evaluate_variable (Debugger
*debugger
, const gchar
* name
, IAnjutaDebuggerCallback callback
, gpointer user_data
)
3474 DEBUG_PRINT ("In function: evaluate_variable()");
3476 g_return_if_fail (IS_DEBUGGER (debugger
));
3478 buff
= g_strdup_printf ("-var-evaluate-expression %s", name
);
3479 debugger_queue_command (debugger
, buff
, FALSE
, FALSE
, gdb_var_evaluate_expression
, callback
, user_data
);
3484 debugger_assign_variable (Debugger
*debugger
, const gchar
* name
, const gchar
*value
)
3488 DEBUG_PRINT ("In function: assign_variable()");
3490 g_return_if_fail (IS_DEBUGGER (debugger
));
3492 buff
= g_strdup_printf ("-var-assign %s %s", name
, value
);
3493 debugger_queue_command (debugger
, buff
, FALSE
, FALSE
, NULL
, NULL
, NULL
);
3498 gdb_var_list_children (Debugger
*debugger
,
3499 const GDBMIValue
*mi_results
, const GList
*cli_results
,
3503 IAnjutaDebuggerCallback callback
= debugger
->priv
->current_cmd
.callback
;
3504 gpointer user_data
= debugger
->priv
->current_cmd
.user_data
;
3506 if (mi_results
!= NULL
)
3508 const GDBMIValue
*literal
;
3509 const GDBMIValue
*children
;
3513 literal
= gdbmi_value_hash_lookup (mi_results
, "numchild");
3516 numchild
= strtoul(gdbmi_value_literal_get (literal
), NULL
, 0);
3517 children
= gdbmi_value_hash_lookup (mi_results
, "children");
3519 for(i
= 0 ; i
< numchild
; ++i
)
3521 const GDBMIValue
*const gdbmi_chl
=
3522 gdbmi_value_list_get_nth (children
, i
);
3523 IAnjutaDebuggerVariableObject
*var
;
3525 var
= g_new0 (IAnjutaDebuggerVariableObject
, 1);
3527 literal
= gdbmi_value_hash_lookup (gdbmi_chl
, "name");
3529 var
->name
= (gchar
*)gdbmi_value_literal_get (literal
);
3531 literal
= gdbmi_value_hash_lookup (gdbmi_chl
, "exp");
3533 var
->expression
= (gchar
*)gdbmi_value_literal_get(literal
);
3535 literal
= gdbmi_value_hash_lookup (gdbmi_chl
, "type");
3537 var
->type
= (gchar
*)gdbmi_value_literal_get(literal
);
3539 literal
= gdbmi_value_hash_lookup (gdbmi_chl
, "value");
3541 var
->value
= (gchar
*)gdbmi_value_literal_get(literal
);
3543 literal
= gdbmi_value_hash_lookup (gdbmi_chl
, "numchild");
3545 var
->children
= strtoul(gdbmi_value_literal_get(literal
), NULL
, 10);
3547 list
= g_list_prepend (list
, var
);
3549 list
= g_list_reverse (list
);
3552 callback (list
, user_data
, NULL
);
3553 g_list_foreach (list
, (GFunc
)g_free
, NULL
);
3557 void debugger_list_variable_children (Debugger
*debugger
, const gchar
* name
, IAnjutaDebuggerCallback callback
, gpointer user_data
)
3561 DEBUG_PRINT ("In function: list_variable_children()");
3563 g_return_if_fail (IS_DEBUGGER (debugger
));
3565 buff
= g_strdup_printf ("-var-list-children --all-values %s", name
);
3566 debugger_queue_command (debugger
, buff
, FALSE
, FALSE
, gdb_var_list_children
, callback
, user_data
);
3571 gdb_var_create (Debugger
*debugger
,
3572 const GDBMIValue
*mi_results
, const GList
*cli_results
,
3575 const GDBMIValue
* result
;
3576 IAnjutaDebuggerVariableObject var
= {0,};
3577 IAnjutaDebuggerCallback callback
= debugger
->priv
->current_cmd
.callback
;
3578 gpointer user_data
= debugger
->priv
->current_cmd
.user_data
;
3580 if ((error
== NULL
) && (mi_results
!= NULL
))
3582 result
= gdbmi_value_hash_lookup (mi_results
, "name");
3583 var
.name
= (gchar
*)gdbmi_value_literal_get(result
);
3585 result
= gdbmi_value_hash_lookup (mi_results
, "type");
3586 var
.type
= (gchar
*)gdbmi_value_literal_get (result
);
3588 result
= gdbmi_value_hash_lookup (mi_results
, "numchild");
3589 var
.children
= strtoul (gdbmi_value_literal_get(result
), NULL
, 10);
3591 callback (&var
, user_data
, error
);
3595 void debugger_create_variable (Debugger
*debugger
, const gchar
* name
, IAnjutaDebuggerCallback callback
, gpointer user_data
)
3599 DEBUG_PRINT ("In function: create_variable()");
3601 g_return_if_fail (IS_DEBUGGER (debugger
));
3603 buff
= g_strdup_printf ("-var-create - * %s", name
);
3604 debugger_queue_command (debugger
, buff
, FALSE
, FALSE
, gdb_var_create
, callback
, user_data
);
3609 gdb_var_update (Debugger
*debugger
,
3610 const GDBMIValue
*mi_results
, const GList
*cli_results
,
3614 glong idx
= 0, changed_count
= 0;
3615 const GDBMIValue
*const gdbmi_changelist
=
3616 gdbmi_value_hash_lookup (mi_results
, "changelist");
3617 IAnjutaDebuggerCallback callback
= debugger
->priv
->current_cmd
.callback
;
3618 gpointer user_data
= debugger
->priv
->current_cmd
.user_data
;
3621 changed_count
= gdbmi_value_get_size (gdbmi_changelist
);
3622 for(; idx
<changed_count
; ++idx
)
3624 const GDBMIValue
*const gdbmi_change
=
3625 gdbmi_value_list_get_nth (gdbmi_changelist
, idx
);
3626 const GDBMIValue
* value
;
3629 value
= gdbmi_value_hash_lookup (gdbmi_change
, "name");
3632 IAnjutaDebuggerVariableObject
*var
= g_new0 (IAnjutaDebuggerVariableObject
, 1);
3633 var
->changed
= TRUE
;
3634 var
->name
= (gchar
*)gdbmi_value_literal_get(value
);
3635 list
= g_list_prepend (list
, var
);
3637 value
= gdbmi_value_hash_lookup (gdbmi_change
, "type_changed");
3640 const gchar
*type_changed
= gdbmi_value_literal_get (value
);
3642 if (strcmp (type_changed
, "true"))
3644 var
->deleted
= TRUE
;
3648 value
= gdbmi_value_hash_lookup (gdbmi_change
, "in_scope");
3651 const gchar
*in_scope
= gdbmi_value_literal_get(value
);
3653 if (strcmp (in_scope
, "false") == 0)
3657 else if (strcmp (in_scope
, "invalid") == 0)
3659 var
->deleted
= TRUE
;
3664 list
= g_list_reverse (list
);
3665 callback (list
, user_data
, NULL
);
3666 g_list_foreach (list
, (GFunc
)g_free
, NULL
);
3670 void debugger_update_variable (Debugger
*debugger
, IAnjutaDebuggerCallback callback
, gpointer user_data
)
3672 DEBUG_PRINT ("In function: update_variable()");
3674 g_return_if_fail (IS_DEBUGGER (debugger
));
3676 debugger_queue_command (debugger
, "-var-update *", FALSE
, FALSE
, gdb_var_update
, callback
, user_data
);
3680 debugger_get_type (void)
3682 static GType obj_type
= 0;
3686 static const GTypeInfo obj_info
=
3688 sizeof (DebuggerClass
),
3689 (GBaseInitFunc
) NULL
,
3690 (GBaseFinalizeFunc
) NULL
,
3691 (GClassInitFunc
) debugger_class_init
,
3692 (GClassFinalizeFunc
) NULL
,
3693 NULL
, /* class_data */
3695 0, /* n_preallocs */
3696 (GInstanceInitFunc
) debugger_instance_init
,
3697 NULL
/* value_table */
3699 obj_type
= g_type_register_static (G_TYPE_OBJECT
,
3700 "Debugger", &obj_info
, 0);
3706 debugger_dispose (GObject
*obj
)
3708 Debugger
*debugger
= DEBUGGER (obj
);
3710 DEBUG_PRINT ("In function: debugger_shutdown()");
3712 /* Do not emit signal when the debugger is destroyed */
3713 debugger
->priv
->instance
= NULL
;
3714 debugger_abort (debugger
);
3716 /* Good Bye message */
3717 if (debugger
->priv
->output_callback
)
3719 debugger
->priv
->output_callback (IANJUTA_DEBUGGER_OUTPUT
,
3720 "Debugging session completed.\n",
3721 debugger
->priv
->output_user_data
);
3724 if (debugger
->priv
->launcher
)
3726 anjuta_launcher_reset (debugger
->priv
->launcher
);
3727 g_object_unref (debugger
->priv
->launcher
);
3728 debugger
->priv
->launcher
= NULL
;
3731 G_OBJECT_CLASS (parent_class
)->dispose (obj
);
3735 debugger_finalize (GObject
*obj
)
3737 Debugger
*debugger
= DEBUGGER (obj
);
3738 g_string_free (debugger
->priv
->stdo_line
, TRUE
);
3739 g_string_free (debugger
->priv
->stdo_acc
, TRUE
);
3740 g_string_free (debugger
->priv
->stde_line
, TRUE
);
3741 g_free (debugger
->priv
);
3742 G_OBJECT_CLASS (parent_class
)->finalize (obj
);
3746 debugger_class_init (DebuggerClass
* klass
)
3748 GObjectClass
*object_class
;
3750 g_return_if_fail (klass
!= NULL
);
3751 object_class
= G_OBJECT_CLASS (klass
);
3753 DEBUG_PRINT ("Initializing debugger class");
3755 parent_class
= g_type_class_peek_parent (klass
);
3756 object_class
->dispose
= debugger_dispose
;
3757 object_class
->finalize
= debugger_finalize
;
3763 debugger_signal (const gchar
*sig
, gboolean show_msg
)
3765 /* eg:- "SIGTERM" */
3769 DEBUG_PRINT ("In function: debugger_signal()");
3771 if (debugger_is_active () == FALSE
)
3773 if (debugger
.prog_is_running
== FALSE
)
3775 if (debugger
.child_pid
< 1)
3777 DEBUG_PRINT ("Not sending signal - pid not known\n");
3783 buff
= g_strdup_printf (_("Sending signal %s to the process: %d"),
3784 sig
, (int) debugger
.child_pid
);
3785 gdb_util_append_message (ANJUTA_PLUGIN (debugger
.plugin
), buff
);
3789 if (debugger_is_ready ())
3791 cmd
= g_strconcat ("signal ", sig
, NULL
);
3792 stack_trace_set_frame (debugger
.stack
, 0);
3793 debugger_put_cmd_in_queqe (cmd
, DB_CMD_ALL
, NULL
, NULL
);
3794 debugger_put_cmd_in_queqe ("info program", DB_CMD_NONE
,
3795 on_debugger_update_prog_status
,
3798 debugger_execute_cmd_in_queqe ();
3805 parent
= GTK_WINDOW (ANJUTA_PLUGIN (debugger
.plugin
)->shell
);
3806 status
= gdb_util_kill_process (debugger
.child_pid
, sig
);
3807 if (status
!= 0 && show_msg
)
3808 anjuta_util_dialog_error (parent
,
3809 _("Error whilst signaling the process."));
3814 query_set_cmd (const gchar
*cmd
, gboolean state
)
3817 gchar
*tmp
= g_stpcpy (buffer
, cmd
);
3818 strcpy (tmp
, state
? "on" : "off");
3819 debugger_put_cmd_in_queqe (buffer
, DB_CMD_NONE
, NULL
, NULL
);
3823 query_set_verbose (gboolean state
)
3825 query_set_cmd ("set verbose ", state
);
3829 query_set_print_staticmembers (gboolean state
)
3831 query_set_cmd ("set print static-members ", state
);
3835 query_set_print_pretty (gboolean state
)
3837 query_set_cmd ("set print pretty ", state
);
3840 void debugger_query_evaluate_expr_tip (const gchar
*expr
,
3841 DebuggerCLIFunc parser
, gpointer data
)
3843 query_set_verbose (FALSE
);
3844 query_set_print_staticmembers (FALSE
);
3845 gchar
*printcmd
= g_strconcat ("print ", expr
, NULL
);
3846 debugger_put_cmd_in_queqe (printcmd
, DB_CMD_NONE
, parser
, data
);
3847 query_set_verbose (TRUE
);
3848 query_set_print_staticmembers (TRUE
);
3853 debugger_query_evaluate_expression (const gchar
*expr
, DebuggerFunc parser
,
3856 query_set_print_pretty (TRUE
);
3857 query_set_verbose (FALSE
);
3858 gchar
*printcmd
= g_strconcat ("print ", expr
, NULL
);
3859 debugger_put_cmd_in_queqe (printcmd
, DB_CMD_SE_MESG
| DB_CMD_SE_DIALOG
,
3861 query_set_print_pretty (FALSE
);
3862 query_set_verbose (TRUE
);