@@ -3768,6 +3768,7 @@ void ObjectFileMachO::ParseSymtab(Symtab &symtab) {
37683768
37693769 SymbolType type = eSymbolTypeInvalid;
37703770 SectionSP symbol_section;
3771+ lldb::addr_t symbol_byte_size = 0 ;
37713772 bool add_nlist = true ;
37723773 bool is_gsym = false ;
37733774 bool demangled_is_synthesized = false ;
@@ -4353,6 +4354,47 @@ void ObjectFileMachO::ParseSymtab(Symtab &symtab) {
43534354
43544355 if (symbol_section) {
43554356 const addr_t section_file_addr = symbol_section->GetFileAddress ();
4357+ if (symbol_byte_size == 0 && function_starts_count > 0 ) {
4358+ addr_t symbol_lookup_file_addr = nlist.n_value ;
4359+ // Do an exact address match for non-ARM addresses, else get the
4360+ // closest since the symbol might be a thumb symbol which has an
4361+ // address with bit zero set.
4362+ FunctionStarts::Entry *func_start_entry =
4363+ function_starts.FindEntry (symbol_lookup_file_addr, !is_arm);
4364+ if (is_arm && func_start_entry) {
4365+ // Verify that the function start address is the symbol address
4366+ // (ARM) or the symbol address + 1 (thumb).
4367+ if (func_start_entry->addr != symbol_lookup_file_addr &&
4368+ func_start_entry->addr != (symbol_lookup_file_addr + 1 )) {
4369+ // Not the right entry, NULL it out...
4370+ func_start_entry = nullptr ;
4371+ }
4372+ }
4373+ if (func_start_entry) {
4374+ func_start_entry->data = true ;
4375+
4376+ addr_t symbol_file_addr = func_start_entry->addr ;
4377+ if (is_arm)
4378+ symbol_file_addr &= THUMB_ADDRESS_BIT_MASK;
4379+
4380+ const FunctionStarts::Entry *next_func_start_entry =
4381+ function_starts.FindNextEntry (func_start_entry);
4382+ const addr_t section_end_file_addr =
4383+ section_file_addr + symbol_section->GetByteSize ();
4384+ if (next_func_start_entry) {
4385+ addr_t next_symbol_file_addr = next_func_start_entry->addr ;
4386+ // Be sure the clear the Thumb address bit when we calculate the
4387+ // size from the current and next address
4388+ if (is_arm)
4389+ next_symbol_file_addr &= THUMB_ADDRESS_BIT_MASK;
4390+ symbol_byte_size = std::min<lldb::addr_t >(
4391+ next_symbol_file_addr - symbol_file_addr,
4392+ section_end_file_addr - symbol_file_addr);
4393+ } else {
4394+ symbol_byte_size = section_end_file_addr - symbol_file_addr;
4395+ }
4396+ }
4397+ }
43564398 symbol_value -= section_file_addr;
43574399 }
43584400
@@ -4459,6 +4501,9 @@ void ObjectFileMachO::ParseSymtab(Symtab &symtab) {
44594501 if (nlist.n_desc & N_WEAK_REF)
44604502 sym[sym_idx].SetIsWeak (true );
44614503
4504+ if (symbol_byte_size > 0 )
4505+ sym[sym_idx].SetByteSize (symbol_byte_size);
4506+
44624507 if (demangled_is_synthesized)
44634508 sym[sym_idx].SetDemangledNameIsSynthesized (true );
44644509
@@ -4577,7 +4622,23 @@ void ObjectFileMachO::ParseSymtab(Symtab &symtab) {
45774622 Address symbol_addr;
45784623 if (module_sp->ResolveFileAddress (symbol_file_addr, symbol_addr)) {
45794624 SectionSP symbol_section (symbol_addr.GetSection ());
4625+ uint32_t symbol_byte_size = 0 ;
45804626 if (symbol_section) {
4627+ const addr_t section_file_addr = symbol_section->GetFileAddress ();
4628+ const FunctionStarts::Entry *next_func_start_entry =
4629+ function_starts.FindNextEntry (func_start_entry);
4630+ const addr_t section_end_file_addr =
4631+ section_file_addr + symbol_section->GetByteSize ();
4632+ if (next_func_start_entry) {
4633+ addr_t next_symbol_file_addr = next_func_start_entry->addr ;
4634+ if (is_arm)
4635+ next_symbol_file_addr &= THUMB_ADDRESS_BIT_MASK;
4636+ symbol_byte_size = std::min<lldb::addr_t >(
4637+ next_symbol_file_addr - symbol_file_addr,
4638+ section_end_file_addr - symbol_file_addr);
4639+ } else {
4640+ symbol_byte_size = section_end_file_addr - symbol_file_addr;
4641+ }
45814642 sym[sym_idx].SetID (synthetic_sym_id++);
45824643 // Don't set the name for any synthetic symbols, the Symbol
45834644 // object will generate one if needed when the name is accessed
@@ -4589,6 +4650,8 @@ void ObjectFileMachO::ParseSymtab(Symtab &symtab) {
45894650 add_symbol_addr (symbol_addr.GetFileAddress ());
45904651 if (symbol_flags)
45914652 sym[sym_idx].SetFlags (symbol_flags);
4653+ if (symbol_byte_size)
4654+ sym[sym_idx].SetByteSize (symbol_byte_size);
45924655 ++sym_idx;
45934656 }
45944657 }
0 commit comments