BUG/MINOR: debug: do not emit empty lines in thread dumps

In 2.3, commit 471425f51 ("BUG/MINOR: debug: Don't dump the lua stack
if it is not initialized") introduced the possibility to emit an empty
line when there's no Lua info to dump. The problem is that doing this
on the CLI in "show threads" marks the end of the output, and it may
affect some external tools. We need to make sure that LFs are only
emitted if there's something on the line and that all lines properly
start with the prefix.

This may be backported as far as 2.0 since the commit above was
backported there.

(cherry picked from commit cb01f5daa72eec595407a85959d301960d472c93)
Signed-off-by: Christopher Faulet <cfaulet@haproxy.com>
(cherry picked from commit de15dfa3c121a9e8ab790c6c3723e1c9e3521424)
Signed-off-by: Christopher Faulet <cfaulet@haproxy.com>
(cherry picked from commit f16a412149884c39066ab514bda526d28afbbb00)
Signed-off-by: Christopher Faulet <cfaulet@haproxy.com>
diff --git a/src/debug.c b/src/debug.c
index f9eccad..71b7a7b 100644
--- a/src/debug.c
+++ b/src/debug.c
@@ -272,9 +272,10 @@
 	if (hlua && hlua->T) {
 		chunk_appendf(buf, "stack traceback:\n    ");
 		append_prefixed_str(buf, hlua_traceback(hlua->T, "\n    "), pfx, '\n', 0);
-		b_putchr(buf, '\n');
 	}
-	else
+
+	/* we may need to terminate the current line */
+	if (*b_peek(buf, b_data(buf)-1) != '\n')
 		b_putchr(buf, '\n');
 #endif
 }