From 7e13b9546a4536e38a768f07ff228c54cc1b99e9 Mon Sep 17 00:00:00 2001 From: Cekis Date: Sat, 20 Nov 2021 19:08:23 -0500 Subject: [PATCH] Fixed size issue with ByteStream and removed some debug output --- CMakeLists.txt | 26 +++++++------ .../src/shared/CrcStringTable.cpp | 3 -- .../src/shared/object/AlterScheduler.cpp | 6 +-- .../library/platform/utils/Base/Archive.cpp | 2 +- .../3rd/library/platform/utils/Base/Archive.h | 8 ++-- .../library/archive/src/shared/ByteStream.cpp | 39 +------------------ .../library/archive/src/shared/ByteStream.h | 9 +++-- 7 files changed, 29 insertions(+), 64 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 7a066532..16eb9f2f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -77,15 +77,21 @@ elseif (UNIX) endif () # don't put anything too crazy in debug...and any common flags go into CMAKE_CXX_FLAGS - set(CMAKE_CXX_FLAGS_DEBUG "-D_DEBUG -DDEBUG_LEVEL=2 -DPRODUCTION=0 -O0 -ggdb") + set(CMAKE_CXX_FLAGS_DEBUG "-D_DEBUG -DDEBUG_LEVEL=2 -DPRODUCTION=0 -O0 -ggdb -pg -no-pie") # release specific cflags - optimizations beyond the default for both types is mostly just -O flags set(CMAKE_CXX_FLAGS_RELEASE "-DDEBUG_LEVEL=0 -DPRODUCTION=1") # we use fewer, if any, crazy optimizations for profile generation, and likewise release flags for the minsizerel - set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_RELEASE} -ggdb") + set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_RELEASE} -ggdb -pg -no-pie") set(CMAKE_CXX_FLAGS_MINSIZEREL "${CMAKE_CXX_FLAGS_RELEASE}") + # our "always on" flags - build by default for the system we're on but include all instruction sets + set(CMAKE_CXX_FLAGS "-pipe -march=native -mtune=native \ + -Wformat -Wno-overloaded-virtual -Wno-missing-braces -Wno-format \ + -Wno-write-strings -Wno-unknown-pragmas \ + -Wno-uninitialized -Wno-reorder -Wno-tautological-constant-out-of-range-compare -Wno-address-of-packed-member") + # Ofast doesn't work with gcc builds if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang") set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -Ofast \ @@ -94,12 +100,12 @@ elseif (UNIX) -fno-coverage-mapping -fno-spell-checking \ -mno-retpoline") - set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -ggdb") + set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -ggdb -fprofile-instr-generate -fcoverage-mapping") # RELWITHDEBINFO is used for building bins that produce profdata files - # we only need the basics of our heavy optimizations here, i think - that and one of these flags - # breaks JNI when we profile - set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "-Ofast -finline-hint-functions -fprofile-instr-generate") + # we only need the basics of our heavy optimizations here, i think - that and one of these flags + # breaks JNI when we profile + set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "-Ofast -finline-hint-functions -fprofile-instr-generate -g -fcoverage-mapping") # MINSIZEREL is used for profiled, flto builds set(CMAKE_CXX_FLAGS_MINSIZEREL "${CMAKE_CXX_FLAGS_RELEASE} -flto -fwhole-program-vtables") @@ -109,14 +115,10 @@ elseif (UNIX) set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -Og") elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Intel") set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -O3") + elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "g++") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-stringop-overflow") endif () - # our "always on" flags - build by default for the system we're on but include all instruction sets - set(CMAKE_CXX_FLAGS "-pipe -march=native -mtune=native \ - -Wformat -Wno-overloaded-virtual -Wno-missing-braces -Wno-format \ - -Wno-write-strings -Wno-unknown-pragmas \ - -Wno-uninitialized -Wno-reorder -Wno-tautological-constant-out-of-range-compare -Wno-stringop-overflow -Wno-address-of-packed-member") - add_definitions(-DLINUX -D_REENTRANT -Dlinux -D_USING_STL -D_GNU_SOURCE -D_XOPEN_SOURCE=500 -U_FORTIFY_SOURCE) # this is so some profile specific stuff is turned on in the code diff --git a/engine/shared/library/sharedFoundation/src/shared/CrcStringTable.cpp b/engine/shared/library/sharedFoundation/src/shared/CrcStringTable.cpp index d9855c03..6c962b3f 100755 --- a/engine/shared/library/sharedFoundation/src/shared/CrcStringTable.cpp +++ b/engine/shared/library/sharedFoundation/src/shared/CrcStringTable.cpp @@ -165,8 +165,6 @@ ConstCharCrcString const CrcStringTable::lookUp(uint32 crc) const high = mid - 1; } - WARNING(true,("\n=========== Could not find entry 0x%08x with %d entries!!\n", crc, m_numberOfEntries)); - low = 0; high = m_numberOfEntries - 1; @@ -175,7 +173,6 @@ ConstCharCrcString const CrcStringTable::lookUp(uint32 crc) const int const mid = (low + high) / 2; uint32 const entry = m_crcTable[mid]; - WARNING(true, ("Checking 0x%08x against entry value 0x%08x at index %d", crc, entry, mid)); if (crc == entry) return ConstCharCrcString(m_strings + m_stringsOffsetTable[mid], crc); else diff --git a/engine/shared/library/sharedObject/src/shared/object/AlterScheduler.cpp b/engine/shared/library/sharedObject/src/shared/object/AlterScheduler.cpp index 2ae61799..24e46165 100755 --- a/engine/shared/library/sharedObject/src/shared/object/AlterScheduler.cpp +++ b/engine/shared/library/sharedObject/src/shared/object/AlterScheduler.cpp @@ -114,7 +114,7 @@ namespace AlterSchedulerNamespace float const cs_schedulerTicksPerSecond = 1000.0f; // # schedule ticks per second. Frame rates will not be able to exceed this. float const cs_secondsPerSchedulerTick = 1.0f / cs_schedulerTicksPerSecond; - uint32 const cs_freeFillPattern = 0xEFEFEFEF; // this should match MemoryManager's free fill pattern. + uint64_t const cs_freeFillPattern = 0xEFEFEFEFEFEFEFEF; // this should match MemoryManager's free fill pattern. // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -291,7 +291,7 @@ void AlterSchedulerNamespace::validateObject(Object const *object) #ifdef _DEBUG //-- Check if object memory is deleted. - if (*reinterpret_cast(object) == cs_freeFillPattern) //lint !e740 // unusual pointer cast // Yes. + if (*reinterpret_cast(object) == cs_freeFillPattern) //lint !e740 // unusual pointer cast // Yes. { DEBUG_WARNING(true, ("validateObject(): alter scheduler found deleted object (object memory starts with 4 bytes of free-fill pattern).")); //lint !e740 // unusual pointer cast from incompatible indirect types // okay, I'm doing something unusual. isInvalid = true; @@ -313,7 +313,7 @@ void AlterSchedulerNamespace::validateObject(Object const *object) } catch (...) { //lint !e1775 // catch block does not declare any exception // that's right: I want to catch it all. - WARNING(true, ("validateObject(): Object-derived class with address [%x] failed to return valid C++ type info; likely a deleted Object.", reinterpret_cast(object))); + WARNING(true, ("validateObject(): Object-derived class with address [%x] failed to return valid C++ type info; likely a deleted Object.", reinterpret_cast(object))); isInvalid = true; } } diff --git a/external/3rd/library/platform/utils/Base/Archive.cpp b/external/3rd/library/platform/utils/Base/Archive.cpp index fa1ec78e..11e235b9 100755 --- a/external/3rd/library/platform/utils/Base/Archive.cpp +++ b/external/3rd/library/platform/utils/Base/Archive.cpp @@ -152,7 +152,7 @@ namespace Base return *this; } - void ByteStream::get(void * target, ReadIterator & readIterator, const unsigned long int targetSize) const + void ByteStream::get(void * target, ReadIterator & readIterator, const uint32_t targetSize) const { assert(readIterator.getReadPosition() + targetSize <= allocatedSize); memcpy(target, &data->buffer[readIterator.getReadPosition()], targetSize); diff --git a/external/3rd/library/platform/utils/Base/Archive.h b/external/3rd/library/platform/utils/Base/Archive.h index c461f4d7..f8f5ef39 100755 --- a/external/3rd/library/platform/utils/Base/Archive.h +++ b/external/3rd/library/platform/utils/Base/Archive.h @@ -63,7 +63,7 @@ const unsigned MAX_ARRAY_SIZE = 1024; ReadIterator & operator = (const ReadIterator & source); void advance (const unsigned int distance); - void get (void * target, const unsigned long int readSize); + void get (void * target, const uint32_t readSize); const unsigned int getSize () const; const unsigned char * const getBuffer () const; const unsigned int getReadPosition () const; @@ -92,7 +92,7 @@ const unsigned MAX_ARRAY_SIZE = 1024; void ref (); protected: unsigned char * buffer; - unsigned long size; + uint32_t size; private: struct DataFreeList { @@ -132,7 +132,7 @@ const unsigned MAX_ARRAY_SIZE = 1024; void put(const void * const source, const unsigned int sourceSize); private: - void get(void * target, ReadIterator & readIterator, const unsigned long int readSize) const; + void get(void * target, ReadIterator & readIterator, const uint32_t readSize) const; void growToAtLeast(const unsigned int targetSize); void reAllocate(const unsigned int newSize); @@ -255,7 +255,7 @@ const unsigned MAX_ARRAY_SIZE = 1024; return *this; } - inline void ByteStream::ReadIterator::get(void * target, const unsigned long int readSize) + inline void ByteStream::ReadIterator::get(void * target, const uint32_t readSize) { assert(stream); stream->get(target, *this, readSize); diff --git a/external/ours/library/archive/src/shared/ByteStream.cpp b/external/ours/library/archive/src/shared/ByteStream.cpp index 13aab2c1..6b16bf29 100755 --- a/external/ours/library/archive/src/shared/ByteStream.cpp +++ b/external/ours/library/archive/src/shared/ByteStream.cpp @@ -5,16 +5,6 @@ #include #include -#include -#include -#include -#include -#include -#include -#include -#include -#include - // ====================================================================== //static volatile int s_dataFreeListLocked; @@ -234,7 +224,7 @@ ByteStream &ByteStream::operator=(ByteStream const &rhs) @author Justin Randall */ -void ByteStream::get(void *target, ReadIterator &readIterator, const unsigned long int targetSize) const +void ByteStream::get(void *target, ReadIterator &readIterator, const uint32_t targetSize) const { if (data && readIterator.getReadPosition() + targetSize <= allocatedSize) { @@ -243,31 +233,6 @@ void ByteStream::get(void *target, ReadIterator &readIterator, const unsigned lo else { static const char * const desc = "Archive::ByteStream - read beyond end of buffer"; - std::cout << "read position: " << readIterator.getReadPosition() << " target size: " << targetSize << " allocated size: " << allocatedSize << std::endl; - std::cout << "I'm being called from: " << program_invocation_name; - std::cout << "======> BUFFER: " << std::endl; - - std::stringstream ss; - ss << std::hex << std::setfill('0'); - for (int i = 0; i < allocatedSize; ++i) - { - ss << std::setw(2) << static_cast(data->buffer[i]); - } - std::cout << ss.str() << std::endl; - - char pid_buf[30]; - sprintf(pid_buf, "%d", getpid()); - char name_buf[512]; - name_buf[readlink("/proc/self/exe", name_buf, 511)]=0; - prctl(PR_SET_PTRACER, PR_SET_PTRACER_ANY, 0, 0, 0); - int child_pid = fork(); - if (!child_pid) { - dup2(2,1); // redirect output to stderr - edit: unnecessary? - execl("/usr/bin/gdb", "gdb", "--batch", "-n", "-ex", "thread", "-ex", "bt", name_buf, pid_buf, NULL); - abort(); /* If gdb failed to start */ - } else { - waitpid(child_pid,NULL,0); - } ReadException ex(desc); throw (ex); } @@ -380,7 +345,7 @@ ByteStream::Data *ByteStream::Data::getNewData() void ByteStream::Data::releaseOldData(ByteStream::Data *oldData) { - assert((unsigned) reinterpret_cast(oldData) != 0xefefefefu); + assert(reinterpret_cast(oldData) != 0xefefefefefefefefu); if (oldData->size > 4096) delete oldData; diff --git a/external/ours/library/archive/src/shared/ByteStream.h b/external/ours/library/archive/src/shared/ByteStream.h index a94aeb36..d40bb090 100755 --- a/external/ours/library/archive/src/shared/ByteStream.h +++ b/external/ours/library/archive/src/shared/ByteStream.h @@ -9,6 +9,7 @@ #include #include +#include //--------------------------------------------------------------------- @@ -82,7 +83,7 @@ public: bool operator == (const ReadIterator & other) const; bool operator != (const ReadIterator & other) const; void advance (const unsigned int distance); - void get (void * target, const unsigned long int readSize); + void get (void * target, const uint32_t readSize); const unsigned int getSize () const; const unsigned char * const getBuffer () const; const unsigned int getReadPosition () const; @@ -136,7 +137,7 @@ public: void setAllocatedSizeLimit(unsigned int limit); private: - void get(void * target, ReadIterator & readIterator, const unsigned long int readSize) const; + void get(void * target, ReadIterator & readIterator, const uint32_t readSize) const; void growToAtLeast(const unsigned int targetSize); void reAllocate(const unsigned int newSize); @@ -155,7 +156,7 @@ private: // inner classes friend class ByteStream; friend class Archive::ReadIterator; unsigned char * buffer; - unsigned long size; + uint32_t size; private: struct DataFreeList { @@ -252,7 +253,7 @@ inline ReadIterator & ReadIterator::operator = (const ReadIterator & rhs) //--------------------------------------------------------------------- -inline void ReadIterator::get(void * target, const unsigned long int readSize) +inline void ReadIterator::get(void * target, const uint32_t readSize) { if(stream) {