| 1 |
/* |
| 2 |
* Copyright (C) 2002-2010 The DOSBox Team |
| 3 |
* |
| 4 |
* This program is free software; you can redistribute it and/or modify |
| 5 |
* it under the terms of the GNU General Public License as published by |
| 6 |
* the Free Software Foundation; either version 2 of the License, or |
| 7 |
* (at your option) any later version. |
| 8 |
* |
| 9 |
* This program is distributed in the hope that it will be useful, |
| 10 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 |
* GNU General Public License for more details. |
| 13 |
* |
| 14 |
* You should have received a copy of the GNU General Public License |
| 15 |
* along with this program; if not, write to the Free Software |
| 16 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
| 17 |
*/ |
| 18 |
|
| 19 |
/* $Id: debug_gui.cpp,v 1.38 2009-05-27 09:15:41 qbix79 Exp $ */ |
| 20 |
|
| 21 |
#include "dosbox.h" |
| 22 |
|
| 23 |
#if C_DEBUG |
| 24 |
#include "control.h" |
| 25 |
#include <stdlib.h> |
| 26 |
#include <stdarg.h> |
| 27 |
#include <stdio.h> |
| 28 |
#include <curses.h> |
| 29 |
#include <string.h> |
| 30 |
|
| 31 |
#include "support.h" |
| 32 |
#include "regs.h" |
| 33 |
#include "debug.h" |
| 34 |
#include "debug_inc.h" |
| 35 |
|
| 36 |
struct _LogGroup { |
| 37 |
char const* front; |
| 38 |
bool enabled; |
| 39 |
}; |
| 40 |
#include <list> |
| 41 |
#include <string> |
| 42 |
using namespace std; |
| 43 |
|
| 44 |
#define MAX_LOG_BUFFER 500 |
| 45 |
static list<string> logBuff; |
| 46 |
static list<string>::iterator logBuffPos = logBuff.end(); |
| 47 |
|
| 48 |
static _LogGroup loggrp[LOG_MAX]={{"",true},{0,false}}; |
| 49 |
static FILE* debuglog; |
| 50 |
|
| 51 |
extern int old_cursor_state; |
| 52 |
|
| 53 |
|
| 54 |
|
| 55 |
void DEBUG_ShowMsg(char const* format,...) { |
| 56 |
|
| 57 |
char buf[512]; |
| 58 |
va_list msg; |
| 59 |
va_start(msg,format); |
| 60 |
vsprintf(buf,format,msg); |
| 61 |
va_end(msg); |
| 62 |
|
| 63 |
/* Add newline if not present */ |
| 64 |
Bitu len=strlen(buf); |
| 65 |
if(buf[len-1]!='\n') strcat(buf,"\n"); |
| 66 |
|
| 67 |
if(debuglog) fprintf(debuglog,"%s",buf); |
| 68 |
|
| 69 |
if (logBuffPos!=logBuff.end()) { |
| 70 |
logBuffPos=logBuff.end(); |
| 71 |
DEBUG_RefreshPage(0); |
| 72 |
// mvwprintw(dbg.win_out,dbg.win_out->_maxy-1, 0, ""); |
| 73 |
} |
| 74 |
logBuff.push_back(buf); |
| 75 |
if (logBuff.size() > MAX_LOG_BUFFER) |
| 76 |
logBuff.pop_front(); |
| 77 |
|
| 78 |
logBuffPos = logBuff.end(); |
| 79 |
wprintw(dbg.win_out,"%s",buf); |
| 80 |
wrefresh(dbg.win_out); |
| 81 |
} |
| 82 |
|
| 83 |
void DEBUG_RefreshPage(char scroll) { |
| 84 |
if (scroll==-1 && logBuffPos!=logBuff.begin()) logBuffPos--; |
| 85 |
else if (scroll==1 && logBuffPos!=logBuff.end()) logBuffPos++; |
| 86 |
|
| 87 |
list<string>::iterator i = logBuffPos; |
| 88 |
int maxy, maxx; getmaxyx(dbg.win_out,maxy,maxx); |
| 89 |
int rem_lines = maxy; |
| 90 |
|
| 91 |
wclear(dbg.win_out); |
| 92 |
|
| 93 |
while (rem_lines > 0 && i!=logBuff.begin()) { |
| 94 |
--i; |
| 95 |
for (string::size_type posf=0, posl; (posl=(*i).find('\n',posf)) != string::npos ;posf=posl+1) |
| 96 |
rem_lines -= (int) ((posl-posf) / maxx) + 1; // len=(posl+1)-posf-1 |
| 97 |
/* Const cast is needed for pdcurses which has no const char in mvwprintw (bug maybe) */ |
| •98 |
mvwprintw(dbg.win_out,rem_lines-1, 0, "%s", const_cast<char*>((*i).c_str())); |
| 99 |
} |
| 100 |
mvwprintw(dbg.win_out,maxy-1, 0, ""); |
| 101 |
wrefresh(dbg.win_out); |
| 102 |
} |
| 103 |
|
| 104 |
void LOG::operator() (char const* format, ...){ |
| 105 |
char buf[512]; |
| 106 |
va_list msg; |
| 107 |
va_start(msg,format); |
| 108 |
vsprintf(buf,format,msg); |
| 109 |
va_end(msg); |
| 110 |
|
| 111 |
if (d_type>=LOG_MAX) return; |
| 112 |
if ((d_severity!=LOG_ERROR) && (!loggrp[d_type].enabled)) return; |
| 113 |
DEBUG_ShowMsg("%10u: %s:%s\n",cycle_count,loggrp[d_type].front,buf); |
| 114 |
} |
| 115 |
|
| 116 |
|
| 117 |
static void Draw_RegisterLayout(void) { |
| 118 |
mvwaddstr(dbg.win_reg,0,0,"EAX="); |
| 119 |
mvwaddstr(dbg.win_reg,1,0,"EBX="); |
| 120 |
mvwaddstr(dbg.win_reg,2,0,"ECX="); |
| 121 |
mvwaddstr(dbg.win_reg,3,0,"EDX="); |
| 122 |
|
| 123 |
mvwaddstr(dbg.win_reg,0,14,"ESI="); |
| 124 |
mvwaddstr(dbg.win_reg,1,14,"EDI="); |
| 125 |
mvwaddstr(dbg.win_reg,2,14,"EBP="); |
| 126 |
mvwaddstr(dbg.win_reg,3,14,"ESP="); |
| 127 |
|
| 128 |
mvwaddstr(dbg.win_reg,0,28,"DS="); |
| 129 |
mvwaddstr(dbg.win_reg,0,38,"ES="); |
| 130 |
mvwaddstr(dbg.win_reg,0,48,"FS="); |
| 131 |
mvwaddstr(dbg.win_reg,0,58,"GS="); |
| 132 |
mvwaddstr(dbg.win_reg,0,68,"SS="); |
| 133 |
|
| 134 |
mvwaddstr(dbg.win_reg,1,28,"CS="); |
| 135 |
mvwaddstr(dbg.win_reg,1,38,"EIP="); |
| 136 |
|
| 137 |
mvwaddstr(dbg.win_reg,2,75,"CPL"); |
| 138 |
mvwaddstr(dbg.win_reg,2,68,"IOPL"); |
| 139 |
|
| 140 |
mvwaddstr(dbg.win_reg,1,52,"C Z S O A P D I T "); |
| 141 |
} |
| 142 |
|
| 143 |
|
| 144 |
static void DrawBars(void) { |
| 145 |
if (has_colors()) { |
| 146 |
attrset(COLOR_PAIR(PAIR_BLACK_BLUE)); |
| 147 |
} |
| 148 |
/* Show the Register bar */ |
| 149 |
mvaddstr(getbegy(dbg.win_reg)-1,0, "---(Register Overview )---"); |
| 150 |
/* Show the Data Overview bar perhaps with more special stuff in the end */ |
| 151 |
mvaddstr(getbegy(dbg.win_data)-1,0,"---(Data Overview Scroll: page up/down)---"); |
| 152 |
/* Show the Code Overview perhaps with special stuff in bar too */ |
| 153 |
mvaddstr(getbegy(dbg.win_code)-1,0,"---(Code Overview Scroll: up/down )---"); |
| 154 |
/* Show the Variable Overview bar */ |
| 155 |
mvaddstr(getbegy(dbg.win_var)-1,0, "---(Variable Overview )---"); |
| 156 |
/* Show the Output OverView */ |
| 157 |
mvaddstr(getbegy(dbg.win_out)-1,0, "---(OutPut/Input Scroll: home/end )---"); |
| 158 |
attrset(0); |
| 159 |
} |
| 160 |
|
| 161 |
|
| 162 |
|
| 163 |
static void MakeSubWindows(void) { |
| 164 |
/* The Std output win should go in bottem */ |
| 165 |
/* Make all the subwindows */ |
| 166 |
int win_main_maxy, win_main_maxx; getmaxyx(dbg.win_main,win_main_maxy,win_main_maxx); |
| 167 |
int outy=1; |
| 168 |
/* The Register window */ |
| 169 |
dbg.win_reg=subwin(dbg.win_main,4,win_main_maxx,outy,0); |
| 170 |
outy+=5; |
| 171 |
/* The Data Window */ |
| 172 |
dbg.win_data=subwin(dbg.win_main,10,win_main_maxx,outy,0); |
| 173 |
outy+=11; |
| 174 |
/* The Code Window */ |
| 175 |
dbg.win_code=subwin(dbg.win_main,11,win_main_maxx,outy,0); |
| 176 |
outy+=12; |
| 177 |
/* The Variable Window */ |
| 178 |
dbg.win_var=subwin(dbg.win_main,4,win_main_maxx,outy,0); |
| 179 |
outy+=5; |
| 180 |
/* The Output Window */ |
| 181 |
dbg.win_out=subwin(dbg.win_main,win_main_maxy-outy-1,win_main_maxx,outy,0); |
| 182 |
dbg.input_y=win_main_maxy-1; |
| 183 |
scrollok(dbg.win_out,TRUE); |
| 184 |
DrawBars(); |
| 185 |
Draw_RegisterLayout(); |
| 186 |
refresh(); |
| 187 |
} |
| 188 |
|
| 189 |
static void MakePairs(void) { |
| 190 |
init_pair(PAIR_BLACK_BLUE, COLOR_BLACK, COLOR_CYAN); |
| 191 |
init_pair(PAIR_BYELLOW_BLACK, COLOR_YELLOW /*| FOREGROUND_INTENSITY */, COLOR_BLACK); |
| 192 |
init_pair(PAIR_GREEN_BLACK, COLOR_GREEN /*| FOREGROUND_INTENSITY */, COLOR_BLACK); |
| 193 |
init_pair(PAIR_BLACK_GREY, COLOR_BLACK /*| FOREGROUND_INTENSITY */, COLOR_WHITE); |
| 194 |
init_pair(PAIR_GREY_RED, COLOR_WHITE/*| FOREGROUND_INTENSITY */, COLOR_RED); |
| 195 |
} |
| 196 |
static void LOG_Destroy(Section*) { |
| 197 |
if(debuglog) fclose(debuglog); |
| 198 |
} |
| 199 |
|
| 200 |
static void LOG_Init(Section * sec) { |
| 201 |
Section_prop * sect=static_cast<Section_prop *>(sec); |
| 202 |
const char * blah=sect->Get_string("logfile"); |
| 203 |
if(blah && blah[0] &&(debuglog = fopen(blah,"wt+"))){ |
| 204 |
}else{ |
| 205 |
debuglog=0; |
| 206 |
} |
| 207 |
sect->AddDestroyFunction(&LOG_Destroy); |
| 208 |
char buf[1024]; |
| 209 |
for (Bitu i=1;i<LOG_MAX;i++) { |
| 210 |
strcpy(buf,loggrp[i].front); |
| 211 |
buf[strlen(buf)]=0; |
| 212 |
lowcase(buf); |
| 213 |
loggrp[i].enabled=sect->Get_bool(buf); |
| 214 |
} |
| 215 |
} |
| 216 |
|
| 217 |
|
| 218 |
void LOG_StartUp(void) { |
| 219 |
/* Setup logging groups */ |
| 220 |
loggrp[LOG_ALL].front="ALL"; |
| 221 |
loggrp[LOG_VGA].front="VGA"; |
| 222 |
loggrp[LOG_VGAGFX].front="VGAGFX"; |
| 223 |
loggrp[LOG_VGAMISC].front="VGAMISC"; |
| 224 |
loggrp[LOG_INT10].front="INT10"; |
| 225 |
loggrp[LOG_SB].front="SBLASTER"; |
| 226 |
loggrp[LOG_DMACONTROL].front="DMA_CONTROL"; |
| 227 |
|
| 228 |
loggrp[LOG_FPU].front="FPU"; |
| 229 |
loggrp[LOG_CPU].front="CPU"; |
| 230 |
loggrp[LOG_PAGING].front="PAGING"; |
| 231 |
|
| 232 |
loggrp[LOG_FCB].front="FCB"; |
| 233 |
loggrp[LOG_FILES].front="FILES"; |
| 234 |
loggrp[LOG_IOCTL].front="IOCTL"; |
| 235 |
loggrp[LOG_EXEC].front="EXEC"; |
| 236 |
loggrp[LOG_DOSMISC].front="DOSMISC"; |
| 237 |
|
| 238 |
loggrp[LOG_PIT].front="PIT"; |
| 239 |
loggrp[LOG_KEYBOARD].front="KEYBOARD"; |
| 240 |
loggrp[LOG_PIC].front="PIC"; |
| 241 |
|
| 242 |
loggrp[LOG_MOUSE].front="MOUSE"; |
| 243 |
loggrp[LOG_BIOS].front="BIOS"; |
| 244 |
loggrp[LOG_GUI].front="GUI"; |
| 245 |
loggrp[LOG_MISC].front="MISC"; |
| 246 |
|
| 247 |
loggrp[LOG_IO].front="IO"; |
| 248 |
|
| 249 |
/* Register the log section */ |
| 250 |
Section_prop * sect=control->AddSection_prop("log",LOG_Init); |
| 251 |
Prop_string* Pstring = sect->Add_string("logfile",Property::Changeable::Always,""); |
| 252 |
Pstring->Set_help("file where the log messages will be saved to"); |
| 253 |
char buf[1024]; |
| 254 |
for (Bitu i=1;i<LOG_MAX;i++) { |
| 255 |
strcpy(buf,loggrp[i].front); |
| 256 |
lowcase(buf); |
| 257 |
Prop_bool* Pbool = sect->Add_bool(buf,Property::Changeable::Always,true); |
| 258 |
Pbool->Set_help("Enable/Disable logging of this type."); |
| 259 |
} |
| 260 |
MSG_Add("LOG_CONFIGFILE_HELP","Logging related options for the debugger.\n"); |
| 261 |
} |
| 262 |
|
| 263 |
|
| 264 |
|
| 265 |
|
| 266 |
void DBGUI_StartUp(void) { |
| 267 |
/* Start the main window */ |
| 268 |
dbg.win_main=initscr(); |
| 269 |
cbreak(); /* take input chars one at a time, no wait for \n */ |
| 270 |
noecho(); /* don't echo input */ |
| 271 |
nodelay(dbg.win_main,true); |
| 272 |
keypad(dbg.win_main,true); |
| 273 |
#ifndef WIN32 |
| 274 |
resizeterm(50,80); |
| 275 |
touchwin(dbg.win_main); |
| 276 |
#endif |
| 277 |
old_cursor_state = curs_set(0); |
| 278 |
start_color(); |
| 279 |
cycle_count=0; |
| 280 |
MakePairs(); |
| 281 |
MakeSubWindows(); |
| 282 |
|
| 283 |
} |
| 284 |
|
| 285 |
#endif |