+#define IS_HOOKED(h) (debugger_hooks[h].hook._##h != NULL)
+
+/* some macros needed to create the info string */
+#define _DBG_VERSION(major, minor) #major "." #minor
+#define DBG_VERSION(major, minor) _DBG_VERSION(major, minor)
+#define API_VERSION(major, minor) "API:" DBG_VERSION(major, minor)
+
+/* the API version: change if needed */
+#define FIRM_DBG_MAJOR 1
+#define FIRM_DBG_MINOR 0
+
+/** for automatic detection of the debug extension */
+static const char *firm_debug_info_string =
+ API_VERSION(FIRM_DBG_MAJOR, FIRM_DBG_MINOR)
+ ;
+
+/**
+ * Returns non-zero, if the debug extension is active
+ */
+int firm_debug_active(void) {
+ return is_active;
+}
+
+/**
+ * reset the debug text buffer
+ */
+static void reset_dbg_buf(void) {
+ firm_dbg_msg_buf[0] = '\0';
+}
+
+/**
+ * Add text to the debug text buffer
+ */
+static void add_to_dbg_buf(const char *buf) {
+ strncat(firm_dbg_msg_buf, buf, sizeof(firm_dbg_msg_buf));
+}
+
+/**
+ * Return the content of the debug text buffer.
+ *
+ * To be called from the debugger.
+ */
+const char *firm_debug_text(void) {
+ return firm_dbg_msg_buf;
+}
+
+/**
+ * debug output
+ */
+static void dbg_printf(const char *fmt, ...)
+{
+ char buf[1024];
+
+ va_list args;
+ va_start(args, fmt);
+
+ if (fmt[0] != '+')
+ reset_dbg_buf();
+ else
+ ++fmt;
+
+ ir_vsnprintf(buf, sizeof(buf), fmt, args);
+ va_end(args);
+
+ if (redir_output)
+ add_to_dbg_buf(buf);
+ else
+ puts(buf);
+}