StackTrace.h 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. /*******************************************************************************
  2. * Copyright (c) 2009, 2014 IBM Corp.
  3. *
  4. * All rights reserved. This program and the accompanying materials
  5. * are made available under the terms of the Eclipse Public License v1.0
  6. * and Eclipse Distribution License v1.0 which accompany this distribution.
  7. *
  8. * The Eclipse Public License is available at
  9. * http://www.eclipse.org/legal/epl-v10.html
  10. * and the Eclipse Distribution License is available at
  11. * http://www.eclipse.org/org/documents/edl-v10.php.
  12. *
  13. * Contributors:
  14. * Ian Craggs - initial API and implementation and/or initial documentation
  15. *******************************************************************************/
  16. #ifndef STACKTRACE_H_
  17. #define STACKTRACE_H_
  18. #include <stdio.h>
  19. #include "Log.h"
  20. #include "Thread.h"
  21. #if defined(NOSTACKTRACE)
  22. #define FUNC_ENTRY
  23. #define FUNC_ENTRY_NOLOG
  24. #define FUNC_ENTRY_MED
  25. #define FUNC_ENTRY_MAX
  26. #define FUNC_EXIT
  27. #define FUNC_EXIT_NOLOG
  28. #define FUNC_EXIT_MED
  29. #define FUNC_EXIT_MAX
  30. #define FUNC_EXIT_RC(x)
  31. #define FUNC_EXIT_MED_RC(x)
  32. #define FUNC_EXIT_MAX_RC(x)
  33. #else
  34. #if defined(WIN32) || defined(WIN64)
  35. #define inline __inline
  36. #define FUNC_ENTRY StackTrace_entry(__FUNCTION__, __LINE__, TRACE_MINIMUM)
  37. #define FUNC_ENTRY_NOLOG StackTrace_entry(__FUNCTION__, __LINE__, -1)
  38. #define FUNC_ENTRY_MED StackTrace_entry(__FUNCTION__, __LINE__, TRACE_MEDIUM)
  39. #define FUNC_ENTRY_MAX StackTrace_entry(__FUNCTION__, __LINE__, TRACE_MAXIMUM)
  40. #define FUNC_EXIT StackTrace_exit(__FUNCTION__, __LINE__, NULL, TRACE_MINIMUM)
  41. #define FUNC_EXIT_NOLOG StackTrace_exit(__FUNCTION__, __LINE__, -1)
  42. #define FUNC_EXIT_MED StackTrace_exit(__FUNCTION__, __LINE__, NULL, TRACE_MEDIUM)
  43. #define FUNC_EXIT_MAX StackTrace_exit(__FUNCTION__, __LINE__, NULL, TRACE_MAXIMUM)
  44. #define FUNC_EXIT_RC(x) StackTrace_exit(__FUNCTION__, __LINE__, &x, TRACE_MINIMUM)
  45. #define FUNC_EXIT_MED_RC(x) StackTrace_exit(__FUNCTION__, __LINE__, &x, TRACE_MEDIUM)
  46. #define FUNC_EXIT_MAX_RC(x) StackTrace_exit(__FUNCTION__, __LINE__, &x, TRACE_MAXIMUM)
  47. #else
  48. #define FUNC_ENTRY StackTrace_entry(__func__, __LINE__, TRACE_MINIMUM)
  49. #define FUNC_ENTRY_NOLOG StackTrace_entry(__func__, __LINE__, -1)
  50. #define FUNC_ENTRY_MED StackTrace_entry(__func__, __LINE__, TRACE_MEDIUM)
  51. #define FUNC_ENTRY_MAX StackTrace_entry(__func__, __LINE__, TRACE_MAXIMUM)
  52. #define FUNC_EXIT StackTrace_exit(__func__, __LINE__, NULL, TRACE_MINIMUM)
  53. #define FUNC_EXIT_NOLOG StackTrace_exit(__func__, __LINE__, NULL, -1)
  54. #define FUNC_EXIT_MED StackTrace_exit(__func__, __LINE__, NULL, TRACE_MEDIUM)
  55. #define FUNC_EXIT_MAX StackTrace_exit(__func__, __LINE__, NULL, TRACE_MAXIMUM)
  56. #define FUNC_EXIT_RC(x) StackTrace_exit(__func__, __LINE__, &x, TRACE_MINIMUM)
  57. #define FUNC_EXIT_MED_RC(x) StackTrace_exit(__func__, __LINE__, &x, TRACE_MEDIUM)
  58. #define FUNC_EXIT_MAX_RC(x) StackTrace_exit(__func__, __LINE__, &x, TRACE_MAXIMUM)
  59. #endif
  60. #endif
  61. void StackTrace_entry(const char* name, int line, enum LOG_LEVELS trace);
  62. void StackTrace_exit(const char* name, int line, void* return_value, enum LOG_LEVELS trace);
  63. void StackTrace_printStack(FILE* dest);
  64. char* StackTrace_get(thread_id_type);
  65. #endif /* STACKTRACE_H_ */