@@ -351,6 +351,80 @@ static void SetupDefaultClangDiagnostics(CompilerInstance &compiler) {
351
351
}
352
352
}
353
353
354
+ // / Returns a string representing current ABI.
355
+ // /
356
+ // / \param[in] target_arch
357
+ // / The target architecture.
358
+ // /
359
+ // / \return
360
+ // / A string representing target ABI for the current architecture.
361
+ static std::string GetClangTargetABI (const ArchSpec &target_arch) {
362
+ std::string abi;
363
+
364
+ if (target_arch.IsMIPS ()) {
365
+ switch (target_arch.GetFlags () & ArchSpec::eMIPSABI_mask) {
366
+ case ArchSpec::eMIPSABI_N64:
367
+ abi = " n64" ;
368
+ break ;
369
+ case ArchSpec::eMIPSABI_N32:
370
+ abi = " n32" ;
371
+ break ;
372
+ case ArchSpec::eMIPSABI_O32:
373
+ abi = " o32" ;
374
+ break ;
375
+ default :
376
+ break ;
377
+ }
378
+ }
379
+ return abi;
380
+ }
381
+
382
+ static void SetupTargetOpts (CompilerInstance &compiler,
383
+ lldb_private::Target const &target) {
384
+ Log *log = GetLog (LLDBLog::Expressions);
385
+ ArchSpec target_arch = target.GetArchitecture ();
386
+
387
+ const auto target_machine = target_arch.GetMachine ();
388
+ if (target_arch.IsValid ()) {
389
+ std::string triple = target_arch.GetTriple ().str ();
390
+ compiler.getTargetOpts ().Triple = triple;
391
+ LLDB_LOGF (log, " Using %s as the target triple" ,
392
+ compiler.getTargetOpts ().Triple .c_str ());
393
+ } else {
394
+ // If we get here we don't have a valid target and just have to guess.
395
+ // Sometimes this will be ok to just use the host target triple (when we
396
+ // evaluate say "2+3", but other expressions like breakpoint conditions and
397
+ // other things that _are_ target specific really shouldn't just be using
398
+ // the host triple. In such a case the language runtime should expose an
399
+ // overridden options set (3), below.
400
+ compiler.getTargetOpts ().Triple = llvm::sys::getDefaultTargetTriple ();
401
+ LLDB_LOGF (log, " Using default target triple of %s" ,
402
+ compiler.getTargetOpts ().Triple .c_str ());
403
+ }
404
+ // Now add some special fixes for known architectures: Any arm32 iOS
405
+ // environment, but not on arm64
406
+ if (compiler.getTargetOpts ().Triple .find (" arm64" ) == std::string::npos &&
407
+ compiler.getTargetOpts ().Triple .find (" arm" ) != std::string::npos &&
408
+ compiler.getTargetOpts ().Triple .find (" ios" ) != std::string::npos) {
409
+ compiler.getTargetOpts ().ABI = " apcs-gnu" ;
410
+ }
411
+ // Supported subsets of x86
412
+ if (target_machine == llvm::Triple::x86 ||
413
+ target_machine == llvm::Triple::x86_64) {
414
+ compiler.getTargetOpts ().FeaturesAsWritten .push_back (" +sse" );
415
+ compiler.getTargetOpts ().FeaturesAsWritten .push_back (" +sse2" );
416
+ }
417
+
418
+ // Set the target CPU to generate code for. This will be empty for any CPU
419
+ // that doesn't really need to make a special
420
+ // CPU string.
421
+ compiler.getTargetOpts ().CPU = target_arch.GetClangTargetCPU ();
422
+
423
+ // Set the target ABI
424
+ if (std::string abi = GetClangTargetABI (target_arch); !abi.empty ())
425
+ compiler.getTargetOpts ().ABI = std::move (abi);
426
+ }
427
+
354
428
// ===----------------------------------------------------------------------===//
355
429
// Implementation of ClangExpressionParser
356
430
// ===----------------------------------------------------------------------===//
@@ -395,12 +469,6 @@ ClangExpressionParser::ClangExpressionParser(
395
469
// Defaults to lldb::eLanguageTypeUnknown.
396
470
lldb::LanguageType frame_lang = expr.Language ().AsLanguageType ();
397
471
398
- std::string abi;
399
- ArchSpec target_arch;
400
- target_arch = target_sp->GetArchitecture ();
401
-
402
- const auto target_machine = target_arch.GetMachine ();
403
-
404
472
// If the expression is being evaluated in the context of an existing stack
405
473
// frame, we introspect to see if the language runtime is available.
406
474
@@ -419,45 +487,7 @@ ClangExpressionParser::ClangExpressionParser(
419
487
420
488
// 2. Configure the compiler with a set of default options that are
421
489
// appropriate for most situations.
422
- if (target_arch.IsValid ()) {
423
- std::string triple = target_arch.GetTriple ().str ();
424
- m_compiler->getTargetOpts ().Triple = triple;
425
- LLDB_LOGF (log, " Using %s as the target triple" ,
426
- m_compiler->getTargetOpts ().Triple .c_str ());
427
- } else {
428
- // If we get here we don't have a valid target and just have to guess.
429
- // Sometimes this will be ok to just use the host target triple (when we
430
- // evaluate say "2+3", but other expressions like breakpoint conditions and
431
- // other things that _are_ target specific really shouldn't just be using
432
- // the host triple. In such a case the language runtime should expose an
433
- // overridden options set (3), below.
434
- m_compiler->getTargetOpts ().Triple = llvm::sys::getDefaultTargetTriple ();
435
- LLDB_LOGF (log, " Using default target triple of %s" ,
436
- m_compiler->getTargetOpts ().Triple .c_str ());
437
- }
438
- // Now add some special fixes for known architectures: Any arm32 iOS
439
- // environment, but not on arm64
440
- if (m_compiler->getTargetOpts ().Triple .find (" arm64" ) == std::string::npos &&
441
- m_compiler->getTargetOpts ().Triple .find (" arm" ) != std::string::npos &&
442
- m_compiler->getTargetOpts ().Triple .find (" ios" ) != std::string::npos) {
443
- m_compiler->getTargetOpts ().ABI = " apcs-gnu" ;
444
- }
445
- // Supported subsets of x86
446
- if (target_machine == llvm::Triple::x86 ||
447
- target_machine == llvm::Triple::x86_64) {
448
- m_compiler->getTargetOpts ().FeaturesAsWritten .push_back (" +sse" );
449
- m_compiler->getTargetOpts ().FeaturesAsWritten .push_back (" +sse2" );
450
- }
451
-
452
- // Set the target CPU to generate code for. This will be empty for any CPU
453
- // that doesn't really need to make a special
454
- // CPU string.
455
- m_compiler->getTargetOpts ().CPU = target_arch.GetClangTargetCPU ();
456
-
457
- // Set the target ABI
458
- abi = GetClangTargetABI (target_arch);
459
- if (!abi.empty ())
460
- m_compiler->getTargetOpts ().ABI = abi;
490
+ SetupTargetOpts (*m_compiler, *target_sp);
461
491
462
492
// 3. Create and install the target on the compiler.
463
493
m_compiler->createDiagnostics ();
@@ -1179,28 +1209,6 @@ ClangExpressionParser::ParseInternal(DiagnosticManager &diagnostic_manager,
1179
1209
return num_errors;
1180
1210
}
1181
1211
1182
- std::string
1183
- ClangExpressionParser::GetClangTargetABI (const ArchSpec &target_arch) {
1184
- std::string abi;
1185
-
1186
- if (target_arch.IsMIPS ()) {
1187
- switch (target_arch.GetFlags () & ArchSpec::eMIPSABI_mask) {
1188
- case ArchSpec::eMIPSABI_N64:
1189
- abi = " n64" ;
1190
- break ;
1191
- case ArchSpec::eMIPSABI_N32:
1192
- abi = " n32" ;
1193
- break ;
1194
- case ArchSpec::eMIPSABI_O32:
1195
- abi = " o32" ;
1196
- break ;
1197
- default :
1198
- break ;
1199
- }
1200
- }
1201
- return abi;
1202
- }
1203
-
1204
1212
// / Applies the given Fix-It hint to the given commit.
1205
1213
static void ApplyFixIt (const FixItHint &fixit, clang::edit::Commit &commit) {
1206
1214
// This is cobbed from clang::Rewrite::FixItRewriter.
0 commit comments