Skip to content

Commit d239ce1

Browse files
committed
[LLDB][Docs] List available settings
1 parent 59d2e93 commit d239ce1

File tree

15 files changed

+449
-4
lines changed

15 files changed

+449
-4
lines changed

lldb/docs/CMakeLists.txt

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,12 @@ if (LLDB_ENABLE_PYTHON AND SPHINX_FOUND)
3636

3737
add_dependencies(lldb-python-doc-package swig_wrapper_python lldb-python)
3838

39+
add_custom_target(lldb-doc-autogen
40+
COMMAND $<TARGET_FILE:lldb-test> generate-docs "--output-dir=${CMAKE_CURRENT_LIST_DIR}/use"
41+
COMMENT "Generating settings documentation."
42+
)
43+
add_dependencies(lldb-doc-autogen lldb-test)
44+
3945
# FIXME: Don't treat Sphinx warnings as errors. The files generated by
4046
# automodapi are full of warnings (partly caused by SWIG, our documentation
4147
# and probably also automodapi itself), so those warnings need to be fixed
@@ -51,7 +57,7 @@ if (LLDB_ENABLE_PYTHON AND SPHINX_FOUND)
5157
add_custom_target(clean-lldb-html COMMAND "${CMAKE_COMMAND}" -E
5258
remove_directory ${CMAKE_CURRENT_BINARY_DIR}/html)
5359
add_dependencies(docs-lldb-html swig_wrapper_python
54-
lldb-python-doc-package clean-lldb-html)
60+
lldb-python-doc-package clean-lldb-html lldb-doc-autogen)
5561
endif()
5662

5763
if (${SPHINX_OUTPUT_MAN})

lldb/docs/_ext/lldb_setting.py

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
from docutils.parsers.rst import directives
2+
from docutils import nodes
3+
4+
from sphinx import addnodes
5+
from sphinx.application import Sphinx
6+
from sphinx.directives import ObjectDescription
7+
from sphinx.util.docfields import Field, GroupedField
8+
import llvm_slug
9+
10+
11+
class LiteralField(Field):
12+
"""A field that wraps the content in <code></code>"""
13+
14+
def make_field(self, types, domain, item, env=None, inliner=None, location=None):
15+
fieldarg, content = item
16+
fieldname = nodes.field_name("", self.label)
17+
if fieldarg:
18+
fieldname += nodes.Text(" ")
19+
fieldname += nodes.Text(fieldarg)
20+
21+
fieldbody = nodes.field_body("", nodes.literal("", "", *content))
22+
return nodes.field("", fieldname, fieldbody)
23+
24+
25+
# Example:
26+
# ```{lldbsetting} dwim-print-verbosity
27+
# :type: "enum"
28+
#
29+
# The verbosity level used by dwim-print.
30+
#
31+
# :enum none: Use no verbosity when running dwim-print.
32+
# :enum expression: Use partial verbosity when running dwim-print - display a message when `expression` evaluation is used.
33+
# :enum full: Use full verbosity when running dwim-print.
34+
# :default: none
35+
# ```
36+
class LLDBSetting(ObjectDescription):
37+
option_spec = {
38+
"type": directives.unchanged,
39+
}
40+
doc_field_types = [
41+
LiteralField(
42+
"default",
43+
label="Default",
44+
has_arg=False,
45+
names=("default",),
46+
),
47+
GroupedField("enum", label="Enumerations", names=("enum",)),
48+
LiteralField(
49+
"minimum", label="Minimum", has_arg=False, names=("min", "minimum")
50+
),
51+
LiteralField(
52+
"maximum", label="Maximum", has_arg=False, names=("max", "maximum")
53+
),
54+
]
55+
56+
def handle_signature(self, sig: str, signode: addnodes.desc_signature):
57+
typ = self.options.get("type", None)
58+
59+
desc = addnodes.desc_name(text=sig)
60+
desc += nodes.inline(
61+
"",
62+
typ,
63+
classes=[
64+
"lldb-setting-type",
65+
f"lldb-setting-type-{llvm_slug.make_slug(typ)}",
66+
],
67+
)
68+
signode["ids"].append(sig)
69+
signode += desc
70+
71+
72+
def setup(app: Sphinx):
73+
app.add_directive("lldbsetting", LLDBSetting)
74+
75+
return {
76+
"version": "0.1",
77+
"parallel_read_safe": True,
78+
"parallel_write_safe": True,
79+
}

