mirror of
https://github.com/wolfpld/tracy.git
synced 2024-11-10 02:31:48 +00:00
Disassemble symbol code fragments.
This commit is contained in:
parent
79db7f4457
commit
3e134cdce5
@ -1,6 +1,8 @@
|
||||
#include <inttypes.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include <capstone/capstone.h>
|
||||
|
||||
#include "../imgui/imgui.h"
|
||||
#include "TracyImGui.hpp"
|
||||
#include "TracyPrint.hpp"
|
||||
@ -26,7 +28,7 @@ SourceView::~SourceView()
|
||||
delete[] m_data;
|
||||
}
|
||||
|
||||
void SourceView::Open( const char* fileName, int line, uint64_t symAddr )
|
||||
void SourceView::Open( const char* fileName, int line, uint64_t symAddr, const Worker& worker )
|
||||
{
|
||||
m_targetLine = line;
|
||||
m_selectedLine = line;
|
||||
@ -70,6 +72,47 @@ void SourceView::Open( const char* fileName, int line, uint64_t symAddr )
|
||||
txt = end;
|
||||
}
|
||||
}
|
||||
|
||||
m_asm.clear();
|
||||
if( symAddr == 0 ) return;
|
||||
const auto arch = worker.GetCpuArch();
|
||||
if( arch == CpuArchUnknown ) return;
|
||||
uint32_t len;
|
||||
auto code = worker.GetSymbolCode( symAddr, len );
|
||||
if( !code ) return;
|
||||
csh handle;
|
||||
cs_err rval;
|
||||
switch( arch )
|
||||
{
|
||||
case CpuArchX86:
|
||||
rval = cs_open( CS_ARCH_X86, CS_MODE_32, &handle );
|
||||
break;
|
||||
case CpuArchX64:
|
||||
rval = cs_open( CS_ARCH_X86, CS_MODE_64, &handle );
|
||||
break;
|
||||
case CpuArchArm32:
|
||||
rval = cs_open( CS_ARCH_ARM, CS_MODE_ARM, &handle );
|
||||
break;
|
||||
case CpuArchArm64:
|
||||
rval = cs_open( CS_ARCH_ARM64, CS_MODE_ARM, &handle );
|
||||
break;
|
||||
default:
|
||||
assert( false );
|
||||
break;
|
||||
}
|
||||
if( rval != CS_ERR_OK ) return;
|
||||
cs_insn* insn;
|
||||
size_t cnt = cs_disasm( handle, (const uint8_t*)code, len, symAddr, 0, &insn );
|
||||
if( cnt > 0 )
|
||||
{
|
||||
m_asm.reserve( cnt );
|
||||
for( size_t i=0; i<cnt; i++ )
|
||||
{
|
||||
m_asm.emplace_back( AsmLine { insn[i].address, insn[i].mnemonic, insn[i].op_str } );
|
||||
}
|
||||
cs_free( insn, cnt );
|
||||
}
|
||||
cs_close( &handle );
|
||||
}
|
||||
|
||||
void SourceView::Render( const Worker& worker )
|
||||
|
@ -1,3 +1,4 @@
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
struct ImFont;
|
||||
@ -15,11 +16,18 @@ class SourceView
|
||||
const char* end;
|
||||
};
|
||||
|
||||
struct AsmLine
|
||||
{
|
||||
uint64_t addr;
|
||||
std::string mnemonic;
|
||||
std::string operands;
|
||||
};
|
||||
|
||||
public:
|
||||
SourceView( ImFont* font );
|
||||
~SourceView();
|
||||
|
||||
void Open( const char* fileName, int line, uint64_t symAddr );
|
||||
void Open( const char* fileName, int line, uint64_t symAddr, const Worker& worker );
|
||||
void Render( const Worker& worker );
|
||||
|
||||
private:
|
||||
@ -34,6 +42,7 @@ private:
|
||||
int m_selectedLine;
|
||||
|
||||
std::vector<Line> m_lines;
|
||||
std::vector<AsmLine> m_asm;
|
||||
};
|
||||
|
||||
}
|
||||
|
@ -196,7 +196,7 @@ void View::InitTextEditor( ImFont* font )
|
||||
void View::SetTextEditorFile( const char* fileName, int line, uint64_t symAddr )
|
||||
{
|
||||
m_sourceViewFile = fileName;
|
||||
m_sourceView->Open( fileName, line, symAddr );
|
||||
m_sourceView->Open( fileName, line, symAddr, m_worker );
|
||||
}
|
||||
|
||||
const char* View::ShortenNamespace( const char* name ) const
|
||||
|
Loading…
Reference in New Issue
Block a user