[Lldb-commits] [lldb] r241210 - Check to make sure we have a valid N_GSYM symbol name before we use it for anything.

Greg Clayton gclayton at apple.com
Wed Jul 1 16:29:07 PDT 2015


Author: gclayton
Date: Wed Jul  1 18:29:06 2015
New Revision: 241210

URL: http://llvm.org/viewvc/llvm-project?rev=241210&view=rev
Log:
Check to make sure we have a valid N_GSYM symbol name before we use it for anything.


Modified:
    lldb/trunk/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp

Modified: lldb/trunk/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp?rev=241210&r1=241209&r2=241210&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp (original)
+++ lldb/trunk/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp Wed Jul  1 18:29:06 2015
@@ -3386,7 +3386,11 @@ ObjectFileMachO::ParseSymtab ()
                                                         ConstString const_symbol_name(symbol_name);
                                                         sym[sym_idx].GetMangled().SetValue(const_symbol_name, symbol_name_is_mangled);
                                                         if (is_gsym && is_debug)
-                                                            N_GSYM_name_to_sym_idx[sym[sym_idx].GetMangled().GetName(Mangled::ePreferMangled).GetCString()] = sym_idx;
+                                                        {
+                                                            const char *gsym_name = sym[sym_idx].GetMangled().GetName(Mangled::ePreferMangled).GetCString();
+                                                            if (gsym_name)
+                                                                N_GSYM_name_to_sym_idx[gsym_name] = sym_idx;
+                                                        }
                                                     }
                                                 }
                                                 if (symbol_section)
@@ -3513,21 +3517,25 @@ ObjectFileMachO::ParseSymtab ()
                                                         }
                                                         else
                                                         {
-                                                            // Combine N_GSYM stab entries with the non stab symbol
-                                                            ConstNameToSymbolIndexMap::const_iterator pos = N_GSYM_name_to_sym_idx.find(sym[sym_idx].GetMangled().GetName(Mangled::ePreferMangled).GetCString());
-                                                            if (pos != N_GSYM_name_to_sym_idx.end())
+                                                            const char *gsym_name = sym[sym_idx].GetMangled().GetName(Mangled::ePreferMangled).GetCString();
+                                                            if (gsym_name)
                                                             {
-                                                                const uint32_t GSYM_sym_idx = pos->second;
-                                                                m_nlist_idx_to_sym_idx[nlist_idx] = GSYM_sym_idx;
-                                                                // Copy the address, because often the N_GSYM address has an invalid address of zero
-                                                                // when the global is a common symbol
-                                                                sym[GSYM_sym_idx].GetAddressRef().SetSection (symbol_section);
-                                                                sym[GSYM_sym_idx].GetAddressRef().SetOffset (symbol_value);
-                                                                // We just need the flags from the linker symbol, so put these flags
-                                                                // into the N_GSYM flags to avoid duplicate symbols in the symbol table
-                                                                sym[GSYM_sym_idx].SetFlags (nlist.n_type << 16 | nlist.n_desc);
-                                                                sym[sym_idx].Clear();
-                                                                continue;
+                                                                // Combine N_GSYM stab entries with the non stab symbol
+                                                                ConstNameToSymbolIndexMap::const_iterator pos = N_GSYM_name_to_sym_idx.find(gsym_name);
+                                                                if (pos != N_GSYM_name_to_sym_idx.end())
+                                                                {
+                                                                    const uint32_t GSYM_sym_idx = pos->second;
+                                                                    m_nlist_idx_to_sym_idx[nlist_idx] = GSYM_sym_idx;
+                                                                    // Copy the address, because often the N_GSYM address has an invalid address of zero
+                                                                    // when the global is a common symbol
+                                                                    sym[GSYM_sym_idx].GetAddressRef().SetSection (symbol_section);
+                                                                    sym[GSYM_sym_idx].GetAddressRef().SetOffset (symbol_value);
+                                                                    // We just need the flags from the linker symbol, so put these flags
+                                                                    // into the N_GSYM flags to avoid duplicate symbols in the symbol table
+                                                                    sym[GSYM_sym_idx].SetFlags (nlist.n_type << 16 | nlist.n_desc);
+                                                                    sym[sym_idx].Clear();
+                                                                    continue;
+                                                                }
                                                             }
                                                         }
                                                     }
@@ -4235,7 +4243,11 @@ ObjectFileMachO::ParseSymtab ()
                     }
 
                     if (is_gsym)
-                        N_GSYM_name_to_sym_idx[sym[sym_idx].GetMangled().GetName(Mangled::ePreferMangled).GetCString()] = sym_idx;
+                    {
+                        const char *gsym_name = sym[sym_idx].GetMangled().GetName(Mangled::ePreferMangled).GetCString();
+                        if (gsym_name)
+                            N_GSYM_name_to_sym_idx[gsym_name] = sym_idx;
+                    }
 
                     if (symbol_section)
                     {
@@ -4357,20 +4369,24 @@ ObjectFileMachO::ParseSymtab ()
                             else
                             {
                                 // Combine N_GSYM stab entries with the non stab symbol
-                                ConstNameToSymbolIndexMap::const_iterator pos = N_GSYM_name_to_sym_idx.find(sym[sym_idx].GetMangled().GetName(Mangled::ePreferMangled).GetCString());
-                                if (pos != N_GSYM_name_to_sym_idx.end())
+                                const char *gsym_name = sym[sym_idx].GetMangled().GetName(Mangled::ePreferMangled).GetCString();
+                                if (gsym_name)
                                 {
-                                    const uint32_t GSYM_sym_idx = pos->second;
-                                    m_nlist_idx_to_sym_idx[nlist_idx] = GSYM_sym_idx;
-                                    // Copy the address, because often the N_GSYM address has an invalid address of zero
-                                    // when the global is a common symbol
-                                    sym[GSYM_sym_idx].GetAddressRef().SetSection (symbol_section);
-                                    sym[GSYM_sym_idx].GetAddressRef().SetOffset (symbol_value);
-                                    // We just need the flags from the linker symbol, so put these flags
-                                    // into the N_GSYM flags to avoid duplicate symbols in the symbol table
-                                    sym[GSYM_sym_idx].SetFlags (nlist.n_type << 16 | nlist.n_desc);
-                                    sym[sym_idx].Clear();
-                                    continue;
+                                    ConstNameToSymbolIndexMap::const_iterator pos = N_GSYM_name_to_sym_idx.find(gsym_name);
+                                    if (pos != N_GSYM_name_to_sym_idx.end())
+                                    {
+                                        const uint32_t GSYM_sym_idx = pos->second;
+                                        m_nlist_idx_to_sym_idx[nlist_idx] = GSYM_sym_idx;
+                                        // Copy the address, because often the N_GSYM address has an invalid address of zero
+                                        // when the global is a common symbol
+                                        sym[GSYM_sym_idx].GetAddressRef().SetSection (symbol_section);
+                                        sym[GSYM_sym_idx].GetAddressRef().SetOffset (symbol_value);
+                                        // We just need the flags from the linker symbol, so put these flags
+                                        // into the N_GSYM flags to avoid duplicate symbols in the symbol table
+                                        sym[GSYM_sym_idx].SetFlags (nlist.n_type << 16 | nlist.n_desc);
+                                        sym[sym_idx].Clear();
+                                        continue;
+                                    }
                                 }
                             }
                         }





More information about the lldb-commits mailing list