Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

src, test: support reading contents from buffers #116

Merged
merged 2 commits into from
Aug 14, 2017

Conversation

joyeecheung
Copy link
Member

This PR adds support for reading contents from array buffers, typed arrays, and Node buffers (since they are Uint8Arrays).

This currently prints the content like this:

(lldb) v8 inspect 0x00000c20705a94c9
0x00000c20705a94c9:<Object: Object elements {
    [0]=0x00003ea02c904211:<null>,
    [4]=0x00003ea02c904241:<undefined>,
    [23]=0x00000c20705aa9a1:<JSRegExp source=/regexp/>,
    [25]=0x00001a9002c04cb1:<function: c.hashmap.(anonymous function) at /Users/joyee/projects/llnode/test/fixtures/inspect-scenario.js:40:19>}
  properties {
    .some-key=<Smi: 42>,
    .other-key=0x000002ecfb6c8379:<String: "ohai">,
    .cons-string=0x00000c20705a9669:<String: "this could be a ...">,
    .array=0x00000c20705a96f1:<Array: length=6>,
    .long-array=0x00000c20705a97e1:<Array: length=20>,
    .array-buffer=0x00000c20705aa269:<ArrayBuffer: backingStore=0x00000001030012d0, byteLength=5>,
    .uint8-array=0x00000c20705aa3c9:<ArrayBufferView: backingStore=0x0000000103002b70, byteOffset=0, byteLength=6>,
    .buffer=0x00000c20705aa6b1:<ArrayBufferView: backingStore=0x0000000104007200, byteOffset=1296, byteLength=6>,
    .scoped=0x00001a9002c09921:<function: name at /Users/joyee/projects/llnode/test/fixtures/inspect-scenario.js:48:35>}>
(lldb) v8 inspect 0x00000c20705aa269
0x00000c20705aa269:<ArrayBuffer: [ 1, 2, 3, 4, 5 ]>
(lldb) v8 inspect 0x00000c20705aa3c9
0x00000c20705aa3c9:<ArrayBufferView: [ 1, 8, 32, 64, 128, 255 ]>
(lldb) v8 inspect 0x00000c20705aa6b1
0x00000c20705aa6b1:<ArrayBufferView: [ 255, 128, 64, 32, 8, 1 ]>

I have changed the non-detail view of these objects to show the names of each field, so it's now <ArrayBufferView: backingStore=0x0000000104007200, byteOffset=1296, byteLength=6> instead of <ArrayBufferView 0x0000000104007200+1296:6>.

The detailed view currently just prints the content byte by byte separated by commas in one line. At the moment it does not handle endianness, nor does it "merges" the bytes for typed arrays with types other than Uint8, but that can be worked on later.

Also currently it just prints the bytes in decimals like what you get when doing util.inspect on typed arrays in Node.js, I don't have an opinion on what format it's supposed to be, so feel free to give suggestions (e.g. print hexidemals or print it line by line like what memory read in lldb does)

Fixes: #89

cc: @bnoordhuis

Tested on Mac OS 10.12.4 with Node v6.11.1, v4.8.4 and v8.1.4

cjihrig

This comment was marked as off-topic.

@hhellyer
Copy link
Contributor

hhellyer commented Aug 1, 2017

You can do a memory read on the location+offset to location+offset+length to have lldb dump the data and format it as ascii. I like that this change allows us to see the contents of buffers but the detail view (v8 inspect) does lose the details of where and how long the array is. You can only find that out by doing v8 print instead of v8 inspect but it seems odd you need to run the less detailed command in order to do further inspection.

e.g.

(llnode) v8 print 0x00002cb42a6e7721
0x00002cb42a6e7721:<ArrayBufferView: backingStore=0x0000000102858c00, byteOffset=1808, byteLength=20>
(llnode) v8 inspect 0x00002cb42a6e7721
0x00002cb42a6e7721:<ArrayBufferView: [ 104, 101, 108, 108, 111, 44, 32, 73, 39, 109, 32, 97, 32, 98, 117, 102 ... ]>
(llnode) memory read 0x0000000102858c00+1808 0x0000000102858c00+1808+20
0x102859310: 68 65 6c 6c 6f 2c 20 49 27 6d 20 61 20 62 75 66  hello, I'm a buf
0x102859320: 66 65 72 21                                      fer!

The memory read command needs details that are only available from v8 print.

This is a bit of an output format nit (and I should have looked at this sooner) so if no-one else minds I'm happy to land this but should inspect include the location, offset and length as well?

(As an aside it exposes an oddity in that we have --array-length and --string-length options instead of just --length. We can't display an array and string with the same command. I might raise a separate PR to see if we could support ---length and deprecate the --string/--array versions. I don't think both values are used together when formatting any type of object.)

Print byte offset, byte length and location in detailed view. Also print the bytes in hexadecimals
@joyeecheung
Copy link
Member Author

@hhellyer Changed the format printed in detailed view, PTAL. Not it looks like this:

(lldb) v8 inspect 0x00003562e15aa6f9
0x00003562e15aa6f9:<ArrayBufferView: backingStore=0x0000000102044a00, byteOffset=1352, byteLength=6: [
  ff, f0, 80, 0f, 01, 00
]>

(I think printing the bytes as hexadecimals looks nicer, although util.inspect in Node.js prints them in decimals)

Tested with Node v6.11.1, v4.8.4 and v8.2.1. BTW llnode doesn't seem to work properly with 8.3.0 on my Mac (script info looks off). I will open a separate issue for that.

@hhellyer
Copy link
Contributor

@joyeecheung - Looks good, inspect expands the print output nicely. I'll land this shortly.

For anyone else reading the output now looks like:

(llnode) v8 print 0x00002d2fae211321
0x00002d2fae211321:<ArrayBufferView: backingStore=0x0000000103000a00, byteOffset=1976, byteLength=20>
(llnode) v8 inspect 0x00002d2fae211321
0x00002d2fae211321:<ArrayBufferView: backingStore=0x0000000103000a00, byteOffset=1976, byteLength=20: [
  68, 65, 6c, 6c, 6f, 2c, 20, 49, 27, 6d, 20, 61, 20, 62, 75, 66 ...
]>
(llnode) m read 0x0000000103000a00+1976 -c 20
0x1030011b8: 68 65 6c 6c 6f 2c 20 49 27 6d 20 61 20 62 75 66  hello, I'm a buf
0x1030011c8: 66 65 72 21                                      fer!

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.

Reading contents of an Array/ArrayBufferView
3 participants