How to debug EXC_BREAKPOINT (SIGTRAP)

Hello,

I am getting an EXC_BREAKPOINT and trying figure out how to debug this crash.

Some background on func getDecodeResults(noOfDecodes: ) which the crashlog is pointing to:

I believe this crash might be related to the unsafe pointers I'm using for communication between our C code and Swift. Below are the relevant implementation details:

  1. I create an UnsafeMutablePointer for a struct type DECODE_RESULTS, defined internally.
  2. The Swift code allocates fixed memory for this pointer, which is then passed to a C library for initialization and modification.
  3. In the getDecodeResults function (where the crash log points), the first step is converting a C array starting at the UnsafeMutablePointer into a Swift array.

Here’s a snippet for context:

// In class initialization:
private var decodeResults: UnsafeMutablePointer<DECODE_RESULTS>
decodeResults = UnsafeMutablePointer<DECODE_RESULTS>.allocate(capacity: maxNumberOfBarcodes)
// Initialize decodeResults in the C library

// In getDecodeResults function:
let results = Array(UnsafeBufferPointer(start: decodeResults, count: Int(noOfDecodes)))

Crash Log:

Thread 6 name:   Dispatch queue: com.padlocdocks.padlocscan.PLSBarcodeScanner._scanQueue  
Thread 6 Crashed:  
0   AilaDecoder                    0x101d995a8 DecoderManager.getDecodeResults(noOfDecodes:) (in AilaDecoder) (DecoderManager.swift:0) + 38312  

I'm unsure if (DecoderManager.swift:0) indicates the root cause or if it’s an erroneous reference.

Consider your crashing thread backtrace:

Thread 6 Crashed:
0   AilaDecoder 0x101d995a8 DecoderManager.getDecodeResults(noOfDecodes:) (in AilaDecoder) (DecoderManager.swift:0) + 38312
1   AilaDecoder 0x101da58b8 specialized DecoderManager.bufferDecode(sampleBuffer:completion:) (in AilaDecoder) (DecoderManager.swift:385) + 88248
2   AilaDecoder 0x101dbc164 @objc CDDecoder.decode(sampleBuffer:completion:) (in AilaDecoder) (/:0) + 180580
3   Aila        0x10093c340 -[PLSImageScanWrapper multiScanSampleBuffer:withCaptureOutput:] + 292

The offset in frame 3, 292, seems reasonable. The offsets in the lower frames seem way too large. Moreover, frames 2 and 0 are definitely compiler generated, indicated by the :0 line number. OTOH, the line number in frame 1, DecoderManager.swift:385, seems reasonable enough.

In the code snippet you posted, what is line 385?

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

Hi Qinn,

Line 385 in the code contains a call to the function getDecodeResults.

Is it possible to determine where the crash might be occurring using the backtrace? Most of the code in getDecodeResults is straightforward, and I don’t see any immediate issues. However, the first line of the function involves converting a C array into a Swift array, which I am a bit unfamiliar with and think might be the root cause.

Snippet for C to Swift Array Conversion:

let results = Array(UnsafeBufferPointer(start: decodeResults, count: Int(noOfDecodes)))

decodeResults above is of type UnsafeMutablePointer<DECODE_RESULTS>

This crash is rare, takes about 8-10 days of continuous app usage for us.

How to debug EXC_BREAKPOINT (SIGTRAP)
 
 
Q