Remove assert, use CHECK instead.
- Use the CHECK macro everywhere that assert was used. - Remove the _debug version of the tests and leave the CHECK macro so it's always checking in the code. Bug: 23762183 Test: Ran unit tests. Change-Id: Ie705eedae393d0e95bb9d99f852687a11881aef1
This commit is contained in:
parent
51b4f48280
commit
9416703f5b
|
@ -76,17 +76,6 @@ cc_library {
|
|||
defaults: ["libunwindstack_common"],
|
||||
}
|
||||
|
||||
cc_library {
|
||||
name: "libunwindstack_debug",
|
||||
defaults: ["libunwindstack_common"],
|
||||
|
||||
cflags: [
|
||||
"-UNDEBUG",
|
||||
"-O0",
|
||||
"-g",
|
||||
],
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
// Unit Tests
|
||||
//-------------------------------------------------------------------------
|
||||
|
@ -160,21 +149,6 @@ cc_test {
|
|||
],
|
||||
}
|
||||
|
||||
// These unit tests run against the static debug library.
|
||||
cc_test {
|
||||
name: "libunwindstack_test_debug",
|
||||
defaults: ["libunwindstack_test_common"],
|
||||
|
||||
static_libs: [
|
||||
"libunwindstack_debug",
|
||||
],
|
||||
|
||||
data: [
|
||||
"tests/elf32.xz",
|
||||
"tests/elf64.xz",
|
||||
],
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
// Utility Executables
|
||||
//-------------------------------------------------------------------------
|
||||
|
|
|
@ -14,7 +14,6 @@
|
|||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include <assert.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#include <deque>
|
||||
|
@ -23,6 +22,7 @@
|
|||
#include <android-base/stringprintf.h>
|
||||
|
||||
#include "ArmExidx.h"
|
||||
#include "Check.h"
|
||||
#include "Log.h"
|
||||
#include "Machine.h"
|
||||
#include "Memory.h"
|
||||
|
@ -173,7 +173,7 @@ inline bool ArmExidx::GetByte(uint8_t* byte) {
|
|||
}
|
||||
|
||||
inline bool ArmExidx::DecodePrefix_10_00(uint8_t byte) {
|
||||
assert((byte >> 4) == 0x8);
|
||||
CHECK((byte >> 4) == 0x8);
|
||||
|
||||
uint16_t registers = (byte & 0xf) << 8;
|
||||
if (!GetByte(&byte)) {
|
||||
|
@ -232,7 +232,7 @@ inline bool ArmExidx::DecodePrefix_10_00(uint8_t byte) {
|
|||
}
|
||||
|
||||
inline bool ArmExidx::DecodePrefix_10_01(uint8_t byte) {
|
||||
assert((byte >> 4) == 0x9);
|
||||
CHECK((byte >> 4) == 0x9);
|
||||
|
||||
uint8_t bits = byte & 0xf;
|
||||
if (bits == 13 || bits == 15) {
|
||||
|
@ -258,7 +258,7 @@ inline bool ArmExidx::DecodePrefix_10_01(uint8_t byte) {
|
|||
}
|
||||
|
||||
inline bool ArmExidx::DecodePrefix_10_10(uint8_t byte) {
|
||||
assert((byte >> 4) == 0xa);
|
||||
CHECK((byte >> 4) == 0xa);
|
||||
|
||||
// 10100nnn: Pop r4-r[4+nnn]
|
||||
// 10101nnn: Pop r4-r[4+nnn], r14
|
||||
|
@ -419,7 +419,7 @@ inline bool ArmExidx::DecodePrefix_10_11_01nn() {
|
|||
}
|
||||
|
||||
inline bool ArmExidx::DecodePrefix_10_11_1nnn(uint8_t byte) {
|
||||
assert((byte & ~0x07) == 0xb8);
|
||||
CHECK((byte & ~0x07) == 0xb8);
|
||||
|
||||
// 10111nnn: Pop VFP double-precision registers D[8]-D[8+nnn] by FSTMFDX
|
||||
if (log_) {
|
||||
|
@ -439,7 +439,7 @@ inline bool ArmExidx::DecodePrefix_10_11_1nnn(uint8_t byte) {
|
|||
}
|
||||
|
||||
inline bool ArmExidx::DecodePrefix_10(uint8_t byte) {
|
||||
assert((byte >> 6) == 0x2);
|
||||
CHECK((byte >> 6) == 0x2);
|
||||
|
||||
switch ((byte >> 4) & 0x3) {
|
||||
case 0:
|
||||
|
@ -469,7 +469,7 @@ inline bool ArmExidx::DecodePrefix_10(uint8_t byte) {
|
|||
}
|
||||
|
||||
inline bool ArmExidx::DecodePrefix_11_000(uint8_t byte) {
|
||||
assert((byte & ~0x07) == 0xc0);
|
||||
CHECK((byte & ~0x07) == 0xc0);
|
||||
|
||||
uint8_t bits = byte & 0x7;
|
||||
if (bits == 6) {
|
||||
|
@ -550,7 +550,7 @@ inline bool ArmExidx::DecodePrefix_11_000(uint8_t byte) {
|
|||
}
|
||||
|
||||
inline bool ArmExidx::DecodePrefix_11_001(uint8_t byte) {
|
||||
assert((byte & ~0x07) == 0xc8);
|
||||
CHECK((byte & ~0x07) == 0xc8);
|
||||
|
||||
uint8_t bits = byte & 0x7;
|
||||
if (bits == 0) {
|
||||
|
@ -605,7 +605,7 @@ inline bool ArmExidx::DecodePrefix_11_001(uint8_t byte) {
|
|||
}
|
||||
|
||||
inline bool ArmExidx::DecodePrefix_11_010(uint8_t byte) {
|
||||
assert((byte & ~0x07) == 0xd0);
|
||||
CHECK((byte & ~0x07) == 0xd0);
|
||||
|
||||
// 11010nnn: Pop VFP double precision registers D[8]-D[8+nnn] by VPUSH
|
||||
if (log_) {
|
||||
|
@ -624,7 +624,7 @@ inline bool ArmExidx::DecodePrefix_11_010(uint8_t byte) {
|
|||
}
|
||||
|
||||
inline bool ArmExidx::DecodePrefix_11(uint8_t byte) {
|
||||
assert((byte >> 6) == 0x3);
|
||||
CHECK((byte >> 6) == 0x3);
|
||||
|
||||
switch ((byte >> 3) & 0x7) {
|
||||
case 0:
|
||||
|
|
|
@ -0,0 +1,30 @@
|
|||
/*
|
||||
* Copyright (C) 2017 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef _LIBUNWINDSTACK_ERROR_H
|
||||
#define _LIBUNWINDSTACK_ERROR_H
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "Log.h"
|
||||
|
||||
#define CHECK(assertion) \
|
||||
if (__builtin_expect(!(assertion), false)) { \
|
||||
log(0, "%s:%d: %s\n", __FILE__, __LINE__, #assertion); \
|
||||
abort(); \
|
||||
}
|
||||
|
||||
#endif // _LIBUNWINDSTACK_ERROR_H
|
|
@ -14,9 +14,9 @@
|
|||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include <assert.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#include "Check.h"
|
||||
#include "DwarfEhFrame.h"
|
||||
#include "DwarfMemory.h"
|
||||
#include "DwarfSection.h"
|
||||
|
@ -105,8 +105,8 @@ const typename DwarfEhFrame<AddressType>::FdeInfo* DwarfEhFrame<AddressType>::Ge
|
|||
template <typename AddressType>
|
||||
bool DwarfEhFrame<AddressType>::GetFdeOffsetBinary(uint64_t pc, uint64_t* fde_offset,
|
||||
uint64_t total_entries) {
|
||||
assert(fde_count_ > 0);
|
||||
assert(total_entries <= fde_count_);
|
||||
CHECK(fde_count_ > 0);
|
||||
CHECK(total_entries <= fde_count_);
|
||||
|
||||
size_t first = 0;
|
||||
size_t last = total_entries;
|
||||
|
@ -133,7 +133,7 @@ bool DwarfEhFrame<AddressType>::GetFdeOffsetBinary(uint64_t pc, uint64_t* fde_of
|
|||
|
||||
template <typename AddressType>
|
||||
bool DwarfEhFrame<AddressType>::GetFdeOffsetSequential(uint64_t pc, uint64_t* fde_offset) {
|
||||
assert(fde_count_ != 0);
|
||||
CHECK(fde_count_ != 0);
|
||||
last_error_ = DWARF_ERROR_NONE;
|
||||
// We can do a binary search if the pc is in the range of the elements
|
||||
// that have already been cached.
|
||||
|
|
|
@ -14,11 +14,11 @@
|
|||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include <assert.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "Check.h"
|
||||
#include "DwarfEncoding.h"
|
||||
#include "DwarfMemory.h"
|
||||
#include "Memory.h"
|
||||
|
@ -100,8 +100,8 @@ size_t DwarfMemory::GetEncodedSize(uint8_t encoding) {
|
|||
}
|
||||
|
||||
bool DwarfMemory::AdjustEncodedValue(uint8_t encoding, uint64_t* value) {
|
||||
assert((encoding & 0x0f) == 0);
|
||||
assert(encoding != DW_EH_PE_aligned);
|
||||
CHECK((encoding & 0x0f) == 0);
|
||||
CHECK(encoding != DW_EH_PE_aligned);
|
||||
|
||||
// Handle the encoding.
|
||||
switch (encoding) {
|
||||
|
|
|
@ -17,7 +17,6 @@
|
|||
#ifndef _LIBUNWINDSTACK_MEMORY_H
|
||||
#define _LIBUNWINDSTACK_MEMORY_H
|
||||
|
||||
#include <assert.h>
|
||||
#include <stdint.h>
|
||||
#include <sys/types.h>
|
||||
#include <unistd.h>
|
||||
|
@ -25,6 +24,8 @@
|
|||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "Check.h"
|
||||
|
||||
class Memory {
|
||||
public:
|
||||
Memory() = default;
|
||||
|
@ -130,7 +131,7 @@ class MemoryRange : public Memory {
|
|||
public:
|
||||
MemoryRange(Memory* memory, uint64_t begin, uint64_t end)
|
||||
: memory_(memory), begin_(begin), length_(end - begin) {
|
||||
assert(end > begin);
|
||||
CHECK(end > begin);
|
||||
}
|
||||
virtual ~MemoryRange() { delete memory_; }
|
||||
|
||||
|
|
|
@ -14,7 +14,6 @@
|
|||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include <assert.h>
|
||||
#include <elf.h>
|
||||
#include <stdint.h>
|
||||
#include <sys/ptrace.h>
|
||||
|
@ -22,6 +21,7 @@
|
|||
|
||||
#include <vector>
|
||||
|
||||
#include "Check.h"
|
||||
#include "Elf.h"
|
||||
#include "ElfInterface.h"
|
||||
#include "Machine.h"
|
||||
|
@ -43,7 +43,7 @@ template <typename AddressType>
|
|||
bool RegsImpl<AddressType>::GetReturnAddressFromDefault(Memory* memory, uint64_t* value) {
|
||||
switch (return_loc_.type) {
|
||||
case LOCATION_REGISTER:
|
||||
assert(return_loc_.value < total_regs_);
|
||||
CHECK(return_loc_.value < total_regs_);
|
||||
*value = regs_[return_loc_.value];
|
||||
return true;
|
||||
case LOCATION_SP_OFFSET:
|
||||
|
|
|
@ -14,12 +14,12 @@
|
|||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include <assert.h>
|
||||
#include <elf.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "Check.h"
|
||||
#include "Memory.h"
|
||||
#include "Symbols.h"
|
||||
|
||||
|
@ -58,7 +58,7 @@ bool Symbols::GetName(uint64_t addr, uint64_t load_bias, Memory* elf_memory, std
|
|||
if (symbols_.size() != 0) {
|
||||
const Info* info = GetInfoFromCache(addr);
|
||||
if (info) {
|
||||
assert(addr >= info->start_offset && addr <= info->end_offset);
|
||||
CHECK(addr >= info->start_offset && addr <= info->end_offset);
|
||||
*func_offset = addr - info->start_offset;
|
||||
return elf_memory->ReadString(info->str_offset, name, str_end_ - info->str_offset);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue