dRonin  adbada4
dRonin GCS
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Groups Pages
hostosinfo.cpp
Go to the documentation of this file.
1 /**************************************************************************
2 **
3 ** Copyright (C) 2018 dRonin, http://dronin.org
4 ** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
5 ** Contact: http://www.qt-project.org/legal
6 **
7 ** This file is part of Qt Creator.
8 **
9 ** Commercial License Usage
10 ** Licensees holding valid commercial Qt licenses may use this file in
11 ** accordance with the commercial license agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia. For licensing terms and
14 ** conditions see http://qt.digia.com/licensing. For further information
15 ** use the contact form at http://qt.digia.com/contact-us.
16 **
17 ** GNU Lesser General Public License Usage
18 ** Alternatively, this file may be used under the terms of the GNU Lesser
19 ** General Public License version 2.1 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL included in the
21 ** packaging of this file. Please review the following information to
22 ** ensure the GNU Lesser General Public License version 2.1 requirements
23 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
24 **
25 ** In addition, as a special exception, Digia gives you certain additional
26 ** rights. These rights are described in the Digia Qt LGPL Exception
27 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
28 **
29 ****************************************************************************/
30 
31 #include "hostosinfo.h"
32 
33 #include <QDebug>
34 
35 #ifdef Q_OS_WIN
36 #include <windows.h>
37 #endif
38 
39 #ifdef Q_OS_MAC
40 # include <sys/sysctl.h>
41 # include <sys/types.h>
42 # include <unistd.h>
43 #endif
44 
45 using namespace Utils;
46 
48 {
49 #ifdef Q_OS_WIN
50  SYSTEM_INFO info;
51  GetNativeSystemInfo(&info);
52  switch (info.wProcessorArchitecture) {
53  case PROCESSOR_ARCHITECTURE_AMD64:
55  case PROCESSOR_ARCHITECTURE_INTEL:
57  case PROCESSOR_ARCHITECTURE_IA64:
59  case PROCESSOR_ARCHITECTURE_ARM:
61  default:
63  }
64 #else
66 #endif
67 }
68 
70 {
71 #ifdef Q_OS_MAC
72  /*
73  * Based on Apple example "How do I determine if I'm being run under the debugger?"
74  * https://developer.apple.com/library/content/qa/qa1361/_index.html
75  */
76  int mib[4] = {CTL_KERN, KERN_PROC, KERN_PROC_PID, getpid()};
77  struct kinfo_proc info;
78  memset(&info, 0, sizeof(info));
79 
80  // tell sysctl how much it has to play with
81  size_t size = sizeof(info);
82  if (sysctl(mib, sizeof(mib) / sizeof(*mib), &info, &size, NULL, 0) != 0) {
83  qWarning() << "sysctl failed!";
84  return false;
85  }
86 
87  return (info.kp_proc.p_flag & P_TRACED) != 0;
88 #elif defined(Q_OS_WIN)
89  return IsDebuggerPresent();
90 #else
91  qWarning() << "debuggerPresent not implemented!";
92  return false;
93 #endif
94 }
static HostArchitecture hostArchitecture()
Definition: hostosinfo.cpp:47
static bool debuggerPresent()
Is debugger connected to this process?
Definition: hostosinfo.cpp:69