debuglib.c 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. /*
  2. *
  3. Copyright (c) Eicon Networks, 2002.
  4. *
  5. This source file is supplied for the use with
  6. Eicon Networks range of DIVA Server Adapters.
  7. *
  8. Eicon File Revision : 2.1
  9. *
  10. This program is free software; you can redistribute it and/or modify
  11. it under the terms of the GNU General Public License as published by
  12. the Free Software Foundation; either version 2, or (at your option)
  13. any later version.
  14. *
  15. This program is distributed in the hope that it will be useful,
  16. but WITHOUT ANY WARRANTY OF ANY KIND WHATSOEVER INCLUDING ANY
  17. implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  18. See the GNU General Public License for more details.
  19. *
  20. You should have received a copy of the GNU General Public License
  21. along with this program; if not, write to the Free Software
  22. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  23. *
  24. */
  25. #include "debuglib.h"
  26. #ifdef DIVA_NO_DEBUGLIB
  27. static DIVA_DI_PRINTF dprintf;
  28. #else /* DIVA_NO_DEBUGLIB */
  29. _DbgHandle_ myDriverDebugHandle = { 0 /*!Registered*/, DBG_HANDLE_VERSION };
  30. DIVA_DI_PRINTF dprintf = no_printf;
  31. /*****************************************************************************/
  32. #define DBG_FUNC(name) \
  33. void \
  34. myDbgPrint_##name(char *format, ...) \
  35. { va_list ap; \
  36. if (myDriverDebugHandle.dbg_prt) \
  37. { va_start(ap, format); \
  38. (myDriverDebugHandle.dbg_prt) \
  39. (myDriverDebugHandle.id, DLI_##name, format, ap); \
  40. va_end(ap); \
  41. } }
  42. DBG_FUNC(LOG)
  43. DBG_FUNC(FTL)
  44. DBG_FUNC(ERR)
  45. DBG_FUNC(TRC)
  46. DBG_FUNC(MXLOG)
  47. DBG_FUNC(FTL_MXLOG)
  48. void
  49. myDbgPrint_EVL(long msgID, ...)
  50. { va_list ap;
  51. if (myDriverDebugHandle.dbg_ev)
  52. { va_start(ap, msgID);
  53. (myDriverDebugHandle.dbg_ev)
  54. (myDriverDebugHandle.id, (unsigned long)msgID, ap);
  55. va_end(ap);
  56. } }
  57. DBG_FUNC(REG)
  58. DBG_FUNC(MEM)
  59. DBG_FUNC(SPL)
  60. DBG_FUNC(IRP)
  61. DBG_FUNC(TIM)
  62. DBG_FUNC(BLK)
  63. DBG_FUNC(TAPI)
  64. DBG_FUNC(NDIS)
  65. DBG_FUNC(CONN)
  66. DBG_FUNC(STAT)
  67. DBG_FUNC(SEND)
  68. DBG_FUNC(RECV)
  69. DBG_FUNC(PRV0)
  70. DBG_FUNC(PRV1)
  71. DBG_FUNC(PRV2)
  72. DBG_FUNC(PRV3)
  73. /*****************************************************************************/
  74. int
  75. DbgRegister(char *drvName, char *drvTag, unsigned long dbgMask)
  76. {
  77. int len;
  78. /*
  79. * deregister (if already registered) and zero out myDriverDebugHandle
  80. */
  81. DbgDeregister();
  82. /*
  83. * initialize the debug handle
  84. */
  85. myDriverDebugHandle.Version = DBG_HANDLE_VERSION;
  86. myDriverDebugHandle.id = -1;
  87. myDriverDebugHandle.dbgMask = dbgMask | (DL_EVL | DL_FTL | DL_LOG);
  88. len = strlen(drvName);
  89. memcpy(myDriverDebugHandle.drvName, drvName,
  90. (len < sizeof(myDriverDebugHandle.drvName)) ?
  91. len : sizeof(myDriverDebugHandle.drvName) - 1);
  92. len = strlen(drvTag);
  93. memcpy(myDriverDebugHandle.drvTag, drvTag,
  94. (len < sizeof(myDriverDebugHandle.drvTag)) ?
  95. len : sizeof(myDriverDebugHandle.drvTag) - 1);
  96. /*
  97. * Try to register debugging via old (and only) interface
  98. */
  99. dprintf("\000\377", &myDriverDebugHandle);
  100. if (myDriverDebugHandle.dbg_prt)
  101. {
  102. return (1);
  103. }
  104. /*
  105. * Check if we registered with an old maint driver (see debuglib.h)
  106. */
  107. if (myDriverDebugHandle.dbg_end != NULL
  108. /* location of 'dbg_prt' in _OldDbgHandle_ struct */
  109. && (myDriverDebugHandle.regTime.LowPart ||
  110. myDriverDebugHandle.regTime.HighPart))
  111. /* same location as in _OldDbgHandle_ struct */
  112. {
  113. dprintf("%s: Cannot log to old maint driver !", drvName);
  114. myDriverDebugHandle.dbg_end =
  115. ((_OldDbgHandle_ *)&myDriverDebugHandle)->dbg_end;
  116. DbgDeregister();
  117. }
  118. return (0);
  119. }
  120. /*****************************************************************************/
  121. void
  122. DbgSetLevel(unsigned long dbgMask)
  123. {
  124. myDriverDebugHandle.dbgMask = dbgMask | (DL_EVL | DL_FTL | DL_LOG);
  125. }
  126. /*****************************************************************************/
  127. void
  128. DbgDeregister(void)
  129. {
  130. if (myDriverDebugHandle.dbg_end)
  131. {
  132. (myDriverDebugHandle.dbg_end)(&myDriverDebugHandle);
  133. }
  134. memset(&myDriverDebugHandle, 0, sizeof(myDriverDebugHandle));
  135. }
  136. void xdi_dbg_xlog(char *x, ...) {
  137. va_list ap;
  138. va_start(ap, x);
  139. if (myDriverDebugHandle.dbg_end &&
  140. (myDriverDebugHandle.dbg_irq || myDriverDebugHandle.dbg_old) &&
  141. (myDriverDebugHandle.dbgMask & DL_STAT)) {
  142. if (myDriverDebugHandle.dbg_irq) {
  143. (*(myDriverDebugHandle.dbg_irq))(myDriverDebugHandle.id,
  144. (x[0] != 0) ? DLI_TRC : DLI_XLOG, x, ap);
  145. } else {
  146. (*(myDriverDebugHandle.dbg_old))(myDriverDebugHandle.id, x, ap);
  147. }
  148. }
  149. va_end(ap);
  150. }
  151. /*****************************************************************************/
  152. #endif /* DIVA_NO_DEBUGLIB */