Skip to content

Commit 5c568d8

Browse files
committed
Make the DWARF version configurable.
This mirrors a similar change in the swift repository.
1 parent 3ddd697 commit 5c568d8

File tree

5 files changed

+38
-2
lines changed

5 files changed

+38
-2
lines changed

Sources/SwiftDriver/Driver/DebugInfo.swift

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,12 @@
4141
}
4242
}
4343

44-
// The format of debug information.
44+
/// The format of debug information.
4545
public let format: Format
4646

47+
/// The DWARF standard version to be produced.
48+
public let dwarfVersion: UInt8
49+
4750
/// The level of debug information.
4851
public let level: Level?
4952

Sources/SwiftDriver/Driver/Driver.swift

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2308,7 +2308,24 @@ extension Driver {
23082308
diagnosticsEngine.emit(.error_argument_not_allowed_with(arg: fullNotAllowedOption, other: levelOption.spelling))
23092309
}
23102310

2311-
return DebugInfo(format: format, level: level, shouldVerify: shouldVerify)
2311+
// Determine the DWARF version.
2312+
var dwarfVersion: UInt8 = 4
2313+
if let versionArg = parsedOptions.getLastArgument(.dwarfVersion) {
2314+
let parsedVersion = UInt8(versionArg.asSingle)
2315+
if parsedVersion != nil && parsedVersion! >= 2 && parsedVersion! <= 5 {
2316+
dwarfVersion = parsedVersion!
2317+
} else {
2318+
diagnosticsEngine.emit(.error_invalid_arg_value(arg: .dwarfVersion, value: versionArg.asSingle))
2319+
}
2320+
}
2321+
2322+
if format == .codeView && (level == .lineTables || level == .dwarfTypes) {
2323+
let levelOption = parsedOptions.getLast(in: .g)!.option
2324+
let fullNotAllowedOption = Option.debugInfoFormat.spelling + format.rawValue
2325+
diagnosticsEngine.emit(.error_argument_not_allowed_with(arg: fullNotAllowedOption, other: levelOption.spelling))
2326+
}
2327+
2328+
return DebugInfo(format: format, dwarfVersion: dwarfVersion, level: level, shouldVerify: shouldVerify)
23122329
}
23132330

23142331
/// Parses the set of `-sanitize={sanitizer}` arguments and returns all the

Sources/SwiftDriver/Jobs/FrontendJobHelpers.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,7 @@ extension Driver {
193193
try commandLine.appendLast(.enablePrivateImports, from: &parsedOptions)
194194
try commandLine.appendLast(in: .g, from: &parsedOptions)
195195
try commandLine.appendLast(.debugInfoFormat, from: &parsedOptions)
196+
try commandLine.appendLast(.dwarfVersion, from: &parsedOptions)
196197
try commandLine.appendLast(.importUnderlyingModule, from: &parsedOptions)
197198
try commandLine.appendLast(.moduleCachePath, from: &parsedOptions)
198199
try commandLine.appendLast(.moduleLinkName, from: &parsedOptions)

Sources/SwiftOptions/Options.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@ extension Option {
109109
public static let debugForbidTypecheckPrefix: Option = Option("-debug-forbid-typecheck-prefix", .separate, attributes: [.helpHidden, .frontend, .noDriver], helpText: "Triggers llvm fatal_error if typechecker tries to typecheck a decl with the provided prefix name")
110110
public static let debugGenericSignatures: Option = Option("-debug-generic-signatures", .flag, attributes: [.helpHidden, .frontend, .noDriver], helpText: "Debug generic signatures")
111111
public static let debugInfoFormat: Option = Option("-debug-info-format=", .joined, attributes: [.frontend], helpText: "Specify the debug info format type to either 'dwarf' or 'codeview'")
112+
public static let dwarfVersion: Option = Option("-dwarf-version=", .joined, attributes: [.frontend], helpText: "DWARF debug info version to produce if requested")
112113
public static let debugInfoStoreInvocation: Option = Option("-debug-info-store-invocation", .flag, attributes: [.frontend], helpText: "Emit the compiler invocation in the debug info.")
113114
public static let debugMapping: Option = Option("-debug-mapping", .flag, attributes: [.noDriver], helpText: "Dumping information for debug purposes")
114115
public static let debugMapping_: Option = Option("--debug-mapping", .flag, alias: Option.debugMapping, attributes: [.noDriver], helpText: "Dumping information for debug purposes")
@@ -907,6 +908,7 @@ extension Option {
907908
Option.debugForbidTypecheckPrefix,
908909
Option.debugGenericSignatures,
909910
Option.debugInfoFormat,
911+
Option.dwarfVersion,
910912
Option.debugInfoStoreInvocation,
911913
Option.debugMapping,
912914
Option.debugMapping_,

Tests/SwiftDriverTests/SwiftDriverTests.swift

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -574,6 +574,19 @@ final class SwiftDriverTests: XCTestCase {
574574
$1.expect(.error("argument '-debug-info-format=codeview' is not allowed with '-gdwarf-types'"))
575575
}
576576

577+
try assertDriverDiagnostics(args: "swiftc", "foo.swift", "-emit-module", "-dwarf-version=0") {
578+
$1.expect(.error("invalid value '0' in '-dwarf-version="))
579+
}
580+
581+
try assertDriverDiagnostics(args: "swiftc", "foo.swift", "-emit-module", "-dwarf-version=6") {
582+
$1.expect(.error("invalid value '6' in '-dwarf-version="))
583+
}
584+
585+
try assertNoDriverDiagnostics(args: "swiftc", "foo.swift", "-emit-module", "-g", "-debug-info-format=dwarf", "-dwarf-version=4") { driver in
586+
let jobs = try driver.planBuild()
587+
XCTAssertTrue(jobs[0].commandLine.contains(.flag("-dwarf-version=4")))
588+
}
589+
577590
try assertNoDriverDiagnostics(args: "swiftc", "foo.swift", "-g", "-c", "-file-compilation-dir", ".") { driver in
578591
let jobs = try driver.planBuild()
579592
XCTAssertTrue(jobs[0].commandLine.contains(.flag("-file-compilation-dir")))

0 commit comments

Comments
 (0)