Example #1
0
void CCodeView::OnPopupMenu(wxCommandEvent& event)
{
#if wxUSE_CLIPBOARD
  wxTheClipboard->Open();
#endif

  switch (event.GetId())
  {
  case IDM_GOTOINMEMVIEW:
    // CMemoryDlg::Goto(selection);
    break;

#if wxUSE_CLIPBOARD
  case IDM_COPYADDRESS:
    wxTheClipboard->SetData(new wxTextDataObject(wxString::Format("%08x", m_selection)));
    break;

  case IDM_COPYCODE:
  {
    std::string disasm = m_debugger->Disassemble(m_selection);
    wxTheClipboard->SetData(new wxTextDataObject(StrToWxStr(disasm)));
  }
  break;

  case IDM_COPYHEX:
  {
    std::string temp = StringFromFormat("%08x", m_debugger->ReadInstruction(m_selection));
    wxTheClipboard->SetData(new wxTextDataObject(StrToWxStr(temp)));
  }
  break;

  case IDM_COPYFUNCTION:
  {
    Symbol* symbol = m_symbol_db->GetSymbolFromAddr(m_selection);
    if (symbol)
    {
      std::string text;
      text = text + symbol->name + "\r\n";
      // we got a function
      u32 start = symbol->address;
      u32 end = start + symbol->size;
      for (u32 addr = start; addr != end; addr += 4)
      {
        std::string disasm = m_debugger->Disassemble(addr);
        text += StringFromFormat("%08x: ", addr) + disasm + "\r\n";
      }
      wxTheClipboard->SetData(new wxTextDataObject(StrToWxStr(text)));
    }
  }
  break;
#endif

  case IDM_RUNTOHERE:
    m_debugger->SetBreakpoint(m_selection);
    m_debugger->RunToBreakpoint();
    Refresh();
    break;

  // Insert blr or restore old value
  case IDM_INSERTBLR:
    InsertBlrNop(0);
    Refresh();
    break;
  case IDM_INSERTNOP:
    InsertBlrNop(1);
    Refresh();
    break;

  case IDM_JITRESULTS:
  {
    // Propagate back to the parent window and tell it
    // to flip to the JIT tab for the current address.
    wxCommandEvent jit_event(wxEVT_HOST_COMMAND, IDM_UPDATE_JIT_PANE);
    GetEventHandler()->AddPendingEvent(jit_event);
  }
  break;

  case IDM_FOLLOWBRANCH:
  {
    u32 dest = AddrToBranch(m_selection);
    if (dest)
    {
      Center(dest);
      RaiseEvent();
    }
  }
  break;

  case IDM_ADDFUNCTION:
    m_symbol_db->AddFunction(m_selection);
    Host_NotifyMapLoaded();
    break;

  case IDM_RENAMESYMBOL:
  {
    Symbol* symbol = m_symbol_db->GetSymbolFromAddr(m_selection);
    if (symbol)
    {
      wxTextEntryDialog input_symbol(this, _("Rename symbol:"), wxGetTextFromUserPromptStr,
                                     StrToWxStr(symbol->name));
      if (input_symbol.ShowModal() == wxID_OK)
      {
        symbol->name = WxStrToStr(input_symbol.GetValue());
        Refresh();  // Redraw to show the renamed symbol
      }
      Host_NotifyMapLoaded();
    }
  }
  break;

  case IDM_PATCHALERT:
    break;
  }

#if wxUSE_CLIPBOARD
  wxTheClipboard->Close();
#endif
  event.Skip();
}
Example #2
0
void CCodeView::OnPopupMenu(wxCommandEvent& event)
{
  switch (event.GetId())
  {
  case IDM_GOTOINMEMVIEW:
    // CMemoryDlg::Goto(selection);
    break;

#if wxUSE_CLIPBOARD
  case IDM_COPYADDRESS:
  {
    wxClipboardLocker locker;
    wxTheClipboard->SetData(new wxTextDataObject(wxString::Format("%08x", m_selection)));
  }
  break;

  case IDM_COPYCODE:
  {
    wxClipboardLocker locker;
    std::string disasm = m_debugger->Disassemble(m_selection);
    wxTheClipboard->SetData(new wxTextDataObject(StrToWxStr(disasm)));
  }
  break;

  case IDM_COPYHEX:
  {
    wxClipboardLocker locker;
    wxTheClipboard->SetData(
        new wxTextDataObject(wxString::Format("%08x", m_debugger->ReadInstruction(m_selection))));
  }
  break;

  case IDM_COPYFUNCTION:
  {
    Symbol* symbol = m_symbol_db->GetSymbolFromAddr(m_selection);
    if (symbol)
    {
      std::string text;
      text = text + symbol->name + "\r\n";
      // we got a function
      u32 start = symbol->address;
      u32 end = start + symbol->size;
      for (u32 addr = start; addr != end; addr += 4)
      {
        std::string disasm = m_debugger->Disassemble(addr);
        text += StringFromFormat("%08x: ", addr) + disasm + "\r\n";
      }
      wxClipboardLocker locker;
      wxTheClipboard->SetData(new wxTextDataObject(StrToWxStr(text)));
    }
  }
  break;
#endif

  case IDM_RUNTOHERE:
    m_debugger->SetBreakpoint(m_selection);
    m_debugger->RunToBreakpoint();
    Refresh();
    break;

  // Insert blr or restore old value
  case IDM_INSERTBLR:
    InsertBlrNop(0);
    Refresh();
    break;

  case IDM_INSERTNOP:
    InsertBlrNop(1);
    Refresh();
    break;

  case IDM_ASSEMBLE:
  {
    if (!PowerPC::HostIsInstructionRAMAddress(m_selection))
      break;
    const PowerPC::TryReadInstResult read_result = PowerPC::TryReadInstruction(m_selection);
    if (!read_result.valid)
      break;
    AssemblerEntryDialog dialog(m_selection, this, _("Enter instruction code:"),
                                wxGetTextFromUserPromptStr,
                                wxString::Format(wxT("%#08x"), read_result.hex));
    if (dialog.ShowModal() == wxID_OK)
    {
      unsigned long code;
      if (dialog.GetValue().ToULong(&code, 0) && code <= std::numeric_limits<u32>::max())
      {
        m_debugger->InsertBLR(m_selection, code);
        Refresh();
      }
    }
    break;
  }

  case IDM_JITRESULTS:
  {
    // Propagate back to the parent window and tell it
    // to flip to the JIT tab for the current address.
    wxCommandEvent jit_event(wxEVT_HOST_COMMAND, IDM_UPDATE_JIT_PANE);
    GetEventHandler()->AddPendingEvent(jit_event);
  }
  break;

  case IDM_FOLLOWBRANCH:
  {
    u32 dest = AddrToBranch(m_selection);
    if (dest)
    {
      Center(dest);
      RaiseEvent();
    }
  }
  break;

  case IDM_ADDFUNCTION:
    m_symbol_db->AddFunction(m_selection);
    Host_NotifyMapLoaded();
    break;

  case IDM_RENAMESYMBOL:
  {
    Symbol* symbol = m_symbol_db->GetSymbolFromAddr(m_selection);
    if (symbol)
    {
      wxTextEntryDialog input_symbol(this, _("Rename symbol:"), wxGetTextFromUserPromptStr,
                                     StrToWxStr(symbol->name));
      if (input_symbol.ShowModal() == wxID_OK)
      {
        symbol->name = WxStrToStr(input_symbol.GetValue());
        Refresh();  // Redraw to show the renamed symbol
      }
      Host_NotifyMapLoaded();
    }
  }
  break;

  case IDM_SETSYMBOLSIZE:
  {
    Symbol* symbol = m_symbol_db->GetSymbolFromAddr(m_selection);
    if (!symbol)
      break;

    wxTextEntryDialog dialog(this,
                             wxString::Format(_("Enter symbol (%s) size:"), symbol->name.c_str()),
                             wxGetTextFromUserPromptStr, wxString::Format(wxT("%i"), symbol->size));

    if (dialog.ShowModal() == wxID_OK)
    {
      unsigned long size;
      if (dialog.GetValue().ToULong(&size, 0) && size <= std::numeric_limits<u32>::max())
      {
        PPCAnalyst::ReanalyzeFunction(symbol->address, *symbol, size);
        Refresh();
        Host_NotifyMapLoaded();
      }
    }
  }
  break;

  case IDM_SETSYMBOLEND:
  {
    Symbol* symbol = m_symbol_db->GetSymbolFromAddr(m_selection);
    if (!symbol)
      break;

    wxTextEntryDialog dialog(
        this, wxString::Format(_("Enter symbol (%s) end address:"), symbol->name.c_str()),
        wxGetTextFromUserPromptStr, wxString::Format(wxT("%#08x"), symbol->address + symbol->size));

    if (dialog.ShowModal() == wxID_OK)
    {
      unsigned long address;
      if (dialog.GetValue().ToULong(&address, 0) && address <= std::numeric_limits<u32>::max() &&
          address >= symbol->address)
      {
        PPCAnalyst::ReanalyzeFunction(symbol->address, *symbol, address - symbol->address);
        Refresh();
        Host_NotifyMapLoaded();
      }
    }
  }
  break;

  case IDM_PATCHALERT:
    break;

  default:
    event.Skip();
    break;
  }
}