1 /* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*- */
4 Copyright (C) 2006 Sebastien Granjoux
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
34 #include <libanjuta/anjuta-debug.h>
38 #include "data_view.h"
43 *---------------------------------------------------------------------------*/
46 *---------------------------------------------------------------------------*/
50 DmaDebuggerQueue
*debugger
;
53 DmaDataView
*dataview
;
54 DmaDataBuffer
*buffer
;
59 *---------------------------------------------------------------------------*/
62 on_memory_block_read (const IAnjutaDebuggerMemoryBlock
*block
, DmaMemory
*mem
, GError
*err
)
68 /* Command has been cancelled */
72 guint length
= block
->length
;
73 gchar
*data
= block
->data
;
74 gulong address
= block
->address
;
81 /* Skip undefined data */
82 for (start
= tag
; *tag
== 0; tag
++)
85 if (length
== 0) return;
88 address
+= tag
- start
;
90 /* Compute length of defined data */
91 for (start
= tag
; (length
!= 0) && (*tag
!= 0); tag
++)
96 dma_data_buffer_set_data (mem
->buffer
, address
, tag
- start
, data
);
98 address
+= tag
- start
;
103 read_memory_block (gulong address
, gulong length
, gpointer user_data
)
105 DmaMemory
*mem
= (DmaMemory
*)user_data
;
107 if (mem
->debugger
!= NULL
)
109 dma_queue_inspect_memory (
113 (IAnjutaDebuggerCallback
)on_memory_block_read
,
119 dma_memory_update (DmaMemory
*mem
)
121 dma_data_buffer_invalidate(mem
->buffer
);
122 dma_data_view_refresh(mem
->dataview
);
126 on_program_stopped (DmaMemory
*mem
)
128 dma_memory_update (mem
);
132 destroy_memory_gui (DmaMemory
*mem
)
135 if (mem
->menu
!= NULL
)
137 gtk_widget_destroy (mem
->menu
);
140 if (mem
->window
!= NULL
)
142 gtk_widget_destroy (mem
->window
);
144 mem
->dataview
= NULL
;
145 dma_data_buffer_remove_all_page (mem
->buffer
);
149 if (mem
->buffer
!= NULL
)
151 g_object_unref (mem
->buffer
);
157 on_debugger_stopped (DmaMemory
*mem
)
160 g_signal_handlers_disconnect_by_func (mem
->plugin
, G_CALLBACK (on_debugger_stopped
), mem
);
161 g_signal_handlers_disconnect_by_func (mem
->plugin
, G_CALLBACK (on_program_stopped
), mem
);
163 destroy_memory_gui (mem
);
167 create_memory_gui (DmaMemory
*mem
)
169 g_return_val_if_fail (mem
->buffer
== NULL
, FALSE
);
170 g_return_val_if_fail (mem
->window
== NULL
, FALSE
);
172 mem
->buffer
= dma_data_buffer_new (0x0000, 0xFFFFFFFFU
, read_memory_block
, NULL
, mem
);
173 if (mem
->buffer
== NULL
) return FALSE
;
175 mem
->dataview
= (DmaDataView
*)dma_data_view_new_with_buffer (mem
->buffer
);
177 mem
->window
= gtk_frame_new (NULL
);
178 gtk_frame_set_shadow_type (GTK_FRAME (mem
->window
), GTK_SHADOW_IN
);
179 gtk_container_add (GTK_CONTAINER (mem
->window
),
180 GTK_WIDGET (mem
->dataview
));
182 gtk_widget_show_all (mem
->window
);
183 anjuta_shell_add_widget (mem
->plugin
->shell
,
185 "AnjutaDebuggerMemory", _("Memory"),
186 "debugger-memory", ANJUTA_SHELL_PLACEMENT_NONE
,
193 on_debugger_started (DmaMemory
*mem
)
195 /* Keep graphical interface if already existing, could happens after
196 * unloading a program in the debugger */
197 if (mem
->window
) return;
199 if (!dma_debugger_queue_is_supported (mem
->debugger
, HAS_MEMORY
)) return;
201 if (!create_memory_gui (mem
)) return;
203 /* Connect signals */
204 g_signal_connect_swapped (mem
->plugin
, "debugger-stopped", G_CALLBACK (on_debugger_stopped
), mem
);
205 g_signal_connect_swapped (mem
->plugin
, "program-stopped", G_CALLBACK (on_program_stopped
), mem
);
208 /* Constructor & Destructor
209 *---------------------------------------------------------------------------*/
212 dma_memory_new(DebugManagerPlugin
*plugin
)
216 mem
= g_new0 (DmaMemory
, 1);
218 mem
->debugger
= dma_debug_manager_get_queue (plugin
);
219 mem
->plugin
= ANJUTA_PLUGIN (plugin
);
221 g_signal_connect_swapped (mem
->plugin
, "debugger-started", G_CALLBACK (on_debugger_started
), mem
);
227 dma_memory_free(DmaMemory
* mem
)
229 g_return_if_fail (mem
!= NULL
);
231 g_signal_handlers_disconnect_matched (mem
->plugin
, G_SIGNAL_MATCH_DATA
, 0, 0, NULL
, NULL
, mem
);
233 destroy_memory_gui (mem
);