Ran the sources through the compiler with -Wshadow warnings
enabled after we'd found a few bugs that were caused by shadowed
local variables; the most important issue this turned up was
a common mistake of trying to obtain a mutex lock for the scope
of a code block by doing

        Mutex::Locker(m_map_mutex);

This doesn't assign the lock object to a local variable; it is
a temporary that has its dtor called immediately.  Instead,

        Mutex::Locker locker(m_map_mutex);

does what is intended.  For some reason -Wshadow happened to
highlight these as shadowed variables.

I also fixed a few obivous and easy shadowed variable issues
across the code base but there are a couple dozen more that
should be fixed when someone has a free minute.
<rdar://problem/12437585>




git-svn-id: https://llvm.org/svn/llvm-project/lldb/trunk@165269 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/source/API/SBDebugger.cpp b/source/API/SBDebugger.cpp
index ca39d2a..3540b28 100644
--- a/source/API/SBDebugger.cpp
+++ b/source/API/SBDebugger.cpp
@@ -555,7 +555,6 @@
     if (m_opaque_sp)
     {
         FileSpec file_spec (filename, true);
-        TargetSP target_sp;
         const bool add_dependent_modules = true;
         Error error (m_opaque_sp->GetTargetList().CreateTarget (*m_opaque_sp, 
                                                                 file_spec, 
diff --git a/source/API/SBProcess.cpp b/source/API/SBProcess.cpp
index f2613dd..ea2638c 100644
--- a/source/API/SBProcess.cpp
+++ b/source/API/SBProcess.cpp
@@ -1078,7 +1078,6 @@
     {
         Mutex::Locker api_locker (process_sp->GetTarget().GetAPIMutex());
         sb_error.SetError(process_sp->GetWatchpointSupportInfo (num));
-        LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
         if (log)
             log->Printf ("SBProcess(%p)::GetNumSupportedHardwareWatchpoints () => %u",
                          process_sp.get(), num);
diff --git a/source/Breakpoint/BreakpointResolverName.cpp b/source/Breakpoint/BreakpointResolverName.cpp
index 86a536c..0f0e06d 100644
--- a/source/Breakpoint/BreakpointResolverName.cpp
+++ b/source/Breakpoint/BreakpointResolverName.cpp
@@ -168,9 +168,9 @@
             if (context.module_sp)
             {
                 size_t num_names = m_func_names.size();
-                for (int i = 0; i < num_names; i++)
+                for (int j = 0; j < num_names; j++)
                 {
-                    uint32_t num_functions = context.module_sp->FindFunctions (m_func_names[i], 
+                    uint32_t num_functions = context.module_sp->FindFunctions (m_func_names[j], 
                                                                                NULL,
                                                                                m_func_name_type_mask, 
                                                                                include_symbols,
@@ -183,7 +183,7 @@
                     if (num_functions == 0 && !filter_by_cu)
                     {
                         if (m_func_name_type_mask & (eFunctionNameTypeBase | eFunctionNameTypeFull | eFunctionNameTypeAuto))
-                            context.module_sp->FindSymbolsWithNameAndType (m_func_names[i], eSymbolTypeCode, sym_list);
+                            context.module_sp->FindSymbolsWithNameAndType (m_func_names[j], eSymbolTypeCode, sym_list);
                     }
                 }
             }
diff --git a/source/Commands/CommandObjectTarget.cpp b/source/Commands/CommandObjectTarget.cpp
index 226c00f..82f7cf3 100644
--- a/source/Commands/CommandObjectTarget.cpp
+++ b/source/Commands/CommandObjectTarget.cpp
@@ -3855,9 +3855,9 @@
                     const size_t num_matches = FindModulesByName (target, arg_cstr, module_list, false);
                     if (num_matches > 0)
                     {
-                        for (size_t i=0; i<num_matches; ++i)
+                        for (size_t j=0; j<num_matches; ++j)
                         {
-                            Module *module = module_list.GetModulePointerAtIndex(i);
+                            Module *module = module_list.GetModulePointerAtIndex(j);
                             if (module)
                             {
                                 if (LookupInModule (m_interpreter, module, result, syntax_error))
diff --git a/source/Core/Communication.cpp b/source/Core/Communication.cpp
index 64cc2f9..0c7a890 100644
--- a/source/Core/Communication.cpp
+++ b/source/Core/Communication.cpp
@@ -208,7 +208,7 @@
 {
     lldb::ConnectionSP connection_sp (m_connection_sp);
 
-    Mutex::Locker (m_write_mutex);
+    Mutex::Locker locker(m_write_mutex);
     lldb_private::LogIfAnyCategoriesSet (LIBLLDB_LOG_COMMUNICATION,
                                          "%p Communication::Write (src = %p, src_len = %llu) connection = %p",
                                          this, 
diff --git a/source/Core/DataBufferMemoryMap.cpp b/source/Core/DataBufferMemoryMap.cpp
index 1668b56..8f9b56d 100644
--- a/source/Core/DataBufferMemoryMap.cpp
+++ b/source/Core/DataBufferMemoryMap.cpp
@@ -97,15 +97,15 @@
 // offset.
 //----------------------------------------------------------------------
 size_t
-DataBufferMemoryMap::MemoryMapFromFileSpec (const FileSpec* file, 
+DataBufferMemoryMap::MemoryMapFromFileSpec (const FileSpec* filespec,
                                             off_t offset, 
                                             size_t length,
                                             bool writeable)
 {
-    if (file != NULL)
+    if (filespec != NULL)
     {
         char path[PATH_MAX];
-        if (file->GetPath(path, sizeof(path)))
+        if (filespec->GetPath(path, sizeof(path)))
         {
             uint32_t options = File::eOpenOptionRead;
             if (writeable)
diff --git a/source/Core/FormatManager.cpp b/source/Core/FormatManager.cpp
index ef0e719..deb1169 100644
--- a/source/Core/FormatManager.cpp
+++ b/source/Core/FormatManager.cpp
@@ -413,7 +413,7 @@
                          const char** matching_category,
                          TypeCategoryImpl::FormatCategoryItems* matching_type)
 {
-    Mutex::Locker(m_map_mutex);
+    Mutex::Locker locker(m_map_mutex);
     
     MapIterator pos, end = m_map.end();
     for (pos = m_map.begin(); pos != end; pos++)
@@ -432,7 +432,7 @@
 CategoryMap::GetSummaryFormat (ValueObject& valobj,
                                lldb::DynamicValueType use_dynamic)
 {
-    Mutex::Locker(m_map_mutex);
+    Mutex::Locker locker(m_map_mutex);
     
     uint32_t reason_why;        
     ActiveCategoriesIterator begin, end = m_active_categories.end();
@@ -548,7 +548,7 @@
 CategoryMap::GetSyntheticChildren (ValueObject& valobj,
                                    lldb::DynamicValueType use_dynamic)
 {
-    Mutex::Locker(m_map_mutex);
+    Mutex::Locker locker(m_map_mutex);
     
     uint32_t reason_why;
     
@@ -571,7 +571,7 @@
 {
     if (callback)
     {
-        Mutex::Locker(m_map_mutex);
+        Mutex::Locker locker(m_map_mutex);
         
         // loop through enabled categories in respective order
         {
@@ -603,7 +603,7 @@
 TypeCategoryImplSP
 CategoryMap::GetAtIndex (uint32_t index)
 {
-    Mutex::Locker(m_map_mutex);
+    Mutex::Locker locker(m_map_mutex);
     
     if (index < m_map.size())
     {
diff --git a/source/Core/StreamCallback.cpp b/source/Core/StreamCallback.cpp
index edce04e..63f3c9f 100644
--- a/source/Core/StreamCallback.cpp
+++ b/source/Core/StreamCallback.cpp
@@ -35,7 +35,7 @@
 StreamString &
 StreamCallback::FindStreamForThread(lldb::tid_t cur_tid)
 {
-    Mutex::Locker (m_collection_mutex);
+    Mutex::Locker locker(m_collection_mutex);
     collection::iterator iter = m_accumulated_data.find (cur_tid);
     if (iter == m_accumulated_data.end())
     {
diff --git a/source/Expression/ClangExpressionDeclMap.cpp b/source/Expression/ClangExpressionDeclMap.cpp
index f4bdfc0..5166300 100644
--- a/source/Expression/ClangExpressionDeclMap.cpp
+++ b/source/Expression/ClangExpressionDeclMap.cpp
@@ -301,9 +301,7 @@
                            context);
     
     if (!user_type.GetOpaqueQualType())
-    {
-        lldb::LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_EXPRESSIONS));
-        
+    {        
         if (log)
             log->Printf("ClangExpressionDeclMap::BuildCastVariable - Couldn't export the type for a constant cast result");
         
diff --git a/source/Interpreter/OptionValueFileSpecLIst.cpp b/source/Interpreter/OptionValueFileSpecLIst.cpp
index 3328dc6..325460f 100644
--- a/source/Interpreter/OptionValueFileSpecLIst.cpp
+++ b/source/Interpreter/OptionValueFileSpecLIst.cpp
@@ -150,9 +150,9 @@
                     {
                         // Sort and then erase in reverse so indexes are always valid
                         std::sort(remove_indexes.begin(), remove_indexes.end());
-                        for (int i=num_remove_indexes-1; i<num_remove_indexes; ++i)
+                        for (int j=num_remove_indexes-1; j<num_remove_indexes; ++j)
                         {
-                            m_current_value.Remove (i);
+                            m_current_value.Remove (j);
                         }
                     }
                 }
diff --git a/source/Interpreter/OptionValuePathMappings.cpp b/source/Interpreter/OptionValuePathMappings.cpp
index d507b14..b594938 100644
--- a/source/Interpreter/OptionValuePathMappings.cpp
+++ b/source/Interpreter/OptionValuePathMappings.cpp
@@ -151,9 +151,9 @@
                     {
                         // Sort and then erase in reverse so indexes are always valid
                         std::sort(remove_indexes.begin(), remove_indexes.end());
-                        for (int i=num_remove_indexes-1; i<num_remove_indexes; ++i)
+                        for (int j=num_remove_indexes-1; j<num_remove_indexes; ++j)
                         {
-                            m_path_mappings.Remove (i, m_notify_changes);
+                            m_path_mappings.Remove (j, m_notify_changes);
                         }
                     }
                 }
diff --git a/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.cpp b/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.cpp
index ba29279..a72fe58 100644
--- a/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.cpp
+++ b/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.cpp
@@ -117,7 +117,7 @@
 AppleObjCRuntimeV2::RunFunctionToFindClassName(addr_t object_addr, Thread *thread, char *name_dst, size_t max_name_len)
 {
     // Since we are going to run code we have to make sure only one thread at a time gets to try this.
-    Mutex::Locker (m_get_class_name_args_mutex);
+    Mutex::Locker locker(m_get_class_name_args_mutex);
     
     StreamString errors;
     
diff --git a/source/Target/Process.cpp b/source/Target/Process.cpp
index 5858f99..2dbe88f 100644
--- a/source/Target/Process.cpp
+++ b/source/Target/Process.cpp
@@ -3131,7 +3131,6 @@
         
                 if (state != eStateStopped)
                 {
-                    LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_PROCESS));
                     if (log)
                         log->Printf("Process::Destroy() Halt failed to stop, state is: %s", StateAsCString(state));
                     // If we really couldn't stop the process then we should just error out here, but if the
@@ -3147,7 +3146,6 @@
             }
             else
             {
-                LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_PROCESS));
                 if (log)
                     log->Printf("Process::Destroy() Halt got error: %s", error.AsCString());
                 return error;
diff --git a/source/Target/StopInfo.cpp b/source/Target/StopInfo.cpp
index b9c70d9..26c2cf5 100644
--- a/source/Target/StopInfo.cpp
+++ b/source/Target/StopInfo.cpp
@@ -316,10 +316,10 @@
         {
             m_should_stop = true;
             m_should_stop_is_valid = true;
-            LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_PROCESS));
+            LogSP log_process(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_PROCESS));
 
-            if (log)
-                log->Printf ("Process::%s could not find breakpoint site id: %lld...", __FUNCTION__, m_value);
+            if (log_process)
+                log_process->Printf ("Process::%s could not find breakpoint site id: %lld...", __FUNCTION__, m_value);
         }
         if (log)
             log->Printf ("Process::%s returning from action with m_should_stop: %d.", __FUNCTION__, m_should_stop);
@@ -676,10 +676,10 @@
         }
         else
         {
-            LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_PROCESS));
+            LogSP log_process(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_PROCESS));
 
-            if (log)
-                log->Printf ("Process::%s could not find watchpoint id: %lld...", __FUNCTION__, m_value);
+            if (log_process)
+                log_process->Printf ("Process::%s could not find watchpoint id: %lld...", __FUNCTION__, m_value);
         }
         if (log)
             log->Printf ("Process::%s returning from action with m_should_stop: %d.", __FUNCTION__, m_should_stop);