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