"Das U-Boot" Source Tree

log: Avoid including function names by default

Unless function names are requested, the logging system should not
compile these into the code. Adjust the macros to handle this.

This means that turning on function names at runtime won't work unless
CONFIG_LOGF_FUNC is enabled. We could perhaps split this into a
separate option if that is a problem.

Enable CONFIG_LOGF_FUNC logging for sandbox since the tests expect the
function names to be included. Fix up the pinmux test which checks a
logging statement.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Quentin Schulz <quentin.schulz@cherry.de>

authored by

Simon Glass and committed by
Tom Rini
dfc0acd0 99b23d45

+26 -11
+2 -2
common/log_console.c
··· 38 38 printf("%d-", rec->line); 39 39 if (fmt & BIT(LOGF_FUNC)) { 40 40 if (CONFIG_IS_ENABLED(USE_TINY_PRINTF)) { 41 - printf("%s()", rec->func); 41 + printf("%s()", rec->func ?: "?"); 42 42 } else { 43 43 printf("%*s()", CONFIG_LOGF_FUNC_PAD, 44 - rec->func); 44 + rec->func ?: "?"); 45 45 } 46 46 } 47 47 }
+1 -1
common/log_syslog.c
··· 88 88 if (fmt & BIT(LOGF_LINE)) 89 89 append(&ptr, msg_end, "%d-", rec->line); 90 90 if (fmt & BIT(LOGF_FUNC)) 91 - append(&ptr, msg_end, "%s()", rec->func); 91 + append(&ptr, msg_end, "%s()", rec->func ?: "?"); 92 92 if (fmt & BIT(LOGF_MSG)) 93 93 append(&ptr, msg_end, "%s%s", 94 94 fmt != BIT(LOGF_MSG) ? " " : "", rec->msg);
+1
configs/sandbox_defconfig
··· 40 40 CONFIG_LOG=y 41 41 CONFIG_LOG_MAX_LEVEL=9 42 42 CONFIG_LOG_DEFAULT_LEVEL=6 43 + CONFIG_LOGF_FUNC=y 43 44 CONFIG_DISPLAY_BOARDINFO_LATE=y 44 45 CONFIG_STACKPROTECTOR=y 45 46 CONFIG_CMD_CPU=y
+11 -5
include/log.h
··· 125 125 * @level: Level of log record (indicating its severity) 126 126 * @file: File name of file where log record was generated 127 127 * @line: Line number in file where log record was generated 128 - * @func: Function where log record was generated 128 + * @func: Function where log record was generated, NULL if not known 129 129 * @fmt: printf() format string for log record 130 130 * @...: Optional parameters, according to the format string @fmt 131 131 * Return: 0 if log record was emitted, -ve on error ··· 141 141 * @level: Level of log record (indicating its severity) 142 142 * @file: File name of file where log record was generated 143 143 * @line: Line number in file where log record was generated 144 - * @func: Function where log record was generated 144 + * @func: Function where log record was generated, NULL if not known 145 145 * @addr: Starting address to display at start of line 146 146 * @data: pointer to data buffer 147 147 * @width: data value width. May be 1, 2, or 4. ··· 193 193 #define _LOG_DEBUG 0 194 194 #endif 195 195 196 + #ifdef CONFIG_LOGF_FUNC 197 + #define _log_func __func__ 198 + #else 199 + #define _log_func NULL 200 + #endif 201 + 196 202 #if CONFIG_IS_ENABLED(LOG) 197 203 198 204 /* Emit a log record if the level is less that the maximum */ ··· 201 207 if (_LOG_DEBUG != 0 || _l <= _LOG_MAX_LEVEL) \ 202 208 _log((enum log_category_t)(_cat), \ 203 209 (enum log_level_t)(_l | _LOG_DEBUG), __FILE__, \ 204 - __LINE__, __func__, \ 210 + __LINE__, _log_func, \ 205 211 pr_fmt(_fmt), ##_args); \ 206 212 }) 207 213 ··· 211 217 if (_LOG_DEBUG != 0 || _l <= _LOG_MAX_LEVEL) \ 212 218 _log_buffer((enum log_category_t)(_cat), \ 213 219 (enum log_level_t)(_l | _LOG_DEBUG), __FILE__, \ 214 - __LINE__, __func__, _addr, _data, \ 220 + __LINE__, _log_func, _addr, _data, \ 215 221 _width, _count, _linelen); \ 216 222 }) 217 223 #else ··· 314 320 #define assert_noisy(x) \ 315 321 ({ bool _val = (x); \ 316 322 if (!_val) \ 317 - __assert_fail(#x, "?", __LINE__, __func__); \ 323 + __assert_fail(#x, "?", __LINE__, _log_func); \ 318 324 _val; \ 319 325 }) 320 326
+7 -1
test/cmd/pinmux.c
··· 30 30 31 31 console_record_reset(); 32 32 run_command("pinmux status P9", 0); 33 - ut_assert_nextlinen("single-pinctrl pinctrl-single-no-width: missing register width"); 33 + if (IS_ENABLED(CONFIG_LOGF_FUNC)) { 34 + ut_assert_nextlinen( 35 + " single_of_to_plat() single-pinctrl pinctrl-single-no-width: missing register width"); 36 + } else { 37 + ut_assert_nextlinen( 38 + "single-pinctrl pinctrl-single-no-width: missing register width"); 39 + } 34 40 ut_assert_nextlinen("P9 not found"); 35 41 ut_assert_console_end(); 36 42
+4 -2
test/log/log_test.c
··· 452 452 /* This one should product no output due to the debug level */ 453 453 log_buffer(LOGC_BOOT, LOGL_DEBUG, 0, buf, 1, 0x12, 0); 454 454 455 - ut_assert_nextline("00000000: 00 11 22 33 44 55 66 77 88 99 aa bb cc dd ee ff ..\"3DUfw........"); 456 - ut_assert_nextline("00000010: 10 00 .."); 455 + ut_assert_nextline( 456 + " log_test_buffer() 00000000: 00 11 22 33 44 55 66 77 88 99 aa bb cc dd ee ff ..\"3DUfw........"); 457 + ut_assert_nextline( 458 + " log_test_buffer() 00000010: 10 00 .."); 457 459 ut_assert_console_end(); 458 460 free(buf); 459 461