Skip to content

Conversation

@kastiglione
Copy link

@kastiglione kastiglione commented Dec 3, 2025

Adopt stringForPrintObject(_:mangledTypeName:), an overload added in swiftlang/swift#84742.

This new overload allows lldb to call stringForPrintObject using only a pointer referencing the value, and the mangled typename corresponding to the value. The resulting expression does not reference the concrete type.

By not referencing a value's type, po can be performed on variables (and their nested stored properties) without loading the modules corresponding to the value's type. This will improve performance and reliability of po.

rdar://158968103

Adopt `stringForPrintObject(_:mangledTypeName:)`, an overload added in
swiftlang/swift#84742.

This new overload allows lldb to call `stringForPrintObject` using only a pointer
referencing the value, and the mangled typename corresponding to the value. The
resulting expression does not reference the concrete type.

By not referencing a value's type, `po` can be performed on variables (and their nested
stored properties) without loading the modules corresponding to the value's type. This
will improve performance and reliability of `po`.
@kastiglione kastiglione requested a review from a team as a code owner December 3, 2025 00:00
@kastiglione
Copy link
Author

@swift-ci test

@kastiglione kastiglione marked this pull request as draft December 3, 2025 00:00
@kastiglione
Copy link
Author

Draft mode: follow up will include experimental setting, and tests.

@kastiglione
Copy link
Author

@swift-ci test

@kastiglione
Copy link
Author

@swift-ci test macOS

@kastiglione
Copy link
Author

Existing tests all pass with new po.

@kastiglione kastiglione marked this pull request as ready for review December 3, 2025 23:38
@kastiglione
Copy link
Author

@swift-ci test

return false;
}

static bool printObjectViaPointer(Stream &strm, ValueObject &object,

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this function return llvm::Error and return createStringError for the various failure modes for easier debugging?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not able to picture how this improves debugging? Can you walk me through it?

auto result_or_err = runObjectDescription(object, expr_string, process, true);
if (!result_or_err) {
LLDB_LOG_ERROR(log, result_or_err.takeError(),
"stringForPrintObject(_:mangledTypeName:) failed: {0}");

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

then this could just be return result_or_err.takeError()

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wouldn't returning lose the context of stringForPrintObject(_:mangledTypeName:) being the source of the error?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could do joinError(createStringError(..), esult_or_err.takeError()).

)
self.expect("po value", substrs=["2025"])
self._filecheck("INT")
# CHECK-INT: stringForPrintObject(UnsafeRawPointer(bitPattern: {{[0-9]+}}), mangledTypeName: "SiD")

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Neat test, reusing filecheck this way!


StringRef mangled_type_name = object.GetMangledTypeName();
// Swift's APIs that accept mangled names require the "$s" prefix removed.
mangled_type_name.consume_front("$s");

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"$e" is also valid mangling for embedded Swift.

Also, when I see mangled names without the front "$s" omitted, I also see it with the last "D" omitted too (I think that's a "TypeMangling" node). I guess this isn't necessary here?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The removes $e prefixes now.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess this isn't necessary here?

Not that I've seen. Tests work without having to make any adjustments to suffix.

bool is_simulator = platform->GetPluginName().ends_with("-simulator");
if (is_simulator) {
// The simulators look like the host OS to Process, but Platform
// can the version out of an environment variable.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"can the" -> "can get the"

llvm::VersionTuple version = process_sp->GetHostOSVersion();
os_vers << version.getAsString();
auto platform = target->GetPlatform();
bool is_simulator = platform->GetPluginName().ends_with("-simulator");

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we really not have a nicer way to tell if a Platform is a simulator?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's Triple::isSimulatorEnvironment but it's unclear if that applies here, based on the comment:

// The simulators look like the host OS to Process, but Platform
// can get the version out of an environment variable.


bool GetPreparePlaygroundStubFunctions() const { return m_prepare_playground_stub_functions; }

void SetDisableAvailability() { m_disable_availability = true; }

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is an odd set API. It only allows you to set it to true, which the name doesn't really imply?

We usually do:

SetWhatever(bool new_value)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

which the name doesn't really imply?

It doesn't? I'm failing to see how it would be interpreted otherwise…

There's no reason for code to call SetDisableAvailability(False), as that is the default. Since there's no reason for it to be called like that, I made the function take no arguments, so that it can be called only one way. This may be different than other bool setters, but I feel it's better prevent it from being mis-called than make it match other setters.

addr_t addr = LLDB_INVALID_ADDRESS;
if (flags.Test(eTypeInstanceIsPointer)) {
// Objects are pointers.
addr = object.GetValueAsUnsigned(LLDB_INVALID_ADDRESS);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should use GetValueAsAddress.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

GetValueAsAddress is on SBValue, I don't see an equivalent on ValueObject.

@kastiglione
Copy link
Author

@swift-ci test

Copy link

@adrian-prantl adrian-prantl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM with outstanding feedback addressed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants