tracy/server/TracySourceView.hpp

230 lines
6.1 KiB
C++
Raw Normal View History

2020-04-01 23:02:42 +00:00
#ifndef __TRACYSOURCEVIEW_HPP__
#define __TRACYSOURCEVIEW_HPP__
2020-03-25 21:37:34 +00:00
#include <string>
#include <vector>
2020-04-04 00:25:12 +00:00
#include "tracy_robin_hood.h"
2020-04-26 20:26:17 +00:00
#include "TracyCharUtil.hpp"
2020-03-28 00:22:27 +00:00
#include "TracyDecayValue.hpp"
2020-04-26 12:23:16 +00:00
#include "../common/TracyProtocol.hpp"
2020-03-28 00:22:27 +00:00
struct ImFont;
namespace tracy
{
2020-04-17 17:09:13 +00:00
class View;
class Worker;
class SourceView
{
public:
enum class RegsX86 : uint8_t
{
2020-05-01 14:14:27 +00:00
invalid, flags,
rax, rbx, rcx, rdx, rsi, rdi, rbp, rsp, r8, r9, r10, r11, r12, r13, r14, r15,
mm0, mm1, mm2, mm3, mm4, mm5, mm6, mm7,
xmm0, xmm1, xmm2, xmm3, xmm4, xmm5, xmm6, xmm7, xmm8, xmm9,
xmm10, xmm11, xmm12, xmm13, xmm14, xmm15, xmm16, xmm17, xmm18, xmm19,
xmm20, xmm21, xmm22, xmm23, xmm24, xmm25, xmm26, xmm27, xmm28, xmm29,
xmm30, xmm31, k0, k1, k2, k3, k4, k5, k6, k7,
NUMBER_OF_ENTRIES
};
private:
2020-04-24 21:48:18 +00:00
enum class TokenColor : uint8_t
{
Default,
Comment,
Preprocessor,
String,
CharacterLiteral,
Keyword,
Number,
Punctuation,
Type,
Special
2020-04-24 21:48:18 +00:00
};
struct Token
{
const char* begin;
const char* end;
TokenColor color;
};
struct Line
{
const char* begin;
const char* end;
2020-04-24 21:48:18 +00:00
std::vector<Token> tokens;
};
2020-04-26 20:26:17 +00:00
struct AsmOpParams
{
uint8_t type;
uint16_t width;
};
2020-04-26 22:49:37 +00:00
enum class LeaData : uint8_t
{
none,
b,
bd,
bi,
bid,
d,
i,
id,
r,
rd
};
2020-05-01 17:15:46 +00:00
enum { ReadBit = 0x100 };
enum { WriteBit = 0x200 };
enum { ReuseBit = 0x400 };
enum { RegMask = 0x0FF };
enum { FlagMask = 0xF00 };
2020-05-01 17:15:46 +00:00
2020-03-25 21:37:34 +00:00
struct AsmLine
{
uint64_t addr;
2020-03-27 23:53:48 +00:00
uint64_t jumpAddr;
2020-03-25 21:37:34 +00:00
std::string mnemonic;
std::string operands;
2020-04-19 13:54:43 +00:00
uint8_t len;
2020-04-26 22:49:37 +00:00
LeaData leaData;
2020-05-01 18:09:21 +00:00
bool jumpConditional;
2020-04-26 20:26:17 +00:00
std::vector<AsmOpParams> params;
union
{
RegsX86 readX86[12];
};
union
{
RegsX86 writeX86[20];
};
uint16_t regData[20];
2020-03-25 21:37:34 +00:00
};
enum { AsmLineSize = sizeof( AsmLine ) };
2020-04-04 00:25:12 +00:00
struct JumpData
{
uint64_t min;
uint64_t max;
int level;
std::vector<uint64_t> source;
};
2020-04-08 20:04:00 +00:00
enum
{
DisplaySource,
DisplayAsm,
DisplayMixed
};
public:
SourceView( ImFont* font );
~SourceView();
void OpenSource( const char* fileName, int line, const View& view );
void OpenSymbol( const char* fileName, int line, uint64_t baseAddr, uint64_t symAddr, const Worker& worker, const View& view );
2020-04-17 17:09:13 +00:00
void Render( const Worker& worker, const View& view );
void CalcInlineStats( bool val ) { m_calcInlineStats = val; }
private:
void ParseSource( const char* fileName, const Worker* worker, const View& view );
bool Disassemble( uint64_t symAddr, const Worker& worker );
void RenderSimpleSourceView();
2020-04-17 17:09:13 +00:00
void RenderSymbolView( const Worker& worker, const View& view );
2020-04-17 17:09:13 +00:00
void RenderSymbolSourceView( uint32_t iptotal, unordered_flat_map<uint64_t, uint32_t> ipcount, unordered_flat_map<uint64_t, uint32_t> ipcountAsm, uint32_t ipmax, const Worker& worker, const View& view );
uint64_t RenderSymbolAsmView( uint32_t iptotal, unordered_flat_map<uint64_t, uint32_t> ipcount, uint32_t ipmax, const Worker& worker, const View& view );
2020-04-08 20:04:00 +00:00
void RenderLine( const Line& line, int lineNum, uint32_t ipcnt, uint32_t iptotal, uint32_t ipmax, const Worker* worker );
2020-05-01 20:39:37 +00:00
void RenderAsmLine( AsmLine& line, uint32_t ipcnt, uint32_t iptotal, uint32_t ipmax, const Worker& worker, uint64_t& jumpOut, int maxAddrLen, const View& view );
2020-03-25 21:53:05 +00:00
void SelectLine( uint32_t line, const Worker* worker, bool changeAsmLine = true, uint64_t targetAddr = 0 );
2020-04-08 21:59:10 +00:00
void SelectAsmLines( uint32_t file, uint32_t line, const Worker& worker, bool changeAsmLine = true, uint64_t targetAddr = 0 );
void SelectAsmLinesHover( uint32_t file, uint32_t line, const Worker& worker );
2020-04-08 20:57:42 +00:00
void GatherIpStats( uint64_t addr, uint32_t& iptotalSrc, uint32_t& iptotalAsm, unordered_flat_map<uint64_t, uint32_t>& ipcountSrc, unordered_flat_map<uint64_t, uint32_t>& ipcountAsm, uint32_t& ipmaxSrc, uint32_t& ipmaxAsm, const Worker& worker );
2020-04-26 20:26:17 +00:00
void SelectMicroArchitecture( const char* moniker );
2020-04-24 21:48:18 +00:00
TokenColor IdentifyToken( const char*& begin, const char* end );
std::vector<Token> Tokenize( const char* begin, const char* end );
void ResetAsm();
2020-05-01 20:39:37 +00:00
void FollowRead( int line, RegsX86 reg, int limit );
void FollowWrite( int line, RegsX86 reg, int limit );
void CheckRead( int line, RegsX86 reg, int limit );
void CheckWrite( int line, RegsX86 reg, int limit );
2020-04-24 21:48:18 +00:00
struct TokenizerState
{
void Reset()
{
isInComment = false;
isInPreprocessor = false;
}
bool isInComment;
bool isInPreprocessor;
};
ImFont* m_font;
const char* m_file;
uint32_t m_fileStringIdx;
2020-03-24 23:07:31 +00:00
uint64_t m_symAddr;
uint64_t m_baseAddr;
2020-03-25 21:53:05 +00:00
uint64_t m_targetAddr;
char* m_data;
size_t m_dataSize;
int m_targetLine;
int m_selectedLine;
2020-05-01 14:33:24 +00:00
int m_asmSelected;
DecayValue<int> m_hoveredLine;
DecayValue<uint32_t> m_hoveredSource;
2020-04-08 20:04:00 +00:00
int m_displayMode;
uint32_t m_codeLen;
2020-04-19 12:40:36 +00:00
int32_t m_disasmFail;
2020-03-28 00:22:27 +00:00
DecayValue<uint64_t> m_highlightAddr;
bool m_asmRelative;
bool m_asmBytes;
2020-04-01 23:37:56 +00:00
bool m_asmShowSourceLocation;
bool m_calcInlineStats;
uint8_t m_maxAsmBytes;
std::vector<Line> m_lines;
2020-03-25 21:37:34 +00:00
std::vector<AsmLine> m_asm;
2020-04-04 00:25:12 +00:00
unordered_flat_map<uint64_t, JumpData> m_jumpTable;
2020-04-04 11:51:55 +00:00
unordered_flat_set<uint64_t> m_jumpOut;
2020-04-04 00:25:12 +00:00
int m_maxJumpLevel;
2020-04-04 01:34:54 +00:00
bool m_showJumps;
2020-04-08 20:18:00 +00:00
2020-04-08 20:25:36 +00:00
unordered_flat_map<uint32_t, uint32_t> m_sourceFiles;
2020-04-08 20:57:42 +00:00
unordered_flat_set<uint64_t> m_selectedAddresses;
unordered_flat_set<uint64_t> m_selectedAddressesHover;
2020-04-08 23:45:38 +00:00
uint32_t m_maxLine;
2020-04-08 23:45:38 +00:00
int m_maxMnemonicLen;
2020-04-24 21:48:18 +00:00
TokenizerState m_tokenizer;
2020-04-26 12:23:16 +00:00
2020-04-26 20:26:17 +00:00
unordered_flat_map<const char*, int, charutil::Hasher, charutil::Comparator> m_microArchOpMap;
2020-04-26 12:23:16 +00:00
CpuArchitecture m_cpuArch;
2020-04-26 12:52:18 +00:00
int m_selMicroArch;
2020-04-26 20:26:17 +00:00
int m_idxMicroArch;
bool m_showLatency;
};
}
2020-04-01 23:02:42 +00:00
#endif