How to Dump Memory in JDEDEBUG.log for Debugging/tracing Using jdeWriteLog and jdeTraceSz1 APIs
Purpose of Document
Are there any standard APIs available that can be used in debugging a certain business function?
NOTE:
Who this is for: C programmer
Requirement: C programming skill
Disclaimer: Example code in this document is provided as-is without warranty.
Alternative solution: Use existing standard business function B0900102 - Write to JDE log
Overview
Many times the online debugging may not be easy in debugging memory issue where jdedebug.log does not give you the value of variables used in a routine, some of standard JDE APIs can be used,
void jdeWriteLogEntry( LOGFILETYPE iLogType, const JCHAR *module, /* Module making the entry, i.e. jdeFatal jdeKrnl etc. */ const ZCHAR *srcFile, /* source module name __FILE__ */ int srcLine, /* source module line __LINE__ */ int errNum, /* Msg text short */ const JCHAR *tempText /* Msg text description */ )
Example:
jdeWriteLogEntry(JDELOG, _J("jdeXML"), __FILE__, __LINE__, 0, _J("INITIALIZING XML SERVICE KERNEL"));
__FILE__ is C++ Preprocessor part of the C/C++ standard. Usually the file name is the business function object name (e.g., B4200310)
__LINE__ is C++ Preprocessor part of the C/C++ standard. Is the line number in the source file where jdeWriteLogEntry is (e.g., line number 5356)
Message in the log will be written as b4200310.c5356
Through the use of __FILE__ and __LINE__, it specifies which business function and line number so this API can be used for debugging as well as describing an error.
void jdeVWriteLogEntry( const JCHAR *module, /* Module making the entry, i.e. jdeFatal jdeKrnl etc. */ const ZCHAR *srcFile, /* source module name __FILE__ */ int srcLine, /* source module line __LINE__ */ int errNum, /* Msg text short */ const JCHAR *msgFormat, /* Msg format specifier */ ... /* optional parms for msgFormat */ )
As we can see, Log Type (whether it is JDELOG or JDEDEBUGLOG) and Module ID are optional. Regardless, it always writes to JDELOG and JDEDEBUGLOG.
Through the use of __FILE__ and __LINE__, it specifies which business function and line number so this API can be used for debugging as well as describing an error.
void jdeWriteLog( const JCHAR *module, /* Module making the entry */ int errNum, /* Msg text short */ const JCHAR *msgFormat, /* Msg format specifier */ )
void jdeTraceSz1( NULL, /* Set this value Null */ const JCHAR *format, /* Error String with Dereferncing Error for next parameter */ ,... /* As many as you define de-referencing in * format */ )
Example 1 (De-reference number):
long lNumber = 0 ; /* declare variable - declare this in the code block*/
MathNumericToLong(&lpDS->mnUnallowableAmtTot_EHGOVUNTOT, &lNumber); /* Convert JDE MathNumeric to Long */ jdeTraceSz1(NULL, _J("For Debug:F20111_FetchExpRptHeader : Value from ExpRpt Header is = (%ld)"), lNumber);
Note: in case above code does not write long integer value, try,
char szTempString[42] = {0}; /* declare local variable */
FormatMathNumeric(szTempString, &lpDS->mnForAmtSelectedToMatch); /* in case you want to write mnForAmtSelectedToMatch */ jdeTraceSz1(NULL, "doseo 693 : %s", szTempString); /* this is example of non unicode business function. e.g., B7 releases */
When you need to print out actual value (memory) into jdedebug.log, this implementation can be useful
Refer to printf( const char *format ,…) API in C Programming lanague
For this example, dereferenced pointer value can be written into jdedebug.log (CallObject Kernel log) as below,
For Debug:F20111_FetchExpRptHeader : Value from ExpRpt Header is = (2147483647)
<Internal_Only> Our API documenation does not have API jdeTraceSz1 () information. But this API is the best one to implement to write/trace actual value in jdedebug.log. If you have prototype for this API, please put some comment in this document. </Internal_Only>