lldb/docs/_static/lldb-setting.css

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
/*
2+
Terms use normal weight and upper case by default.
3+
For settings, the term should be bold and use the original case.
4+
*/
5+
dl[class]:not(.option-list):not(.field-list):not(.footnote):not(.glossary):not(
6+
.simple
7+
).lldbsetting
8+
.field-list
9+
> dt {
10+
text-transform: none;
11+
font-weight: bold;
12+
}
13+
14+
.lldb-setting-type {
15+
--setting-color: var(--light-color);
16+
--background-opacity: 0.1;
17+
}
18+
19+
.lldb-setting-type {
20+
float: right;
21+
text-align: right;
22+
text-indent: 0;
23+
line-height: 1.4;
24+
background-color: rgba(var(--setting-color), var(--background-opacity));
25+
padding: 0px 8px;
26+
border-radius: 99999px;
27+
border: rgba(var(--setting-color), 1) 1px solid;
28+
font-size: 0.9em;
29+
color: rgba(var(--setting-color), 1);
30+
}
31+
32+
body[data-theme="dark"] .lldb-setting-type {
33+
--setting-color: var(--dark-color);
34+
--background-opacity: 0.2;
35+
}
36+
@media (prefers-color-scheme: dark) {
37+
body[data-theme="auto"] .lldb-setting-type {
38+
--setting-color: var(--dark-color);
39+
--background-opacity: 0.2;
40+
}
41+
}
42+
43+
/* anything string-like (default) */
44+
.lldb-setting-type-string,
45+
.lldb-setting-type /* fallback */ {
46+
--dark-color: 255, 177, 38;
47+
--light-color: 125, 98, 1;
48+
}
49+
50+
/* array-like */
51+
.lldb-setting-type-arguments,
52+
.lldb-setting-type-array,
53+
.lldb-setting-type-file-list {
54+
--dark-color: 211, 131, 255;
55+
--light-color: 64, 33, 242;
56+
}
57+
58+
/* map-like */
59+
.lldb-setting-type-dictionary,
60+
.lldb-setting-type-path-map {
61+
--dark-color: 243, 0, 255;
62+
--light-color: 157, 0, 183;
63+
}
64+
65+
/* boolean */
66+
.lldb-setting-type-boolean {
67+
--dark-color: 29, 180, 8;
68+
--light-color: 0, 123, 33;
69+
}
70+
71+
/* numbers */
72+
.lldb-setting-type-int,
73+
.lldb-setting-type-unsigned {
74+
--dark-color: 80, 164, 198;
75+
--light-color: 1, 108, 140;
76+
}
77+
78+
/* enum */
79+
.lldb-setting-type-enum {
80+
--dark-color: 255, 87, 73;
81+
--light-color: 191, 3, 10;
82+
}

lldb/docs/conf.py

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
# serve to show the default.
1313
import sys, os, re, shutil
1414
from datetime import date
15+
from pathlib import Path
1516

1617
# Add path for llvm_slug module.
1718
sys.path.insert(0, os.path.abspath(os.path.join("..", "..", "llvm", "docs")))
@@ -41,9 +42,16 @@
4142
# If your documentation needs a minimal Sphinx version, state it here.
4243
# needs_sphinx = '1.0'
4344

