This is an archive of the discontinued LLVM Phabricator instance.

Add SBDebugger::GetSetting() public API
ClosedPublic

Authored by yinghuitan on Aug 31 2022, 11:46 AM.

Details

Summary

This patch adds new SBDebugger::GetSetting() API which
enables client to access settings as SBStructuredData.

Implementation wise, a new ToJSON() virtual function is added to OptionValue
class so that each concrete child class can override and provides its
own JSON representation. This patch aims to define the APIs and implement
a common set of OptionValue child classes, leaving the remaining for
future patches.

This patch is used later by auto deduce source map from source line breakpoint
feature for testing generated source map entries.

Diff Detail

Event Timeline

yinghuitan created this revision.Aug 31 2022, 11:46 AM
Herald added a project: Restricted Project. · View Herald TranscriptAug 31 2022, 11:46 AM
yinghuitan requested review of this revision.Aug 31 2022, 11:46 AM
Herald added a project: Restricted Project. · View Herald TranscriptAug 31 2022, 11:46 AM

Re-diff with clang-format

I'm a little sad that we don't yet have a way to read the current value of a setting into an SBStructuredData, so we do this piecemeal instead. But that's a bigger project, so if you need this now, it doesn't seem fair to block you on that. We should really name the output SBStructuredData keys more instructively, however.

