[Lldb-commits] [lldb] r139476 - /lldb/trunk/source/Interpreter/CommandInterpreter.cpp

Greg Clayton gclayton at apple.com
Sat Sep 10 17:01:44 PDT 2011


Author: gclayton
Date: Sat Sep 10 19:01:44 2011
New Revision: 139476

URL: http://llvm.org/viewvc/llvm-project?rev=139476&view=rev
Log:
Don't skip the application specific ~/.lldbinit file when the program
name is "lldb". So currently when you startup any application and you
have not specified that you would like to skip loading init files through
the API or from "lldb" options, then LLDB will try and load:

"~/.lldbinit-%s" where %s the basename of your program
"~/.lldbinit"

Then LLDB will load any program specified on the command line and then
source the "./.llbinit" file for any temporary debug session specific
commands.

I want this feature because I have thread and frame formats that do
ANSI color codes that I only want to load when running in a terminal
which is when I am running the "lldb" command line program.


Modified:
    lldb/trunk/source/Interpreter/CommandInterpreter.cpp

Modified: lldb/trunk/source/Interpreter/CommandInterpreter.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Interpreter/CommandInterpreter.cpp?rev=139476&r1=139475&r2=139476&view=diff
==============================================================================
--- lldb/trunk/source/Interpreter/CommandInterpreter.cpp (original)
+++ lldb/trunk/source/Interpreter/CommandInterpreter.cpp Sat Sep 10 19:01:44 2011
@@ -1793,38 +1793,45 @@
 void
 CommandInterpreter::SourceInitFile (bool in_cwd, CommandReturnObject &result)
 {
-    // Don't parse any .lldbinit files if we were asked not to
-    if (m_skip_lldbinit_files && m_skip_app_init_files)
-        return;
-
-    const char *init_file_path = in_cwd ? "./.lldbinit" : "~/.lldbinit";
-
-    std::string app_specific_init;
-    
-    if (!m_skip_app_init_files)
-    {
-        FileSpec host_spec = Host::GetProgramFileSpec();
-        const char *host_name = host_spec.GetFilename().AsCString();
-    
-        if (host_name != NULL && strcmp (host_name, "lldb") != 0)
-        {
-            app_specific_init += init_file_path;
-            app_specific_init += "-";
-            app_specific_init += host_name;
-        }
-    }
-    
     FileSpec init_file;
-    if (!app_specific_init.empty())
+    if (in_cwd)
     {
-        init_file.SetFile (app_specific_init.c_str(), true);
+        // In the current working directory we don't load any program specific
+        // .lldbinit files, we only look for a "./.lldbinit" file.
+        if (m_skip_lldbinit_files)
+            return;
+
+        init_file.SetFile ("./.lldbinit", true);
     }
-    
-    if (!m_skip_lldbinit_files && !init_file.Exists())
+    else
     {
-        init_file.SetFile (init_file_path, true);
-    }
+        // If we aren't looking in the current working directory we are looking
+        // in the home directory. We will first see if there is an application
+        // specific ".lldbinit" file whose name is "~/.lldbinit" followed by a 
+        // "-" and the name of the program. If this file doesn't exist, we fall
+        // back to just the "~/.lldbinit" file. We also obey any requests to not
+        // load the init files.
+        const char *init_file_path = "~/.lldbinit";
+
+        if (m_skip_app_init_files == false)
+        {
+            FileSpec program_file_spec (Host::GetProgramFileSpec());
+            const char *program_name = program_file_spec.GetFilename().AsCString();
     
+            if (program_name)
+            {
+                char program_init_file_name[PATH_MAX];
+                ::snprintf (program_init_file_name, sizeof(program_init_file_name), "%s-%s", init_file_path, program_name);
+                init_file.SetFile (program_init_file_name, true);
+                if (!init_file.Exists())
+                    init_file.Clear();
+            }
+        }
+        
+        if (!init_file && !m_skip_lldbinit_files)
+			init_file.SetFile (init_file_path, true);
+    }
+
     // If the file exists, tell HandleCommand to 'source' it; this will do the actual broadcasting
     // of the commands back to any appropriate listener (see CommandObjectSource::Execute for more details).
 





More information about the lldb-commits mailing list