This is an archive of the discontinued LLVM Phabricator instance.

[lldb] Refactor SBFileSpec::GetDirectory
ClosedPublic

Authored by bulbazord on May 1 2023, 5:31 PM.

Details

Summary

There's no reason to create an entire new filespec to mutate and grab
data from when we can just grab the data directly.

Diff Detail

Event Timeline

bulbazord created this revision.May 1 2023, 5:31 PM
Herald added a project: Restricted Project. · View Herald TranscriptMay 1 2023, 5:31 PM
bulbazord requested review of this revision.May 1 2023, 5:31 PM
Herald added a project: Restricted Project. · View Herald TranscriptMay 1 2023, 5:31 PM
JDevlieghere accepted this revision.May 1 2023, 7:08 PM
This revision is now accepted and ready to land.May 1 2023, 7:08 PM
mib accepted this revision.May 1 2023, 9:09 PM
This revision was automatically updated to reflect the committed changes.

The old code had the side-effect of NOT resolving the path of the SBFileSpec in order to get its directory. I am not sure whether that was on purpose or not, however.

The old code had the side-effect of NOT resolving the path of the SBFileSpec in order to get its directory. I am not sure whether that was on purpose or not, however.

To be more precise, the old code had the side-effect of guaranteeing that whatever path was given to you was from an unresolved FileSpec. Right now, if the SBFileSpec is unresolved, this will do the exact same thing as before. With this change, if an SBFileSpec is resolved, the path you're getting is from a resolved FileSpec. I'm pretty sure that this shouldn't actually be different than what was there before since we're making a copy from the underlying FileSpec though, unless I'm missing something?

omjavaid reopened this revision.May 15 2023, 11:47 AM
omjavaid added a subscriber: omjavaid.

This introduced test failures on windows lldb-aarch64-windows buildbot.

lldb-api :: functionalities/process_save_core/TestProcessSaveCore.py
lldb-api :: python_api/symbol-context/TestSymbolContext.py

https://lab.llvm.org/buildbot/#/builders/219/builds/2485

I am reverting it, kindly revisit it.

This revision is now accepted and ready to land.May 15 2023, 11:47 AM

AssertionError: 'C:\\Users\\tcwg\\llvm-worker\\lldb-aarch64-windows\\build\\lldb-test-build.noindex\\functionalities\\process_save_core\\TestProcessSaveCore.test_save_windows_mini_dump_dwarf\\a.out' not found in ['C:/Users/tcwg/llvm-worker/lldb-aarch64-windows/build/lldb-test-build.noindex/functionalities/process_save_core/TestProcessSaveCore.test_save_windows_mini_dump_dwarf\\a.out', 'C:/Windows/System32\\ntdll.dll', 'C:/Windows/System32\\kernel32.dll', 'C:/Windows/System32\\KernelBase.dll']

Looks like a path normalization issue... GetPathAsConstString() has a bool parameter that defaults to true for normalizing paths. The right thing for this patch to do is actually return m_opaque_up->GetPathAsConstString().GetCString() then instead of invoking GetDirectory() directly.

Ok, after looking at this more closely, it's a little clearer to me why SBFileSpec::GetDirectory was written this way to begin with. The method itself requires its return value to be denormalized (something not explicitly documented in the header nor the SWIG docstrings for this class/method). The only way to get the FileSpec's path in a denormalized form is by using FileSpec::GetPath and its variants... That's why we create a new FileSpec, remove its filename, and then get the path as a ConstString. I won't be addressing that in this patch because I view this as a flaw of the existing FileSpec implementation.

Thank you for finding and reverting this.