Bug Summary

File:/home/anal/dolphin-emu/Source/Core/DolphinWX/Src/Debugger/JitWindow.cpp
Location:line 181, column 3
Description:Value stored to 'sptr' is never read

Annotated Source Code

1// Copyright 2013 Dolphin Emulator Project
2// Licensed under GPLv2
3// Refer to the license.txt file included.
4
5#include <wx/button.h>
6#include <wx/textctrl.h>
7#include <wx/listctrl.h>
8#include <wx/thread.h>
9#include <wx/listctrl.h>
10
11#include "JitWindow.h"
12#include "HW/CPU.h"
13#include "PowerPC/PowerPC.h"
14#include "PowerPC/JitCommon/JitBase.h"
15#include "PowerPC/JitCommon/JitCache.h"
16#include "PowerPC/PPCAnalyst.h"
17#include "PowerPCDisasm.h"
18#include "disasm.h"
19
20#include "Debugger/PPCDebugInterface.h"
21#include "Debugger/Debugger_SymbolMap.h"
22
23#include "Core.h"
24#include "StringUtil.h"
25#include "LogManager.h"
26#include "../WxUtils.h"
27
28#include "../Globals.h"
29
30enum
31{
32 IDM_REFRESH_LIST = 23350,
33 IDM_PPC_BOX,
34 IDM_X86_BOX,
35 IDM_NEXT,
36 IDM_PREV,
37 IDM_BLOCKLIST,
38};
39
40BEGIN_EVENT_TABLE(CJitWindow, wxPanel)const wxEventTable CJitWindow::sm_eventTable = { &wxPanel
::sm_eventTable, &CJitWindow::sm_eventTableEntries[0] }; const
wxEventTable *CJitWindow::GetEventTable() const { return &
CJitWindow::sm_eventTable; } wxEventHashTable CJitWindow::sm_eventHashTable
(CJitWindow::sm_eventTable); wxEventHashTable &CJitWindow
::GetEventHashTable() const { return CJitWindow::sm_eventHashTable
; } const wxEventTableEntry CJitWindow::sm_eventTableEntries[
] = {
41 //EVT_TEXT(IDM_ADDRBOX, CJitWindow::OnAddrBoxChange)
42 //EVT_LISTBOX(IDM_SYMBOLLIST, CJitWindow::OnSymbolListChange)
43 //EVT_HOST_COMMAND(wxID_ANY, CJitWindow::OnHostMessage)
44 EVT_BUTTON(IDM_REFRESH_LIST, CJitWindow::OnRefresh)wxEventTableEntry(wxEVT_BUTTON, IDM_REFRESH_LIST, wxID_ANY, wxNewEventTableFunctor
(wxEVT_BUTTON, ( wxObjectEventFunction )( wxEventFunction )static_cast
<wxCommandEventFunction>(&CJitWindow::OnRefresh)), __null
),
45END_EVENT_TABLE()wxEventTableEntry(wxEVT_NULL, 0, 0, 0, 0) };
46
47CJitWindow::CJitWindow(wxWindow* parent, wxWindowID id, const wxPoint& pos,
48 const wxSize& size, long style, const wxString& name)
49: wxPanel(parent, id, pos, size, style, name)
50{
51 wxBoxSizer* sizerBig = new wxBoxSizer(wxVERTICAL);
52 wxBoxSizer* sizerSplit = new wxBoxSizer(wxHORIZONTAL);
53 sizerSplit->Add(ppc_box = new wxTextCtrl(this, IDM_PPC_BOX, _T("(ppc)")L"(ppc)",
54 wxDefaultPosition, wxDefaultSize, wxTE_MULTILINE0x0020), 1, wxEXPAND);
55 sizerSplit->Add(x86_box = new wxTextCtrl(this, IDM_X86_BOX, _T("(x86)")L"(x86)",
56 wxDefaultPosition, wxDefaultSize, wxTE_MULTILINE0x0020), 1, wxEXPAND);
57 sizerBig->Add(block_list = new JitBlockList(this, IDM_BLOCKLIST,
58 wxDefaultPosition, wxSize(100, 140),
59 wxLC_REPORT0x0020 | wxSUNKEN_BORDERwxBORDER_SUNKEN | wxLC_ALIGN_LEFT0x0080 | wxLC_SINGLE_SEL0x2000 | wxLC_SORT_ASCENDING0x4000),
60 0, wxEXPAND);
61 sizerBig->Add(sizerSplit, 2, wxEXPAND);
62// sizerBig->Add(memview, 5, wxEXPAND);
63// sizerBig->Add(sizerRight, 0, wxEXPAND | wxALL, 3);
64 sizerBig->Add(button_refresh = new wxButton(this, IDM_REFRESH_LIST, _("&Refresh")wxGetTranslation(("&Refresh"))));
65// sizerRight->Add(addrbox = new wxTextCtrl(this, IDM_ADDRBOX, _T("")));
66// sizerRight->Add(new wxButton(this, IDM_SETPC, _("S&et PC")));
67
68 SetSizer(sizerBig);
69
70 sizerSplit->Fit(this);
71 sizerBig->Fit(this);
72}
73
74void CJitWindow::OnRefresh(wxCommandEvent& /*event*/) {
75 block_list->Update();
76}
77
78void CJitWindow::ViewAddr(u32 em_address)
79{
80 Show(true);
81 Compare(em_address);
82 SetFocus();
83}
84
85void CJitWindow::Compare(u32 em_address)
86{
87 u8 *xDis = new u8[1<<18];
88 memset(xDis, 0, 1<<18);
89
90 disassembler x64disasm;
91 x64disasm.set_syntax_intel();
92
93 int block_num = jit->GetBlockCache()->GetBlockNumberFromStartAddress(em_address);
94 if (block_num < 0)
95 {
96 for (int i = 0; i < 500; i++)
97 {
98 block_num = jit->GetBlockCache()->GetBlockNumberFromStartAddress(em_address - 4 * i);
99 if (block_num >= 0)
100 break;
101 }
102
103 if (block_num >= 0)
104 {
105 JitBlock *block = jit->GetBlockCache()->GetBlock(block_num);
106 if (!(block->originalAddress <= em_address &&
107 block->originalSize + block->originalAddress >= em_address))
108 block_num = -1;
109 }
110
111 // Do not merge this "if" with the above - block_num changes inside it.
112 if (block_num < 0)
113 {
114 ppc_box->SetValue(StrToWxStr(StringFromFormat("(non-code address: %08x)",
115 em_address)));
116 x86_box->SetValue(StrToWxStr(StringFromFormat("(no translation)")));
117 delete[] xDis;
118 return;
119 }
120 }
121 JitBlock *block = jit->GetBlockCache()->GetBlock(block_num);
122
123 // 800031f0
124 // == Fill in x86 box
125
126 const u8 *code = (const u8 *)jit->GetBlockCache()->GetCompiledCodeFromBlock(block_num);
127 u64 disasmPtr = (u64)code;
128 int size = block->codeSize;
129 const u8 *end = code + size;
130 char *sptr = (char*)xDis;
131
132 int num_x86_instructions = 0;
133 while ((u8*)disasmPtr < end)
134 {
135#ifdef _M_X641
136 disasmPtr += x64disasm.disasm64(disasmPtr, disasmPtr, (u8*)disasmPtr, sptr);
137#else
138 disasmPtr += x64disasm.disasm32(disasmPtr, disasmPtr, (u8*)disasmPtr, sptr);
139#endif
140 sptr += strlen(sptr);
141 *sptr++ = 13;
142 *sptr++ = 10;
143 num_x86_instructions++;
144 }
145 x86_box->SetValue(StrToWxStr((char*)xDis));
146
147 // == Fill in ppc box
148 u32 ppc_addr = block->originalAddress;
149 PPCAnalyst::CodeBuffer code_buffer(32000);
150 PPCAnalyst::BlockStats st;
151 PPCAnalyst::BlockRegStats gpa;
152 PPCAnalyst::BlockRegStats fpa;
153 bool broken_block = false;
154 u32 merged_addresses[32];
155 const int capacity_of_merged_addresses = sizeof(merged_addresses) / sizeof(merged_addresses[0]);
156 int size_of_merged_addresses;
157 if (PPCAnalyst::Flatten(ppc_addr, &size, &st, &gpa, &fpa, broken_block, &code_buffer, size, merged_addresses, capacity_of_merged_addresses, size_of_merged_addresses) != 0xffffffff)
158 {
159 sptr = (char*)xDis;
160 for (int i = 0; i < size; i++)
161 {
162 const PPCAnalyst::CodeOp &op = code_buffer.codebuffer[i];
163 char temp[256];
164 DisassembleGekko(op.inst.hex, op.address, temp, 256);
165 sptr += sprintf(sptr, "%08x %s\n", op.address, temp);
166 }
167
168 // Add stats to the end of the ppc box since it's generally the shortest.
169 sptr += sprintf(sptr, "\n");
170
171 // Add some generic analysis
172 if (st.isFirstBlockOfFunction)
173 sptr += sprintf(sptr, "(first block of function)\n");
174 if (st.isLastBlockOfFunction)
175 sptr += sprintf(sptr, "(first block of function)\n");
176
177 sptr += sprintf(sptr, "%i estimated cycles\n", st.numCycles);
178
179 sptr += sprintf(sptr, "Num instr: PPC: %i x86: %i (blowup: %i%%)\n",
180 size, num_x86_instructions, 100 * (num_x86_instructions / size - 1));
181 sptr += sprintf(sptr, "Num bytes: PPC: %i x86: %i (blowup: %i%%)\n",
Value stored to 'sptr' is never read
182 size * 4, block->codeSize, 100 * (block->codeSize / (4 * size) - 1));
183
184 ppc_box->SetValue(StrToWxStr((char*)xDis));
185 }
186 else
187 {
188 ppc_box->SetValue(StrToWxStr(StringFromFormat(
189 "(non-code address: %08x)", em_address)));
190 x86_box->SetValue("---");
191 }
192
193 delete[] xDis;
194}
195
196void CJitWindow::Update()
197{
198
199}
200
201void CJitWindow::OnHostMessage(wxCommandEvent& event)
202{
203 switch (event.GetId())
204 {
205 case IDM_NOTIFYMAPLOADED:
206 //NotifyMapLoaded();
207 break;
208 }
209}
210
211// JitBlockList
212//================
213
214enum {
215 COLUMN_ADDRESS,
216 COLUMN_PPCSIZE,
217 COLUMN_X86SIZE,
218 COLUMN_NAME,
219 COLUMN_FLAGS,
220 COLUMN_NUMEXEC,
221 COLUMN_COST, // (estimated as x86size * numexec)
222};
223
224JitBlockList::JitBlockList(wxWindow* parent, const wxWindowID id,
225 const wxPoint& pos, const wxSize& size, long style)
226 : wxListCtrl(parent, id, pos, size, style) // | wxLC_VIRTUAL)
227{
228 Init();
229}
230
231void JitBlockList::Init()
232{
233 InsertColumn(COLUMN_ADDRESS, _("Address")wxGetTranslation(("Address")));
234 InsertColumn(COLUMN_PPCSIZE, _("PPC Size")wxGetTranslation(("PPC Size")));
235 InsertColumn(COLUMN_X86SIZE, _("x86 Size")wxGetTranslation(("x86 Size")));
236 InsertColumn(COLUMN_NAME, _("Symbol")wxGetTranslation(("Symbol")));
237 InsertColumn(COLUMN_FLAGS, _("Flags")wxGetTranslation(("Flags")));
238 InsertColumn(COLUMN_NUMEXEC, _("NumExec")wxGetTranslation(("NumExec")));
239 InsertColumn(COLUMN_COST, _("Cost")wxGetTranslation(("Cost")));
240}
241
242void JitBlockList::Update()
243{
244}