jak-project/goalc/debugger/DebugInfo.h
water111 951f31878e
[Source Line Debugger] Tracking objects and IR (#115)
* track where segments are when debugging

* missing windows include

* figure out what function we're in

* addr to IR is working
2020-11-13 22:33:57 -05:00

57 lines
1.3 KiB
C++

#pragma once
#include <vector>
#include <string>
#include <unordered_map>
#include <cassert>
#include "common/common_types.h"
#include "goalc/emitter/Instruction.h"
#include "goalc/debugger/disassemble.h"
struct FunctionDebugInfo {
u32 offset_in_seg; // not including type tag.
u32 length;
u8 seg;
std::string name;
std::vector<std::string> irs;
std::vector<InstructionInfo> instructions;
std::string disassemble_debug_info(bool* had_failure);
};
class DebugInfo {
public:
explicit DebugInfo(std::string obj_name);
FunctionDebugInfo& add_function(const std::string& name) {
if (m_functions.find(name) != m_functions.end()) {
assert(false);
}
auto& result = m_functions[name];
result.name = name;
return result;
}
bool lookup_function(FunctionDebugInfo** info, std::string* name, u32 offset, u8 seg) {
for (auto& kv : m_functions) {
auto start = kv.second.offset_in_seg;
auto end = start + kv.second.length;
if (offset >= start && offset < end && seg == kv.second.seg) {
*info = &kv.second;
*name = kv.first;
return true;
}
}
return false;
}
void clear() { m_functions.clear(); }
std::string disassemble_debug_functions(bool* had_failure);
private:
std::string m_obj_name;
std::unordered_map<std::string, FunctionDebugInfo> m_functions;
};