<rdar://problem/12524607>

Flush the process when symbols are loaded/unloaded manually. This was going on in:
- "target modules load" command
- SBTarget::SetSectionLoadAddress(...)
- SBTarget::ClearSectionLoadAddress(...)
- SBTarget::SetModuleLoadAddress(...)
- SBTarget::ClearModuleLoadAddress(...)



git-svn-id: https://llvm.org/svn/llvm-project/lldb/trunk@173745 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/source/API/SBTarget.cpp b/source/API/SBTarget.cpp
index 79b038b..f4582da 100644
--- a/source/API/SBTarget.cpp
+++ b/source/API/SBTarget.cpp
@@ -2329,7 +2329,13 @@
                 }
                 else
                 {
-                    target_sp->GetSectionLoadList().SetSectionLoadAddress (section_sp, section_base_addr);
+                    if (target_sp->GetSectionLoadList().SetSectionLoadAddress (section_sp, section_base_addr))
+                    {
+                        // Flush info in the process (stack frames, etc)
+                        ProcessSP process_sp (target_sp->GetProcessSP());
+                        if (process_sp)
+                            process_sp->Flush();
+                    }
                 }
             }
         }
@@ -2355,7 +2361,13 @@
         }
         else
         {
-            target_sp->GetSectionLoadList().SetSectionUnloaded (section.GetSP());
+            if (target_sp->GetSectionLoadList().SetSectionUnloaded (section.GetSP()))
+            {
+                // Flush info in the process (stack frames, etc)
+                ProcessSP process_sp (target_sp->GetProcessSP());
+                if (process_sp)
+                    process_sp->Flush();                
+            }
         }
     }
     else
@@ -2386,6 +2398,10 @@
                     ModuleList module_list;
                     module_list.Append(module_sp);
                     target_sp->ModulesDidLoad (module_list);
+                    // Flush info in the process (stack frames, etc)
+                    ProcessSP process_sp (target_sp->GetProcessSP());
+                    if (process_sp)
+                        process_sp->Flush();
                 }
             }
         }
@@ -2420,12 +2436,20 @@
                 SectionList *section_list = objfile->GetSectionList();
                 if (section_list)
                 {
+                    bool changed = false;
                     const size_t num_sections = section_list->GetSize();
                     for (size_t sect_idx = 0; sect_idx < num_sections; ++sect_idx)
                     {
                         SectionSP section_sp (section_list->GetSectionAtIndex(sect_idx));
                         if (section_sp)
-                            target_sp->GetSectionLoadList().SetSectionUnloaded (section_sp);
+                            changed |= target_sp->GetSectionLoadList().SetSectionUnloaded (section_sp) > 0;
+                    }
+                    if (changed)
+                    {
+                        // Flush info in the process (stack frames, etc)
+                        ProcessSP process_sp (target_sp->GetProcessSP());
+                        if (process_sp)
+                            process_sp->Flush();                        
                     }
                 }
                 else
diff --git a/source/Commands/CommandObjectTarget.cpp b/source/Commands/CommandObjectTarget.cpp
index 55168ca..64d2684 100644
--- a/source/Commands/CommandObjectTarget.cpp
+++ b/source/Commands/CommandObjectTarget.cpp
@@ -2915,7 +2915,12 @@
                                 }
                                 
                                 if (changed)
+                                {
                                     target->ModulesDidLoad (matching_modules);
+                                    Process *process = m_exe_ctx.GetProcessPtr();
+                                    if (process)
+                                        process->Flush();
+                                }
                             }
                             else
                             {
@@ -4171,7 +4176,6 @@
     {
         LoadSubCommand ("add",          CommandObjectSP (new CommandObjectTargetModulesAdd (interpreter)));
         LoadSubCommand ("load",         CommandObjectSP (new CommandObjectTargetModulesLoad (interpreter)));
-        //LoadSubCommand ("unload",       CommandObjectSP (new CommandObjectTargetModulesUnload (interpreter)));
         LoadSubCommand ("dump",         CommandObjectSP (new CommandObjectTargetModulesDump (interpreter)));
         LoadSubCommand ("list",         CommandObjectSP (new CommandObjectTargetModulesList (interpreter)));
         LoadSubCommand ("lookup",       CommandObjectSP (new CommandObjectTargetModulesLookup (interpreter)));
diff --git a/source/Target/SectionLoadList.cpp b/source/Target/SectionLoadList.cpp
index 68aa7f0..17e5581 100644
--- a/source/Target/SectionLoadList.cpp
+++ b/source/Target/SectionLoadList.cpp
@@ -155,6 +155,7 @@
         sect_to_addr_collection::iterator sta_pos = m_sect_to_addr.find(section_sp.get());
         if (sta_pos != m_sect_to_addr.end())
         {
+            ++unload_count;
             addr_t load_addr = sta_pos->second;
             m_sect_to_addr.erase (sta_pos);