Mostly complete tracing. Probably a lot of bugs.

This commit is contained in:
Ben Vanik
2014-08-14 20:28:44 -07:00
parent cebf595958
commit c275562594
54 changed files with 1052 additions and 161 deletions

View File

@@ -26,6 +26,15 @@ enum DebugInfoFlags {
DEBUG_INFO_ALL_DISASM = 0xFFFF,
};
enum TraceFlags {
TRACE_NONE = 0,
TRACE_EXTERN_CALLS = (1 << 0),
TRACE_USER_CALLS = (1 << 1),
TRACE_SOURCE = (1 << 2),
TRACE_SOURCE_VALUES = (1 << 3),
TRACE_FUNCTION_GENERATION = (1 << 4),
};
typedef struct SourceMapEntry_s {
uint64_t source_offset; // Original source address/offset.
uint64_t hir_offset; // Block ordinal (16b) | Instr ordinal (16b)

View File

@@ -12,6 +12,7 @@
#include <alloy/runtime/debugger.h>
#include <alloy/runtime/symbol_info.h>
#include <alloy/runtime/thread_state.h>
#include <xdb/protocol.h>
namespace alloy {
namespace runtime {
@@ -73,8 +74,18 @@ int Function::Call(ThreadState* thread_state, uint64_t return_address) {
int result = 0;
uint64_t trace_base = thread_state->memory()->trace_base();
if (symbol_info_->behavior() == FunctionInfo::BEHAVIOR_EXTERN) {
auto handler = symbol_info_->extern_handler();
if (trace_base && true) {
auto ev = xdb::protocol::KernelCallEvent::Append(trace_base);
ev->type = xdb::protocol::EventType::KERNEL_CALL;
ev->thread_id = thread_state->thread_id();
ev->module_id = 0;
ev->ordinal = 0;
}
if (handler) {
handler(thread_state->raw_context(), symbol_info_->extern_arg0(),
symbol_info_->extern_arg1());
@@ -83,8 +94,28 @@ int Function::Call(ThreadState* thread_state, uint64_t return_address) {
symbol_info_->name().c_str());
result = 1;
}
if (trace_base && true) {
auto ev = xdb::protocol::KernelCallReturnEvent::Append(trace_base);
ev->type = xdb::protocol::EventType::KERNEL_CALL_RETURN;
ev->thread_id = thread_state->thread_id();
}
} else {
if (trace_base && true) {
auto ev = xdb::protocol::UserCallEvent::Append(trace_base);
ev->type = xdb::protocol::EventType::USER_CALL;
ev->call_type = 0; // ?
ev->thread_id = thread_state->thread_id();
ev->address = static_cast<uint32_t>(symbol_info_->address());
}
CallImpl(thread_state, return_address);
if (trace_base && true) {
auto ev = xdb::protocol::UserCallReturnEvent::Append(trace_base);
ev->type = xdb::protocol::EventType::USER_CALL_RETURN;
ev->thread_id = thread_state->thread_id();
}
}
if (original_thread_state != thread_state) {

View File

@@ -13,6 +13,7 @@
#include <alloy/runtime/module.h>
#include <poly/poly.h>
#include <xdb/protocol.h>
// TODO(benvanik): based on compiler support
#include <alloy/backend/ivm/ivm_backend.h>
@@ -26,7 +27,11 @@ namespace runtime {
using alloy::backend::Backend;
using alloy::frontend::Frontend;
Runtime::Runtime(Memory* memory) : memory_(memory) {}
Runtime::Runtime(Memory* memory, uint32_t debug_info_flags,
uint32_t trace_flags)
: memory_(memory),
debug_info_flags_(debug_info_flags),
trace_flags_(trace_flags) {}
Runtime::~Runtime() {
{
@@ -224,14 +229,24 @@ int Runtime::DemandFunction(FunctionInfo* symbol_info,
if (symbol_status == SymbolInfo::STATUS_NEW) {
// Symbol is undefined, so define now.
Function* function = nullptr;
int result =
frontend_->DefineFunction(symbol_info, DEBUG_INFO_DEFAULT, &function);
int result = frontend_->DefineFunction(symbol_info, debug_info_flags_,
trace_flags_, &function);
if (result) {
symbol_info->set_status(SymbolInfo::STATUS_FAILED);
return result;
}
symbol_info->set_function(function);
auto trace_base = memory()->trace_base();
if (trace_base && trace_flags_ & TRACE_FUNCTION_GENERATION) {
auto ev = xdb::protocol::FunctionCompiledEvent::Append(trace_base);
ev->type = xdb::protocol::EventType::FUNCTION_COMPILED;
ev->flags = 0;
ev->address = static_cast<uint32_t>(symbol_info->address());
ev->length =
static_cast<uint32_t>(symbol_info->end_address() - ev->address);
}
// Before we give the symbol back to the rest, let the debugger know.
debugger_->OnFunctionDefined(symbol_info, function);

View File

@@ -29,7 +29,8 @@ namespace runtime {
class Runtime {
public:
explicit Runtime(Memory* memory);
explicit Runtime(Memory* memory, uint32_t debug_info_flags = 0,
uint32_t trace_flags = 0);
virtual ~Runtime();
Memory* memory() const { return memory_; }
@@ -60,6 +61,9 @@ class Runtime {
protected:
Memory* memory_;
uint32_t debug_info_flags_;
uint32_t trace_flags_;
std::unique_ptr<Debugger> debugger_;
std::unique_ptr<frontend::Frontend> frontend_;