_ Dbg. h, dbgautoattach. h

Source: Internet
Author: User

_ Dbg. h, dbgautoattach. h

# Ifndef _ HSS_DBG_HSS __# define _ HSS_DBG_HSS __/************************** **************************************** * ******************************* \ * 2009-06-28 macro output of debugging information version
(1) macro _ trace, _ trace_file, _ trace_fmt, _ trace_end (2) macro _ if, _ if, _ trace_dbg, _ trace_file_dbg, _ trace_fmt_dbg, _ trace_end_dbg (the macro name dbg is behind, is to find all macros when searching _ trace) (3) usage example: _ trace "a = % d B = % d \ r \ n ", a, B); _ trace_end _ trace_file "a = % d B = % d \ r \ n", a, B); _ trace_end // note: this macro has parameters and cannot contain commas (_ trace_fmt) (_ FILE __, _ LINE __, TRUE) after the parameter brackets of the macro) "a = % d B = % d", a, B); _ trace_end where _ FILE _ can be replaced with other FILE names. if the full path is used, only the FILE name (4) _ if is a long format version. The content of the display condition (5) _ if is a short format version with no conditions displayed, only display the value of the condition \********************************** **************************************** * ***********************/# include <shlwapi. h> # pragma comment (lib, "shlwapi. lib ") //////////////////////////////////////// //////////////////////////////////////// /// // # define _ trace_end if (_ sztrace & _ sztrac E [0]) \ OutputDebugStringA (_ sztrace); \}# define _ trace \ {\ char _ sztrace [260] = {0 }; \ _ snprintf (_ sztrace, sizeof (_ sztrace), # define _ trace_file \ {\ char _ sztrace [260] = {0 }; \ int _ n = _ snprintf (_ sztrace, sizeof (_ sztrace)-1, "% 08X % s/% d", GetCurrentThreadId (), strrchr (_ FILE __, '\') + 1, _ LINE _); \ _ snprintf (_ sztrace + _ n, sizeof (_ sztrace) -_ n-1, # define _ trace_fmt (file, line, er Ror) \ {\ char _ sztrace [260] = {0}; \ int _ n = 0; \ if (file & (char *) file) [0]) \ {\ LPCTSTR _ p = strrchr (file, '\'); \ if (_ p = 0) \ _ p = file; \ _ n + = _ snprintf (_ sztrace + _ n, sizeof (_ sztrace)-1-_ n, "% s", _ p ); \ }\ if (line) \ {\ _ n + = _ snprintf (_ sztrace + _ n, sizeof (_ sztrace)-1-_ n, "/% d", line) ;\}\ if (error) \{\ int se = GetLastError (); \ LPSTR _ lpMsgbuf = 0; \ if (FormatMessage (\ messages | FORMAT_MESSAGE_FROM_SYSTEM | messages, \ NULL, \ se, \ MAKELANGID (LANG_NEUTRAL, SUBLANG_DEFAULT), \ (LPSTR) & _ lpMsgbuf, \ 0, \ NULL )\) \ {\ if (_ lpMsgbuf & _ lpMsgbuf [0]) \ {\ _ n + = _ snprintf (_ sztrace + _ n, sizeof (_ sztrace)-1-_ n, "% s (% d)", _ lpMsgbuf, se); \} \ if (_ lpMsgbuf) \{\ LocalFree (_ lpMsgbuf );\}\ }\}\_ _ N + = _ snprintf (_ sztrace + _ n, sizeof (_ sztrace)-1-_ n, //////////////////////////////////////// //////////////////////////////////////// /// // sample: _ trace_bytes ("profix", pData, cbData) _ trace_end; # define _ trace_bytes (Profix, pData, cbData) \ {\ int _ size = cbData * 3 + (Profix = 0? 0: strlen (Profix) + 32; \ char * _ sztrace = (char *) alloca (_ size); \ LPBYTE _ p = (LPBYTE) pData; \ if (_ sztrace) \ {\ int _ n = _ snprintf (_ sztrace, _ size-1, "% s", Profix ); \ for (int _ l = 0; _ l <cbData; _ l ++) \ {\ DWORD _ d = (DWORD) _ p [_ l]; \ _ n + = _ snprintf (_ sztrace + _ n, _ size-1-_ n, "% 02X", _ d); \}\_ _ n + = _ snprintf (_ sztrace + _ n, _ size-1-_ n, "(% d)", cbData); \ _ szt Race [_ n] = 0; \ _ sztrace [_ size-1] = 0; \}////////////////////////////////////// //////////////////////////////////////// /// // # define __ FL _ trace_file "\ r \ n "); __trace_end; //////////////////////////////////////// //////////////////////////////////////// /// // # ifdef _ dbg _ _/////////////////////////////////////// ////////////////////////// //////////////////////////////////////// /// // # Define _ trace_end_dbg _ trace_end # define _ trace_dbg _ trace # define _ trace_file_dbg _ trace_file # define _ trace_fmt_dbg _ _ trace_fmt /************************************* **************************************** * ******************* \ * 2009-06-28 shows the format of the program's branch and determined value length: __if: _ if the text of the judgment condition is not displayed \****************************** ******************* **************************************** * ********/# Define _ if_false (x) \ {\ char _ szif [256] = {0}; \ if (! (X) \ {\ _ snprintf (_ szif, sizeof (_ szif)-1, "% s/% d = (" # x ") \ r \ n ", strrchr (_ FILE __, '\') + 1, _ LINE __, (x); \ OutputDebugStringA (_ szif ); \}\}\ if (x) //////////////////////////////////////// //////////////////////////////////////// /// // # define _ if_true (x) \ {\ char _ szif [256] = {0}; \ if (x) \ {\ _ snprintf (_ szif, sizeof (_ szif)-1, "% s/% d = (" # x ") \ r \ n", strrchr (_ FILE __, '\') + 1, _ LINE __, (x); \ OutputDebugStringA (_ szif); \}\}\ if (x) //////////////////////////////////////// //////////////////////////////////////// /// // # define _ if (x) \ {\ char _ szif [256] = {0}; \ if (x) \ {\ _ snprintf (_ szif, sizeof (_ szif)-1, "% s/% d = (" # x ") \ r \ n", strrchr (_ FILE __, '\') + 1, _ LINE __, (x) ;\}\ else \{\_ snprintf (_ szif, sizeof (_ szif)-1, "% s/% d = (" # x ") \ r \ n", strrchr (_ FILE __, '\') + 1, _ LINE __, (x) ;\}\ OutputDebugStringA (_ szif) ;\}\ if (x) //////////////////////////////////////// //////////////////////////////////////// /// // # define _ if (x) \ {\ char _ szif [256] = {0}; \ if (x) \ {\ _ snprintf (_ szif, sizeof (_ szif)-1, "% s/% d \ r \ n", strrchr (_ FILE __, '\') + 1, _ LINE __, (x )); \} \ else \ {\ _ snprintf (_ szif, sizeof (_ szif)-1, "% s/% d \ r \ n ", strrchr (_ FILE __, '\') + 1, _ LINE __, (x) ;\}\ OutputDebugStringA (_ szif ); \} \ if (x) //////////////////////////////////////// //////////////////////////////////////// /// // # else /// //////////////////////////////////////// //////////////////////////////////////// /// // # define _ if (x) if (x) # define _ if_true (x) if (x) # define _ if_false (x) if (x) # define _ trace_end_dbg} # define _ trace_dbg if (0) {(# define _ trace_file_dbg if (0) {(# define _ trace_fmt_dbg if (0) {(////////////////////////////////////// //////////////////////////////////////// /// // # endif/ //////////////////////////////////////// //////////////////////////////////////// /// // # endif

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.