Skip to content

Conversation

@carlpeto
Copy link
Contributor

Refactoring the JSON writer in swift-backtrace to allow its reuse. This will be used by the new swift-symbolicate tool.

Currently this is in draft for feedback and is not yet complete. The shared JSON formatting code has been moved into the Runtime module.

Copy link
Contributor

@al45tair al45tair left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should make BacktraceJSONFormatter a little bit more like BacktraceFormatter, API-wise; I don't think it should be a protocol, with users of the type expected to implement methods from that protocol — rather, I think a lot of those functions should really be handled via a BacktraceJSONFormatterOptions struct.

Also, this PR needs a proper title :-) But you knew that already.

// Provides functionality to format JSON backtraces.
//
//===----------------------------------------------------------------------===//
import Swift
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: Let's have a blank line above this:

Suggested change
import Swift
import Swift

Comment on lines +40 to +54
static func getDescription() -> String?
static func getArchitecture() -> String?
static func getPlatform() -> String?
static func getFaultAddress() -> String?
static func allThreads() -> [ThreadType]
static func crashingThreadIndex() -> Int?
static func writeThreadRegisters(thread: ThreadType, capturedBytes: inout [UInt64:Array<UInt8>])
static func getImages() -> ImageMap?

// settings for the output format
static func getShouldShowAllThreads() -> Bool
static func getShouldShowAllRegisters() -> Bool
static func getShouldDemangle() -> Bool
static func getShouldSanitize() -> Bool
static func getShowMentionedImages() -> Bool
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMO most of these should be options in an option type, see e.g. the BacktraceFormattingOptions type in BacktraceFormatter.swift.

It's not obvious from its name what writeThreadRegisters is supposed to do, or why it's a part of this protocol. Maybe that will become clearer as I read through the code below.

Comment on lines +157 to +158
mentionedImages: inout Set<Int>,
capturedBytes: inout [UInt64:Array<UInt8>]) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are these inout? We don't modify them, do we?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmmm. We do modify them, because BacktraceJSONFormatter is a protocol rather than being a class or struct, so there's no state.

I think BacktraceJSONFormatter should be a class or struct (I'll leave which up to you — it doesn't matter too much unless we're going to pass them around), and the mentionedImages and capturedBytes variables should be member variables. The constructor for BacktraceJSONFormatter should take a BacktraceJSONFormatterOptions argument, and it should have a format(backtrace: Backtrace) method and a format(backtrace: SymbolicatedBacktrace) method.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants