Search
lxdream.org :: lxdream/src/gui/debug_win.c
lxdream 0.9.1
released Jun 29
Download Now
filename src/gui/debug_win.c
changeset 480:d28c2992f5ee
prev457:af605fd32c0b
next484:e2c1476f4c67
author nkeynes
date Wed Oct 31 11:53:35 2007 +0000 (12 years ago)
permissions -rw-r--r--
last change Fix miscellaneous warnings
file annotate diff log raw
nkeynes@10
     1
/**
nkeynes@480
     2
 * $Id: debug_win.c,v 1.27 2007-10-31 11:53:35 nkeynes Exp $
nkeynes@10
     3
 * This file is responsible for the main debugger gui frame.
nkeynes@10
     4
 *
nkeynes@10
     5
 * Copyright (c) 2005 Nathan Keynes.
nkeynes@10
     6
 *
nkeynes@10
     7
 * This program is free software; you can redistribute it and/or modify
nkeynes@10
     8
 * it under the terms of the GNU General Public License as published by
nkeynes@10
     9
 * the Free Software Foundation; either version 2 of the License, or
nkeynes@10
    10
 * (at your option) any later version.
nkeynes@10
    11
 *
nkeynes@10
    12
 * This program is distributed in the hope that it will be useful,
nkeynes@10
    13
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
nkeynes@10
    14
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
nkeynes@10
    15
 * GNU General Public License for more details.
nkeynes@10
    16
 */
nkeynes@2
    17
#include <stdlib.h>
nkeynes@2
    18
#include <stdarg.h>
nkeynes@69
    19
#include <stdio.h>
nkeynes@455
    20
#include <math.h>
nkeynes@2
    21
#include <gnome.h>
nkeynes@2
    22
#include "mem.h"
nkeynes@30
    23
#include "cpu.h"
nkeynes@435
    24
#include "gui/gtkui.h"
nkeynes@435
    25
#include "sh4/sh4dasm.h"
nkeynes@435
    26
#include "aica/armdasm.h"
nkeynes@2
    27
nkeynes@435
    28
GdkColor *msg_colors[] = { &gui_colour_error, &gui_colour_error, &gui_colour_warn, 
nkeynes@435
    29
			   &gui_colour_normal,&gui_colour_debug, &gui_colour_trace };
nkeynes@2
    30
nkeynes@435
    31
const cpu_desc_t cpu_list[4] = { &sh4_cpu_desc, &arm_cpu_desc, &armt_cpu_desc, NULL };
nkeynes@45
    32
nkeynes@435
    33
void init_register_list( debug_window_t data );
nkeynes@435
    34
uint32_t row_to_address( debug_window_t data, int row );
nkeynes@480
    35
int address_to_row( debug_window_t data, uint32_t address );
nkeynes@435
    36
void set_disassembly_pc( debug_window_t data, unsigned int pc, gboolean select );
nkeynes@435
    37
void set_disassembly_region( debug_window_t data, unsigned int page );
nkeynes@435
    38
void set_disassembly_cpu( debug_window_t data, const gchar *cpu );
nkeynes@435
    39
nkeynes@455
    40
void on_mode_field_changed ( GtkEditable *editable, gpointer user_data);
nkeynes@455
    41
gboolean on_page_field_key_press_event( GtkWidget * widget, GdkEventKey *event,
nkeynes@455
    42
                                        gpointer user_data);
nkeynes@455
    43
void on_jump_pc_btn_clicked( GtkButton *button, gpointer user_data);
nkeynes@455
    44
void on_disasm_list_select_row (GtkCList *clist, gint row, gint column,
nkeynes@455
    45
				GdkEvent *event, gpointer user_data);
nkeynes@455
    46
void on_disasm_list_unselect_row (GtkCList *clist, gint row, gint column,
nkeynes@455
    47
				  GdkEvent *event, gpointer user_data);
nkeynes@457
    48
gboolean on_debug_delete_event(GtkWidget *widget, GdkEvent event, gpointer user_data);
nkeynes@455
    49
nkeynes@435
    50
struct debug_window_info {
nkeynes@9
    51
    int disasm_from;
nkeynes@9
    52
    int disasm_to;
nkeynes@9
    53
    int disasm_pc;
nkeynes@429
    54
    const struct cpu_desc_struct *cpu;
nkeynes@392
    55
    const cpu_desc_t *cpu_list;
nkeynes@9
    56
    GtkCList *regs_list;
nkeynes@9
    57
    GtkCList *disasm_list;
nkeynes@9
    58
    GtkEntry *page_field;
nkeynes@455
    59
    GtkWidget *window;
nkeynes@455
    60
    GtkWidget *statusbar;
nkeynes@9
    61
    char saved_regs[0];
nkeynes@8
    62
};
nkeynes@8
    63
nkeynes@455
    64
debug_window_t debug_window_new( const gchar *title, GtkWidget *menubar, 
nkeynes@455
    65
				 GtkWidget *toolbar, GtkAccelGroup *accel_group )
nkeynes@2
    66
{
nkeynes@455
    67
    debug_window_t data = g_malloc0( sizeof(struct debug_window_info) + cpu_list[0]->regs_size );
nkeynes@455
    68
        GtkWidget *vbox;
nkeynes@455
    69
nkeynes@455
    70
    data->window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
nkeynes@455
    71
    gtk_window_set_default_size (GTK_WINDOW (data->window), 1000, 700);
nkeynes@455
    72
    gtk_window_set_title( GTK_WINDOW(data->window), title );
nkeynes@455
    73
    gtk_window_add_accel_group (GTK_WINDOW (data->window), accel_group);
nkeynes@455
    74
nkeynes@455
    75
    gtk_toolbar_set_style( GTK_TOOLBAR(toolbar), GTK_TOOLBAR_ICONS );
nkeynes@455
    76
nkeynes@455
    77
    data->statusbar = gtk_statusbar_new();
nkeynes@455
    78
nkeynes@455
    79
    GtkWidget *hpaned = gtk_hpaned_new ();
nkeynes@455
    80
    gtk_paned_set_position (GTK_PANED (hpaned), 800);
nkeynes@455
    81
nkeynes@455
    82
    GtkWidget *disasm_box = gtk_vbox_new(FALSE,0);
nkeynes@455
    83
    gtk_paned_pack1 (GTK_PANED (hpaned), disasm_box, TRUE, TRUE);
nkeynes@455
    84
nkeynes@455
    85
    GtkWidget *hbox1 = gtk_hbox_new (FALSE, 0);
nkeynes@455
    86
    gtk_box_pack_start (GTK_BOX (disasm_box), hbox1, FALSE, FALSE, 3);
nkeynes@455
    87
    gtk_box_pack_start (GTK_BOX (hbox1), gtk_label_new (_("Page")), FALSE, FALSE, 4);
nkeynes@9
    88
    
nkeynes@455
    89
    data->page_field = GTK_ENTRY(gtk_entry_new ());
nkeynes@455
    90
    gtk_box_pack_start (GTK_BOX (hbox1), GTK_WIDGET(data->page_field), FALSE, TRUE, 0);
nkeynes@455
    91
    
nkeynes@455
    92
    GtkWidget *jump_pc_btn = gtk_button_new_with_mnemonic (_(" Jump to PC "));
nkeynes@455
    93
    gtk_box_pack_start (GTK_BOX (hbox1), jump_pc_btn, FALSE, FALSE, 4);
nkeynes@455
    94
    
nkeynes@455
    95
    gtk_box_pack_start (GTK_BOX (hbox1), gtk_label_new(_("Mode")), FALSE, FALSE, 5);
nkeynes@455
    96
    
nkeynes@455
    97
    GtkWidget *mode_box = gtk_combo_new ();
nkeynes@455
    98
    gtk_box_pack_start (GTK_BOX (hbox1), mode_box, FALSE, FALSE, 0);
nkeynes@455
    99
    GList *mode_box_items = NULL;
nkeynes@455
   100
    mode_box_items = g_list_append (mode_box_items, (gpointer) _("SH4"));
nkeynes@455
   101
    mode_box_items = g_list_append (mode_box_items, (gpointer) _("ARM7"));
nkeynes@455
   102
    mode_box_items = g_list_append (mode_box_items, (gpointer) _("ARM7T"));
nkeynes@455
   103
    gtk_combo_set_popdown_strings (GTK_COMBO (mode_box), mode_box_items);
nkeynes@455
   104
    g_list_free (mode_box_items);
nkeynes@455
   105
nkeynes@455
   106
    GtkWidget *mode_field = GTK_COMBO (mode_box)->entry;
nkeynes@455
   107
    gtk_editable_set_editable (GTK_EDITABLE (mode_field), FALSE);
nkeynes@455
   108
nkeynes@455
   109
    GtkWidget *disasm_scroll = gtk_scrolled_window_new (NULL, NULL);
nkeynes@455
   110
    gtk_box_pack_start (GTK_BOX (disasm_box), disasm_scroll, TRUE, TRUE, 0);
nkeynes@455
   111
    gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (disasm_scroll), GTK_SHADOW_IN);
nkeynes@455
   112
    data->disasm_list = GTK_CLIST(gtk_clist_new (4));
nkeynes@455
   113
    gtk_clist_set_column_width (GTK_CLIST (data->disasm_list), 0, 80);
nkeynes@455
   114
    gtk_clist_set_column_width (GTK_CLIST (data->disasm_list), 2, 80);
nkeynes@455
   115
    gtk_clist_set_column_width (GTK_CLIST (data->disasm_list), 3, 80);
nkeynes@455
   116
    gtk_clist_set_column_width( data->disasm_list, 1, 16 );
nkeynes@455
   117
    gtk_clist_column_titles_hide (GTK_CLIST (data->disasm_list));
nkeynes@455
   118
    gtk_container_add (GTK_CONTAINER (disasm_scroll), GTK_WIDGET(data->disasm_list));
nkeynes@455
   119
    
nkeynes@455
   120
    GtkWidget *reg_scroll = gtk_scrolled_window_new (NULL, NULL);
nkeynes@455
   121
    gtk_paned_pack2 (GTK_PANED (hpaned), reg_scroll, FALSE, TRUE);
nkeynes@455
   122
    gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (reg_scroll), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
nkeynes@455
   123
    gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (reg_scroll), GTK_SHADOW_IN);
nkeynes@455
   124
    
nkeynes@455
   125
    data->regs_list = GTK_CLIST(gtk_clist_new (2));
nkeynes@455
   126
    gtk_container_add (GTK_CONTAINER (reg_scroll), GTK_WIDGET(data->regs_list));
nkeynes@455
   127
    gtk_clist_set_column_width (GTK_CLIST (data->regs_list), 0, 80);
nkeynes@455
   128
    gtk_clist_set_column_width (GTK_CLIST (data->regs_list), 1, 80);
nkeynes@455
   129
    gtk_clist_column_titles_hide (GTK_CLIST (data->regs_list));
nkeynes@455
   130
    gtk_widget_modify_font( GTK_WIDGET(data->regs_list), gui_fixed_font );
nkeynes@455
   131
    
nkeynes@455
   132
    vbox = gtk_vbox_new(FALSE, 0);
nkeynes@455
   133
    gtk_container_add( GTK_CONTAINER(data->window), vbox );
nkeynes@455
   134
    gtk_box_pack_start( GTK_BOX(vbox), menubar, FALSE, FALSE, 0 );
nkeynes@455
   135
    gtk_box_pack_start( GTK_BOX(vbox), toolbar, FALSE, FALSE, 0 );
nkeynes@455
   136
    gtk_box_pack_start( GTK_BOX(vbox), hpaned, TRUE, TRUE, 0 );
nkeynes@455
   137
    gtk_box_pack_start( GTK_BOX(vbox), data->statusbar, FALSE, FALSE, 0 );
nkeynes@455
   138
nkeynes@455
   139
    g_signal_connect ((gpointer) data->page_field, "key_press_event",
nkeynes@455
   140
		      G_CALLBACK (on_page_field_key_press_event),
nkeynes@455
   141
		      data);
