debug.cc revision 2
19243SN/A/*
210206Sandreas.hansson@arm.com * Copyright (c) 2003 The Regents of The University of Michigan
39243SN/A * All rights reserved.
49243SN/A *
59243SN/A * Redistribution and use in source and binary forms, with or without
69243SN/A * modification, are permitted provided that the following conditions are
79243SN/A * met: redistributions of source code must retain the above copyright
89243SN/A * notice, this list of conditions and the following disclaimer;
99243SN/A * redistributions in binary form must reproduce the above copyright
109243SN/A * notice, this list of conditions and the following disclaimer in the
119243SN/A * documentation and/or other materials provided with the distribution;
129243SN/A * neither the name of the copyright holders nor the names of its
139243SN/A * contributors may be used to endorse or promote products derived from
149831SN/A * this software without specific prior written permission.
159831SN/A *
169831SN/A * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
179243SN/A * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
189243SN/A * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
199243SN/A * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
209243SN/A * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
219243SN/A * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
229243SN/A * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
239243SN/A * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
249243SN/A * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
259243SN/A * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
269243SN/A * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
279243SN/A */
289243SN/A
299243SN/A#include <sys/types.h>
309243SN/A#include <signal.h>
319243SN/A#include <unistd.h>
329243SN/A
339243SN/A#include <string>
349243SN/A#include <vector>
359243SN/A
369243SN/A#include "debug.hh"
379243SN/A#include "eventq.hh"
389243SN/A#include "param.hh"
399243SN/A#include "sim_events.hh"
409243SN/A
419243SN/Ausing namespace std;
429967SN/A
439243SN/Avoid
449243SN/Adebug_break()
459243SN/A{
469243SN/A    kill(getpid(), SIGTRAP);
4710146Sandreas.hansson@arm.com}
489243SN/A
499243SN/A//
5010146Sandreas.hansson@arm.com// Debug event: place a breakpoint on the process function and
5110146Sandreas.hansson@arm.com// schedule the event to break at a particular cycle
529243SN/A//
539488SN/Aclass DebugBreakEvent : public Event
549488SN/A{
559243SN/A  public:
569243SN/A
579243SN/A    DebugBreakEvent(EventQueue *q, Tick _when);
589243SN/A
599243SN/A    void process();	// process event
609243SN/A    virtual const char *description();
6110146Sandreas.hansson@arm.com};
629243SN/A
639243SN/A//
649243SN/A// constructor: schedule at specified time
6510146Sandreas.hansson@arm.com//
6610146Sandreas.hansson@arm.comDebugBreakEvent::DebugBreakEvent(EventQueue *q, Tick _when)
6710146Sandreas.hansson@arm.com    : Event(q)
689243SN/A{
699243SN/A    schedule(_when, -20000);
709243SN/A}
719243SN/A
729243SN/A//
739243SN/A// handle debug event: set debugger breakpoint on this function
749243SN/A//
759243SN/Avoid
769243SN/ADebugBreakEvent::process()
779243SN/A{
789243SN/A    debug_break();
799243SN/A    delete this;
809243SN/A}
819243SN/A
829243SN/A
8310146Sandreas.hansson@arm.comconst char *
849243SN/ADebugBreakEvent::description()
859243SN/A{
869243SN/A    return "debug break";
879243SN/A}
889243SN/A
899243SN/A//
909243SN/A// Parameter context for global debug options
919243SN/A//
929243SN/Aclass DebugContext : public ParamContext
939243SN/A{
9410146Sandreas.hansson@arm.com  public:
959243SN/A    DebugContext(const string &_iniSection)
969243SN/A        : ParamContext(_iniSection) {}
979243SN/A    void checkParams();
9810146Sandreas.hansson@arm.com};
999243SN/A
1009243SN/ADebugContext debugParams("debug");
1019243SN/A
1029243SN/AVectorParam<Tick> break_cycles(&debugParams, "break_cycles",
1039243SN/A                                 "cycle(s) to create breakpoint events");
1049243SN/A
1059243SN/Avoid
1069243SN/ADebugContext::checkParams()
1079243SN/A{
1089243SN/A    if (break_cycles.isValid()) {
1099243SN/A        vector<Tick> &cycles = break_cycles;
1109243SN/A
1119243SN/A        vector<Tick>::iterator i = cycles.begin();
1129243SN/A        vector<Tick>::iterator end = cycles.end();
1139243SN/A
1149243SN/A        for (; i < end; ++i)
1159243SN/A            new DebugBreakEvent(&mainEventQueue, *i);
1169243SN/A    }
1179243SN/A}
1189243SN/A
1199243SN/A//
1209243SN/A// handy function to schedule DebugBreakEvent on main event queue
1219243SN/A// (callable from debugger)
1229243SN/A//
1239243SN/Aextern "C" void sched_break_cycle(Tick when)
1249243SN/A{
1259243SN/A    new DebugBreakEvent(&mainEventQueue, when);
1269243SN/A}
1279243SN/A
1289243SN/Aextern "C" void dump_stats()
1299243SN/A{
13010206Sandreas.hansson@arm.com    new DumpStatsEvent();
13110206Sandreas.hansson@arm.com}
1329243SN/A
13310206Sandreas.hansson@arm.comextern "C" void eventq_dump()
13410206Sandreas.hansson@arm.com{
13510206Sandreas.hansson@arm.com    mainEventQueue.dump();
13610206Sandreas.hansson@arm.com}
13710206Sandreas.hansson@arm.com
13810206Sandreas.hansson@arm.com