{"id":1533,"date":"2018-02-07T16:11:28","date_gmt":"2018-02-07T07:11:28","guid":{"rendered":"http:\/\/rageworx.info\/?p=1533"},"modified":"2022-03-02T01:47:24","modified_gmt":"2022-03-01T16:47:24","slug":"how-to-set-debug-mode-easily-for-libusb-and-libuvc","status":"publish","type":"post","link":"https:\/\/rageworx.info\/?p=1533","title":{"rendered":"How to set debug mode easily for libusb and libuvc."},"content":{"rendered":"<p>Here is a tip for programer for debug any application with using libusb(x) or libuvc.<\/p>\n<p>There&#8217;s many way to debug what it going on with gbd when you are using gcc or MinGW (incl. MinGW-W64) , you may feels somehow difficult to control gdb to debug in deep call stacks without IDE like Code::Blocks.<\/p>\n<p>You can use putenv() to set debug mode to print all messages to &#8216;stdout&#8217; (aka. console, or terminal) .<\/p>\n<h3>Preparation<\/h3>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"cpp\" data-enlighter-theme=\"dracula\">#include \"libuvc\/libuvc.h\"\r\n\r\n#ifdef DEBUG\r\n#include \"libusb.h\"\r\n#include &lt;pthread.h&gt;\r\n#endif \/\/\/ of DEBUG\r\n<\/pre>\n<h3>Enable debugging message<\/h3>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"cpp\" data-enlighter-theme=\"dracula\">int main (int argc, char ** argv)\r\n{\r\n    #ifdef DEBUG\r\n    \/\/LIBUSB_DEBUG\r\n    putenv( \"LIBUSB_DEBUG=4\" );\r\n    #endif\r\n....<\/pre>\n<p>Meaning of number appends LIBUSB_DEBUG is this level :<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"cpp\" data-enlighter-theme=\"dracula\">\/** \\ingroup lib\r\n *  Log message levels.\r\n *  - LIBUSB_LOG_LEVEL_NONE (0)    : no messages ever printed by the library (default)\r\n *  - LIBUSB_LOG_LEVEL_ERROR (1)   : error messages are printed to stderr\r\n *  - LIBUSB_LOG_LEVEL_WARNING (2) : warning and error messages are printed to stderr\r\n *  - LIBUSB_LOG_LEVEL_INFO (3)    : informational messages are printed to stdout, warning\r\n *    and error messages are printed to stderr\r\n *  - LIBUSB_LOG_LEVEL_DEBUG (4)   : debug and informational messages are printed to stdout,\r\n *    warnings and errors to stderr\r\n *\/\r\nenum libusb_log_level {\r\n    LIBUSB_LOG_LEVEL_NONE = 0,\r\n    LIBUSB_LOG_LEVEL_ERROR,\r\n    LIBUSB_LOG_LEVEL_WARNING,\r\n    LIBUSB_LOG_LEVEL_INFO,\r\n    LIBUSB_LOG_LEVEL_DEBUG,\r\n};<\/pre>\n<p>When you enable this, you can see all debugging messages on your terminal or console.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Here is a tip for programer for debug any application with using libusb(x) or libuvc. There&#8217;s many way to debug what it going on with gbd when you are using gcc or MinGW (incl. MinGW-W64) , you may feels somehow difficult to control gdb to debug in deep call stacks&#8230; <a href=\"https:\/\/rageworx.info\/?p=1533\">Read more &raquo;<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[5,3],"tags":[565,566,562,563],"class_list":["post-1533","post","type-post","status-publish","format-standard","hentry","category-development","category-raphs","tag-debug","tag-easy","tag-libusb","tag-libuvc"],"_links":{"self":[{"href":"https:\/\/rageworx.info\/index.php?rest_route=\/wp\/v2\/posts\/1533","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/rageworx.info\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/rageworx.info\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/rageworx.info\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/rageworx.info\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1533"}],"version-history":[{"count":0,"href":"https:\/\/rageworx.info\/index.php?rest_route=\/wp\/v2\/posts\/1533\/revisions"}],"wp:attachment":[{"href":"https:\/\/rageworx.info\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1533"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/rageworx.info\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1533"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/rageworx.info\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1533"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}