exetrace.cc revision 1968
1955SN/A/* 2955SN/A * Copyright (c) 2001-2005 The Regents of The University of Michigan 37816Ssteve.reinhardt@amd.com * All rights reserved. 45871Snate@binkert.org * 51762SN/A * Redistribution and use in source and binary forms, with or without 6955SN/A * modification, are permitted provided that the following conditions are 7955SN/A * met: redistributions of source code must retain the above copyright 8955SN/A * notice, this list of conditions and the following disclaimer; 9955SN/A * redistributions in binary form must reproduce the above copyright 10955SN/A * notice, this list of conditions and the following disclaimer in the 11955SN/A * documentation and/or other materials provided with the distribution; 12955SN/A * neither the name of the copyright holders nor the names of its 13955SN/A * contributors may be used to endorse or promote products derived from 14955SN/A * this software without specific prior written permission. 15955SN/A * 16955SN/A * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 17955SN/A * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 18955SN/A * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 19955SN/A * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 20955SN/A * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 21955SN/A * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 22955SN/A * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 23955SN/A * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 24955SN/A * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25955SN/A * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 26955SN/A * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27955SN/A */ 28955SN/A 29955SN/A#include <fstream> 302665Ssaidi@eecs.umich.edu#include <iomanip> 312665Ssaidi@eecs.umich.edu 325863Snate@binkert.org#include "sim/param.hh" 33955SN/A#include "encumbered/cpu/full/dyn_inst.hh" 34955SN/A#include "encumbered/cpu/full/spec_state.hh" 35955SN/A#include "encumbered/cpu/full/issue.hh" 36955SN/A#include "cpu/exetrace.hh" 37955SN/A#include "cpu/exec_context.hh" 388878Ssteve.reinhardt@amd.com#include "base/loader/symtab.hh" 392632Sstever@eecs.umich.edu#include "cpu/base.hh" 408878Ssteve.reinhardt@amd.com#include "cpu/static_inst.hh" 412632Sstever@eecs.umich.edu 42955SN/Ausing namespace std; 438878Ssteve.reinhardt@amd.com 442632Sstever@eecs.umich.edu 452761Sstever@eecs.umich.edu//////////////////////////////////////////////////////////////////////// 462632Sstever@eecs.umich.edu// 472632Sstever@eecs.umich.edu// Methods for the InstRecord object 482632Sstever@eecs.umich.edu// 492761Sstever@eecs.umich.edu 502761Sstever@eecs.umich.edu 512761Sstever@eecs.umich.eduvoid 528878Ssteve.reinhardt@amd.comTrace::InstRecord::dump(ostream &outs) 538878Ssteve.reinhardt@amd.com{ 542761Sstever@eecs.umich.edu if (flags[INTEL_FORMAT]) { 552761Sstever@eecs.umich.edu#if FULL_SYSTEM 562761Sstever@eecs.umich.edu bool is_trace_system = (cpu->system->name() == trace_system); 572761Sstever@eecs.umich.edu#else 582761Sstever@eecs.umich.edu bool is_trace_system = true; 598878Ssteve.reinhardt@amd.com#endif 608878Ssteve.reinhardt@amd.com if (is_trace_system) { 612632Sstever@eecs.umich.edu ccprintf(outs, "%7d ) ", cycle); 622632Sstever@eecs.umich.edu outs << "0x" << hex << PC << ":\t"; 638878Ssteve.reinhardt@amd.com if (staticInst->isLoad()) { 648878Ssteve.reinhardt@amd.com outs << "<RD 0x" << hex << addr; 652632Sstever@eecs.umich.edu outs << ">"; 66955SN/A } else if (staticInst->isStore()) { 67955SN/A outs << "<WR 0x" << hex << addr; 68955SN/A outs << ">"; 695863Snate@binkert.org } 705863Snate@binkert.org outs << endl; 715863Snate@binkert.org } 725863Snate@binkert.org } else { 735863Snate@binkert.org if (flags[PRINT_CYCLE]) 745863Snate@binkert.org ccprintf(outs, "%7d: ", cycle); 755863Snate@binkert.org 765863Snate@binkert.org outs << cpu->name() << " "; 775863Snate@binkert.org 785863Snate@binkert.org if (flags[TRACE_MISSPEC]) 795863Snate@binkert.org outs << (misspeculating ? "-" : "+") << " "; 808878Ssteve.reinhardt@amd.com 815863Snate@binkert.org if (flags[PRINT_THREAD_NUM]) 825863Snate@binkert.org outs << "T" << thread << " : "; 835863Snate@binkert.org 845863Snate@binkert.org 855863Snate@binkert.org std::string sym_str; 865863Snate@binkert.org Addr sym_addr; 875863Snate@binkert.org if (debugSymbolTable 885863Snate@binkert.org && debugSymbolTable->findNearestSymbol(PC, sym_str, sym_addr)) { 895863Snate@binkert.org if (PC != sym_addr) 905863Snate@binkert.org sym_str += csprintf("+%d", PC - sym_addr); 915863Snate@binkert.org outs << "@" << sym_str << " : "; 925863Snate@binkert.org } 935863Snate@binkert.org else { 945863Snate@binkert.org outs << "0x" << hex << PC << " : "; 955863Snate@binkert.org } 968878Ssteve.reinhardt@amd.com 975863Snate@binkert.org // 985863Snate@binkert.org // Print decoded instruction 995863Snate@binkert.org // 1006654Snate@binkert.org 101955SN/A#if defined(__GNUC__) && (__GNUC__ < 3) 1025396Ssaidi@eecs.umich.edu // There's a bug in gcc 2.x library that prevents setw() 1035863Snate@binkert.org // from working properly on strings 1045863Snate@binkert.org string mc(staticInst->disassemble(PC, debugSymbolTable)); 1054202Sbinkertn@umich.edu while (mc.length() < 26) 1065863Snate@binkert.org mc += " "; 1075863Snate@binkert.org outs << mc; 1085863Snate@binkert.org#else 1095863Snate@binkert.org outs << setw(26) << left << staticInst->disassemble(PC, debugSymbolTable); 110955SN/A#endif 1116654Snate@binkert.org 1125273Sstever@gmail.com outs << " : "; 1135871Snate@binkert.org 1145273Sstever@gmail.com if (flags[PRINT_OP_CLASS]) { 1156655Snate@binkert.org outs << opClassStrings[staticInst->opClass()] << " : "; 1168878Ssteve.reinhardt@amd.com } 1176655Snate@binkert.org 1186655Snate@binkert.org if (flags[PRINT_RESULT_DATA] && data_status != DataInvalid) { 1196655Snate@binkert.org outs << " D="; 1206655Snate@binkert.org#if 0 1215871Snate@binkert.org if (data_status == DataDouble) 1226654Snate@binkert.org ccprintf(outs, "%f", data.as_double); 1238947Sandreas.hansson@arm.com else 1245396Ssaidi@eecs.umich.edu ccprintf(outs, "%#018x", data.as_int); 1258120Sgblack@eecs.umich.edu#else 1268120Sgblack@eecs.umich.edu ccprintf(outs, "%#018x", data.as_int); 1278120Sgblack@eecs.umich.edu#endif 1288120Sgblack@eecs.umich.edu } 1298120Sgblack@eecs.umich.edu 1308120Sgblack@eecs.umich.edu if (flags[PRINT_EFF_ADDR] && addr_valid) 1318120Sgblack@eecs.umich.edu outs << " A=0x" << hex << addr; 1328120Sgblack@eecs.umich.edu 1338879Ssteve.reinhardt@amd.com if (flags[PRINT_INT_REGS] && regs_valid) { 1348879Ssteve.reinhardt@amd.com for (int i = 0; i < 32;) 1358879Ssteve.reinhardt@amd.com for (int j = i + 1; i <= j; i++) 1368879Ssteve.reinhardt@amd.com ccprintf(outs, "r%02d = %#018x%s", i, iregs->regs[i], 1378879Ssteve.reinhardt@amd.com ((i == j) ? "\n" : " ")); 1388879Ssteve.reinhardt@amd.com outs << "\n"; 1398879Ssteve.reinhardt@amd.com } 1408879Ssteve.reinhardt@amd.com 1418879Ssteve.reinhardt@amd.com if (flags[PRINT_FETCH_SEQ] && fetch_seq_valid) 1428879Ssteve.reinhardt@amd.com outs << " FetchSeq=" << dec << fetch_seq; 1438879Ssteve.reinhardt@amd.com 1448879Ssteve.reinhardt@amd.com if (flags[PRINT_CP_SEQ] && cp_seq_valid) 1458879Ssteve.reinhardt@amd.com outs << " CPSeq=" << dec << cp_seq; 1468120Sgblack@eecs.umich.edu 1478120Sgblack@eecs.umich.edu // 1488120Sgblack@eecs.umich.edu // End of line... 1498120Sgblack@eecs.umich.edu // 1508120Sgblack@eecs.umich.edu outs << endl; 1518120Sgblack@eecs.umich.edu } 1528120Sgblack@eecs.umich.edu} 1538120Sgblack@eecs.umich.edu 1548120Sgblack@eecs.umich.edu 1558120Sgblack@eecs.umich.eduvector<bool> Trace::InstRecord::flags(NUM_BITS); 1568120Sgblack@eecs.umich.edustring Trace::InstRecord::trace_system; 1578120Sgblack@eecs.umich.edu 1588120Sgblack@eecs.umich.edu//////////////////////////////////////////////////////////////////////// 1598120Sgblack@eecs.umich.edu// 1608879Ssteve.reinhardt@amd.com// Parameter space for per-cycle execution address tracing options. 1618879Ssteve.reinhardt@amd.com// Derive from ParamContext so we can override checkParams() function. 1628879Ssteve.reinhardt@amd.com// 1638879Ssteve.reinhardt@amd.comclass ExecutionTraceParamContext : public ParamContext 1648879Ssteve.reinhardt@amd.com{ 1658879Ssteve.reinhardt@amd.com public: 1668879Ssteve.reinhardt@amd.com ExecutionTraceParamContext(const string &_iniSection) 1678879Ssteve.reinhardt@amd.com : ParamContext(_iniSection) 1688879Ssteve.reinhardt@amd.com { 1698879Ssteve.reinhardt@amd.com } 1708879Ssteve.reinhardt@amd.com 1718879Ssteve.reinhardt@amd.com void checkParams(); // defined at bottom of file 1728120Sgblack@eecs.umich.edu}; 1738947Sandreas.hansson@arm.com 1747816Ssteve.reinhardt@amd.comExecutionTraceParamContext exeTraceParams("exetrace"); 1755871Snate@binkert.org 1765871Snate@binkert.orgParam<bool> exe_trace_spec(&exeTraceParams, "speculative", 1776121Snate@binkert.org "capture speculative instructions", true); 1785871Snate@binkert.org 1795871Snate@binkert.orgParam<bool> exe_trace_print_cycle(&exeTraceParams, "print_cycle", 1806003Snate@binkert.org "print cycle number", true); 1818980Ssteve.reinhardt@amd.comParam<bool> exe_trace_print_opclass(&exeTraceParams, "print_opclass", 182955SN/A "print op class", true); 1835871Snate@binkert.orgParam<bool> exe_trace_print_thread(&exeTraceParams, "print_thread", 1845871Snate@binkert.org "print thread number", true); 1855871Snate@binkert.orgParam<bool> exe_trace_print_effaddr(&exeTraceParams, "print_effaddr", 1865871Snate@binkert.org "print effective address", true); 187955SN/AParam<bool> exe_trace_print_data(&exeTraceParams, "print_data", 1886121Snate@binkert.org "print result data", true); 1898881Smarc.orr@gmail.comParam<bool> exe_trace_print_iregs(&exeTraceParams, "print_iregs", 1906121Snate@binkert.org "print all integer regs", false); 1916121Snate@binkert.orgParam<bool> exe_trace_print_fetchseq(&exeTraceParams, "print_fetchseq", 1921533SN/A "print fetch sequence number", false); 1936655Snate@binkert.orgParam<bool> exe_trace_print_cp_seq(&exeTraceParams, "print_cpseq", 1946655Snate@binkert.org "print correct-path sequence number", false); 1956655Snate@binkert.orgParam<bool> exe_trace_intel_format(&exeTraceParams, "intel_format", 1966655Snate@binkert.org "print trace in intel compatible format", false); 1975871Snate@binkert.orgParam<string> exe_trace_system(&exeTraceParams, "trace_system", 1985871Snate@binkert.org "print trace of which system (client or server)", 1995863Snate@binkert.org "client"); 2005871Snate@binkert.org 2018878Ssteve.reinhardt@amd.com 2025871Snate@binkert.org// 2035871Snate@binkert.org// Helper function for ExecutionTraceParamContext::checkParams() just 2045871Snate@binkert.org// to get us into the InstRecord namespace 2055863Snate@binkert.org// 2066121Snate@binkert.orgvoid 2075863Snate@binkert.orgTrace::InstRecord::setParams() 2085871Snate@binkert.org{ 2098336Ssteve.reinhardt@amd.com flags[TRACE_MISSPEC] = exe_trace_spec; 2108336Ssteve.reinhardt@amd.com 2118336Ssteve.reinhardt@amd.com flags[PRINT_CYCLE] = exe_trace_print_cycle; 2128336Ssteve.reinhardt@amd.com flags[PRINT_OP_CLASS] = exe_trace_print_opclass; 2134678Snate@binkert.org flags[PRINT_THREAD_NUM] = exe_trace_print_thread; 2148336Ssteve.reinhardt@amd.com flags[PRINT_RESULT_DATA] = exe_trace_print_effaddr; 2158336Ssteve.reinhardt@amd.com flags[PRINT_EFF_ADDR] = exe_trace_print_data; 2168336Ssteve.reinhardt@amd.com flags[PRINT_INT_REGS] = exe_trace_print_iregs; 2174678Snate@binkert.org flags[PRINT_FETCH_SEQ] = exe_trace_print_fetchseq; 2184678Snate@binkert.org flags[PRINT_CP_SEQ] = exe_trace_print_cp_seq; 2194678Snate@binkert.org flags[INTEL_FORMAT] = exe_trace_intel_format; 2204678Snate@binkert.org trace_system = exe_trace_system; 2217827Snate@binkert.org} 2227827Snate@binkert.org 2238336Ssteve.reinhardt@amd.comvoid 2244678Snate@binkert.orgExecutionTraceParamContext::checkParams() 2258336Ssteve.reinhardt@amd.com{ 2268336Ssteve.reinhardt@amd.com Trace::InstRecord::setParams(); 2278336Ssteve.reinhardt@amd.com} 2288336Ssteve.reinhardt@amd.com 2298336Ssteve.reinhardt@amd.com