Skip to content

Commit 1950598

Browse files
[lldb][windows] add NSDate and FoundationEssentials.Date dataformatters
1 parent dbe29e4 commit 1950598

File tree

9 files changed

+158
-4
lines changed

9 files changed

+158
-4
lines changed

lldb/source/Plugins/Language/ObjC/Cocoa.cpp

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1256,22 +1256,28 @@ bool lldb_private::formatters::ObjCSELSummaryProvider(
12561256
// this call gives the POSIX equivalent of the Cocoa epoch
12571257
time_t lldb_private::formatters::GetOSXEpoch() {
12581258
static time_t epoch = 0;
1259+
#ifndef _AIX
12591260
if (!epoch) {
1260-
#if !defined(_WIN32) && !defined(_AIX)
1261+
#ifndef _WIN32
12611262
tzset();
1263+
#endif
12621264
tm tm_epoch;
12631265
tm_epoch.tm_sec = 0;
1264-
tm_epoch.tm_hour = 0;
12651266
tm_epoch.tm_min = 0;
1266-
tm_epoch.tm_mon = 0;
1267+
tm_epoch.tm_hour = 0;
12671268
tm_epoch.tm_mday = 1;
1269+
tm_epoch.tm_mon = 0;
12681270
tm_epoch.tm_year = 2001 - 1900;
12691271
tm_epoch.tm_isdst = -1;
1272+
#ifdef _WIN32
1273+
epoch = _mkgmtime(&tm_epoch);
1274+
#else
12701275
tm_epoch.tm_gmtoff = 0;
12711276
tm_epoch.tm_zone = nullptr;
12721277
epoch = timegm(&tm_epoch);
12731278
#endif
12741279
}
1280+
#endif
12751281
return epoch;
12761282
}
12771283

lldb/source/Plugins/Language/Swift/FoundationValueTypes.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,14 @@ bool lldb_private::formatters::swift::Date_SummaryProvider(
3737

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

40+
#ifdef _WIN32
41+
static ConstString g__timeIntervalSinceReferenceDate(
42+
"_timeIntervalSinceReferenceDate");
43+
if (!time_sp)
44+
time_sp = valobj.GetChildAtNamePath(
45+
{g__timeIntervalSinceReferenceDate, "_value"});
46+
#endif
47+
4048
if (!time_sp)
4149
return false;
4250

lldb/source/Plugins/Language/Swift/SwiftLanguage.cpp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -670,8 +670,16 @@ LoadFoundationValueTypesFormatters(lldb::TypeCategoryImplSP swift_category_sp) {
670670

671671
lldb_private::formatters::AddCXXSummary(
672672
swift_category_sp, lldb_private::formatters::swift::Date_SummaryProvider,
673-
"Foundation.Date summary provider", ConstString("Foundation.Date"),
673+
"Foundation.Date summary provider",
674+
ConstString("Foundation(Essentials)?\\.Date"),
675+
TypeSummaryImpl::Flags(summary_flags).SetDontShowChildren(true), true);
676+
677+
#ifdef _WIN32
678+
lldb_private::formatters::AddCXXSummary(
679+
swift_category_sp, lldb_private::formatters::swift::Date_SummaryProvider,
680+
"Foundation.NSDate summary provider", ConstString("Foundation.NSDate"),
674681
TypeSummaryImpl::Flags(summary_flags).SetDontShowChildren(true));
682+
#endif
675683

676684
lldb_private::formatters::AddCXXSummary(
677685
swift_category_sp,
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
CXX_SOURCES := jitbp.cpp
2+
3+
include Makefile.rules
4+
5+
# Build LLVM IR that lli will JIT.
6+
# Matches the commands from the shell test.
7+
jitbp.ll: jitbp.cpp
8+
$(CXX) -g -S -emit-llvm --target=x86_64-unknown-unknown-elf \
9+
-o $@ $<
10+
11+
all: jitbp.ll
12+
13+
clean::
14+
rm -f jitbp.ll
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
"""
2+
Test that pending breakpoints resolve for JITted code with MCJIT and RuntimeDyld.
3+
Converted from the original LLDB shell test.
4+
"""
5+
6+
import lldb
7+
import os
8+
from lldbsuite.test.decorators import *
9+
from lldbsuite.test.lldbtest import *
10+
from lldbsuite.test import lldbutil
11+
12+
class TestJitBreakpoint(TestBase):
13+
14+
def setUp(self):
15+
TestBase.setUp(self)
16+
# Makefile builds jitbp.ll for us
17+
self.ll = self.getBuildArtifact("jitbp.ll")
18+
19+
@skipUnlessArch("x86_64")
20+
@expectedFailureAll(oslist=["windows"])
21+
def test_jit_breakpoints(self):
22+
self.build() # Runs the Makefile → produces jitbp.ll
23+
self.do_test("--jit-kind=mcjit")
24+
self.do_test("--jit-linker=rtdyld")
25+
26+
def do_test(self, jit_flag):
27+
debugger = self.dbg
28+
debugger.SetAsync(False)
29+
30+
# Equivalent to: settings set plugin.jit-loader.gdb.enable on
31+
debugger.HandleCommand("settings set plugin.jit-loader.gdb.enable on")
32+
33+
# Create target for lli
34+
lli_path = lldbutil.which("lli")
35+
self.assertIsNotNone(lli_path, "Could not find lli executable")
36+
target = debugger.CreateTarget(lli_path)
37+
self.assertTrue(target.IsValid())
38+
39+
# Create pending breakpoint: b jitbp
40+
bp = target.BreakpointCreateByName("jitbp")
41+
self.assertTrue(bp.IsValid())
42+
self.assertEqual(bp.GetNumLocations(), 0, "Expected pending breakpoint")
43+
44+
# Launch lli with JIT flag and compiled jitbp.ll
45+
launch_info = target.GetLaunchInfo()
46+
launch_info.SetArguments([jit_flag, self.ll], True)
47+
48+
error = lldb.SBError()
49+
process = target.Launch(launch_info, error)
50+
self.assertTrue(process.IsValid())
51+
self.assertTrue(error.Success(), error.GetCString())
52+
53+
# Expect stop at JITted breakpoint
54+
self.assertEqual(process.GetState(), lldb.eStateStopped)
55+
56+
# Validate call frame
57+
thread = process.GetSelectedThread()
58+
frame = thread.GetSelectedFrame()
59+
self.assertIn("jitbp", frame.GetFunctionName())
60+
61+
# Breakpoint should now have resolved
62+
self.assertGreaterEqual(bp.GetNumLocations(), 1,
63+
"Breakpoint must resolve after JIT loads code")
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
int jitbp() { return 0; }
2+
int main() { return jitbp(); }
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
SWIFT_SOURCES := main.swift
2+
3+
include Makefile.rules
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
"""
2+
Test Foundation.Date summary strings.
3+
"""
4+
5+
import lldb
6+
from lldbsuite.test.lldbtest import *
7+
from lldbsuite.test.decorators import *
8+
import lldbsuite.test.lldbutil as lldbutil
9+
10+
import sys
11+
12+
13+
class TestCase(TestBase):
14+
@swiftTest
15+
def test_swift_date_formatters(self):
16+
"""Test Date summary strings."""
17+
self.build()
18+
19+
_ = lldbutil.run_to_source_breakpoint(
20+
self, "break here", lldb.SBFileSpec("main.swift")
21+
)
22+
23+
self.expect(
24+
"v date",
25+
startstr="(Foundation.Date) date = 1999-11-05 23:17:00 UTC",
26+
)
27+
28+
if sys.platform != "win32":
29+
return
30+
31+
self.expect(
32+
"v nsdate",
33+
startstr="(Foundation.NSDate) date = 1999-11-05 23:17:00 UTC",
34+
)
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import Foundation
2+
3+
let paris = TimeZone(identifier: "Europe/Paris")!
4+
5+
var comps = DateComponents()
6+
comps.year = 1999
7+
comps.month = 11
8+
comps.day = 6
9+
comps.hour = 0
10+
comps.minute = 17
11+
comps.timeZone = paris
12+
13+
let date = Calendar(identifier: .gregorian).date(from: comps)!
14+
let nsdate = date as NSDate
15+
16+
print("break here")

0 commit comments

Comments
 (0)