nkeynes@455
   142
    g_signal_connect ((gpointer) jump_pc_btn, "clicked",
nkeynes@455
   143
		      G_CALLBACK (on_jump_pc_btn_clicked),
nkeynes@455
   144
		      data);
nkeynes@455
   145
    g_signal_connect ((gpointer) mode_field, "changed",
nkeynes@455
   146
		      G_CALLBACK (on_mode_field_changed),
nkeynes@455
   147
		      data);
nkeynes@455
   148
    g_signal_connect ((gpointer) data->disasm_list, "select_row",
nkeynes@455
   149
		      G_CALLBACK (on_disasm_list_select_row),
nkeynes@455
   150
		      data);
nkeynes@455
   151
    g_signal_connect ((gpointer) data->disasm_list, "unselect_row",
nkeynes@455
   152
		      G_CALLBACK (on_disasm_list_unselect_row),
nkeynes@455
   153
		      data);
nkeynes@457
   154
    g_signal_connect ((gpointer) data->window, "delete_event",
nkeynes@457
   155
		      G_CALLBACK (on_debug_delete_event),
nkeynes@457
   156
		      data);
nkeynes@455
   157
    
nkeynes@9
   158
    data->disasm_from = -1;
nkeynes@9
   159
    data->disasm_to = -1;
nkeynes@9
   160
    data->disasm_pc = -1;
nkeynes@11
   161
    data->cpu = cpu_list[0];
nkeynes@11
   162
    data->cpu_list = cpu_list;
nkeynes@9
   163
    
nkeynes@11
   164
    init_register_list( data );
nkeynes@455
   165
    gtk_object_set_data( GTK_OBJECT(data->window), "debug_data", data );
nkeynes@29
   166
    set_disassembly_pc( data, *data->cpu->pc, FALSE );
nkeynes@435
   167
    debug_window_set_running( data, FALSE );
nkeynes@435
   168
nkeynes@455
   169
    gtk_widget_show_all( data->window );
nkeynes@9
   170
    return data;
nkeynes@2
   171
}
nkeynes@2
   172
nkeynes@435
   173
void debug_window_show( debug_window_t data, gboolean show )
nkeynes@435
   174
{
nkeynes@435
   175
    if( show ) {
nkeynes@455
   176
	gtk_widget_show( data->window );
nkeynes@435
   177
    } else {
nkeynes@455
   178
	gtk_widget_hide( data->window );
nkeynes@455
   179
    }
nkeynes@455
   180
}
nkeynes@455
   181
nkeynes@455
   182
int debug_window_get_selected_row( debug_window_t data )
nkeynes@455
   183
{
nkeynes@455
   184
    if( data->disasm_list->selection == NULL ) {
nkeynes@455
   185
	return -1;
nkeynes@455
   186
    } else {
nkeynes@455
   187
	return GPOINTER_TO_INT(data->disasm_list->selection->data);
nkeynes@435
   188
    }
nkeynes@435
   189
}
nkeynes@435
   190
nkeynes@435
   191
void init_register_list( debug_window_t data ) 
nkeynes@11
   192
{
nkeynes@11
   193
    int i;
nkeynes@11
   194
    char buf[20];
nkeynes@11
   195
    char *arr[2];
nkeynes@11
   196
nkeynes@11
   197
    gtk_clist_clear( data->regs_list );
nkeynes@11
   198
    arr[1] = buf;
nkeynes@11
   199
    for( i=0; data->cpu->regs_info[i].name != NULL; i++ ) {
nkeynes@11
   200
        arr[0] = data->cpu->regs_info[i].name;
nkeynes@11
   201
        if( data->cpu->regs_info->type == REG_INT )
nkeynes@11
   202
            sprintf( buf, "%08X", *((uint32_t *)data->cpu->regs_info[i].value) );
nkeynes@11
   203
        else
nkeynes@11
   204
            sprintf( buf, "%f", *((float *)data->cpu->regs_info[i].value) );
nkeynes@11
   205
        gtk_clist_append( data->regs_list, arr );
nkeynes@11
   206
    }
nkeynes@11
   207
}
nkeynes@11
   208
