Home > front end >  How to inspect the bytes contained in a "Foundation.Data" byte buffer in Xcode?
How to inspect the bytes contained in a "Foundation.Data" byte buffer in Xcode?

Time:08-22

I'm having trouble getting Xcode to show me the underlying memory of a "data" as I can view it in the debug panel

I can control-click on any of those and choose 'View Memory of "data"' etc, but none of them show the memory block I'm looking for. (I know this because I print() the first few bytes accessed via the subscript operator data[0] etc.)

  • _representation shows me address 0x0
  • slice (1) shows me memory but not what I'm looking for
  • slice (2) shows me the same as the previous one
  • lowerBound shows me the same as the previous two
  • upperBound shows me some other memory not what I'm looking for
  • storage shows me address 0x0

I'm used to languages more like C where I'd have a pointer or array.

I've also tried stepping through the disassembly while viewing the registers where the code is indexing into the data but I'm not used to ARM asm and can't seem to find the address I'm looking for that way either.

(No, it's not the memory at 0x40006000022804b0)


desired behavior

View the bytes encapsulated by the Data

specific problem or error

Every component of the Data that the debugger presents to me shows either nothing or bytes other than what I'm looking for when I use the context menu "View Memory of ..."

and the shortest code necessary to reproduce the problem

This problem is not about my code. It's about how to get the Xcode debugger to show me the underlying memory of an object.

CodePudding user response:

Data has multiple different backing storage strategies (e.g. one for slicing, one for bridging to Objective C, etc.)

0x40006000022804b0 contains a Foundation.__DataStorage object. It has a _bytes property which is where the actual buffer is. It's exposed -[NSData bytes], which you can print out for debugging purposes

  • Related