Source map in DebugInfo. IVM needs to port its stuff over eventually.

This commit is contained in:
Ben Vanik
2014-01-25 21:20:28 -08:00
parent 4609339c5a
commit 0cca23cdd7
12 changed files with 135 additions and 19 deletions

View File

@@ -17,12 +17,56 @@ DebugInfo::DebugInfo() :
source_disasm_(0),
raw_hir_disasm_(0),
hir_disasm_(0),
machine_code_disasm_(0) {
machine_code_disasm_(0),
source_map_count_(0),
source_map_(NULL) {
}
DebugInfo::~DebugInfo() {
xe_free(source_map_);
xe_free(source_disasm_);
xe_free(raw_hir_disasm_);
xe_free(hir_disasm_);
xe_free(machine_code_disasm_);
}
void DebugInfo::InitializeSourceMap(size_t source_map_count,
SourceMapEntry* source_map) {
source_map_count_ = source_map_count;
source_map_ = source_map;
// TODO(benvanik): ensure sorted in some way? MC offset?
}
SourceMapEntry* DebugInfo::LookupSourceOffset(uint64_t offset) {
// TODO(benvanik): binary search? We know the list is sorted by code order.
for (size_t n = 0; n < source_map_count_; n++) {
auto entry = &source_map_[n];
if (entry->source_offset == offset) {
return entry;
}
}
return NULL;
}
SourceMapEntry* DebugInfo::LookupHIROffset(uint64_t offset) {
// TODO(benvanik): binary search? We know the list is sorted by code order.
for (size_t n = 0; n < source_map_count_; n++) {
auto entry = &source_map_[n];
if (entry->hir_offset >= offset) {
return entry;
}
}
return NULL;
}
SourceMapEntry* DebugInfo::LookupCodeOffset(uint64_t offset) {
// TODO(benvanik): binary search? We know the list is sorted by code order.
for (size_t n = 0; n < source_map_count_; n++) {
auto entry = &source_map_[n];
if (entry->code_offset >= offset) {
return entry;
}
}
return 0;
}

View File

@@ -25,10 +25,20 @@ enum DebugInfoFlags {
DEBUG_INFO_HIR_DISASM = (1 << 3),
DEBUG_INFO_MACHINE_CODE_DISASM = (1 << 4),
DEBUG_INFO_SOURCE_MAP = (1 << 5),
DEBUG_INFO_DEFAULT = DEBUG_INFO_SOURCE_MAP,
DEBUG_INFO_ALL_DISASM = 0xFFFF,
};
typedef struct SourceMapEntry_s {
uint64_t source_offset; // Original source address/offset.
uint64_t hir_offset; // Block ordinal (16b) | Instr ordinal (16b)
uint64_t code_offset; // Offset from emitted code start.
} SourceMapEntry;
class DebugInfo {
public:
DebugInfo();
@@ -43,16 +53,20 @@ public:
const char* machine_code_disasm() const { return machine_code_disasm_; }
void set_machine_code_disasm(char* value) { machine_code_disasm_ = value; }
// map functions: source addr -> hir index (raw?)
// hir index (raw?) to lir index (raw?)
// lir index (raw?) to machine code offset
// source -> machine code offset
void InitializeSourceMap(size_t source_map_count,
SourceMapEntry* source_map);
SourceMapEntry* LookupSourceOffset(uint64_t offset);
SourceMapEntry* LookupHIROffset(uint64_t offset);
SourceMapEntry* LookupCodeOffset(uint64_t offset);
private:
char* source_disasm_;
char* raw_hir_disasm_;
char* hir_disasm_;
char* machine_code_disasm_;
size_t source_map_count_;
SourceMapEntry* source_map_;
};

View File

@@ -250,7 +250,7 @@ int Runtime::DemandFunction(
if (symbol_status == SymbolInfo::STATUS_NEW) {
// Symbol is undefined, so define now.
Function* function = NULL;
int result = frontend_->DefineFunction(symbol_info, DEBUG_INFO_NONE, &function);
int result = frontend_->DefineFunction(symbol_info, DEBUG_INFO_DEFAULT, &function);
if (result) {
symbol_info->set_status(SymbolInfo::STATUS_FAILED);
return result;