[Lldb-commits] [lldb] r373803 - [MachO] Move nlist parsing into helper function (NFC)

Jonas Devlieghere via lldb-commits lldb-commits at lists.llvm.org
Fri Oct 4 15:21:32 PDT 2019


Author: jdevlieghere
Date: Fri Oct  4 15:21:32 2019
New Revision: 373803

URL: http://llvm.org/viewvc/llvm-project?rev=373803&view=rev
Log:
[MachO] Move nlist parsing into helper function (NFC)

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=373803&r1=373802&r2=373803&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp (original)
+++ lldb/trunk/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp Fri Oct  4 15:21:32 2019
@@ -2038,6 +2038,18 @@ UUID ObjectFileMachO::GetSharedCacheUUID
   return dsc_uuid;
 }
 
+bool ParseNList(DataExtractor &nlist_data, lldb::offset_t &nlist_data_offset,
+                size_t nlist_byte_size, struct nlist_64 &nlist) {
+  if (!nlist_data.ValidOffsetForDataOfSize(nlist_data_offset, nlist_byte_size))
+    return false;
+  nlist.n_strx = nlist_data.GetU32_unchecked(&nlist_data_offset);
+  nlist.n_type = nlist_data.GetU8_unchecked(&nlist_data_offset);
+  nlist.n_sect = nlist_data.GetU8_unchecked(&nlist_data_offset);
+  nlist.n_desc = nlist_data.GetU16_unchecked(&nlist_data_offset);
+  nlist.n_value = nlist_data.GetAddress_unchecked(&nlist_data_offset);
+  return true;
+}
+
 size_t ObjectFileMachO::ParseSymtab() {
   static Timer::Category func_cat(LLVM_PRETTY_FUNCTION);
   Timer scoped_timer(func_cat, "ObjectFileMachO::ParseSymtab () module = %s",
@@ -2734,21 +2746,9 @@ size_t ObjectFileMachO::ParseSymtab() {
                   /////////////////////////////
                   {
                     struct nlist_64 nlist;
-                    if (!dsc_local_symbols_data.ValidOffsetForDataOfSize(
-                            nlist_data_offset, nlist_byte_size))
+                    if (!ParseNList(dsc_local_symbols_data, nlist_data_offset, nlist_byte_size, nlist)
                       break;
 
-                    nlist.n_strx = dsc_local_symbols_data.GetU32_unchecked(
-                        &nlist_data_offset);
-                    nlist.n_type = dsc_local_symbols_data.GetU8_unchecked(
-                        &nlist_data_offset);
-                    nlist.n_sect = dsc_local_symbols_data.GetU8_unchecked(
-                        &nlist_data_offset);
-                    nlist.n_desc = dsc_local_symbols_data.GetU16_unchecked(
-                        &nlist_data_offset);
-                    nlist.n_value = dsc_local_symbols_data.GetAddress_unchecked(
-                        &nlist_data_offset);
-
                     SymbolType type = eSymbolTypeInvalid;
                     const char *symbol_name = dsc_local_symbols_data.PeekCStr(
                         string_table_offset + nlist.n_strx);
@@ -3681,16 +3681,9 @@ size_t ObjectFileMachO::ParseSymtab() {
     SymbolIndexToName reexport_shlib_needs_fixup;
     for (; nlist_idx < symtab_load_command.nsyms; ++nlist_idx) {
       struct nlist_64 nlist;
-      if (!nlist_data.ValidOffsetForDataOfSize(nlist_data_offset,
-                                               nlist_byte_size))
+      if (!ParseNList(nlist_data, nlist_data_offset, nlist_byte_size, nlist))
         break;
 
-      nlist.n_strx = nlist_data.GetU32_unchecked(&nlist_data_offset);
-      nlist.n_type = nlist_data.GetU8_unchecked(&nlist_data_offset);
-      nlist.n_sect = nlist_data.GetU8_unchecked(&nlist_data_offset);
-      nlist.n_desc = nlist_data.GetU16_unchecked(&nlist_data_offset);
-      nlist.n_value = nlist_data.GetAddress_unchecked(&nlist_data_offset);
-
       SymbolType type = eSymbolTypeInvalid;
       const char *symbol_name = nullptr;
 




More information about the lldb-commits mailing list