Allow adding addresses directly from memory search

This commit is contained in:
Ilari Liusvaara 2012-09-07 21:58:01 +03:00
parent b502d82d35
commit 92e9cc9fb2

View file

@ -1,5 +1,7 @@
#include "core/dispatch.hpp"
#include "core/memorymanip.hpp"
#include "core/memorywatch.hpp"
#include "library/string.hpp"
#include "platform/wxwidgets/platform.hpp"
@ -15,6 +17,7 @@
#define wxID_UPDATE (wxID_HIGHEST + 2)
#define wxID_TYPESELECT (wxID_HIGHEST + 3)
#define wxID_HEX_SELECT (wxID_HIGHEST + 4)
#define wxID_ADD (wxID_HIGHEST + 5)
#define wxID_BUTTONS_BASE (wxID_HIGHEST + 128)
#define DATATYPES 8
@ -26,6 +29,8 @@
class wxwindow_memorysearch;
namespace
{
const char* watchchars = "bBwWdDqQ";
wxwindow_memorysearch* mwatch;
const char* datatypes[] = {
"signed byte",
@ -175,6 +180,7 @@ public:
wxwindow_memorysearch();
~wxwindow_memorysearch();
bool ShouldPreventAppExit() const;
void on_add(wxCommandEvent& e);
void on_close(wxCloseEvent& e);
void on_button_click(wxCommandEvent& e);
bool update_queued;
@ -188,6 +194,7 @@ private:
wxTextCtrl* matches;
wxComboBox* type;
wxCheckBox* hexmode2;
std::map<long, uint64_t> addresses;
unsigned typecode;
bool hexmode;
};
@ -205,7 +212,7 @@ wxwindow_memorysearch::wxwindow_memorysearch()
wxFlexGridSizer* toplevel = new wxFlexGridSizer(4, 1, 0, 0);
SetSizer(toplevel);
wxFlexGridSizer* buttons = new wxFlexGridSizer(1, 5, 0, 0);
wxFlexGridSizer* buttons = new wxFlexGridSizer(1, 6, 0, 0);
buttons->Add(tmp = new wxButton(this, wxID_RESET, wxT("Reset")), 0, wxGROW);
tmp->Connect(wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler(wxwindow_memorysearch::on_button_click),
NULL, this);
@ -224,6 +231,9 @@ wxwindow_memorysearch::wxwindow_memorysearch()
buttons->Add(hexmode2 = new wxCheckBox(this, wxID_HEX_SELECT, wxT("Hex display")), 0, wxGROW);
hexmode2->Connect(wxEVT_COMMAND_CHECKBOX_CLICKED,
wxCommandEventHandler(wxwindow_memorysearch::on_button_click), NULL, this);
buttons->Add(tmp = new wxButton(this, wxID_ADD, wxT("Add")), 0, wxGROW);
tmp->Connect(wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler(wxwindow_memorysearch::on_add),
NULL, this);
toplevel->Add(buttons);
wxFlexGridSizer* searches = new wxFlexGridSizer(1, BROW_SIZE, 0, 0);
@ -236,7 +246,7 @@ wxwindow_memorysearch::wxwindow_memorysearch()
toplevel->Add(count = new wxStaticText(this, wxID_ANY, wxT("XXX candidates")), 0, wxGROW);
toplevel->Add(matches = new wxTextCtrl(this, wxID_ANY, wxT(""), wxDefaultPosition, wxSize(500, 300),
wxTE_MULTILINE | wxTE_READONLY | wxTE_DONTWRAP), 1, wxGROW);
wxTE_MULTILINE | wxTE_READONLY | wxTE_DONTWRAP | wxTE_NOHIDESEL), 1, wxGROW);
toplevel->SetSizeHints(this);
Fit();
@ -261,14 +271,46 @@ void wxwindow_memorysearch::on_close(wxCloseEvent& e)
mwatch = NULL;
}
void wxwindow_memorysearch::on_add(wxCommandEvent& e)
{
long start, end;
long startx, starty, endx, endy;
matches->GetSelection(&start, &end);
if(start == end)
return;
if(!matches->PositionToXY(start, &startx, &starty))
return;
if(!matches->PositionToXY(end, &endx, &endy))
return;
if(endx == 0 && endy != 0)
endy--;
char wch = watchchars[typecode];
for(long r = starty; r <= endy; r++) {
if(!addresses.count(r))
return;
uint64_t addr = addresses[r];
try {
std::string n = pick_text(this, "Name for watch", (stringfmt() << "Enter name for watch at 0x"
<< std::hex << addr << ":").str());
if(n == "")
continue;
std::string e = (stringfmt() << "C0x" << std::hex << addr << "z" << wch).str();
runemufn([n, e]() { set_watchexpr_for(n, e); });
} catch(canceled_exception& e) {
}
}
}
void wxwindow_memorysearch::update()
{
std::string ret;
uint64_t addr_count;
runemufn([msearch, &ret, &addr_count, typecode, hexmode]() {
runemufn([msearch, &ret, &addr_count, typecode, hexmode, &addresses]() {
addr_count = msearch->get_candidate_count();
if(addr_count <= CANDIDATE_LIMIT) {
addresses.clear();
std::list<uint64_t> addrs = msearch->get_candidates();
long j = 0;
for(auto i : addrs) {
std::ostringstream row;
row << hexformat_address(i) << " ";
@ -284,9 +326,11 @@ void wxwindow_memorysearch::update()
};
row << std::endl;
ret = ret + row.str();
addresses[j++] = i;
}
} else {
ret = "Too many candidates to display";
addresses.clear();
}
});
std::ostringstream x;