1 //===-- ObjectFile.cpp ------------------------------------------*- C++ -*-===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 
10 #include "lldb/lldb-private.h"
11 #include "lldb/Core/DataBuffer.h"
12 #include "lldb/Core/DataBufferHeap.h"
13 #include "lldb/Core/Log.h"
14 #include "lldb/Core/Module.h"
15 #include "lldb/Core/ModuleSpec.h"
16 #include "lldb/Core/PluginManager.h"
17 #include "lldb/Core/RegularExpression.h"
18 #include "lldb/Core/Section.h"
19 #include "lldb/Core/Timer.h"
20 #include "lldb/Symbol/ObjectFile.h"
21 #include "lldb/Symbol/ObjectContainer.h"
22 #include "lldb/Symbol/SymbolFile.h"
23 #include "lldb/Target/Process.h"
24 #include "Plugins/ObjectContainer/BSD-Archive/ObjectContainerBSDArchive.h"
25 
26 using namespace lldb;
27 using namespace lldb_private;
28 
29 ObjectFileSP
30 ObjectFile::FindPlugin (const lldb::ModuleSP &module_sp,
31                         const FileSpec* file,
32                         lldb::offset_t file_offset,
33                         lldb::offset_t file_size,
34                         DataBufferSP &data_sp,
35                         lldb::offset_t &data_offset)
36 {
37     ObjectFileSP object_file_sp;
38 
39     if (module_sp)
40     {
41         Timer scoped_timer (__PRETTY_FUNCTION__,
42                             "ObjectFile::FindPlugin (module = %s, file = %p, file_offset = 0x%8.8" PRIx64 ", file_size = 0x%8.8" PRIx64 ")",
43                             module_sp->GetFileSpec().GetPath().c_str(),
44                             static_cast<const void*>(file),
45                             static_cast<uint64_t>(file_offset),
46                             static_cast<uint64_t>(file_size));
47         if (file)
48         {
49             FileSpec archive_file;
50             ObjectContainerCreateInstance create_object_container_callback;
51 
52             const bool file_exists = file->Exists();
53             if (!data_sp)
54             {
55                 // We have an object name which most likely means we have
56                 // a .o file in a static archive (.a file). Try and see if
57                 // we have a cached archive first without reading any data
58                 // first
59                 if (file_exists && module_sp->GetObjectName())
60                 {
61                     for (uint32_t idx = 0; (create_object_container_callback = PluginManager::GetObjectContainerCreateCallbackAtIndex(idx)) != nullptr; ++idx)
62                     {
63                         std::unique_ptr<ObjectContainer> object_container_ap(create_object_container_callback(module_sp, data_sp, data_offset, file, file_offset, file_size));
64 
65                         if (object_container_ap.get())
66                             object_file_sp = object_container_ap->GetObjectFile(file);
67 
68                         if (object_file_sp.get())
69                             return object_file_sp;
70                     }
71                 }
72                 // Ok, we didn't find any containers that have a named object, now
73                 // lets read the first 512 bytes from the file so the object file
74                 // and object container plug-ins can use these bytes to see if they
75                 // can parse this file.
76                 if (file_size > 0)
77                 {
78                     data_sp = file->ReadFileContents(file_offset, std::min<size_t>(512, file_size));
79                     data_offset = 0;
80                 }
81             }
82 
83             if (!data_sp || data_sp->GetByteSize() == 0)
84             {
85                 // Check for archive file with format "/path/to/archive.a(object.o)"
86                 char path_with_object[PATH_MAX*2];
87                 module_sp->GetFileSpec().GetPath(path_with_object, sizeof(path_with_object));
88 
89                 ConstString archive_object;
90                 const bool must_exist = true;
91                 if (ObjectFile::SplitArchivePathWithObject (path_with_object, archive_file, archive_object, must_exist))
92                 {
93                     file_size = archive_file.GetByteSize();
94                     if (file_size > 0)
95                     {
96                         file = &archive_file;
97                         module_sp->SetFileSpecAndObjectName (archive_file, archive_object);
98                         // Check if this is a object container by iterating through all object
99                         // container plugin instances and then trying to get an object file
100                         // from the container plugins since we had a name. Also, don't read
101                         // ANY data in case there is data cached in the container plug-ins
102                         // (like BSD archives caching the contained objects within an file).
103                         for (uint32_t idx = 0; (create_object_container_callback = PluginManager::GetObjectContainerCreateCallbackAtIndex(idx)) != nullptr; ++idx)
104                         {
105                             std::unique_ptr<ObjectContainer> object_container_ap(create_object_container_callback(module_sp, data_sp, data_offset, file, file_offset, file_size));
106 
107                             if (object_container_ap.get())
108                                 object_file_sp = object_container_ap->GetObjectFile(file);
109 
110                             if (object_file_sp.get())
111                                 return object_file_sp;
112                         }
113                         // We failed to find any cached object files in the container
114                         // plug-ins, so lets read the first 512 bytes and try again below...
115                         data_sp = archive_file.ReadFileContents(file_offset, 512);
116                     }
117                 }
118             }
119 
120             if (data_sp && data_sp->GetByteSize() > 0)
121             {
122                 // Check if this is a normal object file by iterating through
123                 // all object file plugin instances.
124                 ObjectFileCreateInstance create_object_file_callback;
125                 for (uint32_t idx = 0; (create_object_file_callback = PluginManager::GetObjectFileCreateCallbackAtIndex(idx)) != nullptr; ++idx)
126                 {
127                     object_file_sp.reset (create_object_file_callback(module_sp, data_sp, data_offset, file, file_offset, file_size));
128                     if (object_file_sp.get())
129                         return object_file_sp;
130                 }
131 
132                 // Check if this is a object container by iterating through
133                 // all object container plugin instances and then trying to get
134                 // an object file from the container.
135                 for (uint32_t idx = 0; (create_object_container_callback = PluginManager::GetObjectContainerCreateCallbackAtIndex(idx)) != nullptr; ++idx)
136                 {
137                     std::unique_ptr<ObjectContainer> object_container_ap(create_object_container_callback(module_sp, data_sp, data_offset, file, file_offset, file_size));
138 
139                     if (object_container_ap.get())
140                         object_file_sp = object_container_ap->GetObjectFile(file);
141 
142                     if (object_file_sp.get())
143                         return object_file_sp;
144                 }
145             }
146         }
147     }
148     // We didn't find it, so clear our shared pointer in case it
149     // contains anything and return an empty shared pointer
150     object_file_sp.reset();
151     return object_file_sp;
152 }
153 
154 ObjectFileSP
155 ObjectFile::FindPlugin (const lldb::ModuleSP &module_sp,
156                         const ProcessSP &process_sp,
157                         lldb::addr_t header_addr,
158                         DataBufferSP &data_sp)
159 {
160     ObjectFileSP object_file_sp;
161 
162     if (module_sp)
163     {
164         Timer scoped_timer (__PRETTY_FUNCTION__,
165                             "ObjectFile::FindPlugin (module = %s, process = %p, header_addr = 0x%" PRIx64 ")",
166                             module_sp->GetFileSpec().GetPath().c_str(),
167                             static_cast<void*>(process_sp.get()), header_addr);
168         uint32_t idx;
169 
170         // Check if this is a normal object file by iterating through
171         // all object file plugin instances.
172         ObjectFileCreateMemoryInstance create_callback;
173         for (idx = 0; (create_callback = PluginManager::GetObjectFileCreateMemoryCallbackAtIndex(idx)) != nullptr; ++idx)
174         {
175             object_file_sp.reset (create_callback(module_sp, data_sp, process_sp, header_addr));
176             if (object_file_sp.get())
177                 return object_file_sp;
178         }
179     }
180 
181     // We didn't find it, so clear our shared pointer in case it
182     // contains anything and return an empty shared pointer
183     object_file_sp.reset();
184     return object_file_sp;
185 }
186 
187 size_t
188 ObjectFile::GetModuleSpecifications (const FileSpec &file,
189                                      lldb::offset_t file_offset,
190                                      lldb::offset_t file_size,
191                                      ModuleSpecList &specs)
192 {
193     DataBufferSP data_sp (file.ReadFileContents(file_offset, 512));
194     if (data_sp)
195     {
196         if (file_size == 0)
197         {
198             const lldb::offset_t actual_file_size = file.GetByteSize();
199             if (actual_file_size > file_offset)
200                 file_size = actual_file_size - file_offset;
201         }
202         return ObjectFile::GetModuleSpecifications (file,       // file spec
203                                                     data_sp,    // data bytes
204                                                     0,          // data offset
205                                                     file_offset,// file offset
206                                                     file_size,  // file length
207                                                     specs);
208     }
209     return 0;
210 }
211 
212 size_t
213 ObjectFile::GetModuleSpecifications (const lldb_private::FileSpec& file,
214                                      lldb::DataBufferSP& data_sp,
215                                      lldb::offset_t data_offset,
216                                      lldb::offset_t file_offset,
217                                      lldb::offset_t file_size,
218                                      lldb_private::ModuleSpecList &specs)
219 {
220     const size_t initial_count = specs.GetSize();
221     ObjectFileGetModuleSpecifications callback;
222     uint32_t i;
223     // Try the ObjectFile plug-ins
224     for (i = 0; (callback = PluginManager::GetObjectFileGetModuleSpecificationsCallbackAtIndex(i)) != nullptr; ++i)
225     {
226         if (callback (file, data_sp, data_offset, file_offset, file_size, specs) > 0)
227             return specs.GetSize() - initial_count;
228     }
229 
230     // Try the ObjectContainer plug-ins
231     for (i = 0; (callback = PluginManager::GetObjectContainerGetModuleSpecificationsCallbackAtIndex(i)) != nullptr; ++i)
232     {
233         if (callback (file, data_sp, data_offset, file_offset, file_size, specs) > 0)
234             return specs.GetSize() - initial_count;
235     }
236     return 0;
237 }
238 
239 ObjectFile::ObjectFile (const lldb::ModuleSP &module_sp,
240                         const FileSpec *file_spec_ptr,
241                         lldb::offset_t file_offset,
242                         lldb::offset_t length,
243                         const lldb::DataBufferSP& data_sp,
244                         lldb::offset_t data_offset
245 ) :
246     ModuleChild (module_sp),
247     m_file (),  // This file could be different from the original module's file
248     m_type (eTypeInvalid),
249     m_strata (eStrataInvalid),
250     m_file_offset (file_offset),
251     m_length (length),
252     m_data (),
253     m_unwind_table (*this),
254     m_process_wp(),
255     m_memory_addr (LLDB_INVALID_ADDRESS),
256     m_sections_ap(),
257     m_symtab_ap ()
258 {
259     if (file_spec_ptr)
260         m_file = *file_spec_ptr;
261     if (data_sp)
262         m_data.SetData (data_sp, data_offset, length);
263     Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_OBJECT));
264     if (log)
265         log->Printf ("%p ObjectFile::ObjectFile() module = %p (%s), file = %s, file_offset = 0x%8.8" PRIx64 ", size = %" PRIu64,
266                      static_cast<void*>(this),
267                      static_cast<void*>(module_sp.get()),
268                      module_sp->GetSpecificationDescription().c_str(),
269                      m_file ? m_file.GetPath().c_str() : "<NULL>",
270                      m_file_offset, m_length);
271 }
272 
273 
274 ObjectFile::ObjectFile (const lldb::ModuleSP &module_sp,
275                         const ProcessSP &process_sp,
276                         lldb::addr_t header_addr,
277                         DataBufferSP& header_data_sp) :
278     ModuleChild (module_sp),
279     m_file (),
280     m_type (eTypeInvalid),
281     m_strata (eStrataInvalid),
282     m_file_offset (0),
283     m_length (0),
284     m_data (),
285     m_unwind_table (*this),
286     m_process_wp (process_sp),
287     m_memory_addr (header_addr),
288     m_sections_ap(),
289     m_symtab_ap ()
290 {
291     if (header_data_sp)
292         m_data.SetData (header_data_sp, 0, header_data_sp->GetByteSize());
293     Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_OBJECT));
294     if (log)
295         log->Printf ("%p ObjectFile::ObjectFile() module = %p (%s), process = %p, header_addr = 0x%" PRIx64,
296                      static_cast<void*>(this),
297                      static_cast<void*>(module_sp.get()),
298                      module_sp->GetSpecificationDescription().c_str(),
299                      static_cast<void*>(process_sp.get()), m_memory_addr);
300 }
301 
302 
303 ObjectFile::~ObjectFile()
304 {
305     Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_OBJECT));
306     if (log)
307         log->Printf ("%p ObjectFile::~ObjectFile ()\n",
308                      static_cast<void*>(this));
309 }
310 
311 bool
312 ObjectFile::SetModulesArchitecture (const ArchSpec &new_arch)
313 {
314     ModuleSP module_sp (GetModule());
315     if (module_sp)
316         return module_sp->SetArchitecture (new_arch);
317     return false;
318 }
319 
320 AddressClass
321 ObjectFile::GetAddressClass (addr_t file_addr)
322 {
323     Symtab *symtab = GetSymtab();
324     if (symtab)
325     {
326         Symbol *symbol = symtab->FindSymbolContainingFileAddress(file_addr);
327         if (symbol)
328         {
329             if (symbol->ValueIsAddress())
330             {
331                 const SectionSP section_sp (symbol->GetAddressRef().GetSection());
332                 if (section_sp)
333                 {
334                     const SectionType section_type = section_sp->GetType();
335                     switch (section_type)
336                     {
337                     case eSectionTypeInvalid:
338                         return eAddressClassUnknown;
339                     case eSectionTypeCode:
340                         return eAddressClassCode;
341                     case eSectionTypeContainer:
342                         return eAddressClassUnknown;
343                     case eSectionTypeData:
344                     case eSectionTypeDataCString:
345                     case eSectionTypeDataCStringPointers:
346                     case eSectionTypeDataSymbolAddress:
347                     case eSectionTypeData4:
348                     case eSectionTypeData8:
349                     case eSectionTypeData16:
350                     case eSectionTypeDataPointers:
351                     case eSectionTypeZeroFill:
352                     case eSectionTypeDataObjCMessageRefs:
353                     case eSectionTypeDataObjCCFStrings:
354                     case eSectionTypeGoSymtab:
355                         return eAddressClassData;
356                     case eSectionTypeDebug:
357                     case eSectionTypeDWARFDebugAbbrev:
358                     case eSectionTypeDWARFDebugAddr:
359                     case eSectionTypeDWARFDebugAranges:
360                     case eSectionTypeDWARFDebugFrame:
361                     case eSectionTypeDWARFDebugInfo:
362                     case eSectionTypeDWARFDebugLine:
363                     case eSectionTypeDWARFDebugLoc:
364                     case eSectionTypeDWARFDebugMacInfo:
365                     case eSectionTypeDWARFDebugPubNames:
366                     case eSectionTypeDWARFDebugPubTypes:
367                     case eSectionTypeDWARFDebugRanges:
368                     case eSectionTypeDWARFDebugStr:
369                     case eSectionTypeDWARFDebugStrOffsets:
370                     case eSectionTypeDWARFAppleNames:
371                     case eSectionTypeDWARFAppleTypes:
372                     case eSectionTypeDWARFAppleNamespaces:
373                     case eSectionTypeDWARFAppleObjC:
374                         return eAddressClassDebug;
375                     case eSectionTypeEHFrame:
376                     case eSectionTypeARMexidx:
377                     case eSectionTypeARMextab:
378                     case eSectionTypeCompactUnwind:
379                         return eAddressClassRuntime;
380                     case eSectionTypeELFSymbolTable:
381                     case eSectionTypeELFDynamicSymbols:
382                     case eSectionTypeELFRelocationEntries:
383                     case eSectionTypeELFDynamicLinkInfo:
384                     case eSectionTypeOther:
385                         return eAddressClassUnknown;
386                     }
387                 }
388             }
389 
390             const SymbolType symbol_type = symbol->GetType();
391             switch (symbol_type)
392             {
393             case eSymbolTypeAny:            return eAddressClassUnknown;
394             case eSymbolTypeAbsolute:       return eAddressClassUnknown;
395             case eSymbolTypeCode:           return eAddressClassCode;
396             case eSymbolTypeTrampoline:     return eAddressClassCode;
397             case eSymbolTypeResolver:       return eAddressClassCode;
398             case eSymbolTypeData:           return eAddressClassData;
399             case eSymbolTypeRuntime:        return eAddressClassRuntime;
400             case eSymbolTypeException:      return eAddressClassRuntime;
401             case eSymbolTypeSourceFile:     return eAddressClassDebug;
402             case eSymbolTypeHeaderFile:     return eAddressClassDebug;
403             case eSymbolTypeObjectFile:     return eAddressClassDebug;
404             case eSymbolTypeCommonBlock:    return eAddressClassDebug;
405             case eSymbolTypeBlock:          return eAddressClassDebug;
406             case eSymbolTypeLocal:          return eAddressClassData;
407             case eSymbolTypeParam:          return eAddressClassData;
408             case eSymbolTypeVariable:       return eAddressClassData;
409             case eSymbolTypeVariableType:   return eAddressClassDebug;
410             case eSymbolTypeLineEntry:      return eAddressClassDebug;
411             case eSymbolTypeLineHeader:     return eAddressClassDebug;
412             case eSymbolTypeScopeBegin:     return eAddressClassDebug;
413             case eSymbolTypeScopeEnd:       return eAddressClassDebug;
414             case eSymbolTypeAdditional:     return eAddressClassUnknown;
415             case eSymbolTypeCompiler:       return eAddressClassDebug;
416             case eSymbolTypeInstrumentation:return eAddressClassDebug;
417             case eSymbolTypeUndefined:      return eAddressClassUnknown;
418             case eSymbolTypeObjCClass:      return eAddressClassRuntime;
419             case eSymbolTypeObjCMetaClass:  return eAddressClassRuntime;
420             case eSymbolTypeObjCIVar:       return eAddressClassRuntime;
421             case eSymbolTypeReExported:     return eAddressClassRuntime;
422             }
423         }
424     }
425     return eAddressClassUnknown;
426 }
427 
428 DataBufferSP
429 ObjectFile::ReadMemory (const ProcessSP &process_sp, lldb::addr_t addr, size_t byte_size)
430 {
431     DataBufferSP data_sp;
432     if (process_sp)
433     {
434         std::unique_ptr<DataBufferHeap> data_ap (new DataBufferHeap (byte_size, 0));
435         Error error;
436         const size_t bytes_read = process_sp->ReadMemory (addr,
437                                                           data_ap->GetBytes(),
438                                                           data_ap->GetByteSize(),
439                                                           error);
440         if (bytes_read == byte_size)
441             data_sp.reset (data_ap.release());
442     }
443     return data_sp;
444 }
445 
446 size_t
447 ObjectFile::GetData (lldb::offset_t offset, size_t length, DataExtractor &data) const
448 {
449     // The entire file has already been mmap'ed into m_data, so just copy from there
450     // as the back mmap buffer will be shared with shared pointers.
451     return data.SetData (m_data, offset, length);
452 }
453 
454 size_t
455 ObjectFile::CopyData (lldb::offset_t offset, size_t length, void *dst) const
456 {
457     // The entire file has already been mmap'ed into m_data, so just copy from there
458     // Note that the data remains in target byte order.
459     return m_data.CopyData (offset, length, dst);
460 }
461 
462 
463 size_t
464 ObjectFile::ReadSectionData (const Section *section, lldb::offset_t section_offset, void *dst, size_t dst_len) const
465 {
466     assert(section);
467     section_offset *= section->GetTargetByteSize();
468 
469     // If some other objectfile owns this data, pass this to them.
470     if (section->GetObjectFile() != this)
471         return section->GetObjectFile()->ReadSectionData (section, section_offset, dst, dst_len);
472 
473     if (IsInMemory())
474     {
475         ProcessSP process_sp (m_process_wp.lock());
476         if (process_sp)
477         {
478             Error error;
479             const addr_t base_load_addr = section->GetLoadBaseAddress (&process_sp->GetTarget());
480             if (base_load_addr != LLDB_INVALID_ADDRESS)
481                 return process_sp->ReadMemory (base_load_addr + section_offset, dst, dst_len, error);
482         }
483     }
484     else
485     {
486         const lldb::offset_t section_file_size = section->GetFileSize();
487         if (section_offset < section_file_size)
488         {
489             const size_t section_bytes_left = section_file_size - section_offset;
490             size_t section_dst_len = dst_len;
491             if (section_dst_len > section_bytes_left)
492                 section_dst_len = section_bytes_left;
493             return CopyData (section->GetFileOffset() + section_offset, section_dst_len, dst);
494         }
495         else
496         {
497             if (section->GetType() == eSectionTypeZeroFill)
498             {
499                 const uint64_t section_size = section->GetByteSize();
500                 const uint64_t section_bytes_left = section_size - section_offset;
501                 uint64_t section_dst_len = dst_len;
502                 if (section_dst_len > section_bytes_left)
503                     section_dst_len = section_bytes_left;
504                 memset(dst, 0, section_dst_len);
505                 return section_dst_len;
506             }
507         }
508     }
509     return 0;
510 }
511 
512 //----------------------------------------------------------------------
513 // Get the section data the file on disk
514 //----------------------------------------------------------------------
515 size_t
516 ObjectFile::ReadSectionData (const Section *section, DataExtractor& section_data) const
517 {
518     // If some other objectfile owns this data, pass this to them.
519     if (section->GetObjectFile() != this)
520         return section->GetObjectFile()->ReadSectionData (section, section_data);
521 
522     if (IsInMemory())
523     {
524         ProcessSP process_sp (m_process_wp.lock());
525         if (process_sp)
526         {
527             const addr_t base_load_addr = section->GetLoadBaseAddress (&process_sp->GetTarget());
528             if (base_load_addr != LLDB_INVALID_ADDRESS)
529             {
530                 DataBufferSP data_sp (ReadMemory (process_sp, base_load_addr, section->GetByteSize()));
531                 if (data_sp)
532                 {
533                     section_data.SetData (data_sp, 0, data_sp->GetByteSize());
534                     section_data.SetByteOrder (process_sp->GetByteOrder());
535                     section_data.SetAddressByteSize (process_sp->GetAddressByteSize());
536                     return section_data.GetByteSize();
537                 }
538             }
539         }
540         return GetData(section->GetFileOffset(), section->GetFileSize(), section_data);
541     }
542     else
543     {
544         // The object file now contains a full mmap'ed copy of the object file data, so just use this
545         return MemoryMapSectionData (section, section_data);
546     }
547     section_data.Clear();
548     return 0;
549 }
550 
551 size_t
552 ObjectFile::MemoryMapSectionData (const Section *section, DataExtractor& section_data) const
553 {
554     // If some other objectfile owns this data, pass this to them.
555     if (section->GetObjectFile() != this)
556         return section->GetObjectFile()->MemoryMapSectionData (section, section_data);
557 
558     if (IsInMemory())
559     {
560         return ReadSectionData (section, section_data);
561     }
562     else
563     {
564         // The object file now contains a full mmap'ed copy of the object file data, so just use this
565         return GetData(section->GetFileOffset(), section->GetFileSize(), section_data);
566     }
567 }
568 
569 
570 bool
571 ObjectFile::SplitArchivePathWithObject (const char *path_with_object, FileSpec &archive_file, ConstString &archive_object, bool must_exist)
572 {
573     RegularExpression g_object_regex("(.*)\\(([^\\)]+)\\)$");
574     RegularExpression::Match regex_match(2);
575     if (g_object_regex.Execute (path_with_object, &regex_match))
576     {
577         std::string path;
578         std::string obj;
579         if (regex_match.GetMatchAtIndex (path_with_object, 1, path) &&
580             regex_match.GetMatchAtIndex (path_with_object, 2, obj))
581         {
582             archive_file.SetFile (path.c_str(), false);
583             archive_object.SetCString(obj.c_str());
584             if (must_exist && !archive_file.Exists())
585                 return false;
586             return true;
587         }
588     }
589     return false;
590 }
591 
592 void
593 ObjectFile::ClearSymtab ()
594 {
595     ModuleSP module_sp(GetModule());
596     if (module_sp)
597     {
598         lldb_private::Mutex::Locker locker(module_sp->GetMutex());
599         Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_OBJECT));
600         if (log)
601             log->Printf ("%p ObjectFile::ClearSymtab () symtab = %p",
602                          static_cast<void*>(this),
603                          static_cast<void*>(m_symtab_ap.get()));
604         m_symtab_ap.reset();
605     }
606 }
607 
608 SectionList *
609 ObjectFile::GetSectionList(bool update_module_section_list)
610 {
611     if (m_sections_ap.get() == nullptr)
612     {
613         if (update_module_section_list)
614         {
615             ModuleSP module_sp(GetModule());
616             if (module_sp)
617             {
618                 lldb_private::Mutex::Locker locker(module_sp->GetMutex());
619                 CreateSections(*module_sp->GetUnifiedSectionList());
620             }
621         }
622         else
623         {
624             SectionList unified_section_list;
625             CreateSections(unified_section_list);
626         }
627     }
628     return m_sections_ap.get();
629 }
630 
631 lldb::SymbolType
632 ObjectFile::GetSymbolTypeFromName (llvm::StringRef name,
633                                    lldb::SymbolType symbol_type_hint)
634 {
635     if (!name.empty())
636     {
637         if (name.startswith("_OBJC_"))
638         {
639             // ObjC
640             if (name.startswith("_OBJC_CLASS_$_"))
641                 return lldb::eSymbolTypeObjCClass;
642             if (name.startswith("_OBJC_METACLASS_$_"))
643                 return lldb::eSymbolTypeObjCMetaClass;
644             if (name.startswith("_OBJC_IVAR_$_"))
645                 return lldb::eSymbolTypeObjCIVar;
646         }
647         else if (name.startswith(".objc_class_name_"))
648         {
649             // ObjC v1
650             return lldb::eSymbolTypeObjCClass;
651         }
652     }
653     return symbol_type_hint;
654 }
655