[Lldb-commits] [lldb] r219169 - Add "target.expr-parser-compiler-args" setting.

Todd Fiala todd.fiala at gmail.com
Mon Oct 6 16:13:30 PDT 2014


Author: tfiala
Date: Mon Oct  6 18:13:30 2014
New Revision: 219169

URL: http://llvm.org/viewvc/llvm-project?rev=219169&view=rev
Log:
Add "target.expr-parser-compiler-args" setting.

This setting contains the following:
A list containing all the arguments to be passed to the expression parser compiler.

This change also ensures quoted arguments are handled appropriately.

See http://reviews.llvm.org/D5472 for more details.

Change by Tong Shen.

Modified:
    lldb/trunk/include/lldb/Expression/ClangExpressionParser.h
    lldb/trunk/include/lldb/Target/Target.h
    lldb/trunk/source/Expression/ClangExpressionParser.cpp
    lldb/trunk/source/Expression/ClangFunction.cpp
    lldb/trunk/source/Expression/ClangUserExpression.cpp
    lldb/trunk/source/Expression/ClangUtilityFunction.cpp
    lldb/trunk/source/Interpreter/Args.cpp
    lldb/trunk/source/Target/Target.cpp

Modified: lldb/trunk/include/lldb/Expression/ClangExpressionParser.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Expression/ClangExpressionParser.h?rev=219169&r1=219168&r2=219169&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Expression/ClangExpressionParser.h (original)
+++ lldb/trunk/include/lldb/Expression/ClangExpressionParser.h Mon Oct  6 18:13:30 2014
@@ -52,6 +52,7 @@ public:
     //------------------------------------------------------------------
     ClangExpressionParser (ExecutionContextScope *exe_scope,
                            ClangExpression &expr,
+                           Args &expr_parser_compiler_args,
                            bool generate_debug_info);
     
     //------------------------------------------------------------------

Modified: lldb/trunk/include/lldb/Target/Target.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Target/Target.h?rev=219169&r1=219168&r2=219169&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Target/Target.h (original)
+++ lldb/trunk/include/lldb/Target/Target.h Mon Oct  6 18:13:30 2014
@@ -113,6 +113,12 @@ public:
     
     void
     SetRunArguments (const Args &args);
+
+    bool
+    GetExprParserCompilerArguments (Args &args) const;
+
+    void
+    SetExprParserCompilerArguments (const Args &args);
     
     size_t
     GetEnvironmentAsArgs (Args &env) const;

