[Lldb-commits] [lldb] b620852 - [lldb] Make the g_arguments_data constexpr and fix the static assert

Jonas Devlieghere via lldb-commits lldb-commits at lists.llvm.org
Tue Jul 12 13:12:45 PDT 2022


Author: Jonas Devlieghere
Date: 2022-07-12T13:12:36-07:00
New Revision: b620852d235079e56a4fdf71828bf8e7c66f813f

URL: https://github.com/llvm/llvm-project/commit/b620852d235079e56a4fdf71828bf8e7c66f813f
DIFF: https://github.com/llvm/llvm-project/commit/b620852d235079e56a4fdf71828bf8e7c66f813f.diff

LOG: [lldb] Make the g_arguments_data constexpr and fix the static assert

This fixes the static assert that's meant to keep the g_arguments_data
table in sync with the CommandArgumentType enumeration. Indeed, the
assert didn't fire even though the current code is missing an entry.
This patches fixes that as well.

Differential revision: https://reviews.llvm.org/D129529

Added: 
    

Modified: 
    lldb/include/lldb/Interpreter/CommandObject.h
    lldb/source/Interpreter/CommandObject.cpp

Removed: 
    


################################################################################
diff  --git a/lldb/include/lldb/Interpreter/CommandObject.h b/lldb/include/lldb/Interpreter/CommandObject.h
index 45fc47b02c046..0fc1c61bdb92f 100644
--- a/lldb/include/lldb/Interpreter/CommandObject.h
+++ b/lldb/include/lldb/Interpreter/CommandObject.h
@@ -104,9 +104,6 @@ class CommandObject {
   typedef std::vector<CommandArgumentData>
       CommandArgumentEntry; // Used to build individual command argument lists
 
-  static ArgumentTableEntry g_arguments_data
-      [lldb::eArgTypeLastArg]; // Main argument information table
-
   typedef std::map<std::string, lldb::CommandObjectSP> CommandMap;
 
   CommandObject(CommandInterpreter &interpreter, llvm::StringRef name,

diff  --git a/lldb/source/Interpreter/CommandObject.cpp b/lldb/source/Interpreter/CommandObject.cpp
index c92fec53a55e9..910d740625e98 100644
--- a/lldb/source/Interpreter/CommandObject.cpp
+++ b/lldb/source/Interpreter/CommandObject.cpp
@@ -547,7 +547,7 @@ CommandObject::LookupArgumentName(llvm::StringRef arg_name) {
   const ArgumentTableEntry *table = GetArgumentTable();
   for (int i = 0; i < eArgTypeLastArg; ++i)
     if (arg_name == table[i].arg_name)
-      return_type = g_arguments_data[i].arg_type;
+      return_type = GetArgumentTable()[i].arg_type;
 
   return return_type;
 }
@@ -924,14 +924,14 @@ const char *CommandObject::GetArgumentTypeAsCString(
     const lldb::CommandArgumentType arg_type) {
   assert(arg_type < eArgTypeLastArg &&
          "Invalid argument type passed to GetArgumentTypeAsCString");
-  return g_arguments_data[arg_type].arg_name;
+  return GetArgumentTable()[arg_type].arg_name;
 }
 
 const char *CommandObject::GetArgumentDescriptionAsCString(
     const lldb::CommandArgumentType arg_type) {
   assert(arg_type < eArgTypeLastArg &&
          "Invalid argument type passed to GetArgumentDescriptionAsCString");
-  return g_arguments_data[arg_type].help_text;
+  return GetArgumentTable()[arg_type].help_text;
 }
 
 Target &CommandObject::GetDummyTarget() {
@@ -1041,7 +1041,7 @@ static llvm::StringRef arch_helper() {
   return g_archs_help.GetString();
 }
 
-CommandObject::ArgumentTableEntry CommandObject::g_arguments_data[] = {
+static constexpr CommandObject::ArgumentTableEntry g_arguments_data[] = {
     // clang-format off
     { eArgTypeAddress, "address", CommandCompletions::eNoCompletion, { nullptr, false }, "A valid address in the target program's execution space." },
     { eArgTypeAddressOrExpression, "address-expression", CommandCompletions::eNoCompletion, { nullptr, false }, "An expression that resolves to an address." },
@@ -1134,17 +1134,18 @@ CommandObject::ArgumentTableEntry CommandObject::g_arguments_data[] = {
     { eArgTypeSaveCoreStyle, "corefile-style", CommandCompletions::eNoCompletion, { nullptr, false }, "The type of corefile that lldb will try to create, dependant on this target's capabilities." },
     { eArgTypeLogHandler, "log-handler", CommandCompletions::eNoCompletion, { nullptr, false }, "The log handle that will be used to write out log messages." },
     { eArgTypeSEDStylePair, "substitution-pair", CommandCompletions::eNoCompletion, { nullptr, false }, "A sed-style pattern and target pair." },
+    { eArgTypeRecognizerID, "frame-recognizer-id", CommandCompletions::eNoCompletion, { nullptr, false }, "The ID for a stack frame recognizer." },
     { eArgTypeConnectURL, "process-connect-url", CommandCompletions::eNoCompletion, { nullptr, false }, "A URL-style specification for a remote connection." },
     { eArgTypeTargetID, "target-id", CommandCompletions::eNoCompletion, { nullptr, false }, "The index ID for an lldb Target." },
     { eArgTypeStopHookID, "stop-hook-id", CommandCompletions::eNoCompletion, { nullptr, false }, "The ID you receive when you create a stop-hook." }
     // clang-format on
 };
 
+static_assert(
+    (sizeof(g_arguments_data) / sizeof(CommandObject::ArgumentTableEntry)) ==
+        eArgTypeLastArg,
+    "g_arguments_data out of sync with CommandArgumentType enumeration");
+
 const CommandObject::ArgumentTableEntry *CommandObject::GetArgumentTable() {
-  // If this assertion fires, then the table above is out of date with the
-  // CommandArgumentType enumeration
-  static_assert((sizeof(CommandObject::g_arguments_data) /
-                 sizeof(CommandObject::ArgumentTableEntry)) == eArgTypeLastArg,
-                "");
-  return CommandObject::g_arguments_data;
+  return g_arguments_data;
 }


        


More information about the lldb-commits mailing list