codelldb
codelldb copied to clipboard
Weird evaluation of char arrays inside a struct (native expressions)
OS: macOS 11.3.1 (20E241) VSCode version: 1.56.2 Extension version: 1.6.3 Compiler: Apple clang version 12.0.5 (C/C++) Build target: x86_64-apple-macosx11.0.0
(Better see the screenshot – I fail at English) In the watch window I get weird evaluation of a sized char arrays inside a struct if I refer to the struct by pointer (native expressions). Same thing inside the locals window looks fine.
Example code:
#include <string.h>
#include <stdlib.h>
typedef struct SomeStruct {
char chars[100];
} SomeStruct;
int main(int argc, char const *argv[]) {
SomeStruct* foo = (SomeStruct*)malloc(sizeof(SomeStruct));
strcpy(foo->chars, "hello!");
return 0;
}
Value of "lldb.dereferencePointers"
doesn't seem to matter.
Excerpts from debug log:
- locals window:
"evaluateName":"foo.chars","name":"chars","type":"char [100]","value":""hello!"","variablesReference":1017`
- watch window:
"evaluateName":"foo.chars","name":"chars","type":"char [100]","value":""\xf0B@"","variablesReference":1018`
Debug log
configuration: { name: 'Launch', type: 'lldb', request: 'launch', program: '${workspaceFolder}/main', expressions: 'native', args: [], __configurationTarget: 5, relativePathBase: '/Volumes/Crucial/projects/3rd_party/vscode/plugins/vadimcn_vscode_lldb/bug_reports/watch_window_char_eval' } liblldb: /Users/anpan/.vscode/extensions/vadimcn.vscode-lldb-1.6.3/lldb/lib/liblldb.dylib environment: {} params: { evaluateForHovers: true, commandCompletions: true } Listening on port 51738 [2021-05-26T12:04:09.777Z DEBUG codelldb] New debug session INFO(Python) 15:04:10 formatters: Initializing INFO(Python) 15:04:10 formatters.rust: Initializing [2021-05-26T12:04:10.065Z DEBUG codelldb::dap_codec] --> {"command":"initialize","arguments":{"clientID":"vscode","clientName":"Visual Studio Code","adapterID":"lldb","pathFormat":"path","linesStartAt1":true,"columnsStartAt1":true,"supportsVariableType":true,"supportsVariablePaging":true,"supportsRunInTerminalRequest":true,"locale":"en-gb","supportsProgressReporting":true,"supportsInvalidatedEvent":true},"type":"request","seq":1} [2021-05-26T12:04:10.065Z DEBUG codelldb::dap_codec] {"command":"launch","arguments":{"name":"Launch","type":"lldb","request":"launch","program":"/Volumes/Crucial/projects/3rd_party/vscode/plugins/vadimcn_vscode_lldb/bug_reports/watch_window_char_eval/main","expressions":"native","args":[],"__configurationTarget":5,"relativePathBase":"/Volumes/Crucial/projects/3rd_party/vscode/plugins/vadimcn_vscode_lldb/bug_reports/watch_window_char_eval","_adapterSettings":{"displayFormat":"auto","showDisassembly":"auto","dereferencePointers":false,"suppressMissingSourceFiles":true,"evaluationTimeout":5,"consoleMode":"commands","sourceLanguages":null,"terminalPromptClear":null,"evaluateForHovers":true,"commandCompletions":true},"__sessionId":"33c0edd5-7bb1-4ab0-a332-aec19e672dae"},"type":"request","seq":2} [2021-05-26T12:04:10.069Z DEBUG codelldb::dap_codec] {"command":"setBreakpoints","arguments":{"source":{"name":"main.c","path":"/Volumes/Crucial/projects/3rd_party/vscode/plugins/vadimcn_vscode_lldb/bug_reports/watch_window_char_eval/main.c"},"lines":[16],"breakpoints":[{"line":16}],"sourceModified":false},"type":"request","seq":3} [2021-05-26T12:04:10.076Z DEBUG codelldb::dap_codec] {"type":"response","seq":4,"command":"runInTerminal","request_seq":3,"success":true,"body":{"shellProcessId":26985}} [2021-05-26T12:04:10.086Z DEBUG codelldb::dap_codec] --> {"command":"setFunctionBreakpoints","arguments":{"breakpoints":[]},"type":"request","seq":5} [2021-05-26T12:04:10.087Z DEBUG codelldb::dap_codec] {"command":"setDataBreakpoints","arguments":{"breakpoints":[]},"type":"request","seq":6} [2021-05-26T12:04:10.097Z DEBUG codelldb::dap_codec] {"command":"setExceptionBreakpoints","arguments":{"filters":["cpp_throw"]},"type":"request","seq":7} [2021-05-26T12:04:10.105Z DEBUG codelldb::dap_codec] {"command":"configurationDone","type":"request","seq":8} [2021-05-26T12:04:10.111Z DEBUG codelldb::dap_codec] {"command":"threads","type":"request","seq":9} [2021-05-26T12:04:10.441Z DEBUG codelldb::dap_codec] [2021-05-26T12:04:10.502Z DEBUG codelldb::debug_session] Debug event: 0x7fc971d8f5e0 Event: broadcaster = 0x7fc973114050 (lldb.process), type = 0x00000001 (state-changed), data = { process = 0x7fc973114018 (pid = 27740), state = stopped} [2021-05-26T12:04:10.502Z DEBUG codelldb::dap_codec] <-- {"type":"event","seq":52,"event":"stopped","body":{"allThreadsStopped":true,"reason":"breakpoint","threadId":262705}} [2021-05-26T12:04:10.511Z DEBUG codelldb::dap_codec] --> {"command":"threads","type":"request","seq":10} [2021-05-26T12:04:10.511Z DEBUG codelldb::dap_codec] <-- {"type":"response","request_seq":10,"success":true,"command":"threads","body":{"threads":[{"id":262705,"name":"1: tid=262705"}]}} [2021-05-26T12:04:10.513Z DEBUG codelldb::dap_codec] --> {"command":"stackTrace","arguments":{"threadId":262705,"startFrame":0,"levels":1},"type":"request","seq":11} [2021-05-26T12:04:10.514Z DEBUG codelldb::dap_codec] <-- {"type":"response","request_seq":11,"success":true,"command":"stackTrace","body":{"stackFrames":[{"column":5,"id":1001,"line":16,"name":"main","source":{"name":"main.c","path":"/Volumes/Crucial/projects/3rd_party/vscode/plugins/vadimcn_vscode_lldb/bug_reports/watch_window_char_eval/main.c"}}],"totalFrames":2}} [2021-05-26T12:04:10.924Z DEBUG codelldb::dap_codec] --> {"command":"scopes","arguments":{"frameId":1001},"type":"request","seq":12} [2021-05-26T12:04:10.924Z DEBUG codelldb::dap_codec] <-- {"type":"response","request_seq":12,"success":true,"command":"scopes","body":{"scopes":[{"expensive":false,"name":"Local","variablesReference":1002},{"expensive":false,"name":"Static","variablesReference":1003},{"expensive":false,"name":"Global","variablesReference":1004},{"expensive":false,"name":"Registers","variablesReference":1005}]}} [2021-05-26T12:04:10.930Z DEBUG codelldb::dap_codec] --> {"command":"variables","arguments":{"variablesReference":1002},"type":"request","seq":13} [2021-05-26T12:04:10.937Z DEBUG codelldb::dap_codec] --> {"command":"stackTrace","arguments":{"threadId":262705,"startFrame":1,"levels":19},"type":"request","seq":14} [2021-05-26T12:04:10.940Z DEBUG codelldb::dap_codec] <-- {"type":"response","request_seq":13,"success":true,"command":"variables","body":{"variables":[{"evaluateName":"argc","name":"argc","type":"int","value":"1","variablesReference":0},{"evaluateName":"argv","name":"argv","type":"const char **","value":"0x00007ffeefbff4e0","variablesReference":1006},{"evaluateName":"foo","name":"foo","type":"SomeStruct *","value":"0x00000001004042f0","variablesReference":1007}]}} [2021-05-26T12:04:10.940Z DEBUG codelldb::disassembly] libdyld.dylib`start + 1 [2021-05-26T12:04:10.940Z DEBUG codelldb::dap_codec] <-- {"type":"response","request_seq":14,"success":true,"command":"stackTrace","body":{"stackFrames":[{"column":0,"id":1008,"line":4,"name":"start","presentationHint":"subtle","source":{"name":"@start","sourceReference":1000}}],"totalFrames":2}} [2021-05-26T12:04:12.951Z DEBUG codelldb::dap_codec] --> {"command":"variables","arguments":{"variablesReference":1007},"type":"request","seq":15} [2021-05-26T12:04:12.951Z DEBUG codelldb::dap_codec] <-- {"type":"response","request_seq":15,"success":true,"command":"variables","body":{"variables":[{"evaluateName":"foo.chars","name":"chars","type":"char [100]","value":""hello!"","variablesReference":1009}]}} [2021-05-26T12:04:15.430Z DEBUG codelldb::dap_codec] --> {"command":"evaluate","arguments":{"expression":"foo","frameId":1001,"context":"watch"},"type":"request","seq":16} [2021-05-26T12:04:15.430Z DEBUG codelldb::dap_codec] --> {"command":"scopes","arguments":{"frameId":1001},"type":"request","seq":17} [2021-05-26T12:04:15.648Z DEBUG codelldb::debug_session] Debug event: 0x7fc971c814d8 Event: broadcaster = 0x7fc9729ed440 (lldb.target), type = 0x00000002 (modules-loaded), data = {__lldb_apple_objc_v2_get_dynamic_class_info2} [2021-05-26T12:04:15.648Z DEBUG codelldb::dap_codec] <-- {"type":"response","request_seq":17,"success":true,"command":"scopes","body":{"scopes":[{"expensive":false,"name":"Local","variablesReference":1011},{"expensive":false,"name":"Static","variablesReference":1012},{"expensive":false,"name":"Global","variablesReference":1013},{"expensive":false,"name":"Registers","variablesReference":1014}]}} [2021-05-26T12:04:15.648Z DEBUG codelldb::debug_session] Debug event: 0x7fc951c10018 Event: broadcaster = 0x7fc9729ed440 (lldb.target), type = 0x00000002 (modules-loaded), data = {__lldb_caller_function} [2021-05-26T12:04:15.648Z DEBUG codelldb::dap_codec] <-- {"type":"event","seq":53,"event":"module","body":{"module":{"id":"__lldb_apple_objc_v2_get_dynamic_class_info2","name":"__lldb_apple_objc_v2_get_dynamic_class_info2","path":"__lldb_apple_objc_v2_get_dynamic_class_info2","symbolStatus":"Symbols not found"},"reason":"new"}} [2021-05-26T12:04:15.648Z DEBUG codelldb::dap_codec] <-- {"type":"event","seq":54,"event":"module","body":{"module":{"id":"__lldb_caller_function","name":"__lldb_caller_function","path":"__lldb_caller_function","symbolStatus":"Symbols not found"},"reason":"new"}} [2021-05-26T12:04:15.648Z DEBUG codelldb::debug_session] Debug event: 0x7fc971fd9ae8 Event: broadcaster = 0x7fc9729ed440 (lldb.target), type = 0x00000002 (modules-loaded), data = {__lldb_apple_objc_v2_get_shared_cache_class_info} [2021-05-26T12:04:15.648Z DEBUG codelldb::debug_session] Debug event: 0x7fc971fdcce8 Event: broadcaster = 0x7fc9729ed440 (lldb.target), type = 0x00000002 (modules-loaded), data = {__lldb_caller_function} [2021-05-26T12:04:15.648Z DEBUG codelldb::dap_codec] <-- {"type":"event","seq":55,"event":"module","body":{"module":{"id":"__lldb_apple_objc_v2_get_shared_cache_class_info","name":"__lldb_apple_objc_v2_get_shared_cache_class_info","path":"__lldb_apple_objc_v2_get_shared_cache_class_info","symbolStatus":"Symbols not found"},"reason":"new"}} [2021-05-26T12:04:15.648Z DEBUG codelldb::dap_codec] <-- {"type":"event","seq":56,"event":"module","body":{"module":{"id":"__lldb_caller_function","name":"__lldb_caller_function","path":"__lldb_caller_function","symbolStatus":"Symbols not found"},"reason":"new"}} [2021-05-26T12:04:15.648Z DEBUG codelldb::dap_codec] <-- {"type":"response","request_seq":16,"success":true,"command":"evaluate","body":{"result":"0x00000001004042f0","type":"SomeStruct *","variablesReference":1010}} [2021-05-26T12:04:15.651Z DEBUG codelldb::dap_codec] --> {"command":"variables","arguments":{"variablesReference":1011},"type":"request","seq":18} [2021-05-26T12:04:15.651Z DEBUG codelldb::dap_codec] <-- {"type":"response","request_seq":18,"success":true,"command":"variables","body":{"variables":[{"evaluateName":"argc","name":"argc","type":"int","value":"1","variablesReference":0},{"evaluateName":"argv","name":"argv","type":"const char **","value":"0x00007ffeefbff4e0","variablesReference":1015},{"evaluateName":"foo","name":"foo","type":"SomeStruct *","value":"0x00000001004042f0","variablesReference":1016}]}} [2021-05-26T12:04:15.655Z DEBUG codelldb::dap_codec] --> {"command":"variables","arguments":{"variablesReference":1016},"type":"request","seq":19} [2021-05-26T12:04:15.656Z DEBUG codelldb::dap_codec] <-- {"type":"response","request_seq":19,"success":true,"command":"variables","body":{"variables":[{"evaluateName":"foo.chars","name":"chars","type":"char [100]","value":""hello!"","variablesReference":1017}]}} [2021-05-26T12:04:17.418Z DEBUG codelldb::dap_codec] --> {"command":"variables","arguments":{"variablesReference":1010},"type":"request","seq":20} [2021-05-26T12:04:17.418Z DEBUG codelldb::dap_codec] <-- {"type":"response","request_seq":20,"success":true,"command":"variables","body":{"variables":[{"evaluateName":"foo.chars","name":"chars","type":"char [100]","value":""\xf0B@"","variablesReference":1018}]}}
Sorry for the barrage of "reports" 🥺
Looks like a LLDB bug: I can reproduce it in the CLI version as well:
(lldb) expr --ptr-depth=1 -- foo
(SomeStruct *) $39 = 0x00005555555592a0 {
chars = "\xa0\x92UUUU"
}
Sorry about that. I only checked:
(lldb) p foo->chars
(char [100]) $14 = "hello!"
Which obviously works. Didn't know that is not how you get stuff from lldb, my bad.