Files
clang-p2996/lldb/tools/lldb-mi/MIUtilDateTimeStd.cpp
Ilia K 3b0494c304 MI fix allowing multiple logging instances of lldb-mi to run simultaneously.
Summary:
Currently if two instances of lldb-mi are running with logging enabled using '--log' the log file conflicts. This produces the following error 
MI: Error: File Handler. Error Permission denied opening 'C:\Users\Ewan\LLVM\build\Debug\bin\lldb-mi-log.txt'

Fixed in this patch by renaming lldb-mi-log.txt based on the date, e.g. lldb-mi-log.txt-20150316163631.log, and moving the file into the temp directory by using the --log-dir option.

Regrading previous review comments the P_tmpdir macro is defined in Windows but always points to "\", which doesn't help much. Also when using the Windows API for GetTempPath() dynamic memory seems much more messy.

Patch from ewan@codeplay.com

Reviewers: abidh, EwanCrawford

Subscribers: zturner, lldb-commits, deepak2427

Differential Revision: http://reviews.llvm.org/D9054

llvm-svn: 235589
2015-04-23 12:48:42 +00:00

92 lines
2.9 KiB
C++

//===-- MIUtilDateTimeStd.cpp -----------------------------------*- C++ -*-===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// In-house headers:
#include "MIUtilDateTimeStd.h"
#include "MICmnResources.h"
//++ ------------------------------------------------------------------------------------
// Details: CMIUtilDateTimeStd constructor.
// Type: Method.
// Args: None.
// Return: None.
// Throws: None.
//--
CMIUtilDateTimeStd::CMIUtilDateTimeStd(void)
{
}
//++ ------------------------------------------------------------------------------------
// Details: CMIUtilDateTimeStd destructor.
// Type: Method.
// Args: None.
// Return: None.
// Throws: None.
//--
CMIUtilDateTimeStd::~CMIUtilDateTimeStd(void)
{
}
//++ ------------------------------------------------------------------------------------
// Details: Retrieve system local current date. Format is MM/DD/YYYY.
// Type: Method.
// Args: None.
// Return: CMIUtilString - Text description.
// Throws: None.
//--
CMIUtilString
CMIUtilDateTimeStd::GetDate(void)
{
CMIUtilString strDate(MIRSRC(IDS_WORD_INVALIDBRKTS));
std::time(&m_rawTime);
const std::tm *pTi = std::localtime(&m_rawTime);
if (std::strftime(&m_pScratch[0], sizeof(m_pScratch), "%d/%m/%y", pTi) > 0)
strDate = m_pScratch;
return strDate;
}
//++ ------------------------------------------------------------------------------------
// Details: Retrieve system local current time. Format is HH:MM:SS 24 hour clock.
// Type: Method.
// Args: None.
// Return: CMIUtilString - Text description.
// Throws: None.
//--
CMIUtilString
CMIUtilDateTimeStd::GetTime(void)
{
std::time(&m_rawTime);
const std::tm *pTi = std::localtime(&m_rawTime);
const CMIUtilString seconds(CMIUtilString::Format("%d", pTi->tm_sec));
const CMIUtilString zero((seconds.length() == 1) ? "0" : "");
const CMIUtilString strTime(CMIUtilString::Format("%d:%d:%s%s", pTi->tm_hour, pTi->tm_min, zero.c_str(), seconds.c_str()));
return strTime;
}
//++ ------------------------------------------------------------------------------------
// Details: Retrieve system local current date and time in yyyy-MM-dd--HH-mm-ss format for log file names.
// Type: Method.
// Args: None.
// Return: CMIUtilString - Text description.
// Throws: None.
//--
CMIUtilString
CMIUtilDateTimeStd::GetDateTimeLogFilename(void)
{
std::time(&m_rawTime);
const std::tm *pTi = std::localtime(&m_rawTime);
const CMIUtilString strTime(CMIUtilString::Format("%d%02d%02d%02d%02d%02d", pTi->tm_year + 1900, pTi->tm_mon,
pTi->tm_mday, pTi->tm_hour, pTi->tm_min, pTi->tm_sec));
return strTime;
}