nkeynes@2
   209
/*
nkeynes@2
   210
 * Check for changed registers and update the display
nkeynes@2
   211
 */
nkeynes@435
   212
void debug_window_update( debug_window_t data )
nkeynes@2
   213
{
nkeynes@2
   214
    int i;
nkeynes@9
   215
    for( i=0; data->cpu->regs_info[i].name != NULL; i++ ) {
nkeynes@9
   216
        if( data->cpu->regs_info[i].type == REG_INT ) {
nkeynes@2
   217
            /* Yes this _is_ probably fairly evil */
nkeynes@9
   218
            if( *((uint32_t *)data->cpu->regs_info[i].value) !=
nkeynes@9
   219
                *((uint32_t *)((char *)data->saved_regs + ((char *)data->cpu->regs_info[i].value - (char *)data->cpu->regs))) ) {
nkeynes@2
   220
                char buf[20];
nkeynes@9
   221
                sprintf( buf, "%08X", *((uint32_t *)data->cpu->regs_info[i].value) );
nkeynes@9
   222
                gtk_clist_set_text( data->regs_list, i, 1, buf );
nkeynes@435
   223
                gtk_clist_set_foreground( data->regs_list, i, &gui_colour_changed );
nkeynes@2
   224
            } else {
nkeynes@435
   225
                gtk_clist_set_foreground( data->regs_list, i, &gui_colour_normal );
nkeynes@2
   226
            }
nkeynes@2
   227
        } else {
nkeynes@9
   228
            if( *((float *)data->cpu->regs_info[i].value) !=
nkeynes@9
   229
                *((float *)((char *)data->saved_regs + ((char *)data->cpu->regs_info[i].value - (char *)data->cpu->regs))) ) {
nkeynes@2
   230
                char buf[20];
nkeynes@9
   231
                sprintf( buf, "%f", *((float *)data->cpu->regs_info[i].value) );
nkeynes@9
   232
                gtk_clist_set_text( data->regs_list, i, 1, buf );
nkeynes@435
   233
                gtk_clist_set_foreground( data->regs_list, i, &gui_colour_changed );
nkeynes@2
   234
            } else {
nkeynes@435
   235
                gtk_clist_set_foreground( data->regs_list, i, &gui_colour_normal );
nkeynes@2
   236
            }
nkeynes@2
   237
        }
nkeynes@2
   238
    }
nkeynes@9
   239
nkeynes@455
   240
    set_disassembly_pc( data, *data->cpu->pc, TRUE );
nkeynes@9
   241
    memcpy( data->saved_regs, data->cpu->regs, data->cpu->regs_size );
nkeynes@2
   242
}
nkeynes@2
   243
nkeynes@435
   244
