1 /* Debugging macros and interface. 2 Copyright (C) 1999-2020 Free Software Foundation, Inc. 3 This file is part of GNU Make. 4 5 GNU Make is free software; you can redistribute it and/or modify it under the 6 terms of the GNU General Public License as published by the Free Software 7 Foundation; either version 3 of the License, or (at your option) any later 8 version. 9 10 GNU Make is distributed in the hope that it will be useful, but WITHOUT ANY 11 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR 12 A PARTICULAR PURPOSE. See the GNU General Public License for more details. 13 14 You should have received a copy of the GNU General Public License along with 15 this program. If not, see <http://www.gnu.org/licenses/>. */ 16 17 #ifndef DEBUG_H 18 #define DEBUG_H 19 20 #include "types.h" 21 22 /** 23 \brief debug masks which control tracing output. 24 25 Imagine the below enums values as define'd values rather than 26 distinct values of an enum. The enum is more (gdb) debugger friendly 27 in showing what's set (e.g. DB_NONE, DB_ALL, or a single value 28 and in entering expressons (e.g print db_level & DB_BASIC). 29 */ 30 typedef enum { 31 DB_NONE = 0x000, /**< Mask when none of the below are set. */ 32 DB_BASIC = 0x001, /**< targets which need to be made and status; 33 also set when tracing or debugging */ 34 DB_VERBOSE = 0x002, /**< A more verbose trace */ 35 DB_JOBS = 0x004, /**< Prints messages giving details on the 36 invocation of specific subcommands. 37 Can be set via --debug=jobs 38 */ 39 DB_IMPLICIT = 0x008, /**< Prints messages describing the implicit 40 rule searches for each target. Can be 41 set via --debug=implicit 42 */ 43 DB_TRACE = 0x010, /**< tracing */ 44 DB_SHELL = 0x020, /**< add +x to SHELL invocations */ 45 DB_MAKEFILES = 0x100, 46 DB_READ_MAKEFILES = 0x200, /**< Reading makefiles */ 47 DB_CALL = 0x400, /**< GNU Make function call and returns */ 48 DB_UPDATE_GOAL = 0x800, /**< GNU Make function call and returns */ 49 DB_ALL = 0xfff /**< Bitmask for all of the above. */ 50 } debug_level_mask_t; 51 52 typedef enum { 53 DEBUGGER_ON_ERROR = 0x1, /**< Enter debugger on any error */ 54 DEBUGGER_ON_FATAL = 0x2, /**< Enter debugger on a fatal error */ 55 DEBUGGER_ON_SIG = 0x4 /**< Enter debugger on getting a signal */ 56 } debug_enter_debugger_t; 57 58 typedef enum { 59 DEBUGGER_QUIT_RC = 77, /**< debugger issued a "quit" command. */ 60 } debug_dummy_t; 61 62 /** These variables are trickery to force the above enum symbol values to 63 be recorded in debug symbol tables. It is used to allow one refer 64 to above enumeration values in a debugger and debugger 65 expressions */ 66 extern debug_level_mask_t debug_dummy_level_mask; 67 extern debug_enter_debugger_t debug_dummy_enter_debugger_mask; 68 69 /** bitmask of debug_level_mask values. */ 70 extern int db_level; 71 72 /*! 73 If 0 (or false) we are not in the debugger command read loop. 74 If 1 (or true) we are in the debugger command read loop. 75 If DEBUGGER_QUIT_RC we've requested to quit. 76 */ 77 extern int in_debugger; 78 79 #include <setjmp.h> 80 extern jmp_buf debugger_loop; 81 82 /** \brief The structure used to hold the list of strings given 83 + in command switches of a type that takes string arguments. */ 84 struct stringlist 85 { 86 const char **list; /**< Nil-terminated list of strings. */ 87 unsigned int idx; /**< Index into above. */ 88 unsigned int max; /**< Number of pointers allocated. */ 89 }; 90 91 extern int debug_flag; 92 93 /*! If 1, we don't give additional error reporting information. */ 94 extern int no_extended_errors; 95 96 /*! If 1, we show variable definitions */ 97 extern int show_variable_definitions; 98 99 /*! If true, enter the debugger before updating goal target. */ 100 extern bool b_debugger_goal; 101 102 /*! If true, enter the debugger before reading any makefiles. */ 103 extern bool b_debugger_preread; 104 105 /*! If nonzero, we are debugging after each "step" for that many times. 106 When we have a value 1, then we actually run the debugger read loop. 107 Otherwise we decrement the step count. 108 109 */ 110 extern unsigned int i_debugger_stepping; 111 112 /*! If nonzero, we are debugging after each "next" for that many times. 113 When we have a value 1, then we actually run the debugger read loop. 114 Otherwise we decrement the step count. 115 116 */ 117 extern unsigned int i_debugger_nexting; 118 119 /*! If nonzero, enter the debugger if we hit a fatal error. 120 */ 121 extern unsigned int debugger_on_error; 122 123 /*! If nonzero, we have requested some sort of debugging. 124 */ 125 extern unsigned int debugger_enabled; 126 127 extern stringlist_t *db_flags; 128 129 #define ISDB(_l) ((_l)&db_level) 130 131 /* When adding macros to this list be sure to update the value of 132 XGETTEXT_OPTIONS in the po/Makevars file. */ 133 134 /*! Debugged print */ 135 #define DBPRINT(_x) \ 136 printf _x; fflush (stdout) 137 138 /*! Debugged print indented a number of spaces given by "_depth" */ 139 #define DBPRINTS(_x, _depth) \ 140 print_spaces (_depth); \ 141 DBPRINT(_x) 142 143 /*! Debugged print if debug mask is set indented a number of spaces 144 implied by global variable "depth" 145 */ 146 #define DBS(_l,_x) \ 147 do { \ 148 if(ISDB(_l)) { \ 149 DBPRINTS(_x, depth); \ 150 } \ 151 } while(0) 152 153 /*! Debugged print if debug mask is set indented a number of spaces 154 given by "_depth" 155 */ 156 #define DBSD(_l,_x,_depth) \ 157 do { \ 158 if(ISDB(_l)) { \ 159 DBPRINTS(_x, _depth); \ 160 } \ 161 } while(0) 162 163 extern int db_level; 164 165 #define ISDB(_l) ((_l)&db_level) 166 167 #define DBF(_l,_x) do{ if(ISDB(_l)) {print_spaces (depth); \ 168 printf (_x, file->name); \ 169 fflush (stdout);} }while(0) 170 171 #define DB(_l,_x) do{ if(ISDB(_l)) {printf _x; fflush (stdout);} }while(0) 172 173 174 #endif /*DEBUG_H*/ 175