[haiku-commits] Re: r39823 - in haiku/trunk/src/apps/debugger: . debug_info types

  • From: Ingo Weinhold <ingo_weinhold@xxxxxx>
  • To: haiku-commits@xxxxxxxxxxxxx
  • Date: Mon, 13 Dec 2010 12:05:22 +0100

On 2010-12-12 at 23:08:44 [+0100], anevilyak@xxxxxxxxx wrote:
> Modified: haiku/trunk/src/apps/debugger/ThreadHandler.cpp
> ===================================================================
> --- haiku/trunk/src/apps/debugger/ThreadHandler.cpp    2010-12-12 18:30:27 
> UTC (rev 39822)
> +++ haiku/trunk/src/apps/debugger/ThreadHandler.cpp    2010-12-12 22:08:43 
> UTC (rev 39823)
> @@ -1,5 +1,6 @@
>  /*
>   * Copyright 2009, Ingo Weinhold, ingo_weinhold@xxxxxxx
> + * Copyright 2010, Rene Gollent, rene@xxxxxxxxxxxx
>   * Distributed under the terms of the MIT License.
>   */
>  
> @@ -589,6 +590,33 @@
>              if 
>              (fStepStatement->ContainsAddress(cpuState->InstructionPointer()
>              )) {
>                  _SingleStepThread(cpuState->InstructionPointer());
>                  return true;
> +            } else {

Please avoid the "else" block when the "if" block returns anyway.

> +                StackTrace* stackTrace = fThread->GetStackTrace();
> +                Reference<StackTrace> stackTraceReference(stackTrace);
> +
> +                if (stackTrace == NULL && cpuState != NULL) {
> +                    if 
> (fDebuggerInterface->GetArchitecture()->CreateStackTrace(
> +                            fThread->GetTeam(), this, cpuState, 
> stackTrace) == B_OK) {
> +                        stackTraceReference.SetTo(stackTrace, true);
> +                    }
> +                }
> +
> +                if (stackTrace != NULL) {
> +                    StackFrame *frame = stackTrace->FrameAt(0);
> +                    Image* image = frame->GetImage();
> +                    ImageDebugInfo* info = NULL;
> +                    if (GetImageDebugInfo(image, info) != B_OK)
> +                        return false;
> +
> +                    Reference<ImageDebugInfo>(info, true);
> +
> +                    if (info->GetAddressSectionType(
> +                        cpuState->InstructionPointer())
> +                        == ADDRESS_SECTION_TYPE_PLT) {

Both lines should be indented one more level.

> +                        _SingleStepThread(cpuState->InstructionPointer());
> +                        return true;
> +                    }
> +                }
>              }
>              return false;
>          }
> 
> Modified: haiku/trunk/src/apps/debugger/debug_info/DwarfImageDebugInfo.cpp
> ===================================================================
> --- haiku/trunk/src/apps/debugger/debug_info/DwarfImageDebugInfo.cpp    
> 2010-12-12 18:30:27 UTC (rev 39822)
> +++ haiku/trunk/src/apps/debugger/debug_info/DwarfImageDebugInfo.cpp    
> 2010-12-12 22:08:43 UTC (rev 39823)
> @@ -429,6 +429,30 @@
>  }
>  
>  
> +AddressSectionType
> +DwarfImageDebugInfo::GetAddressSectionType(target_addr_t address)
> +{
> +    address -= fRelocationDelta;
> +    ElfFile* file = fFile->GetElfFile();
> +
> +    ElfSection* section = file->GetSection(".text");
> +    if (section != NULL && address >= section->LoadAddress()
> +        && address < section->LoadAddress() + section->Size()) {
> +            file->PutSection(section);
> +            return ADDRESS_SECTION_TYPE_FUNCTION;
> +    }
> +
> +    section = file->GetSection(".plt");
> +    if (section != NULL && address >= section->LoadAddress()
> +        && address < section->LoadAddress() + section->Size()) {
> +            file->PutSection(section);
> +            return ADDRESS_SECTION_TYPE_PLT;
> +    }
> +
> +    return ADDRESS_SECTION_TYPE_UNKNOWN;
> +}

ElfFile::GetSection() is too expensive to call it here. It actually reads the 
section's data from the file, which is also unnecessary in this case. But 
even if it didn't, looking up the section by name is already relatively 
expensive. I would introduce an ElfFile::FindSection() that only returns the 
section without loading it and use it in DwarfImageDebugInfo::Init() to get 
and cache the section addresses.

CU, Ingo

Other related posts: