12
12
13
13
#include " SwiftLanguageRuntime.h"
14
14
#include " Plugins/LanguageRuntime/Swift/LLDBMemoryReader.h"
15
+ #include " Plugins/TypeSystem/Swift/TypeSystemSwiftTypeRef.h"
15
16
#include " ReflectionContextInterface.h"
16
17
#include " SwiftMetadataCache.h"
17
18
34
35
#include " lldb/Interpreter/CommandObject.h"
35
36
#include " lldb/Interpreter/CommandObjectMultiword.h"
36
37
#include " lldb/Interpreter/CommandReturnObject.h"
38
+ #include " lldb/Symbol/CompilerType.h"
37
39
#include " lldb/Symbol/FuncUnwinders.h"
38
40
#include " lldb/Symbol/Function.h"
39
41
#include " lldb/Symbol/VariableList.h"
63
65
#include " llvm/ADT/StringRef.h"
64
66
#include " llvm/BinaryFormat/Dwarf.h"
65
67
#include " llvm/Support/raw_ostream.h"
68
+ #include " llvm/Support/Error.h"
69
+ #include " llvm/Support/FormatAdapters.h"
66
70
#include " llvm/Support/Memory.h"
67
71
68
72
// FIXME: we should not need this
@@ -2183,6 +2187,61 @@ class CommandObjectLanguageSwiftTaskSelect final : public CommandObjectParsed {
2183
2187
}
2184
2188
};
2185
2189
2190
+ class CommandObjectLanguageSwiftTaskInfo final : public CommandObjectParsed {
2191
+ public:
2192
+ CommandObjectLanguageSwiftTaskInfo (CommandInterpreter &interpreter)
2193
+ : CommandObjectParsed(interpreter, " info" ,
2194
+ " Print the Task being run on the current thread." ) {
2195
+ }
2196
+
2197
+ private:
2198
+ void DoExecute (Args &command, CommandReturnObject &result) override {
2199
+ if (!m_exe_ctx.GetThreadPtr ()) {
2200
+ result.AppendError (" must be run from a running process and valid thread" );
2201
+ return ;
2202
+ }
2203
+
2204
+ auto task_addr_or_err =
2205
+ GetTaskAddrFromThreadLocalStorage (m_exe_ctx.GetThreadRef ());
2206
+ if (auto error = task_addr_or_err.takeError ()) {
2207
+ result.AppendError (toString (std::move (error)));
2208
+ return ;
2209
+ }
2210
+
2211
+ auto ts_or_err = m_exe_ctx.GetTargetRef ().GetScratchTypeSystemForLanguage (
2212
+ eLanguageTypeSwift);
2213
+ if (auto error = ts_or_err.takeError ()) {
2214
+ result.AppendErrorWithFormatv (" could not get Swift type system: {0}" ,
2215
+ llvm::fmt_consume (std::move (error)));
2216
+ return ;
2217
+ }
2218
+
2219
+ auto *ts = llvm::dyn_cast_or_null<TypeSystemSwiftTypeRef>(ts_or_err->get ());
2220
+ if (!ts) {
2221
+ result.AppendError (" could not get Swift type system" );
2222
+ return ;
2223
+ }
2224
+
2225
+ addr_t task_addr = task_addr_or_err.get ();
2226
+ // TypeMangling for "Swift.UnsafeCurrentTask"
2227
+ CompilerType task_type =
2228
+ ts->GetTypeFromMangledTypename (ConstString (" $sSctD" ));
2229
+ auto task_sp = ValueObject::CreateValueObjectFromAddress (
2230
+ " current_task" , task_addr, m_exe_ctx, task_type, false );
2231
+ if (auto synthetic_sp = task_sp->GetSyntheticValue ())
2232
+ task_sp = synthetic_sp;
2233
+
2234
+ auto error = task_sp->Dump (result.GetOutputStream ());
2235
+ if (error) {
2236
+ result.AppendErrorWithFormatv (" failed to print current task: {0}" ,
2237
+ toString (std::move (error)));
2238
+ return ;
2239
+ }
2240
+
2241
+ result.SetStatus (lldb::eReturnStatusSuccessFinishResult);
2242
+ }
2243
+ };
2244
+
2186
2245
class CommandObjectLanguageSwiftTask final : public CommandObjectMultiword {
2187
2246
public:
2188
2247
CommandObjectLanguageSwiftTask (CommandInterpreter &interpreter)
@@ -2195,6 +2254,9 @@ class CommandObjectLanguageSwiftTask final : public CommandObjectMultiword {
2195
2254
LoadSubCommand (
2196
2255
" select" ,
2197
2256
CommandObjectSP (new CommandObjectLanguageSwiftTaskSelect (interpreter)));
2257
+ LoadSubCommand (
2258
+ " info" ,
2259
+ CommandObjectSP (new CommandObjectLanguageSwiftTaskInfo (interpreter)));
2198
2260
}
2199
2261
};
2200
2262
@@ -2643,7 +2705,7 @@ std::optional<lldb::addr_t> SwiftLanguageRuntime::TrySkipVirtualParentProlog(
2643
2705
}
2644
2706
2645
2707
llvm::Expected<lldb::addr_t > GetTaskAddrFromThreadLocalStorage (Thread &thread) {
2646
- #if SWIFT_THREADING_USE_DIRECT_TSD
2708
+ #if !SWIFT_THREADING_USE_RESERVED_TLS_KEYS
2647
2709
return llvm::createStringError (
2648
2710
" getting the current task from a thread is not supported" );
2649
2711
#else
0 commit comments