LibreOffice Module comphelper (master)  1
debuggerinfo.cxx
Go to the documentation of this file.
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3  * This file is part of the LibreOffice project.
4  *
5  * This Source Code Form is subject to the terms of the Mozilla Public
6  * License, v. 2.0. If a copy of the MPL was not distributed with this
7  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8  */
9 
11 
12 #include <cassert>
13 #include <cstring>
14 #include <ctype.h>
15 
16 #if defined(_WIN32)
17 #define WIN32_LEAN_AND_MEAN
18 #include <windows.h>
19 #elif defined UNX
20 #include <unistd.h>
21 #include <fcntl.h>
22 #endif
23 
24 namespace comphelper
25 {
26 #if defined DBG_UTIL
28 {
29 #if defined(_WIN32)
30  return IsDebuggerPresent();
31 #elif defined LINUX
32  char buf[4096];
33  int fd = open("/proc/self/status", O_RDONLY);
34  if (fd < 0)
35  return false;
36  int size = read(fd, buf, sizeof(buf) - 1);
37  close(fd);
38  if (size < 0)
39  return false;
40  assert(size < int(sizeof(buf)) - 1);
41  buf[sizeof(buf) - 1] = '\0';
42  // "TracerPid: <pid>" for pid != 0 means something is attached
43  const char* pos = strstr(buf, "TracerPid:");
44  if (pos == nullptr)
45  return false;
46  pos += strlen("TracerPid:");
47  while (*pos != '\n' && isspace(*pos))
48  ++pos;
49  return *pos != '\n' && *pos != '0';
50 #else
51  return false; // feel free to add your platform
52 #endif
53 }
54 #endif
55 
56 } // namespace comphelper
57 
58 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
const BorderLinePrimitive2D *pCandidateB assert(pCandidateA)
size_t pos
size
bool close
bool isDebuggerAttached()
Returns true if the process is running with a debugger attached.