debug.cc revision 11164
17965Sgblack@eecs.umich.edu/*
28332Snate@binkert.org * Copyright (c) 2003-2005 The Regents of The University of Michigan
37965Sgblack@eecs.umich.edu * All rights reserved.
47965Sgblack@eecs.umich.edu *
57965Sgblack@eecs.umich.edu * Redistribution and use in source and binary forms, with or without
67965Sgblack@eecs.umich.edu * modification, are permitted provided that the following conditions are
77965Sgblack@eecs.umich.edu * met: redistributions of source code must retain the above copyright
87965Sgblack@eecs.umich.edu * notice, this list of conditions and the following disclaimer;
97965Sgblack@eecs.umich.edu * redistributions in binary form must reproduce the above copyright
107965Sgblack@eecs.umich.edu * notice, this list of conditions and the following disclaimer in the
117965Sgblack@eecs.umich.edu * documentation and/or other materials provided with the distribution;
127965Sgblack@eecs.umich.edu * neither the name of the copyright holders nor the names of its
137965Sgblack@eecs.umich.edu * contributors may be used to endorse or promote products derived from
147965Sgblack@eecs.umich.edu * this software without specific prior written permission.
157965Sgblack@eecs.umich.edu *
167965Sgblack@eecs.umich.edu * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
177965Sgblack@eecs.umich.edu * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
187965Sgblack@eecs.umich.edu * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
197965Sgblack@eecs.umich.edu * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
207965Sgblack@eecs.umich.edu * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
217965Sgblack@eecs.umich.edu * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
227965Sgblack@eecs.umich.edu * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
237965Sgblack@eecs.umich.edu * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
247965Sgblack@eecs.umich.edu * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
257965Sgblack@eecs.umich.edu * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
267965Sgblack@eecs.umich.edu * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
277965Sgblack@eecs.umich.edu *
287965Sgblack@eecs.umich.edu * Authors: Nathan Binkert
297965Sgblack@eecs.umich.edu *          Steve Reinhardt
307965Sgblack@eecs.umich.edu */
317965Sgblack@eecs.umich.edu
327965Sgblack@eecs.umich.edu#include <string>
337965Sgblack@eecs.umich.edu#include <vector>
347965Sgblack@eecs.umich.edu
357965Sgblack@eecs.umich.edu#include "base/debug.hh"
367965Sgblack@eecs.umich.edu#include "sim/debug.hh"
377965Sgblack@eecs.umich.edu#include "sim/eventq_impl.hh"
387965Sgblack@eecs.umich.edu#include "sim/global_event.hh"
397965Sgblack@eecs.umich.edu#include "sim/sim_events.hh"
407965Sgblack@eecs.umich.edu#include "sim/sim_exit.hh"
417965Sgblack@eecs.umich.edu#include "cpu/pc_event.hh"
427965Sgblack@eecs.umich.edu#include "sim/system.hh"
438229Snate@binkert.org
448229Snate@binkert.orgusing namespace std;
4512334Sgabeblack@google.com
467965Sgblack@eecs.umich.edu//
477965Sgblack@eecs.umich.edu// Debug event: place a breakpoint on the process function and
487965Sgblack@eecs.umich.edu// schedule the event to break at a particular cycle
497965Sgblack@eecs.umich.edu//
508590Sgblack@eecs.umich.edustruct DebugBreakEvent : public GlobalEvent
517965Sgblack@eecs.umich.edu{
527965Sgblack@eecs.umich.edu    DebugBreakEvent(Tick when);
5314277Sgabeblack@google.com    void process();     // process event
5414277Sgabeblack@google.com    virtual const char *description() const;
5514277Sgabeblack@google.com};
5614277Sgabeblack@google.com
5714277Sgabeblack@google.com//
587965Sgblack@eecs.umich.edu// constructor: schedule at specified time
5914277Sgabeblack@google.com//
6014277Sgabeblack@google.comDebugBreakEvent::DebugBreakEvent(Tick when)
6114277Sgabeblack@google.com    : GlobalEvent(when, Debug_Break_Pri, AutoDelete)
6214277Sgabeblack@google.com{
637965Sgblack@eecs.umich.edu}
647965Sgblack@eecs.umich.edu
657965Sgblack@eecs.umich.edu//
6614277Sgabeblack@google.com// handle debug event: set debugger breakpoint on this function
6714277Sgabeblack@google.com//
6814277Sgabeblack@google.comvoid
6914277Sgabeblack@google.comDebugBreakEvent::process()
7014277Sgabeblack@google.com{
7114277Sgabeblack@google.com    Debug::breakpoint();
7214277Sgabeblack@google.com}
7314277Sgabeblack@google.com
7414277Sgabeblack@google.com
7514277Sgabeblack@google.comconst char *
767965Sgblack@eecs.umich.eduDebugBreakEvent::description() const
7710417Sandreas.hansson@arm.com{
7814277Sgabeblack@google.com    return "debug breakpoint";
797965Sgblack@eecs.umich.edu}
8014277Sgabeblack@google.com
8114277Sgabeblack@google.com//
827965Sgblack@eecs.umich.edu// handy function to schedule DebugBreakEvent on main event queue
837965Sgblack@eecs.umich.edu// (callable from debugger)
848590Sgblack@eecs.umich.edu//
8514277Sgabeblack@google.comvoid
8614277Sgabeblack@google.comschedBreak(Tick when)
8714277Sgabeblack@google.com{
8814277Sgabeblack@google.com    new DebugBreakEvent(when);
8914277Sgabeblack@google.com    warn("need to stop all queues");
9014277Sgabeblack@google.com}
9114277Sgabeblack@google.com
9214277Sgabeblack@google.comvoid
9314277Sgabeblack@google.comschedRelBreak(Tick delta)
9414277Sgabeblack@google.com{
9514277Sgabeblack@google.com    schedBreak(curTick() + delta);
9614277Sgabeblack@google.com}
9714277Sgabeblack@google.com
9814277Sgabeblack@google.comvoid
9914277Sgabeblack@google.combreakAtKernelFunction(const char* funcName)
10014277Sgabeblack@google.com{
10114277Sgabeblack@google.com    System* curSystem = System::systemList[0];
10214277Sgabeblack@google.com    curSystem->addKernelFuncEvent<BreakPCEvent>(funcName,
10314277Sgabeblack@google.com                                                "GDB scheduled break", true);
10414277Sgabeblack@google.com}
10514277Sgabeblack@google.com
10614277Sgabeblack@google.com///
10714277Sgabeblack@google.com/// Function to cause the simulator to take a checkpoint from the debugger
10814277Sgabeblack@google.com///
10914277Sgabeblack@google.comvoid
11014277Sgabeblack@google.comtakeCheckpoint(Tick when)
11114277Sgabeblack@google.com{
11214277Sgabeblack@google.com    if (!when)
11314277Sgabeblack@google.com        when = curTick() + 1;
11414277Sgabeblack@google.com    exitSimLoop("checkpoint", 0, when, 0);
11514277Sgabeblack@google.com}
11614277Sgabeblack@google.com
11714277Sgabeblack@google.comvoid
11814277Sgabeblack@google.comeventqDump()
11914277Sgabeblack@google.com{
12014277Sgabeblack@google.com    for (uint32_t i = 0; i < numMainEventQueues; ++i) {
1218590Sgblack@eecs.umich.edu        mainEventQueue[i]->dump();
1228590Sgblack@eecs.umich.edu    }
12314277Sgabeblack@google.com}
12414277Sgabeblack@google.com
12514277Sgabeblack@google.comint remote_gdb_base_port = 7000;
1268590Sgblack@eecs.umich.edu
1278590Sgblack@eecs.umich.eduint
12814277Sgabeblack@google.comgetRemoteGDBPort()
12914277Sgabeblack@google.com{
13014277Sgabeblack@google.com    return remote_gdb_base_port;
13114277Sgabeblack@google.com}
13214277Sgabeblack@google.com
13314277Sgabeblack@google.com// Set remote GDB base port.  0 means disable remote GDB.
13414277Sgabeblack@google.com// Callable from python.
13514277Sgabeblack@google.comvoid
13614277Sgabeblack@google.comsetRemoteGDBPort(int port)
13714277Sgabeblack@google.com{
13814277Sgabeblack@google.com    remote_gdb_base_port = port;
13914277Sgabeblack@google.com}
14014277Sgabeblack@google.com
14114277Sgabeblack@google.com