summaryrefslogtreecommitdiffstats
path: root/sandbox/linux/seccomp/debug.h
blob: eb5a194e086749b67fd45b8356e17dc8e97ce8c3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
// Copyright (c) 2010 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef DEBUG_H__
#define DEBUG_H__

#include <map>
#include <stdio.h>
#include <stdlib.h>
#include <string>
#include <string.h>

#include "sandbox_impl.h"

namespace playground {

class Debug {
 public:
  // If debugging is enabled, write a message to stderr.
  static void message(const char* msg)
  #ifndef NDEBUG
  asm("playground$debugMessage")
  #if defined(__x86_64__)
  __attribute__((visibility("internal")))
  #endif
  ;
  #else
  { }
  #endif

  // If debugging is enabled, write the name of the syscall and an optional
  // message to stderr.
  static void syscall(long long* tm, int sysnum,
                      const char* msg, int call = -1)
  #ifndef NDEBUG
  ;
  #else
  { }
  #endif

  // Print how much wall-time has elapsed since the last call to syscall()
  static void elapsed(long long tm, int sysnum, int call = -1)
  #ifndef NDEBUG
  ;
  #else
  {
  }
  #endif

  // Check whether debugging is enabled.
  static bool isEnabled() {
    #ifndef NDEBUG
    return enabled_;
    #else
    return false;
    #endif
  }

 private:
  #ifndef NDEBUG
  Debug();
  static bool  enter();
  static bool  leave();
  static void  _message(const char* msg);
  static void  gettimeofday(long long* tm);
  static char* itoa(char* s, int n);

  static Debug debug_;

  static bool  enabled_;
  static int   numSyscallNames_;
  static const char **syscallNames_;
  static std::map<int, std::string> syscallNamesMap_;
  #endif
};

} // namespace

#endif // DEBUG_H__