You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

func_utils.cc 2.2 kB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. /**
  2. * Copyright 2019 Huawei Technologies Co., Ltd
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. #include "common/func_utils.h"
  17. namespace mindspore {
  18. namespace predict {
  19. #if MS_USE_ARM
  20. _Unwind_Reason_Code PrintTraceArm(_Unwind_Context *ctx, void *d) {
  21. MS_ASSERT(ctx != nullptr);
  22. MS_ASSERT(d != nullptr);
  23. Dl_info info;
  24. int *depth = static_cast<int *>(d);
  25. auto ipAddr = static_cast<int64_t>(_Unwind_GetIP(ctx));
  26. if (dladdr(reinterpret_cast<void *>(ipAddr), &info)) {
  27. const char *symbol = "";
  28. const char *dlfile = "";
  29. if (info.dli_sname) {
  30. symbol = info.dli_sname;
  31. }
  32. if (info.dli_fname) {
  33. dlfile = info.dli_fname;
  34. }
  35. MS_PRINT_ERROR("#%d: (%08lx) %s %s ", *depth, ipAddr, dlfile, symbol);
  36. }
  37. (*depth)++;
  38. return _URC_NO_REASON;
  39. }
  40. #endif
  41. void CoreDumpTraceFunc(int iSignum) {
  42. MS_PRINT_ERROR("----- start get backtrace info -----");
  43. #if MS_USE_ARM
  44. int depth = 0;
  45. _Unwind_Backtrace(&PrintTraceArm, &depth);
  46. #else
  47. const auto maxDeep = 32;
  48. const auto maxStringLen = 100;
  49. void *apBuffer[maxStringLen];
  50. char **ppStrings;
  51. auto iStackDepth = backtrace(apBuffer, maxDeep);
  52. if (0 > iStackDepth) {
  53. KillProcess("Get backtrace depth failed");
  54. return;
  55. }
  56. MS_PRINT_ERROR("Current stack depth is %d", iStackDepth);
  57. ppStrings = backtrace_symbols(apBuffer, iStackDepth);
  58. if (nullptr == ppStrings) {
  59. KillProcess("Get backtrace_symbols failed");
  60. return;
  61. }
  62. for (int iLoop = 0; iLoop < iStackDepth; iLoop++) {
  63. MS_PRINT_ERROR("%s \n", ppStrings[iLoop]);
  64. }
  65. #endif
  66. MS_PRINT_ERROR("----- finish get backtrace info -----");
  67. KillProcess("Exit after core dump");
  68. return; // try exit 1
  69. }
  70. } // namespace predict
  71. } // namespace mindspore