splhack added a comment.

@clayborg yes, it'd be possible to pass the baton down to Platform.h since it 
is just `void *`, so no dependencies required.

But, first, let me explain the callback and baton flow.

----

For Python, user will set a callable Python object as the callback.
For C++ API, user will set a function pointer with a baton as the callback.

Both Python callback and C++ API callback will go into SBPlatform 
SetLocateModuleCallback.
SetLocateModuleCallback will use a lambda in order to convert ModuleSpec and 
FileSpec to SBModuleSpec and SBFileSpec.
This is because Platform.h and Target.cpp are not able to use SBModuleSpec and 
SBFileSpec.

  |               |                                      |                   |  
                               |          |
  | user callback |<-----(SBModuleSpec, SBFileSpec)----->| SBPlatform lambda 
|<-----(ModuleSpec, FileSpec)---->| Platform |
  |      baton    |                                      |  captures callback|  
                               |          |
  |               |                                      |           baton   |  
                               |          |

This summary is what things are retained by which layer.

- Python
  - the user callable object
- SBPlatform
  - C++ API: the user callback and the baton
  - Python: LLDBSwigPythonCallLocateModuleCallback and the user callable object 
as a baton
- Platform
  - SBPlatform lambda in std::function

There are three things.

- SBPlatform lambda created by SetLocateModuleCallback, the type is 
Platform::LocateModuleCallback.
- The user callback or LLDBSwigPythonCallLocateModuleCallback, the type is 
SBPlatformLocateModuleCallback.
- The baton (for Python, this is the callable object)

----

And back to 'passing the baton down to Platform.h'.
As the locate callback implementation in D153734 
<https://reviews.llvm.org/D153734> 
lldb/unittests/Target/LocateModuleCallbackTest.cpp,
internal users can use lambda to capture/retain anything for the callback. For 
example, `this` is captured by the locate callback in this case.
Therefore, no need to pass the baton down to Platform.h.

  m_platform_sp->SetLocateModuleCallback([this](const ModuleSpec &module_spec,
                                                FileSpec &module_file_spec,
                                                FileSpec &symbol_file_spec) {
    CheckCallbackArgs(module_spec, module_file_spec, symbol_file_spec);
    symbol_file_spec.SetPath(GetInputFilePath(k_breakpad_symbol_file));
    return Status();
  });




Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D153735/new/

https://reviews.llvm.org/D153735

_______________________________________________
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits

Reply via email to