1*a9fa9459Szrj // debug.h -- gold internal debugging support -*- C++ -*-
2*a9fa9459Szrj
3*a9fa9459Szrj // Copyright (C) 2007-2016 Free Software Foundation, Inc.
4*a9fa9459Szrj // Written by Ian Lance Taylor <iant@google.com>.
5*a9fa9459Szrj
6*a9fa9459Szrj // This file is part of gold.
7*a9fa9459Szrj
8*a9fa9459Szrj // This program is free software; you can redistribute it and/or modify
9*a9fa9459Szrj // it under the terms of the GNU General Public License as published by
10*a9fa9459Szrj // the Free Software Foundation; either version 3 of the License, or
11*a9fa9459Szrj // (at your option) any later version.
12*a9fa9459Szrj
13*a9fa9459Szrj // This program is distributed in the hope that it will be useful,
14*a9fa9459Szrj // but WITHOUT ANY WARRANTY; without even the implied warranty of
15*a9fa9459Szrj // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16*a9fa9459Szrj // GNU General Public License for more details.
17*a9fa9459Szrj
18*a9fa9459Szrj // You should have received a copy of the GNU General Public License
19*a9fa9459Szrj // along with this program; if not, write to the Free Software
20*a9fa9459Szrj // Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
21*a9fa9459Szrj // MA 02110-1301, USA.
22*a9fa9459Szrj
23*a9fa9459Szrj #ifndef GOLD_DEBUG_H
24*a9fa9459Szrj #define GOLD_DEBUG_H
25*a9fa9459Szrj
26*a9fa9459Szrj #include <cstring>
27*a9fa9459Szrj
28*a9fa9459Szrj #include "parameters.h"
29*a9fa9459Szrj #include "errors.h"
30*a9fa9459Szrj
31*a9fa9459Szrj namespace gold
32*a9fa9459Szrj {
33*a9fa9459Szrj
34*a9fa9459Szrj // The different types of debugging we support. These are bitflags.
35*a9fa9459Szrj
36*a9fa9459Szrj const int DEBUG_TASK = 0x1;
37*a9fa9459Szrj const int DEBUG_SCRIPT = 0x2;
38*a9fa9459Szrj const int DEBUG_FILES = 0x4;
39*a9fa9459Szrj const int DEBUG_RELAXATION = 0x8;
40*a9fa9459Szrj const int DEBUG_INCREMENTAL = 0x10;
41*a9fa9459Szrj const int DEBUG_LOCATION = 0x20;
42*a9fa9459Szrj
43*a9fa9459Szrj const int DEBUG_ALL = (DEBUG_TASK | DEBUG_SCRIPT | DEBUG_FILES
44*a9fa9459Szrj | DEBUG_RELAXATION | DEBUG_INCREMENTAL
45*a9fa9459Szrj | DEBUG_LOCATION);
46*a9fa9459Szrj
47*a9fa9459Szrj // Convert a debug string to the appropriate enum.
48*a9fa9459Szrj inline int
debug_string_to_enum(const char * arg)49*a9fa9459Szrj debug_string_to_enum(const char* arg)
50*a9fa9459Szrj {
51*a9fa9459Szrj static const struct { const char* name; int value; }
52*a9fa9459Szrj debug_options[] =
53*a9fa9459Szrj {
54*a9fa9459Szrj { "task", DEBUG_TASK },
55*a9fa9459Szrj { "script", DEBUG_SCRIPT },
56*a9fa9459Szrj { "files", DEBUG_FILES },
57*a9fa9459Szrj { "relaxation", DEBUG_RELAXATION },
58*a9fa9459Szrj { "incremental", DEBUG_INCREMENTAL },
59*a9fa9459Szrj { "location", DEBUG_LOCATION },
60*a9fa9459Szrj { "all", DEBUG_ALL }
61*a9fa9459Szrj };
62*a9fa9459Szrj
63*a9fa9459Szrj int retval = 0;
64*a9fa9459Szrj for (size_t i = 0; i < sizeof(debug_options) / sizeof(*debug_options); ++i)
65*a9fa9459Szrj if (strstr(arg, debug_options[i].name))
66*a9fa9459Szrj retval |= debug_options[i].value;
67*a9fa9459Szrj return retval;
68*a9fa9459Szrj }
69*a9fa9459Szrj
70*a9fa9459Szrj // Print a debug message if TYPE is enabled. This is a macro so that
71*a9fa9459Szrj // we only evaluate the arguments if necessary.
72*a9fa9459Szrj
73*a9fa9459Szrj #define gold_debug(TYPE, FORMAT, ...) \
74*a9fa9459Szrj do \
75*a9fa9459Szrj { \
76*a9fa9459Szrj if (is_debugging_enabled(TYPE)) \
77*a9fa9459Szrj parameters->errors()->debug(FORMAT, __VA_ARGS__); \
78*a9fa9459Szrj } \
79*a9fa9459Szrj while (0)
80*a9fa9459Szrj
81*a9fa9459Szrj } // End namespace gold.
82*a9fa9459Szrj
83*a9fa9459Szrj #endif // !defined(GOLD_DEBUG_H)
84