diff --git a/src/command_line.cc b/src/command_line.cc index 5178a6dc..8db61165 100644 --- a/src/command_line.cc +++ b/src/command_line.cc @@ -383,6 +383,8 @@ void LanguageServerMain(const std::string& bin_name, // MAIN //////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////// int main(int argc, char** argv) { + TraceMe(); + std::unordered_map options = ParseOptions(argc, argv); diff --git a/src/platform.h b/src/platform.h index a2c0fd34..bf55128c 100644 --- a/src/platform.h +++ b/src/platform.h @@ -47,4 +47,6 @@ std::vector GetPlatformClangArguments(); void FreeUnusedMemory(); // If true objective-c index tests will be run. -bool RunObjectiveCIndexTests(); \ No newline at end of file +bool RunObjectiveCIndexTests(); + +void TraceMe(); diff --git a/src/platform_posix.cc b/src/platform_posix.cc index a38e7ef1..d0d0c603 100644 --- a/src/platform_posix.cc +++ b/src/platform_posix.cc @@ -37,8 +37,11 @@ #if defined(__FreeBSD__) #include // MAXPATHLEN #include // sysctl +#elif defined(__APPLE__) || defined(__BSD__) +#include #elif defined(__linux__) #include +#include #endif #include @@ -272,4 +275,12 @@ bool RunObjectiveCIndexTests() { #endif } +void TraceMe() { + // If the environment variable is defined, wait for a debugger. + // In gdb, you need to invoke `signal SIGCONT` if you want cquery to continue + // after detaching. + if (getenv("CQUERY_TRACEME")) + raise(SIGTSTP); +} + #endif diff --git a/src/platform_win.cc b/src/platform_win.cc index 88370a58..b61aa0fe 100644 --- a/src/platform_win.cc +++ b/src/platform_win.cc @@ -146,4 +146,8 @@ bool RunObjectiveCIndexTests() { return false; } +// TODO Wait for debugger to attach +void TraceMe() { +} + #endif