debug.h 2.5 KB

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