Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion lldb/source/Plugins/Language/ObjC/Cocoa.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1256,9 +1256,11 @@ bool lldb_private::formatters::ObjCSELSummaryProvider(
// this call gives the POSIX equivalent of the Cocoa epoch
time_t lldb_private::formatters::GetOSXEpoch() {
static time_t epoch = 0;
#ifndef _AIX
if (!epoch) {
#if !defined(_WIN32) && !defined(_AIX)
#ifndef _WIN32
tzset();
#endif
tm tm_epoch;
tm_epoch.tm_sec = 0;
tm_epoch.tm_hour = 0;
Expand All @@ -1267,11 +1269,15 @@ time_t lldb_private::formatters::GetOSXEpoch() {
tm_epoch.tm_mday = 1;
tm_epoch.tm_year = 2001 - 1900;
tm_epoch.tm_isdst = -1;
#ifdef _WIN32
epoch = _mkgmtime(&tm_epoch);
#else
tm_epoch.tm_gmtoff = 0;
tm_epoch.tm_zone = nullptr;
epoch = timegm(&tm_epoch);
#endif
}
#endif
return epoch;
}

Expand Down
6 changes: 6 additions & 0 deletions lldb/source/Plugins/Language/Swift/FoundationValueTypes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,15 @@ using namespace lldb_private::formatters::swift;
bool lldb_private::formatters::swift::Date_SummaryProvider(
ValueObject &valobj, Stream &stream, const TypeSummaryOptions &options) {
static ConstString g__time("_time");
static ConstString g__timeIntervalSinceReferenceDate(
"_timeIntervalSinceReferenceDate");

ValueObjectSP time_sp(valobj.GetChildAtNamePath({g__time}));

if (!time_sp)
time_sp = valobj.GetChildAtNamePath(
{g__timeIntervalSinceReferenceDate, "_value"});

if (!time_sp)
return false;

Expand Down
5 changes: 3 additions & 2 deletions lldb/source/Plugins/Language/Swift/SwiftLanguage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -670,8 +670,9 @@ LoadFoundationValueTypesFormatters(lldb::TypeCategoryImplSP swift_category_sp) {

lldb_private::formatters::AddCXXSummary(
swift_category_sp, lldb_private::formatters::swift::Date_SummaryProvider,
"Foundation.Date summary provider", ConstString("Foundation.Date"),
TypeSummaryImpl::Flags(summary_flags).SetDontShowChildren(true));
"Foundation.Date summary provider",
ConstString("Foundation(Essentials)?\\.(NS)?Date"),
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will match:

  • Foundation.Date
  • FoundationEssentials.Date
  • Foundation.NSDate

This should not clash with the other Foundation.NSDate formatter. The tests should confirm this.

TypeSummaryImpl::Flags(summary_flags).SetDontShowChildren(true), true);

lldb_private::formatters::AddCXXSummary(
swift_category_sp,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
SWIFT_SOURCES := main.swift

include Makefile.rules
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
"""
Test Foundation.Date summary strings.
"""

import lldb
from lldbsuite.test.lldbtest import *
from lldbsuite.test.decorators import *
import lldbsuite.test.lldbutil as lldbutil

import sys


class TestCase(TestBase):
@skipUnlessFoundation
@swiftTest
def test_swift_date_formatters(self):
"""Test Date summary strings."""
self.build()

_ = lldbutil.run_to_source_breakpoint(
self, "break here", lldb.SBFileSpec("main.swift")
)

self.expect(
"v date",

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit (for the future): I think it's better to spell out "frame variable" instead of "v". We've changed aliases in the past so it could happen again, it's also easier to grep

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! I opened #12005 as a follow up.

startstr="(Foundation.Date) date = 2001-01-15 13:12:00 UTC",
)

if sys.platform != "win32":
return

self.expect(
"v nsdate",
startstr="(Foundation.NSDate) date = 2001-01-15 13:12:00 UTC",
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import Foundation

let paris = TimeZone(identifier: "Europe/Paris")!

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: it would be better to put this code in a main() (or whatever name you want) function and immediately call it. These variables are actually static, not local variables. I think this works now because of DIL but we might want to go back to enforcing frame var works only for local variables in the future.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! I opened #12005 as a follow up.


var comps = DateComponents()
comps.year = 2001
comps.month = 1
comps.day = 15
comps.hour = 14
comps.minute = 12
comps.timeZone = paris

let date = Calendar(identifier: .gregorian).date(from: comps)!
let nsdate = date as NSDate

print("break here")