Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 // A utility for printing the contents of a postmortem stability minidump. | 5 // A utility for printing the contents of a postmortem stability minidump. |
| 6 | 6 |
| 7 #include <windows.h> // NOLINT | 7 #include <windows.h> // NOLINT |
| 8 #include <dbghelp.h> | 8 #include <dbghelp.h> |
| 9 | 9 |
| 10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 26 base::FilePath* minidump_path) { | 26 base::FilePath* minidump_path) { |
| 27 *minidump_path = cmd->GetSwitchValuePath("minidump"); | 27 *minidump_path = cmd->GetSwitchValuePath("minidump"); |
| 28 if (minidump_path->empty()) { | 28 if (minidump_path->empty()) { |
| 29 LOG(ERROR) << "Missing minidump file.\n"; | 29 LOG(ERROR) << "Missing minidump file.\n"; |
| 30 LOG(ERROR) << base::StringPrintf(kUsage, cmd->GetProgram().value().c_str()); | 30 LOG(ERROR) << base::StringPrintf(kUsage, cmd->GetProgram().value().c_str()); |
| 31 return false; | 31 return false; |
| 32 } | 32 } |
| 33 return true; | 33 return true; |
| 34 } | 34 } |
| 35 | 35 |
| 36 void Indent(FILE* out, size_t indent_level) { | 36 void Indent(FILE* out, size_t indent_level) { |
|
bcwhite
2017/01/27 15:16:57
"int" for indent_level is fine and will eliminate
manzagop (departed)
2017/01/27 19:16:42
Done.
| |
| 37 DCHECK(out); | 37 DCHECK(out); |
| 38 for (size_t i = 0; i < indent_level; ++i) | 38 for (size_t i = 0; i < indent_level; ++i) |
| 39 fprintf(out, " "); | 39 fprintf(out, " "); |
| 40 } | 40 } |
| 41 | 41 |
| 42 void PrintUserData( | |
| 43 FILE* out, | |
| 44 size_t indent_level, | |
| 45 const google::protobuf::Map<std::string, browser_watcher::TypedValue>& | |
| 46 user_data) { | |
| 47 DCHECK(out); | |
| 48 Indent(out, indent_level); | |
| 49 fprintf(out, "User data (%zu)\n", user_data.size()); | |
| 50 for (const auto& kv : user_data) { | |
| 51 Indent(out, indent_level + 1); | |
| 52 fprintf(out, "%s : ", kv.first.c_str()); | |
| 53 const browser_watcher::TypedValue& value = kv.second; | |
| 54 switch (kv.second.value_case()) { | |
| 55 case browser_watcher::TypedValue::kBytesValue: { | |
| 56 const std::string& bytes_value = value.bytes_value(); | |
| 57 for (size_t i = 0; i < bytes_value.size(); ++i) | |
| 58 fprintf(out, "%02X", bytes_value.at(i)); | |
|
bcwhite
2017/01/27 15:16:57
perhaps "%02X " (separate bytes with a space?)
manzagop (departed)
2017/01/27 19:16:42
Done.
| |
| 59 fprintf(out, "\n"); | |
| 60 break; | |
| 61 } | |
| 62 case browser_watcher::TypedValue::kBytesReference: | |
| 63 fprintf(out, "bytes reference (address: %llu, size: %lld)\n", | |
|
bcwhite
2017/01/27 15:16:57
Should size be "%llu" as well?
manzagop (departed)
2017/01/27 19:16:42
Hm. The size is stored and analyzed as unsigned, b
bcwhite
2017/01/27 20:03:24
The address could be a problem, given that a rando
manzagop (departed)
2017/01/27 20:15:42
I created https://crbug.com/686187
| |
| 64 value.bytes_reference().address(), | |
| 65 value.bytes_reference().size()); | |
| 66 break; | |
| 67 case browser_watcher::TypedValue::kStringValue: | |
| 68 fprintf(out, "%s\n", value.string_value().c_str()); | |
|
bcwhite
2017/01/27 15:16:57
"\"%s\"\n"
in case there are spaces at the head or
manzagop (departed)
2017/01/27 19:16:42
Done.
| |
| 69 break; | |
| 70 case browser_watcher::TypedValue::kStringReference: | |
| 71 fprintf(out, "string reference (address: %llu, size: %lld)\n", | |
| 72 value.string_reference().address(), | |
| 73 value.string_reference().size()); | |
| 74 break; | |
| 75 case browser_watcher::TypedValue::kCharValue: | |
| 76 fprintf(out, "%s\n", value.char_value().c_str()); | |
|
bcwhite
2017/01/27 15:16:57
"'%s'\n"
manzagop (departed)
2017/01/27 19:16:42
Done.
| |
| 77 break; | |
| 78 case browser_watcher::TypedValue::kBoolValue: | |
| 79 fprintf(out, "%d\n", value.bool_value()); | |
|
bcwhite
2017/01/27 15:16:57
"%s", value.bool_value() ? "true" : "false"
manzagop (departed)
2017/01/27 19:16:42
Done.
| |
| 80 break; | |
| 81 case browser_watcher::TypedValue::kSignedValue: | |
| 82 fprintf(out, "%lld\n", value.signed_value()); | |
| 83 break; | |
| 84 case browser_watcher::TypedValue::kUnsignedValue: | |
| 85 fprintf(out, "%llu\n", value.unsigned_value()); | |
| 86 break; | |
| 87 case browser_watcher::TypedValue::VALUE_NOT_SET: | |
| 88 fprintf(out, "<not set>\n"); | |
| 89 break; | |
| 90 } | |
| 91 } | |
| 92 } | |
| 93 | |
| 42 void PrintActivity(FILE* out, | 94 void PrintActivity(FILE* out, |
| 43 size_t indent_level, | 95 size_t indent_level, |
| 44 const browser_watcher::Activity& activity) { | 96 const browser_watcher::Activity& activity) { |
| 45 DCHECK(out); | 97 DCHECK(out); |
| 46 Indent(out, indent_level); | 98 Indent(out, indent_level); |
| 47 fprintf(out, "Activity\n"); | 99 fprintf(out, "Activity\n"); |
| 48 Indent(out, indent_level + 1); | 100 Indent(out, indent_level + 1); |
| 49 fprintf(out, "type: %d\n", activity.type()); | 101 fprintf(out, "type: %d\n", activity.type()); |
| 50 Indent(out, indent_level + 1); | 102 Indent(out, indent_level + 1); |
| 51 fprintf(out, "time: %lld\n", activity.time()); | 103 fprintf(out, "time: %lld\n", activity.time()); |
| 52 switch (activity.type()) { | 104 switch (activity.type()) { |
| 53 case browser_watcher::Activity::UNKNOWN: | 105 case browser_watcher::Activity::UNKNOWN: |
| 54 break; | 106 break; |
| 55 case browser_watcher::Activity::ACT_TASK_RUN: | 107 case browser_watcher::Activity::ACT_TASK_RUN: |
| 56 Indent(out, indent_level + 1); | 108 Indent(out, indent_level + 1); |
| 57 fprintf(out, "origin_address: %llx\n", activity.origin_address()); | 109 fprintf(out, "origin_address: %llx\n", activity.origin_address()); |
| 58 fprintf(out, "task_sequence_id: %lld\n", activity.task_sequence_id()); | 110 fprintf(out, "task_sequence_id: %lld\n", activity.task_sequence_id()); |
| 59 break; | 111 break; |
| 60 case browser_watcher::Activity::ACT_LOCK_ACQUIRE: | 112 case browser_watcher::Activity::ACT_LOCK_ACQUIRE: |
| 61 Indent(out, indent_level + 1); | 113 Indent(out, indent_level + 1); |
| 62 fprintf(out, "lock_address: %llx\n", activity.lock_address()); | 114 fprintf(out, "lock_address: %llx\n", activity.lock_address()); |
| 63 break; | 115 break; |
| 64 case browser_watcher::Activity::ACT_EVENT_WAIT: | 116 case browser_watcher::Activity::ACT_EVENT_WAIT: |
| 65 Indent(out, indent_level + 1); | 117 Indent(out, indent_level + 1); |
| 66 fprintf(out, "event_address: %llx\n", activity.event_address()); | 118 fprintf(out, "event_address: %llx\n", activity.event_address()); |
| 67 break; | 119 break; |
| 68 case browser_watcher::Activity::ACT_THREAD_JOIN: | 120 case browser_watcher::Activity::ACT_THREAD_JOIN: |
| 69 Indent(out, indent_level + 1); | 121 Indent(out, indent_level + 1); |
| 70 fprintf(out, "thread_id: %lld\n", activity.thread_id()); | 122 fprintf(out, "thread_id: %lld\n", activity.thread_id()); |
|
bcwhite
2017/01/27 15:16:57
Should you display these in hex?
manzagop (departed)
2017/01/27 19:16:42
I believe they're most commonly seen in decimal.
| |
| 71 break; | 123 break; |
| 72 case browser_watcher::Activity::ACT_PROCESS_WAIT: | 124 case browser_watcher::Activity::ACT_PROCESS_WAIT: |
| 73 Indent(out, indent_level + 1); | 125 Indent(out, indent_level + 1); |
| 74 fprintf(out, "process_id: %lld\n", activity.process_id()); | 126 fprintf(out, "process_id: %lld\n", activity.process_id()); |
| 75 break; | 127 break; |
| 76 } | 128 } |
| 129 | |
| 130 PrintUserData(out, indent_level + 1, activity.user_data()); | |
| 77 } | 131 } |
| 78 | 132 |
| 79 void PrintProcessState(FILE* out, | 133 void PrintProcessState(FILE* out, |
| 80 const browser_watcher::ProcessState& process) { | 134 const browser_watcher::ProcessState& process) { |
| 81 fprintf(out, "Process %lld (%d threads)\n", process.process_id(), | 135 fprintf(out, "Process %lld (%d threads)\n", process.process_id(), |
| 82 process.threads_size()); | 136 process.threads_size()); |
| 83 for (const browser_watcher::ThreadState& thread : process.threads()) { | 137 for (const browser_watcher::ThreadState& thread : process.threads()) { |
| 84 fprintf(out, "Thread %lld (%s) : %d activities\n", thread.thread_id(), | 138 fprintf(out, "Thread %lld (%s) : %d activities\n", thread.thread_id(), |
| 85 thread.thread_name().c_str(), thread.activity_count()); | 139 thread.thread_name().c_str(), thread.activity_count()); |
| 86 for (const browser_watcher::Activity& activity : thread.activities()) | 140 for (const browser_watcher::Activity& activity : thread.activities()) |
| 87 PrintActivity(out, 1, activity); | 141 PrintActivity(out, 1, activity); |
| 88 } | 142 } |
| 89 } | 143 } |
| 90 | 144 |
| 91 // TODO(manzagop): flesh out as StabilityReport gets fleshed out. | 145 // TODO(manzagop): flesh out as StabilityReport gets fleshed out. |
| 92 void PrintReport(FILE* out, const browser_watcher::StabilityReport& report) { | 146 void PrintReport(FILE* out, const browser_watcher::StabilityReport& report) { |
| 147 PrintUserData(out, 0U, report.global_data()); | |
| 93 for (int i = 0; i < report.process_states_size(); ++i) { | 148 for (int i = 0; i < report.process_states_size(); ++i) { |
| 94 const browser_watcher::ProcessState process = report.process_states(i); | 149 const browser_watcher::ProcessState process = report.process_states(i); |
| 95 PrintProcessState(out, process); | 150 PrintProcessState(out, process); |
| 96 } | 151 } |
| 97 } | 152 } |
| 98 | 153 |
| 99 int Main(int argc, char** argv) { | 154 int Main(int argc, char** argv) { |
| 100 base::CommandLine::Init(argc, argv); | 155 base::CommandLine::Init(argc, argv); |
| 101 | 156 |
| 102 // Get the dump. | 157 // Get the dump. |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 142 PrintReport(stdout, report); | 197 PrintReport(stdout, report); |
| 143 | 198 |
| 144 return 0; | 199 return 0; |
| 145 } | 200 } |
| 146 | 201 |
| 147 } // namespace | 202 } // namespace |
| 148 | 203 |
| 149 int main(int argc, char** argv) { | 204 int main(int argc, char** argv) { |
| 150 return Main(argc, argv); | 205 return Main(argc, argv); |
| 151 } | 206 } |
| OLD | NEW |