debug.cc revision 56
16157Snate@binkert.org/*
26157Snate@binkert.org * Copyright (c) 2003 The Regents of The University of Michigan
36157Snate@binkert.org * All rights reserved.
46157Snate@binkert.org *
56157Snate@binkert.org * Redistribution and use in source and binary forms, with or without
66157Snate@binkert.org * modification, are permitted provided that the following conditions are
76157Snate@binkert.org * met: redistributions of source code must retain the above copyright
86157Snate@binkert.org * notice, this list of conditions and the following disclaimer;
96157Snate@binkert.org * redistributions in binary form must reproduce the above copyright
106157Snate@binkert.org * notice, this list of conditions and the following disclaimer in the
116157Snate@binkert.org * documentation and/or other materials provided with the distribution;
126157Snate@binkert.org * neither the name of the copyright holders nor the names of its
136157Snate@binkert.org * contributors may be used to endorse or promote products derived from
146157Snate@binkert.org * this software without specific prior written permission.
156157Snate@binkert.org *
166157Snate@binkert.org * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
176157Snate@binkert.org * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
186157Snate@binkert.org * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
196157Snate@binkert.org * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
206157Snate@binkert.org * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
216157Snate@binkert.org * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
226157Snate@binkert.org * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
236157Snate@binkert.org * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
246157Snate@binkert.org * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
256157Snate@binkert.org * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
266157Snate@binkert.org * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
276157Snate@binkert.org */
286157Snate@binkert.org
296157Snate@binkert.org#include <sys/types.h>
306157Snate@binkert.org#include <signal.h>
3112563Sgabeblack@google.com#include <unistd.h>
3212563Sgabeblack@google.com
336157Snate@binkert.org#include <string>
346157Snate@binkert.org#include <vector>
356157Snate@binkert.org
366157Snate@binkert.org#include "sim/debug.hh"
376157Snate@binkert.org#include "sim/eventq.hh"
386157Snate@binkert.org#include "sim/param.hh"
396157Snate@binkert.org#include "sim/sim_events.hh"
4012246Sgabeblack@google.com
4112246Sgabeblack@google.comusing namespace std;
426157Snate@binkert.org
436157Snate@binkert.orgvoid
4412892Sbrandon.potter@amd.comdebug_break()
4512892Sbrandon.potter@amd.com{
4612892Sbrandon.potter@amd.com    kill(getpid(), SIGTRAP);
4710133Sandreas.hansson@arm.com}
4810133Sandreas.hansson@arm.com
4910133Sandreas.hansson@arm.com//
5010133Sandreas.hansson@arm.com// Debug event: place a breakpoint on the process function and
5110133Sandreas.hansson@arm.com// schedule the event to break at a particular cycle
5210133Sandreas.hansson@arm.com//
5310133Sandreas.hansson@arm.comclass DebugBreakEvent : public Event
5410133Sandreas.hansson@arm.com{
5510133Sandreas.hansson@arm.com  public:
5610133Sandreas.hansson@arm.com
5710133Sandreas.hansson@arm.com    DebugBreakEvent(EventQueue *q, Tick _when);
5810133Sandreas.hansson@arm.com
5910133Sandreas.hansson@arm.com    void process();	// process event
6010133Sandreas.hansson@arm.com    virtual const char *description();
6110133Sandreas.hansson@arm.com};
6210133Sandreas.hansson@arm.com
6310133Sandreas.hansson@arm.com//
6410133Sandreas.hansson@arm.com// constructor: schedule at specified time
6511755Sandreas.hansson@arm.com//
6610133Sandreas.hansson@arm.comDebugBreakEvent::DebugBreakEvent(EventQueue *q, Tick _when)
6710133Sandreas.hansson@arm.com    : Event(q)
686157Snate@binkert.org{
696157Snate@binkert.org    schedule(_when, -20000);
706157Snate@binkert.org}
716157Snate@binkert.org
726157Snate@binkert.org//
736157Snate@binkert.org// handle debug event: set debugger breakpoint on this function
746157Snate@binkert.org//
756157Snate@binkert.orgvoid
766157Snate@binkert.orgDebugBreakEvent::process()
776157Snate@binkert.org{
786157Snate@binkert.org    debug_break();
796157Snate@binkert.org    delete this;
806157Snate@binkert.org}
816157Snate@binkert.org
826157Snate@binkert.org
836157Snate@binkert.orgconst char *
846157Snate@binkert.orgDebugBreakEvent::description()
856157Snate@binkert.org{
866157Snate@binkert.org    return "debug break";
876157Snate@binkert.org}
886157Snate@binkert.org
896157Snate@binkert.org//
906157Snate@binkert.org// Parameter context for global debug options
916157Snate@binkert.org//
926157Snate@binkert.orgclass DebugContext : public ParamContext
936157Snate@binkert.org{
946157Snate@binkert.org  public:
956157Snate@binkert.org    DebugContext(const string &_iniSection)
966157Snate@binkert.org        : ParamContext(_iniSection) {}
976157Snate@binkert.org    void checkParams();
986157Snate@binkert.org};
996157Snate@binkert.org
1006157Snate@binkert.orgDebugContext debugParams("debug");
1016157Snate@binkert.org
1026157Snate@binkert.orgVectorParam<Tick> break_cycles(&debugParams, "break_cycles",
1036157Snate@binkert.org                                 "cycle(s) to create breakpoint events");
1046157Snate@binkert.org
1056157Snate@binkert.orgvoid
10612563Sgabeblack@google.comDebugContext::checkParams()
1076157Snate@binkert.org{
1086157Snate@binkert.org    if (break_cycles.isValid()) {
1096157Snate@binkert.org        vector<Tick> &cycles = break_cycles;
1106157Snate@binkert.org
1118483Sgblack@eecs.umich.edu        vector<Tick>::iterator i = cycles.begin();
1128483Sgblack@eecs.umich.edu        vector<Tick>::iterator end = cycles.end();
1136157Snate@binkert.org
1146882SBrad.Beckmann@amd.com        for (; i < end; ++i)
1156286Snate@binkert.org            new DebugBreakEvent(&mainEventQueue, *i);
1166286Snate@binkert.org    }
1178092Snilay@cs.wisc.edu}
1186286Snate@binkert.org
1196286Snate@binkert.org//
1206157Snate@binkert.org// handy function to schedule DebugBreakEvent on main event queue
12111208Sjoseph.gross@amd.com// (callable from debugger)
1226157Snate@binkert.org//
12311210SBrad.Beckmann@amd.comextern "C" void sched_break_cycle(Tick when)
12410301Snilay@cs.wisc.edu{
1256157Snate@binkert.org    new DebugBreakEvent(&mainEventQueue, when);
1266157Snate@binkert.org}
12711307Santhony.gutierrez@amd.com
12811122Snilay@cs.wisc.eduextern "C" void dump_stats()
12910301Snilay@cs.wisc.edu{
13010301Snilay@cs.wisc.edu    new DumpStatsEvent();
13110301Snilay@cs.wisc.edu}
13210301Snilay@cs.wisc.edu
13310301Snilay@cs.wisc.eduextern "C" void eventq_dump()
13411308Santhony.gutierrez@amd.com{
13510301Snilay@cs.wisc.edu    mainEventQueue.dump();
13610301Snilay@cs.wisc.edu}
13711308Santhony.gutierrez@amd.com
13811308Santhony.gutierrez@amd.com