Skip to content

Commit

Permalink
simplify some file system locations, remove crash dumps
Browse files Browse the repository at this point in the history
  • Loading branch information
gorlak committed Jan 3, 2014
1 parent 9576e74 commit 8e6fc71
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 143 deletions.
1 change: 0 additions & 1 deletion Exception.h
Expand Up @@ -77,7 +77,6 @@ namespace Helium
std::string m_Callstack;
std::vector< std::string > m_Threads;
std::string m_State;
std::string m_Dump;

// CPP-specific info
std::string m_CPPClass;
Expand Down
57 changes: 0 additions & 57 deletions ExceptionWin.cpp
Expand Up @@ -767,63 +767,6 @@ std::string Helium::GetExceptionInfo(LPEXCEPTION_POINTERS info)
return buffer;
}

std::string Helium::WriteDump(LPEXCEPTION_POINTERS info, bool full)
{
std::string directory = GetDumpDirectory();
if ( directory.empty() )
{
Print( TXT( "Could not determine crash dump directory, failed to generate dump." ) );
return TXT( "" );
}

HELIUM_TCHAR_TO_WIDE( directory.c_str(), convertedDirectory );

SHCreateDirectoryEx( NULL, convertedDirectory, NULL );

// Tack time (in seconds since UTC) onto end of file name
time_t now;
time( &now );

wchar_t module[ MAX_PATH ];
wchar_t file[ MAX_PATH ];
GetModuleFileName( 0, module, MAX_PATH );
_tsplitpath( module, NULL, NULL, file, NULL );

wchar_t dmpFile[ MAX_PATH ] = { L'\0' };
_sntprintf( dmpFile, sizeof( dmpFile ) - 1, L"%s\\%s_%ld.dmp", convertedDirectory, file, now );

HANDLE dmp = CreateFile( dmpFile, FILE_ALL_ACCESS, FILE_SHARE_READ, 0, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, 0 );
if ( dmp!=INVALID_HANDLE_VALUE )
{
MINIDUMP_EXCEPTION_INFORMATION ex;
ex.ClientPointers = true;
ex.ExceptionPointers = info;
ex.ThreadId = GetCurrentThreadId();

_MINIDUMP_TYPE type;

if ( full )
{
type = MiniDumpWithFullMemory;
}
else
{
type = MiniDumpNormal;
}

// generate the minidump
MiniDumpWriteDump( GetCurrentProcess(), GetCurrentProcessId(), dmp, type, &ex, 0, 0 );

// close the file
CloseHandle( dmp );

HELIUM_WIDE_TO_TCHAR( dmpFile, convertedDmpFile );
return convertedDmpFile;
}

return TXT("");
}

#if !HELIUM_RELEASE && !HELIUM_PROFILE

static Mutex& GetStackWalkMutex()
Expand Down
3 changes: 0 additions & 3 deletions ExceptionWin.h
Expand Up @@ -64,7 +64,4 @@ namespace Helium
HELIUM_PLATFORM_API std::string GetExceptionInfo( LPEXCEPTION_POINTERS info );
HELIUM_PLATFORM_API const char* GetExceptionClass( uint32_t exceptionCode );
HELIUM_PLATFORM_API void GetExceptionDetails( LPEXCEPTION_POINTERS info, ExceptionArgs& args );

// Core dumps (full dumps include process heaps)
HELIUM_PLATFORM_API std::string WriteDump( LPEXCEPTION_POINTERS info, bool full );
}
8 changes: 1 addition & 7 deletions Process.h
Expand Up @@ -51,11 +51,5 @@ namespace Helium
HELIUM_PLATFORM_API std::string GetMachineName();

/// Location for user preferences on disk
HELIUM_PLATFORM_API std::string GetPreferencesDirectory();

/// Location for app cache data on disk
HELIUM_PLATFORM_API std::string GetAppDataDirectory();

/// Location for crash dumps
HELIUM_PLATFORM_API std::string GetDumpDirectory();
HELIUM_PLATFORM_API std::string GetHomeDirectory();
}
35 changes: 8 additions & 27 deletions ProcessPosix.cpp
Expand Up @@ -154,32 +154,13 @@ std::string Helium::GetMachineName()
return "";
}

std::string Helium::GetPreferencesDirectory()
std::string Helium::GetHomeDirectory()
{
const char* home = getenv( "HOME" );
std::string path = home;
path += "/.";
path += GetProcessName();
path += "/preferences/";
return path;
}

std::string Helium::GetAppDataDirectory()
{
const char* home = getenv( "HOME" );
std::string path = home;
path += "/.";
path += GetProcessName();
path += "/data/";
return path;
}

