Print Dout() and DoutEntering() debug output on windows.
This is a bit of a hack currently and requires a recompile with -DDEBUG_CURLIO.
This commit is contained in:
@@ -34,6 +34,8 @@ if(NOT WORD_SIZE EQUAL 32)
|
||||
endif(WINDOWS)
|
||||
endif (NOT WORD_SIZE EQUAL 32)
|
||||
|
||||
add_definitions(-Dcwdebug_EXPORTS)
|
||||
|
||||
list(APPEND cwdebug_SOURCE_FILES ${cwdebug_HEADER_FILES})
|
||||
|
||||
add_library (cwdebug ${cwdebug_SOURCE_FILES})
|
||||
|
||||
@@ -413,4 +413,71 @@ void cwdebug_backtrace(int n)
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // CWDEBUG
|
||||
#elif defined(DEBUG_CURLIO)
|
||||
|
||||
#include "debug.h"
|
||||
|
||||
namespace debug
|
||||
{
|
||||
|
||||
libcwd_do_type const libcw_do;
|
||||
AI_THREADLOCAL int Indent::S_indentation;
|
||||
|
||||
std::ostream& operator<<(std::ostream& os, Indent::print_nt)
|
||||
{
|
||||
if (Indent::S_indentation)
|
||||
os << std::string(Indent::S_indentation, ' ');
|
||||
return os;
|
||||
}
|
||||
|
||||
std::ostream& operator<<(std::ostream& os, libcwd::buf2str const& b2s)
|
||||
{
|
||||
static char const c2s_tab[7] = { 'a', 'b', 't', 'n', 'v', 'f', 'r' };
|
||||
size_t size = b2s.mSize;
|
||||
for (char const* p1 = b2s.mBuf; size > 0; --size, ++p1)
|
||||
{
|
||||
char c =*p1;
|
||||
if ((c > 31 && c != 92 && c != 127) || (unsigned char)c > 159)
|
||||
os.put(c);
|
||||
else
|
||||
{
|
||||
os.put('\\');
|
||||
if (c > 6 && c < 14)
|
||||
{
|
||||
os.put(c2s_tab[c - 7]);
|
||||
return os;
|
||||
}
|
||||
else if (c == 27)
|
||||
{
|
||||
os.put('e');
|
||||
return os;
|
||||
}
|
||||
else if (c == '\\')
|
||||
{
|
||||
os.put('\\');
|
||||
return os;
|
||||
}
|
||||
short old_fill = os.fill('0');
|
||||
std::ios_base::fmtflags old_flgs = os.flags();
|
||||
os.width(3);
|
||||
os << std::oct << (int)((unsigned char)c);
|
||||
os.setf(old_flgs);
|
||||
os.fill(old_fill);
|
||||
}
|
||||
}
|
||||
return os;
|
||||
}
|
||||
|
||||
namespace dc
|
||||
{
|
||||
|
||||
fake_channel const warning(1, "WARNING ");
|
||||
fake_channel const curl(1, "CURL ");
|
||||
fake_channel const curlio(1, "CURLIO ");
|
||||
fake_channel const statemachine(1, "STATEMACHINE");
|
||||
fake_channel const notice(1, "NOTICE ");
|
||||
|
||||
} // namespace dc
|
||||
} // namespace debug
|
||||
|
||||
#endif
|
||||
|
||||
@@ -27,6 +27,111 @@
|
||||
|
||||
#ifndef CWDEBUG
|
||||
|
||||
#ifdef DEBUG_CURLIO
|
||||
|
||||
#if LL_WINDOWS
|
||||
#define CWD_DLLEXPORT __declspec(dllexport)
|
||||
#define CWD_DLLIMPORT __declspec(dllimport)
|
||||
#elif LL_LINUX
|
||||
#define CWD_DLLEXPORT __attribute__ ((visibility("default")))
|
||||
#define CWD_DLLIMPORT
|
||||
#else
|
||||
#define CWD_DLLEXPORT
|
||||
#define CWD_DLLIMPORT
|
||||
#endif // LL_WINDOWS
|
||||
|
||||
#if LL_COMMON_LINK_SHARED
|
||||
#if defined(cwdebug_EXPORTS)
|
||||
#define CWD_API CWD_DLLEXPORT
|
||||
#else // cwdebug_EXPORTS
|
||||
#define CWD_API CWD_DLLIMPORT
|
||||
#endif // cwdebug_EXPORTS
|
||||
#else // LL_COMMON_LINK_SHARED
|
||||
#error LL_COMMON_LINK_SHARED not defined
|
||||
#endif // LL_COMMON_LINK_SHARED
|
||||
|
||||
// If CWDEBUG is not defined, but DEBUG_CURLIO is, then replace
|
||||
// some of the cwd macro's with something that generates viewer
|
||||
// specific debug output. Note that this generates a LOT of
|
||||
// output and should not normally be defined.
|
||||
|
||||
#include <string>
|
||||
|
||||
#if LL_WINDOWS
|
||||
#define AI_THREADLOCAL __declspec(thread)
|
||||
#else
|
||||
#define AI_THREADLOCAL __thread
|
||||
#endif
|
||||
|
||||
namespace debug {
|
||||
namespace libcwd {
|
||||
|
||||
struct buf2str {
|
||||
buf2str(char const* buf, int size) : mBuf(buf), mSize(size) { }
|
||||
char const* mBuf;
|
||||
int mSize;
|
||||
};
|
||||
|
||||
} // namespace libcwd
|
||||
|
||||
extern CWD_API std::ostream& operator<<(std::ostream& os, libcwd::buf2str const& b2s);
|
||||
|
||||
inline void init() { }
|
||||
struct libcwd_do_type {
|
||||
void on() const { }
|
||||
};
|
||||
extern CWD_API libcwd_do_type const libcw_do;
|
||||
struct CWD_API Indent {
|
||||
int M_indent;
|
||||
static AI_THREADLOCAL int S_indentation;
|
||||
enum print_nt { print };
|
||||
Indent(int indent) : M_indent(indent) { S_indentation += M_indent; }
|
||||
~Indent() { S_indentation -= M_indent; }
|
||||
friend CWD_API std::ostream& operator<<(std::ostream& os, print_nt);
|
||||
};
|
||||
|
||||
namespace dc {
|
||||
|
||||
struct fake_channel {
|
||||
int mOn;
|
||||
char const* mLabel;
|
||||
fake_channel(int on, char const* label) : mOn(on), mLabel(label) { }
|
||||
fake_channel(void) : mOn(0) { }
|
||||
bool is_on() const { return mOn; }
|
||||
bool is_off() const { return !mOn; }
|
||||
void on() const { }
|
||||
void off() const { }
|
||||
};
|
||||
extern CWD_API fake_channel const warning;
|
||||
extern CWD_API fake_channel const curl;
|
||||
extern CWD_API fake_channel const curlio;
|
||||
extern CWD_API fake_channel const statemachine;
|
||||
extern CWD_API fake_channel const notice;
|
||||
|
||||
} // namespace dc
|
||||
} // namespace debug
|
||||
|
||||
#define Debug(x) do { using namespace debug; x; } while(0)
|
||||
#define Dout(a, b) do { using namespace debug; if ((a).mOn) { llinfos_nf << (a).mLabel << ": " << Indent::print << b << llendl; } } while(0)
|
||||
#define DoutEntering(a, b) \
|
||||
int __slviewer_debug_indentation = 2; \
|
||||
{ \
|
||||
using namespace debug; \
|
||||
if ((a).mOn) \
|
||||
llinfos_nf << (a).mLabel << ": " << Indent::print << "Entering " << b << llendl; \
|
||||
else \
|
||||
__slviewer_debug_indentation = 0; \
|
||||
} \
|
||||
debug::Indent __slviewer_debug_indent(__slviewer_debug_indentation);
|
||||
|
||||
#else // !DEBUG_CURLIO
|
||||
|
||||
#define Debug(x)
|
||||
#define Dout(a, b)
|
||||
#define DoutEntering(a, b)
|
||||
|
||||
#endif // !DEBUG_CURLIO
|
||||
|
||||
#ifndef DOXYGEN // No need to document this. See http://libcwd.sourceforge.net/ for more info.
|
||||
|
||||
#include <iostream>
|
||||
@@ -36,9 +141,6 @@
|
||||
#define AllocTag2(p, desc)
|
||||
#define AllocTag_dynamic_description(p, x)
|
||||
#define AllocTag(p, x)
|
||||
#define Debug(x)
|
||||
#define Dout(a, b)
|
||||
#define DoutEntering(a, b)
|
||||
#define DoutFatal(a, b) LibcwDoutFatal(::std, , a, b)
|
||||
#define ForAllDebugChannels(STATEMENT)
|
||||
#define ForAllDebugObjects(STATEMENT)
|
||||
|
||||
@@ -886,9 +886,18 @@ void CurlEasyRequest::addHeader(char const* header)
|
||||
mHeaders = curl_slist_append(mHeaders, header);
|
||||
}
|
||||
|
||||
#ifdef CWDEBUG
|
||||
static int curl_debug_callback(CURL*, curl_infotype infotype, char* buf, size_t size, void* user_ptr)
|
||||
#if defined(CWDEBUG) || defined(DEBUG_CURLIO)
|
||||
|
||||
#ifndef CWDEBUG
|
||||
#define LIBCWD_DEBUGCHANNELS 0
|
||||
#define LibcwDoutScopeBegin(a, b, c) do { using namespace debug; llinfos_nf << dc::curlio.mLabel << ": ";
|
||||
#define LibcwDoutStream llcont
|
||||
#define LibcwDoutScopeEnd llcont << llendl; } while(0)
|
||||
#endif
|
||||
|
||||
static int curl_debug_cb(CURL*, curl_infotype infotype, char* buf, size_t size, void* user_ptr)
|
||||
{
|
||||
#ifdef CWDEBUG
|
||||
using namespace ::libcwd;
|
||||
|
||||
CurlEasyRequest* request = (CurlEasyRequest*)user_ptr;
|
||||
@@ -898,6 +907,13 @@ static int curl_debug_callback(CURL*, curl_infotype infotype, char* buf, size_t
|
||||
libcw_do.marker().assign(marker.str().data(), marker.str().size());
|
||||
if (!debug::channels::dc::curlio.is_on())
|
||||
debug::channels::dc::curlio.on();
|
||||
#else
|
||||
if (infotype == CURLINFO_TEXT)
|
||||
{
|
||||
while (size > 0 && (buf[size - 1] == '\r' || buf[size - 1] == '\n'))
|
||||
--size;
|
||||
}
|
||||
#endif
|
||||
LibcwDoutScopeBegin(LIBCWD_DEBUGCHANNELS, libcw_do, dc::curlio|cond_nonewline_cf(infotype == CURLINFO_TEXT))
|
||||
switch (infotype)
|
||||
{
|
||||
@@ -976,7 +992,9 @@ static int curl_debug_callback(CURL*, curl_infotype infotype, char* buf, size_t
|
||||
else
|
||||
LibcwDoutStream << size << " bytes";
|
||||
LibcwDoutScopeEnd;
|
||||
#ifdef CWDEBUG
|
||||
libcw_do.pop_marker();
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
@@ -1041,7 +1059,7 @@ void CurlEasyRequest::applyDefaultOptions(void)
|
||||
if (dc::curlio.is_on())
|
||||
{
|
||||
setopt(CURLOPT_VERBOSE, 1);
|
||||
setopt(CURLOPT_DEBUGFUNCTION, &curl_debug_callback);
|
||||
setopt(CURLOPT_DEBUGFUNCTION, &curl_debug_cb);
|
||||
setopt(CURLOPT_DEBUGDATA, this);
|
||||
}
|
||||
);
|
||||
|
||||
@@ -39,7 +39,7 @@
|
||||
#endif
|
||||
#include <deque>
|
||||
|
||||
#define DEBUG_WINDOWS_CODE_ON_LINUX 0
|
||||
#define DEBUG_WINDOWS_CODE_ON_LINUX 1
|
||||
|
||||
#if DEBUG_WINDOWS_CODE_ON_LINUX
|
||||
|
||||
@@ -1262,7 +1262,7 @@ MultiHandle::~MultiHandle()
|
||||
delete mReadPollSet;
|
||||
}
|
||||
|
||||
#ifdef CWDEBUG
|
||||
#if defined(CWDEBUG) || defined(DEBUG_CURLIO)
|
||||
#undef AI_CASE_RETURN
|
||||
#define AI_CASE_RETURN(x) do { case x: return #x; } while(0)
|
||||
char const* action_str(int action)
|
||||
|
||||
@@ -253,7 +253,7 @@ extern S32 gStartImageHeight;
|
||||
// local globals
|
||||
//
|
||||
|
||||
#ifdef CWDEBUG
|
||||
#if defined(CWDEBUG) || defined(DEBUG_CURLIO)
|
||||
static bool gCurlIo;
|
||||
#endif
|
||||
|
||||
|
||||
Reference in New Issue
Block a user