Skip to content

Commit 927926b

Browse files
authored
[lldb] Fix a quirk in SBValue::GetDescription (#75793)
The function was using the default version of ValueObject::Dump, which has a default of using the synthetic-ness of the top-level value for determining whether to print _all_ values as synthetic. This resulted in some unusual behavior, where e.g. a std::vector is stringified as synthetic if its dumped as the top level object, but in its raw form if it is a member of a struct without a pretty printer. The SBValue class already has properties which determine whether one should be looking at the synthetic view of the object (and also whether to use dynamic types), so it seems more natural to use that.
1 parent d23188d commit 927926b

File tree

4 files changed

+41
-3
lines changed

4 files changed

+41
-3
lines changed

lldb/source/API/SBValue.cpp

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
#include "lldb/Core/ValueObject.h"
2525
#include "lldb/Core/ValueObjectConstResult.h"
2626
#include "lldb/DataFormatters/DataVisualization.h"
27+
#include "lldb/DataFormatters/DumpValueObjectOptions.h"
2728
#include "lldb/Symbol/Block.h"
2829
#include "lldb/Symbol/ObjectFile.h"
2930
#include "lldb/Symbol/Type.h"
@@ -1209,10 +1210,14 @@ bool SBValue::GetDescription(SBStream &description) {
12091210

12101211
ValueLocker locker;
12111212
lldb::ValueObjectSP value_sp(GetSP(locker));
1212-
if (value_sp)
1213-
value_sp->Dump(strm);
1214-
else
1213+
if (value_sp) {
1214+
DumpValueObjectOptions options;
1215+
options.SetUseDynamicType(m_opaque_sp->GetUseDynamic());
1216+
options.SetUseSyntheticValue(m_opaque_sp->GetUseSynthetic());
1217+
value_sp->Dump(strm, options);
1218+
} else {
12151219
strm.PutCString("No value");
1220+
}
12161221

12171222
return true;
12181223
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
CXX_SOURCES := main.cpp
2+
3+
include Makefile.rules
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import lldb
2+
from lldbsuite.test.decorators import *
3+
from lldbsuite.test.lldbtest import *
4+
from lldbsuite.test import lldbutil
5+
6+
7+
class TestSBValueSynthetic(TestBase):
8+
NO_DEBUG_INFO_TESTCASE = True
9+
10+
def test_str(self):
11+
self.build()
12+
lldbutil.run_to_source_breakpoint(
13+
self, "break here", lldb.SBFileSpec("main.cpp")
14+
)
15+
16+
vector = self.frame().FindVariable("vector")
17+
has_vector = self.frame().FindVariable("has_vector")
18+
self.expect(str(vector), exe=False, substrs=["42", "47"])
19+
self.expect(str(has_vector), exe=False, substrs=["42", "47"])
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#include <vector>
2+
3+
struct HasVector {
4+
std::vector<int> v;
5+
};
6+
7+
int main() {
8+
std::vector<int> vector = {42, 47};
9+
HasVector has_vector = {vector};
10+
return 0; // break here
11+
}

0 commit comments

Comments
 (0)