diff --git a/src/c_wrapper/debug.cpp b/src/c_wrapper/debug.cpp
index 4dd17f9a118a232b812cbe57cd820a09183218a1..95cb808432c7aaccfa3287eb413a323c0a5d8290 100644
--- a/src/c_wrapper/debug.cpp
+++ b/src/c_wrapper/debug.cpp
@@ -1,8 +1,18 @@
 #include "debug.h"
+#include <iostream>
 #include <stdlib.h>
 
 namespace pyopencl {
 
+void
+dbg_print_str(std::ostream &stm, const char *str, size_t len)
+{
+    // TODO escape
+    stm << '"';
+    stm.write(str, len);
+    stm << '"';
+}
+
 static PYOPENCL_INLINE bool
 _get_debug_env()
 {
diff --git a/src/c_wrapper/debug.h b/src/c_wrapper/debug.h
index cd4b0d7e0e5fdd0c5a8abd6c2073e45222575685..1b8c2ca7bb2a5da7bd1adf0aec0f2de88708f7fe 100644
--- a/src/c_wrapper/debug.h
+++ b/src/c_wrapper/debug.h
@@ -1,5 +1,6 @@
 #include "wrap_cl.h"
-#include "utils.h"
+#include "function.h"
+#include <string.h>
 
 #ifndef __PYOPENCL_DEBUG_H
 #define __PYOPENCL_DEBUG_H
@@ -15,6 +16,13 @@ extern bool debug_enabled;
 
 #define DEBUG_ON (PYOPENCL_EXPECT(debug_enabled, DEFAULT_DEBUG))
 
+void dbg_print_str(std::ostream&, const char*, size_t);
+static PYOPENCL_INLINE void
+dbg_print_str(std::ostream &stm, const char *str)
+{
+    return dbg_print_str(stm, str, strlen(str));
+}
+
 }
 
 #endif
diff --git a/src/c_wrapper/error.h b/src/c_wrapper/error.h
index 5014ea87effc46255600e9ce511beaf8c9f3716f..d98e0b5aacb04d389ee0d2c308573d5cf22b2c22 100644
--- a/src/c_wrapper/error.h
+++ b/src/c_wrapper/error.h
@@ -1,7 +1,6 @@
 #include "wrap_cl.h"
 #include "pyhelper.h"
 #include "clobj.h"
-#include "debug.h"
 
 #include <string.h>
 #include <stdexcept>
diff --git a/src/c_wrapper/utils.h b/src/c_wrapper/utils.h
index f1b24740cec824f6b79f372a6010fc08330a0ecb..c935b5533b8ad328ce50b8c297cbc1073fd2fe28 100644
--- a/src/c_wrapper/utils.h
+++ b/src/c_wrapper/utils.h
@@ -1,5 +1,6 @@
 #include "wrap_cl.h"
 #include "function.h"
+#include "debug.h"
 
 #include <string>
 #include <sstream>
@@ -83,10 +84,7 @@ template<>
 PYOPENCL_INLINE void
 _print_buf_content<char>(std::ostream &stm, const char *p, size_t len)
 {
-    // TODO escape
-    stm << '"';
-    stm.write(p, len);
-    stm << '"';
+    dbg_print_str(stm, p, len);
 }
 
 template<typename T>
@@ -164,7 +162,7 @@ struct CLGenericArgPrinter<
     static PYOPENCL_INLINE void
     print(std::ostream &stm, const char *str)
     {
-        _print_buf_content<char>(stm, str, strlen(str));
+        dbg_print_str(stm, str);
     }
 };