This is an archive of the discontinued LLVM Phabricator instance.

Add a new SBDebugger::SetDestroyCallback() API
ClosedPublic

Authored by yinghuitan on Feb 7 2023, 10:52 AM.

Details

Summary

Adding a new SBDebugger::SetDestroyCallback() API.
This API can be used by any client to query for statistics/metrics before
exiting debug sessions.

Diff Detail

Event Timeline

yinghuitan created this revision.Feb 7 2023, 10:52 AM
Herald added a project: Restricted Project. · View Herald TranscriptFeb 7 2023, 10:52 AM
yinghuitan requested review of this revision.Feb 7 2023, 10:52 AM
Herald added a project: Restricted Project. · View Herald TranscriptFeb 7 2023, 10:52 AM
clayborg requested changes to this revision.Feb 7 2023, 1:49 PM

If I am reading the code for this patch correctly, we need the BatonSP stuff because we have differing callback bytes for public vs private APIs. If we switch to using a common callback type of:

typedef void (*DebuggerDestroyCallback)(lldb::user_id_t &debugger_id, void *baton);

(we can define this both internally and leave the current "SBDebuggerDestroyCallback" in SBDefines.h alone), then we can avoid having to add any of the BatonSP stuff and just store a "void * m_destroy_callback_baton;" in Debugger.h.

lldb/include/lldb/Core/Debugger.h
599–600

Why do we need the fancy BatonSP stuff here? Can't we just store this as a void *? Or is the fancy baton stuff required for the python for some reason? I couldn't see any reason by reading the code quickly, please correct me if so.

lldb/include/lldb/lldb-types.h
71–72 ↗(On Diff #495599)

This can't be in the public lldb-types.h header file as no on will be able to use it since it uses "lldb_private::Debugger". If this is to be in the public header files, then this needs to change to be one of:

typedef void (*DebuggerDestroyCallback)(lldb::user_id_t &debugger_id, void *baton);
typedef void (*DebuggerDestroyCallback)(lldb::SBDebugger &debugger, void *baton);

The "debugger_id" is the easier one to do since we need to make this work with python so that python users can install a callback from python and have it all work.

This can however exist in the lldb-private-types.h which is not part of the public API, so it can be moved there and then it won't cause any issues. I realize there are other typedefs in here than mention lldb_private stuff, but they shouldn't be here.

This revision now requires changes to proceed.Feb 7 2023, 1:49 PM

Address review comments by using the same type for internal and
public callbacks.

Just change HandleDestroryCallback to a member function and this is good to go.

lldb/source/Core/Debugger.cpp
688–694

This should be a member function instead of a static function that takes a debugger_sp an argument.

700
yinghuitan updated this revision to Diff 502897.Mar 6 2023, 6:33 PM

Address review feedback.

clayborg accepted this revision.Mar 7 2023, 12:02 PM
This revision is now accepted and ready to land.Mar 7 2023, 12:02 PM
This revision was automatically updated to reflect the committed changes.