debug.hh revision 10685
15882Snate@binkert.org/*
25882Snate@binkert.org * Copyright (c) 2003-2005 The Regents of The University of Michigan
38232Snate@binkert.org * Copyright (c) 2010 The Hewlett-Packard Development Company
45882Snate@binkert.org * All rights reserved.
55882Snate@binkert.org *
65882Snate@binkert.org * Redistribution and use in source and binary forms, with or without
75882Snate@binkert.org * modification, are permitted provided that the following conditions are
85882Snate@binkert.org * met: redistributions of source code must retain the above copyright
95882Snate@binkert.org * notice, this list of conditions and the following disclaimer;
105882Snate@binkert.org * redistributions in binary form must reproduce the above copyright
115882Snate@binkert.org * notice, this list of conditions and the following disclaimer in the
125882Snate@binkert.org * documentation and/or other materials provided with the distribution;
135882Snate@binkert.org * neither the name of the copyright holders nor the names of its
145882Snate@binkert.org * contributors may be used to endorse or promote products derived from
155882Snate@binkert.org * this software without specific prior written permission.
165882Snate@binkert.org *
175882Snate@binkert.org * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
185882Snate@binkert.org * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
195882Snate@binkert.org * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
205882Snate@binkert.org * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
215882Snate@binkert.org * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
225882Snate@binkert.org * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
235882Snate@binkert.org * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
245882Snate@binkert.org * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
255882Snate@binkert.org * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
265882Snate@binkert.org * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
275882Snate@binkert.org * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
285882Snate@binkert.org *
295882Snate@binkert.org * Authors: Nathan Binkert
305882Snate@binkert.org */
315882Snate@binkert.org
325882Snate@binkert.org#ifndef __BASE_DEBUG_HH__
335882Snate@binkert.org#define __BASE_DEBUG_HH__
345882Snate@binkert.org
359554Sandreas.hansson@arm.com#include <map>
368232Snate@binkert.org#include <string>
378232Snate@binkert.org#include <vector>
388232Snate@binkert.org
398231Snate@binkert.orgnamespace Debug {
408231Snate@binkert.org
418231Snate@binkert.orgvoid breakpoint();
428231Snate@binkert.org
438232Snate@binkert.orgclass Flag
448232Snate@binkert.org{
458232Snate@binkert.org  protected:
468232Snate@binkert.org    const char *_name;
478232Snate@binkert.org    const char *_desc;
488269Snate@binkert.org    std::vector<Flag *> _kids;
498232Snate@binkert.org
508232Snate@binkert.org  public:
518232Snate@binkert.org    Flag(const char *name, const char *desc);
528232Snate@binkert.org    virtual ~Flag();
538232Snate@binkert.org
548232Snate@binkert.org    std::string name() const { return _name; }
558232Snate@binkert.org    std::string desc() const { return _desc; }
568269Snate@binkert.org    std::vector<Flag *> kids() { return _kids; }
578232Snate@binkert.org
588232Snate@binkert.org    virtual void enable() = 0;
598232Snate@binkert.org    virtual void disable() = 0;
608232Snate@binkert.org};
618232Snate@binkert.org
628232Snate@binkert.orgclass SimpleFlag : public Flag
638232Snate@binkert.org{
648232Snate@binkert.org  protected:
658232Snate@binkert.org    bool _status;
668232Snate@binkert.org
678232Snate@binkert.org  public:
688232Snate@binkert.org    SimpleFlag(const char *name, const char *desc)
6910360Sandreas.hansson@arm.com        : Flag(name, desc), _status(false)
708232Snate@binkert.org    { }
718232Snate@binkert.org
728232Snate@binkert.org    bool status() const { return _status; }
738232Snate@binkert.org    operator bool() const { return _status; }
748232Snate@binkert.org    bool operator!() const { return !_status; }
758232Snate@binkert.org
768232Snate@binkert.org    void enable() { _status = true; }
778232Snate@binkert.org    void disable() { _status = false; }
788232Snate@binkert.org};
798232Snate@binkert.org
808232Snate@binkert.orgclass CompoundFlag : public SimpleFlag
818232Snate@binkert.org{
828232Snate@binkert.org  protected:
838269Snate@binkert.org    void
8410685Sandreas.hansson@arm.com    addFlag(Flag *f)
858269Snate@binkert.org    {
8610685Sandreas.hansson@arm.com        if (f != nullptr)
8710685Sandreas.hansson@arm.com            _kids.push_back(f);
888269Snate@binkert.org    }
898232Snate@binkert.org
908232Snate@binkert.org  public:
918232Snate@binkert.org    CompoundFlag(const char *name, const char *desc,
9210685Sandreas.hansson@arm.com        Flag *f00 = nullptr, Flag *f01 = nullptr,
9310685Sandreas.hansson@arm.com        Flag *f02 = nullptr, Flag *f03 = nullptr,
9410685Sandreas.hansson@arm.com        Flag *f04 = nullptr, Flag *f05 = nullptr,
9510685Sandreas.hansson@arm.com        Flag *f06 = nullptr, Flag *f07 = nullptr,
9610685Sandreas.hansson@arm.com        Flag *f08 = nullptr, Flag *f09 = nullptr,
9710685Sandreas.hansson@arm.com        Flag *f10 = nullptr, Flag *f11 = nullptr,
9810685Sandreas.hansson@arm.com        Flag *f12 = nullptr, Flag *f13 = nullptr,
9910685Sandreas.hansson@arm.com        Flag *f14 = nullptr, Flag *f15 = nullptr,
10010685Sandreas.hansson@arm.com        Flag *f16 = nullptr, Flag *f17 = nullptr,
10110685Sandreas.hansson@arm.com        Flag *f18 = nullptr, Flag *f19 = nullptr)
1028232Snate@binkert.org        : SimpleFlag(name, desc)
1038232Snate@binkert.org    {
1048232Snate@binkert.org        addFlag(f00); addFlag(f01); addFlag(f02); addFlag(f03); addFlag(f04);
1058232Snate@binkert.org        addFlag(f05); addFlag(f06); addFlag(f07); addFlag(f08); addFlag(f09);
1068232Snate@binkert.org        addFlag(f10); addFlag(f11); addFlag(f12); addFlag(f13); addFlag(f14);
1078232Snate@binkert.org        addFlag(f15); addFlag(f16); addFlag(f17); addFlag(f18); addFlag(f19);
1088232Snate@binkert.org    }
1098232Snate@binkert.org
1108232Snate@binkert.org    void enable();
1118232Snate@binkert.org    void disable();
1128232Snate@binkert.org};
1138232Snate@binkert.org
1149554Sandreas.hansson@arm.comtypedef std::map<std::string, Flag *> FlagsMap;
1159554Sandreas.hansson@arm.comFlagsMap &allFlags();
1169554Sandreas.hansson@arm.com
1179554Sandreas.hansson@arm.comFlag *findFlag(const std::string &name);
1189554Sandreas.hansson@arm.com
11910171SCurtis.Dunham@arm.comextern Flag *const All;
12010171SCurtis.Dunham@arm.com
1219554Sandreas.hansson@arm.combool changeFlag(const char *s, bool value);
1229554Sandreas.hansson@arm.com
1238231Snate@binkert.org} // namespace Debug
1245882Snate@binkert.org
1259554Sandreas.hansson@arm.comvoid setDebugFlag(const char *string);
1269554Sandreas.hansson@arm.com
1279554Sandreas.hansson@arm.comvoid clearDebugFlag(const char *string);
1289554Sandreas.hansson@arm.com
1299554Sandreas.hansson@arm.comvoid dumpDebugFlags();
1309554Sandreas.hansson@arm.com
1315882Snate@binkert.org#endif // __BASE_DEBUG_HH__
132