usage: trace2 BUG() invocations

die() messages are traced in trace2, but BUG() messages are not. Anyone
tracking die() messages would have even more reason to track BUG().
Therefore, write to trace2 when BUG() is invoked.

Signed-off-by: Jonathan Tan <jonathantanmy@google.com>
Helped-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
Jonathan Tan
2021-02-05 12:09:08 -08:00
committed by Junio C Hamano
parent 773e25afc4
commit 0a9dde4a04
3 changed files with 39 additions and 0 deletions

11
usage.c
View File

@@ -266,6 +266,10 @@ int BUG_exit_code;
static NORETURN void BUG_vfl(const char *file, int line, const char *fmt, va_list params)
{
char prefix[256];
va_list params_copy;
static int in_bug;
va_copy(params_copy, params);
/* truncation via snprintf is OK here */
if (file)
@@ -274,6 +278,13 @@ static NORETURN void BUG_vfl(const char *file, int line, const char *fmt, va_lis
snprintf(prefix, sizeof(prefix), "BUG: ");
vreportf(prefix, fmt, params);
if (in_bug)
abort();
in_bug = 1;
trace2_cmd_error_va(fmt, params_copy);
if (BUG_exit_code)
exit(BUG_exit_code);
abort();