Skip to content

Commit 92f0e4c

Browse files
committed
[LLDB] Fixes summary formatter for libc++ map allowing modification of contained value
Reviewed By: clayborg Differential Revision: https://reviews.llvm.org/D140624
1 parent f3e2f26 commit 92f0e4c

File tree

4 files changed

+65
-10
lines changed

4 files changed

+65
-10
lines changed

lldb/source/Plugins/Language/CPlusPlus/LibCxxMap.cpp

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -397,18 +397,9 @@ lldb_private::formatters::LibcxxStdMapSyntheticFrontEnd::GetChildAtIndex(
397397
// at this point we have a valid
398398
// we need to copy current_sp into a new object otherwise we will end up with
399399
// all items named __value_
400-
DataExtractor data;
401-
Status error;
402-
iterated_sp->GetData(data, error);
403-
if (error.Fail()) {
404-
m_tree = nullptr;
405-
return lldb::ValueObjectSP();
406-
}
407400
StreamString name;
408401
name.Printf("[%" PRIu64 "]", (uint64_t)idx);
409-
auto potential_child_sp = CreateValueObjectFromData(
410-
name.GetString(), data, m_backend.GetExecutionContextRef(),
411-
m_element_type);
402+
auto potential_child_sp = iterated_sp->Clone(ConstString(name.GetString()));
412403
if (potential_child_sp) {
413404
switch (potential_child_sp->GetNumChildren()) {
414405
case 1: {
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
CXX_SOURCES := main.cpp
2+
3+
USE_LIBCPP := 1
4+
5+
CXXFLAGS_EXTRAS := -O0
6+
include Makefile.rules
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
"""
2+
Test change libc++ map values.
3+
"""
4+
5+
import lldb
6+
from lldbsuite.test.decorators import *
7+
from lldbsuite.test.lldbtest import *
8+
from lldbsuite.test import lldbutil
9+
10+
class LibcxxChangeValueTestCase(TestBase):
11+
12+
def setUp(self):
13+
# Call super's setUp().
14+
TestBase.setUp(self)
15+
16+
@add_test_categories(["libc++"])
17+
@expectedFailureAll(oslist=["windows"], bugnumber="llvm.org/pr24772")
18+
def test(self):
19+
"""Test that we can change values of libc++ map."""
20+
self.build()
21+
self.runCmd("file " + self.getBuildArtifact("a.out"), CURRENT_EXECUTABLE_SET)
22+
23+
bkpt = self.target().FindBreakpointByID(
24+
lldbutil.run_break_set_by_source_regexp(
25+
self, "Set break point at this line."))
26+
27+
self.runCmd("run", RUN_SUCCEEDED)
28+
29+
# Get Frame #0.
30+
target = self.dbg.GetSelectedTarget()
31+
process = target.GetProcess()
32+
self.assertState(process.GetState(), lldb.eStateStopped)
33+
thread = lldbutil.get_stopped_thread(
34+
process, lldb.eStopReasonBreakpoint)
35+
self.assertTrue(
36+
thread.IsValid(),
37+
"There should be a thread stopped due to breakpoint condition")
38+
frame0 = thread.GetFrameAtIndex(0)
39+
self.assertTrue(frame0.IsValid(), "Got a valid frame.")
40+
41+
val_value = frame0.FindVariable("M")
42+
self.assertTrue(val_value.IsValid(), "Got the SBValue for val")
43+
pair0 = val_value.GetChildMemberWithName("[0]")
44+
self.assertTrue(pair0.IsValid(), "Got the SBValue for [0]")
45+
self.assertTrue(pair0.GetNumChildren() == 2, "Got 2 children")
46+
pair0_second = pair0.GetChildMemberWithName("second")
47+
self.assertTrue(pair0_second.IsValid(), "Got the SBValue for [0].second")
48+
result = pair0_second.SetValueFromCString("12345")
49+
self.assertTrue(result, "Setting val returned True.")
50+
result = pair0_second.GetValueAsUnsigned()
51+
self.assertTrue(result == 12345, "Got correct value (12345)")
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#include <map>
2+
3+
int main()
4+
{
5+
std::map<int, int> M = {{1,1},{2,2}};
6+
return M[1]; // Set break point at this line.
7+
}

0 commit comments

Comments
 (0)