[PATCH v3 2/8] btrace: Export btrace_decode_error function.

Tim Wiederhake
2016-11-21T15:49:07Z

2016-11-21 Tim Wiederhake <tim.wiederhake@intel.com>

gdb/ChangeLog:

* record-btrace.c (btrace_ui_out_decode_error): Move most of it ...
* btrace.c (btrace_decode_error): ... here. New function.
* btrace.h (btrace_decode_error): New export.

---
gdb/btrace.c | 49 ++++++++++++++++++++++++++++++++++++++++++++
gdb/btrace.h | 5 +++++
gdb/record-btrace.c | 59 ++++-------------------------------------------------
3 files changed, 58 insertions(+), 55 deletions(-)

diff --git a/gdb/btrace.c b/gdb/btrace.c
index 7df1b00..ac7d46e 100644
--- a/gdb/btrace.c
+++ b/gdb/btrace.c
@@ -1699,6 +1699,55 @@ btrace_maint_clear (struct btrace_thread_info *btinfo)

/* See btrace.h. */

+const char *
+btrace_decode_error (enum btrace_format format, int errcode)
+{
+ switch (format)
+ {
+ case BTRACE_FORMAT_BTS:
+ switch (errcode)
+ {
+ case BDE_BTS_OVERFLOW:
+ return _("instruction overflow");
+
+ case BDE_BTS_INSN_SIZE:
+ return _("unknown instruction");
+
+ default:
+ break;
+ }
+ break;
+
+#if defined (HAVE_LIBIPT)
+ case BTRACE_FORMAT_PT:
+ switch (errcode)
+ {
+ case BDE_PT_USER_QUIT:
+ return _("trace decode cancelled");
+
+ case BDE_PT_DISABLED:
+ return _("disabled");
+
+ case BDE_PT_OVERFLOW:
+ return _("overflow");
+
+ default:
+ if (errcode < 0)
+ return pt_errstr (pt_errcode (errcode));
+ break;
+ }
+ break;
+#endif /* defined (HAVE_LIBIPT) */
+
+ default:
+ break;
+ }
+
+ return _("unknown");
+}
+
+/* See btrace.h. */
+
void
btrace_fetch (struct thread_info *tp)
{
diff --git a/gdb/btrace.h b/gdb/btrace.h
index 114242d..d0497b4 100644
--- a/gdb/btrace.h
+++ b/gdb/btrace.h
@@ -384,6 +384,11 @@ extern void btrace_disable (struct thread_info *);
target_teardown_btrace instead of target_disable_btrace. */
extern void btrace_teardown (struct thread_info *);

+/* Return a human readable error string for the given ERRCODE in FORMAT.
+ The pointer will never be NULL and must not be freed. */
+
+extern const char *btrace_decode_error (enum btrace_format format, int errcode);
+
/* Fetch the branch trace for a single thread. */
extern void btrace_fetch (struct thread_info *);

diff --git a/gdb/record-btrace.c b/gdb/record-btrace.c
index 6c50bab..0576123 100644
--- a/gdb/record-btrace.c
+++ b/gdb/record-btrace.c
@@ -464,63 +464,12 @@ static void
btrace_ui_out_decode_error (struct ui_out *uiout, int errcode,
enum btrace_format format)
{
- const char *errstr;
- int is_error;
-
- errstr = _("unknown");
- is_error = 1;
-
- switch (format)
- {
- default:
- break;
-
- case BTRACE_FORMAT_BTS:
- switch (errcode)
- {
- default:
- break;
-
- case BDE_BTS_OVERFLOW:
- errstr = _("instruction overflow");
- break;
-
- case BDE_BTS_INSN_SIZE:
- errstr = _("unknown instruction");
- break;
- }
- break;
-
-#if defined (HAVE_LIBIPT)
- case BTRACE_FORMAT_PT:
- switch (errcode)
- {
- case BDE_PT_USER_QUIT:
- is_error = 0;
- errstr = _("trace decode cancelled");
- break;
-
- case BDE_PT_DISABLED:
- is_error = 0;
- errstr = _("disabled");
- break;
-
- case BDE_PT_OVERFLOW:
- is_error = 0;
- errstr = _("overflow");
- break;
-
- default:
- if (errcode < 0)
- errstr = pt_errstr (pt_errcode (errcode));
- break;
- }
- break;
-#endif /* defined (HAVE_LIBIPT) */
- }
+ const char *errstr = btrace_decode_error (format, errcode);

ui_out_text (uiout, _("["));
- if (is_error)
+
+ /* ERRCODE > 0 indicates notifications on BTRACE_FORMAT_PT. */
+ if (!(format == BTRACE_FORMAT_PT && errcode > 0))
{
ui_out_text (uiout, _("decode error ("));
ui_out_field_int (uiout, "errcode", errcode);
--
2.7.4