Modified: lldb/trunk/source/Expression/ClangExpressionParser.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Expression/ClangExpressionParser.cpp?rev=219169&r1=219168&r2=219169&view=diff
==============================================================================
--- lldb/trunk/source/Expression/ClangExpressionParser.cpp (original)
+++ lldb/trunk/source/Expression/ClangExpressionParser.cpp Mon Oct  6 18:13:30 2014
@@ -98,6 +98,7 @@ std::string GetBuiltinIncludePath(const
 
 ClangExpressionParser::ClangExpressionParser (ExecutionContextScope *exe_scope,
                                               ClangExpression &expr,
+                                              Args &expr_parser_compiler_args,
                                               bool generate_debug_info) :
     m_expr (expr),
     m_compiler (),
@@ -152,6 +153,11 @@ ClangExpressionParser::ClangExpressionPa
 
     // 3. Set options.
 
+    clang::CompilerInvocation::CreateFromArgs(m_compiler->getInvocation(),
+        expr_parser_compiler_args.GetConstArgumentVector(),
+        expr_parser_compiler_args.GetConstArgumentVector() + expr_parser_compiler_args.GetArgumentCount(),
+        m_compiler->getDiagnostics());
+
     lldb::LanguageType language = expr.Language();
 
     switch (language)

Modified: lldb/trunk/source/Expression/ClangFunction.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Expression/ClangFunction.cpp?rev=219169&r1=219168&r2=219169&view=diff
==============================================================================
--- lldb/trunk/source/Expression/ClangFunction.cpp (original)
+++ lldb/trunk/source/Expression/ClangFunction.cpp Mon Oct  6 18:13:30 2014
@@ -238,7 +238,9 @@ ClangFunction::CompileFunction (Stream &
     if (jit_process_sp)
     {
         const bool generate_debug_info = true;
-        m_parser.reset(new ClangExpressionParser(jit_process_sp.get(), *this, generate_debug_info));
+        Args expr_parser_compiler_args;
+        jit_process_sp->GetTarget().GetExprParserCompilerArguments (expr_parser_compiler_args);
+        m_parser.reset(new ClangExpressionParser(jit_process_sp.get(), *this, expr_parser_compiler_args, generate_debug_info));
         
         num_errors = m_parser->Parse (errors);
     }

Modified: lldb/trunk/source/Expression/ClangUserExpression.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Expression/ClangUserExpression.cpp?rev=219169&r1=219168&r2=219169&view=diff
==============================================================================
--- lldb/trunk/source/Expression/ClangUserExpression.cpp (original)
+++ lldb/trunk/source/Expression/ClangUserExpression.cpp Mon Oct  6 18:13:30 2014
@@ -527,7 +527,9 @@ ClangUserExpression::Parse (Stream &erro
     if (!exe_scope)
         exe_scope = exe_ctx.GetTargetPtr();
 
-    ClangExpressionParser parser(exe_scope, *this, generate_debug_info);
+    Args expr_parser_compiler_args;
+    target->GetExprParserCompilerArguments (expr_parser_compiler_args);
+    ClangExpressionParser parser(exe_scope, *this, expr_parser_compiler_args, generate_debug_info);
 
     unsigned num_errors = parser.Parse (error_stream);
 

Modified: lldb/trunk/source/Expression/ClangUtilityFunction.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Expression/ClangUtilityFunction.cpp?rev=219169&r1=219168&r2=219169&view=diff
==============================================================================
--- lldb/trunk/source/Expression/ClangUtilityFunction.cpp (original)
+++ lldb/trunk/source/Expression/ClangUtilityFunction.cpp Mon Oct  6 18:13:30 2014
@@ -122,7 +122,9 @@ ClangUtilityFunction::Install (Stream &e
     }
     
     const bool generate_debug_info = true;
-    ClangExpressionParser parser(exe_ctx.GetBestExecutionContextScope(), *this, generate_debug_info);
+    Args expr_parser_compiler_args;
+    target->GetExprParserCompilerArguments (expr_parser_compiler_args);
+    ClangExpressionParser parser(exe_ctx.GetBestExecutionContextScope(), *this, expr_parser_compiler_args, generate_debug_info);
     
     unsigned num_errors = parser.Parse (error_stream);
     

Modified: lldb/trunk/source/Interpreter/Args.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Interpreter/Args.cpp?rev=219169&r1=219168&r2=219169&view=diff
==============================================================================
--- lldb/trunk/source/Interpreter/Args.cpp (original)
+++ lldb/trunk/source/Interpreter/Args.cpp Mon Oct  6 18:13:30 2014
@@ -647,6 +647,20 @@ Args::ParseOptions (Options &options)
     }
     OptionParser::Prepare();
     int val;
+
+    // Before parsing arguments, insert quote char to the head of the string.
+    // So quoted arguments like "-l" won't be treated as option.
+    int argv_iter = 0;
+    for (auto args_iter = m_args.begin(); args_iter != m_args.end(); args_iter++, argv_iter++)
+    {
+        char quote_char = GetArgumentQuoteCharAtIndex(argv_iter);
+        if (quote_char != '\0')
+        {
+            *args_iter = std::string(1, quote_char) + *args_iter;
+            m_argv[argv_iter] = args_iter->c_str();
+        }
+    }
+
     while (1)
     {
         int long_options_index = -1;
@@ -696,8 +710,23 @@ Args::ParseOptions (Options &options)
             }
             else
             {
+                const char *value = OptionParser::GetOptionArgument();
+                if (value)
+                {
+                    // Remove leading quote char from option value
+                    argv_iter = 0;
+                    for (auto args_iter = m_args.begin(); args_iter != m_args.end(); args_iter++, argv_iter++)
+                    {
+                        if (*args_iter == value && GetArgumentQuoteCharAtIndex(argv_iter) != '\0')
+                        {
+                            *args_iter = args_iter->substr(1);
+                            value = args_iter->c_str();
+                            break;
+                        }
+                    }
+                }
                 error = options.SetOptionValue(long_options_index,
-                                               (def->option_has_arg == OptionParser::eNoArgument) ? nullptr : OptionParser::GetOptionArgument());
+                                               (def->option_has_arg == OptionParser::eNoArgument) ? nullptr : value);
             }
         }
         else
