microsoft / microsoft/vscode-cpptools

Incorrect Memory address return by Cppvsdbg debugger for memory inspection

Open
#13,589 3 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

bug debugger Visual Studio
Dominant language
TypeScript
Stars
6.2k
Forks
1.7k
Avg merge
14h 46m
Merged PRs (30d)
61

Description

Environment

Environment: Windows
Debugger : Cppvsdbg
Language: C/C++

Bug Summary and Steps to Reproduce

Bug Summary:
While debugging C/C++ application using cppvsdbg, If you click the little memory icon when you hover mouse in variable (like integer type) in VARIABLES window, then VSCode will open hex code editor and show memory binary representation in the hex editor window. Cppvsdbg is sending wrong memory address in the hex editor.

Steps to reproduce:

  1. In Windows, Create a simple hello world application with some int / float/ double variable.
  2. Create a launch.json file for debugging C/C++ application using "cppvsdbg" type.
  3. Click Run & Debug icon the side panel then click Run with your launch.json profile.
  4. After launching the debugger, hover your mouse in an variable in "VARIABLE" window.
  5. Hex editor will open and show incorrect memory address for the variable.

Image

Debugger Configurations
{
    "version": "0.2.0",
    "configurations": [
      {
        "name": "C/C++: cl.exe build and debug active file",
        "type": "cppvsdbg",
        "request": "launch",
        "program": "${fileDirname}\\${fileBasenameNoExtension}.exe",
        "args": [],
        "stopAtEntry": false,
        "cwd": "${workspaceFolder}",
        "environment": [],
        "logging": {
          "trace": true,
          "traceResponse": true,
          "engineLogging": true
        }
      },
    ],
  }
Debugger Logs
### Take a look value2 memoryReference value in "Scope" mode vs "presentationHint"

#################### DAP message for getting address of an integer variable (e.g: &value2) int watch window ######
-> (C) {"command":"evaluate","arguments":{"expression":"&value2","frameId":1000,"context":"watch"},"type":"request","seq":22}
-> (C) {"command":"scopes","arguments":{"frameId":1000},"type":"request","seq":23}
<- (R) {"seq":159,"type":"response","request_seq":23,"success":true,"command":"scopes","body":{"scopes":[{"name":"Locals","variablesReference":1022,"expensive":false},{"name":"Registers","presentationHint":"registers","variablesReference":1023,"expensive":true}]}}
<- (R) {"seq":161,"type":"response","request_seq":22,"success":true,"command":"evaluate","body":{"result":"0x000000a7d4bcfb50 {1065353215}","type":"int *","presentationHint":{"attributes":["readOnly"]},"variablesReference":1024,"memoryReference":"0x000000A7D4BCFB50","evaluateResponseReference":1024}}

################## variable window DAP message ########################
(C) {"command":"variables","arguments":{"variablesReference":1010},"type":"request","seq":16}
<- (R) {"seq":140,"type":"response","request_seq":16,"success":true,"command":"variables","body":{"variables":[{"name":"byteArray","value":"{ size=4 }","type":"std::vector<unsigned char,std::allocator<unsigned char>>","presentationHint":{"kind":"data","attributes":["readOnly"]},"evaluateName":"byteArray","variablesReference":1012},{"name":"cstr","value":"0x0000022cff493b00 \"˜9¸{ö\"","type":"const char *","presentationHint":{"kind":"data","attributes":["rawString"]},"evaluateName":"cstr","variablesReference":1013,"memoryReference":"0x0000022CFF493B00"},{"name":"doubleAsFloat","value":"3.61283159","type":"float","presentationHint":{"kind":"data"},"evaluateName":"doubleAsFloat","variablesReference":0},{"name":"doubleNumber","value":"3.6128315516282616","type":"double","presentationHint":{"kind":"data"},"evaluateName":"doubleNumber","variablesReference":0},{"name":"f","value":"0x000000a7d4bcfb50 {0.999999940}","type":"float *","presentationHint":{"kind":"data"},"evaluateName":"f","variablesReference":1014,"memoryReference":"0x000000A7D4BCFB50"},{"name":"f2","value":"0.999999940","type":"float","presentationHint":{"kind":"data"},"evaluateName":"f2","variablesReference":0},{"name":"floatNum","value":"0x0000022cff496760 {0.999999940}","type":"float *","presentationHint":{"kind":"data"},"evaluateName":"floatNum","variablesReference":1015,"memoryReference":"0x0000022CFF496760"},{"name":"magicNumber","value":"126","type":"int","presentationHint":{"kind":"data"},"evaluateName":"magicNumber","variablesReference":0,"memoryReference":"0x000000000000007E"},{"name":"message","value":"{ size=6 }","type":"std::vector<std::string,std::allocator<std::string>>","presentationHint":{"kind":"data","attributes":["readOnly"]},"evaluateName":"message","variablesReference":1016},{"name":"mg","value":"100","type":"int","presentationHint":{"kind":"data"},"evaluateName":"mg","variablesReference":0,"memoryReference":"0x0000000000000064"},{"name":"str","value":"\"\\x1\"","type":"std::string","presentationHint":{"kind":"data","attributes":["readOnly","rawString"]},"evaluateName":"str","variablesReference":1017},{"name":"text","value":"\"hello Meta !! nice to meet you. I am from Bangladesh and went to BUET and Starting Microsoft\"","type":"std::string","presentationHint":{"kind":"data","attributes":["readOnly","rawString"]},"evaluateName":"text","variablesReference":1018},{"name":"value2","value":"1065353215","type":"int","presentationHint":{"kind":"data"},"evaluateName":"value2","variablesReference":0,"memoryReference":"0x000000003F7FFFFF"}]}}
#################################### end #########################
Other Extensions

No response

Additional Information

No response

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by tracing the cppvsdbg DAP responses for variables and evaluate requests, using the reported memoryReference values as the reproduction evidence. Compare the address returned for scalar variables such as value2 with the address returned for pointer variables, then verify that the Variables view's memory action opens the variable's actual address.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp, typescript, vscode
Domain
devtools
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.