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
32 #include <libanjuta/anjuta-debug.h>
36 #include "data_view.h"
41 *---------------------------------------------------------------------------*/
44 *---------------------------------------------------------------------------*/
48 DmaDebuggerQueue
*debugger
;
51 DmaDataBuffer
*buffer
;
56 *---------------------------------------------------------------------------*/
59 on_memory_block_read (const IAnjutaDebuggerMemoryBlock
*block
, DmaMemory
*mem
, GError
*err
)
65 /* Command has been cancelled */
69 guint length
= block
->length
;
70 gchar
*data
= block
->data
;
71 gulong address
= block
->address
;
78 /* Skip undefined data */
79 for (start
= tag
; *tag
== 0; tag
++)
82 if (length
== 0) return;
85 address
+= tag
- start
;
87 /* Compute length of defined data */
88 for (start
= tag
; (length
!= 0) && (*tag
!= 0); tag
++)
93 dma_data_buffer_set_data (mem
->buffer
, address
, tag
- start
, data
);
95 address
+= tag
- start
;
100 read_memory_block (gulong address
, gulong length
, gpointer user_data
)
102 DmaMemory
*mem
= (DmaMemory
*)user_data
;
104 if (mem
->debugger
!= NULL
)
106 dma_queue_inspect_memory (
110 (IAnjutaDebuggerCallback
)on_memory_block_read
,
116 dma_memory_update (DmaMemory
*mem
)
118 dma_data_buffer_invalidate(mem
->buffer
);
119 dma_data_view_refresh(DMA_DATA_VIEW (mem
->window
));
123 on_program_stopped (DmaMemory
*mem
)
125 dma_memory_update (mem
);
129 destroy_memory_gui (DmaMemory
*mem
)
132 if (mem
->menu
!= NULL
)
134 gtk_widget_destroy (mem
->menu
);
137 if (mem
->window
!= NULL
)
139 gtk_widget_destroy (mem
->window
);
141 dma_data_buffer_remove_all_page (mem
->buffer
);
145 if (mem
->buffer
!= NULL
)
147 g_object_unref (mem
->buffer
);
153 on_debugger_stopped (DmaMemory
*mem
)
156 g_signal_handlers_disconnect_by_func (mem
->plugin
, G_CALLBACK (on_debugger_stopped
), mem
);
157 g_signal_handlers_disconnect_by_func (mem
->plugin
, G_CALLBACK (on_program_stopped
), mem
);
159 destroy_memory_gui (mem
);
163 create_memory_gui (DmaMemory
*mem
)
167 g_return_val_if_fail (mem
->buffer
== NULL
, FALSE
);
168 g_return_val_if_fail (mem
->window
== NULL
, FALSE
);
170 mem
->buffer
= dma_data_buffer_new (0x0000, 0xFFFFFFFFU
, read_memory_block
, NULL
, mem
);
171 if (mem
->buffer
== NULL
) return FALSE
;
173 dataview
= dma_data_view_new_with_buffer (mem
->buffer
);
174 mem
->window
= dataview
;
176 anjuta_shell_add_widget (mem
->plugin
->shell
,
178 "AnjutaDebuggerMemory", _("Memory"),
179 NULL
, ANJUTA_SHELL_PLACEMENT_CENTER
,
186 on_debugger_started (DmaMemory
*mem
)
188 /* Keep graphical interface if already existing, could happens after
189 * unloading a program in the debugger */
190 if (mem
->window
) return;
192 if (!dma_debugger_queue_is_supported (mem
->debugger
, HAS_MEMORY
)) return;
194 if (!create_memory_gui (mem
)) return;
196 /* Connect signals */
197 g_signal_connect_swapped (mem
->plugin
, "debugger-stopped", G_CALLBACK (on_debugger_stopped
), mem
);
198 g_signal_connect_swapped (mem
->plugin
, "program-stopped", G_CALLBACK (on_program_stopped
), mem
);
201 /* Constructor & Destructor
202 *---------------------------------------------------------------------------*/
205 dma_memory_new(DebugManagerPlugin
*plugin
)
209 mem
= g_new0 (DmaMemory
, 1);
211 mem
->debugger
= dma_debug_manager_get_queue (plugin
);
212 mem
->plugin
= ANJUTA_PLUGIN (plugin
);
214 g_signal_connect_swapped (mem
->plugin
, "debugger-started", G_CALLBACK (on_debugger_started
), mem
);
220 dma_memory_free(DmaMemory
* mem
)
222 g_return_if_fail (mem
!= NULL
);
224 g_signal_handlers_disconnect_matched (mem
->plugin
, G_SIGNAL_MATCH_DATA
, 0, 0, NULL
, NULL
, mem
);
226 destroy_memory_gui (mem
);