LCOV - code coverage report
Current view: top level - toolkit/crashreporter/breakpad-client/linux/handler - minidump_descriptor.h (source / functions) Hit Total Coverage
Test: output.info Lines: 0 16 0.0 %
Date: 2017-07-14 16:53:18 Functions: 0 9 0.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : // Copyright (c) 2012 Google Inc.
       2             : // All rights reserved.
       3             : //
       4             : // Redistribution and use in source and binary forms, with or without
       5             : // modification, are permitted provided that the following conditions are
       6             : // met:
       7             : //
       8             : //     * Redistributions of source code must retain the above copyright
       9             : // notice, this list of conditions and the following disclaimer.
      10             : //     * Redistributions in binary form must reproduce the above
      11             : // copyright notice, this list of conditions and the following disclaimer
      12             : // in the documentation and/or other materials provided with the
      13             : // distribution.
      14             : //     * Neither the name of Google Inc. nor the names of its
      15             : // contributors may be used to endorse or promote products derived from
      16             : // this software without specific prior written permission.
      17             : //
      18             : // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
      19             : // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
      20             : // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
      21             : // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
      22             : // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
      23             : // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
      24             : // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
      25             : // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
      26             : // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
      27             : // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
      28             : // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
      29             : 
      30             : #ifndef CLIENT_LINUX_HANDLER_MINIDUMP_DESCRIPTOR_H_
      31             : #define CLIENT_LINUX_HANDLER_MINIDUMP_DESCRIPTOR_H_
      32             : 
      33             : #include <assert.h>
      34             : #include <sys/types.h>
      35             : 
      36             : #include <string>
      37             : 
      38             : #include "linux/handler/microdump_extra_info.h"
      39             : #include "common/using_std_string.h"
      40             : 
      41             : // This class describes how a crash dump should be generated, either:
      42             : // - Writing a full minidump to a file in a given directory (the actual path,
      43             : //   inside the directory, is determined by this class).
      44             : // - Writing a full minidump to a given fd.
      45             : // - Writing a reduced microdump to the console (logcat on Android).
      46             : namespace google_breakpad {
      47             : 
      48           0 : class MinidumpDescriptor {
      49             :  public:
      50             :   struct MicrodumpOnConsole {};
      51             :   static const MicrodumpOnConsole kMicrodumpOnConsole;
      52             : 
      53             :   MinidumpDescriptor()
      54             :       : mode_(kUninitialized),
      55             :         fd_(-1),
      56             :         size_limit_(-1) {}
      57             : 
      58           0 :   explicit MinidumpDescriptor(const string& directory)
      59           0 :       : mode_(kWriteMinidumpToFile),
      60             :         fd_(-1),
      61             :         directory_(directory),
      62             :         c_path_(NULL),
      63           0 :         size_limit_(-1) {
      64           0 :     assert(!directory.empty());
      65           0 :   }
      66             : 
      67             :   explicit MinidumpDescriptor(int fd)
      68             :       : mode_(kWriteMinidumpToFd),
      69             :         fd_(fd),
      70             :         c_path_(NULL),
      71             :         size_limit_(-1) {
      72             :     assert(fd != -1);
      73             :   }
      74             : 
      75             :   explicit MinidumpDescriptor(const MicrodumpOnConsole&)
      76             :       : mode_(kWriteMicrodumpToConsole),
      77             :         fd_(-1),
      78             :         size_limit_(-1) {}
      79             : 
      80             :   explicit MinidumpDescriptor(const MinidumpDescriptor& descriptor);
      81             :   MinidumpDescriptor& operator=(const MinidumpDescriptor& descriptor);
      82             : 
      83             :   static MinidumpDescriptor getMicrodumpDescriptor();
      84             : 
      85           0 :   bool IsFD() const { return mode_ == kWriteMinidumpToFd; }
      86             : 
      87           0 :   int fd() const { return fd_; }
      88             : 
      89           0 :   string directory() const { return directory_; }
      90             : 
      91           0 :   const char* path() const { return c_path_; }
      92             : 
      93           0 :   bool IsMicrodumpOnConsole() const {
      94           0 :     return mode_ == kWriteMicrodumpToConsole;
      95             :   }
      96             : 
      97             :   // Updates the path so it is unique.
      98             :   // Should be called from a normal context: this methods uses the heap.
      99             :   void UpdatePath();
     100             : 
     101           0 :   off_t size_limit() const { return size_limit_; }
     102             :   void set_size_limit(off_t limit) { size_limit_ = limit; }
     103             : 
     104           0 :   MicrodumpExtraInfo* microdump_extra_info() {
     105           0 :     assert(IsMicrodumpOnConsole());
     106           0 :     return &microdump_extra_info_;
     107             :   };
     108             : 
     109             :  private:
     110             :   enum DumpMode {
     111             :     kUninitialized = 0,
     112             :     kWriteMinidumpToFile,
     113             :     kWriteMinidumpToFd,
     114             :     kWriteMicrodumpToConsole
     115             :   };
     116             : 
     117             :   // Specifies the dump mode (see DumpMode).
     118             :   DumpMode mode_;
     119             : 
     120             :   // The file descriptor where the minidump is generated.
     121             :   int fd_;
     122             : 
     123             :   // The directory where the minidump should be generated.
     124             :   string directory_;
     125             : 
     126             :   // The full path to the generated minidump.
     127             :   string path_;
     128             : 
     129             :   // The C string of |path_|. Precomputed so it can be access from a compromised
     130             :   // context.
     131             :   const char* c_path_;
     132             : 
     133             :   off_t size_limit_;
     134             : 
     135             :   // The extra microdump data (e.g. product name/version, build
     136             :   // fingerprint, gpu fingerprint) that should be appended to the dump
     137             :   // (microdump only). Microdumps don't have the ability of appending
     138             :   // extra metadata after the dump is generated (as opposite to
     139             :   // minidumps MIME fields), therefore the extra data must be provided
     140             :   // upfront. Any memory pointed to by members of the
     141             :   // MicrodumpExtraInfo struct must be valid for the lifetime of the
     142             :   // process (read: the caller has to guarantee that it is stored in
     143             :   // global static storage.)
     144             :   MicrodumpExtraInfo microdump_extra_info_;
     145             : };
     146             : 
     147             : }  // namespace google_breakpad
     148             : 
     149             : #endif  // CLIENT_LINUX_HANDLER_MINIDUMP_DESCRIPTOR_H_

Generated by: LCOV version 1.13