eclipse-cdt-cloud / cdt-gdb-adapter

CDT GDB Debug Adapter
Eclipse Public License 2.0
28 stars 40 forks source link

Error: -var-create: unable to create variable object #235

Closed jonahgraham closed 1 year ago

jonahgraham commented 1 year ago

I am seeing errors of the form Error: -var-create: unable to create variable object when clicking through multiple frames in a thread.

This is happening because the --frame argument is not consistently passed to GDB, leading some calls to be using the wrong frame. --frame is being omitted when frameId == 0.

jonahgraham commented 1 year ago

Here is a full trace of the problem:

From client: scopes({"frameId":1004})
To client: {"seq":0,"type":"response","request_seq":12,"command":"scopes","success":true,"body":{"scopes":[{"name":"Local","variablesReference":1007,"expensive":false},{"name":"Registers","variablesReference":1008,"expensive":true}]}}
From client: variables({"variablesReference":1007})
GDB command: 22 -stack-info-depth 100
GDB result: 22 done,depth="3"
GDB command: 23 -stack-list-variables --thread 4 --frame 1 --simple-values
GDB result: 23 done,variables=[{name="ret",type="void *",value="<optimized out>"},{name="arg",arg="1",type="void *",value="<optimized out>"},{name="pd",type="struct pthread *",value="<optimized out>"},{name="unwind_buf",type="struct pthread_unwind_buf"},{name="not_first_call",type="int",value="0"}]
GDB command: 24 -var-create --thread 4 --frame 1 - * "ret"
GDB result: 24 done,name="var8",numchild="0",value="<optimized out>",type="void *",thread-id="4",has_more="0"
GDB command: 25 -var-create --thread 4 --frame 1 - * "arg"
GDB result: 25 done,name="var9",numchild="0",value="<optimized out>",type="void *",thread-id="4",has_more="0"
GDB command: 26 -var-create --thread 4 --frame 1 - * "pd"
GDB result: 26 done,name="var10",numchild="37",value="<optimized out>",type="struct pthread *",thread-id="4",has_more="0"
GDB command: 27 -var-create --thread 4 --frame 1 - * "unwind_buf"
GDB result: 27 done,name="var11",numchild="2",value="{...}",type="struct pthread_unwind_buf",thread-id="4",has_more="0"
GDB command: 28 -var-create --thread 4 --frame 1 - * "not_first_call"
GDB result: 28 done,name="var12",numchild="0",value="0",type="int",thread-id="4",has_more="0"
To client: {"seq":0,"type":"response","request_seq":13,"command":"variables","success":true,"body":{"variables":[{"name":"ret","value":"<optimized out>","type":"void *","memoryReference":"&(ret)","variablesReference":0},{"name":"arg","value":"<optimized out>","type":"void *","memoryReference":"&(arg)","variablesReference":0},{"name":"pd","value":"<optimized out>","type":"struct pthread *","memoryReference":"&(pd)","variablesReference":1009},{"name":"unwind_buf","value":"{...}","type":"struct pthread_unwind_buf","memoryReference":"&(unwind_buf)","variablesReference":1010},{"name":"not_first_call","value":"0","type":"int","memoryReference":"&(not_first_call)","variablesReference":0}]}}
From client: scopes({"frameId":1003})
To client: {"seq":0,"type":"response","request_seq":14,"command":"scopes","success":true,"body":{"scopes":[{"name":"Local","variablesReference":1011,"expensive":false},{"name":"Registers","variablesReference":1012,"expensive":true}]}}
From client: variables({"variablesReference":1011})
GDB command: 29 -stack-info-depth 100
GDB result: 29 done,depth="3"
GDB command: 30 -stack-list-variables --thread 4 --simple-values
GDB result: 30 done,variables=[{name="ret",type="void *",value="<optimized out>"},{name="arg",arg="1",type="void *",value="<optimized out>"},{name="pd",type="struct pthread *",value="<optimized out>"},{name="unwind_buf",type="struct pthread_unwind_buf"},{name="not_first_call",type="int",value="0"}]
GDB command: 31 -var-create --thread 4 --frame 0 - * "ret"
GDB result: 31 error,msg="-var-create: unable to create variable object"
To client: {"seq":0,"type":"response","request_seq":15,"command":"variables","success":false,"body":{"variables":[],"error":{"id":1,"format":"-var-create: unable to create variable object","showUser":true}},"message":"-var-create: unable to create variable object"}

The last -var-create is failing because the correct frame is being passed to it, but the call above 30 -stack-list-variables is missing the --frame 0, so it is reporting the variables of frame 1 as can be seen higher up in the trace