45+
sys.path.append(str(Path("_ext").resolve()))
46+
4447
# Add any Sphinx extension module names here, as strings. They can be extensions
4548
# coming with Sphinx (named 'sphinx.ext.*') or your custom ones.
46-
extensions = ["sphinx.ext.todo", "sphinx.ext.mathjax", "sphinx.ext.intersphinx"]
49+
extensions = [
50+
"sphinx.ext.todo",
51+
"sphinx.ext.mathjax",
52+
"sphinx.ext.intersphinx",
53+
"lldb_setting",
54+
]
4755

4856
# When building man pages, we do not use the markdown pages,
4957
# So, we can continue without the myst_parser dependencies.
@@ -59,6 +67,7 @@
5967
# Automatic anchors for markdown titles
6068
myst_heading_anchors = 6
6169
myst_heading_slug_func = "llvm_slug.make_slug"
70+
myst_enable_extensions = ["fieldlist"]
6271

6372
autodoc_default_options = {"special-members": True}
6473

@@ -132,7 +141,7 @@
132141
# included by any doctree (as the manpage ignores those pages but they are
133142
# potentially still around from a previous website generation).
134143
if building_man_page:
135-
exclude_patterns.append(automodapi_toctreedirnm)
144+
exclude_patterns += [automodapi_toctreedirnm, "use/settings.md"]
136145
# Use the recommended 'any' rule so that referencing SB API classes is possible
137146
# by just writing `SBData`.
138147
default_role = "any"
@@ -192,7 +201,10 @@
192201
# Add any paths that contain custom static files (such as style sheets) here,
193202
# relative to this directory. They are copied after the builtin static files,
194203
# so a file named "default.css" will overwrite the builtin "default.css".
195-
# html_static_path = ["_static"]
204+
html_static_path = ["_static"]
205+
html_css_files = [
206+
"lldb-setting.css",
207+
]
196208

197209
html_extra_path = [".htaccess"]
198210

lldb/docs/index.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,7 @@ interesting areas to contribute to lldb.
137137
use/aarch64-linux
138138
use/symbolfilejson
139139
use/mcp
140+
use/settings
140141
use/troubleshooting
141142
use/links
142143
Man Page <man/lldb>

lldb/docs/use/.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# autogenerated
2+
/settings.md

lldb/include/lldb/Interpreter/OptionValueEnumeration.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,8 @@ class OptionValueEnumeration
7070

7171
void SetDefaultValue(enum_type value) { m_default_value = value; }
7272

73+
const EnumerationMap &Enumerations() const { return m_enumerations; }
74+
7375
protected:
7476
void SetEnumerations(const OptionEnumValues &enumerators);
7577
void DumpEnum(Stream &strm, enum_type value);

lldb/include/lldb/Interpreter/OptionValueFormatEntity.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,9 @@ class OptionValueFormatEntity
4545

4646
const FormatEntity::Entry &GetDefaultValue() const { return m_default_entry; }
4747

48+
llvm::StringRef GetDefaultFormatStr() const { return m_default_format; }
49+
std::string GetEscapedDefaultFormatStr() const;
50+
4851
protected:
4952
std::string m_current_format;
5053
std::string m_default_format;

lldb/include/lldb/Interpreter/OptionValueProperties.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,11 @@ class OptionValueProperties
8282
return ProtectedGetPropertyAtIndex(idx);
8383
}
8484

85+
virtual size_t
86+
GetNumProperties(const ExecutionContext *exe_ctx = nullptr) const {
87+
return m_properties.size();
88+
}
89+
8590
// Property can be a property path like
8691
// "target.process.extra-startup-command"
8792
virtual const Property *

lldb/include/lldb/Interpreter/OptionValueRegex.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,8 @@ class OptionValueRegex : public Cloneable<OptionValueRegex, OptionValue> {
5555

5656
bool IsValid() const { return m_regex.IsValid(); }
5757

58+
llvm::StringRef GetDefaultValue() const { return m_default_regex_str; }
59+
5860
protected:
5961
RegularExpression m_regex;
6062
std::string m_default_regex_str;

0 commit comments

Comments
 (0)