void set_disassembly_region( debug_window_t data, unsigned int page )
nkeynes@2
   245
{
nkeynes@11
   246
    uint32_t i, posn, next;
nkeynes@2
   247
    char buf[80];
nkeynes@2
   248
    char addr[10];
nkeynes@11
   249
    char opcode[16] = "";
nkeynes@2
   250
    char *arr[4] = { addr, " ", opcode, buf };
nkeynes@2
   251
    unsigned int from = page & 0xFFFFF000;
nkeynes@2
   252
    unsigned int to = from + 4096;
nkeynes@2
   253
    
nkeynes@9
   254
    gtk_clist_clear(data->disasm_list);
nkeynes@2
   255
nkeynes@2
   256
    sprintf( addr, "%08X", from );
nkeynes@9
   257
    gtk_entry_set_text( data->page_field, addr );
nkeynes@2
   258
nkeynes@14
   259
    if( !data->cpu->is_valid_page_func( from ) ) {
nkeynes@2
   260
        arr[3] = "This page is currently unmapped";
nkeynes@9
   261
        gtk_clist_append( data->disasm_list, arr );
nkeynes@435
   262
        gtk_clist_set_foreground( data->disasm_list, 0, &gui_colour_error );
nkeynes@2
   263
    } else {
nkeynes@11
   264
        for( i=from; i<to; i = next ) {
nkeynes@11
   265
	    next = data->cpu->disasm_func( i, buf, sizeof(buf), opcode );
nkeynes@2
   266
            sprintf( addr, "%08X", i );
nkeynes@9
   267
            posn = gtk_clist_append( data->disasm_list, arr );
nkeynes@2
   268
            if( buf[0] == '?' )
nkeynes@435
   269
                gtk_clist_set_foreground( data->disasm_list, posn, &gui_colour_warn );
nkeynes@43
   270
	    if( data->cpu->get_breakpoint != NULL ) {
nkeynes@43
   271
		int type = data->cpu->get_breakpoint( i );
nkeynes@43
   272
		switch(type) {
nkeynes@43
   273
		case BREAK_ONESHOT:
nkeynes@435
   274
		    gtk_clist_set_background( data->disasm_list, posn, &gui_colour_temp_break );
nkeynes@43
   275
		    break;
nkeynes@43
   276
		case BREAK_KEEP:
nkeynes@435
   277
		    gtk_clist_set_background( data->disasm_list, posn, &gui_colour_break );
nkeynes@43
   278
		    break;
nkeynes@43
   279
		}
nkeynes@43
   280
	    }
nkeynes@2
   281
        }
nkeynes@9
   282
        if( data->disasm_pc != -1 && data->disasm_pc >= from && data->disasm_pc < to )
nkeynes@9
   283
            gtk_clist_set_foreground( data->disasm_list, address_to_row(data, data->disasm_pc),
nkeynes@435
   284
                                      &gui_colour_pc );
nkeynes@2
   285
    }
nkeynes@2
   286
nkeynes@2
   287
    if( page != from ) { /* not a page boundary */
nkeynes@9
   288
        gtk_clist_moveto( data->disasm_list, (page-from)>>1, 0, 0.5, 0.0 );
nkeynes@2
   289
    }
nkeynes@9
   290
    data->disasm_from = from;
nkeynes@9
   291
    data->disasm_to = to;
nkeynes@2
   292
}
nkeynes@2
   293
nkeynes@435
   294
void jump_to_disassembly( debug_window_t data, unsigned int addr, gboolean select )
nkeynes@2
   295
{
nkeynes@2
   296
    int row;
nkeynes@2
   297
    
nkeynes@9
   298
    if( addr < data->disasm_from || addr >= data->disasm_to )
nkeynes@9
   299
        set_disassembly_region(data,addr);
nkeynes@2
   300
nkeynes@9
   301
    row = address_to_row( data, addr );
nkeynes@2
   302
    if(select) {
nkeynes@9
   303
        gtk_clist_select_row( data->disasm_list, row, 0 );
nkeynes@2
   304
    }
nkeynes@9
   305
    if( gtk_clist_row_is_visible( data->disasm_list, row ) != GTK_VISIBILITY_FULL ){
nkeynes@9
   306
        gtk_clist_moveto( data->disasm_list, row, 0, 0.5, 0.0 );
nkeynes@2
   307
    }
nkeynes@2
   308
}
nkeynes@2
   309
nkeynes@435
   310
void jump_to_pc( debug_window_t data, gboolean select )
nkeynes@9
   311
{
nkeynes@9
   312
    jump_to_disassembly( data, *data->cpu->pc, select );
nkeynes@9
   313
}
nkeynes@9
   314
nkeynes@435
   315
void set_disassembly_pc( debug_window_t data, unsigned int pc, gboolean select )
nkeynes@2
   316
{
nkeynes@2
   317
    int row;
nkeynes@2
   318
    
nkeynes@9
   319
    jump_to_disassembly( data, pc, select );
nkeynes@9
   320
    if( data->disasm_pc != -1 && data->disasm_pc >= data->disasm_from && 
nkeynes@9
   321
	data->disasm_pc < data->disasm_to )
nkeynes@9
   322
        gtk_clist_set_foreground( data->disasm_list, 
nkeynes@9
   323
				  (data->disasm_pc - data->disasm_from) / data->cpu->instr_size,
nkeynes@435
   324
                                  &gui_colour_normal );
nkeynes@9
   325
    row = address_to_row( data, pc );
nkeynes@435
   326
    gtk_clist_set_foreground( data->disasm_list, row, &gui_colour_pc );
nkeynes@9
   327
    data->disasm_pc = pc;
nkeynes@2
   328
}
nkeynes@2
   329
nkeynes@435
   330
void set_disassembly_cpu( debug_window_t data, const gchar *cpu )
nkeynes@10
   331
{
nkeynes@11
   332
    int i;
nkeynes@11
   333
    for( i=0; data->cpu_list[i] != NULL; i++ ) {
nkeynes@11
   334
	if( strcmp( data->cpu_list[i]->name, cpu ) == 0 ) {
nkeynes@11
   335
	    if( data->cpu != data->cpu_list[i] ) {
nkeynes@11
   336
		data->cpu = data->cpu_list[i];
nkeynes@69
   337
		data->disasm_from = data->disasm_to = -1; /* Force reload */
nkeynes@30
   338
		set_disassembly_pc( data, *data->cpu->pc, FALSE );
nkeynes@11
   339
		init_register_list( data );
nkeynes@11
   340
	    }
nkeynes@11
   341
	    return;
nkeynes@11
   342
	}
nkeynes@11
   343
    }
nkeynes@10
   344
}
nkeynes@10
   345
nkeynes@455
   346
void debug_window_toggle_breakpoint( debug_window_t data, int row )
nkeynes@43
   347
{
nkeynes@43
   348
    uint32_t pc = row_to_address( data, row );
nkeynes@43
   349
    int oldType = data->cpu->get_breakpoint( pc );
nkeynes@43
   350
    if( oldType != BREAK_NONE ) {
nkeynes@43
   351
	data->cpu->clear_breakpoint( pc, oldType );
nkeynes@435
   352
	gtk_clist_set_background( data->disasm_list, row, &gui_colour_white );
nkeynes@43
   353
    } else {
nkeynes@45
   354
	data->cpu->set_breakpoint( pc, BREAK_KEEP );
nkeynes@435
   355
	gtk_clist_set_background( data->disasm_list, row, &gui_colour_break );
nkeynes@43
   356
    }
nkeynes@45
   357
}
nkeynes@45
   358
nkeynes@455
   359
void debug_window_set_oneshot_breakpoint( debug_window_t data, int row )
nkeynes@45
   360
{
nkeynes@45
   361
    uint32_t pc = row_to_address( data, row );
nkeynes@45
   362
    data->cpu->clear_breakpoint( pc, BREAK_ONESHOT );
nkeynes@45
   363
    data->cpu->set_breakpoint( pc, BREAK_ONESHOT );
nkeynes@435
   364
    gtk_clist_set_background( data->disasm_list, row, &gui_colour_temp_break );
nkeynes@43
   365
}
nkeynes@43
   366
nkeynes@30
   367
/**
nkeynes@30
   368
 * Execute a single instruction using the current CPU mode.
nkeynes@30
   369
 */
nkeynes@455
   370
void debug_window_single_step( debug_window_t data )
nkeynes@30
   371
{
nkeynes@30
   372
    data->cpu->step_func();
nkeynes@30
   373
    gtk_gui_update();
nkeynes@30
   374
}
nkeynes@30
   375
nkeynes@435
   376
uint32_t row_to_address( debug_window_t data, int row ) {
nkeynes@9
   377
    return data->cpu->instr_size * row + data->disasm_from;
nkeynes@9
   378
}
nkeynes@2
   379
nkeynes@435
   380
int address_to_row( debug_window_t data, uint32_t address ) {
nkeynes@9
   381
    if( data->disasm_from > address || data->disasm_to <= address )
nkeynes@9
   382
	return -1;
nkeynes@9
   383
    return (address - data->disasm_from) / data->cpu->instr_size;
nkeynes@9
   384
}
nkeynes@9
   385
nkeynes@435
   386
