Skip to content

Commit

Permalink
Fix raw address breakpoints not resolving
Browse files Browse the repository at this point in the history
Summary: An address breakpoint of the form "b 0x1000" won't resolve if it's created while the process isn't running. This patch deletes Address::SectionWasDeleted, renames Address::SectionWasDeletedPrivate to SectionWasDeleted (and makes it public), and changes the section check in Breakpoint::ModulesChanged back to its original form

Reviewers: jingham, #lldb

Reviewed By: jingham

Subscribers: davide, lldb-commits

Differential Revision: https://reviews.llvm.org/D51816

llvm-svn: 341849
  • Loading branch information
Ted Woodward committed Sep 10, 2018
1 parent bef0941 commit 860bafa
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 23 deletions.
19 changes: 5 additions & 14 deletions lldb/include/lldb/Core/Address.h
Expand Up @@ -525,11 +525,11 @@ class Address {
bool CalculateSymbolContextLineEntry(LineEntry &line_entry) const;

//------------------------------------------------------------------
// Returns true if the section should be valid, but isn't because the shared
// pointer to the section can't be reconstructed from a weak pointer that
// contains a valid weak reference to a section. Returns false if the section
// weak pointer has no reference to a section, or if the section is still
// valid
// Returns true if the m_section_wp once had a reference to a valid section
// shared pointer, but no longer does. This can happen if we have an address
// from a module that gets unloaded and deleted. This function should only be
// called if GetSection() returns an empty shared pointer and you want to
// know if this address used to have a valid section.
//------------------------------------------------------------------
bool SectionWasDeleted() const;

Expand All @@ -539,15 +539,6 @@ class Address {
//------------------------------------------------------------------
lldb::SectionWP m_section_wp; ///< The section for the address, can be NULL.
lldb::addr_t m_offset; ///< Offset into section if \a m_section_wp is valid...

//------------------------------------------------------------------
// Returns true if the m_section_wp once had a reference to a valid section
// shared pointer, but no longer does. This can happen if we have an address
// from a module that gets unloaded and deleted. This function should only be
// called if GetSection() returns an empty shared pointer and you want to
// know if this address used to have a valid section.
//------------------------------------------------------------------
bool SectionWasDeletedPrivate() const;
};

//----------------------------------------------------------------------
Expand Down
Expand Up @@ -97,3 +97,40 @@ def address_breakpoints(self):

# The hit count for the breakpoint should now be 2.
self.assertTrue(breakpoint.GetHitCount() == 2)



def test_address_breakpoint_set_before_launch(self):
"""Test that an address bp set before the process is launched works correctly."""
self.build()

exe = self.getBuildArtifact("a.out")

# Create a target by the debugger.
target = self.dbg.CreateTarget(exe)
self.assertTrue(target, VALID_TARGET)

# get the address of the symbol "main"
sc_list = target.FindSymbols("main", lldb.eSymbolTypeCode)
symbol = sc_list.GetContextAtIndex(0).GetSymbol()
address = symbol.GetStartAddress().GetFileAddress()

# BreakpointCreateBySBAddress will resolve the address, causing this
# test to always pass, so use runCmd
self.runCmd("break set -a " + str(address))

# Disable ASLR. This will allow us to actually test (on platforms that support this flag)
# that the breakpoint was able to track the module.

launch_info = lldb.SBLaunchInfo(None)
flags = launch_info.GetLaunchFlags()
flags &= ~lldb.eLaunchFlagDisableASLR
launch_info.SetLaunchFlags(flags)

error = lldb.SBError()

process = target.Launch(launch_info, error)
self.assertTrue(process, PROCESS_IS_VALID)
self.expect("process status", STOPPED_DUE_TO_BREAKPOINT,
substrs=["stop reason = breakpoint 1.1"])

2 changes: 1 addition & 1 deletion lldb/source/Breakpoint/Breakpoint.cpp
Expand Up @@ -555,7 +555,7 @@ void Breakpoint::ModulesChanged(ModuleList &module_list, bool load,
// address that we haven't resolved to a section yet. So we'll have to
// look in all the new modules to resolve this location. Otherwise, if
// it was set in this module, re-resolve it here.
if (section_sp && section_sp->GetModule() == module_sp) {
if (!section_sp || section_sp->GetModule() == module_sp) {
if (!seen)
seen = true;

Expand Down
10 changes: 2 additions & 8 deletions lldb/source/Core/Address.cpp
Expand Up @@ -281,7 +281,7 @@ addr_t Address::GetFileAddress() const {
// We have a valid file range, so we can return the file based address by
// adding the file base address to our offset
return sect_file_addr + m_offset;
} else if (SectionWasDeletedPrivate()) {
} else if (SectionWasDeleted()) {
// Used to have a valid section but it got deleted so the offset doesn't
// mean anything without the section
return LLDB_INVALID_ADDRESS;
Expand All @@ -302,7 +302,7 @@ addr_t Address::GetLoadAddress(Target *target) const {
return sect_load_addr + m_offset;
}
}
} else if (SectionWasDeletedPrivate()) {
} else if (SectionWasDeleted()) {
// Used to have a valid section but it got deleted so the offset doesn't
// mean anything without the section
return LLDB_INVALID_ADDRESS;
Expand Down Expand Up @@ -761,12 +761,6 @@ bool Address::Dump(Stream *s, ExecutionContextScope *exe_scope, DumpStyle style,
}

bool Address::SectionWasDeleted() const {
if (GetSection())
return false;
return SectionWasDeletedPrivate();
}

bool Address::SectionWasDeletedPrivate() const {
lldb::SectionWP empty_section_wp;

// If either call to "std::weak_ptr::owner_before(...) value returns true,
Expand Down

0 comments on commit 860bafa

Please sign in to comment.