Fixed size issue with ByteStream and removed some debug output

This commit is contained in:
Cekis
2021-11-20 19:08:23 -05:00
parent d49e30c9f0
commit 7e13b9546a
7 changed files with 29 additions and 64 deletions
+14 -12
View File
@@ -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
@@ -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
@@ -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<uint32 const*>(object) == cs_freeFillPattern) //lint !e740 // unusual pointer cast // Yes.
if (*reinterpret_cast<uint64_t const*>(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<unsigned uint64_t const>(object)));
WARNING(true, ("validateObject(): Object-derived class with address [%x] failed to return valid C++ type info; likely a deleted Object.", reinterpret_cast<uint64_t const>(object)));
isInvalid = true;
}
}
+1 -1
View File
@@ -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);
+4 -4
View File
@@ -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);
+2 -37
View File
@@ -5,16 +5,6 @@
#include <cassert>
#include <cstring>
#include <iostream>
#include <sstream>
#include <iomanip>
#include <execinfo.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/wait.h>
#include <unistd.h>
#include <sys/prctl.h>
// ======================================================================
//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<unsigned>(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<long>(oldData) != 0xefefefefu);
assert(reinterpret_cast<uint64_t>(oldData) != 0xefefefefefefefefu);
if (oldData->size > 4096)
delete oldData;
+5 -4
View File
@@ -9,6 +9,7 @@
#include <exception>
#include <vector>
#include <cstdint>
//---------------------------------------------------------------------
@@ -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)
{