forked from amazingfate/loongoffice
ac9083f64fc064e4bad3dc522a90ca214b3f1c2f "make isDebuggerAttached() public comphelper API" had forgotten to drop the NDEBUG condition, causing --enable-dbgutil --disable-assert-always-abort builds like <https://ci.libreoffice.org//job/lo_tb_random_config_linux/2215/> to fail with > /usr/lib64/gcc/x86_64-suse-linux/9/../../../../x86_64-suse-linux/bin/ld: /lo/home/tdf/lode/jenkins/workspace/lo_tb_random_config_linux/workdir/CxxObject/vcl/source/app/watchdog.o: in function `WatchdogThread::start()': > /lo/home/tdf/lode/jenkins/workspace/lo_tb_random_config_linux/vcl/source/app/watchdog.cxx:138: undefined reference to `comphelper::isDebuggerAttached()' > collect2: error: ld returned 1 exit status > /lo/home/tdf/lode/jenkins/workspace/lo_tb_random_config_linux/vcl/Library_vcl.mk:20: recipe for target '/lo/home/tdf/lode/jenkins/workspace/lo_tb_random_config_linux/instdir/program/libvcllo.so' failed Change-Id: Ia391881f0b6a79709fbebfd204097840a9890147 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/90698 Tested-by: Jenkins Reviewed-by: Stephan Bergmann <sbergman@redhat.com>
59 lines
1.4 KiB
C++
59 lines
1.4 KiB
C++
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
|
/*
|
|
* This file is part of the LibreOffice project.
|
|
*
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
|
*/
|
|
|
|
#include <comphelper/debuggerinfo.hxx>
|
|
|
|
#include <cassert>
|
|
#include <cstring>
|
|
#include <ctype.h>
|
|
|
|
#if defined(_WIN32)
|
|
#define WIN32_LEAN_AND_MEAN
|
|
#include <windows.h>
|
|
#elif defined UNX
|
|
#include <unistd.h>
|
|
#include <fcntl.h>
|
|
#endif
|
|
|
|
namespace comphelper
|
|
{
|
|
#if defined DBG_UTIL
|
|
bool isDebuggerAttached()
|
|
{
|
|
#if defined(_WIN32)
|
|
return IsDebuggerPresent();
|
|
#elif defined LINUX
|
|
char buf[4096];
|
|
int fd = open("/proc/self/status", O_RDONLY);
|
|
if (fd < 0)
|
|
return false;
|
|
int size = read(fd, buf, sizeof(buf) - 1);
|
|
close(fd);
|
|
if (size < 0)
|
|
return false;
|
|
assert(size < int(sizeof(buf)) - 1);
|
|
buf[sizeof(buf) - 1] = '\0';
|
|
// "TracerPid: <pid>" for pid != 0 means something is attached
|
|
const char* pos = strstr(buf, "TracerPid:");
|
|
if (pos == nullptr)
|
|
return false;
|
|
pos += strlen("TracerPid:");
|
|
while (*pos != '\n' && isspace(*pos))
|
|
++pos;
|
|
return *pos != '\n' && *pos != '0';
|
|
#else
|
|
return false; // feel free to add your platform
|
|
#endif
|
|
}
|
|
#endif
|
|
|
|
} // namespace comphelper
|
|
|
|
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|