CoCalc provides the best real-time collaborative environment for Jupyter Notebooks, LaTeX documents, and SageMath, scalable from individual users to large groups and classes!
CoCalc provides the best real-time collaborative environment for Jupyter Notebooks, LaTeX documents, and SageMath, scalable from individual users to large groups and classes!
Path: blob/master/Windows/Debugger/CtrlDisAsmView.h
Views: 1401
#pragma once12// CtrlDisAsmView3//4// This Win32 control is made to be flexible and usable with5// every kind of CPU architecture that has fixed width instruction words.6// Just supply it an instance of a class derived from Debugger, with all methods7// overridden for full functionality. Look at the ppc one for an example.8//9// To add to a dialog box, just draw a User Control in the dialog editor,10// and set classname to "CtrlDisAsmView". you also need to call CtrlDisAsmView::init()11// before opening this dialog, to register the window class.12//13// To get a class instance to be able to access it, just use14// CtrlDisAsmView::getFrom(GetDlgItem(yourdialog, IDC_yourid)).1516#include <vector>17#include <algorithm>1819#include "Common/CommonWindows.h"20#include "Common/Log.h"21#include "Core/Debugger/DebugInterface.h"22#include "Core/Debugger/DisassemblyManager.h"2324class CtrlDisAsmView25{26HWND wnd;27HFONT font;28HFONT boldfont;29RECT rect;3031DisassemblyManager manager;32u32 curAddress;33u32 selectRangeStart;34u32 selectRangeEnd;35int rowHeight;36int charWidth;3738bool hasFocus;39bool showHex;40DebugInterface *debugger;41static TCHAR szClassName[];4243u32 windowStart;44int visibleRows;45bool whiteBackground;46bool displaySymbols;4748struct {49int addressStart;50int opcodeStart;51int argumentsStart;52int arrowsStart;53} pixelPositions;5455std::vector<u32> jumpStack;5657std::string searchQuery;58int matchAddress;59bool searching;60bool dontRedraw;61bool keyTaken;6263enum class CopyInstructionsMode {64OPCODES,65DISASM,66ADDRESSES,67};6869void assembleOpcode(u32 address, const std::string &defaultText);70std::string disassembleRange(u32 start, u32 size);71void disassembleToFile();72void search(bool continueSearch);73void followBranch();74void calculatePixelPositions();75bool getDisasmAddressText(u32 address, char* dest, bool abbreviateLabels, bool showData);76void updateStatusBarText();77void drawBranchLine(HDC hdc, std::map<u32, int> &addressPositions, const BranchLine &line);78void CopyInstructions(u32 startAddr, u32 endAddr, CopyInstructionsMode mode);79void NopInstructions(u32 startAddr, u32 endAddr);80std::set<std::string> getSelectedLineArguments();81void drawArguments(HDC hdc, const DisassemblyLineInfo &line, int x, int y, int textColor, const std::set<std::string> ¤tArguments);8283public:84CtrlDisAsmView(HWND _wnd);85~CtrlDisAsmView();86static void init();87static void deinit();88static LRESULT CALLBACK wndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam);89static CtrlDisAsmView * getFrom(HWND wnd);9091void onChar(WPARAM wParam, LPARAM lParam);92void onPaint(WPARAM wParam, LPARAM lParam);93void onVScroll(WPARAM wParam, LPARAM lParam);94void onKeyDown(WPARAM wParam, LPARAM lParam);95void onKeyUp(WPARAM wParam, LPARAM lParam);96void onMouseDown(WPARAM wParam, LPARAM lParam, int button);97void onMouseUp(WPARAM wParam, LPARAM lParam, int button);98void onMouseMove(WPARAM wParam, LPARAM lParam, int button);99void scrollAddressIntoView();100bool curAddressIsVisible();101void redraw();102void scanFunctions();103void clearFunctions() { manager.clear(); };104105void getOpcodeText(u32 address, char* dest, int bufsize);106int getRowHeight() { return rowHeight; };107u32 yToAddress(int y);108109void setDontRedraw(bool b) { dontRedraw = b; };110void setDebugger(DebugInterface *deb)111{112debugger=deb;113curAddress=debugger->getPC();114manager.setCpu(deb);115}116DebugInterface *getDebugger()117{118return debugger;119}120121void scrollStepping(u32 newPc);122u32 getInstructionSizeAt(u32 address);123124void gotoAddr(unsigned int addr)125{126if (positionLocked_ != 0)127return;128u32 windowEnd = manager.getNthNextAddress(windowStart,visibleRows);129u32 newAddress = manager.getStartAddress(addr);130131if (newAddress < windowStart || newAddress >= windowEnd)132{133windowStart = manager.getNthPreviousAddress(newAddress,visibleRows/2);134}135136setCurAddress(newAddress);137scanFunctions();138redraw();139}140void gotoPC()141{142gotoAddr(debugger->getPC());143}144u32 getSelection()145{146return curAddress;147}148149void setShowMode(bool s)150{151showHex=s;152}153154void toggleBreakpoint(bool toggleEnabled = false);155void editBreakpoint();156157void scrollWindow(int lines)158{159if (lines < 0)160windowStart = manager.getNthPreviousAddress(windowStart,abs(lines));161else162windowStart = manager.getNthNextAddress(windowStart,lines);163164scanFunctions();165redraw();166}167168void setCurAddress(u32 newAddress, bool extend = false)169{170newAddress = manager.getStartAddress(newAddress);171u32 after = manager.getNthNextAddress(newAddress,1);172curAddress = newAddress;173selectRangeStart = extend ? std::min(selectRangeStart, newAddress) : newAddress;174selectRangeEnd = extend ? std::max(selectRangeEnd, after) : after;175updateStatusBarText();176}177178void LockPosition() {179positionLocked_++;180}181void UnlockPosition() {182positionLocked_--;183_assert_(positionLocked_ >= 0);184}185186private:187bool redrawScheduled_ = false;188int positionLocked_ = 0;189};190191192