summaryrefslogtreecommitdiffstats
path: root/sandbox/linux/seccomp/debug.h
blob: 4201fbe8136e3d86db991fe6677fac1a6ca83ca2 (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
// 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(int sysnum, const char* msg, 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 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__