Skip to content

Commit 62ba489

Browse files
Brigid Smithenh-google
authored andcommitted
Changing how debuggerd filters log messages to different locations.
The system by which debuggerd filters its output to different locations is now based on an enum called logtype with easy to understand categories for log messages (like THREAD, MEMORY, etc.) instead of the old, fairly esoteric scope_flags variable. Now much of the output that previously went to logcat does not show up on the screen, but all output can be found in the tombstone file. In addition, the tombstone's location is now printed so it can be located easily. Bug: 15341747 Change-Id: Ia2f2051d1dfdea934d0e6ed220f24345e35ba6a2
1 parent 59d16c9 commit 62ba489

File tree

12 files changed

+263
-261
lines changed

12 files changed

+263
-261
lines changed

debuggerd/arm/machine.cpp

Lines changed: 25 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -40,57 +40,55 @@
4040

4141
// If configured to do so, dump memory around *all* registers
4242
// for the crashing thread.
43-
void dump_memory_and_code(log_t* log, pid_t tid, int scope_flags) {
43+
void dump_memory_and_code(log_t* log, pid_t tid) {
4444
struct pt_regs regs;
4545
if (ptrace(PTRACE_GETREGS, tid, 0, &regs)) {
4646
return;
4747
}
4848

49-
if (IS_AT_FAULT(scope_flags) && DUMP_MEMORY_FOR_ALL_REGISTERS) {
50-
static const char REG_NAMES[] = "r0r1r2r3r4r5r6r7r8r9slfpipsp";
49+
static const char REG_NAMES[] = "r0r1r2r3r4r5r6r7r8r9slfpipsp";
5150

52-
for (int reg = 0; reg < 14; reg++) {
53-
// this may not be a valid way to access, but it'll do for now
54-
uintptr_t addr = regs.uregs[reg];
51+
for (int reg = 0; reg < 14; reg++) {
52+
// this may not be a valid way to access, but it'll do for now
53+
uintptr_t addr = regs.uregs[reg];
5554

56-
// Don't bother if it looks like a small int or ~= null, or if
57-
// it's in the kernel area.
58-
if (addr < 4096 || addr >= 0xc0000000) {
59-
continue;
60-
}
61-
62-
_LOG(log, scope_flags | SCOPE_SENSITIVE, "\nmemory near %.2s:\n", &REG_NAMES[reg * 2]);
63-
dump_memory(log, tid, addr, scope_flags | SCOPE_SENSITIVE);
55+
// Don't bother if it looks like a small int or ~= null, or if
56+
// it's in the kernel area.
57+
if (addr < 4096 || addr >= 0xc0000000) {
58+
continue;
6459
}
60+
61+
_LOG(log, logtype::MEMORY, "\nmemory near %.2s:\n", &REG_NAMES[reg * 2]);
62+
dump_memory(log, tid, addr);
6563
}
6664

6765
// explicitly allow upload of code dump logging
68-
_LOG(log, scope_flags, "\ncode around pc:\n");
69-
dump_memory(log, tid, static_cast<uintptr_t>(regs.ARM_pc), scope_flags);
66+
_LOG(log, logtype::MEMORY, "\ncode around pc:\n");
67+
dump_memory(log, tid, static_cast<uintptr_t>(regs.ARM_pc));
7068

7169
if (regs.ARM_pc != regs.ARM_lr) {
72-
_LOG(log, scope_flags, "\ncode around lr:\n");
73-
dump_memory(log, tid, static_cast<uintptr_t>(regs.ARM_lr), scope_flags);
70+
_LOG(log, logtype::MEMORY, "\ncode around lr:\n");
71+
dump_memory(log, tid, static_cast<uintptr_t>(regs.ARM_lr));
7472
}
7573
}
7674

77-
void dump_registers(log_t* log, pid_t tid, int scope_flags) {
75+
void dump_registers(log_t* log, pid_t tid) {
7876
struct pt_regs r;
7977
if (ptrace(PTRACE_GETREGS, tid, 0, &r)) {
80-
_LOG(log, scope_flags, "cannot get registers: %s\n", strerror(errno));
78+
_LOG(log, logtype::REGISTERS, "cannot get registers: %s\n", strerror(errno));
8179
return;
8280
}
8381

84-
_LOG(log, scope_flags, " r0 %08x r1 %08x r2 %08x r3 %08x\n",
82+
_LOG(log, logtype::REGISTERS, " r0 %08x r1 %08x r2 %08x r3 %08x\n",
8583
static_cast<uint32_t>(r.ARM_r0), static_cast<uint32_t>(r.ARM_r1),
8684
static_cast<uint32_t>(r.ARM_r2), static_cast<uint32_t>(r.ARM_r3));
87-
_LOG(log, scope_flags, " r4 %08x r5 %08x r6 %08x r7 %08x\n",
85+
_LOG(log, logtype::REGISTERS, " r4 %08x r5 %08x r6 %08x r7 %08x\n",
8886
static_cast<uint32_t>(r.ARM_r4), static_cast<uint32_t>(r.ARM_r5),
8987
static_cast<uint32_t>(r.ARM_r6), static_cast<uint32_t>(r.ARM_r7));
90-
_LOG(log, scope_flags, " r8 %08x r9 %08x sl %08x fp %08x\n",
88+
_LOG(log, logtype::REGISTERS, " r8 %08x r9 %08x sl %08x fp %08x\n",
9189
static_cast<uint32_t>(r.ARM_r8), static_cast<uint32_t>(r.ARM_r9),
9290
static_cast<uint32_t>(r.ARM_r10), static_cast<uint32_t>(r.ARM_fp));
93-
_LOG(log, scope_flags, " ip %08x sp %08x lr %08x pc %08x cpsr %08x\n",
91+
_LOG(log, logtype::REGISTERS, " ip %08x sp %08x lr %08x pc %08x cpsr %08x\n",
9492
static_cast<uint32_t>(r.ARM_ip), static_cast<uint32_t>(r.ARM_sp),
9593
static_cast<uint32_t>(r.ARM_lr), static_cast<uint32_t>(r.ARM_pc),
9694
static_cast<uint32_t>(r.ARM_cpsr));
@@ -100,14 +98,14 @@ void dump_registers(log_t* log, pid_t tid, int scope_flags) {
10098
int i;
10199

102100
if (ptrace(PTRACE_GETVFPREGS, tid, 0, &vfp_regs)) {
103-
_LOG(log, scope_flags, "cannot get registers: %s\n", strerror(errno));
101+
_LOG(log, logtype::REGISTERS, "cannot get registers: %s\n", strerror(errno));
104102
return;
105103
}
106104

107105
for (i = 0; i < NUM_VFP_REGS; i += 2) {
108-
_LOG(log, scope_flags, " d%-2d %016llx d%-2d %016llx\n",
106+
_LOG(log, logtype::REGISTERS, " d%-2d %016llx d%-2d %016llx\n",
109107
i, vfp_regs.fpregs[i], i+1, vfp_regs.fpregs[i+1]);
110108
}
111-
_LOG(log, scope_flags, " scr %08lx\n", vfp_regs.fpscr);
109+
_LOG(log, logtype::REGISTERS, " scr %08lx\n", vfp_regs.fpscr);
112110
#endif
113111
}

debuggerd/arm64/machine.cpp

Lines changed: 25 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -37,68 +37,66 @@
3737
* If configured to do so, dump memory around *all* registers
3838
* for the crashing thread.
3939
*/
40-
void dump_memory_and_code(log_t* log, pid_t tid, int scope_flags) {
40+
void dump_memory_and_code(log_t* log, pid_t tid) {
4141
struct user_pt_regs regs;
4242
struct iovec io;
4343
io.iov_base = &regs;
4444
io.iov_len = sizeof(regs);
4545

4646
if (ptrace(PTRACE_GETREGSET, tid, (void*)NT_PRSTATUS, &io) == -1) {
47-
_LOG(log, scope_flags, "%s: ptrace failed to get registers: %s\n",
47+
LOG_ERROR("%s: ptrace failed to get registers: %s\n",
4848
__func__, strerror(errno));
4949
return;
5050
}
5151

52-
if (IS_AT_FAULT(scope_flags) && DUMP_MEMORY_FOR_ALL_REGISTERS) {
53-
for (int reg = 0; reg < 31; reg++) {
54-
uintptr_t addr = regs.regs[reg];
52+
for (int reg = 0; reg < 31; reg++) {
53+
uintptr_t addr = regs.regs[reg];
5554

56-
/*
57-
* Don't bother if it looks like a small int or ~= null, or if
58-
* it's in the kernel area.
59-
*/
60-
if (addr < 4096 || addr >= (1UL<<63)) {
61-
continue;
62-
}
63-
64-
_LOG(log, scope_flags | SCOPE_SENSITIVE, "\nmemory near x%d:\n", reg);
65-
dump_memory(log, tid, addr, scope_flags | SCOPE_SENSITIVE);
55+
/*
56+
* Don't bother if it looks like a small int or ~= null, or if
57+
* it's in the kernel area.
58+
*/
59+
if (addr < 4096 || addr >= (1UL<<63)) {
60+
continue;
6661
}
62+
63+
_LOG(log, logtype::MEMORY, "\nmemory near x%d:\n", reg);
64+
dump_memory(log, tid, addr);
6765
}
6866

69-
_LOG(log, scope_flags, "\ncode around pc:\n");
70-
dump_memory(log, tid, (uintptr_t)regs.pc, scope_flags);
67+
_LOG(log, logtype::MEMORY, "\ncode around pc:\n");
68+
dump_memory(log, tid, (uintptr_t)regs.pc);
7169

7270
if (regs.pc != regs.sp) {
73-
_LOG(log, scope_flags, "\ncode around sp:\n");
74-
dump_memory(log, tid, (uintptr_t)regs.sp, scope_flags);
71+
_LOG(log, logtype::MEMORY, "\ncode around sp:\n");
72+
dump_memory(log, tid, (uintptr_t)regs.sp);
7573
}
7674
}
7775

78-
void dump_registers(log_t* log, pid_t tid, int scope_flags)
79-
{
76+
void dump_registers(log_t* log, pid_t tid) {
8077
struct user_pt_regs r;
8178
struct iovec io;
8279
io.iov_base = &r;
8380
io.iov_len = sizeof(r);
8481

8582
if (ptrace(PTRACE_GETREGSET, tid, (void*) NT_PRSTATUS, (void*) &io) == -1) {
86-
_LOG(log, scope_flags, "ptrace error: %s\n", strerror(errno));
83+
LOG_ERROR("ptrace error: %s\n", strerror(errno));
8784
return;
8885
}
8986

9087
for (int i = 0; i < 28; i += 4) {
91-
_LOG(log, scope_flags, " x%-2d %016lx x%-2d %016lx x%-2d %016lx x%-2d %016lx\n",
88+
_LOG(log, logtype::REGISTERS,
89+
" x%-2d %016lx x%-2d %016lx x%-2d %016lx x%-2d %016lx\n",
9290
i, (uint64_t)r.regs[i],
9391
i+1, (uint64_t)r.regs[i+1],
9492
i+2, (uint64_t)r.regs[i+2],
9593
i+3, (uint64_t)r.regs[i+3]);
9694
}
9795

98-
_LOG(log, scope_flags, " x28 %016lx x29 %016lx x30 %016lx\n",
96+
_LOG(log, logtype::REGISTERS, " x28 %016lx x29 %016lx x30 %016lx\n",
9997
(uint64_t)r.regs[28], (uint64_t)r.regs[29], (uint64_t)r.regs[30]);
10098

101-
_LOG(log, scope_flags, " sp %016lx pc %016lx\n",
99+
_LOG(log, logtype::REGISTERS, " sp %016lx pc %016lx\n",
102100
(uint64_t)r.sp, (uint64_t)r.pc);
103101

104102

@@ -107,12 +105,12 @@ void dump_registers(log_t* log, pid_t tid, int scope_flags)
107105
io.iov_len = sizeof(f);
108106

109107
if (ptrace(PTRACE_GETREGSET, tid, (void*) NT_PRFPREG, (void*) &io) == -1) {
110-
_LOG(log, scope_flags, "ptrace error: %s\n", strerror(errno));
108+
LOG_ERROR("ptrace error: %s\n", strerror(errno));
111109
return;
112110
}
113111

114112
for (int i = 0; i < 32; i += 4) {
115-
_LOG(log, scope_flags, " v%-2d %016lx v%-2d %016lx v%-2d %016lx v%-2d %016lx\n",
113+
_LOG(log, logtype::REGISTERS, " v%-2d %016lx v%-2d %016lx v%-2d %016lx v%-2d %016lx\n",
116114
i, (uint64_t)f.vregs[i],
117115
i+1, (uint64_t)f.vregs[i+1],
118116
i+2, (uint64_t)f.vregs[i+2],

debuggerd/backtrace.cpp

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
#include <UniquePtr.h>
3131

3232
#include "backtrace.h"
33+
3334
#include "utility.h"
3435

3536
static void dump_process_header(log_t* log, pid_t pid) {
@@ -49,15 +50,15 @@ static void dump_process_header(log_t* log, pid_t pid) {
4950
localtime_r(&t, &tm);
5051
char timestr[64];
5152
strftime(timestr, sizeof(timestr), "%F %T", &tm);
52-
_LOG(log, SCOPE_AT_FAULT, "\n\n----- pid %d at %s -----\n", pid, timestr);
53+
_LOG(log, logtype::BACKTRACE, "\n\n----- pid %d at %s -----\n", pid, timestr);
5354

5455
if (procname) {
55-
_LOG(log, SCOPE_AT_FAULT, "Cmd line: %s\n", procname);
56+
_LOG(log, logtype::BACKTRACE, "Cmd line: %s\n", procname);
5657
}
5758
}
5859

5960
static void dump_process_footer(log_t* log, pid_t pid) {
60-
_LOG(log, SCOPE_AT_FAULT, "\n----- end %d -----\n", pid);
61+
_LOG(log, logtype::BACKTRACE, "\n----- end %d -----\n", pid);
6162
}
6263

6364
static void dump_thread(
@@ -79,22 +80,22 @@ static void dump_thread(
7980
}
8081
}
8182

82-
_LOG(log, SCOPE_AT_FAULT, "\n\"%s\" sysTid=%d\n", threadname ? threadname : "<unknown>", tid);
83+
_LOG(log, logtype::BACKTRACE, "\n\"%s\" sysTid=%d\n", threadname ? threadname : "<unknown>", tid);
8384

8485
if (!attached && ptrace(PTRACE_ATTACH, tid, 0, 0) < 0) {
85-
_LOG(log, SCOPE_AT_FAULT, "Could not attach to thread: %s\n", strerror(errno));
86+
_LOG(log, logtype::BACKTRACE, "Could not attach to thread: %s\n", strerror(errno));
8687
return;
8788
}
8889

8990
wait_for_stop(tid, total_sleep_time_usec);
9091

9192
UniquePtr<Backtrace> backtrace(Backtrace::Create(tid, BACKTRACE_CURRENT_THREAD));
9293
if (backtrace->Unwind(0)) {
93-
dump_backtrace_to_log(backtrace.get(), log, SCOPE_AT_FAULT, " ");
94+
dump_backtrace_to_log(backtrace.get(), log, " ");
9495
}
9596

9697
if (!attached && ptrace(PTRACE_DETACH, tid, 0, 0) != 0) {
97-
LOG("ptrace detach from %d failed: %s\n", tid, strerror(errno));
98+
LOG_ERROR("ptrace detach from %d failed: %s\n", tid, strerror(errno));
9899
*detach_failed = true;
99100
}
100101
}
@@ -133,9 +134,8 @@ void dump_backtrace(int fd, int amfd, pid_t pid, pid_t tid, bool* detach_failed,
133134
dump_process_footer(&log, pid);
134135
}
135136

136-
void dump_backtrace_to_log(Backtrace* backtrace, log_t* log,
137-
int scope_flags, const char* prefix) {
137+
void dump_backtrace_to_log(Backtrace* backtrace, log_t* log, const char* prefix) {
138138
for (size_t i = 0; i < backtrace->NumFrames(); i++) {
139-
_LOG(log, scope_flags, "%s%s\n", prefix, backtrace->FormatFrameData(i).c_str());
139+
_LOG(log, logtype::BACKTRACE, "%s%s\n", prefix, backtrace->FormatFrameData(i).c_str());
140140
}
141141
}

debuggerd/backtrace.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ void dump_backtrace(int fd, int amfd, pid_t pid, pid_t tid, bool* detach_failed,
2929
int* total_sleep_time_usec);
3030

3131
/* Dumps the backtrace in the backtrace data structure to the log. */
32-
void dump_backtrace_to_log(Backtrace* backtrace, log_t* log,
33-
int scope_flags, const char* prefix);
32+
void dump_backtrace_to_log(Backtrace* backtrace, log_t* log, const char* prefix);
3433

3534
#endif // _DEBUGGERD_BACKTRACE_H

0 commit comments

Comments
 (0)