Launcher_Linux.cpp 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. /*
  2. * Copyright (c) Contributors to the Open 3D Engine Project.
  3. * For complete copyright and license terms please see the LICENSE at the root of this distribution.
  4. *
  5. * SPDX-License-Identifier: Apache-2.0 OR MIT
  6. *
  7. */
  8. #include <Launcher.h>
  9. #include <../Common/UnixLike/Launcher_UnixLike.h>
  10. #include <AzCore/Debug/StackTracer.h>
  11. #include <AzCore/IO/SystemFile.h> // for AZ_MAX_PATH_LEN
  12. #include <AzCore/Math/Vector2.h>
  13. #include <execinfo.h>
  14. #include <libgen.h>
  15. #include <netdb.h>
  16. #include <sys/prctl.h>
  17. #include <sys/resource.h>
  18. #include <sys/types.h>
  19. namespace
  20. {
  21. void SignalHandler(int sig, siginfo_t* info, void* secret)
  22. {
  23. FILE* ftrace = fopen("backtrace.log", "w");
  24. if (!ftrace)
  25. {
  26. ftrace = stderr;
  27. }
  28. AZ::Debug::StackFrame frames[25];
  29. unsigned int frameCount = AZ_ARRAY_SIZE(frames);
  30. frameCount = AZ::Debug::StackRecorder::Record(frames, frameCount);
  31. AZ::Debug::SymbolStorage::StackLine lines[25];
  32. AZ::Debug::SymbolStorage::DecodeFrames(frames, frameCount, lines);
  33. for (unsigned int frame = 0; frame < frameCount; ++frame)
  34. {
  35. fprintf(ftrace, "%s", lines[frame]);
  36. }
  37. if (ftrace != stderr)
  38. {
  39. fclose(ftrace);
  40. }
  41. abort();
  42. }
  43. void InitStackTracer()
  44. {
  45. struct sigaction sa;
  46. sa.sa_sigaction = SignalHandler;
  47. sigemptyset(&sa.sa_mask);
  48. sa.sa_flags = SA_RESTART | SA_SIGINFO;
  49. sigaction(SIGSEGV, &sa, 0);
  50. sigaction(SIGBUS, &sa, 0);
  51. sigaction(SIGILL, &sa, 0);
  52. prctl(PR_SET_DUMPABLE, 1, 0, 0, 0);
  53. }
  54. }
  55. int main(int argc, char** argv)
  56. {
  57. const AZ::Debug::Trace tracer;
  58. bool waitForDebugger = false;
  59. for (int i = 1; i < argc; ++i)
  60. {
  61. if (!strcmp(argv[i], "-wait"))
  62. {
  63. waitForDebugger = true;
  64. break;
  65. }
  66. }
  67. if (waitForDebugger)
  68. {
  69. while(!AZ::Debug::Trace::Instance().IsDebuggerPresent())
  70. {
  71. AZStd::this_thread::sleep_for(AZStd::chrono::milliseconds(50));
  72. }
  73. }
  74. InitStackTracer();
  75. using namespace O3DELauncher;
  76. PlatformMainInfo mainInfo;
  77. mainInfo.m_updateResourceLimits = IncreaseResourceLimits;
  78. bool ret = mainInfo.CopyCommandLine(argc, argv);
  79. // run the Lumberyard application
  80. ReturnCode status = ret ?
  81. Run(mainInfo) :
  82. ReturnCode::ErrCommandLine;
  83. return static_cast<int>(status);
  84. }
  85. void CVar_OnViewportPosition([[maybe_unused]] const AZ::Vector2& value) {}