Skip to content

Watching local variables of types vectors, maps etc. is empty when debugging C++ with lldb #1768

@socuwn

Description

@socuwn
  • VSCode Version Insiders: March 2018 v1.22
  • VSCode Version Stable: February 2018 v1.21
    (Same thing happens on both)
  • OS Version: macOS High Sierra 10.13.3
  • C/C++ extension version: 0.16.1

Steps to Reproduce:

// app.cpp
#include <iostream>
#include <vector>
#include <map>
#include <string>

int main() {
	int i = 4;
	std::string s = "four";
	std::vector<int> v;
	std::map<int,std::string> m;
	v.push_back(2);
	v.push_back(1);
	v.push_back(3);
	m.insert(std::make_pair(2,"two"));
	m.insert(std::make_pair(1,"one"));
	m.insert(std::make_pair(3,"three"));
}
// launch.json
{
        
	"version": "0.2.0",
	"configurations": [
		{
			"name": "(lldb) Launch",
			"type": "cppdbg",
			"request": "launch",
			"program": "${workspaceFolder}/app",
			"args": [],
			"stopAtEntry": false,
			"cwd": "${workspaceFolder}",
			"environment": [],
			"externalConsole": false,
			"MIMode": "lldb"
		}
	]
}

Built with:
g++ -o app app.cpp -g -Wall -std=c++17 -lstdc++

Watchlist shows this at breakpoint for last statement in main:

i: 4
s: "four"
v: size=0
m: size=0

Using lldb manually from terminal shows correct content of v, and m:

Process 8715 stopped
* thread #1, queue = 'com.apple.main-thread', stop reason = breakpoint 1.1
    frame #0: 0x00000001000018d5 app`main at app.cpp:18
   15           v.push_back(3);
   16           m.insert(std::make_pair(2,"two"));
   17           m.insert(std::make_pair(1,"one"));
-> 18           m.insert(std::make_pair(3,"three"));
   19   }
   20
   21
Target 0: (app) stopped.
(lldb) p m
(std::__1::map<int, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, std::__1::less<int>, std::__1::allocator<std::__1::pair<const int, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > > > >) $0 = size=2 {
  [0] = (first = 1, second = "one")
  [1] = (first = 2, second = "two")
}
(lldb) p s
(std::__1::string) $1 = "four"
(lldb) p v
(std::__1::vector<int, std::__1::allocator<int> >) $2 = size=3 {
  [0] = 2
  [1] = 1
  [2] = 3
}

Output console:
Extensions:
waiting for v8 protocol on stdin/stdout

Metadata

Metadata

Assignees

Labels

bugdebuggerfixedCheck the Milestone for the release in which the fix is or will be available.

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions