Issue 276 - generate GUIDs ahead of time in Linux handler. r=Liu Li

git-svn-id: http://google-breakpad.googlecode.com/svn/trunk@290 4c0a9323-5329-0410-9bdc-e9ce6186880e
This commit is contained in:
ted.mielczarek 2008-10-14 11:21:34 +00:00
parent 1de70760db
commit c5f46b2f4b
2 changed files with 55 additions and 29 deletions

View file

@ -118,7 +118,9 @@ ExceptionHandler::~ExceptionHandler() {
} }
bool ExceptionHandler::WriteMinidump() { bool ExceptionHandler::WriteMinidump() {
return InternalWriteMinidump(0, 0, NULL); bool success = InternalWriteMinidump(0, 0, NULL);
UpdateNextID();
return success;
} }
// static // static
@ -226,15 +228,7 @@ bool ExceptionHandler::InternalWriteMinidump(int signo,
if (filter_ && !filter_(callback_context_)) if (filter_ && !filter_(callback_context_))
return false; return false;
GUID guid; bool success = false;
bool success = false;;
char guid_str[kGUIDStringLength + 1];
if (CreateGUID(&guid) && GUIDToString(&guid, guid_str, sizeof(guid_str))) {
char minidump_path[PATH_MAX];
snprintf(minidump_path, sizeof(minidump_path), "%s/%s.dmp",
dump_path_c_,
guid_str);
// Block all the signals we want to process when writting minidump. // Block all the signals we want to process when writting minidump.
// We don't want it to be interrupted. // We don't want it to be interrupted.
sigset_t sig_blocked, sig_old; sigset_t sig_blocked, sig_old;
@ -249,7 +243,7 @@ bool ExceptionHandler::InternalWriteMinidump(int signo,
} }
success = minidump_generator_.WriteMinidumpToFile( success = minidump_generator_.WriteMinidumpToFile(
minidump_path, signo, sighandler_ebp, sig_ctx); next_minidump_path_c_, signo, sighandler_ebp, sig_ctx);
// Unblock the signals. // Unblock the signals.
if (blocked) { if (blocked) {
@ -257,10 +251,26 @@ bool ExceptionHandler::InternalWriteMinidump(int signo,
} }
if (callback_) if (callback_)
success = callback_(dump_path_c_, guid_str, success = callback_(dump_path_c_, next_minidump_id_c_,
callback_context_, success); callback_context_, success);
}
return success; return success;
} }
void ExceptionHandler::UpdateNextID() {
GUID guid;
char guid_str[kGUIDStringLength + 1];
if (CreateGUID(&guid) && GUIDToString(&guid, guid_str, sizeof(guid_str))) {
next_minidump_id_ = guid_str;
next_minidump_id_c_ = next_minidump_id_.c_str();
char minidump_path[PATH_MAX];
snprintf(minidump_path, sizeof(minidump_path), "%s/%s.dmp",
dump_path_c_,
guid_str);
next_minidump_path_ = minidump_path;
next_minidump_path_c_ = next_minidump_path_.c_str();
}
}
} // namespace google_breakpad } // namespace google_breakpad

View file

@ -126,6 +126,7 @@ class ExceptionHandler {
void set_dump_path(const string &dump_path) { void set_dump_path(const string &dump_path) {
dump_path_ = dump_path; dump_path_ = dump_path;
dump_path_c_ = dump_path_.c_str(); dump_path_c_ = dump_path_.c_str();
UpdateNextID();
} }
// Writes a minidump immediately. This can be used to capture the // Writes a minidump immediately. This can be used to capture the
@ -160,6 +161,10 @@ class ExceptionHandler {
bool InternalWriteMinidump(int signo, uintptr_t sighandler_ebp, bool InternalWriteMinidump(int signo, uintptr_t sighandler_ebp,
struct sigcontext **sig_ctx); struct sigcontext **sig_ctx);
// Generates a new ID and stores it in next_minidump_id, and stores the
// path of the next minidump to be written in next_minidump_path_.
void UpdateNextID();
private: private:
FilterCallback filter_; FilterCallback filter_;
MinidumpCallback callback_; MinidumpCallback callback_;
@ -168,9 +173,20 @@ class ExceptionHandler {
// The directory in which a minidump will be written, set by the dump_path // The directory in which a minidump will be written, set by the dump_path
// argument to the constructor, or set_dump_path. // argument to the constructor, or set_dump_path.
string dump_path_; string dump_path_;
// C style dump path. Keep this when setting dump path, since calling
// c_str() of std::string when crashing may not be safe. // The basename of the next minidump to be written, without the extension
string next_minidump_id_;
// The full pathname of the next minidump to be written, including the file
// extension
string next_minidump_path_;
// Pointers to C-string representations of the above. These are set
// when the above are set so we can avoid calling c_str during
// an exception.
const char *dump_path_c_; const char *dump_path_c_;
const char *next_minidump_id_c_;
const char *next_minidump_path_c_;
// True if the ExceptionHandler installed an unhandled exception filter // True if the ExceptionHandler installed an unhandled exception filter
// when created (with an install_handler parameter set to true). // when created (with an install_handler parameter set to true).