std::string Helium::GetDumpDirectory()
{
const char* home = getenv( "HOME" );
std::string path = home;
path += "/.";
path += GetProcessName();
path += "/dumps/";
return path;
const char* user = getenv( "HOME" );
if ( user )
{
return user;
}
HELIUM_ASSERT( false );
return "";
}
63 changes: 15 additions & 48 deletions ProcessWin.cpp
Expand Up @@ -161,16 +161,16 @@ int Helium::Execute( const std::string& command, std::string& output )

ProcessHandle Helium::Spawn( const std::string& command, bool autoKill )
{
static HANDLE hJob = INVALID_HANDLE_VALUE;
if ( autoKill && hJob == INVALID_HANDLE_VALUE )
{
hJob = CreateJobObject( NULL, NULL ); // GLOBAL
if( HELIUM_VERIFY( hJob ) )
{
// Configure all child processes associated with the job to terminate when the
JOBOBJECT_EXTENDED_LIMIT_INFORMATION jeli = { 0 };
jeli.BasicLimitInformation.LimitFlags = JOB_OBJECT_LIMIT_KILL_ON_JOB_CLOSE;
HELIUM_VERIFY( SetInformationJobObject( hJob, JobObjectExtendedLimitInformation, &jeli, sizeof(jeli)) );
static HANDLE hJob = INVALID_HANDLE_VALUE;
if ( autoKill && hJob == INVALID_HANDLE_VALUE )
{
hJob = CreateJobObject( NULL, NULL ); // GLOBAL
if( HELIUM_VERIFY( hJob ) )
{
// Configure all child processes associated with the job to terminate when the
JOBOBJECT_EXTENDED_LIMIT_INFORMATION jeli = { 0 };
jeli.BasicLimitInformation.LimitFlags = JOB_OBJECT_LIMIT_KILL_ON_JOB_CLOSE;
HELIUM_VERIFY( SetInformationJobObject( hJob, JobObjectExtendedLimitInformation, &jeli, sizeof(jeli)) );
}
}

Expand All @@ -183,9 +183,9 @@ ProcessHandle Helium::Spawn( const std::string& command, bool autoKill )

DWORD flags = 0x0;

OSVERSIONINFO osvi;
memset(&osvi, 0, sizeof( OSVERSIONINFO ) );
osvi.dwOSVersionInfoSize = sizeof( OSVERSIONINFO );
OSVERSIONINFO osvi;
memset(&osvi, 0, sizeof( OSVERSIONINFO ) );
osvi.dwOSVersionInfoSize = sizeof( OSVERSIONINFO );
::GetVersionEx(&osvi);
if ( osvi.dwMajorVersion == 6 && ( osvi.dwMinorVersion == 0 || osvi.dwMinorVersion == 1 ) ) // vista and 7
{
Expand Down Expand Up @@ -220,7 +220,7 @@ ProcessHandle Helium::Spawn( const std::string& command, bool autoKill )

if ( autoKill && hJob )
{
HELIUM_VERIFY( ::AssignProcessToJobObject( hJob, pi.hProcess ) );
HELIUM_VERIFY( ::AssignProcessToJobObject( hJob, pi.hProcess ) );
}

// release handles to our new process
Expand Down Expand Up @@ -311,7 +311,7 @@ std::string Helium::GetMachineName()
return computername;
}

std::string Helium::GetPreferencesDirectory()
std::string Helium::GetHomeDirectory()
{
std::string profileDirectory;

Expand All @@ -326,36 +326,3 @@ std::string Helium::GetPreferencesDirectory()

return profileDirectory;
}

std::string Helium::GetAppDataDirectory()
{
std::string appDataDirectory;

wchar_t path[ MAX_PATH ];
HRESULT result = SHGetFolderPath( NULL, CSIDL_LOCAL_APPDATA, NULL, SHGFP_TYPE_CURRENT, path );
bool bSuccess = ( result == S_OK );
if ( bSuccess )
{
HELIUM_WIDE_TO_TCHAR( path, convertedPath );
appDataDirectory = convertedPath;
}

return appDataDirectory;
}

std::string Helium::GetDumpDirectory()
{
wchar_t tempDir[ MAX_PATH ];
size_t result = ::GetTempPath( MAX_PATH, tempDir );
if ( result == 0 || result > MAX_PATH )
{
return TXT("");
}

// Make sure that the directory exists
wchar_t directory[ MAX_PATH ] = { 0 };
_snwprintf( directory, sizeof( directory ) - 1, L"%s\\dumps", &tempDir );

HELIUM_WIDE_TO_TCHAR( directory, convertedDirectory );
return convertedDirectory;
}

0 comments on commit 8e6fc71

Please sign in to comment.