Commit 5e252e52 authored by Benoît Lizé's avatar Benoît Lizé Committed by Commit Bot

tools: Comment and correctness fixes in dump_process_memory.

It is not necessary to kill the entire process group to dump it, and it is not
required to ptrace() it. Fix the first one, and document why ptrace() may still
be useful.

Reported by bgeffon@google.com.

Bug: 845459
Change-Id: I9f08e7208cfcfdec00bcaf80f83c585f1d4ea195
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1675649Reviewed-by: default avatarEgor Pasko <pasko@chromium.org>
Commit-Queue: Benoit L <lizeb@chromium.org>
Cr-Commit-Position: refs/heads/master@{#672040}
parent 8e2c2eac
...@@ -45,9 +45,8 @@ class ScopedPtracer { ...@@ -45,9 +45,8 @@ class ScopedPtracer {
ScopedPtracer(pid_t pid) : pid_(pid), is_attached_(false) { ScopedPtracer(pid_t pid) : pid_(pid), is_attached_(false) {
// ptrace() delivers a SIGSTOP signal to one thread in the target process, // ptrace() delivers a SIGSTOP signal to one thread in the target process,
// unless it is already stopped. Since we want to stop the whole process, // unless it is already stopped. Since we want to stop the whole process,
// send a signal to every thread in the process group. // kill() it first.
pid_t process_group_id = getpgid(pid); if (kill(pid, SIGSTOP)) {
if (killpg(process_group_id, SIGSTOP)) {
PLOG(ERROR) << "Cannot stop the process group of " << pid; PLOG(ERROR) << "Cannot stop the process group of " << pid;
return; return;
} }
...@@ -206,6 +205,9 @@ bool DumpRegion(const MappedMemoryRegion& region, ...@@ -206,6 +205,9 @@ bool DumpRegion(const MappedMemoryRegion& region,
// disk. // disk.
bool DumpMappings(pid_t pid) { bool DumpMappings(pid_t pid) {
LOG(INFO) << "Attaching to " << pid; LOG(INFO) << "Attaching to " << pid;
// ptrace() is not required to read the process's memory, but the permissions
// to attach to the target process is.
// Attach anyway to make it clearer when this fails.
ScopedPtracer tracer(pid); ScopedPtracer tracer(pid);
if (!tracer.IsAttached()) if (!tracer.IsAttached())
return false; return false;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment