From 27aa65ecfb542956f43fbb9e177b64ab21e5c3e6 Mon Sep 17 00:00:00 2001 From: Christopher Faulet Date: Tue, 1 Oct 2019 22:03:49 +0200 Subject: [PATCH] MINOR: htx: Adapt htx_dump() to be used from traces This function now dumps info about the HTX message into a buffer, passed as argument. In addition, it is possible to only dump meta information, without the message content. --- include/common/htx.h | 42 ++++++++++++++++++++++-------------------- 1 file changed, 22 insertions(+), 20 deletions(-) diff --git a/include/common/htx.h b/include/common/htx.h index b2ab1346f..aa0176f83 100644 --- a/include/common/htx.h +++ b/include/common/htx.h @@ -805,16 +805,19 @@ static inline const char *htx_blk_type_str(enum htx_blk_type type) } /* For debugging purpose */ -static inline void htx_dump(struct htx *htx) +static inline void htx_dump(struct buffer *chunk, const struct htx *htx, int full) { int32_t pos; - fprintf(stderr, "htx:%p [ size=%u - data=%u - used=%u - wrap=%s - extra=%llu]\n", - htx, htx->size, htx->data, htx_nbblks(htx), - (!htx->head_addr) ? "NO" : "YES", - (unsigned long long)htx->extra); - fprintf(stderr, "\tfirst=%d - head=%d - tail=%d - tail_addr=%d - head_addr=%d, end_addr=%d\n", - htx->first, htx->head, htx->tail, htx->tail_addr, htx->head_addr, htx->end_addr); + chunk_appendf(chunk, " htx=%p(size=%u,data=%u,used=%u,wrap=%s,flags=0x%08x,extra=%llu," + "first=%d,head=%d,tail=%d,tail_addr=%d,head_addr=%d,end_addr=%d)", + htx, htx->size, htx->data, htx_nbblks(htx), (!htx->head_addr) ? "NO" : "YES", + htx->flags, (unsigned long long)htx->extra, htx->first, htx->head, htx->tail, + htx->tail_addr, htx->head_addr, htx->end_addr); + + if (!full || !htx_nbblks(htx)) + return; + chunk_memcat(chunk, "\n", 1); for (pos = htx_get_head(htx); pos != -1; pos = htx_get_next(htx, pos)) { struct htx_sl *sl; @@ -828,23 +831,22 @@ static inline void htx_dump(struct htx *htx) if (type == HTX_BLK_REQ_SL || type == HTX_BLK_RES_SL) { sl = htx_get_blk_ptr(htx, blk); - fprintf(stderr, "\t\t[%u] type=%-17s - size=%-6u - addr=%-6u\t%.*s %.*s %.*s\n", - pos, htx_blk_type_str(type), sz, blk->addr, - HTX_SL_P1_LEN(sl), HTX_SL_P1_PTR(sl), - HTX_SL_P2_LEN(sl), HTX_SL_P2_PTR(sl), - HTX_SL_P3_LEN(sl), HTX_SL_P3_PTR(sl)); + chunk_appendf(chunk, "\t\t[%u] type=%-17s - size=%-6u - addr=%-6u\t%.*s %.*s %.*s\n", + pos, htx_blk_type_str(type), sz, blk->addr, + HTX_SL_P1_LEN(sl), HTX_SL_P1_PTR(sl), + HTX_SL_P2_LEN(sl), HTX_SL_P2_PTR(sl), + HTX_SL_P3_LEN(sl), HTX_SL_P3_PTR(sl)); } else if (type == HTX_BLK_HDR || type == HTX_BLK_TLR) - fprintf(stderr, "\t\t[%u] type=%-17s - size=%-6u - addr=%-6u\t%.*s: %.*s\n", - pos, htx_blk_type_str(type), sz, blk->addr, - (int)n.len, n.ptr, - (int)v.len, v.ptr); + chunk_appendf(chunk, "\t\t[%u] type=%-17s - size=%-6u - addr=%-6u\t%.*s: %.*s\n", + pos, htx_blk_type_str(type), sz, blk->addr, + (int)n.len, n.ptr, + (int)v.len, v.ptr); else - fprintf(stderr, "\t\t[%u] type=%-17s - size=%-6u - addr=%-6u%s\n", - pos, htx_blk_type_str(type), sz, blk->addr, - (!v.len ? "\t" : "")); + chunk_appendf(chunk, "\t\t[%u] type=%-17s - size=%-6u - addr=%-6u%s\n", + pos, htx_blk_type_str(type), sz, blk->addr, + (!v.len ? "\t" : "")); } - fprintf(stderr, "\n"); } #endif /* _COMMON_HTX_H */