Search
lxdream.org :: lxdream/src/gui/debug_win.c :: diff
lxdream 0.9.1
released Jun 29
Download Now
filename src/gui/debug_win.c
changeset 455:3080881d00d4
prev437:2c259474b474
next457:af605fd32c0b
author nkeynes
date Sun Oct 21 05:21:35 2007 +0000 (12 years ago)
permissions -rw-r--r--
last change More GUI WIP
file annotate diff log raw
1.1 --- a/src/gui/debug_win.c Thu Oct 11 08:22:03 2007 +0000
1.2 +++ b/src/gui/debug_win.c Sun Oct 21 05:21:35 2007 +0000
1.3 @@ -1,5 +1,5 @@
1.4 /**
1.5 - * $Id: debug_win.c,v 1.24 2007-10-11 08:22:03 nkeynes Exp $
1.6 + * $Id: debug_win.c,v 1.25 2007-10-21 05:21:35 nkeynes Exp $
1.7 * This file is responsible for the main debugger gui frame.
1.8 *
1.9 * Copyright (c) 2005 Nathan Keynes.
1.10 @@ -17,11 +17,10 @@
1.11 #include <stdlib.h>
1.12 #include <stdarg.h>
1.13 #include <stdio.h>
1.14 +#include <math.h>
1.15 #include <gnome.h>
1.16 -#include <math.h>
1.17 #include "mem.h"
1.18 #include "cpu.h"
1.19 -#include "debugif.h"
1.20 #include "gui/gtkui.h"
1.21 #include "sh4/sh4dasm.h"
1.22 #include "aica/armdasm.h"
1.23 @@ -37,61 +36,153 @@
1.24 void set_disassembly_region( debug_window_t data, unsigned int page );
1.25 void set_disassembly_cpu( debug_window_t data, const gchar *cpu );
1.26
1.27 +void on_mode_field_changed ( GtkEditable *editable, gpointer user_data);
1.28 +gboolean on_page_field_key_press_event( GtkWidget * widget, GdkEventKey *event,
1.29 + gpointer user_data);
1.30 +void on_jump_pc_btn_clicked( GtkButton *button, gpointer user_data);
1.31 +void on_disasm_list_select_row (GtkCList *clist, gint row, gint column,
1.32 + GdkEvent *event, gpointer user_data);
1.33 +void on_disasm_list_unselect_row (GtkCList *clist, gint row, gint column,
1.34 + GdkEvent *event, gpointer user_data);
1.35 +
1.36 +
1.37 struct debug_window_info {
1.38 int disasm_from;
1.39 int disasm_to;
1.40 int disasm_pc;
1.41 const struct cpu_desc_struct *cpu;
1.42 const cpu_desc_t *cpu_list;
1.43 - GtkCList *msgs_list;
1.44 GtkCList *regs_list;
1.45 GtkCList *disasm_list;
1.46 GtkEntry *page_field;
1.47 - GtkWidget *win;
1.48 - GtkProgressBar *icounter;
1.49 - char icounter_text[16];
1.50 + GtkWidget *window;
1.51 + GtkWidget *statusbar;
1.52 char saved_regs[0];
1.53 };
1.54
1.55 -debug_window_t debug_window_new( )
1.56 +debug_window_t debug_window_new( const gchar *title, GtkWidget *menubar,
1.57 + GtkWidget *toolbar, GtkAccelGroup *accel_group )
1.58 {
1.59 - GtkWidget *win = create_debug_win();
1.60 - GnomeAppBar *appbar;
1.61 + debug_window_t data = g_malloc0( sizeof(struct debug_window_info) + cpu_list[0]->regs_size );
1.62 + GtkWidget *vbox;
1.63 + GtkWidget *frame;
1.64 +
1.65 + data->window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
1.66 + gtk_window_set_default_size (GTK_WINDOW (data->window), 1000, 700);
1.67 + gtk_window_set_title( GTK_WINDOW(data->window), title );
1.68 + gtk_window_add_accel_group (GTK_WINDOW (data->window), accel_group);
1.69 +
1.70 + gtk_toolbar_set_style( GTK_TOOLBAR(toolbar), GTK_TOOLBAR_ICONS );
1.71 +
1.72 + data->statusbar = gtk_statusbar_new();
1.73 +
1.74 + GtkWidget *hpaned = gtk_hpaned_new ();
1.75 + gtk_paned_set_position (GTK_PANED (hpaned), 800);
1.76 +
1.77 +
1.78 + GtkWidget *disasm_box = gtk_vbox_new(FALSE,0);
1.79 + gtk_paned_pack1 (GTK_PANED (hpaned), disasm_box, TRUE, TRUE);
1.80 +
1.81 + GtkWidget *hbox1 = gtk_hbox_new (FALSE, 0);
1.82 + gtk_box_pack_start (GTK_BOX (disasm_box), hbox1, FALSE, FALSE, 3);
1.83 + gtk_box_pack_start (GTK_BOX (hbox1), gtk_label_new (_("Page")), FALSE, FALSE, 4);
1.84
1.85 - debug_window_t data = g_malloc0( sizeof(struct debug_window_info) + cpu_list[0]->regs_size );
1.86 + data->page_field = GTK_ENTRY(gtk_entry_new ());
1.87 + gtk_box_pack_start (GTK_BOX (hbox1), GTK_WIDGET(data->page_field), FALSE, TRUE, 0);
1.88 +
1.89 + GtkWidget *jump_pc_btn = gtk_button_new_with_mnemonic (_(" Jump to PC "));
1.90 + gtk_box_pack_start (GTK_BOX (hbox1), jump_pc_btn, FALSE, FALSE, 4);
1.91 +
1.92 + gtk_box_pack_start (GTK_BOX (hbox1), gtk_label_new(_("Mode")), FALSE, FALSE, 5);
1.93 +
1.94 + GtkWidget *mode_box = gtk_combo_new ();
1.95 + gtk_box_pack_start (GTK_BOX (hbox1), mode_box, FALSE, FALSE, 0);
1.96 + GList *mode_box_items = NULL;
1.97 + mode_box_items = g_list_append (mode_box_items, (gpointer) _("SH4"));
1.98 + mode_box_items = g_list_append (mode_box_items, (gpointer) _("ARM7"));
1.99 + mode_box_items = g_list_append (mode_box_items, (gpointer) _("ARM7T"));
1.100 + gtk_combo_set_popdown_strings (GTK_COMBO (mode_box), mode_box_items);
1.101 + g_list_free (mode_box_items);
1.102 +
1.103 + GtkWidget *mode_field = GTK_COMBO (mode_box)->entry;
1.104 + gtk_editable_set_editable (GTK_EDITABLE (mode_field), FALSE);
1.105 +
1.106 + GtkWidget *disasm_scroll = gtk_scrolled_window_new (NULL, NULL);
1.107 + gtk_box_pack_start (GTK_BOX (disasm_box), disasm_scroll, TRUE, TRUE, 0);
1.108 + gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (disasm_scroll), GTK_SHADOW_IN);
1.109 + data->disasm_list = GTK_CLIST(gtk_clist_new (4));
1.110 + gtk_clist_set_column_width (GTK_CLIST (data->disasm_list), 0, 80);
1.111 + gtk_clist_set_column_width (GTK_CLIST (data->disasm_list), 2, 80);
1.112 + gtk_clist_set_column_width (GTK_CLIST (data->disasm_list), 3, 80);
1.113 + gtk_clist_set_column_width( data->disasm_list, 1, 16 );
1.114 + gtk_clist_column_titles_hide (GTK_CLIST (data->disasm_list));
1.115 + gtk_container_add (GTK_CONTAINER (disasm_scroll), GTK_WIDGET(data->disasm_list));
1.116 +
1.117 + GtkWidget *reg_scroll = gtk_scrolled_window_new (NULL, NULL);
1.118 + gtk_paned_pack2 (GTK_PANED (hpaned), reg_scroll, FALSE, TRUE);
1.119 + gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (reg_scroll), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
1.120 + gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (reg_scroll), GTK_SHADOW_IN);
1.121 +
1.122 + data->regs_list = GTK_CLIST(gtk_clist_new (2));
1.123 + gtk_container_add (GTK_CONTAINER (reg_scroll), GTK_WIDGET(data->regs_list));
1.124 + gtk_clist_set_column_width (GTK_CLIST (data->regs_list), 0, 80);
1.125 + gtk_clist_set_column_width (GTK_CLIST (data->regs_list), 1, 80);
1.126 + gtk_clist_column_titles_hide (GTK_CLIST (data->regs_list));
1.127 + gtk_widget_modify_font( GTK_WIDGET(data->regs_list), gui_fixed_font );
1.128 +
1.129 + vbox = gtk_vbox_new(FALSE, 0);
1.130 + gtk_container_add( GTK_CONTAINER(data->window), vbox );
1.131 + gtk_box_pack_start( GTK_BOX(vbox), menubar, FALSE, FALSE, 0 );
1.132 + gtk_box_pack_start( GTK_BOX(vbox), toolbar, FALSE, FALSE, 0 );
1.133 + gtk_box_pack_start( GTK_BOX(vbox), hpaned, TRUE, TRUE, 0 );
1.134 + gtk_box_pack_start( GTK_BOX(vbox), data->statusbar, FALSE, FALSE, 0 );
1.135 +
1.136 + g_signal_connect ((gpointer) data->page_field, "key_press_event",
1.137 + G_CALLBACK (on_page_field_key_press_event),
1.138 + data);
1.139 + g_signal_connect ((gpointer) jump_pc_btn, "clicked",
1.140 + G_CALLBACK (on_jump_pc_btn_clicked),
1.141 + data);
1.142 + g_signal_connect ((gpointer) mode_field, "changed",
1.143 + G_CALLBACK (on_mode_field_changed),
1.144 + data);
1.145 + g_signal_connect ((gpointer) data->disasm_list, "select_row",
1.146 + G_CALLBACK (on_disasm_list_select_row),
1.147 + data);
1.148 + g_signal_connect ((gpointer) data->disasm_list, "unselect_row",
1.149 + G_CALLBACK (on_disasm_list_unselect_row),
1.150 + data);
1.151 +
1.152 data->disasm_from = -1;
1.153 data->disasm_to = -1;
1.154 data->disasm_pc = -1;
1.155 data->cpu = cpu_list[0];
1.156 data->cpu_list = cpu_list;
1.157
1.158 - data->regs_list= gtk_object_get_data(GTK_OBJECT(win), "reg_list");
1.159 - data->win = win;
1.160 - gtk_widget_modify_font( GTK_WIDGET(data->regs_list), gui_fixed_font );
1.161 init_register_list( data );
1.162 - data->msgs_list = gtk_object_get_data(GTK_OBJECT(win), "output_list");
1.163 - data->disasm_list = gtk_object_get_data(GTK_OBJECT(win), "disasm_list");
1.164 - gtk_clist_set_column_width( data->disasm_list, 1, 16 );
1.165 - data->page_field = gtk_object_get_data(GTK_OBJECT(win), "page_field");
1.166 -
1.167 - appbar = gtk_object_get_data(GTK_OBJECT(win), "debug_appbar");
1.168 - data->icounter = gnome_appbar_get_progress( appbar );
1.169 - gtk_progress_bar_set_text(data->icounter, "1");
1.170 -
1.171 - gtk_object_set_data( GTK_OBJECT(win), "debug_data", data );
1.172 + gtk_object_set_data( GTK_OBJECT(data->window), "debug_data", data );
1.173 set_disassembly_pc( data, *data->cpu->pc, FALSE );
1.174 debug_window_set_running( data, FALSE );
1.175
1.176 - gtk_widget_show( win );
1.177 + gtk_widget_show_all( data->window );
1.178 return data;
1.179 }
1.180
1.181 void debug_window_show( debug_window_t data, gboolean show )
1.182 {
1.183 if( show ) {
1.184 - gtk_widget_show( data->win );
1.185 + gtk_widget_show( data->window );
1.186 } else {
1.187 - gtk_widget_hide( data->win );
1.188 + gtk_widget_hide( data->window );
1.189 + }
1.190 +}
1.191 +
1.192 +int debug_window_get_selected_row( debug_window_t data )
1.193 +{
1.194 + if( data->disasm_list->selection == NULL ) {
1.195 + return -1;
1.196 + } else {
1.197 + return GPOINTER_TO_INT(data->disasm_list->selection->data);
1.198 }
1.199 }
1.200
1.201 @@ -144,7 +235,7 @@
1.202 }
1.203 }
1.204
1.205 - set_disassembly_pc( data, *data->cpu->pc, FALSE );
1.206 + set_disassembly_pc( data, *data->cpu->pc, TRUE );
1.207 memcpy( data->saved_regs, data->cpu->regs, data->cpu->regs_size );
1.208 }
1.209
1.210 @@ -250,7 +341,7 @@
1.211 }
1.212 }
1.213
1.214 -void debug_win_toggle_breakpoint( debug_window_t data, int row )
1.215 +void debug_window_toggle_breakpoint( debug_window_t data, int row )
1.216 {
1.217 uint32_t pc = row_to_address( data, row );
1.218 int oldType = data->cpu->get_breakpoint( pc );
1.219 @@ -263,7 +354,7 @@
1.220 }
1.221 }
1.222
1.223 -void debug_win_set_oneshot_breakpoint( debug_window_t data, int row )
1.224 +void debug_window_set_oneshot_breakpoint( debug_window_t data, int row )
1.225 {
1.226 uint32_t pc = row_to_address( data, row );
1.227 data->cpu->clear_breakpoint( pc, BREAK_ONESHOT );
1.228 @@ -274,7 +365,7 @@
1.229 /**
1.230 * Execute a single instruction using the current CPU mode.
1.231 */
1.232 -void debug_win_single_step( debug_window_t data )
1.233 +void debug_window_single_step( debug_window_t data )
1.234 {
1.235 data->cpu->step_func();
1.236 gtk_gui_update();
1.237 @@ -290,52 +381,6 @@
1.238 return (address - data->disasm_from) / data->cpu->instr_size;
1.239 }
1.240
1.241 -#if 0
1.242 -void emit( void *ptr, int level, const gchar *source, const char *msg, ... )
1.243 -{
1.244 - char buf[20], addr[10] = "", *p;
1.245 - const gchar *arr[4] = {buf, source, addr};
1.246 - int posn;
1.247 - time_t tm = time(NULL);
1.248 - va_list ap;
1.249 - debug_window_t data = NULL;
1.250 - /*
1.251 - if( ptr == NULL )
1.252 - data = debug_win;
1.253 - else data = (debug_window_t)ptr;
1.254 - */
1.255 - if( level > global_msg_level ) {
1.256 - return; // ignored
1.257 - }
1.258 - va_start(ap, msg);
1.259 -
1.260 - strftime( buf, sizeof(buf), "%H:%M:%S", localtime(&tm) );
1.261 -
1.262 - if( data == NULL ) {
1.263 - fprintf( stderr, "%s %08X %-5s ", buf, *sh4_cpu_desc.pc, msg_levels[level] );
1.264 - vfprintf( stderr, msg, ap );
1.265 - fprintf( stderr, "\n" );
1.266 - va_end(ap);
1.267 - return;
1.268 - }
1.269 -
1.270 - p = g_strdup_vprintf( msg, ap );
1.271 - sprintf( addr, "%08X", *data->cpu->pc );
1.272 - arr[3] = p;
1.273 - posn = gtk_clist_append(data->msgs_list, (gchar **)arr);
1.274 - free(p);
1.275 - va_end(ap);
1.276 -
1.277 - gtk_clist_set_foreground( data->msgs_list, posn, msg_colors[level] );
1.278 - gtk_clist_moveto( data->msgs_list, posn, 0, 1.0, 0.0 );
1.279 -
1.280 - /* emit _really_ slows down the emu, to the point where the gui can be
1.281 - * completely unresponsive if I don't include this:
1.282 - */
1.283 - while( gtk_events_pending() )
1.284 - gtk_main_iteration();
1.285 -}
1.286 -#endif
1.287 debug_window_t get_debug_info( GtkWidget *widget ) {
1.288
1.289 GtkWidget *win = gtk_widget_get_toplevel(widget);
1.290 @@ -343,19 +388,57 @@
1.291 return data;
1.292 }
1.293
1.294 -void debug_win_enable_widget( debug_window_t data, const char *name,
1.295 - gboolean enabled )
1.296 -{
1.297 - GtkWidget *widget = GTK_WIDGET(gtk_object_get_data(GTK_OBJECT(data->win), name));
1.298 - gtk_widget_set_sensitive( widget, enabled );
1.299 -}
1.300 -
1.301 void debug_window_set_running( debug_window_t data, gboolean isRunning )
1.302 {
1.303 if( data != NULL ) {
1.304 - debug_win_enable_widget( data, "stop_btn", isRunning );
1.305 - debug_win_enable_widget( data, "step_btn", !isRunning );
1.306 - debug_win_enable_widget( data, "run_btn", !isRunning );
1.307 - debug_win_enable_widget( data, "runto_btn", !isRunning );
1.308 + gtk_gui_enable_action( "SingleStep", !isRunning );
1.309 + gtk_gui_enable_action( "RunTo", !isRunning );
1.310 }
1.311 }
1.312 +
1.313 +void on_mode_field_changed ( GtkEditable *editable, gpointer user_data)
1.314 +{
1.315 + const gchar *text = gtk_entry_get_text( GTK_ENTRY(editable) );
1.316 + set_disassembly_cpu( gtk_gui_get_debugger(), text );
1.317 +}
1.318 +
1.319 +
1.320 +gboolean on_page_field_key_press_event( GtkWidget * widget, GdkEventKey *event,
1.321 + gpointer user_data)
1.322 +{
1.323 + if( event->keyval == GDK_Return || event->keyval == GDK_Linefeed ) {
1.324 + debug_window_t data = get_debug_info(widget);
1.325 + const gchar *text = gtk_entry_get_text( GTK_ENTRY(widget) );
1.326 + gchar *endptr;
1.327 + unsigned int val = strtoul( text, &endptr, 16 );
1.328 + if( text == endptr ) { /* invalid input */
1.329 + char buf[10];
1.330 + sprintf( buf, "%08X", row_to_address(data,0) );
1.331 + gtk_entry_set_text( GTK_ENTRY(widget), buf );
1.332 + } else {
1.333 + set_disassembly_region(data, val);
1.334 + }
1.335 + }
1.336 + return FALSE;
1.337 +}
1.338 +
1.339 +
1.340 +void on_jump_pc_btn_clicked( GtkButton *button, gpointer user_data)
1.341 +{
1.342 + debug_window_t data = get_debug_info( GTK_WIDGET(button) );
1.343 + jump_to_pc( data, TRUE );
1.344 +}
1.345 +
1.346 +void on_disasm_list_select_row (GtkCList *clist, gint row, gint column,
1.347 + GdkEvent *event, gpointer user_data)
1.348 +{
1.349 + gtk_gui_enable_action( "SetBreakpoint", TRUE );
1.350 + gtk_gui_enable_action( "RunTo", TRUE );
1.351 +}
1.352 +
1.353 +void on_disasm_list_unselect_row (GtkCList *clist, gint row, gint column,
1.354 + GdkEvent *event, gpointer user_data)
1.355 +{
1.356 + gtk_gui_enable_action( "SetBreakpoint", FALSE );
1.357 + gtk_gui_enable_action( "RunTo", FALSE );
1.358 +}
.