diff options
author | qxy11 <yangjanet6@gmail.com> | 2025-06-23 11:51:08 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2025-06-23 11:51:08 -0700 |
commit | 3095d3a47d624b573d0748ee37f8f201d5702b63 (patch) | |
tree | c6a4c9e05af0993b3c4bbc6c3ca7d501c195f28b /lldb/packages/Python/lldbsuite/test | |
parent | 97e8266172533fe9deb701a0851b442298f0f011 (diff) | |
download | llvm-3095d3a47d624b573d0748ee37f8f201d5702b63.zip llvm-3095d3a47d624b573d0748ee37f8f201d5702b63.tar.gz llvm-3095d3a47d624b573d0748ee37f8f201d5702b63.tar.bz2 |
[lldb] Add count for number of DWO files loaded in statistics (#144424)
## Summary
A new `totalLoadedDwoFileCount` and `totalDwoFileCount` counters to
available statisctics when calling "statistics dump".
1. `GetDwoFileCounts ` is created, and returns a pair of ints
representing the number of loaded DWO files and the total number of DWO
files, respectively. An override is implemented for `SymbolFileDWARF`
that loops through each compile unit, and adds to a counter if it's a
DWO unit, and then uses `GetDwoSymbolFile(false)` to check whether the
DWO file was already loaded/parsed.
3. In `Statistics`, use `GetSeparateDebugInfo` to sum up the total
number of loaded/parsed DWO files along with the total number of DWO
files. This is done by checking whether the DWO file was already
successfully `loaded` in the collected DWO data, anding adding to the
`totalLoadedDwoFileCount`, and adding to `totalDwoFileCount` for all CU
units.
## Expected Behavior
- When binaries are compiled with split-dwarf and separate DWO files,
`totalLoadedDwoFileCount` would be the number of loaded DWO files and
`totalDwoFileCount` would be the total count of DWO files.
- When using a DWP file instead of separate DWO files,
`totalLoadedDwoFileCount` would be the number of parsed compile units,
while `totalDwoFileCount` would be the total number of CUs in the DWP
file. This should be similar to the counts we get from loading separate
DWO files rather than only counting whether a single DWP file was
loaded.
- When not using split-dwarf, we expect both `totalDwoFileCount` and
`totalLoadedDwoFileCount` to be 0 since no separate debug info is
loaded.
## Testing
**Manual Testing**
On an internal script that has many DWO files, `statistics dump` was
called before and after a `type lookup` command. The
`totalLoadedDwoFileCount` increased as expected after the `type lookup`.
```
(lldb) statistics dump
{
...
"totalLoadedDwoFileCount": 29,
}
(lldb) type lookup folly::Optional<unsigned int>::Storage
typedef std::conditional<true, folly::Optional<unsigned int>::StorageTriviallyDestructible, folly::Optional<unsigned int>::StorageNonTriviallyDestructible>::type
typedef std::conditional<true, folly::Optional<unsigned int>::StorageTriviallyDestructible, folly::Optional<unsigned int>::StorageNonTriviallyDestructible>::type
...
(lldb) statistics dump
{
...
"totalLoadedDwoFileCount": 2160,
}
```
**Unit test**
Added three unit tests that build with new "third.cpp" and "baz.cpp"
files. For tests with w/ flags `-gsplit-dwarf -gpubnames`, this
generates 2 DWO files. Then, the test incrementally adds breakpoints,
and does a type lookup, and the count should increase for each of these
as new DWO files get loaded to support these.
```
$ bin/lldb-dotest -p TestStats.py ~/llvm-sand/external/llvm-project/lldb/test/API/commands/statistics/basic/
----------------------------------------------------------------------
Ran 20 tests in 211.738s
OK (skipped=3)
```
Diffstat (limited to 'lldb/packages/Python/lldbsuite/test')
-rw-r--r-- | lldb/packages/Python/lldbsuite/test/builders/builder.py | 26 | ||||
-rw-r--r-- | lldb/packages/Python/lldbsuite/test/make/Makefile.rules | 4 |
2 files changed, 23 insertions, 7 deletions
diff --git a/lldb/packages/Python/lldbsuite/test/builders/builder.py b/lldb/packages/Python/lldbsuite/test/builders/builder.py index de05732..efb1ba5 100644 --- a/lldb/packages/Python/lldbsuite/test/builders/builder.py +++ b/lldb/packages/Python/lldbsuite/test/builders/builder.py @@ -247,13 +247,25 @@ class Builder: def _getDebugInfoArgs(self, debug_info): if debug_info is None: return [] - if debug_info == "dwarf": - return ["MAKE_DSYM=NO"] - if debug_info == "dwo": - return ["MAKE_DSYM=NO", "MAKE_DWO=YES"] - if debug_info == "gmodules": - return ["MAKE_DSYM=NO", "MAKE_GMODULES=YES"] - return None + + debug_options = debug_info if isinstance(debug_info, list) else [debug_info] + option_flags = { + "dwarf": {"MAKE_DSYM": "NO"}, + "dwo": {"MAKE_DSYM": "NO", "MAKE_DWO": "YES"}, + "gmodules": {"MAKE_DSYM": "NO", "MAKE_GMODULES": "YES"}, + "debug_names": {"MAKE_DEBUG_NAMES": "YES"}, + "dwp": {"MAKE_DSYM": "NO", "MAKE_DWP": "YES"}, + } + + # Collect all flags, with later options overriding earlier ones + flags = {} + + for option in debug_options: + if not option or option not in option_flags: + return None # Invalid options + flags.update(option_flags[option]) + + return [f"{key}={value}" for key, value in flags.items()] def getBuildCommand( self, diff --git a/lldb/packages/Python/lldbsuite/test/make/Makefile.rules b/lldb/packages/Python/lldbsuite/test/make/Makefile.rules index 06959f2..58833e1 100644 --- a/lldb/packages/Python/lldbsuite/test/make/Makefile.rules +++ b/lldb/packages/Python/lldbsuite/test/make/Makefile.rules @@ -276,6 +276,10 @@ ifeq "$(MAKE_DWO)" "YES" CFLAGS += -gsplit-dwarf endif +ifeq "$(MAKE_DEBUG_NAMES)" "YES" + CFLAGS += -gpubnames +endif + ifeq "$(USE_PRIVATE_MODULE_CACHE)" "YES" THE_CLANG_MODULE_CACHE_DIR := $(BUILDDIR)/private-module-cache else |