minidump_descriptor.cc
1 // Copyright 2012 Google LLC 2 // 3 // Redistribution and use in source and binary forms, with or without 4 // modification, are permitted provided that the following conditions are 5 // met: 6 // 7 // * Redistributions of source code must retain the above copyright 8 // notice, this list of conditions and the following disclaimer. 9 // * Redistributions in binary form must reproduce the above 10 // copyright notice, this list of conditions and the following disclaimer 11 // in the documentation and/or other materials provided with the 12 // distribution. 13 // * Neither the name of Google LLC nor the names of its 14 // contributors may be used to endorse or promote products derived from 15 // this software without specific prior written permission. 16 // 17 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 18 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 19 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 20 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 21 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 22 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 23 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 24 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 25 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 29 #ifdef HAVE_CONFIG_H 30 #include <config.h> // Must come first 31 #endif 32 33 #include <stdio.h> 34 35 #include "client/linux/handler/minidump_descriptor.h" 36 37 #include "common/linux/guid_creator.h" 38 39 namespace google_breakpad { 40 41 //static 42 const MinidumpDescriptor::MicrodumpOnConsole 43 MinidumpDescriptor::kMicrodumpOnConsole = {}; 44 45 MinidumpDescriptor::MinidumpDescriptor(const MinidumpDescriptor& descriptor) 46 : mode_(descriptor.mode_), 47 fd_(descriptor.fd_), 48 directory_(descriptor.directory_), 49 c_path_(NULL), 50 size_limit_(descriptor.size_limit_), 51 address_within_principal_mapping_( 52 descriptor.address_within_principal_mapping_), 53 skip_dump_if_principal_mapping_not_referenced_( 54 descriptor.skip_dump_if_principal_mapping_not_referenced_), 55 sanitize_stacks_(descriptor.sanitize_stacks_), 56 microdump_extra_info_(descriptor.microdump_extra_info_) { 57 // The copy constructor is not allowed to be called on a MinidumpDescriptor 58 // with a valid path_, as getting its c_path_ would require the heap which 59 // can cause problems in compromised environments. 60 assert(descriptor.path_.empty()); 61 } 62 63 MinidumpDescriptor& MinidumpDescriptor::operator=( 64 const MinidumpDescriptor& descriptor) { 65 assert(descriptor.path_.empty()); 66 67 mode_ = descriptor.mode_; 68 fd_ = descriptor.fd_; 69 directory_ = descriptor.directory_; 70 path_.clear(); 71 if (c_path_) { 72 // This descriptor already had a path set, so generate a new one. 73 c_path_ = NULL; 74 UpdatePath(); 75 } 76 size_limit_ = descriptor.size_limit_; 77 address_within_principal_mapping_ = 78 descriptor.address_within_principal_mapping_; 79 skip_dump_if_principal_mapping_not_referenced_ = 80 descriptor.skip_dump_if_principal_mapping_not_referenced_; 81 sanitize_stacks_ = descriptor.sanitize_stacks_; 82 microdump_extra_info_ = descriptor.microdump_extra_info_; 83 return *this; 84 } 85 86 void MinidumpDescriptor::UpdatePath() { 87 assert(mode_ == kWriteMinidumpToFile && !directory_.empty()); 88 89 GUID guid; 90 char guid_str[kGUIDStringLength + 1]; 91 if (!CreateGUID(&guid) || !GUIDToString(&guid, guid_str, sizeof(guid_str))) { 92 assert(false); 93 } 94 95 path_.clear(); 96 path_ = directory_ + "/" + guid_str + ".dmp"; 97 c_path_ = path_.c_str(); 98 } 99 100 } // namespace google_breakpad