Merge "libdebuggerd: cleanup."

This commit is contained in:
Treehugger Robot 2017-09-01 19:45:31 +00:00 committed by Gerrit Code Review
commit 2b8a95a2a7
25 changed files with 51 additions and 94 deletions

View File

@ -47,13 +47,14 @@
#define ATRACE_TAG ATRACE_TAG_BIONIC
#include <utils/Trace.h>
#include "backtrace.h"
#include "tombstone.h"
#include "utility.h"
#include "libdebuggerd/backtrace.h"
#include "libdebuggerd/tombstone.h"
#include "libdebuggerd/utility.h"
#include "debuggerd/handler.h"
#include "protocol.h"
#include "tombstoned/tombstoned.h"
#include "protocol.h"
#include "util.h"
using android::base::unique_fd;

View File

@ -45,8 +45,8 @@
#include "tombstoned/tombstoned.h"
#include "util.h"
#include "backtrace.h"
#include "tombstone.h"
#include "libdebuggerd/backtrace.h"
#include "libdebuggerd/tombstone.h"
using android::base::unique_fd;

View File

@ -17,6 +17,8 @@
#define LOG_TAG "DEBUG"
#include "libdebuggerd/machine.h"
#include <errno.h>
#include <stdint.h>
#include <string.h>
@ -25,8 +27,7 @@
#include <backtrace/Backtrace.h>
#include <log/log.h>
#include "machine.h"
#include "utility.h"
#include "libdebuggerd/utility.h"
void dump_memory_and_code(log_t* log, Backtrace* backtrace) {
pt_regs regs;

View File

@ -17,6 +17,8 @@
#define LOG_TAG "DEBUG"
#include "libdebuggerd/machine.h"
#include <elf.h>
#include <errno.h>
#include <stdint.h>
@ -27,8 +29,7 @@
#include <backtrace/Backtrace.h>
#include <log/log.h>
#include "machine.h"
#include "utility.h"
#include "libdebuggerd/utility.h"
void dump_memory_and_code(log_t* log, Backtrace* backtrace) {
struct user_pt_regs regs;

View File

@ -16,6 +16,8 @@
#define LOG_TAG "DEBUG"
#include "libdebuggerd/backtrace.h"
#include <errno.h>
#include <dirent.h>
#include <limits.h>
@ -34,9 +36,7 @@
#include <backtrace/Backtrace.h>
#include <log/log.h>
#include "backtrace.h"
#include "utility.h"
#include "libdebuggerd/utility.h"
static void dump_process_header(log_t* log, pid_t pid, const char* process_name) {
time_t t = time(NULL);

View File

@ -16,6 +16,8 @@
#define LOG_TAG "DEBUG"
#include "libdebuggerd/elf_utils.h"
#include <elf.h>
#include <stdint.h>
#include <stdlib.h>
@ -27,8 +29,6 @@
#include <backtrace/Backtrace.h>
#include <log/log.h>
#include "elf_utils.h"
#define NOTE_ALIGN(size) (((size) + 3) & ~3)
template <typename HdrType, typename PhdrType, typename NhdrType>

View File

@ -16,6 +16,8 @@
#define LOG_TAG "DEBUG"
#include "libdebuggerd/machine.h"
#include <errno.h>
#include <inttypes.h>
#include <stdint.h>
@ -25,8 +27,7 @@
#include <backtrace/Backtrace.h>
#include <log/log.h>
#include "machine.h"
#include "utility.h"
#include "libdebuggerd/utility.h"
#define R(x) (static_cast<uintptr_t>(x))

View File

@ -16,6 +16,8 @@
#define LOG_TAG "DEBUG"
#include "libdebuggerd/machine.h"
#include <errno.h>
#include <inttypes.h>
#include <stdint.h>
@ -25,8 +27,7 @@
#include <backtrace/Backtrace.h>
#include <log/log.h>
#include "machine.h"
#include "utility.h"
#include "libdebuggerd/utility.h"
#define R(x) (static_cast<uintptr_t>(x))

View File

@ -16,6 +16,8 @@
#define LOG_TAG "DEBUG"
#include "libdebuggerd/open_files_list.h"
#include <dirent.h>
#include <errno.h>
#include <stdio.h>
@ -31,9 +33,7 @@
#include <android-base/file.h>
#include <log/log.h>
#include "open_files_list.h"
#include "utility.h"
#include "libdebuggerd/utility.h"
void populate_open_files_list(pid_t pid, OpenFilesList* list) {
std::string fd_dir_name = "/proc/" + std::to_string(pid) + "/fd";

View File

@ -22,9 +22,10 @@
#include <gtest/gtest.h>
#include <android-base/file.h>
#include "libdebuggerd/utility.h"
#include "BacktraceMock.h"
#include "log_fake.h"
#include "utility.h"
const char g_expected_full_dump[] =
"\nmemory near r1:\n"

View File

@ -14,6 +14,8 @@
* limitations under the License.
*/
#include "elf_fake.h"
#include <stdint.h>
#include <string>

View File

@ -14,6 +14,8 @@
* limitations under the License.
*/
#include "log_fake.h"
#include <errno.h>
#include <stdarg.h>

View File

@ -24,7 +24,7 @@
#include "android-base/test_utils.h"
#include "open_files_list.h"
#include "libdebuggerd/open_files_list.h"
// Check that we can produce a list of open files for the current process, and
// that it includes a known open file.

View File

@ -14,6 +14,8 @@
* limitations under the License.
*/
#include "ptrace_fake.h"
#include <errno.h>
#include <signal.h>
#include <stdarg.h>
@ -21,8 +23,6 @@
#include <string>
#include "ptrace_fake.h"
siginfo_t g_fake_si = {.si_signo = 0};
void ptrace_set_fake_getsiginfo(const siginfo_t& si) {

View File

@ -22,7 +22,7 @@
#include <gtest/gtest.h>
#include <android-base/file.h>
#include "utility.h"
#include "libdebuggerd/utility.h"
#include "BacktraceMock.h"
#include "elf_fake.h"

View File

@ -16,6 +16,8 @@
#define LOG_TAG "DEBUG"
#include "libdebuggerd/tombstone.h"
#include <dirent.h>
#include <errno.h>
#include <fcntl.h>
@ -43,22 +45,18 @@
#include <log/logprint.h>
#include <private/android_filesystem_config.h>
// Needed to get DEBUGGER_SIGNAL.
#include "debuggerd/handler.h"
#include "backtrace.h"
#include "elf_utils.h"
#include "machine.h"
#include "open_files_list.h"
#include "tombstone.h"
#include "libdebuggerd/backtrace.h"
#include "libdebuggerd/elf_utils.h"
#include "libdebuggerd/machine.h"
#include "libdebuggerd/open_files_list.h"
using android::base::StringPrintf;
#define STACK_WORDS 16
#define MAX_TOMBSTONES 10
#define TOMBSTONE_DIR "/data/tombstones"
#define TOMBSTONE_TEMPLATE (TOMBSTONE_DIR"/tombstone_%02d")
static bool signal_has_si_addr(int si_signo, int si_code) {
// Manually sent signals won't have si_addr.
if (si_code == SI_USER || si_code == SI_QUEUE || si_code == SI_TKILL) {
@ -764,59 +762,6 @@ static void dump_crash(log_t* log, BacktraceMap* map, BacktraceMap* map_new,
}
}
// open_tombstone - find an available tombstone slot, if any, of the
// form tombstone_XX where XX is 00 to MAX_TOMBSTONES-1, inclusive. If no
// file is available, we reuse the least-recently-modified file.
int open_tombstone(std::string* out_path) {
// In a single pass, find an available slot and, in case none
// exist, find and record the least-recently-modified file.
char path[128];
int fd = -1;
int oldest = -1;
struct stat oldest_sb;
for (int i = 0; i < MAX_TOMBSTONES; i++) {
snprintf(path, sizeof(path), TOMBSTONE_TEMPLATE, i);
struct stat sb;
if (stat(path, &sb) == 0) {
if (oldest < 0 || sb.st_mtime < oldest_sb.st_mtime) {
oldest = i;
oldest_sb.st_mtime = sb.st_mtime;
}
continue;
}
if (errno != ENOENT) continue;
fd = open(path, O_CREAT | O_EXCL | O_WRONLY | O_NOFOLLOW | O_CLOEXEC, 0600);
if (fd < 0) continue; // raced ?
if (out_path) {
*out_path = path;
}
fchown(fd, AID_SYSTEM, AID_SYSTEM);
return fd;
}
if (oldest < 0) {
ALOGE("debuggerd: failed to find a valid tombstone, default to using tombstone 0.\n");
oldest = 0;
}
// we didn't find an available file, so we clobber the oldest one
snprintf(path, sizeof(path), TOMBSTONE_TEMPLATE, oldest);
fd = open(path, O_CREAT | O_TRUNC | O_WRONLY | O_NOFOLLOW | O_CLOEXEC, 0600);
if (fd < 0) {
ALOGE("debuggerd: failed to open tombstone file '%s': %s\n", path, strerror(errno));
return -1;
}
if (out_path) {
*out_path = path;
}
fchown(fd, AID_SYSTEM, AID_SYSTEM);
return fd;
}
void engrave_tombstone(int tombstone_fd, BacktraceMap* map, BacktraceMap* map_new,
const OpenFilesList* open_files, pid_t pid, pid_t tid,
const std::string& process_name, const std::map<pid_t, std::string>& threads,

View File

@ -16,7 +16,7 @@
#define LOG_TAG "DEBUG"
#include "utility.h"
#include "libdebuggerd/utility.h"
#include <errno.h>
#include <signal.h>

View File

@ -16,6 +16,8 @@
#define LOG_TAG "DEBUG"
#include "libdebuggerd/machine.h"
#include <errno.h>
#include <stdint.h>
#include <string.h>
@ -24,8 +26,7 @@
#include <backtrace/Backtrace.h>
#include <log/log.h>
#include "machine.h"
#include "utility.h"
#include "libdebuggerd/utility.h"
void dump_memory_and_code(log_t* log, Backtrace* backtrace) {
struct pt_regs r;

View File

@ -16,6 +16,8 @@
#define LOG_TAG "DEBUG"
#include "libdebuggerd/machine.h"
#include <errno.h>
#include <stdint.h>
#include <string.h>
@ -25,8 +27,7 @@
#include <backtrace/Backtrace.h>
#include <log/log.h>
#include "machine.h"
#include "utility.h"
#include "libdebuggerd/utility.h"
void dump_memory_and_code(log_t* log, Backtrace* backtrace) {
struct user_regs_struct r;