Skip to content

Change image list -r so that it actually shows the ref count and whether the image is in the shared cache. #83341

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 29, 2024

Conversation

jimingham
Copy link
Collaborator

The help for the -r option to image list says:

   -r[<width>] ( --ref-count=[<width>] )
        Display the reference count if the module is still in the shared module cache.

but that's not what it actually does. It unconditionally shows the use_count for all Module shared pointers, regardless of whether they are still in the shared module cache or whether they are just in the ModuleCollection and other entities are keeping them alive. That seems like a more useful behavior, but then it is also useful to know what's in the shared cache, so I changed this to:

   -r[<width>] ( --ref-count=[<width>] )
        Display whether the module is still in the the shared module cache (Y/N), and its shared pointer use_count.

So instead of just {5} you will see {Y 5} if it is in the shared cache and {N 5} if not.

I didn't add tests for this because I'm not sure how much we want to fix shared cache behavior in the testsuite.

whether the image is in the shared cache.
@jimingham jimingham requested review from clayborg and medismailben and removed request for JDevlieghere February 28, 2024 21:22
@llvmbot llvmbot added the lldb label Feb 28, 2024
@llvmbot
Copy link
Member

llvmbot commented Feb 28, 2024

@llvm/pr-subscribers-lldb

Author: None (jimingham)

Changes

The help for the -r option to image list says:

   -r[&lt;width&gt;] ( --ref-count=[&lt;width&gt;] )
        Display the reference count if the module is still in the shared module cache.

but that's not what it actually does. It unconditionally shows the use_count for all Module shared pointers, regardless of whether they are still in the shared module cache or whether they are just in the ModuleCollection and other entities are keeping them alive. That seems like a more useful behavior, but then it is also useful to know what's in the shared cache, so I changed this to:

   -r[&lt;width&gt;] ( --ref-count=[&lt;width&gt;] )
        Display whether the module is still in the the shared module cache (Y/N), and its shared pointer use_count.

So instead of just {5} you will see {Y 5} if it is in the shared cache and {N 5} if not.

I didn't add tests for this because I'm not sure how much we want to fix shared cache behavior in the testsuite.


Full diff: https://github.com/llvm/llvm-project/pull/83341.diff

2 Files Affected:

  • (modified) lldb/source/Commands/CommandObjectTarget.cpp (+6-2)
  • (modified) lldb/source/Commands/Options.td (+2-2)
