void DumpCCS(const TargetInfo& ti, target_ptr_t ccs, uint32_t starting_depth) { // Traverse and print the passed Cost Center Stack for (unsigned int depth=starting_depth; depth<64; depth++) { Indent(depth); // Get CC pointer from CCS const target_ptr_t cc = ti.ReadMemoryPtr(ccs + OFFSET_ConstCentreStack_cc); if (cc == 0) { std::printf("(Can't read CC pointer)\n"); break; } // Retrieve symbol information from CC const target_ptr_t label_ptr = ti.ReadMemoryPtr(cc + OFFSET_ConstCentre_label); const target_ptr_t module_ptr = ti.ReadMemoryPtr(cc + OFFSET_ConstCentre_module); const target_ptr_t srcloc_ptr = ti.ReadMemoryPtr(cc + OFFSET_ConstCentre_srcloc); char label[256], module[256], srcloc[256]; if (ti.ReadMemoryString(label_ptr, label, sizeof(label)) == false) std::strcpy(label, "(can't read label)"); if (ti.ReadMemoryString(module_ptr, module, sizeof(module)) == false) std::strcpy(module, "(can't read module)"); if (ti.ReadMemoryString(srcloc_ptr, srcloc, sizeof(srcloc)) == false) std::strcpy(srcloc, "(can't read srcloc)"); std::printf("CCS:0x%x <%s> from %s (%s)\n", ccs, label, module, srcloc); // Walk the CC stack ccs = ti.ReadMemoryPtr(ccs + OFFSET_ConstCentreStack_prevStack); if (ccs == 0) break; } }
void DumpSTG( const TargetInfo& ti, SymbolManager *symbol, target_ptr_t sp, uint32_t starting_depth) { // TODO: See GHC's 'Printer.c' on how we could print more information about what's on // the stack // Traverse and print the passed STG stack for (unsigned int depth=starting_depth; depth<128; depth++) { // Top closure const target_ptr_t info = ti.ReadMemoryPtr(sp); const uint32_t sym_id = symbol->AddressToSymbolID(info); Indent(depth); // Let our wrapper collect the required information uint32_t closure_type, closure_size; target_ptr_t fun_ref; if (GetClosureTypeAndSize(ti.m_task_port, sp, &closure_type, &closure_size, &fun_ref) != 0) { std::printf("0x%x (Can't read stack frame)\n", sp); break; } // Referenced closure char ref_buf[256] = { 0 }; if (fun_ref != 0) { std::snprintf( ref_buf, sizeof(ref_buf), ", <%s>", symbol->SymbolIDToName(symbol->AddressToSymbolID(ti.ReadMemoryPtr(fun_ref)))); } std::printf("0x%x <%s> (%s, %ib%s)\n", sp, symbol->SymbolIDToName(sym_id), ClosureTypeToString(closure_type), closure_size, ref_buf); if (closure_type == wrapper_STOP_FRAME) break; // TODO: Handle underflow frames if (closure_type == wrapper_UNDERFLOW_FRAME) break; sp += closure_size; } }
target_ptr_t CCSPtrFromTopOfStack(const TargetInfo& ti, target_ptr_t sp_reg) { return ti.ReadMemoryPtr (sp_reg + OFFSET_StgClosure_header + OFFSET_StgHeader_prof + OFFSET_StgProfHeader_ccs); }
// Get a Cost Center Stack pointer from either the base register or the STG stack pointer target_ptr_t CCSPtrFromBaseReg(const TargetInfo& ti, target_ptr_t base_reg) { return ti.ReadMemoryPtr(base_reg + OFFSET_StgRegTable_rCCCS); }