From cbfc7302fb3b5d5c77d2aa7974b26983ce479aa0 Mon Sep 17 00:00:00 2001 From: Christopher Ferris Date: Tue, 5 Nov 2013 11:04:12 -0800 Subject: [PATCH] Add some clarifying defines. In order to be explicit in the Backtrace::Create() calls, adding a couple of defines and some comments to describe what they mean. Change-Id: I6ad08c529791821496a95fa33cea1c95b0a7eada --- include/backtrace/backtrace.h | 8 ++++++++ libbacktrace/Backtrace.cpp | 6 +++--- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/include/backtrace/backtrace.h b/include/backtrace/backtrace.h index b35a6d53a..a83398240 100644 --- a/include/backtrace/backtrace.h +++ b/include/backtrace/backtrace.h @@ -23,6 +23,14 @@ __BEGIN_DECLS +// When the pid to be traced is set to this value, then trace the current +// process. If the tid value is not BACKTRACE_NO_TID, then the specified +// thread from the current process will be traced. +#define BACKTRACE_CURRENT_PROCESS -1 +// When the tid to be traced is set to this value, then trace the specified +// pid. +#define BACKTRACE_NO_TID -1 + #define MAX_BACKTRACE_FRAMES 64 typedef struct backtrace_map_info { diff --git a/libbacktrace/Backtrace.cpp b/libbacktrace/Backtrace.cpp index 17d9e1d90..b22d30114 100644 --- a/libbacktrace/Backtrace.cpp +++ b/libbacktrace/Backtrace.cpp @@ -213,13 +213,13 @@ bool BacktracePtrace::ReadWord(uintptr_t ptr, uint32_t* out_value) { } Backtrace* Backtrace::Create(pid_t pid, pid_t tid) { - if (pid < 0 || pid == getpid()) { - if (tid < 0 || tid == gettid()) { + if (pid == BACKTRACE_CURRENT_PROCESS || pid == getpid()) { + if (tid == BACKTRACE_NO_TID || tid == gettid()) { return CreateCurrentObj(); } else { return CreateThreadObj(tid); } - } else if (tid < 0) { + } else if (tid == BACKTRACE_NO_TID) { return CreatePtraceObj(pid, pid); } else { return CreatePtraceObj(pid, tid);