From 4b3d4db43fc89bd75611b3dc9d7dc25b049e557d Mon Sep 17 00:00:00 2001 From: Kingcom Date: Mon, 26 Aug 2013 20:29:24 +0200 Subject: [PATCH] Display ?? in memory view for invalid addresses --- Windows/Debugger/CtrlMemView.cpp | 181 +++++++++--------------- Windows/Debugger/CtrlMemView.h | 14 -- Windows/Debugger/Debugger_MemoryDlg.cpp | 7 - 3 files changed, 66 insertions(+), 136 deletions(-) diff --git a/Windows/Debugger/CtrlMemView.cpp b/Windows/Debugger/CtrlMemView.cpp index c00819f20c..f3669e7fc6 100644 --- a/Windows/Debugger/CtrlMemView.cpp +++ b/Windows/Debugger/CtrlMemView.cpp @@ -21,23 +21,22 @@ extern HMENU g_hPopupMenus; CtrlMemView::CtrlMemView(HWND _wnd) { - wnd=_wnd; - SetWindowLongPtr(wnd, GWLP_USERDATA, (LONG)this); - SetWindowLong(wnd, GWL_STYLE, GetWindowLong(wnd,GWL_STYLE) | WS_VSCROLL); - SetScrollRange(wnd, SB_VERT, -1,1,TRUE); + wnd=_wnd; + SetWindowLongPtr(wnd, GWLP_USERDATA, (LONG)this); + SetWindowLong(wnd, GWL_STYLE, GetWindowLong(wnd,GWL_STYLE) | WS_VSCROLL); + SetScrollRange(wnd, SB_VERT, -1,1,TRUE); - rowHeight = g_Config.iFontHeight; - charWidth = g_Config.iFontWidth; + rowHeight = g_Config.iFontHeight; + charWidth = g_Config.iFontWidth; - font = - CreateFont(rowHeight,charWidth,0,0,FW_DONTCARE,FALSE,FALSE,FALSE,DEFAULT_CHARSET,OUT_DEFAULT_PRECIS, - CLIP_DEFAULT_PRECIS,DEFAULT_QUALITY,DEFAULT_PITCH,"Lucida Console"); - underlineFont = - CreateFont(rowHeight,charWidth,0,0,FW_DONTCARE,FALSE,TRUE,FALSE,DEFAULT_CHARSET,OUT_DEFAULT_PRECIS, - CLIP_DEFAULT_PRECIS,DEFAULT_QUALITY,DEFAULT_PITCH,"Lucida Console"); - curAddress=0; - mode=MV_NORMAL; - debugger = 0; + font = + CreateFont(rowHeight,charWidth,0,0,FW_DONTCARE,FALSE,FALSE,FALSE,DEFAULT_CHARSET,OUT_DEFAULT_PRECIS, + CLIP_DEFAULT_PRECIS,DEFAULT_QUALITY,DEFAULT_PITCH,"Lucida Console"); + underlineFont = + CreateFont(rowHeight,charWidth,0,0,FW_DONTCARE,FALSE,TRUE,FALSE,DEFAULT_CHARSET,OUT_DEFAULT_PRECIS, + CLIP_DEFAULT_PRECIS,DEFAULT_QUALITY,DEFAULT_PITCH,"Lucida Console"); + curAddress=0; + debugger = 0; ctrlDown = false; hasFocus = false; @@ -165,8 +164,6 @@ CtrlMemView *CtrlMemView::getFrom(HWND hwnd) void CtrlMemView::onPaint(WPARAM wParam, LPARAM lParam) { - if (!debugger) return; - // draw to a bitmap for double buffering PAINTSTRUCT ps; HDC actualHdc = BeginPaint(wnd, &ps); @@ -200,111 +197,65 @@ void CtrlMemView::onPaint(WPARAM wParam, LPARAM lParam) TextOut(hdc,addressStart,rowY,temp,(int)strlen(temp)); SetTextColor(hdc,0x000000); - if (debugger->isAlive()) + + u32 memory[4]; + bool valid = debugger != NULL && debugger->isAlive() && Memory::IsValidAddress(address); + if (valid) { + memory[0] = debugger->readMemory(address); + memory[1] = debugger->readMemory(address+4); + memory[2] = debugger->readMemory(address+8); + memory[3] = debugger->readMemory(address+12); + } - switch(mode) { - case MV_NORMAL: + u8* m = (u8*) memory; + for (int j = 0; j < rowSize; j++) + { + if (valid) sprintf(temp,"%02X",m[j]); + else strcpy(temp,"??"); + + unsigned char c = m[j]; + if (c < 32 || c >= 128 || valid == false) c = '.'; + + if (address+j == curAddress) + { + COLORREF oldBkColor = GetBkColor(hdc); + COLORREF oldTextColor = GetTextColor(hdc); + + if (hasFocus && !asciiSelected) { - u32 memory[4]; - if (Memory::IsValidAddress(address)) - { - memory[0] = debugger->readMemory(address); - memory[1] = debugger->readMemory(address+4); - memory[2] = debugger->readMemory(address+8); - memory[3] = debugger->readMemory(address+12); - } - else - { - memory[0] = memory[1] = memory[2] = memory[3] = 0xFFFFFFFF; - } - - u8* m = (u8*) memory; - for (int j = 0; j < rowSize; j++) - { - sprintf(temp,"%02X",m[j]); - unsigned char c = m[j]; - if (c < 32 || c >= 128) c = '.'; - - if (address+j == curAddress) - { - COLORREF oldBkColor = GetBkColor(hdc); - COLORREF oldTextColor = GetTextColor(hdc); - - if (hasFocus && !asciiSelected) - { - SetTextColor(hdc,0xFFFFFF); - SetBkColor(hdc,0xFF9933); - if (selectedNibble == 0) SelectObject(hdc,(HGDIOBJ)underlineFont); - } else { - SetTextColor(hdc,0); - SetBkColor(hdc,0xC0C0C0); - } - TextOut(hdc,hexStart+j*3*charWidth,rowY,&temp[0],1); - - if (hasFocus && !asciiSelected) - { - if (selectedNibble == 1) SelectObject(hdc,(HGDIOBJ)underlineFont); - else SelectObject(hdc,(HGDIOBJ)font); - } - TextOut(hdc,hexStart+j*3*charWidth+charWidth,rowY,&temp[1],1); - - if (hasFocus && asciiSelected) - { - SetTextColor(hdc,0xFFFFFF); - SetBkColor(hdc,0xFF9933); - } else { - SetTextColor(hdc,0); - SetBkColor(hdc,0xC0C0C0); - SelectObject(hdc,(HGDIOBJ)font); - } - TextOut(hdc,asciiStart+j*(charWidth+2),rowY,(char*)&c,1); - - SetTextColor(hdc,oldTextColor); - SetBkColor(hdc,oldBkColor); - } else { - TextOut(hdc,hexStart+j*3*charWidth,rowY,temp,2); - TextOut(hdc,asciiStart+j*(charWidth+2),rowY,(char*)&c,1); - } - } + SetTextColor(hdc,0xFFFFFF); + SetBkColor(hdc,0xFF9933); + if (selectedNibble == 0) SelectObject(hdc,(HGDIOBJ)underlineFont); + } else { + SetTextColor(hdc,0); + SetBkColor(hdc,0xC0C0C0); } - break; -/* case MV_SYMBOLS: + TextOut(hdc,hexStart+j*3*charWidth,rowY,&temp[0],1); + + if (hasFocus && !asciiSelected) { - SetTextColor(hdc,0x0000FF); - int fn = symbolMap.GetSymbolNum(address); - if (fn==-1) - { - sprintf(temp, "%s (ns)", Memory::GetAddressName(address)); - } - else - sprintf(temp, "%s (0x%x b)", symbolMap.GetSymbolName(fn),symbolMap.GetSymbolSize(fn)); - TextOut(hdc,200,rowY1,temp,(int)strlen(temp)); + if (selectedNibble == 1) SelectObject(hdc,(HGDIOBJ)underlineFont); + else SelectObject(hdc,(HGDIOBJ)font); + } + TextOut(hdc,hexStart+j*3*charWidth+charWidth,rowY,&temp[1],1); - SetTextColor(hdc,0x000000); - - if (align==4) - { - u32 value = Memory::ReadUnchecked_U32(address); - int num = symbolMap.GetSymbolNum(value); - if (num != -1) - sprintf(temp, "%08x [%s]", value, symbolMap.GetSymbolName(num)); - else - sprintf(temp, "%08x", value); - } - else if (align==2) - { - u16 value = Memory::ReadUnchecked_U16(address); - int num = symbolMap.GetSymbolNum(value); - if (num != -1) - sprintf(temp, "%04x [%s]", value, symbolMap.GetSymbolName(num)); - else - sprintf(temp, "%04x", value); - } + if (hasFocus && asciiSelected) + { + SetTextColor(hdc,0xFFFFFF); + SetBkColor(hdc,0xFF9933); + } else { + SetTextColor(hdc,0); + SetBkColor(hdc,0xC0C0C0); + SelectObject(hdc,(HGDIOBJ)font); + } + TextOut(hdc,asciiStart+j*(charWidth+2),rowY,(char*)&c,1); - TextOut(hdc,70,rowY1,temp,(int)strlen(temp)); - break; - }*/ + SetTextColor(hdc,oldTextColor); + SetBkColor(hdc,oldBkColor); + } else { + TextOut(hdc,hexStart+j*3*charWidth,rowY,temp,2); + TextOut(hdc,asciiStart+j*(charWidth+2),rowY,(char*)&c,1); } } } diff --git a/Windows/Debugger/CtrlMemView.h b/Windows/Debugger/CtrlMemView.h index 8aa8193cf7..c016aaa6de 100644 --- a/Windows/Debugger/CtrlMemView.h +++ b/Windows/Debugger/CtrlMemView.h @@ -19,13 +19,6 @@ #include "../../Core/Debugger/DebugInterface.h" -enum MemViewMode -{ - MV_NORMAL, - MV_SYMBOLS, - MV_MAX -}; - class CtrlMemView { HWND wnd; @@ -51,7 +44,6 @@ class CtrlMemView bool hasFocus; static TCHAR szClassName[]; DebugInterface *debugger; - MemViewMode mode; void updateStatusBarText(); public: CtrlMemView(HWND _wnd); @@ -79,12 +71,6 @@ public: void onMouseMove(WPARAM wParam, LPARAM lParam, int button); void redraw(); - void setMode(MemViewMode m) - { - mode=m; - redraw(); - } - void gotoPoint(int x, int y); void gotoAddr(unsigned int addr); void scrollWindow(int lines); diff --git a/Windows/Debugger/Debugger_MemoryDlg.cpp b/Windows/Debugger/Debugger_MemoryDlg.cpp index 292a891777..a083353ecc 100644 --- a/Windows/Debugger/Debugger_MemoryDlg.cpp +++ b/Windows/Debugger/Debugger_MemoryDlg.cpp @@ -147,13 +147,6 @@ BOOL CMemoryDlg::DlgProc(UINT message, WPARAM wParam, LPARAM lParam) } break; }; - break; - case IDC_MODENORMAL: - mv->setMode(MV_NORMAL); - break; - case IDC_MODESYMBOLS: - mv->setMode(MV_NORMAL); - // mv->setMode(MV_SYMBOLS); break; } }