3
3
#include " lldb/Core/Module.h"
4
4
#include " lldb/Symbol/Function.h"
5
5
#include " lldb/Symbol/SymbolContext.h"
6
+ #include " lldb/Target/Platform.h"
6
7
#include " lldb/Target/Process.h"
7
8
#include " lldb/Target/StackFrameRecognizer.h"
8
9
#include " lldb/Target/Target.h"
9
10
#include " lldb/Target/Thread.h"
10
11
12
+ #include " lldb/Utility/ConstString.h"
13
+ #include " lldb/Utility/FileSpec.h"
11
14
#include " lldb/Utility/LLDBLog.h"
12
15
#include " lldb/Utility/Log.h"
13
16
@@ -222,6 +225,66 @@ class SwiftHiddenFrameRecognizer : public StackFrameRecognizer {
222
225
}
223
226
};
224
227
228
+ // / A frame recognizer for Swift exception breakpoints.
229
+ class SwiftExceptionBreakpointFrameRecognizer : public StackFrameRecognizer {
230
+ public:
231
+ class SwiftExceptionFrame : public RecognizedStackFrame {
232
+ public:
233
+ SwiftExceptionFrame (StackFrameSP frame) : m_frame_sp(frame) {
234
+ m_stop_desc = " Swift exception breakpoint" ;
235
+ }
236
+
237
+ StackFrameSP GetMostRelevantFrame () override {
238
+ if (!m_frame_sp)
239
+ return {};
240
+
241
+ auto thread_sp = m_frame_sp->GetThread ();
242
+ if (!thread_sp)
243
+ return {};
244
+
245
+ StringRef symbol_name;
246
+ {
247
+ const SymbolContext &sc =
248
+ m_frame_sp->GetSymbolContext (eSymbolContextSymbol);
249
+ if (!sc.symbol )
250
+ return {};
251
+ symbol_name = sc.symbol ->GetName ();
252
+ }
253
+
254
+ StackFrameSP relevant_frame_sp;
255
+ if (symbol_name == " swift_willThrow" )
256
+ relevant_frame_sp = thread_sp->GetStackFrameAtIndex (1 );
257
+ else if (symbol_name == " swift_willThrowTypedImpl" )
258
+ relevant_frame_sp = thread_sp->GetStackFrameAtIndex (2 );
259
+ else {
260
+ assert (false && " unexpected frame name" );
261
+ return {};
262
+ }
263
+
264
+ if (relevant_frame_sp) {
265
+ // Select the relevant frame only if source is available.
266
+ const SymbolContext &sc =
267
+ relevant_frame_sp->GetSymbolContext (eSymbolContextCompUnit);
268
+ if (sc.comp_unit )
269
+ return relevant_frame_sp;
270
+ }
271
+
272
+ return {};
273
+ }
274
+
275
+ private:
276
+ StackFrameSP m_frame_sp;
277
+ };
278
+
279
+ RecognizedStackFrameSP RecognizeFrame (StackFrameSP frame) override {
280
+ return std::make_shared<SwiftExceptionFrame>(frame);
281
+ };
282
+
283
+ std::string GetName () override {
284
+ return " Swift exception breakpoint frame recognizer" ;
285
+ }
286
+ };
287
+
225
288
void RegisterSwiftFrameRecognizers (Process &process) {
226
289
RegularExpressionSP module_regex_sp = nullptr ;
227
290
auto &manager = process.GetTarget ().GetFrameRecognizerManager ();
@@ -247,6 +310,16 @@ void RegisterSwiftFrameRecognizers(Process &process) {
247
310
manager.AddRecognizer (srf_sp, module_regex_sp, symbol_regex_sp,
248
311
Mangled::NamePreference::ePreferMangled, false );
249
312
}
313
+ {
314
+ auto srf_sp = std::make_shared<SwiftExceptionBreakpointFrameRecognizer>();
315
+ ConstString module_name = ConstString (" swiftCore" );
316
+ if (auto platform_sp = process.GetTarget ().GetPlatform ())
317
+ module_name = platform_sp->GetFullNameForDylib (module_name);
318
+ manager.AddRecognizer (srf_sp, module_name,
319
+ {ConstString (" swift_willThrow" ),
320
+ ConstString (" swift_willThrowTypedImpl" )},
321
+ Mangled::NamePreference::ePreferMangled, false );
322
+ }
250
323
}
251
324
252
325
} // namespace lldb_private
0 commit comments