vadimcn / codelldb

A native debugger extension for VSCode based on LLDB
https://marketplace.visualstudio.com/items?itemName=vadimcn.vscode-lldb
MIT License
2.42k stars 237 forks source link

Evaluate request: return memory reference for integral values #1043

Closed puremourning closed 5 months ago

puremourning commented 6 months ago

If the evaluation result looks like an integer literal, then provide that as a memory reference, allowing the user to dump arbitrary addresses e.g. by typing htem in or casting some variable to (void*).


In general, given an explicit memory value, we can now "dump" memory at that address, so say we have the following code:

  unsigned char data[1024];
  Foo f{ 10, 20, 30.7f };

  memcpy(data + 3, &f, sizeof(Foo));

We may want to inspect the memory pointed to by data. If we put data in the evaluator, we get a stringified representation. Instead we can put (void*)data or just the actual integral value and the result can be used with the "read memory" request to view the output:

Watches: ----
Expression: (void*)data
 *- Result: 0x000000016fdfe8d8
Memory at address 0x000000016fdfe8d8
--------------------------------------------------------------------------------------
Address             Bytes                                             Text
--------------------------------------------------------------------------------------
0x000000016FDFE8D8: 00 00 00 0A 00 00 00 00  00 00 00 14 00 00 00 00  ................
0x000000016FDFE8E8: 00 00 00 9A 99 F5 41 00  00 00 00 00 00 00 00 00  ......A.........
0x000000016FDFE8F8: 00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  ................
0x000000016FDFE908: 00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  ................
0x000000016FDFE918: 00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  ................
0x000000016FDFE928: 00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  ................
0x000000016FDFE938: 00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  ................
puremourning commented 6 months ago

Basically, implementing this TODO:

                    // TODO: if it's a literal and looks like an address (e.g. some
                    // sort of integer, use that as the addres)
puremourning commented 5 months ago

@vadimcn any interest in this PR?

vadimcn commented 5 months ago

@vadimcn any interest in this PR?

Mmmm, probably not. Normal variables are typed, so we can tell what was intended to be a pointer and what wasn't. I think that assuming any random integer could be a pointer is a bit too much.

puremourning commented 5 months ago

Cheers. On the general concept (dump arbitrary address, or memory around pointer) are you onboard with doing something though? It’s a real use case I’ve come across a number of times and had to (sadly) downshift to cpptools or command line a few times.

If so, I’ll take another look to see if there’s a way to do this more robustly. Such as including the memory reference on all pointer values regardless of representation.