diff --git a/lldb/source/Commands/CommandObjectTarget.cpp b/lldb/source/Commands/CommandObjectTarget.cpp
index 45265577e8b61c..b2346c2402a81d 100644
--- a/lldb/source/Commands/CommandObjectTarget.cpp
+++ b/lldb/source/Commands/CommandObjectTarget.cpp
@@ -3376,15 +3376,19 @@ class CommandObjectTargetModulesList : public CommandObjectParsed {
 
       case 'r': {
         size_t ref_count = 0;
+        char in_shared_cache = 'Y';
+        
         ModuleSP module_sp(module->shared_from_this());
+        if (!ModuleList::ModuleIsInCache(module))
+          in_shared_cache = 'N';
         if (module_sp) {
           // Take one away to make sure we don't count our local "module_sp"
           ref_count = module_sp.use_count() - 1;
         }
         if (width)
-          strm.Printf("{%*" PRIu64 "}", width, (uint64_t)ref_count);
+          strm.Printf("{%c %*" PRIu64 "}", in_shared_cache, width, (uint64_t)ref_count);
         else
-          strm.Printf("{%" PRIu64 "}", (uint64_t)ref_count);
+          strm.Printf("{%c %" PRIu64 "}", in_shared_cache, (uint64_t)ref_count);
       } break;
 
       case 's':
diff --git a/lldb/source/Commands/Options.td b/lldb/source/Commands/Options.td
index ad4321d9a386cc..91d5eea830dedf 100644
--- a/lldb/source/Commands/Options.td
+++ b/lldb/source/Commands/Options.td
@@ -936,8 +936,8 @@ let Command = "target modules list" in {
     OptionalArg<"Width">, Desc<"Display the modification time with optional "
     "width of the module.">;
   def target_modules_list_ref_count : Option<"ref-count", "r">, Group<1>,
-    OptionalArg<"Width">, Desc<"Display the reference count if the module is "
-    "still in the shared module cache.">;
+    OptionalArg<"Width">, Desc<"Display whether the module is still in the "
+    "the shared module cache (Y/N), and its shared pointer use_count.">;
   def target_modules_list_pointer : Option<"pointer", "p">, Group<1>,
     OptionalArg<"None">, Desc<"Display the module pointer.">;
   def target_modules_list_global : Option<"global", "g">, Group<1>,

Copy link

⚠️ C/C++ code formatter, clang-format found issues in your code. ⚠️

You can test this locally with the following command:
git-clang-format --diff e427e934f677567f8184ff900cb4cbdb8cf21a21 b95ffa364ecfc8593dc48a1986385d81cbeb05c2 -- lldb/source/Commands/CommandObjectTarget.cpp
View the diff from clang-format here.
diff --git a/lldb/source/Commands/CommandObjectTarget.cpp b/lldb/source/Commands/CommandObjectTarget.cpp
index b2346c2402..0d52fde961 100644
--- a/lldb/source/Commands/CommandObjectTarget.cpp
+++ b/lldb/source/Commands/CommandObjectTarget.cpp
@@ -3377,7 +3377,7 @@ protected:
       case 'r': {
         size_t ref_count = 0;
         char in_shared_cache = 'Y';
-        
+
         ModuleSP module_sp(module->shared_from_this());
         if (!ModuleList::ModuleIsInCache(module))
           in_shared_cache = 'N';
@@ -3386,7 +3386,8 @@ protected:
           ref_count = module_sp.use_count() - 1;
         }
         if (width)
-          strm.Printf("{%c %*" PRIu64 "}", in_shared_cache, width, (uint64_t)ref_count);
+          strm.Printf("{%c %*" PRIu64 "}", in_shared_cache, width,
+                      (uint64_t)ref_count);
         else
           strm.Printf("{%c %" PRIu64 "}", in_shared_cache, (uint64_t)ref_count);
       } break;

@medismailben
Copy link
Member

medismailben commented Feb 28, 2024

Does it make sense to have an image multiple times in the shared cache ? If not, instead of saying {Y/N count} what about printing {location(shared cache/module collection)} and only print it ref count if it's not in the shared cache ?

@medismailben
Copy link
Member

Does it make sense to have an image multiple times in the shared cache ? If not, instead of saying {Y/N count} what about printing {location(shared cache/module collection)} and only print it ref count if it's not in the shared cache ?

My bad, I thought you were talking about the dyld shared cache as opposed to the lldb shared module cache. LGTM then.

@jimingham jimingham merged commit 9728170 into llvm:main Feb 29, 2024
@jimingham jimingham deleted the image-list-ref-count branch February 29, 2024 00:14
JDevlieghere pushed a commit to swiftlang/llvm-project that referenced this pull request Mar 15, 2024
…ether the image is in the shared cache. (llvm#83341)

The help for the `-r` option to `image list` says:

       -r[<width>] ( --ref-count=[<width>] )
Display the reference count if the module is still in the shared module
cache.

but that's not what it actually does. It unconditionally shows the
use_count for all Module shared pointers, regardless of whether they are
still in the shared module cache or whether they are just in the
ModuleCollection and other entities are keeping them alive. That seems
like a more useful behavior, but then it is also useful to know what's
in the shared cache, so I changed this to:

       -r[<width>] ( --ref-count=[<width>] )
Display whether the module is still in the the shared module cache
(Y/N), and its shared pointer use_count.

So instead of just `{5}` you will see `{Y 5}` if it is in the shared
cache and `{N 5}` if not.

I didn't add tests for this because I'm not sure how much we want to fix
shared cache behavior in the testsuite.

(cherry picked from commit 9728170)
mylai-mtk pushed a commit to mylai-mtk/llvm-project that referenced this pull request Jul 12, 2024
…ether the image is in the shared cache. (llvm#83341)

The help for the `-r` option to `image list` says:

       -r[<width>] ( --ref-count=[<width>] )
Display the reference count if the module is still in the shared module
cache.

but that's not what it actually does. It unconditionally shows the
use_count for all Module shared pointers, regardless of whether they are
still in the shared module cache or whether they are just in the
ModuleCollection and other entities are keeping them alive. That seems
like a more useful behavior, but then it is also useful to know what's
in the shared cache, so I changed this to:

       -r[<width>] ( --ref-count=[<width>] )
Display whether the module is still in the the shared module cache
(Y/N), and its shared pointer use_count.

So instead of just `{5}` you will see `{Y 5}` if it is in the shared
cache and `{N 5}` if not.

I didn't add tests for this because I'm not sure how much we want to fix
shared cache behavior in the testsuite.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants