From 0c40637012f8ed203c323a539ebd3ff0e0a1626c Mon Sep 17 00:00:00 2001 From: Johnny Chen Date: Wed, 14 Sep 2011 20:23:45 +0000 Subject: [PATCH] Add logging to Target::CreateWatchpointLocation() and fix some bug of using the wrong variable. Plus simplify WatchpointLocation::Dump() output. llvm-svn: 139724 --- lldb/source/Breakpoint/WatchpointLocation.cpp | 4 +-- lldb/source/Target/Target.cpp | 25 ++++++++++++++++--- 2 files changed, 22 insertions(+), 7 deletions(-) diff --git a/lldb/source/Breakpoint/WatchpointLocation.cpp b/lldb/source/Breakpoint/WatchpointLocation.cpp index 6e35418cb7dd..3a78290cc619 100644 --- a/lldb/source/Breakpoint/WatchpointLocation.cpp +++ b/lldb/source/Breakpoint/WatchpointLocation.cpp @@ -85,15 +85,13 @@ WatchpointLocation::Dump(Stream *s) const if (s == NULL) return; - s->Printf("WatchpointLocation %u: addr = 0x%8.8llx size = %zu state = %s type = %s watchpoint (%s%s) hw_index = %i hit_count = %-4u ignore_count = %-4u callback = %8p baton = %8p", + s->Printf("WatchpointLocation %u: addr = 0x%8.8llx size = %zu state = %s type = %s%s hit_count = %-4u ignore_count = %-4u callback = %8p baton = %8p", GetID(), (uint64_t)m_addr, m_byte_size, m_enabled ? "enabled " : "disabled", - IsHardware() ? "hardware" : "software", m_watch_read ? "r" : "", m_watch_write ? "w" : "", - GetHardwareIndex(), GetHitCount(), GetIgnoreCount(), m_callback, diff --git a/lldb/source/Target/Target.cpp b/lldb/source/Target/Target.cpp index 11934e0a201a..2c788f55a4ea 100644 --- a/lldb/source/Target/Target.cpp +++ b/lldb/source/Target/Target.cpp @@ -333,6 +333,11 @@ Target::CreateBreakpoint (SearchFilterSP &filter_sp, BreakpointResolverSP &resol WatchpointLocationSP Target::CreateWatchpointLocation(lldb::addr_t addr, size_t size, uint32_t type) { + LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_WATCHPOINTS)); + if (log) + log->Printf("Target::%s (addr = 0x%8.8llx size = %zu type = %u)\n", + __FUNCTION__, addr, size, type); + WatchpointLocationSP wp_loc_sp; bool process_is_valid = m_process_sp && m_process_sp->IsAlive(); if (!process_is_valid) @@ -348,10 +353,10 @@ Target::CreateWatchpointLocation(lldb::addr_t addr, size_t size, uint32_t type) WatchpointLocationSP matched_sp = m_watchpoint_location_list.FindByAddress(addr); if (matched_sp) { - size_t old_size = wp_loc_sp->GetByteSize(); + size_t old_size = matched_sp->GetByteSize(); uint32_t old_type = - (wp_loc_sp->WatchpointRead() ? LLDB_WATCH_TYPE_READ : 0) | - (wp_loc_sp->WatchpointWrite() ? LLDB_WATCH_TYPE_WRITE : 0); + (matched_sp->WatchpointRead() ? LLDB_WATCH_TYPE_READ : 0) | + (matched_sp->WatchpointWrite() ? LLDB_WATCH_TYPE_WRITE : 0); // Return an empty watchpoint location if the same one exists already. if (size == old_size && type == old_type) return wp_loc_sp; @@ -362,10 +367,22 @@ Target::CreateWatchpointLocation(lldb::addr_t addr, size_t size, uint32_t type) } WatchpointLocation *new_loc = new WatchpointLocation(addr, size); + if (!new_loc) + printf("WatchpointLocation ctor failed, out of memory?\n"); + new_loc->SetWatchpointType(type); wp_loc_sp.reset(new_loc); m_watchpoint_location_list.Add(wp_loc_sp); - m_process_sp->EnableWatchpoint(wp_loc_sp.get()); + Error rc = m_process_sp->EnableWatchpoint(wp_loc_sp.get()); + if (rc.Success()) + wp_loc_sp->SetEnabled(true); + + if (log) + log->Printf("Target::%s (creation of watchpoint %s with id = %u)\n", + __FUNCTION__, + rc.Success() ? "succeeded" : "failed", + wp_loc_sp->GetID()); + return wp_loc_sp; }