This is an archive of the discontinued LLVM Phabricator instance.

Override CalculateFrameVariableError in SymbolFileOnDemand
ClosedPublic

Authored by GeorgeHuyubo on Nov 2 2022, 12:31 PM.

Details

Summary

Override CalculateFrameVariableError function in SymbolFileOnDemand.
Implement it by calling the same function of m_sym_file_impl, so that the wrapped symfile's error can be exposed.
This will enable the vscode debug session (which has the symbol ondemand enabled by default) to show error in the LOCALS variable section when there is error.

This piece of code was added for symbol on demand feature(https://reviews.llvm.org/rG7b81192d462bbd8031d5c665e29cd6b4c0c6887a). And missing overridden CalculateFrameVariableError is causing the error in symfile not being able to be exposed.

Added unit test that would fail before this patch, and now is succeeding.

Diff Detail

Event Timeline

GeorgeHuyubo created this revision.Nov 2 2022, 12:31 PM
Herald added a project: Restricted Project. · View Herald TranscriptNov 2 2022, 12:31 PM
GeorgeHuyubo requested review of this revision.Nov 2 2022, 12:31 PM
Herald added a project: Restricted Project. · View Herald TranscriptNov 2 2022, 12:31 PM
GeorgeHuyubo edited the summary of this revision. (Show Details)Nov 2 2022, 12:37 PM
GeorgeHuyubo edited the summary of this revision. (Show Details)

It'd be great to put some background in the summary.

The issue is introduced when adding Symbol OnDemand feature. We added a wrapper that ignore the error. And this affected the ability to populate the error when we have this feature turned on :D

(something like this, would be nice to link back to the symbol OnDemand patch as well)

GeorgeHuyubo edited the summary of this revision. (Show Details)Nov 2 2022, 2:16 PM
yinghuitan requested changes to this revision.Nov 2 2022, 2:56 PM
yinghuitan added inline comments.
lldb/include/lldb/Symbol/SymbolFileOnDemand.h
121

Please add a unit test which should fail in symbol on-demand mode but succeeds after your patch. Checkout Greg's original test checking frame variable error as example.

lldb/source/Symbol/SymbolFileOnDemand.cpp
277–279

You should only forward to underlying m_sym_file_impl->CalculateFrameVariableError() when m_debug_info_enabled is true otherwise it will trigger parsing of debug info. Follow the pattern in other methods of this file.

This revision now requires changes to proceed.Nov 2 2022, 2:56 PM
GeorgeHuyubo marked 2 inline comments as done.

Address comments.

GeorgeHuyubo edited the summary of this revision. (Show Details)Nov 2 2022, 5:09 PM
clayborg requested changes to this revision.Nov 3 2022, 11:09 AM

Just have the case when debug info is not enabled return "Status()" (a default constructed error with no error) and this will be good to go.

lldb/source/Symbol/SymbolFileOnDemand.cpp
281

This will create an infinite loop right? See code change suggestions for fix.

This revision now requires changes to proceed.Nov 3 2022, 11:09 AM

The refactoring comment should be done as well for this diff as suggested.

lldb/test/API/tools/lldb-vscode/variables/TestVSCode_variables.py
572–574

If this function is just like the test_darwin_dwarf_missing_obj, I would suggest refactoring test_darwin_dwarf_missing_obj into a function that doesn't start with "test", and then having both test_darwin_dwarf_missing_obj and test_darwin_dwarf_missing_obj_with_symbol_ondemand_enabled call it.

So copy the "test_darwin_dwarf_missing_obj" function and name it "darwin_dwarf_missing_obj" and add a new parameter named "initCommands":

def darwin_dwarf_missing_obj(self, initCommands):

Then copy the code from this function into that function, and replace the remove the line:

initCommands = ['settings set symbols.load-on-demand true']

Then just modify the code for both tests to call the refactored function

@no_debug_info_test
@skipUnlessDarwin
def test_darwin_dwarf_missing_obj(self):
    '''
        Test that if we build a binary with DWARF in .o files and we remove
        the .o file for main.cpp, that we get a variable named "<error>"
        whose value matches the appriopriate error. Errors when getting
        variables are returned in the LLDB API when the user should be
        notified of issues that can easily be solved by rebuilding or
        changing compiler options and are designed to give better feedback
        to the user.
    '''
    darwin_dwarf_missing_obj(self, None)

@no_debug_info_test
@skipUnlessDarwin
def test_darwin_dwarf_missing_obj_with_symbol_ondemand_enabled(self):
    '''
        Test that if we build a binary with DWARF in .o files and we remove
        the .o file for main.cpp, that we get a variable named "<error>"
        whose value matches the appriopriate error. Test with symbol_ondemand_enabled.
    '''
    darwin_dwarf_missing_obj(self, ['settings set symbols.load-on-demand true'])

Any method on a test suite class that doesn't start with "test" is just a help function.

Addressed comments.

clayborg accepted this revision.Nov 3 2022, 1:52 PM

Looks good!

This revision was not accepted when it landed; it landed in state Needs Review.Nov 3 2022, 3:09 PM
This revision was automatically updated to reflect the committed changes.
GeorgeHuyubo marked 2 inline comments as done.