debug.h 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. // debug.h -- gold internal debugging support -*- C++ -*-
  2. // Copyright (C) 2007-2015 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_ALL = (DEBUG_TASK | DEBUG_SCRIPT | DEBUG_FILES
  32. | DEBUG_RELAXATION | DEBUG_INCREMENTAL
  33. | DEBUG_LOCATION);
  34. // Convert a debug string to the appropriate enum.
  35. inline int
  36. debug_string_to_enum(const char* arg)
  37. {
  38. static const struct { const char* name; int value; }
  39. debug_options[] =
  40. {
  41. { "task", DEBUG_TASK },
  42. { "script", DEBUG_SCRIPT },
  43. { "files", DEBUG_FILES },
  44. { "relaxation", DEBUG_RELAXATION },
  45. { "incremental", DEBUG_INCREMENTAL },
  46. { "location", DEBUG_LOCATION },
  47. { "all", DEBUG_ALL }
  48. };
  49. int retval = 0;
  50. for (size_t i = 0; i < sizeof(debug_options) / sizeof(*debug_options); ++i)
  51. if (strstr(arg, debug_options[i].name))
  52. retval |= debug_options[i].value;
  53. return retval;
  54. }
  55. // Print a debug message if TYPE is enabled. This is a macro so that
  56. // we only evaluate the arguments if necessary.
  57. #define gold_debug(TYPE, FORMAT, ...) \
  58. do \
  59. { \
  60. if (is_debugging_enabled(TYPE)) \
  61. parameters->errors()->debug(FORMAT, __VA_ARGS__); \
  62. } \
  63. while (0)
  64. } // End namespace gold.
  65. #endif // !defined(GOLD_DEBUG_H)