Skip to content

[lldb/crashlog] Add --no-parallel-image-loading hidden flag #94513

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

Conversation

medismailben
Copy link
Member

This patch adds the --no-parallel-image-loading to the crashlog command. By default, image loading will happen in parallel in the crashlog script however, sometimes, when running tests or debugging the crashlog script itself, it's better to load the images sequentially.

As its name suggests, this flag will disable the default image loading behaviour to load all the images sequencially in the main thread.

@llvmbot llvmbot added the lldb label Jun 5, 2024
@llvmbot
Copy link
Member

llvmbot commented Jun 5, 2024

@llvm/pr-subscribers-lldb

Author: Med Ismail Bennani (medismailben)

Changes

This patch adds the --no-parallel-image-loading to the crashlog command. By default, image loading will happen in parallel in the crashlog script however, sometimes, when running tests or debugging the crashlog script itself, it's better to load the images sequentially.

As its name suggests, this flag will disable the default image loading behaviour to load all the images sequencially in the main thread.


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

2 Files Affected:

  • (modified) lldb/examples/python/crashlog.py (+38-16)
  • (modified) lldb/examples/python/crashlog_scripted_process.py (+7)
diff --git a/lldb/examples/python/crashlog.py b/lldb/examples/python/crashlog.py
index 641b2e64d53b1..485e60ab95bba 100755
--- a/lldb/examples/python/crashlog.py
+++ b/lldb/examples/python/crashlog.py
@@ -555,30 +555,44 @@ def load_images(self, options, loaded_images=None):
 
         futures = []
         with tempfile.TemporaryDirectory() as obj_dir:
-            with concurrent.futures.ThreadPoolExecutor() as executor:
 
-                def add_module(image, target, obj_dir):
-                    return image, image.add_module(target, obj_dir)
+            def add_module(image, target, obj_dir):
+                return image, image.add_module(target, obj_dir)
+
+            if options.parallel_image_loading:
+                with concurrent.futures.ThreadPoolExecutor() as executor:
+                    for image in images_to_load:
+                        if image not in loaded_images:
+                            if image.uuid == uuid.UUID(int=0):
+                                continue
+                            futures.append(
+                                executor.submit(
+                                    add_module,
+                                    image=image,
+                                    target=self.target,
+                                    obj_dir=obj_dir,
+                                )
+                            )
 
+                    for future in concurrent.futures.as_completed(futures):
+                        image, err = future.result()
+                        if err:
+                            print(err)
+                        else:
+                            loaded_images.append(image)
+            else:
                 for image in images_to_load:
                     if image not in loaded_images:
                         if image.uuid == uuid.UUID(int=0):
                             continue
-                        futures.append(
-                            executor.submit(
-                                add_module,
-                                image=image,
-                                target=self.target,
-                                obj_dir=obj_dir,
-                            )
+                        image, err = add_module(
+                            image=image, target=self.target, obj_dir=obj_dir
                         )
 
-                for future in concurrent.futures.as_completed(futures):
-                    image, err = future.result()
-                    if err:
-                        print(err)
-                    else:
-                        loaded_images.append(image)
+                        if err:
+                            print(err)
+                        else:
+                            loaded_images.append(image)
 
 
 class CrashLogFormatException(Exception):
@@ -1528,6 +1542,7 @@ def load_crashlog_in_scripted_process(debugger, crashlog_path, options, result):
                 "file_path": crashlog_path,
                 "load_all_images": options.load_all_images,
                 "crashed_only": options.crashed_only,
+                "parallel_image_loading": options.parallel_image_loading,
             }
         )
     )
@@ -1720,6 +1735,13 @@ def CreateSymbolicateCrashLogOptions(
         help="show source for all threads, not just the crashed thread",
         default=False,
     )
+    arg_parser.add_argument(
+        "--no-parallel-image-loading",
+        dest="parallel_image_loading",
+        action="store_false",
+        help=argparse.SUPPRESS,
+        default=True,
+    )
     if add_interactive_options:
         arg_parser.add_argument(
             "-i",
diff --git a/lldb/examples/python/crashlog_scripted_process.py b/lldb/examples/python/crashlog_scripted_process.py
index 26c5c37b7371d..ebce4834ef198 100644
--- a/lldb/examples/python/crashlog_scripted_process.py
+++ b/lldb/examples/python/crashlog_scripted_process.py
@@ -84,6 +84,13 @@ def __init__(self, exe_ctx: lldb.SBExecutionContext, args: lldb.SBStructuredData
             if crashed_only.GetType() == lldb.eStructuredDataTypeBoolean:
                 self.options.crashed_only = crashed_only.GetBooleanValue()
 
+        parallel_image_loading = args.GetValueForKey("parallel_image_loading")
+        if parallel_image_loading and parallel_image_loading.IsValid():
+            if parallel_image_loading.GetType() == lldb.eStructuredDataTypeBoolean:
+                self.options.parallel_image_loading = (
+                    parallel_image_loading.GetBooleanValue()
+                )
+
         self.pid = super().get_process_id()
         self.crashed_thread_idx = 0
         self.exception = None

@medismailben medismailben force-pushed the crashlog-no-parallel-image-loading branch from 4f3d032 to eb62de9 Compare June 5, 2024 19:29
This patch adds the `--no-parallel-image-loading` to the crashlog
command. By default, image loading will happen in parallel in the
crashlog script however, sometimes, when running tests or debugging the
crashlog script itself, it's better to load the images sequentially.

As its name suggests, this flag will disable the default image loading
behaviour to load all the images sequencially in the main thread.

Signed-off-by: Med Ismail Bennani <[email protected]>
@medismailben medismailben force-pushed the crashlog-no-parallel-image-loading branch from eb62de9 to cc40507 Compare June 5, 2024 20:12
@medismailben medismailben merged commit 68a9cb7 into llvm:main Jun 5, 2024
5 checks passed
medismailben added a commit to medismailben/llvm-project that referenced this pull request Jun 6, 2024
…4513)

This patch adds the `--no-parallel-image-loading` to the crashlog
command. By default, image loading will happen in parallel in the
crashlog script however, sometimes, when running tests or debugging the
crashlog script itself, it's better to load the images sequentially.

As its name suggests, this flag will disable the default image loading
behaviour to load all the images sequencially in the main thread.

Signed-off-by: Med Ismail Bennani <[email protected]>
(cherry picked from commit 68a9cb7)
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.

3 participants