debug_window_t get_debug_info( GtkWidget *widget ) {
nkeynes@9
   387
    
nkeynes@9
   388
    GtkWidget *win = gtk_widget_get_toplevel(widget);
nkeynes@435
   389
    debug_window_t data = (debug_window_t)gtk_object_get_data( GTK_OBJECT(win), "debug_data" );
nkeynes@9
   390
    return data;
nkeynes@9
   391
}
nkeynes@9
   392
nkeynes@435
   393
void debug_window_set_running( debug_window_t data, gboolean isRunning ) 
nkeynes@28
   394
{
nkeynes@392
   395
    if( data != NULL ) {
nkeynes@455
   396
	gtk_gui_enable_action( "SingleStep", !isRunning );
nkeynes@455
   397
	gtk_gui_enable_action( "RunTo", !isRunning );
nkeynes@392
   398
    }
nkeynes@28
   399
}
nkeynes@455
   400
nkeynes@455
   401
void on_mode_field_changed ( GtkEditable *editable, gpointer user_data)
nkeynes@455
   402
{
nkeynes@455
   403
    const gchar *text = gtk_entry_get_text( GTK_ENTRY(editable) );
nkeynes@455
   404
    set_disassembly_cpu( gtk_gui_get_debugger(), text );
nkeynes@455
   405
}
nkeynes@455
   406
nkeynes@455
   407
nkeynes@455
   408
gboolean on_page_field_key_press_event( GtkWidget * widget, GdkEventKey *event,
nkeynes@455
   409
                                        gpointer user_data)
nkeynes@455
   410
{
nkeynes@455
   411
    if( event->keyval == GDK_Return || event->keyval == GDK_Linefeed ) {
nkeynes@455
   412
	debug_window_t data = get_debug_info(widget);
nkeynes@455
   413
        const gchar *text = gtk_entry_get_text( GTK_ENTRY(widget) );
nkeynes@455
   414
        gchar *endptr;
nkeynes@455
   415
        unsigned int val = strtoul( text, &endptr, 16 );
nkeynes@455
   416
        if( text == endptr ) { /* invalid input */
nkeynes@455
   417
            char buf[10];
nkeynes@455
   418
            sprintf( buf, "%08X", row_to_address(data,0) );
nkeynes@455
   419
            gtk_entry_set_text( GTK_ENTRY(widget), buf );
nkeynes@455
   420
        } else {
nkeynes@455
   421
            set_disassembly_region(data, val);
nkeynes@455
   422
        }
nkeynes@455
   423
    }
nkeynes@455
   424
    return FALSE;
nkeynes@455
   425
}
nkeynes@455
   426
nkeynes@455
   427
nkeynes@455
   428
void on_jump_pc_btn_clicked( GtkButton *button, gpointer user_data)
nkeynes@455
   429
{
nkeynes@455
   430
    debug_window_t data = get_debug_info( GTK_WIDGET(button) );
nkeynes@455
   431
    jump_to_pc( data, TRUE );
nkeynes@455
   432
}
nkeynes@455
   433
nkeynes@455
   434
void on_disasm_list_select_row (GtkCList *clist, gint row, gint column,
nkeynes@455
   435
				GdkEvent *event, gpointer user_data)
nkeynes@455
   436
{
nkeynes@455
   437
    gtk_gui_enable_action( "SetBreakpoint", TRUE );
nkeynes@455
   438
    gtk_gui_enable_action( "RunTo", TRUE );
nkeynes@455
   439
}
nkeynes@455
   440
nkeynes@455
   441
void on_disasm_list_unselect_row (GtkCList *clist, gint row, gint column,
nkeynes@455
   442
				  GdkEvent *event, gpointer user_data)
nkeynes@455
   443
{
nkeynes@455
   444
    gtk_gui_enable_action( "SetBreakpoint", FALSE );
nkeynes@455
   445
    gtk_gui_enable_action( "RunTo", FALSE );
nkeynes@455
   446
}
nkeynes@457
   447
nkeynes@457
   448
gboolean on_debug_delete_event(GtkWidget *widget, GdkEvent event, gpointer user_data)
nkeynes@457
   449
{
nkeynes@457
   450
    gtk_widget_hide( widget );
nkeynes@457
   451
    return TRUE;
nkeynes@457
   452
}
.