Improve backtrace formatting.

Show the symbol offset, when available.

Centralized formatting of native stack traces in libcorkscrew.
It's handy for automated tools if all stacks look the same.
Since we already made them all look them same, we might as well
do the formatting in just one place.

Do not strip the Thumb bit on ARM.  This fixes an off-by-one
issue that could happen when resolving a PC that was at the
very beginning of a Thumb function, since the symbol table would
have the Thumb bit set but since we stripped the bit from our
PC, we would be looking for an address one byte before the
one listed in the symbol table.  It's also quite useful to see
whether a given function is executing in Thumb mode just by glancing
at the PC.

Change-Id: Icaa29add85ce0bcafe24d5ce2098e138d809e2ab
diff --git a/include/corkscrew/backtrace.h b/include/corkscrew/backtrace.h
index 157d029..556ad04 100644
--- a/include/corkscrew/backtrace.h
+++ b/include/corkscrew/backtrace.h
@@ -41,10 +41,12 @@
  * Describes the symbols associated with a backtrace frame.
  */
 typedef struct {
-    uintptr_t relative_pc;       /* relative PC offset from the start of the library,
+    uintptr_t relative_pc;       /* relative frame PC offset from the start of the library,
                                     or the absolute PC if the library is unknown */
+    uintptr_t relative_symbol_addr; /* relative offset of the symbol from the start of the
+                                    library or 0 if the library is unknown */
     char* map_name;              /* executable or library name, or NULL if unknown */
-    char* name;                  /* symbol name, or NULL if unknown */
+    char* symbol_name;           /* symbol name, or NULL if unknown */
     char* demangled_name;        /* demangled symbol name, or NULL if unknown */
 } backtrace_symbol_t;
 
@@ -95,6 +97,17 @@
  */
 void free_backtrace_symbols(backtrace_symbol_t* backtrace_symbols, size_t frames);
 
+enum {
+    // A hint for how big to make the line buffer for format_backtrace_line
+    MAX_BACKTRACE_LINE_LENGTH = 800,
+};
+
+/**
+ * Formats a line from a backtrace as a zero-terminated string into the specified buffer.
+ */
+void format_backtrace_line(unsigned frameNumber, const backtrace_frame_t* frame,
+        const backtrace_symbol_t* symbol, char* buffer, size_t bufferSize);
+
 #ifdef __cplusplus
 }
 #endif