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 | #include <stdio.h> |
31 | |
32 | #include "client/linux/handler/minidump_descriptor.h" |
33 | |
34 | #include "common/linux/guid_creator.h" |
35 | |
36 | namespace google_breakpad { |
37 | |
38 | //static |
39 | const MinidumpDescriptor::MicrodumpOnConsole |
40 | MinidumpDescriptor::kMicrodumpOnConsole = {}; |
41 | |
42 | MinidumpDescriptor::MinidumpDescriptor(const MinidumpDescriptor& descriptor) |
43 | : mode_(descriptor.mode_), |
44 | fd_(descriptor.fd_), |
45 | directory_(descriptor.directory_), |
46 | c_path_(NULL), |
47 | size_limit_(descriptor.size_limit_), |
48 | address_within_principal_mapping_( |
49 | descriptor.address_within_principal_mapping_), |
50 | skip_dump_if_principal_mapping_not_referenced_( |
51 | descriptor.skip_dump_if_principal_mapping_not_referenced_), |
52 | sanitize_stacks_(descriptor.sanitize_stacks_), |
53 | microdump_extra_info_(descriptor.microdump_extra_info_) { |
54 | // The copy constructor is not allowed to be called on a MinidumpDescriptor |
55 | // with a valid path_, as getting its c_path_ would require the heap which |
56 | // can cause problems in compromised environments. |
57 | assert(descriptor.path_.empty()); |
58 | } |
59 | |
60 | MinidumpDescriptor& MinidumpDescriptor::operator=( |
61 | const MinidumpDescriptor& descriptor) { |
62 | assert(descriptor.path_.empty()); |
63 | |
64 | mode_ = descriptor.mode_; |
65 | fd_ = descriptor.fd_; |
66 | directory_ = descriptor.directory_; |
67 | path_.clear(); |
68 | if (c_path_) { |
69 | // This descriptor already had a path set, so generate a new one. |
70 | c_path_ = NULL; |
71 | UpdatePath(); |
72 | } |
73 | size_limit_ = descriptor.size_limit_; |
74 | address_within_principal_mapping_ = |
75 | descriptor.address_within_principal_mapping_; |
76 | skip_dump_if_principal_mapping_not_referenced_ = |
77 | descriptor.skip_dump_if_principal_mapping_not_referenced_; |
78 | sanitize_stacks_ = descriptor.sanitize_stacks_; |
79 | microdump_extra_info_ = descriptor.microdump_extra_info_; |
80 | return *this; |
81 | } |
82 | |
83 | void MinidumpDescriptor::UpdatePath() { |
84 | assert(mode_ == kWriteMinidumpToFile && !directory_.empty()); |
85 | |
86 | GUID guid; |
87 | char guid_str[kGUIDStringLength + 1]; |
88 | if (!CreateGUID(&guid) || !GUIDToString(&guid, guid_str, sizeof(guid_str))) { |
89 | assert(false); |
90 | } |
91 | |
92 | path_.clear(); |
93 | path_ = directory_ + "/" + guid_str + ".dmp" ; |
94 | c_path_ = path_.c_str(); |
95 | } |
96 | |
97 | } // namespace google_breakpad |
98 | |