debug.cc revision 5336
14276Sgblack@eecs.umich.edu/*
24276Sgblack@eecs.umich.edu * Copyright (c) 2003-2005 The Regents of The University of Michigan
34276Sgblack@eecs.umich.edu * All rights reserved.
44276Sgblack@eecs.umich.edu *
54276Sgblack@eecs.umich.edu * Redistribution and use in source and binary forms, with or without
67087Snate@binkert.org * modification, are permitted provided that the following conditions are
77087Snate@binkert.org * met: redistributions of source code must retain the above copyright
87087Snate@binkert.org * notice, this list of conditions and the following disclaimer;
97087Snate@binkert.org * redistributions in binary form must reproduce the above copyright
107087Snate@binkert.org * notice, this list of conditions and the following disclaimer in the
117087Snate@binkert.org * documentation and/or other materials provided with the distribution;
127087Snate@binkert.org * neither the name of the copyright holders nor the names of its
137087Snate@binkert.org * contributors may be used to endorse or promote products derived from
144276Sgblack@eecs.umich.edu * this software without specific prior written permission.
157087Snate@binkert.org *
167087Snate@binkert.org * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
177087Snate@binkert.org * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
187087Snate@binkert.org * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
197087Snate@binkert.org * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
207087Snate@binkert.org * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
217087Snate@binkert.org * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
227087Snate@binkert.org * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
234276Sgblack@eecs.umich.edu * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
247087Snate@binkert.org * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
254276Sgblack@eecs.umich.edu * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
264276Sgblack@eecs.umich.edu * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
274276Sgblack@eecs.umich.edu *
284276Sgblack@eecs.umich.edu * Authors: Nathan Binkert
294276Sgblack@eecs.umich.edu *          Steve Reinhardt
304276Sgblack@eecs.umich.edu */
314276Sgblack@eecs.umich.edu
324276Sgblack@eecs.umich.edu#include <sys/types.h>
334276Sgblack@eecs.umich.edu#include <signal.h>
344276Sgblack@eecs.umich.edu#include <unistd.h>
354276Sgblack@eecs.umich.edu
364276Sgblack@eecs.umich.edu#include <string>
374276Sgblack@eecs.umich.edu#include <vector>
384276Sgblack@eecs.umich.edu
394276Sgblack@eecs.umich.edu#include "sim/debug.hh"
404276Sgblack@eecs.umich.edu#include "sim/eventq.hh"
414276Sgblack@eecs.umich.edu#include "sim/sim_events.hh"
424276Sgblack@eecs.umich.edu
434276Sgblack@eecs.umich.eduusing namespace std;
444276Sgblack@eecs.umich.edu
454276Sgblack@eecs.umich.eduvoid
464276Sgblack@eecs.umich.edudebug_break()
474276Sgblack@eecs.umich.edu{
484276Sgblack@eecs.umich.edu#ifndef NDEBUG
494704Sgblack@eecs.umich.edu    kill(getpid(), SIGTRAP);
504276Sgblack@eecs.umich.edu#else
514276Sgblack@eecs.umich.edu    cprintf("debug_break suppressed, compiled with NDEBUG\n");
524276Sgblack@eecs.umich.edu#endif
534276Sgblack@eecs.umich.edu}
544276Sgblack@eecs.umich.edu
554276Sgblack@eecs.umich.edu//
564276Sgblack@eecs.umich.edu// Debug event: place a breakpoint on the process function and
574276Sgblack@eecs.umich.edu// schedule the event to break at a particular cycle
584276Sgblack@eecs.umich.edu//
594276Sgblack@eecs.umich.educlass DebugBreakEvent : public Event
60{
61  public:
62
63    DebugBreakEvent(EventQueue *q, Tick _when);
64
65    void process();	// process event
66    virtual const char *description() const;
67};
68
69//
70// constructor: schedule at specified time
71//
72DebugBreakEvent::DebugBreakEvent(EventQueue *q, Tick _when)
73    : Event(q, Debug_Break_Pri)
74{
75    setFlags(AutoDelete);
76    schedule(_when);
77}
78
79//
80// handle debug event: set debugger breakpoint on this function
81//
82void
83DebugBreakEvent::process()
84{
85    debug_break();
86}
87
88
89const char *
90DebugBreakEvent::description() const
91{
92    return "debug break";
93}
94
95//
96// handy function to schedule DebugBreakEvent on main event queue
97// (callable from debugger)
98//
99void
100schedBreakCycle(Tick when)
101{
102    new DebugBreakEvent(&mainEventQueue, when);
103}
104
105void
106eventqDump()
107{
108    mainEventQueue.dump();
109}
110
111