Ver código fonte

[debug] Allow debug message colours to be customised via DBGCOL=...

When multiple iPXE binaries are running concurrently (e.g. in the case
of undionly.kpxe using an underlying iPXE driver via the UNDI
interface) it would be helpful to be able to visually distinguish
debug messages from each binary.

Allow the range of debug colours used to be customised via the
DBGCOL=...  build parameter.  For example:

  # Restrict to colours 31-33 (red, green, yellow)
  make DBGCOL=31-33

  # Restrict to colours 34-36 (blue, magenta, cyan)
  make DBGCOL=34-36

Signed-off-by: Michael Brown <mcb30@ipxe.org>
tags/v1.20.1
Michael Brown 10 anos atrás
pai
commit
13a74e0d27
2 arquivos alterados com 39 adições e 3 exclusões
  1. 25
    0
      src/Makefile.housekeeping
  2. 14
    3
      src/core/debug.c

+ 25
- 0
src/Makefile.housekeeping Ver arquivo

@@ -710,6 +710,31 @@ $(BIN)/version.o : ../.git/index
710 710
 endif
711 711
 endif
712 712
 
713
+# Debug message autocolourisation range
714
+#
715
+DBGCOL_LIST	:= $(BIN)/.dbgcol.list
716
+ifeq ($(wildcard $(DBGCOL_LIST)),)
717
+DBGCOL_OLD := <invalid>
718
+else
719
+DBGCOL_OLD := $(shell cat $(DBGCOL_LIST))
720
+endif
721
+ifneq ($(DBGCOL_OLD),$(DBGCOL))
722
+$(shell $(ECHO) "$(DBGCOL)" > $(DBGCOL_LIST))
723
+endif
724
+
725
+$(DBGCOL_LIST) : $(MAKEDEPS)
726
+
727
+VERYCLEANUP += $(DBGCOL_LIST)
728
+
729
+DBGCOL_COLOURS := $(subst -, ,$(DBGCOL))
730
+DBGCOL_MIN := $(word 1,$(DBGCOL_COLOURS))
731
+DBGCOL_MAX := $(word 2,$(DBGCOL_COLOURS))
732
+
733
+debug_DEPS += $(DBGCOL_LIST)
734
+
735
+CFLAGS_debug += $(if $(DBGCOL_MIN),-DDBGCOL_MIN=$(DBGCOL_MIN))
736
+CFLAGS_debug += $(if $(DBGCOL_MAX),-DDBGCOL_MAX=$(DBGCOL_MAX))
737
+
713 738
 # We automatically generate rules for any file mentioned in AUTO_SRCS
714 739
 # using the following set of templates.  We use $(eval ...) if
715 740
 # available, otherwise we generate separate Makefile fragments and

+ 14
- 3
src/core/debug.c Ver arquivo

@@ -118,6 +118,15 @@ void dbg_hex_dump_da ( unsigned long dispaddr, const void *data,
118 118
 	}
119 119
 }
120 120
 
121
+/**
122
+ * Base message stream colour
123
+ *
124
+ * We default to using 31 (red foreground) as the base colour.
125
+ */
126
+#ifndef DBGCOL_MIN
127
+#define DBGCOL_MIN 31
128
+#endif
129
+
121 130
 /**
122 131
  * Maximum number of separately coloured message streams
123 132
  *
@@ -125,7 +134,9 @@ void dbg_hex_dump_da ( unsigned long dispaddr, const void *data,
125 134
  * of which will be the terminal default and one of which will be
126 135
  * invisible on the terminal because it matches the background colour.
127 136
  */
128
-#define NUM_AUTO_COLOURS 6
137
+#ifndef DBGCOL_MAX
138
+#define DBGCOL_MAX ( DBGCOL_MIN + 6 - 1 )
139
+#endif
129 140
 
130 141
 /** A colour assigned to an autocolourised debug message stream */
131 142
 struct autocolour {
@@ -142,7 +153,7 @@ struct autocolour {
142 153
  * @ret colour		Colour ID
143 154
  */
144 155
 static int dbg_autocolour ( unsigned long stream ) {
145
-	static struct autocolour acs[NUM_AUTO_COLOURS];
156
+	static struct autocolour acs[ DBGCOL_MAX - DBGCOL_MIN + 1 ];
146 157
 	static unsigned long use;
147 158
 	unsigned int i;
148 159
 	unsigned int oldest;
@@ -180,7 +191,7 @@ static int dbg_autocolour ( unsigned long stream ) {
180 191
  */
181 192
 void dbg_autocolourise ( unsigned long stream ) {
182 193
 	dbg_printf ( "\033[%dm",
183
-		     ( stream ? ( 31 + dbg_autocolour ( stream ) ) : 0 ) );
194
+		     ( stream ? ( DBGCOL_MIN + dbg_autocolour ( stream ) ) :0));
184 195
 }
185 196
 
186 197
 /**

Carregando…
Cancelar
Salvar