skip to Main Content

I’m having trouble getting Xcode to show me the underlying memory of a Foundation.Data.

I’m parsing a binary format that’s passed to my function as a blob in a Data. In the debugger Xcode shows me this:

"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.

2

Answers


  1. 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

    Login or Signup to reply.
  2. Based on comments of Alexander and hippietrail, message.payload is of type Data:

    • Cast Data expression, i.c. message.payload to NSData
    • get bytes property from it
    • right-click on expression, select "Print description of (message.payload as NSData).bytes"
    • copy the hexadecimal address printed
    • Debug->Debug Workflow->View Memory
    • Paste the copied address in the "Address" textbox and press return
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search