Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(893)

Unified Diff: snapshot/mac/module_snapshot_mac.cc

Issue 649633004: Add ModuleSnapshotMac (Closed) Base URL: https://chromium.googlesource.com/crashpad/crashpad@crashpad_info
Patch Set: Rebase onto master Created 6 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « snapshot/mac/module_snapshot_mac.h ('k') | snapshot/mac/thread_snapshot_mac.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: snapshot/mac/module_snapshot_mac.cc
diff --git a/snapshot/mac/module_snapshot_mac.cc b/snapshot/mac/module_snapshot_mac.cc
new file mode 100644
index 0000000000000000000000000000000000000000..a290908c92b082e8259fa13fa61b7271d5b57633
--- /dev/null
+++ b/snapshot/mac/module_snapshot_mac.cc
@@ -0,0 +1,152 @@
+// Copyright 2014 The Crashpad Authors. All rights reserved.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+#include "snapshot/mac/module_snapshot_mac.h"
+
+#include <mach/mach.h>
+#include <mach-o/loader.h>
+
+#include "base/strings/stringprintf.h"
+#include "snapshot/mac/mach_o_image_annotations_reader.h"
+#include "snapshot/mac/mach_o_image_reader.h"
+#include "util/misc/uuid.h"
+#include "util/stdlib/strnlen.h"
+
+namespace crashpad {
+namespace internal {
+
+ModuleSnapshotMac::ModuleSnapshotMac()
+ : ModuleSnapshot(),
+ name_(),
+ timestamp_(0),
+ mach_o_image_reader_(nullptr),
+ process_reader_(nullptr),
+ initialized_() {
+}
+
+ModuleSnapshotMac::~ModuleSnapshotMac() {
+}
+
+bool ModuleSnapshotMac::Initialize(
+ ProcessReader* process_reader,
+ const ProcessReader::Module& process_reader_module) {
+ INITIALIZATION_STATE_SET_INITIALIZING(initialized_);
+
+ process_reader_ = process_reader;
+ name_ = process_reader_module.name;
+ timestamp_ = process_reader_module.timestamp;
+ mach_o_image_reader_ = process_reader_module.reader;
+ if (!mach_o_image_reader_) {
+ return false;
+ }
+
+ INITIALIZATION_STATE_SET_VALID(initialized_);
+ return true;
+}
+
+std::string ModuleSnapshotMac::Name() const {
+ INITIALIZATION_STATE_DCHECK_VALID(initialized_);
+ return name_;
+}
+
+uint64_t ModuleSnapshotMac::Address() const {
+ INITIALIZATION_STATE_DCHECK_VALID(initialized_);
+ return mach_o_image_reader_->Address();
+}
+
+uint64_t ModuleSnapshotMac::Size() const {
+ INITIALIZATION_STATE_DCHECK_VALID(initialized_);
+ return mach_o_image_reader_->Size();
+}
+
+time_t ModuleSnapshotMac::Timestamp() const {
+ INITIALIZATION_STATE_DCHECK_VALID(initialized_);
+ return timestamp_;
+}
+
+void ModuleSnapshotMac::FileVersion(uint16_t* version_0,
+ uint16_t* version_1,
+ uint16_t* version_2,
+ uint16_t* version_3) const {
+ INITIALIZATION_STATE_DCHECK_VALID(initialized_);
+ if (mach_o_image_reader_->FileType() == MH_DYLIB) {
+ uint32_t dylib_version = mach_o_image_reader_->DylibVersion();
+ *version_0 = (dylib_version & 0xffff0000) >> 16;
+ *version_1 = (dylib_version & 0x0000ff00) >> 8;
+ *version_2 = (dylib_version & 0x000000ff);
+ *version_3 = 0;
+ } else {
+ *version_0 = 0;
+ *version_1 = 0;
+ *version_2 = 0;
+ *version_3 = 0;
+ }
+}
+
+void ModuleSnapshotMac::SourceVersion(uint16_t* version_0,
+ uint16_t* version_1,
+ uint16_t* version_2,
+ uint16_t* version_3) const {
+ INITIALIZATION_STATE_DCHECK_VALID(initialized_);
+
+ // LC_SOURCE_VERSION is supposed to be interpreted as a 5-component version
+ // number, 24 bits for the first component and 10 for the others, per
+ // <mach-o/loader.h>. To preserve the full range of possible version numbers
+ // without data loss, map it to the 4 16-bit fields mandated by the interface
+ // here, which was informed by the minidump file format.
+ uint64_t source_version = mach_o_image_reader_->SourceVersion();
+ *version_0 = (source_version & 0xffff000000000000u) >> 48;
+ *version_1 = (source_version & 0x0000ffff00000000u) >> 32;
+ *version_2 = (source_version & 0x00000000ffff0000u) >> 16;
+ *version_3 = source_version & 0x000000000000ffffu;
+}
+
+ModuleSnapshot::ModuleType ModuleSnapshotMac::GetModuleType() const {
+ INITIALIZATION_STATE_DCHECK_VALID(initialized_);
+
+ uint32_t file_type = mach_o_image_reader_->FileType();
+ switch (file_type) {
+ case MH_EXECUTE:
+ return kModuleTypeExecutable;
+ case MH_DYLIB:
+ return kModuleTypeSharedLibrary;
+ case MH_DYLINKER:
+ return kModuleTypeDynamicLoader;
+ case MH_BUNDLE:
+ return kModuleTypeLoadableModule;
+ default:
+ return kModuleTypeUnknown;
+ }
+}
+
+void ModuleSnapshotMac::UUID(crashpad::UUID* uuid) const {
+ INITIALIZATION_STATE_DCHECK_VALID(initialized_);
+ return mach_o_image_reader_->UUID(uuid);
+}
+
+std::vector<std::string> ModuleSnapshotMac::AnnotationsVector() const {
+ MachOImageAnnotationsReader annotations_reader(
+ process_reader_, mach_o_image_reader_, name_);
+ return annotations_reader.Vector();
+}
+
+std::map<std::string, std::string> ModuleSnapshotMac::AnnotationsSimpleMap()
+ const {
+ MachOImageAnnotationsReader annotations_reader(
+ process_reader_, mach_o_image_reader_, name_);
+ return annotations_reader.SimpleMap();
+}
+
+} // namespace internal
+} // namespace crashpad
« no previous file with comments | « snapshot/mac/module_snapshot_mac.h ('k') | snapshot/mac/thread_snapshot_mac.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698