Add -s flag to microdump_stackwalk for dumping stack contents.

Note that the current MicrodumpProcessor::Process implementation has a
bug due to the fact that it creates a local Microdump instance, and then
holds onto a pointer to the object returned by microdump.GetMemory()
which is destroyed when microdump goes out of scope. This CL fixes the
crash by making Microdump outlive MicrodumpProcessor, which is the same
pattern that Minidump/MinidumpProcessor uses.

Bug: google-breakpad:748
Change-Id: I554b46d309649cf404523722bd9ee39e17a10139
Reviewed-on: https://chromium-review.googlesource.com/720809
Reviewed-by: Primiano Tucci <primiano@chromium.org>
Reviewed-by: Ivan Penkov <ivanpe@chromium.org>
This commit is contained in:
Tobias Sargeant 2017-10-16 10:22:57 +01:00 committed by Tobias Sargeant
parent 623c4a0f42
commit 3d6076efc2
6 changed files with 32 additions and 30 deletions

View file

@ -133,4 +133,3 @@ class Microdump {
} // namespace google_breakpad
#endif // GOOGLE_BREAKPAD_PROCESSOR_MICRODUMP_H__

View file

@ -40,9 +40,10 @@
namespace google_breakpad {
class Microdump;
class ProcessState;
class StackFrameSymbolizer;
class MicrodumpProcessor {
public:
// Initializes the MicrodumpProcessor with a stack frame symbolizer.
@ -52,7 +53,7 @@ class MicrodumpProcessor {
virtual ~MicrodumpProcessor();
// Processes the microdump contents and fills process_state with the result.
google_breakpad::ProcessResult Process(const string& microdump_contents,
google_breakpad::ProcessResult Process(Microdump* microdump,
ProcessState* process_state);
private:
StackFrameSymbolizer* frame_symbolizer_;

View file

@ -394,4 +394,3 @@ Microdump::Microdump(const string& contents)
}
} // namespace google_breakpad

View file

@ -54,24 +54,18 @@ MicrodumpProcessor::MicrodumpProcessor(StackFrameSymbolizer* frame_symbolizer)
MicrodumpProcessor::~MicrodumpProcessor() {}
ProcessResult MicrodumpProcessor::Process(const string &microdump_contents,
ProcessResult MicrodumpProcessor::Process(Microdump *microdump,
ProcessState* process_state) {
assert(process_state);
process_state->Clear();
if (microdump_contents.empty()) {
BPLOG(ERROR) << "Microdump is empty.";
return PROCESS_ERROR_MINIDUMP_NOT_FOUND;
}
Microdump microdump(microdump_contents);
process_state->modules_ = microdump.GetModules()->Copy();
process_state->modules_ = microdump->GetModules()->Copy();
scoped_ptr<Stackwalker> stackwalker(
Stackwalker::StackwalkerForCPU(
&process_state->system_info_,
microdump.GetContext(),
microdump.GetMemory(),
microdump->GetContext(),
microdump->GetMemory(),
process_state->modules_,
/* unloaded_modules= */ NULL,
frame_symbolizer_));
@ -90,12 +84,12 @@ ProcessResult MicrodumpProcessor::Process(const string &microdump_contents,
}
process_state->threads_.push_back(stack.release());
process_state->thread_memory_regions_.push_back(microdump.GetMemory());
process_state->thread_memory_regions_.push_back(microdump->GetMemory());
process_state->crashed_ = true;
process_state->requesting_thread_ = 0;
process_state->system_info_ = *microdump.GetSystemInfo();
process_state->crash_reason_ = microdump.GetCrashReason();
process_state->crash_address_ = microdump.GetCrashAddress();
process_state->system_info_ = *microdump->GetSystemInfo();
process_state->crash_reason_ = microdump->GetCrashReason();
process_state->crash_address_ = microdump->GetCrashAddress();
return PROCESS_OK;
}

View file

@ -37,6 +37,7 @@
#include "breakpad_googletest_includes.h"
#include "google_breakpad/processor/basic_source_line_resolver.h"
#include "google_breakpad/processor/call_stack.h"
#include "google_breakpad/processor/microdump.h"
#include "google_breakpad/processor/microdump_processor.h"
#include "google_breakpad/processor/process_state.h"
#include "google_breakpad/processor/stack_frame.h"
@ -47,6 +48,7 @@
namespace {
using google_breakpad::BasicSourceLineResolver;
using google_breakpad::Microdump;
using google_breakpad::MicrodumpProcessor;
using google_breakpad::ProcessState;
using google_breakpad::SimpleSymbolSupplier;
@ -83,7 +85,8 @@ class MicrodumpProcessorTest : public ::testing::Test {
StackFrameSymbolizer frame_symbolizer(&supplier, &resolver);
MicrodumpProcessor processor(&frame_symbolizer);
return processor.Process(microdump_contents, state);
Microdump microdump(microdump_contents);
return processor.Process(&microdump, state);
}
void AnalyzeDump(const string& microdump_file_name, bool omit_symbols,
@ -109,13 +112,6 @@ class MicrodumpProcessorTest : public ::testing::Test {
string files_path_;
};
TEST_F(MicrodumpProcessorTest, TestProcess_Empty) {
ProcessState state;
google_breakpad::ProcessResult result =
ProcessMicrodump("", "", &state);
ASSERT_EQ(google_breakpad::PROCESS_ERROR_MINIDUMP_NOT_FOUND, result);
}
TEST_F(MicrodumpProcessorTest, TestProcess_Invalid) {
ProcessState state;
google_breakpad::ProcessResult result =

View file

@ -41,6 +41,7 @@
#include "common/scoped_ptr.h"
#include "common/using_std_string.h"
#include "google_breakpad/processor/basic_source_line_resolver.h"
#include "google_breakpad/processor/microdump.h"
#include "google_breakpad/processor/microdump_processor.h"
#include "google_breakpad/processor/process_state.h"
#include "google_breakpad/processor/stack_frame_symbolizer.h"
@ -53,12 +54,14 @@ namespace {
struct Options {
bool machine_readable;
bool output_stack_contents;
string microdump_file;
std::vector<string> symbol_paths;
};
using google_breakpad::BasicSourceLineResolver;
using google_breakpad::Microdump;
using google_breakpad::MicrodumpProcessor;
using google_breakpad::ProcessResult;
using google_breakpad::ProcessState;
@ -81,6 +84,10 @@ int PrintMicrodumpProcess(const Options& options) {
std::vector<char> bytes;
file_stream.seekg(0, std::ios_base::end);
bytes.resize(file_stream.tellg());
if (bytes.empty()) {
BPLOG(ERROR) << "Microdump is empty.";
return 1;
}
file_stream.seekg(0, std::ios_base::beg);
file_stream.read(&bytes[0], bytes.size());
string microdump_content(&bytes[0], bytes.size());
@ -94,14 +101,15 @@ int PrintMicrodumpProcess(const Options& options) {
StackFrameSymbolizer frame_symbolizer(symbol_supplier.get(), &resolver);
ProcessState process_state;
MicrodumpProcessor microdump_processor(&frame_symbolizer);
ProcessResult res = microdump_processor.Process(microdump_content,
Microdump microdump(microdump_content);
ProcessResult res = microdump_processor.Process(&microdump,
&process_state);
if (res == google_breakpad::PROCESS_OK) {
if (options.machine_readable) {
PrintProcessStateMachineReadable(process_state);
} else {
PrintProcessState(process_state, false, &resolver);
PrintProcessState(process_state, options.output_stack_contents, &resolver);
}
return 0;
}
@ -120,7 +128,8 @@ static void Usage(int argc, const char *argv[], bool error) {
"\n"
"Options:\n"
"\n"
" -m Output in machine-readable format\n",
" -m Output in machine-readable format\n"
" -s Output stack contents\n",
basename(argv[0]));
}
@ -128,8 +137,9 @@ static void SetupOptions(int argc, const char *argv[], Options* options) {
int ch;
options->machine_readable = false;
options->output_stack_contents = false;
while ((ch = getopt(argc, (char * const *)argv, "hm")) != -1) {
while ((ch = getopt(argc, (char * const *)argv, "hms")) != -1) {
switch (ch) {
case 'h':
Usage(argc, argv, false);
@ -139,6 +149,9 @@ static void SetupOptions(int argc, const char *argv[], Options* options) {
case 'm':
options->machine_readable = true;
break;
case 's':
options->output_stack_contents = true;
break;
case '?':
Usage(argc, argv, true);