this repo has no description
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

Various cleanups

+42 -188
+1 -1
CMakeLists.txt
··· 38 38 add_executable(genfuncmap src/util/genfuncmap.cpp) 39 39 40 40 set(util-SRCS 41 - src/util/log.cc 41 + src/util/log.cpp 42 42 src/util/trace.cpp 43 43 src/util/stlutils.cpp 44 44 src/util/IniConfig.cpp
-56
src/dyld/env_flags.h
··· 1 - // Copyright 2011 Shinichiro Hamaji. All rights reserved. 2 - // 3 - // Redistribution and use in source and binary forms, with or without 4 - // modification, are permitted provided that the following conditions 5 - // are met: 6 - // 7 - // 1. Redistributions of source code must retain the above copyright 8 - // notice, this list of conditions and the following disclaimer. 9 - // 10 - // 2. Redistributions in binary form must reproduce the above 11 - // copyright notice, this list of conditions and the following 12 - // disclaimer in the documentation and/or other materials 13 - // provided with the distribution. 14 - // 15 - // THIS SOFTWARE IS PROVIDED BY Shinichiro Hamaji ``AS IS'' AND ANY 16 - // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 17 - // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 18 - // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL Shinichiro Hamaji OR 19 - // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 20 - // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 21 - // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF 22 - // USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 23 - // ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 24 - // OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT 25 - // OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 26 - // SUCH DAMAGE. 27 - 28 - #ifndef ENV_FLAGS_H_ 29 - #define ENV_FLAGS_H_ 30 - 31 - #include <stdlib.h> 32 - #include <string.h> 33 - 34 - #define LD_MAC_EnvToBool(envname, dflt) \ 35 - (!getenv(envname) ? (dflt) : memchr("tTyY1\0", getenv(envname)[0], 6) != NULL) 36 - 37 - #define LD_MAC_DECLARE_VARIABLE(type, name, tn) \ 38 - namespace FLAG__namespace_do_not_use_directly_use_LD_MAC_DECLARE_##tn##_instead { \ 39 - extern type FLAGS_##name; \ 40 - } \ 41 - using FLAG__namespace_do_not_use_directly_use_LD_MAC_DECLARE_##tn##_instead::FLAGS_##name 42 - 43 - #define LD_MAC_DEFINE_VARIABLE(type, name, value, meaning, tn) \ 44 - namespace FLAG__namespace_do_not_use_directly_use_LD_MAC_DECLARE_##tn##_instead { \ 45 - type FLAGS_##name(value); \ 46 - } \ 47 - using FLAG__namespace_do_not_use_directly_use_LD_MAC_DECLARE_##tn##_instead::FLAGS_##name; 48 - 49 - #define DECLARE_bool(name) \ 50 - LD_MAC_DECLARE_VARIABLE(bool, name, bool) 51 - 52 - #define DEFINE_bool(name, value, meaning) \ 53 - LD_MAC_DEFINE_VARIABLE(bool, name, LD_MAC_EnvToBool("LD_MAC_" #name, value), \ 54 - meaning, bool) 55 - 56 - #endif // ENV_FLAGS_H_
+10 -12
src/libSystem/libc/sysctl.cpp
··· 17 17 int __darwin_sysctl(int* name, unsigned int namelen, 18 18 void* oldp, size_t* oldlenp, 19 19 void* newp, size_t newlen) { 20 - int i; 21 - 22 20 TRACE6(name, namelen, oldp, oldlenp, newp, newlen); 23 21 24 - LOGF("sysctl: namelen=%u", namelen); 25 - for (i = 0; i < namelen; i++) 26 - LOGF(" name[%d]=%d", i, name[i]); 27 - LOGF(" newp=%p\n", newp); 22 + LOG << "sysctl: namelen=" << namelen; 23 + for (int i = 0; i < namelen; i++) 24 + LOG << " name[" << i << "]=" << name[i]; 25 + LOG << " newp=" << newp << std::endl; 28 26 29 27 if (newp) 30 28 { 31 - fprintf(stderr, "sysctl with newp isn't supported yet.\n"); 29 + LOG << "sysctl with newp isn't supported yet.\n"; 32 30 errno = DARWIN_EINVAL; 33 31 return -1; 34 32 } 35 33 36 34 if (namelen != 2) 37 35 { 38 - fprintf(stderr, "sysctl with namelen=%u isn't supported yet.\n", namelen); 36 + LOG << "sysctl with namelen=" << namelen << " isn't supported yet.\n"; 39 37 errno = DARWIN_EINVAL; 40 38 return -1; 41 39 } ··· 46 44 { 47 45 if (*oldlenp != 4 && *oldlenp != 8) 48 46 { 49 - fprintf(stderr, "sysctl(HW) with oldlenp=%lu isn't supported yet.\n", (unsigned long)*oldlenp); 47 + LOG << "sysctl(HW) with oldlenp=" << *oldlenp << " isn't supported yet.\n"; 50 48 errno = DARWIN_EINVAL; 51 49 return -1; 52 50 } ··· 70 68 } 71 69 72 70 default: 73 - fprintf(stderr, "sysctl(HW) with name[1]=%d isn't supported yet.\n", name[1]); 71 + LOG << "sysctl(HW) with name[1]=" << name[1] << " isn't supported yet.\n"; 74 72 75 73 errno = DARWIN_EINVAL; 76 74 return -1; ··· 95 93 break; 96 94 97 95 default: 98 - fprintf(stderr, "sysctl(KERN) with oldp=%u isn't supported yet.\n", *oldp); 96 + LOG << "sysctl(KERN) with name[1]=" << name[1] << " isn't supported yet.\n"; 99 97 errno = DARWIN_EINVAL; 100 98 return -1; 101 99 } ··· 103 101 } 104 102 105 103 default: 106 - fprintf(stderr, "sysctl with name[0]=%d isn't supported yet.\n", name[0]); 104 + LOG << "sysctl with name[0]=" << name[0] << " isn't supported yet.\n"; 107 105 errno = DARWIN_EINVAL; 108 106 return -1; 109 107 }
+11 -24
src/libmach-o/MachOImpl.cpp
··· 199 199 200 200 void MachOImpl::readExport(const uint8_t* start, const uint8_t* p, const uint8_t* end, std::string* name_buf) 201 201 { 202 - LOGF("readExport: %p-%p\n", p, end); 203 - #if 0 204 - char buf[17]; 205 - buf[16] = '\0'; 206 - for (int i = 0; i < 16*8; i++) { 207 - LOGF("%02x ", p[i]); 208 - buf[i % 16] = p[i] < 32 ? '?' : p[i]; 209 - if (i % 16 == 15) LOGF("%s\n", buf); 210 - } 211 - #endif 212 - 213 202 if (p >= end) 214 - { 215 - fprintf(stderr, "broken export trie\n"); // TODO: throw an exception instead 216 - exit(1); 217 - } 203 + throw std::runtime_error("broken export trie"); 218 204 219 205 if (uint8_t term_size = *p++) 220 206 { ··· 228 214 229 215 m_exports.push_back(exp); 230 216 231 - CHECK(expected_term_end == p); 217 + assert(expected_term_end == p); 232 218 } 233 219 234 220 const uint8_t num_children = *p++; ··· 240 226 p++; 241 227 242 228 uint64_t off = uleb128(p); 243 - CHECK(off != 0); 229 + assert(off != 0); 244 230 readExport(start, start + off, end, name_buf); 245 231 246 232 name_buf->resize(orig_name_size); ··· 253 239 m_filename = filename; 254 240 m_need_exports = need_exports; 255 241 m_dyld_data = 0; 256 - CHECK(fd); 242 + 243 + assert(fd > 0); 244 + 257 245 m_fd = fd; 258 246 m_offset = offset; 259 247 m_text_offset = 0; ··· 288 276 else if (header->magic != MH_MAGIC) 289 277 throw std::runtime_error("Not a Mach-O file"); 290 278 291 - LOGF("magic=%x cpu=%d cpusub=%d file=%d ncmds=%d sizecmd=%d flags=%x\n", 292 - header->magic, header->cputype, header->cpusubtype, 293 - header->filetype, header->ncmds, header->sizeofcmds, 294 - header->flags); 279 + LOG << "magic=" << std::hex << header->magic << std::dec << " cpu=" << header->cputype 280 + << " cpusub=" << header->cpusubtype << " filetype=" << header->filetype << " ncmds=" 281 + << header->ncmds << " sizeofcmds=" << header->sizeofcmds << " flags=" << std::hex << header->flags << std::dec << std::endl; 295 282 296 283 m_ptrsize = m_is64 ? 8 : 4; 297 284 ··· 536 523 537 524 LOGF("%p vs %p\n", cmds_ptr, bin + m_mapped_size); 538 525 539 - LOGF("dyinfo: %p, dysyms: %p, symtab: %p, symstrtab: %p, symbol count: %d\n", dyinfo, dysyms, symtab, symstrtab, m_symbols.size()); 526 + LOG << "dyinfo: " << dyinfo << ", dysyms: " << dysyms << ", symtab: " << symtab << ", symstrtab: " << symstrtab << ", symbol count: " << m_symbols.size() << std::endl; 540 527 // No LC_DYLD_INFO_ONLY, we will read classic binding info. 541 528 if (!dyinfo && dysyms && symtab && symstrtab) 542 529 { 543 - LOGF("Reading classic binding info\n"); 530 + LOG << "Reading classic binding info\n"; 544 531 for (size_t i = 0; i < bind_sections_64.size(); i++) 545 532 { 546 533 readClassicBind<section_64>(*bind_sections_64[i], dysyms, symtab, symstrtab);
-39
src/util/log.cc
··· 1 - // Copyright 2011 Shinichiro Hamaji. All rights reserved. 2 - // 3 - // Redistribution and use in source and binary forms, with or without 4 - // modification, are permitted provided that the following conditions 5 - // are met: 6 - // 7 - // 1. Redistributions of source code must retain the above copyright 8 - // notice, this list of conditions and the following disclaimer. 9 - // 10 - // 2. Redistributions in binary form must reproduce the above 11 - // copyright notice, this list of conditions and the following 12 - // disclaimer in the documentation and/or other materials 13 - // provided with the distribution. 14 - // 15 - // THIS SOFTWARE IS PROVIDED BY Shinichiro Hamaji ``AS IS'' AND ANY 16 - // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 17 - // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 18 - // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL Shinichiro Hamaji OR 19 - // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 20 - // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 21 - // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF 22 - // USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 23 - // ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 24 - // OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT 25 - // OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 26 - // SUCH DAMAGE. 27 - 28 - #include "env_flags.h" 29 - 30 - // DEFINE_bool(LOG, false, "Output bunch of logs"); 31 - extern "C" bool g_loggingEnabled = false; 32 - 33 - __attribute__((constructor)) static void initLogging() 34 - { 35 - const char* v = getenv("DYLD_DEBUG"); 36 - if (v && atoi(v)) 37 - g_loggingEnabled = true; 38 - } 39 -
+12
src/util/log.cpp
··· 1 + #include <cstring> 2 + #include <cstdlib> 3 + 4 + extern "C" bool g_loggingEnabled = false; 5 + 6 + __attribute__((constructor)) static void initLogging() 7 + { 8 + const char* v = getenv("DYLD_DEBUG"); 9 + if (v && atoi(v)) 10 + g_loggingEnabled = true; 11 + } 12 +
+8 -56
src/util/log.h
··· 1 - // Copyright 2011 Shinichiro Hamaji. All rights reserved. 2 - // 3 - // Redistribution and use in source and binary forms, with or without 4 - // modification, are permitted provided that the following conditions 5 - // are met: 6 - // 7 - // 1. Redistributions of source code must retain the above copyright 8 - // notice, this list of conditions and the following disclaimer. 9 - // 10 - // 2. Redistributions in binary form must reproduce the above 11 - // copyright notice, this list of conditions and the following 12 - // disclaimer in the documentation and/or other materials 13 - // provided with the distribution. 14 - // 15 - // THIS SOFTWARE IS PROVIDED BY Shinichiro Hamaji ``AS IS'' AND ANY 16 - // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 17 - // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 18 - // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL Shinichiro Hamaji OR 19 - // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 20 - // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 21 - // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF 22 - // USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 23 - // ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 24 - // OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT 25 - // OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 26 - // SUCH DAMAGE. 27 - 28 - #ifndef LOG_H_ 29 - #define LOG_H_ 30 - 31 - #include <assert.h> 32 - #include <stdio.h> 33 - 34 - #ifdef __cplusplus 35 - # include <iostream> 36 - #endif 37 - 38 - //#include "env_flags.h" 39 - 40 - //DECLARE_bool(LOG); 41 - extern bool g_loggingEnabled; 42 - #define FLAGS_LOG g_loggingEnabled 1 + #ifndef UTIL_LOG_H 2 + #define UTIL_LOG_H 43 3 44 - #ifdef NOLOG 45 - # define LOG if (0) std::cout 46 - # define LOGF(...) if (0) fprintf(stderr, __VA_ARGS__) 47 - #else 48 - # define LOG if (FLAGS_LOG) std::cerr 49 - # define LOGF(...) if (FLAGS_LOG) fprintf(stderr, __VA_ARGS__) 50 - #endif 4 + #include <cassert> 5 + #include <cstdio> 6 + #include <iostream> 51 7 52 - #define ERR cerr 8 + extern "C" bool g_loggingEnabled; 53 9 54 - #ifdef NDEBUG 55 - // Do an extra check to avoid warning around unused local variables. 56 - # define CHECK(r) do { if (!(r)) assert(r); } while (0) 57 - #else 58 - # define CHECK(r) assert(r); 59 - #endif 10 + #define LOG if (g_loggingEnabled) std::cerr 11 + #define LOGF(...) if (g_loggingEnabled) fprintf(stderr, __VA_ARGS__) 60 12 61 13 #endif