Skip to content
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

[LLDB][NFC]Move fields that might be referenced in scope-exit to beginning #133785

Merged
merged 1 commit into from
Apr 2, 2025

Conversation

oontvoo
Copy link
Member

@oontvoo oontvoo commented Mar 31, 2025

Details: The ScopedDiscpatcher's dtor may reference these fields so we need the fields' dtor to be be invoked after the dispatcher's.

…nning of functions so they are still valid when referenced.
@oontvoo oontvoo requested a review from JDevlieghere as a code owner March 31, 2025 19:49
@oontvoo oontvoo requested review from labath and removed request for JDevlieghere March 31, 2025 19:49
@llvmbot llvmbot added the lldb label Mar 31, 2025
@oontvoo oontvoo requested a review from JDevlieghere March 31, 2025 19:49
@llvmbot
Copy link
Member

llvmbot commented Mar 31, 2025

@llvm/pr-subscribers-lldb

Author: Vy Nguyen (oontvoo)

Changes

Details: The ScopedDiscpatcher's dtor may reference these fields so we need the fields' dtor to be be invoked after the dispatcher's.


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

1 Files Affected:

  • (modified) lldb/source/Interpreter/CommandInterpreter.cpp (+7-2)
diff --git a/lldb/source/Interpreter/CommandInterpreter.cpp b/lldb/source/Interpreter/CommandInterpreter.cpp
index 8e70922b9bb8d..7fbdf7fe70223 100644
--- a/lldb/source/Interpreter/CommandInterpreter.cpp
+++ b/lldb/source/Interpreter/CommandInterpreter.cpp
@@ -1886,6 +1886,13 @@ bool CommandInterpreter::HandleCommand(const char *command_line,
                                        LazyBool lazy_add_to_history,
                                        CommandReturnObject &result,
                                        bool force_repeat_command) {
+  // These are assigned later in the function but they must be declared before
+  // the ScopedDispatcher object because we need their destructions to occur
+  // after the dispatcher's dtor call, which may reference them.
+  // TODO: This function could be refactored?
+  std::string parsed_command_args;
+  CommandObject *cmd_obj = nullptr;
+
   telemetry::ScopedDispatcher<telemetry::CommandInfo> helper(&m_debugger);
   const bool detailed_command_telemetry =
       telemetry::TelemetryManager::GetInstance()
@@ -1896,8 +1903,6 @@ bool CommandInterpreter::HandleCommand(const char *command_line,
   std::string command_string(command_line);
   std::string original_command_string(command_string);
   std::string real_original_command_string(command_string);
-  std::string parsed_command_args;
-  CommandObject *cmd_obj = nullptr;
 
   helper.DispatchNow([&](lldb_private::telemetry::CommandInfo *info) {
     info->command_id = command_id;

@oontvoo oontvoo merged commit 87bebd3 into llvm:main Apr 2, 2025
12 checks passed
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.

None yet

3 participants