debug.cc revision 11793:ef606668d247
111251Sradhika.jagtap@ARM.com/* 211251Sradhika.jagtap@ARM.com * Copyright (c) 2003-2005 The Regents of The University of Michigan 311251Sradhika.jagtap@ARM.com * All rights reserved. 411251Sradhika.jagtap@ARM.com * 511251Sradhika.jagtap@ARM.com * Redistribution and use in source and binary forms, with or without 611251Sradhika.jagtap@ARM.com * modification, are permitted provided that the following conditions are 711251Sradhika.jagtap@ARM.com * met: redistributions of source code must retain the above copyright 811251Sradhika.jagtap@ARM.com * notice, this list of conditions and the following disclaimer; 911251Sradhika.jagtap@ARM.com * redistributions in binary form must reproduce the above copyright 1011251Sradhika.jagtap@ARM.com * notice, this list of conditions and the following disclaimer in the 1111251Sradhika.jagtap@ARM.com * documentation and/or other materials provided with the distribution; 1211251Sradhika.jagtap@ARM.com * neither the name of the copyright holders nor the names of its 1311251Sradhika.jagtap@ARM.com * contributors may be used to endorse or promote products derived from 1411251Sradhika.jagtap@ARM.com * this software without specific prior written permission. 1511251Sradhika.jagtap@ARM.com * 1611251Sradhika.jagtap@ARM.com * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 1711251Sradhika.jagtap@ARM.com * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 1811251Sradhika.jagtap@ARM.com * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 1911251Sradhika.jagtap@ARM.com * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 2011251Sradhika.jagtap@ARM.com * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 2111251Sradhika.jagtap@ARM.com * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 2211251Sradhika.jagtap@ARM.com * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 2311251Sradhika.jagtap@ARM.com * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 2411251Sradhika.jagtap@ARM.com * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 2511251Sradhika.jagtap@ARM.com * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 2611251Sradhika.jagtap@ARM.com * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 2711251Sradhika.jagtap@ARM.com * 2811251Sradhika.jagtap@ARM.com * Authors: Nathan Binkert 2911251Sradhika.jagtap@ARM.com * Steve Reinhardt 3011251Sradhika.jagtap@ARM.com */ 3111251Sradhika.jagtap@ARM.com 3211251Sradhika.jagtap@ARM.com#include "sim/debug.hh" 3311251Sradhika.jagtap@ARM.com 3411251Sradhika.jagtap@ARM.com#include <string> 3511251Sradhika.jagtap@ARM.com#include <vector> 3611251Sradhika.jagtap@ARM.com 3711251Sradhika.jagtap@ARM.com#include "base/debug.hh" 3811251Sradhika.jagtap@ARM.com#include "cpu/pc_event.hh" 3911251Sradhika.jagtap@ARM.com#include "sim/eventq_impl.hh" 4011251Sradhika.jagtap@ARM.com#include "sim/global_event.hh" 4111251Sradhika.jagtap@ARM.com#include "sim/sim_events.hh" 4211251Sradhika.jagtap@ARM.com#include "sim/sim_exit.hh" 4311251Sradhika.jagtap@ARM.com#include "sim/system.hh" 4411682Sandreas.hansson@arm.com 4511251Sradhika.jagtap@ARM.comusing namespace std; 4611682Sandreas.hansson@arm.com 4711682Sandreas.hansson@arm.com// 4811682Sandreas.hansson@arm.com// Debug event: place a breakpoint on the process function and 4911682Sandreas.hansson@arm.com// schedule the event to break at a particular cycle 5011682Sandreas.hansson@arm.com// 5111251Sradhika.jagtap@ARM.comstruct DebugBreakEvent : public GlobalEvent 5211251Sradhika.jagtap@ARM.com{ 5311251Sradhika.jagtap@ARM.com DebugBreakEvent(Tick when); 5411251Sradhika.jagtap@ARM.com void process(); // process event 5511251Sradhika.jagtap@ARM.com virtual const char *description() const; 5611251Sradhika.jagtap@ARM.com}; 5711251Sradhika.jagtap@ARM.com 5811251Sradhika.jagtap@ARM.com// 5911251Sradhika.jagtap@ARM.com// constructor: schedule at specified time 6011251Sradhika.jagtap@ARM.com// 6111251Sradhika.jagtap@ARM.comDebugBreakEvent::DebugBreakEvent(Tick when) 6211251Sradhika.jagtap@ARM.com : GlobalEvent(when, Debug_Break_Pri, AutoDelete) 6311251Sradhika.jagtap@ARM.com{ 6411251Sradhika.jagtap@ARM.com} 6511251Sradhika.jagtap@ARM.com 6611251Sradhika.jagtap@ARM.com// 6711251Sradhika.jagtap@ARM.com// handle debug event: set debugger breakpoint on this function 6812014Sgabeblack@google.com// 6911251Sradhika.jagtap@ARM.comvoid 7012014Sgabeblack@google.comDebugBreakEvent::process() 7111251Sradhika.jagtap@ARM.com{ 7211251Sradhika.jagtap@ARM.com Debug::breakpoint(); 7311251Sradhika.jagtap@ARM.com} 7411251Sradhika.jagtap@ARM.com 7511251Sradhika.jagtap@ARM.com 7611251Sradhika.jagtap@ARM.comconst char * 7711251Sradhika.jagtap@ARM.comDebugBreakEvent::description() const 7811251Sradhika.jagtap@ARM.com{ 7911251Sradhika.jagtap@ARM.com return "debug breakpoint"; 8011251Sradhika.jagtap@ARM.com} 8111251Sradhika.jagtap@ARM.com 8211251Sradhika.jagtap@ARM.com// 8311251Sradhika.jagtap@ARM.com// handy function to schedule DebugBreakEvent on main event queue 8411251Sradhika.jagtap@ARM.com// (callable from debugger) 8511251Sradhika.jagtap@ARM.com// 8611251Sradhika.jagtap@ARM.comvoid 8711251Sradhika.jagtap@ARM.comschedBreak(Tick when) 8811251Sradhika.jagtap@ARM.com{ 8911251Sradhika.jagtap@ARM.com new DebugBreakEvent(when); 9011251Sradhika.jagtap@ARM.com warn("need to stop all queues"); 9111251Sradhika.jagtap@ARM.com} 9211251Sradhika.jagtap@ARM.com 9311251Sradhika.jagtap@ARM.comvoid 9411251Sradhika.jagtap@ARM.comschedRelBreak(Tick delta) 9511251Sradhika.jagtap@ARM.com{ 9611251Sradhika.jagtap@ARM.com schedBreak(curTick() + delta); 9711251Sradhika.jagtap@ARM.com} 9811251Sradhika.jagtap@ARM.com 9911251Sradhika.jagtap@ARM.comvoid 10011251Sradhika.jagtap@ARM.combreakAtKernelFunction(const char* funcName) 10111251Sradhika.jagtap@ARM.com{ 10211251Sradhika.jagtap@ARM.com System* curSystem = System::systemList[0]; 10311251Sradhika.jagtap@ARM.com curSystem->addKernelFuncEvent<BreakPCEvent>(funcName, 10411251Sradhika.jagtap@ARM.com "GDB scheduled break", true); 10511251Sradhika.jagtap@ARM.com} 10611251Sradhika.jagtap@ARM.com 10712430Schenzou@uchicago.edu/// 10812430Schenzou@uchicago.edu/// Function to cause the simulator to take a checkpoint from the debugger 10912430Schenzou@uchicago.edu/// 11012430Schenzou@uchicago.eduvoid 11112430Schenzou@uchicago.edutakeCheckpoint(Tick when) 11211251Sradhika.jagtap@ARM.com{ 11311251Sradhika.jagtap@ARM.com if (!when) 11411251Sradhika.jagtap@ARM.com when = curTick() + 1; 11511251Sradhika.jagtap@ARM.com exitSimLoop("checkpoint", 0, when, 0); 11611251Sradhika.jagtap@ARM.com} 11711251Sradhika.jagtap@ARM.com 11811251Sradhika.jagtap@ARM.comvoid 11911251Sradhika.jagtap@ARM.comeventqDump() 12011251Sradhika.jagtap@ARM.com{ 12111251Sradhika.jagtap@ARM.com for (uint32_t i = 0; i < numMainEventQueues; ++i) { 12211251Sradhika.jagtap@ARM.com mainEventQueue[i]->dump(); 12311251Sradhika.jagtap@ARM.com } 12411251Sradhika.jagtap@ARM.com} 125 126int remote_gdb_base_port = 7000; 127 128int 129getRemoteGDBPort() 130{ 131 return remote_gdb_base_port; 132} 133 134// Set remote GDB base port. 0 means disable remote GDB. 135// Callable from python. 136void 137setRemoteGDBPort(int port) 138{ 139 remote_gdb_base_port = port; 140} 141 142