@@ -711,6 +740,19 @@ Args::ParseOptions (Options &options)
     // Update our ARGV now that get options has consumed all the options
     m_argv.erase(m_argv.begin(), m_argv.begin() + OptionParser::GetOptionIndex());
     UpdateArgsAfterOptionParsing ();
+
+    // Remove leading quote char from other arguments.
+    argv_iter = 0;
+    for (auto args_iter = m_args.begin(); args_iter != m_args.end(); args_iter++, argv_iter++)
+    {
+        char quote_char = GetArgumentQuoteCharAtIndex(argv_iter);
+        if (quote_char != '\0')
+        {
+            *args_iter = args_iter->substr(1);
+            m_argv[argv_iter] = args_iter->c_str();
+        }
+    }
+
     return error;
 }
 

Modified: lldb/trunk/source/Target/Target.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Target/Target.cpp?rev=219169&r1=219168&r2=219169&view=diff
==============================================================================
--- lldb/trunk/source/Target/Target.cpp (original)
+++ lldb/trunk/source/Target/Target.cpp Mon Oct  6 18:13:30 2014
@@ -2653,6 +2653,7 @@ g_properties[] =
     { "breakpoints-use-platform-avoid-list", OptionValue::eTypeBoolean   , false, true                      , NULL, NULL, "Consult the platform module avoid list when setting non-module specific breakpoints." },
     { "arg0"                               , OptionValue::eTypeString    , false, 0                         , NULL, NULL, "The first argument passed to the program in the argument array which can be different from the executable itself." },
     { "run-args"                           , OptionValue::eTypeArgs      , false, 0                         , NULL, NULL, "A list containing all the arguments to be passed to the executable when it is run. Note that this does NOT include the argv[0] which is in target.arg0." },
+    { "expr-parser-compiler-args"          , OptionValue::eTypeArgs      , false, 0                         , NULL, NULL, "A list containing all the arguments to be passed to the expression parser compiler." },
     { "env-vars"                           , OptionValue::eTypeDictionary, false, OptionValue::eTypeString  , NULL, NULL, "A list of all the environment variables to be passed to the executable's environment, and their values." },
     { "inherit-env"                        , OptionValue::eTypeBoolean   , false, true                      , NULL, NULL, "Inherit the environment from the process that is running LLDB." },
     { "input-path"                         , OptionValue::eTypeFileSpec  , false, 0                         , NULL, NULL, "The file/path to be used by the executable program for reading its standard input." },
@@ -2701,6 +2702,7 @@ enum
     ePropertyBreakpointUseAvoidList,
     ePropertyArg0,
     ePropertyRunArgs,
+    ePropertyExprParserCompilerArgs,
     ePropertyEnvVars,
     ePropertyInheritEnv,
     ePropertyInputPath,
@@ -2956,6 +2958,20 @@ TargetProperties::GetRunArguments (Args
     return m_collection_sp->GetPropertyAtIndexAsArgs (NULL, idx, args);
 }
 
+void
+TargetProperties::SetExprParserCompilerArguments (const Args &args)
+{
+    const uint32_t idx = ePropertyExprParserCompilerArgs;
+    m_collection_sp->SetPropertyAtIndexFromArgs (NULL, idx, args);
+}
+
+bool
+TargetProperties::GetExprParserCompilerArguments (Args &args) const
+{
+    const uint32_t idx = ePropertyExprParserCompilerArgs;
+    return m_collection_sp->GetPropertyAtIndexAsArgs (NULL, idx, args);
+}
+
 void
 TargetProperties::SetRunArguments (const Args &args)
 {





More information about the lldb-commits mailing list