lldb/include/lldb/API/SBTarget.h
91 ↗(On Diff #457046)

You have to say what the structure is so people will know how to fetch the elements.

lldb/source/API/SBTarget.cpp
222 ↗(On Diff #457046)

It seems a little round-about to convert the source map to JSON, then from JSON to an SBStructuredData. You should be able to write the elements directly. I'm not sure how much that matters, however.

lldb/source/Target/PathMappingList.cpp
138

Can we call these something more instructive than "first" and "second"? These are the "original" path and the "substitution" path, maybe those would be good keys?

clayborg added inline comments.Sep 1 2022, 10:48 AM
lldb/bindings/interface/SBTarget.i
969 ↗(On Diff #457046)

Do we want to actually have something more like this:

lldb::SBStructuredData GetSetting(const char *setting);

That allows us to get any setting as structured data? We have a lot of settings and I would rather not have an API for each one of these added to the public API as we need them.

Eventually we could also have:

void SetSetting(lldb::SBStructuredData &data);

This would allow the output to contain multiple settings if needed. Hopefully the output would be in the format of:

{ "target.source-map": [["<orig-path>", "<replace-path>"], ...] }

This would allow us to export all settings, and then import them.

lldb/source/Target/PathMappingList.cpp
138

We can either do this as a key/value pair thing or just as a array of array path pairs in JSON?

Address review feedback.

yinghuitan retitled this revision from Add GetSourceMap public API to Add SBDebugger::GetSetting()/GetSettings() public APIs.Sep 8 2022, 11:23 AM
yinghuitan edited the summary of this revision. (Show Details)
clayborg requested changes to this revision.Sep 8 2022, 12:40 PM
clayborg added inline comments.
lldb/bindings/interface/SBDebugger.i
228

remove this and document the function below such that "setting" can be NULL or empty for to get all settings. Maybe also document that anything that you can type as an argument for "settings show" should work here. See the output of "settings show target" for an example.

Examples that should work here are:

lldb::SBStructuredData settings = debugger.GetSetting(nullptr); // Get all settings
lldb::SBStructuredData settings = debugger.GetSetting(""); // Get all settings
lldb::SBStructuredData settings = debugger.GetSetting("target.arg0"); // Get 1 specific setting
lldb::SBStructuredData settings = debugger.GetSetting("target.arg0 target.language"); // Get 2 specific settings
lldb::SBStructuredData settings = debugger.GetSetting("target"); // Get all target specific settings

So basically anything you can type into "settings show" should work here.

lldb/include/lldb/API/SBDebugger.h
118

remove

lldb/include/lldb/Interpreter/OptionValue.h
88
89
lldb/source/API/SBDebugger.cpp
439–455

Remove this function. We should have only one that takes a "const char *settings"

464

No need to create a shared pointer here.

467
471
lldb/source/Interpreter/OptionValueArray.cpp
81–83

omit braces for single line for statement per llvm guidelines

lldb/source/Interpreter/OptionValueDictionary.cpp
89–90

Use modern C++ iterator style:

for (const auto &value: m_values) {
92–93

This is a dictionary, we already have a key/value to use

lldb/test/API/commands/settings/TestSettings.py
806

we should test values that have strings that contain reserved JSON characters. I believe '\' can be in a string and will need to be double desensitized. Also string values that contain the string quote characters like a string "hello \"world\""

This revision now requires changes to proceed.Sep 8 2022, 12:40 PM
hawkinsw added inline comments.
lldb/test/API/functionalities/source-map/TestTargetSourceMap.py
25

Sorry if this comment is not helpful, but I was wondering ...

Could we use source_map_setting_path here? That would make future changes easier?

yinghuitan updated this revision to Diff 458932.Sep 8 2022, 5:48 PM
yinghuitan marked 11 inline comments as done.

Address review comments

yinghuitan retitled this revision from Add SBDebugger::GetSetting()/GetSettings() public APIs to Add SBDebugger::GetSetting()public APIs.EditedSep 8 2022, 5:52 PM
yinghuitan edited the summary of this revision. (Show Details)
yinghuitan retitled this revision from Add SBDebugger::GetSetting()public APIs to Add SBDebugger::GetSetting() public API.
yinghuitan marked an inline comment as done.
This comment has been deleted.
lldb/test/API/functionalities/source-map/TestTargetSourceMap.py
25

@hawkinsw, sorry, almost missed your comment. There is no single value for source map path but a pair of original/replacement. In this case, original is "." while the replacement is "src_dir" so I think src_dir makes sense here.

yinghuitan marked an inline comment as done.Sep 8 2022, 5:54 PM
hawkinsw added inline comments.Sep 8 2022, 8:59 PM
lldb/test/API/functionalities/source-map/TestTargetSourceMap.py
25

No problem! I am sorry I miscommunicated! I just meant, could we write something like

self.runCmd('settings set %s . "%s"' % (source_map_setting_path, src_dir))
clayborg requested changes to this revision.Sep 8 2022, 11:57 PM
clayborg added inline comments.
lldb/include/lldb/API/SBDebugger.h
119

We still don't need two actual APIs in SBDebugger.h. Remove this.

136

We can default "settings = nullptr" here so users can call without anything, but we should have only 1 API function for getting the settings.

lldb/include/lldb/Interpreter/OptionValue.h
89

Add a comment here. Suggested comment added.

lldb/include/lldb/Interpreter/OptionValueChar.h
34–37

Since this is actually a character, it should store what ever the character value is. So if the character is zero, it should store zero, not a string "(null)"

lldb/source/API/SBDebugger.cpp
439–443

Remove this and only keep the one that takes a 'const char *setting"'

lldb/source/Interpreter/OptionValueDictionary.cpp
92

I think this move can be removed? Watch for warnings here. Some buildbots have warnings as errors which could cause the submission to be reverted.

lldb/test/API/commands/settings/TestSettings.py
799

We need to set a few more settings for anything we support the ToJSON for to ensure they function as expected.

lldb/test/API/functionalities/source-map/TestTargetSourceMap.py
25

Good idea!

This revision now requires changes to proceed.Sep 8 2022, 11:57 PM
yinghuitan added inline comments.Sep 9 2022, 9:38 AM
lldb/include/lldb/Interpreter/OptionValueChar.h
34–37

I am not sure about this. This mimics what OptionValueChar::DumpValue() does. Do we want to keep consistence here?

Address review comments

clayborg requested changes to this revision.Sep 9 2022, 1:51 PM

Just a comment fix and allow the "char" option value to be saved as zero and this will be good to go.

lldb/include/lldb/API/SBDebugger.h
120–121

This comment is no longer true right? Any setting args that are accepted by settings show not longer is true right? It is just a single setting value you can either specify or not right?

lldb/include/lldb/Interpreter/OptionValueChar.h
34–37

if we want to set/restore this value, it should have the correct value. We aren't trying to mimic dump value here. So we should allow it to be set to zero.

34–37
This revision now requires changes to proceed.Sep 9 2022, 1:51 PM
yinghuitan updated this revision to Diff 459208.Sep 9 2022, 2:49 PM

Address review comments

clayborg accepted this revision.Sep 9 2022, 3:22 PM
This revision is now accepted and ready to land.Sep 9 2022, 3:22 PM
This revision was automatically updated to reflect the committed changes.
JDevlieghere added inline comments.Sep 12 2022, 8:31 AM
lldb/include/lldb/Core/UserSettingsController.h
62–64

A flag doesn't scale if we ever decide we need another format. An enum would solve that and would eliminate the need for a comment /*is_json=*/. I think the two values could be Plain` (or Text) and JSON.

lldb/include/lldb/Interpreter/OptionValue.h
86–87

Is this done?

lldb/source/Core/UserSettingsController.cpp
63

Earlier you said that ToJSON should never return NULL. We should enforce that with an assert here.

lldb/source/Interpreter/OptionValueArray.cpp
80–81
lldb/source/Interpreter/OptionValueDictionary.cpp
89–91
yinghuitan added inline comments.Sep 12 2022, 10:25 AM
lldb/include/lldb/Interpreter/OptionValue.h
86–87

No. My goal is simply adding a public API for testing auto deduce source map feature, this patch is much larger than I wanted to achieve so it focuses adding skeleton of the API and implements a subset of OptionValue child classes leaving the remaining for future patches (the implementation is not hard but adding test coverage takes some time).