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