diff options
author | benchan@chromium.org <benchan@chromium.org@4c0a9323-5329-0410-9bdc-e9ce6186880e> | 2012-02-23 18:50:08 +0000 |
---|---|---|
committer | benchan@chromium.org <benchan@chromium.org@4c0a9323-5329-0410-9bdc-e9ce6186880e> | 2012-02-23 18:50:08 +0000 |
commit | 907f95c5bda4144de54778769b7d51814b32c82a (patch) | |
tree | 6c15328998a67c7bdecc57898ca54ccbded496d8 /src/common/linux/tests/crash_generator.cc | |
parent | Fix an invalid cast in PostfixEvaluator<ValueType>::EvaluateInternal(). (diff) | |
download | breakpad-907f95c5bda4144de54778769b7d51814b32c82a.tar.xz |
Modify CrashGenerator::CreateChildCrash to copy proc files.
This patch is taken from the downstream version of breakpad in
Chromium OS: https://gerrit.chromium.org/gerrit/15148
LinuxCoreDumperTest previously assumes the proc files of the child
process created by CrashGenerator::CreateChildCrash() have the same
content as its parent process, which may not be true. This CL modifies
CrashGenerator to copy the proc files of the child process, created by
CreateChildCrash(), before crashing that process.
BUG=chromium-os:25252
TEST=Verified the following:
TEST=Tested the following:
1. Build on 32-bit and 64-bit Linux with gcc 4.4.3 and gcc 4.6.
2. Build on Mac OS X 10.6.8 with gcc 4.2 and clang 3.0 (with latest gmock).
3. All unit tests pass.
Review URL: https://breakpad.appspot.com/353001
git-svn-id: http://google-breakpad.googlecode.com/svn/trunk@925 4c0a9323-5329-0410-9bdc-e9ce6186880e
Diffstat (limited to 'src/common/linux/tests/crash_generator.cc')
-rw-r--r-- | src/common/linux/tests/crash_generator.cc | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/src/common/linux/tests/crash_generator.cc b/src/common/linux/tests/crash_generator.cc index 7274acf9..dff2bca2 100644 --- a/src/common/linux/tests/crash_generator.cc +++ b/src/common/linux/tests/crash_generator.cc @@ -55,6 +55,12 @@ struct ThreadData { pid_t* thread_id_ptr; }; +const char* const kProcFilesToCopy[] = { + "auxv", "cmdline", "environ", "maps", "status" +}; +const size_t kNumProcFilesToCopy = + sizeof(kProcFilesToCopy) / sizeof(kProcFilesToCopy[0]); + // Core file size limit set to 1 MB, which is big enough for test purposes. const rlim_t kCoreSizeLimit = 1024 * 1024; @@ -95,6 +101,10 @@ std::string CrashGenerator::GetCoreFilePath() const { return temp_dir_.path() + "/core"; } +std::string CrashGenerator::GetDirectoryOfProcFilesCopy() const { + return temp_dir_.path() + "/proc"; +} + pid_t CrashGenerator::GetThreadId(unsigned index) const { return reinterpret_cast<pid_t*>(shared_memory_)[index]; } @@ -160,6 +170,15 @@ bool CrashGenerator::CreateChildCrash( } if (SetCoreFileSizeLimit(kCoreSizeLimit)) { CreateThreadsInChildProcess(num_threads); + std::string proc_dir = GetDirectoryOfProcFilesCopy(); + if (mkdir(proc_dir.c_str(), 0755) == -1) { + perror("CrashGenerator: Failed to create proc directory"); + exit(1); + } + if (!CopyProcFiles(getpid(), proc_dir.c_str())) { + fprintf(stderr, "CrashGenerator: Failed to copy proc files\n"); + exit(1); + } if (kill(*GetThreadIdPointer(crash_thread), crash_signal) == -1) { perror("CrashGenerator: Failed to kill thread by signal"); } @@ -185,6 +204,25 @@ bool CrashGenerator::CreateChildCrash( return true; } +bool CrashGenerator::CopyProcFiles(pid_t pid, const char* path) const { + char from_path[PATH_MAX], to_path[PATH_MAX]; + for (size_t i = 0; i < kNumProcFilesToCopy; ++i) { + int num_chars = snprintf(from_path, PATH_MAX, "/proc/%d/%s", + pid, kProcFilesToCopy[i]); + if (num_chars < 0 || num_chars >= PATH_MAX) + return false; + + num_chars = snprintf(to_path, PATH_MAX, "%s/%s", + path, kProcFilesToCopy[i]); + if (num_chars < 0 || num_chars >= PATH_MAX) + return false; + + if (!CopyFile(from_path, to_path)) + return false; + } + return true; +} + void CrashGenerator::CreateThreadsInChildProcess(unsigned num_threads) { *GetThreadIdPointer(0) = getpid(); |