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/Core/Debugger/DisassemblyManager.h
Views: 1401
// Copyright (c) 2012- PPSSPP Project.12// This program is free software: you can redistribute it and/or modify3// it under the terms of the GNU General Public License as published by4// the Free Software Foundation, version 2.0 or later versions.56// This program is distributed in the hope that it will be useful,7// but WITHOUT ANY WARRANTY; without even the implied warranty of8// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the9// GNU General Public License 2.0 for more details.1011// A copy of the GPL 2.0 should have been included with the program.12// If not, see http://www.gnu.org/licenses/1314// Official git repository and contact information can be found at15// https://github.com/hrydgard/ppsspp and http://www.ppsspp.org/.1617#pragma once1819#include "ppsspp_config.h"20#include <mutex>21#include "Common/CommonTypes.h"22#include "Core/Debugger/SymbolMap.h"23#include "Core/MIPS/MIPSAnalyst.h"2425#if PPSSPP_ARCH(AMD64)26typedef u64 HashType;27#else28typedef u32 HashType;29#endif3031enum DisassemblyLineType { DISTYPE_OPCODE, DISTYPE_MACRO, DISTYPE_DATA, DISTYPE_OTHER };3233struct DisassemblyLineInfo34{35DisassemblyLineType type;36MIPSAnalyst::MipsOpcodeInfo info;37std::string name;38std::string params;39u32 totalSize;40};4142enum LineType { LINE_UP, LINE_DOWN, LINE_RIGHT };4344struct BranchLine45{46u32 first;47u32 second;48LineType type;49int laneIndex;5051bool operator<(const BranchLine& other) const52{53return first < other.first;54}55};5657class DisassemblyEntry58{59public:60virtual ~DisassemblyEntry() { };61virtual void recheck() = 0;62virtual int getNumLines() = 0;63virtual int getLineNum(u32 address, bool findStart) = 0;64virtual u32 getLineAddress(int line) = 0;65virtual u32 getTotalSize() = 0;66virtual bool disassemble(u32 address, DisassemblyLineInfo& dest, bool insertSymbols, DebugInterface *cpuDebug) = 0;67virtual void getBranchLines(u32 start, u32 size, std::vector<BranchLine>& dest) { };68};6970class DisassemblyFunction: public DisassemblyEntry71{72public:73DisassemblyFunction(u32 _address, u32 _size);74~DisassemblyFunction();75void recheck() override;76int getNumLines() override;77int getLineNum(u32 address, bool findStart) override;78u32 getLineAddress(int line) override;79u32 getTotalSize() override { return size; };80bool disassemble(u32 address, DisassemblyLineInfo& dest, bool insertSymbols, DebugInterface *cpuDebug) override;81void getBranchLines(u32 start, u32 size, std::vector<BranchLine>& dest) override;8283private:84void generateBranchLines();85void load();86void clear();87void addOpcodeSequence(u32 start, u32 end);8889u32 address;90u32 size;91HashType hash;92std::vector<BranchLine> lines;93std::map<u32,DisassemblyEntry*> entries;94std::vector<u32> lineAddresses;95std::recursive_mutex lock_;96};9798class DisassemblyOpcode: public DisassemblyEntry99{100public:101DisassemblyOpcode(u32 _address, int _num): address(_address), num(_num) { }102void recheck() override { };103int getNumLines() override { return num; };104int getLineNum(u32 address, bool findStart) override { return (address - this->address) / 4; };105u32 getLineAddress(int line) override { return address + line * 4; };106u32 getTotalSize() override { return num * 4; };107bool disassemble(u32 address, DisassemblyLineInfo& dest, bool insertSymbols, DebugInterface *cpuDebug) override;108void getBranchLines(u32 start, u32 size, std::vector<BranchLine>& dest) override;109110private:111u32 address;112int num;113};114115116class DisassemblyMacro: public DisassemblyEntry117{118public:119DisassemblyMacro(u32 _address): address(_address) { }120121void setMacroLi(u32 _immediate, u8 _rt);122void setMacroMemory(const std::string &_name, u32 _immediate, u8 _rt, int _dataSize);123124void recheck() override { };125int getNumLines() override { return 1; };126int getLineNum(u32 address, bool findStart) override { return 0; };127u32 getLineAddress(int line) override { return address; };128u32 getTotalSize() override { return numOpcodes * 4; };129bool disassemble(u32 address, DisassemblyLineInfo& dest, bool insertSymbols, DebugInterface *cpuDebug) override;130private:131enum MacroType { MACRO_LI, MACRO_MEMORYIMM };132133MacroType type;134std::string name;135u32 immediate;136u32 address;137u32 numOpcodes;138u8 rt;139int dataSize;140};141142143class DisassemblyData: public DisassemblyEntry144{145public:146DisassemblyData(u32 _address, u32 _size, DataType _type);147148void recheck() override;149int getNumLines() override { return (int)lines.size(); };150int getLineNum(u32 address, bool findStart) override;151u32 getLineAddress(int line) override { return lineAddresses[line]; };152u32 getTotalSize() override { return size; };153bool disassemble(u32 address, DisassemblyLineInfo& dest, bool insertSymbols, DebugInterface *cpuDebug) override;154155private:156void createLines();157158struct DataEntry159{160std::string text;161u32 size;162int lineNum;163};164165u32 address;166u32 size;167HashType hash;168DataType type;169std::map<u32,DataEntry> lines;170std::vector<u32> lineAddresses;171std::recursive_mutex lock_;172};173174class DisassemblyComment: public DisassemblyEntry175{176public:177DisassemblyComment(u32 _address, u32 _size, std::string name, std::string param);178179void recheck() override { };180int getNumLines() override { return 1; };181int getLineNum(u32 address, bool findStart) override { return 0; };182u32 getLineAddress(int line) override { return address; };183u32 getTotalSize() override { return size; };184bool disassemble(u32 address, DisassemblyLineInfo& dest, bool insertSymbols, DebugInterface *cpuDebug) override;185186private:187u32 address;188u32 size;189std::string name;190std::string param;191};192193class DebugInterface;194195class DisassemblyManager196{197public:198~DisassemblyManager();199200void clear();201202void setCpu(DebugInterface* _cpu) { cpu = _cpu; };203void setMaxParamChars(int num) { maxParamChars = num; clear(); };204void getLine(u32 address, bool insertSymbols, DisassemblyLineInfo &dest, DebugInterface *cpuDebug = nullptr);205void analyze(u32 address, u32 size);206std::vector<BranchLine> getBranchLines(u32 start, u32 size);207208u32 getStartAddress(u32 address);209u32 getNthPreviousAddress(u32 address, int n = 1);210u32 getNthNextAddress(u32 address, int n = 1);211212static DebugInterface* getCpu() { return cpu; };213static int getMaxParamChars() { return maxParamChars; };214private:215static std::map<u32,DisassemblyEntry*> entries;216static std::recursive_mutex entriesLock_;217static DebugInterface* cpu;218static int maxParamChars;219};220221bool isInInterval(u32 start, u32 size, u32 value);222bool IsLikelyStringAt(uint32_t addr);223224225