From johnny.chen at apple.com Mon Aug 29 15:43:14 2011 From: johnny.chen at apple.com (Johnny Chen) Date: Mon, 29 Aug 2011 20:43:14 -0000 Subject: [Lldb-commits] [lldb] r138761 - in /lldb/trunk/source/Plugins/Platform/FreeBSD: PlatformFreeBSD.cpp PlatformFreeBSD.h Message-ID: <20110829204314.9A7A62A6C12C@llvm.org> Author: johnny Date: Mon Aug 29 15:43:14 2011 New Revision: 138761 URL: http://llvm.org/viewvc/llvm-project?rev=138761&view=rev Log: Patch by Filipe for FreeBSD platform plugin! Modified: lldb/trunk/source/Plugins/Platform/FreeBSD/PlatformFreeBSD.cpp lldb/trunk/source/Plugins/Platform/FreeBSD/PlatformFreeBSD.h Modified: lldb/trunk/source/Plugins/Platform/FreeBSD/PlatformFreeBSD.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Platform/FreeBSD/PlatformFreeBSD.cpp?rev=138761&r1=138760&r2=138761&view=diff ============================================================================== --- lldb/trunk/source/Plugins/Platform/FreeBSD/PlatformFreeBSD.cpp (original) +++ lldb/trunk/source/Plugins/Platform/FreeBSD/PlatformFreeBSD.cpp Mon Aug 29 15:43:14 2011 @@ -32,19 +32,34 @@ Platform * PlatformFreeBSD::CreateInstance () { - return new PlatformFreeBSD(); + // The only time we create an instance is when we are creating a remote + // freebsd platform + const bool is_host = false; + return new PlatformFreeBSD (is_host); } const char * PlatformFreeBSD::GetPluginNameStatic() { - return "plugin.platform.FreeBSD"; + return "PlatformFreeBSD"; } const char * -PlatformFreeBSD::GetPluginDescriptionStatic() +PlatformFreeBSD::GetShortPluginNameStatic (bool is_host) { - return "Default platform plugin for FreeBSD"; + if (is_host) + return Platform::GetHostPlatformName (); + else + return "remote-freebsd"; +} + +const char * +PlatformFreeBSD::GetDescriptionStatic (bool is_host) +{ + if (is_host) + return "Local FreeBSD user platform plug-in."; + else + return "Remote FreeBSD user platform plug-in."; } void @@ -54,11 +69,14 @@ if (!g_initialized) { +#if defined (__FreeBSD__) PlatformSP default_platform_sp (CreateInstance()); + //default_platform_sp->SetSystemArchitecture (Host::GetArchitecture()); Platform::SetDefaultPlatform (default_platform_sp); - PluginManager::RegisterPlugin(GetPluginNameStatic(), - GetPluginDescriptionStatic(), - CreateInstance); +#endif + PluginManager::RegisterPlugin(PlatformFreeBSD::GetShortPluginNameStatic(false), + PlatformFreeBSD::GetDescriptionStatic(false), + PlatformFreeBSD::CreateInstance); g_initialized = true; } } @@ -177,8 +195,8 @@ //------------------------------------------------------------------ /// Default Constructor //------------------------------------------------------------------ -PlatformFreeBSD::PlatformFreeBSD () : - Platform(true) +PlatformFreeBSD::PlatformFreeBSD (bool is_host) : + Platform(is_host) { } @@ -219,7 +237,8 @@ return; } - strm << un.sysname << ' ' << un.release << ' ' << un.version << '\n'; + strm << "Host: " << un.sysname << ' ' << un.release << ' ' << un.version << '\n'; + Platform::GetStatus(strm); } size_t Modified: lldb/trunk/source/Plugins/Platform/FreeBSD/PlatformFreeBSD.h URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Platform/FreeBSD/PlatformFreeBSD.h?rev=138761&r1=138760&r2=138761&view=diff ============================================================================== --- lldb/trunk/source/Plugins/Platform/FreeBSD/PlatformFreeBSD.h (original) +++ lldb/trunk/source/Plugins/Platform/FreeBSD/PlatformFreeBSD.h Mon Aug 29 15:43:14 2011 @@ -28,7 +28,7 @@ static void Terminate (); - PlatformFreeBSD (); + PlatformFreeBSD (bool is_host); virtual ~PlatformFreeBSD(); @@ -43,7 +43,10 @@ GetPluginNameStatic(); static const char * - GetPluginDescriptionStatic(); + GetShortPluginNameStatic(bool is_host); + + static const char * + GetDescriptionStatic(bool is_host); virtual const char * GetPluginName() @@ -54,9 +57,9 @@ virtual const char * GetShortPluginName() { - return "PlatformFreeBSD"; + return GetShortPluginNameStatic (IsHost()); } - + virtual uint32_t GetPluginVersion() { @@ -74,7 +77,7 @@ virtual const char * GetDescription () { - return GetPluginDescriptionStatic(); + return GetDescriptionStatic(IsHost()); } virtual void From johnny.chen at apple.com Mon Aug 29 16:01:50 2011 From: johnny.chen at apple.com (Johnny Chen) Date: Mon, 29 Aug 2011 21:01:50 -0000 Subject: [Lldb-commits] [lldb] r138763 - /lldb/trunk/tools/debugserver/source/RNBRemote.cpp Message-ID: <20110829210150.4AB0C2A6C12E@llvm.org> Author: johnny Date: Mon Aug 29 16:01:50 2011 New Revision: 138763 URL: http://llvm.org/viewvc/llvm-project?rev=138763&view=rev Log: Remove an extra break statement. Modified: lldb/trunk/tools/debugserver/source/RNBRemote.cpp Modified: lldb/trunk/tools/debugserver/source/RNBRemote.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/tools/debugserver/source/RNBRemote.cpp?rev=138763&r1=138762&r2=138763&view=diff ============================================================================== --- lldb/trunk/tools/debugserver/source/RNBRemote.cpp (original) +++ lldb/trunk/tools/debugserver/source/RNBRemote.cpp Mon Aug 29 16:01:50 2011 @@ -2681,8 +2681,6 @@ thread_action.state = eStateStepping; break; - break; - default: rnb_err = HandlePacket_ILLFORMED (__FILE__, __LINE__, p, "Unsupported action in vCont packet"); break; From gclayton at apple.com Mon Aug 29 16:49:22 2011 From: gclayton at apple.com (Greg Clayton) Date: Mon, 29 Aug 2011 21:49:22 -0000 Subject: [Lldb-commits] [lldb] r138770 - in /lldb/trunk/tools/debugserver/source/MacOSX: i386/DNBArchImplI386.cpp i386/DNBArchImplI386.h i386/MachRegisterStatesI386.h x86_64/DNBArchImplX86_64.cpp x86_64/DNBArchImplX86_64.h x86_64/MachRegisterStatesX86_64.h Message-ID: <20110829214922.6D4452A6C12C@llvm.org> Author: gclayton Date: Mon Aug 29 16:49:22 2011 New Revision: 138770 URL: http://llvm.org/viewvc/llvm-project?rev=138770&view=rev Log: Added the debug registers for i386 and x86_64 in preparation for watchpoints. Modified: lldb/trunk/tools/debugserver/source/MacOSX/i386/DNBArchImplI386.cpp lldb/trunk/tools/debugserver/source/MacOSX/i386/DNBArchImplI386.h lldb/trunk/tools/debugserver/source/MacOSX/i386/MachRegisterStatesI386.h lldb/trunk/tools/debugserver/source/MacOSX/x86_64/DNBArchImplX86_64.cpp lldb/trunk/tools/debugserver/source/MacOSX/x86_64/DNBArchImplX86_64.h lldb/trunk/tools/debugserver/source/MacOSX/x86_64/MachRegisterStatesX86_64.h Modified: lldb/trunk/tools/debugserver/source/MacOSX/i386/DNBArchImplI386.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/tools/debugserver/source/MacOSX/i386/DNBArchImplI386.cpp?rev=138770&r1=138769&r2=138770&view=diff ============================================================================== --- lldb/trunk/tools/debugserver/source/MacOSX/i386/DNBArchImplI386.cpp (original) +++ lldb/trunk/tools/debugserver/source/MacOSX/i386/DNBArchImplI386.cpp Mon Aug 29 16:49:22 2011 @@ -518,6 +518,24 @@ return m_state.GetError(e_regSetEXC, Write); } +kern_return_t +DNBArchImplI386::GetDBGState(bool force) +{ + if (force || m_state.GetError(e_regSetDBG, Read)) + { + mach_msg_type_number_t count = e_regSetWordSizeDBG; + m_state.SetError(e_regSetDBG, Read, ::thread_get_state(m_thread->ThreadID(), __i386_DEBUG_STATE, (thread_state_t)&m_state.context.dbg, &count)); + } + return m_state.GetError(e_regSetDBG, Read); +} + +kern_return_t +DNBArchImplI386::SetDBGState() +{ + m_state.SetError(e_regSetDBG, Write, ::thread_set_state(m_thread->ThreadID(), __i386_DEBUG_STATE, (thread_state_t)&m_state.context.dbg, e_regSetWordSizeDBG)); + return m_state.GetError(e_regSetDBG, Write); +} + void DNBArchImplI386::ThreadWillResume() { Modified: lldb/trunk/tools/debugserver/source/MacOSX/i386/DNBArchImplI386.h URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/tools/debugserver/source/MacOSX/i386/DNBArchImplI386.h?rev=138770&r1=138769&r2=138770&view=diff ============================================================================== --- lldb/trunk/tools/debugserver/source/MacOSX/i386/DNBArchImplI386.h (original) +++ lldb/trunk/tools/debugserver/source/MacOSX/i386/DNBArchImplI386.h Mon Aug 29 16:49:22 2011 @@ -58,6 +58,7 @@ typedef __i386_float_state_t FPU; typedef __i386_exception_state_t EXC; typedef __i386_avx_state_t AVX; + typedef __i386_debug_state_t DBG; static const DNBRegisterInfo g_gpr_registers[]; static const DNBRegisterInfo g_fpu_registers_no_avx[]; @@ -79,6 +80,7 @@ e_regSetGPR, e_regSetFPU, e_regSetEXC, + e_regSetDBG, kNumRegisterSets } RegisterSet; @@ -87,7 +89,8 @@ e_regSetWordSizeGPR = sizeof(GPR) / sizeof(int), e_regSetWordSizeFPR = sizeof(FPU) / sizeof(int), e_regSetWordSizeEXC = sizeof(EXC) / sizeof(int), - e_regSetWordSizeAVX = sizeof(AVX) / sizeof(int) + e_regSetWordSizeAVX = sizeof(AVX) / sizeof(int), + e_regSetWordSizeDBG = sizeof(DBG) / sizeof(int) } RegisterSetWordSize; enum @@ -99,12 +102,13 @@ struct Context { - __i386_thread_state_t gpr; + GPR gpr; union { - __i386_float_state_t no_avx; - __i386_avx_state_t avx; + FPU no_avx; + AVX avx; } fpu; - __i386_exception_state_t exc; + EXC exc; + DBG dbg; }; struct State @@ -113,6 +117,7 @@ kern_return_t gpr_errs[2]; // Read/Write errors kern_return_t fpu_errs[2]; // Read/Write errors kern_return_t exc_errs[2]; // Read/Write errors + kern_return_t dbg_errs[2]; // Read/Write errors State() { @@ -122,6 +127,7 @@ gpr_errs[i] = -1; fpu_errs[i] = -1; exc_errs[i] = -1; + dbg_errs[i] = -1; } } void InvalidateAllRegisterStates() @@ -142,6 +148,7 @@ case e_regSetGPR: return gpr_errs[err_idx]; case e_regSetFPU: return fpu_errs[err_idx]; case e_regSetEXC: return exc_errs[err_idx]; + case e_regSetDBG: return dbg_errs[err_idx]; default: break; } } @@ -156,7 +163,8 @@ case e_regSetALL: gpr_errs[err_idx] = fpu_errs[err_idx] = - exc_errs[err_idx] = err; + exc_errs[err_idx] = + dbg_errs[err_idx] = err; return true; case e_regSetGPR: @@ -170,7 +178,11 @@ case e_regSetEXC: exc_errs[err_idx] = err; return true; - + + case e_regSetDBG: + dbg_errs[err_idx] = err; + return true; + default: break; } } @@ -185,10 +197,12 @@ kern_return_t GetGPRState (bool force); kern_return_t GetFPUState (bool force); kern_return_t GetEXCState (bool force); + kern_return_t GetDBGState (bool force); kern_return_t SetGPRState (); kern_return_t SetFPUState (); kern_return_t SetEXCState (); + kern_return_t SetDBGState (); static DNBArchProtocol * Create (MachThread *thread); Modified: lldb/trunk/tools/debugserver/source/MacOSX/i386/MachRegisterStatesI386.h URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/tools/debugserver/source/MacOSX/i386/MachRegisterStatesI386.h?rev=138770&r1=138769&r2=138770&view=diff ============================================================================== --- lldb/trunk/tools/debugserver/source/MacOSX/i386/MachRegisterStatesI386.h (original) +++ lldb/trunk/tools/debugserver/source/MacOSX/i386/MachRegisterStatesI386.h Mon Aug 29 16:49:22 2011 @@ -19,6 +19,7 @@ #define __i386_THREAD_STATE 1 #define __i386_FLOAT_STATE 2 #define __i386_EXCEPTION_STATE 3 +#define __i386_DEBUG_STATE 10 #define __i386_AVX_STATE 16 typedef struct { @@ -165,4 +166,15 @@ uint32_t __faultvaddr; } __i386_exception_state_t; +typedef struct { + uint32_t __dr0; + uint32_t __dr1; + uint32_t __dr2; + uint32_t __dr3; + uint32_t __dr4; + uint32_t __dr5; + uint32_t __dr6; + uint32_t __dr7; +} __i386_debug_state_t; + #endif Modified: lldb/trunk/tools/debugserver/source/MacOSX/x86_64/DNBArchImplX86_64.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/tools/debugserver/source/MacOSX/x86_64/DNBArchImplX86_64.cpp?rev=138770&r1=138769&r2=138770&view=diff ============================================================================== --- lldb/trunk/tools/debugserver/source/MacOSX/x86_64/DNBArchImplX86_64.cpp (original) +++ lldb/trunk/tools/debugserver/source/MacOSX/x86_64/DNBArchImplX86_64.cpp Mon Aug 29 16:49:22 2011 @@ -447,6 +447,24 @@ return m_state.GetError(e_regSetEXC, Write); } +kern_return_t +DNBArchImplX86_64::GetDBGState(bool force) +{ + if (force || m_state.GetError(e_regSetDBG, Read)) + { + mach_msg_type_number_t count = e_regSetWordSizeDBG; + m_state.SetError(e_regSetDBG, Read, ::thread_get_state(m_thread->ThreadID(), __x86_64_DEBUG_STATE, (thread_state_t)&m_state.context.dbg, &count)); + } + return m_state.GetError(e_regSetDBG, Read); +} + +kern_return_t +DNBArchImplX86_64::SetDBGState() +{ + m_state.SetError(e_regSetDBG, Write, ::thread_set_state(m_thread->ThreadID(), __x86_64_DEBUG_STATE, (thread_state_t)&m_state.context.dbg, e_regSetWordSizeDBG)); + return m_state.GetError(e_regSetDBG, Write); +} + void DNBArchImplX86_64::ThreadWillResume() { Modified: lldb/trunk/tools/debugserver/source/MacOSX/x86_64/DNBArchImplX86_64.h URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/tools/debugserver/source/MacOSX/x86_64/DNBArchImplX86_64.h?rev=138770&r1=138769&r2=138770&view=diff ============================================================================== --- lldb/trunk/tools/debugserver/source/MacOSX/x86_64/DNBArchImplX86_64.h (original) +++ lldb/trunk/tools/debugserver/source/MacOSX/x86_64/DNBArchImplX86_64.h Mon Aug 29 16:49:22 2011 @@ -57,6 +57,7 @@ typedef __x86_64_float_state_t FPU; typedef __x86_64_exception_state_t EXC; typedef __x86_64_avx_state_t AVX; + typedef __x86_64_debug_state_t DBG; static const DNBRegisterInfo g_gpr_registers[]; static const DNBRegisterInfo g_fpu_registers_no_avx[]; @@ -78,6 +79,7 @@ e_regSetGPR, e_regSetFPU, e_regSetEXC, + e_regSetDBG, kNumRegisterSets } RegisterSet; @@ -86,7 +88,8 @@ e_regSetWordSizeGPR = sizeof(GPR) / sizeof(int), e_regSetWordSizeFPR = sizeof(FPU) / sizeof(int), e_regSetWordSizeEXC = sizeof(EXC) / sizeof(int), - e_regSetWordSizeAVX = sizeof(AVX) / sizeof(int) + e_regSetWordSizeAVX = sizeof(AVX) / sizeof(int), + e_regSetWordSizeDBG = sizeof(DBG) / sizeof(int) } RegisterSetWordSize; enum @@ -98,12 +101,14 @@ struct Context { - __x86_64_thread_state_t gpr; - union { - __x86_64_float_state_t no_avx; - __x86_64_avx_state_t avx; + GPR gpr; + union + { + FPU no_avx; + AVX avx; } fpu; - __x86_64_exception_state_t exc; + EXC exc; + DBG dbg; }; struct State @@ -112,6 +117,7 @@ kern_return_t gpr_errs[2]; // Read/Write errors kern_return_t fpu_errs[2]; // Read/Write errors kern_return_t exc_errs[2]; // Read/Write errors + kern_return_t dbg_errs[2]; // Read/Write errors State() { @@ -121,6 +127,7 @@ gpr_errs[i] = -1; fpu_errs[i] = -1; exc_errs[i] = -1; + dbg_errs[i] = -1; } } @@ -145,6 +152,7 @@ case e_regSetGPR: return gpr_errs[err_idx]; case e_regSetFPU: return fpu_errs[err_idx]; case e_regSetEXC: return exc_errs[err_idx]; + case e_regSetDBG: return dbg_errs[err_idx]; default: break; } } @@ -161,7 +169,8 @@ case e_regSetALL: gpr_errs[err_idx] = fpu_errs[err_idx] = - exc_errs[err_idx] = err; + exc_errs[err_idx] = + dbg_errs[err_idx] = err; return true; case e_regSetGPR: @@ -176,6 +185,10 @@ exc_errs[err_idx] = err; return true; + case e_regSetDBG: + dbg_errs[err_idx] = err; + return true; + default: break; } } @@ -192,10 +205,12 @@ kern_return_t GetGPRState (bool force); kern_return_t GetFPUState (bool force); kern_return_t GetEXCState (bool force); + kern_return_t GetDBGState (bool force); kern_return_t SetGPRState (); kern_return_t SetFPUState (); kern_return_t SetEXCState (); + kern_return_t SetDBGState (); static DNBArchProtocol * Create (MachThread *thread); Modified: lldb/trunk/tools/debugserver/source/MacOSX/x86_64/MachRegisterStatesX86_64.h URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/tools/debugserver/source/MacOSX/x86_64/MachRegisterStatesX86_64.h?rev=138770&r1=138769&r2=138770&view=diff ============================================================================== --- lldb/trunk/tools/debugserver/source/MacOSX/x86_64/MachRegisterStatesX86_64.h (original) +++ lldb/trunk/tools/debugserver/source/MacOSX/x86_64/MachRegisterStatesX86_64.h Mon Aug 29 16:49:22 2011 @@ -19,6 +19,7 @@ #define __x86_64_THREAD_STATE 4 #define __x86_64_FLOAT_STATE 5 #define __x86_64_EXCEPTION_STATE 6 +#define __x86_64_DEBUG_STATE 11 #define __x86_64_AVX_STATE 17 typedef struct { @@ -194,4 +195,16 @@ uint64_t __faultvaddr; } __x86_64_exception_state_t; + +typedef struct { + uint64_t __dr0; + uint64_t __dr1; + uint64_t __dr2; + uint64_t __dr3; + uint64_t __dr4; + uint64_t __dr5; + uint64_t __dr6; + uint64_t __dr7; +} __x86_64_debug_state_t; + #endif From johnny.chen at apple.com Mon Aug 29 20:30:03 2011 From: johnny.chen at apple.com (Johnny Chen) Date: Tue, 30 Aug 2011 01:30:03 -0000 Subject: [Lldb-commits] [lldb] r138790 - in /lldb/trunk/tools/debugserver/source: MacOSX/i386/DNBArchImplI386.cpp MacOSX/i386/DNBArchImplI386.h MacOSX/x86_64/DNBArchImplX86_64.cpp MacOSX/x86_64/DNBArchImplX86_64.h RNBRemote.cpp Message-ID: <20110830013003.7E36F2A6C12C@llvm.org> Author: johnny Date: Mon Aug 29 20:30:03 2011 New Revision: 138790 URL: http://llvm.org/viewvc/llvm-project?rev=138790&view=rev Log: Add stubs of incomplete watchpoint implementation with "FIXME" markers. Modified: lldb/trunk/tools/debugserver/source/MacOSX/i386/DNBArchImplI386.cpp lldb/trunk/tools/debugserver/source/MacOSX/i386/DNBArchImplI386.h lldb/trunk/tools/debugserver/source/MacOSX/x86_64/DNBArchImplX86_64.cpp lldb/trunk/tools/debugserver/source/MacOSX/x86_64/DNBArchImplX86_64.h lldb/trunk/tools/debugserver/source/RNBRemote.cpp Modified: lldb/trunk/tools/debugserver/source/MacOSX/i386/DNBArchImplI386.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/tools/debugserver/source/MacOSX/i386/DNBArchImplI386.cpp?rev=138790&r1=138789&r2=138790&view=diff ============================================================================== --- lldb/trunk/tools/debugserver/source/MacOSX/i386/DNBArchImplI386.cpp (original) +++ lldb/trunk/tools/debugserver/source/MacOSX/i386/DNBArchImplI386.cpp Mon Aug 29 20:30:03 2011 @@ -625,6 +625,117 @@ return false; } +#ifndef DR_FIRSTADDR +#define DR_FIRSTADDR 0 +#endif + +#ifndef DR_LASTADDR +#define DR_LASTADDR 3 +#endif + +#ifndef DR_STATUS +#define DR_STATUS 6 +#endif + +#ifndef DR_CONTROL +#define DR_CONTROL 7 +#endif + +uint32_t +DNBArchImplI386::NumSupportedHardwareWatchpoints() +{ + return DR_LASTADDR - DR_FIRSTADDR + 1; +} + +uint32_t +DNBArchImplI386::EnableHardwareWatchpoint (nub_addr_t addr, nub_size_t size, bool read, bool write) +{ + DNBLogThreadedIf(LOG_WATCHPOINTS, "DNBArchImplI386::EnableHardwareWatchpoint(addr = %8.8p, size = %u, read = %u, write = %u)", addr, size, read, write); + + const uint32_t num_hw_watchpoints = NumSupportedHardwareWatchpoints(); + + // Can't watch zero bytes + if (size == 0) + return INVALID_NUB_HW_INDEX; + + // We must watch for either read or write + if (read == false && write == false) + return INVALID_NUB_HW_INDEX; + + // + // FIXME: Add implmentation. + // + + // Read the debug state + kern_return_t kret = GetDBGState(false); + + if (kret == KERN_SUCCESS) + { + // Check to make sure we have the needed hardware support + uint32_t i = 0; + + DBG debug_state = m_state.context.dbg; + for (i=0; i 0x%8.8x.", kret); + + if (kret == KERN_SUCCESS) + return i; + } + else + { + DNBLogThreadedIf(LOG_WATCHPOINTS, "DNBArchImpl386::EnableHardwareWatchpoint(): All hardware resources (%u) are in use.", num_hw_watchpoints); + } + } + return INVALID_NUB_HW_INDEX; +} + +bool +DNBArchImplI386::DisableHardwareWatchpoint (uint32_t hw_index) +{ + kern_return_t kret = GetDBGState(false); + + const uint32_t num_hw_points = NumSupportedHardwareWatchpoints(); + if (kret == KERN_SUCCESS) + { + if (hw_index < num_hw_points) + { + // + // FIXEME: Add implementation. + // + + DNBLogThreadedIf(LOG_WATCHPOINTS, "DNBArchImplI386::DisableHardwareWatchpoint( %u )", + hw_index); + + kret = SetDBGState(); + + if (kret == KERN_SUCCESS) + return true; + } + } + return false; +} // Set the single step bit in the processor status register. kern_return_t Modified: lldb/trunk/tools/debugserver/source/MacOSX/i386/DNBArchImplI386.h URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/tools/debugserver/source/MacOSX/i386/DNBArchImplI386.h?rev=138790&r1=138789&r2=138790&view=diff ============================================================================== --- lldb/trunk/tools/debugserver/source/MacOSX/i386/DNBArchImplI386.h (original) +++ lldb/trunk/tools/debugserver/source/MacOSX/i386/DNBArchImplI386.h Mon Aug 29 20:30:03 2011 @@ -51,6 +51,10 @@ virtual bool ThreadDidStop(); virtual bool NotifyException(MachException::Data& exc); + virtual uint32_t NumSupportedHardwareWatchpoints(); + virtual uint32_t EnableHardwareWatchpoint (nub_addr_t addr, nub_size_t size, bool read, bool write); + virtual bool DisableHardwareWatchpoint (uint32_t hw_break_index); + protected: kern_return_t EnableHardwareSingleStep (bool enable); Modified: lldb/trunk/tools/debugserver/source/MacOSX/x86_64/DNBArchImplX86_64.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/tools/debugserver/source/MacOSX/x86_64/DNBArchImplX86_64.cpp?rev=138790&r1=138789&r2=138790&view=diff ============================================================================== --- lldb/trunk/tools/debugserver/source/MacOSX/x86_64/DNBArchImplX86_64.cpp (original) +++ lldb/trunk/tools/debugserver/source/MacOSX/x86_64/DNBArchImplX86_64.cpp Mon Aug 29 20:30:03 2011 @@ -554,6 +554,117 @@ return false; } +#ifndef DR_FIRSTADDR +#define DR_FIRSTADDR 0 +#endif + +#ifndef DR_LASTADDR +#define DR_LASTADDR 3 +#endif + +#ifndef DR_STATUS +#define DR_STATUS 6 +#endif + +#ifndef DR_CONTROL +#define DR_CONTROL 7 +#endif + +uint32_t +DNBArchImplX86_64::NumSupportedHardwareWatchpoints() +{ + return DR_LASTADDR - DR_FIRSTADDR + 1; +} + +uint32_t +DNBArchImplX86_64::EnableHardwareWatchpoint (nub_addr_t addr, nub_size_t size, bool read, bool write) +{ + DNBLogThreadedIf(LOG_WATCHPOINTS, "DNBArchImplX86_64::EnableHardwareWatchpoint(addr = %8.8p, size = %u, read = %u, write = %u)", addr, size, read, write); + + const uint32_t num_hw_watchpoints = NumSupportedHardwareWatchpoints(); + + // Can't watch zero bytes + if (size == 0) + return INVALID_NUB_HW_INDEX; + + // We must watch for either read or write + if (read == false && write == false) + return INVALID_NUB_HW_INDEX; + + // + // FIXME: Add implmentation. + // + + // Read the debug state + kern_return_t kret = GetDBGState(false); + + if (kret == KERN_SUCCESS) + { + // Check to make sure we have the needed hardware support + uint32_t i = 0; + + DBG debug_state = m_state.context.dbg; + for (i=0; i 0x%8.8x.", kret); + + if (kret == KERN_SUCCESS) + return i; + } + else + { + DNBLogThreadedIf(LOG_WATCHPOINTS, "DNBArchImplX86_64::EnableHardwareWatchpoint(): All hardware resources (%u) are in use.", num_hw_watchpoints); + } + } + return INVALID_NUB_HW_INDEX; +} + +bool +DNBArchImplX86_64::DisableHardwareWatchpoint (uint32_t hw_index) +{ + kern_return_t kret = GetDBGState(false); + + const uint32_t num_hw_points = NumSupportedHardwareWatchpoints(); + if (kret == KERN_SUCCESS) + { + if (hw_index < num_hw_points) + { + // + // FIXEME: Add implementation. + // + + DNBLogThreadedIf(LOG_WATCHPOINTS, "DNBArchImplX86_64::DisableHardwareWatchpoint( %u )", + hw_index); + + kret = SetDBGState(); + + if (kret == KERN_SUCCESS) + return true; + } + } + return false; +} // Set the single step bit in the processor status register. kern_return_t Modified: lldb/trunk/tools/debugserver/source/MacOSX/x86_64/DNBArchImplX86_64.h URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/tools/debugserver/source/MacOSX/x86_64/DNBArchImplX86_64.h?rev=138790&r1=138789&r2=138790&view=diff ============================================================================== --- lldb/trunk/tools/debugserver/source/MacOSX/x86_64/DNBArchImplX86_64.h (original) +++ lldb/trunk/tools/debugserver/source/MacOSX/x86_64/DNBArchImplX86_64.h Mon Aug 29 20:30:03 2011 @@ -50,6 +50,10 @@ virtual bool ThreadDidStop(); virtual bool NotifyException(MachException::Data& exc); + virtual uint32_t NumSupportedHardwareWatchpoints(); + virtual uint32_t EnableHardwareWatchpoint (nub_addr_t addr, nub_size_t size, bool read, bool write); + virtual bool DisableHardwareWatchpoint (uint32_t hw_break_index); + protected: kern_return_t EnableHardwareSingleStep (bool enable); Modified: lldb/trunk/tools/debugserver/source/RNBRemote.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/tools/debugserver/source/RNBRemote.cpp?rev=138790&r1=138789&r2=138790&view=diff ============================================================================== --- lldb/trunk/tools/debugserver/source/RNBRemote.cpp (original) +++ lldb/trunk/tools/debugserver/source/RNBRemote.cpp Mon Aug 29 20:30:03 2011 @@ -147,12 +147,12 @@ // t.push_back (Packet (write_data_to_memory, &RNBRemote::HandlePacket_X, NULL, "X", "Write data to memory")); // t.push_back (Packet (insert_hardware_bp, &RNBRemote::HandlePacket_UNIMPLEMENTED, NULL, "Z1", "Insert hardware breakpoint")); // t.push_back (Packet (remove_hardware_bp, &RNBRemote::HandlePacket_UNIMPLEMENTED, NULL, "z1", "Remove hardware breakpoint")); -// t.push_back (Packet (insert_write_watch_bp, &RNBRemote::HandlePacket_UNIMPLEMENTED, NULL, "Z2", "Insert write watchpoint")); -// t.push_back (Packet (remove_write_watch_bp, &RNBRemote::HandlePacket_UNIMPLEMENTED, NULL, "z2", "Remove write watchpoint")); -// t.push_back (Packet (insert_read_watch_bp, &RNBRemote::HandlePacket_UNIMPLEMENTED, NULL, "Z3", "Insert read watchpoint")); -// t.push_back (Packet (remove_read_watch_bp, &RNBRemote::HandlePacket_UNIMPLEMENTED, NULL, "z3", "Remove read watchpoint")); -// t.push_back (Packet (insert_access_watch_bp, &RNBRemote::HandlePacket_UNIMPLEMENTED, NULL, "Z4", "Insert access watchpoint")); -// t.push_back (Packet (remove_access_watch_bp, &RNBRemote::HandlePacket_UNIMPLEMENTED, NULL, "z4", "Remove access watchpoint")); + t.push_back (Packet (insert_write_watch_bp, &RNBRemote::HandlePacket_z, NULL, "Z2", "Insert write watchpoint")); + t.push_back (Packet (remove_write_watch_bp, &RNBRemote::HandlePacket_z, NULL, "z2", "Remove write watchpoint")); + t.push_back (Packet (insert_read_watch_bp, &RNBRemote::HandlePacket_z, NULL, "Z3", "Insert read watchpoint")); + t.push_back (Packet (remove_read_watch_bp, &RNBRemote::HandlePacket_z, NULL, "z3", "Remove read watchpoint")); + t.push_back (Packet (insert_access_watch_bp, &RNBRemote::HandlePacket_z, NULL, "Z4", "Insert access watchpoint")); + t.push_back (Packet (remove_access_watch_bp, &RNBRemote::HandlePacket_z, NULL, "z4", "Remove access watchpoint")); t.push_back (Packet (query_current_thread_id, &RNBRemote::HandlePacket_qC, NULL, "qC", "Query current thread ID")); t.push_back (Packet (query_get_pid, &RNBRemote::HandlePacket_qGetPid, NULL, "qGetPid", "Query process id")); // t.push_back (Packet (query_memory_crc, &RNBRemote::HandlePacket_UNIMPLEMENTED, NULL, "qCRC:", "Compute CRC of memory region")); From johnny.chen at apple.com Tue Aug 30 19:27:53 2011 From: johnny.chen at apple.com (Johnny Chen) Date: Wed, 31 Aug 2011 00:27:53 -0000 Subject: [Lldb-commits] [lldb] r138844 - in /lldb/trunk/tools/debugserver/source/MacOSX: i386/DNBArchImplI386.cpp x86_64/DNBArchImplX86_64.cpp x86_64/DNBArchImplX86_64.h Message-ID: <20110831002753.CCF932A6C12C@llvm.org> Author: johnny Date: Tue Aug 30 19:27:53 2011 New Revision: 138844 URL: http://llvm.org/viewvc/llvm-project?rev=138844&view=rev Log: Watchpoint work in progress: add helper methods to DNB arch impl for X86_64 to implment Enable/DisableHardwareWatchpoint. Modified: lldb/trunk/tools/debugserver/source/MacOSX/i386/DNBArchImplI386.cpp lldb/trunk/tools/debugserver/source/MacOSX/x86_64/DNBArchImplX86_64.cpp lldb/trunk/tools/debugserver/source/MacOSX/x86_64/DNBArchImplX86_64.h Modified: lldb/trunk/tools/debugserver/source/MacOSX/i386/DNBArchImplI386.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/tools/debugserver/source/MacOSX/i386/DNBArchImplI386.cpp?rev=138844&r1=138843&r2=138844&view=diff ============================================================================== --- lldb/trunk/tools/debugserver/source/MacOSX/i386/DNBArchImplI386.cpp (original) +++ lldb/trunk/tools/debugserver/source/MacOSX/i386/DNBArchImplI386.cpp Tue Aug 30 19:27:53 2011 @@ -690,7 +690,7 @@ default: break; } - if (dr_val != 0) + if (dr_val == 0) break; // We found an available hw breakpoint slot (in i) } Modified: lldb/trunk/tools/debugserver/source/MacOSX/x86_64/DNBArchImplX86_64.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/tools/debugserver/source/MacOSX/x86_64/DNBArchImplX86_64.cpp?rev=138844&r1=138843&r2=138844&view=diff ============================================================================== --- lldb/trunk/tools/debugserver/source/MacOSX/x86_64/DNBArchImplX86_64.cpp (original) +++ lldb/trunk/tools/debugserver/source/MacOSX/x86_64/DNBArchImplX86_64.cpp Tue Aug 30 19:27:53 2011 @@ -554,26 +554,110 @@ return false; } -#ifndef DR_FIRSTADDR -#define DR_FIRSTADDR 0 -#endif - -#ifndef DR_LASTADDR -#define DR_LASTADDR 3 -#endif - -#ifndef DR_STATUS -#define DR_STATUS 6 -#endif - -#ifndef DR_CONTROL -#define DR_CONTROL 7 -#endif - uint32_t DNBArchImplX86_64::NumSupportedHardwareWatchpoints() { - return DR_LASTADDR - DR_FIRSTADDR + 1; + // Available debug address registers: dr0, dr1, dr2, dr3. + return 4; +} + +static uint32_t +size_and_rw_bits(nub_size_t size, bool read, bool write) +{ + uint32_t rw; + if (read) { + rw = 0x3; // READ or READ/WRITE + } else if (write) { + rw = 0x1; // WRITE + } else { + assert(0 && "read and write cannot both be false"); + } + + switch (size) { + case 1: + return rw; + case 2: + return (0x1 << 2) | rw; + case 4: + return (0x3 << 2) | rw; + case 8: + return (0x2 << 2) | rw; + default: + assert(0 && "invalid size, must be one of 1, 2, 4, or 8"); + } +} +void +DNBArchImplX86_64::SetWatchpoint(DBG &debug_state, uint32_t hw_index, nub_addr_t addr, nub_size_t size, bool read, bool write) +{ + // Set both dr7 (debug control register) and dri (debug address register). + + // dr7{7-0} encodes the local/gloabl enable bits: + // global enable --. .-- local enable + // | | + // v v + // dr0 -> bits{1-0} + // dr1 -> bits{3-2} + // dr2 -> bits{5-4} + // dr3 -> bits{7-6} + // + // dr7{31-16} encodes the rw/len bits: + // b_x+3, b_x+2, b_x+1, b_x + // where bits{x+1, x} => rw + // 0b00: execute, 0b01: write, 0b11: read-or-write, 0b10: io read-or-write (unused) + // and bits{x+3, x+2} => len + // 0b00: 1-byte, 0b01: 2-byte, 0b11: 4-byte, 0b10: 8-byte + // + // dr0 -> bits{19-16} + // dr1 -> bits{23-20} + // dr2 -> bits{27-24} + // dr3 -> bits{31-28} + debug_state.__dr7 |= (1 << (2*hw_index) | size_and_rw_bits(size, read, write) << 16); + switch (hw_index) { + case 0: + debug_state.__dr0 == addr; break; + case 1: + debug_state.__dr1 == addr; break; + case 2: + debug_state.__dr2 == addr; break; + case 3: + debug_state.__dr3 == addr; break; + default: + assert(0 && "invalid hardware register index, must be one of 0, 1, 2, or 3"); + } + return; +} + +void +DNBArchImplX86_64::ClearWatchpoint(DBG &debug_state, uint32_t hw_index) +{ + debug_state.__dr7 &= ~(3 << (2*hw_index)); + switch (hw_index) { + case 0: + debug_state.__dr0 == 0; break; + case 1: + debug_state.__dr1 == 0; break; + case 2: + debug_state.__dr2 == 0; break; + case 3: + debug_state.__dr3 == 0; break; + default: + assert(0 && "invalid hardware register index, must be one of 0, 1, 2, or 3"); + } + return; +} + +bool +DNBArchImplX86_64::IsVacantWatchpoint(const DBG &debug_state, uint32_t hw_index) +{ + // Check dr7 (debug control register) for local/global enable bits: + // global enable --. .-- local enable + // | | + // v v + // dr0 -> bits{1-0} + // dr1 -> bits{3-2} + // dr2 -> bits{5-4} + // dr3 -> bits{7-6} + return (debug_state.__dr7 & (3 << (2*hw_index))) == 0; } uint32_t @@ -583,18 +667,14 @@ const uint32_t num_hw_watchpoints = NumSupportedHardwareWatchpoints(); - // Can't watch zero bytes - if (size == 0) + // Can only watch 1, 2, 4, or 8 bytes. + if (!(size == 1 || size == 2 || size == 4 || size == 8)) return INVALID_NUB_HW_INDEX; // We must watch for either read or write if (read == false && write == false) return INVALID_NUB_HW_INDEX; - // - // FIXME: Add implmentation. - // - // Read the debug state kern_return_t kret = GetDBGState(false); @@ -604,28 +684,18 @@ uint32_t i = 0; DBG debug_state = m_state.context.dbg; - for (i=0; i 0x%8.8x.", kret); @@ -648,17 +718,16 @@ const uint32_t num_hw_points = NumSupportedHardwareWatchpoints(); if (kret == KERN_SUCCESS) { - if (hw_index < num_hw_points) + DBG debug_state = m_state.context.dbg; + if (hw_index < num_hw_points && !IsVacantWatchpoint(debug_state, hw_index)) { - // - // FIXEME: Add implementation. - // - + // Modify our local copy of the debug state, first. + ClearWatchpoint(debug_state, hw_index); + // Ready to disable the watch point in the inferior. + kret = SetDBGState(); DNBLogThreadedIf(LOG_WATCHPOINTS, "DNBArchImplX86_64::DisableHardwareWatchpoint( %u )", hw_index); - kret = SetDBGState(); - if (kret == KERN_SUCCESS) return true; } Modified: lldb/trunk/tools/debugserver/source/MacOSX/x86_64/DNBArchImplX86_64.h URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/tools/debugserver/source/MacOSX/x86_64/DNBArchImplX86_64.h?rev=138844&r1=138843&r2=138844&view=diff ============================================================================== --- lldb/trunk/tools/debugserver/source/MacOSX/x86_64/DNBArchImplX86_64.h (original) +++ lldb/trunk/tools/debugserver/source/MacOSX/x86_64/DNBArchImplX86_64.h Tue Aug 30 19:27:53 2011 @@ -234,6 +234,11 @@ return (s_has_avx == kAVXPresent); } + // Helper functions for watchpoint manipulations. + static void SetWatchpoint(DBG &debug_state, uint32_t hw_index, nub_addr_t addr, nub_size_t size, bool read, bool write); + static void ClearWatchpoint(DBG &debug_state, uint32_t hw_index); + static bool IsVacantWatchpoint(const DBG &debug_state, uint32_t hw_index); + MachThread *m_thread; State m_state; From johnny.chen at apple.com Tue Aug 30 19:50:10 2011 From: johnny.chen at apple.com (Johnny Chen) Date: Wed, 31 Aug 2011 00:50:10 -0000 Subject: [Lldb-commits] [lldb] r138847 - in /lldb/trunk/tools/debugserver/source/MacOSX: i386/DNBArchImplI386.cpp i386/DNBArchImplI386.h x86_64/DNBArchImplX86_64.h Message-ID: <20110831005010.EE96C2A6C12C@llvm.org> Author: johnny Date: Tue Aug 30 19:50:10 2011 New Revision: 138847 URL: http://llvm.org/viewvc/llvm-project?rev=138847&view=rev Log: Watchpoint work in progress: add helper methods to DNB arch impl for I386 to implment Enable/DisableHardwareWatchpoint. Modified: lldb/trunk/tools/debugserver/source/MacOSX/i386/DNBArchImplI386.cpp lldb/trunk/tools/debugserver/source/MacOSX/i386/DNBArchImplI386.h lldb/trunk/tools/debugserver/source/MacOSX/x86_64/DNBArchImplX86_64.h Modified: lldb/trunk/tools/debugserver/source/MacOSX/i386/DNBArchImplI386.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/tools/debugserver/source/MacOSX/i386/DNBArchImplI386.cpp?rev=138847&r1=138846&r2=138847&view=diff ============================================================================== --- lldb/trunk/tools/debugserver/source/MacOSX/i386/DNBArchImplI386.cpp (original) +++ lldb/trunk/tools/debugserver/source/MacOSX/i386/DNBArchImplI386.cpp Tue Aug 30 19:50:10 2011 @@ -625,26 +625,111 @@ return false; } -#ifndef DR_FIRSTADDR -#define DR_FIRSTADDR 0 -#endif - -#ifndef DR_LASTADDR -#define DR_LASTADDR 3 -#endif - -#ifndef DR_STATUS -#define DR_STATUS 6 -#endif - -#ifndef DR_CONTROL -#define DR_CONTROL 7 -#endif - uint32_t DNBArchImplI386::NumSupportedHardwareWatchpoints() { - return DR_LASTADDR - DR_FIRSTADDR + 1; + // Available debug address registers: dr0, dr1, dr2, dr3. + return 4; +} + +static uint32_t +size_and_rw_bits(nub_size_t size, bool read, bool write) +{ + uint32_t rw; + if (read) { + rw = 0x3; // READ or READ/WRITE + } else if (write) { + rw = 0x1; // WRITE + } else { + assert(0 && "read and write cannot both be false"); + } + + switch (size) { + case 1: + return rw; + case 2: + return (0x1 << 2) | rw; + case 4: + return (0x3 << 2) | rw; + case 8: + return (0x2 << 2) | rw; + default: + assert(0 && "invalid size, must be one of 1, 2, 4, or 8"); + } +} +void +DNBArchImplI386::SetWatchpoint(DBG &debug_state, uint32_t hw_index, nub_addr_t addr, nub_size_t size, bool read, bool write) +{ + // Set both dr7 (debug control register) and dri (debug address register). + + // dr7{7-0} encodes the local/gloabl enable bits: + // global enable --. .-- local enable + // | | + // v v + // dr0 -> bits{1-0} + // dr1 -> bits{3-2} + // dr2 -> bits{5-4} + // dr3 -> bits{7-6} + // + // dr7{31-16} encodes the rw/len bits: + // b_x+3, b_x+2, b_x+1, b_x + // where bits{x+1, x} => rw + // 0b00: execute, 0b01: write, 0b11: read-or-write, 0b10: io read-or-write (unused) + // and bits{x+3, x+2} => len + // 0b00: 1-byte, 0b01: 2-byte, 0b11: 4-byte, 0b10: 8-byte + // + // dr0 -> bits{19-16} + // dr1 -> bits{23-20} + // dr2 -> bits{27-24} + // dr3 -> bits{31-28} + debug_state.__dr7 |= (1 << (2*hw_index) | size_and_rw_bits(size, read, write) << 16); + uint32_t addr_32 = addr & 0xffffffff; + switch (hw_index) { + case 0: + debug_state.__dr0 == addr_32; break; + case 1: + debug_state.__dr1 == addr_32; break; + case 2: + debug_state.__dr2 == addr_32; break; + case 3: + debug_state.__dr3 == addr_32; break; + default: + assert(0 && "invalid hardware register index, must be one of 0, 1, 2, or 3"); + } + return; +} + +void +DNBArchImplI386::ClearWatchpoint(DBG &debug_state, uint32_t hw_index) +{ + debug_state.__dr7 &= ~(3 << (2*hw_index)); + switch (hw_index) { + case 0: + debug_state.__dr0 == 0; break; + case 1: + debug_state.__dr1 == 0; break; + case 2: + debug_state.__dr2 == 0; break; + case 3: + debug_state.__dr3 == 0; break; + default: + assert(0 && "invalid hardware register index, must be one of 0, 1, 2, or 3"); + } + return; +} + +bool +DNBArchImplI386::IsVacantWatchpoint(const DBG &debug_state, uint32_t hw_index) +{ + // Check dr7 (debug control register) for local/global enable bits: + // global enable --. .-- local enable + // | | + // v v + // dr0 -> bits{1-0} + // dr1 -> bits{3-2} + // dr2 -> bits{5-4} + // dr3 -> bits{7-6} + return (debug_state.__dr7 & (3 << (2*hw_index))) == 0; } uint32_t @@ -654,18 +739,14 @@ const uint32_t num_hw_watchpoints = NumSupportedHardwareWatchpoints(); - // Can't watch zero bytes - if (size == 0) + // Can only watch 1, 2, 4, or 8 bytes. + if (!(size == 1 || size == 2 || size == 4 || size == 8)) return INVALID_NUB_HW_INDEX; // We must watch for either read or write if (read == false && write == false) return INVALID_NUB_HW_INDEX; - // - // FIXME: Add implmentation. - // - // Read the debug state kern_return_t kret = GetDBGState(false); @@ -675,37 +756,27 @@ uint32_t i = 0; DBG debug_state = m_state.context.dbg; - for (i=0; i 0x%8.8x.", kret); + DNBLogThreadedIf(LOG_WATCHPOINTS, "DNBArchImplI386::EnableHardwareWatchpoint() SetDBGState() => 0x%8.8x.", kret); if (kret == KERN_SUCCESS) return i; } else { - DNBLogThreadedIf(LOG_WATCHPOINTS, "DNBArchImpl386::EnableHardwareWatchpoint(): All hardware resources (%u) are in use.", num_hw_watchpoints); + DNBLogThreadedIf(LOG_WATCHPOINTS, "DNBArchImplI386::EnableHardwareWatchpoint(): All hardware resources (%u) are in use.", num_hw_watchpoints); } } return INVALID_NUB_HW_INDEX; @@ -719,17 +790,16 @@ const uint32_t num_hw_points = NumSupportedHardwareWatchpoints(); if (kret == KERN_SUCCESS) { - if (hw_index < num_hw_points) + DBG debug_state = m_state.context.dbg; + if (hw_index < num_hw_points && !IsVacantWatchpoint(debug_state, hw_index)) { - // - // FIXEME: Add implementation. - // - + // Modify our local copy of the debug state, first. + ClearWatchpoint(debug_state, hw_index); + // Ready to disable the watch point in the inferior. + kret = SetDBGState(); DNBLogThreadedIf(LOG_WATCHPOINTS, "DNBArchImplI386::DisableHardwareWatchpoint( %u )", hw_index); - kret = SetDBGState(); - if (kret == KERN_SUCCESS) return true; } Modified: lldb/trunk/tools/debugserver/source/MacOSX/i386/DNBArchImplI386.h URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/tools/debugserver/source/MacOSX/i386/DNBArchImplI386.h?rev=138847&r1=138846&r2=138847&view=diff ============================================================================== --- lldb/trunk/tools/debugserver/source/MacOSX/i386/DNBArchImplI386.h (original) +++ lldb/trunk/tools/debugserver/source/MacOSX/i386/DNBArchImplI386.h Tue Aug 30 19:50:10 2011 @@ -226,6 +226,11 @@ return (s_has_avx == kAVXPresent); } + // Helper functions for watchpoint manipulations. + static void SetWatchpoint(DBG &debug_state, uint32_t hw_index, nub_addr_t addr, nub_size_t size, bool read, bool write); + static void ClearWatchpoint(DBG &debug_state, uint32_t hw_index); + static bool IsVacantWatchpoint(const DBG &debug_state, uint32_t hw_index); + MachThread *m_thread; State m_state; Modified: lldb/trunk/tools/debugserver/source/MacOSX/x86_64/DNBArchImplX86_64.h URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/tools/debugserver/source/MacOSX/x86_64/DNBArchImplX86_64.h?rev=138847&r1=138846&r2=138847&view=diff ============================================================================== --- lldb/trunk/tools/debugserver/source/MacOSX/x86_64/DNBArchImplX86_64.h (original) +++ lldb/trunk/tools/debugserver/source/MacOSX/x86_64/DNBArchImplX86_64.h Tue Aug 30 19:50:10 2011 @@ -105,9 +105,8 @@ struct Context { - GPR gpr; - union - { + GPR gpr; + union { FPU no_avx; AVX avx; } fpu; From johnny.chen at apple.com Wed Aug 31 12:29:29 2011 From: johnny.chen at apple.com (Johnny Chen) Date: Wed, 31 Aug 2011 17:29:29 -0000 Subject: [Lldb-commits] [lldb] r138863 - in /lldb/trunk/tools/debugserver/source/MacOSX: i386/DNBArchImplI386.cpp x86_64/DNBArchImplX86_64.cpp Message-ID: <20110831172929.6D34C2A6C12C@llvm.org> Author: johnny Date: Wed Aug 31 12:29:29 2011 New Revision: 138863 URL: http://llvm.org/viewvc/llvm-project?rev=138863&view=rev Log: Update comments. Modified: lldb/trunk/tools/debugserver/source/MacOSX/i386/DNBArchImplI386.cpp lldb/trunk/tools/debugserver/source/MacOSX/x86_64/DNBArchImplX86_64.cpp Modified: lldb/trunk/tools/debugserver/source/MacOSX/i386/DNBArchImplI386.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/tools/debugserver/source/MacOSX/i386/DNBArchImplI386.cpp?rev=138863&r1=138862&r2=138863&view=diff ============================================================================== --- lldb/trunk/tools/debugserver/source/MacOSX/i386/DNBArchImplI386.cpp (original) +++ lldb/trunk/tools/debugserver/source/MacOSX/i386/DNBArchImplI386.cpp Wed Aug 31 12:29:29 2011 @@ -767,7 +767,7 @@ { // Modify our local copy of the debug state, first. SetWatchpoint(debug_state, i, addr, size, read, write); - // Ready to set the watch point in the inferior. + // Now set the watch point in the inferior. kret = SetDBGState(); DNBLogThreadedIf(LOG_WATCHPOINTS, "DNBArchImplI386::EnableHardwareWatchpoint() SetDBGState() => 0x%8.8x.", kret); @@ -795,7 +795,7 @@ { // Modify our local copy of the debug state, first. ClearWatchpoint(debug_state, hw_index); - // Ready to disable the watch point in the inferior. + // Now disable the watch point in the inferior. kret = SetDBGState(); DNBLogThreadedIf(LOG_WATCHPOINTS, "DNBArchImplI386::DisableHardwareWatchpoint( %u )", hw_index); Modified: lldb/trunk/tools/debugserver/source/MacOSX/x86_64/DNBArchImplX86_64.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/tools/debugserver/source/MacOSX/x86_64/DNBArchImplX86_64.cpp?rev=138863&r1=138862&r2=138863&view=diff ============================================================================== --- lldb/trunk/tools/debugserver/source/MacOSX/x86_64/DNBArchImplX86_64.cpp (original) +++ lldb/trunk/tools/debugserver/source/MacOSX/x86_64/DNBArchImplX86_64.cpp Wed Aug 31 12:29:29 2011 @@ -695,7 +695,7 @@ { // Modify our local copy of the debug state, first. SetWatchpoint(debug_state, i, addr, size, read, write); - // Ready to set the watch point in the inferior. + // Now set the watch point in the inferior. kret = SetDBGState(); DNBLogThreadedIf(LOG_WATCHPOINTS, "DNBArchImplX86_64::EnableHardwareWatchpoint() SetDBGState() => 0x%8.8x.", kret); @@ -723,7 +723,7 @@ { // Modify our local copy of the debug state, first. ClearWatchpoint(debug_state, hw_index); - // Ready to disable the watch point in the inferior. + // Now disable the watch point in the inferior. kret = SetDBGState(); DNBLogThreadedIf(LOG_WATCHPOINTS, "DNBArchImplX86_64::DisableHardwareWatchpoint( %u )", hw_index); From johnny.chen at apple.com Wed Aug 31 12:51:43 2011 From: johnny.chen at apple.com (Johnny Chen) Date: Wed, 31 Aug 2011 17:51:43 -0000 Subject: [Lldb-commits] [lldb] r138867 - in /lldb/trunk/tools/debugserver/source/MacOSX: i386/DNBArchImplI386.cpp x86_64/DNBArchImplX86_64.cpp Message-ID: <20110831175143.4D5CD2A6C12C@llvm.org> Author: johnny Date: Wed Aug 31 12:51:43 2011 New Revision: 138867 URL: http://llvm.org/viewvc/llvm-project?rev=138867&view=rev Log: Fix the shift amount applied to size_and_rw_bits() for debug control register, which did not take into account the hardware index. Modified: lldb/trunk/tools/debugserver/source/MacOSX/i386/DNBArchImplI386.cpp lldb/trunk/tools/debugserver/source/MacOSX/x86_64/DNBArchImplX86_64.cpp Modified: lldb/trunk/tools/debugserver/source/MacOSX/i386/DNBArchImplI386.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/tools/debugserver/source/MacOSX/i386/DNBArchImplI386.cpp?rev=138867&r1=138866&r2=138867&view=diff ============================================================================== --- lldb/trunk/tools/debugserver/source/MacOSX/i386/DNBArchImplI386.cpp (original) +++ lldb/trunk/tools/debugserver/source/MacOSX/i386/DNBArchImplI386.cpp Wed Aug 31 12:51:43 2011 @@ -682,7 +682,8 @@ // dr1 -> bits{23-20} // dr2 -> bits{27-24} // dr3 -> bits{31-28} - debug_state.__dr7 |= (1 << (2*hw_index) | size_and_rw_bits(size, read, write) << 16); + debug_state.__dr7 |= (1 << (2*hw_index) | + size_and_rw_bits(size, read, write) << (16+4*hw_index)); uint32_t addr_32 = addr & 0xffffffff; switch (hw_index) { case 0: Modified: lldb/trunk/tools/debugserver/source/MacOSX/x86_64/DNBArchImplX86_64.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/tools/debugserver/source/MacOSX/x86_64/DNBArchImplX86_64.cpp?rev=138867&r1=138866&r2=138867&view=diff ============================================================================== --- lldb/trunk/tools/debugserver/source/MacOSX/x86_64/DNBArchImplX86_64.cpp (original) +++ lldb/trunk/tools/debugserver/source/MacOSX/x86_64/DNBArchImplX86_64.cpp Wed Aug 31 12:51:43 2011 @@ -611,7 +611,8 @@ // dr1 -> bits{23-20} // dr2 -> bits{27-24} // dr3 -> bits{31-28} - debug_state.__dr7 |= (1 << (2*hw_index) | size_and_rw_bits(size, read, write) << 16); + debug_state.__dr7 |= (1 << (2*hw_index) | + size_and_rw_bits(size, read, write) << (16+4*hw_index)); switch (hw_index) { case 0: debug_state.__dr0 == addr; break; From johnny.chen at apple.com Wed Aug 31 14:05:55 2011 From: johnny.chen at apple.com (Johnny Chen) Date: Wed, 31 Aug 2011 19:05:55 -0000 Subject: [Lldb-commits] [lldb] r138881 - in /lldb/trunk/tools/debugserver/source/MacOSX: i386/DNBArchImplI386.cpp i386/DNBArchImplI386.h x86_64/DNBArchImplX86_64.cpp x86_64/DNBArchImplX86_64.h Message-ID: <20110831190555.CC2D82A6C12C@llvm.org> Author: johnny Date: Wed Aug 31 14:05:55 2011 New Revision: 138881 URL: http://llvm.org/viewvc/llvm-project?rev=138881&view=rev Log: Add a couple of helper methods to check/clear the debug status register which contains the watchpoint hit information. Modified: lldb/trunk/tools/debugserver/source/MacOSX/i386/DNBArchImplI386.cpp lldb/trunk/tools/debugserver/source/MacOSX/i386/DNBArchImplI386.h lldb/trunk/tools/debugserver/source/MacOSX/x86_64/DNBArchImplX86_64.cpp lldb/trunk/tools/debugserver/source/MacOSX/x86_64/DNBArchImplX86_64.h Modified: lldb/trunk/tools/debugserver/source/MacOSX/i386/DNBArchImplI386.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/tools/debugserver/source/MacOSX/i386/DNBArchImplI386.cpp?rev=138881&r1=138880&r2=138881&view=diff ============================================================================== --- lldb/trunk/tools/debugserver/source/MacOSX/i386/DNBArchImplI386.cpp (original) +++ lldb/trunk/tools/debugserver/source/MacOSX/i386/DNBArchImplI386.cpp Wed Aug 31 14:05:55 2011 @@ -733,6 +733,29 @@ return (debug_state.__dr7 & (3 << (2*hw_index))) == 0; } +// Resets local copy of debug status register to wait for the next debug excpetion. +void +DNBArchImplI386::ClearWatchpointHit(DBG &debug_state) +{ + // See also IsWatchpointHit(). + debug_state.__dr6 = 0; + return; +} + +bool +DNBArchImplI386::IsWatchpointHit(const DBG &debug_state, uint32_t hw_index) +{ + // Check dr6 (debug status register) whether a watchpoint hits: + // is watchpoint hit? + // | + // v + // dr0 -> bits{0} + // dr1 -> bits{1} + // dr2 -> bits{2} + // dr3 -> bits{3} + return (debug_state.__dr6 & (1 << hw_index)); +} + uint32_t DNBArchImplI386::EnableHardwareWatchpoint (nub_addr_t addr, nub_size_t size, bool read, bool write) { Modified: lldb/trunk/tools/debugserver/source/MacOSX/i386/DNBArchImplI386.h URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/tools/debugserver/source/MacOSX/i386/DNBArchImplI386.h?rev=138881&r1=138880&r2=138881&view=diff ============================================================================== --- lldb/trunk/tools/debugserver/source/MacOSX/i386/DNBArchImplI386.h (original) +++ lldb/trunk/tools/debugserver/source/MacOSX/i386/DNBArchImplI386.h Wed Aug 31 14:05:55 2011 @@ -230,6 +230,8 @@ static void SetWatchpoint(DBG &debug_state, uint32_t hw_index, nub_addr_t addr, nub_size_t size, bool read, bool write); static void ClearWatchpoint(DBG &debug_state, uint32_t hw_index); static bool IsVacantWatchpoint(const DBG &debug_state, uint32_t hw_index); + static void ClearWatchpointHit(DBG &debug_state); + static bool IsWatchpointHit(const DBG &debug_state, uint32_t hw_index); MachThread *m_thread; State m_state; Modified: lldb/trunk/tools/debugserver/source/MacOSX/x86_64/DNBArchImplX86_64.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/tools/debugserver/source/MacOSX/x86_64/DNBArchImplX86_64.cpp?rev=138881&r1=138880&r2=138881&view=diff ============================================================================== --- lldb/trunk/tools/debugserver/source/MacOSX/x86_64/DNBArchImplX86_64.cpp (original) +++ lldb/trunk/tools/debugserver/source/MacOSX/x86_64/DNBArchImplX86_64.cpp Wed Aug 31 14:05:55 2011 @@ -661,6 +661,29 @@ return (debug_state.__dr7 & (3 << (2*hw_index))) == 0; } +// Resets local copy of debug status register to wait for the next debug excpetion. +void +DNBArchImplX86_64::ClearWatchpointHit(DBG &debug_state) +{ + // See also IsWatchpointHit(). + debug_state.__dr6 = 0; + return; +} + +bool +DNBArchImplX86_64::IsWatchpointHit(const DBG &debug_state, uint32_t hw_index) +{ + // Check dr6 (debug status register) whether a watchpoint hits: + // is watchpoint hit? + // | + // v + // dr0 -> bits{0} + // dr1 -> bits{1} + // dr2 -> bits{2} + // dr3 -> bits{3} + return (debug_state.__dr6 & (1 << hw_index)); +} + uint32_t DNBArchImplX86_64::EnableHardwareWatchpoint (nub_addr_t addr, nub_size_t size, bool read, bool write) { Modified: lldb/trunk/tools/debugserver/source/MacOSX/x86_64/DNBArchImplX86_64.h URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/tools/debugserver/source/MacOSX/x86_64/DNBArchImplX86_64.h?rev=138881&r1=138880&r2=138881&view=diff ============================================================================== --- lldb/trunk/tools/debugserver/source/MacOSX/x86_64/DNBArchImplX86_64.h (original) +++ lldb/trunk/tools/debugserver/source/MacOSX/x86_64/DNBArchImplX86_64.h Wed Aug 31 14:05:55 2011 @@ -237,6 +237,8 @@ static void SetWatchpoint(DBG &debug_state, uint32_t hw_index, nub_addr_t addr, nub_size_t size, bool read, bool write); static void ClearWatchpoint(DBG &debug_state, uint32_t hw_index); static bool IsVacantWatchpoint(const DBG &debug_state, uint32_t hw_index); + static void ClearWatchpointHit(DBG &debug_state); + static bool IsWatchpointHit(const DBG &debug_state, uint32_t hw_index); MachThread *m_thread; State m_state; From johnny.chen at apple.com Wed Aug 31 16:19:39 2011 From: johnny.chen at apple.com (Johnny Chen) Date: Wed, 31 Aug 2011 21:19:39 -0000 Subject: [Lldb-commits] [lldb] r138899 - in /lldb/trunk/tools/debugserver/source/MacOSX: i386/DNBArchImplI386.cpp i386/DNBArchImplI386.h x86_64/DNBArchImplX86_64.cpp x86_64/DNBArchImplX86_64.h Message-ID: <20110831211939.7403F2A6C12C@llvm.org> Author: johnny Date: Wed Aug 31 16:19:39 2011 New Revision: 138899 URL: http://llvm.org/viewvc/llvm-project?rev=138899&view=rev Log: Renamed the helper method to ClearWatchpointHits() for clarity of its purpose. Modified: lldb/trunk/tools/debugserver/source/MacOSX/i386/DNBArchImplI386.cpp lldb/trunk/tools/debugserver/source/MacOSX/i386/DNBArchImplI386.h lldb/trunk/tools/debugserver/source/MacOSX/x86_64/DNBArchImplX86_64.cpp lldb/trunk/tools/debugserver/source/MacOSX/x86_64/DNBArchImplX86_64.h Modified: lldb/trunk/tools/debugserver/source/MacOSX/i386/DNBArchImplI386.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/tools/debugserver/source/MacOSX/i386/DNBArchImplI386.cpp?rev=138899&r1=138898&r2=138899&view=diff ============================================================================== --- lldb/trunk/tools/debugserver/source/MacOSX/i386/DNBArchImplI386.cpp (original) +++ lldb/trunk/tools/debugserver/source/MacOSX/i386/DNBArchImplI386.cpp Wed Aug 31 16:19:39 2011 @@ -735,7 +735,7 @@ // Resets local copy of debug status register to wait for the next debug excpetion. void -DNBArchImplI386::ClearWatchpointHit(DBG &debug_state) +DNBArchImplI386::ClearWatchpointHits(DBG &debug_state) { // See also IsWatchpointHit(). debug_state.__dr6 = 0; Modified: lldb/trunk/tools/debugserver/source/MacOSX/i386/DNBArchImplI386.h URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/tools/debugserver/source/MacOSX/i386/DNBArchImplI386.h?rev=138899&r1=138898&r2=138899&view=diff ============================================================================== --- lldb/trunk/tools/debugserver/source/MacOSX/i386/DNBArchImplI386.h (original) +++ lldb/trunk/tools/debugserver/source/MacOSX/i386/DNBArchImplI386.h Wed Aug 31 16:19:39 2011 @@ -230,7 +230,7 @@ static void SetWatchpoint(DBG &debug_state, uint32_t hw_index, nub_addr_t addr, nub_size_t size, bool read, bool write); static void ClearWatchpoint(DBG &debug_state, uint32_t hw_index); static bool IsVacantWatchpoint(const DBG &debug_state, uint32_t hw_index); - static void ClearWatchpointHit(DBG &debug_state); + static void ClearWatchpointHits(DBG &debug_state); static bool IsWatchpointHit(const DBG &debug_state, uint32_t hw_index); MachThread *m_thread; Modified: lldb/trunk/tools/debugserver/source/MacOSX/x86_64/DNBArchImplX86_64.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/tools/debugserver/source/MacOSX/x86_64/DNBArchImplX86_64.cpp?rev=138899&r1=138898&r2=138899&view=diff ============================================================================== --- lldb/trunk/tools/debugserver/source/MacOSX/x86_64/DNBArchImplX86_64.cpp (original) +++ lldb/trunk/tools/debugserver/source/MacOSX/x86_64/DNBArchImplX86_64.cpp Wed Aug 31 16:19:39 2011 @@ -663,7 +663,7 @@ // Resets local copy of debug status register to wait for the next debug excpetion. void -DNBArchImplX86_64::ClearWatchpointHit(DBG &debug_state) +DNBArchImplX86_64::ClearWatchpointHits(DBG &debug_state) { // See also IsWatchpointHit(). debug_state.__dr6 = 0; Modified: lldb/trunk/tools/debugserver/source/MacOSX/x86_64/DNBArchImplX86_64.h URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/tools/debugserver/source/MacOSX/x86_64/DNBArchImplX86_64.h?rev=138899&r1=138898&r2=138899&view=diff ============================================================================== --- lldb/trunk/tools/debugserver/source/MacOSX/x86_64/DNBArchImplX86_64.h (original) +++ lldb/trunk/tools/debugserver/source/MacOSX/x86_64/DNBArchImplX86_64.h Wed Aug 31 16:19:39 2011 @@ -237,7 +237,7 @@ static void SetWatchpoint(DBG &debug_state, uint32_t hw_index, nub_addr_t addr, nub_size_t size, bool read, bool write); static void ClearWatchpoint(DBG &debug_state, uint32_t hw_index); static bool IsVacantWatchpoint(const DBG &debug_state, uint32_t hw_index); - static void ClearWatchpointHit(DBG &debug_state); + static void ClearWatchpointHits(DBG &debug_state); static bool IsWatchpointHit(const DBG &debug_state, uint32_t hw_index); MachThread *m_thread; From johnny.chen at apple.com Wed Aug 31 16:44:56 2011 From: johnny.chen at apple.com (Johnny Chen) Date: Wed, 31 Aug 2011 21:44:56 -0000 Subject: [Lldb-commits] [lldb] r138907 - in /lldb/trunk/tools/debugserver/source/MacOSX: i386/DNBArchImplI386.cpp i386/DNBArchImplI386.h x86_64/DNBArchImplX86_64.cpp x86_64/DNBArchImplX86_64.h Message-ID: <20110831214457.07EB52A6C12C@llvm.org> Author: johnny Date: Wed Aug 31 16:44:56 2011 New Revision: 138907 URL: http://llvm.org/viewvc/llvm-project?rev=138907&view=rev Log: Renaming: from IsVacantWatchpoint() to IsWatchpointVacant(). Modified: lldb/trunk/tools/debugserver/source/MacOSX/i386/DNBArchImplI386.cpp lldb/trunk/tools/debugserver/source/MacOSX/i386/DNBArchImplI386.h lldb/trunk/tools/debugserver/source/MacOSX/x86_64/DNBArchImplX86_64.cpp lldb/trunk/tools/debugserver/source/MacOSX/x86_64/DNBArchImplX86_64.h Modified: lldb/trunk/tools/debugserver/source/MacOSX/i386/DNBArchImplI386.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/tools/debugserver/source/MacOSX/i386/DNBArchImplI386.cpp?rev=138907&r1=138906&r2=138907&view=diff ============================================================================== --- lldb/trunk/tools/debugserver/source/MacOSX/i386/DNBArchImplI386.cpp (original) +++ lldb/trunk/tools/debugserver/source/MacOSX/i386/DNBArchImplI386.cpp Wed Aug 31 16:44:56 2011 @@ -720,7 +720,7 @@ } bool -DNBArchImplI386::IsVacantWatchpoint(const DBG &debug_state, uint32_t hw_index) +DNBArchImplI386::IsWatchpointVacant(const DBG &debug_state, uint32_t hw_index) { // Check dr7 (debug control register) for local/global enable bits: // global enable --. .-- local enable @@ -782,7 +782,7 @@ DBG debug_state = m_state.context.dbg; for (i = 0; i < num_hw_watchpoints; ++i) { - if (IsVacantWatchpoint(debug_state, i)) + if (IsWatchpointVacant(debug_state, i)) break; } @@ -815,7 +815,7 @@ if (kret == KERN_SUCCESS) { DBG debug_state = m_state.context.dbg; - if (hw_index < num_hw_points && !IsVacantWatchpoint(debug_state, hw_index)) + if (hw_index < num_hw_points && !IsWatchpointVacant(debug_state, hw_index)) { // Modify our local copy of the debug state, first. ClearWatchpoint(debug_state, hw_index); Modified: lldb/trunk/tools/debugserver/source/MacOSX/i386/DNBArchImplI386.h URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/tools/debugserver/source/MacOSX/i386/DNBArchImplI386.h?rev=138907&r1=138906&r2=138907&view=diff ============================================================================== --- lldb/trunk/tools/debugserver/source/MacOSX/i386/DNBArchImplI386.h (original) +++ lldb/trunk/tools/debugserver/source/MacOSX/i386/DNBArchImplI386.h Wed Aug 31 16:44:56 2011 @@ -229,7 +229,7 @@ // Helper functions for watchpoint manipulations. static void SetWatchpoint(DBG &debug_state, uint32_t hw_index, nub_addr_t addr, nub_size_t size, bool read, bool write); static void ClearWatchpoint(DBG &debug_state, uint32_t hw_index); - static bool IsVacantWatchpoint(const DBG &debug_state, uint32_t hw_index); + static bool IsWatchpointVacant(const DBG &debug_state, uint32_t hw_index); static void ClearWatchpointHits(DBG &debug_state); static bool IsWatchpointHit(const DBG &debug_state, uint32_t hw_index); Modified: lldb/trunk/tools/debugserver/source/MacOSX/x86_64/DNBArchImplX86_64.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/tools/debugserver/source/MacOSX/x86_64/DNBArchImplX86_64.cpp?rev=138907&r1=138906&r2=138907&view=diff ============================================================================== --- lldb/trunk/tools/debugserver/source/MacOSX/x86_64/DNBArchImplX86_64.cpp (original) +++ lldb/trunk/tools/debugserver/source/MacOSX/x86_64/DNBArchImplX86_64.cpp Wed Aug 31 16:44:56 2011 @@ -648,7 +648,7 @@ } bool -DNBArchImplX86_64::IsVacantWatchpoint(const DBG &debug_state, uint32_t hw_index) +DNBArchImplX86_64::IsWatchpointVacant(const DBG &debug_state, uint32_t hw_index) { // Check dr7 (debug control register) for local/global enable bits: // global enable --. .-- local enable @@ -710,7 +710,7 @@ DBG debug_state = m_state.context.dbg; for (i = 0; i < num_hw_watchpoints; ++i) { - if (IsVacantWatchpoint(debug_state, i)) + if (IsWatchpointVacant(debug_state, i)) break; } @@ -743,7 +743,7 @@ if (kret == KERN_SUCCESS) { DBG debug_state = m_state.context.dbg; - if (hw_index < num_hw_points && !IsVacantWatchpoint(debug_state, hw_index)) + if (hw_index < num_hw_points && !IsWatchpointVacant(debug_state, hw_index)) { // Modify our local copy of the debug state, first. ClearWatchpoint(debug_state, hw_index); Modified: lldb/trunk/tools/debugserver/source/MacOSX/x86_64/DNBArchImplX86_64.h URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/tools/debugserver/source/MacOSX/x86_64/DNBArchImplX86_64.h?rev=138907&r1=138906&r2=138907&view=diff ============================================================================== --- lldb/trunk/tools/debugserver/source/MacOSX/x86_64/DNBArchImplX86_64.h (original) +++ lldb/trunk/tools/debugserver/source/MacOSX/x86_64/DNBArchImplX86_64.h Wed Aug 31 16:44:56 2011 @@ -236,7 +236,7 @@ // Helper functions for watchpoint manipulations. static void SetWatchpoint(DBG &debug_state, uint32_t hw_index, nub_addr_t addr, nub_size_t size, bool read, bool write); static void ClearWatchpoint(DBG &debug_state, uint32_t hw_index); - static bool IsVacantWatchpoint(const DBG &debug_state, uint32_t hw_index); + static bool IsWatchpointVacant(const DBG &debug_state, uint32_t hw_index); static void ClearWatchpointHits(DBG &debug_state); static bool IsWatchpointHit(const DBG &debug_state, uint32_t hw_index); From jingham at apple.com Wed Aug 31 20:11:04 2011 From: jingham at apple.com (Jim Ingham) Date: Thu, 01 Sep 2011 01:11:04 -0000 Subject: [Lldb-commits] [lldb] r138929 - in /lldb/trunk/source/Commands: CommandObjectDisassemble.cpp CommandObjectDisassemble.h Message-ID: <20110901011104.F1D4B2A6C12C@llvm.org> Author: jingham Date: Wed Aug 31 20:11:04 2011 New Revision: 138929 URL: http://llvm.org/viewvc/llvm-project?rev=138929&view=rev Log: disassemble with no arguments disassembles at the pc. Also got "disassemble -f" to work, that had gotten broken at some point in the past. Modified: lldb/trunk/source/Commands/CommandObjectDisassemble.cpp lldb/trunk/source/Commands/CommandObjectDisassemble.h Modified: lldb/trunk/source/Commands/CommandObjectDisassemble.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Commands/CommandObjectDisassemble.cpp?rev=138929&r1=138928&r2=138929&view=diff ============================================================================== --- lldb/trunk/source/Commands/CommandObjectDisassemble.cpp (original) +++ lldb/trunk/source/Commands/CommandObjectDisassemble.cpp Wed Aug 31 20:11:04 2011 @@ -37,12 +37,14 @@ num_lines_context(0), num_instructions (0), func_name(), + cur_function (false), start_addr(), end_addr (), at_pc (false), frame_line (false), plugin_name (), - arch() + arch(), + some_location_specified (false) { OptionParsingStarting(); } @@ -89,6 +91,7 @@ if (start_addr == LLDB_INVALID_ADDRESS) error.SetErrorStringWithFormat ("Invalid start address string '%s'.\n", option_arg); + some_location_specified = true; break; case 'e': end_addr = Args::StringToUInt64(option_arg, LLDB_INVALID_ADDRESS, 0); @@ -98,13 +101,15 @@ if (end_addr == LLDB_INVALID_ADDRESS) error.SetErrorStringWithFormat ("Invalid end address string '%s'.\n", option_arg); break; - + some_location_specified = true; case 'n': func_name.assign (option_arg); + some_location_specified = true; break; case 'p': at_pc = true; + some_location_specified = true; break; case 'l': @@ -112,6 +117,7 @@ // Disassemble the current source line kind of implies showing mixed // source code context. show_mixed = true; + some_location_specified = true; break; case 'P': @@ -123,8 +129,8 @@ break; case 'f': - // The default action is to disassemble the function for the current frame. - // There's no need to set any flag. + cur_function = true; + some_location_specified = true; break; case 'a': @@ -147,6 +153,7 @@ num_lines_context = 0; num_instructions = 0; func_name.clear(); + cur_function = false; at_pc = false; frame_line = false; start_addr = LLDB_INVALID_ADDRESS; @@ -154,6 +161,16 @@ raw = false; plugin_name.clear(); arch.Clear(); + some_location_specified = false; +} + +Error +CommandObjectDisassemble::CommandOptions::OptionParsingFinished () +{ + if (!some_location_specified) + at_pc = true; + return Error(); + } const OptionDefinition* @@ -178,10 +195,10 @@ LLDB_OPT_SET_3 | LLDB_OPT_SET_4 | LLDB_OPT_SET_5 , false , "count", 'c', required_argument , NULL, 0, eArgTypeNumLines, "Number of instructions to display."}, -{ LLDB_OPT_SET_3 , true , "name", 'n', required_argument , NULL, CommandCompletions::eSymbolCompletion, eArgTypeFunctionName, "Disassemble entire contents of the given function name."}, -{ LLDB_OPT_SET_4 , true , "frame", 'f', no_argument , NULL, 0, eArgTypeNone, "Disassemble from the start of the current frame's function."}, -{ LLDB_OPT_SET_5 , true , "pc", 'p', no_argument , NULL, 0, eArgTypeNone, "Disassemble around the current pc."}, -{ LLDB_OPT_SET_6 , true , "line", 'l', no_argument , NULL, 0, eArgTypeNone, "Disassemble the current frame's current source line instructions if there debug line table information, else disasemble around the pc."}, +{ LLDB_OPT_SET_3 , false , "name", 'n', required_argument , NULL, CommandCompletions::eSymbolCompletion, eArgTypeFunctionName, "Disassemble entire contents of the given function name."}, +{ LLDB_OPT_SET_4 , false , "frame", 'f', no_argument , NULL, 0, eArgTypeNone, "Disassemble from the start of the current frame's function."}, +{ LLDB_OPT_SET_5 , false , "pc", 'p', no_argument , NULL, 0, eArgTypeNone, "Disassemble around the current pc."}, +{ LLDB_OPT_SET_6 , false , "line", 'l', no_argument , NULL, 0, eArgTypeNone, "Disassemble the current frame's current source line instructions if there debug line table information, else disasemble around the pc."}, { 0 , false , NULL, 0, 0 , NULL, 0, eArgTypeNone, NULL } }; @@ -299,6 +316,12 @@ AddressRange range; if (m_options.frame_line) { + if (exe_ctx.frame == NULL) + { + result.AppendError ("Cannot disassemble around the current line without a selected frame.\n"); + result.SetStatus (eReturnStatusFailed); + return false; + } LineEntry pc_line_entry (exe_ctx.frame->GetSymbolContext(eSymbolContextLineEntry).line_entry); if (pc_line_entry.IsValid()) { @@ -310,6 +333,18 @@ m_options.show_mixed = false; } } + else if (m_options.cur_function) + { + if (exe_ctx.frame == NULL) + { + result.AppendError ("Cannot disassemble around the current function without a selected frame.\n"); + result.SetStatus (eReturnStatusFailed); + return false; + } + Symbol *symbol = exe_ctx.frame->GetSymbolContext(eSymbolContextSymbol).symbol; + if (symbol) + range = symbol->GetAddressRangeRef(); + } // Did the "m_options.frame_line" find a valid range already? If so // skip the rest... Modified: lldb/trunk/source/Commands/CommandObjectDisassemble.h URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Commands/CommandObjectDisassemble.h?rev=138929&r1=138928&r2=138929&view=diff ============================================================================== --- lldb/trunk/source/Commands/CommandObjectDisassemble.h (original) +++ lldb/trunk/source/Commands/CommandObjectDisassemble.h Wed Aug 31 20:11:04 2011 @@ -52,6 +52,8 @@ return plugin_name.c_str(); } + virtual Error + OptionParsingFinished (); bool show_mixed; // Show mixed source/assembly bool show_bytes; @@ -59,12 +61,15 @@ uint32_t num_instructions; bool raw; std::string func_name; + bool cur_function; lldb::addr_t start_addr; lldb::addr_t end_addr; bool at_pc; bool frame_line; std::string plugin_name; ArchSpec arch; + bool some_location_specified; // If no location was specified, we'll select "at_pc". This should be set + // in SetOptionValue if anything the selects a location is set. static OptionDefinition g_option_table[]; }; From gclayton at apple.com Thu Sep 1 13:10:09 2011 From: gclayton at apple.com (Greg Clayton) Date: Thu, 01 Sep 2011 18:10:09 -0000 Subject: [Lldb-commits] [lldb] r138949 - in /lldb/trunk: include/lldb/Core/DataEncoder.h lldb.xcodeproj/project.pbxproj source/Core/DataEncoder.cpp Message-ID: <20110901181009.8FBAC2A6C12C@llvm.org> Author: gclayton Date: Thu Sep 1 13:10:09 2011 New Revision: 138949 URL: http://llvm.org/viewvc/llvm-project?rev=138949&view=rev Log: Added a DataEncoder class for the new IR evaluation expression parser so it can reserve a block of memory and store stuff into it. Added: lldb/trunk/include/lldb/Core/DataEncoder.h lldb/trunk/source/Core/DataEncoder.cpp Modified: lldb/trunk/lldb.xcodeproj/project.pbxproj Added: lldb/trunk/include/lldb/Core/DataEncoder.h URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Core/DataEncoder.h?rev=138949&view=auto ============================================================================== --- lldb/trunk/include/lldb/Core/DataEncoder.h (added) +++ lldb/trunk/include/lldb/Core/DataEncoder.h Thu Sep 1 13:10:09 2011 @@ -0,0 +1,447 @@ +//===-- DataEncoder.h -------------------------------------------*- C++ -*-===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +#ifndef liblldb_DataEncoder_h_ +#define liblldb_DataEncoder_h_ + +#if defined (__cplusplus) + +#include "lldb/lldb-private.h" +#include +#include + +namespace lldb_private { + +//---------------------------------------------------------------------- +/// @class DataEncoder DataEncoder.h "lldb/Core/DataEncoder.h" +/// @brief An binary data encoding class. +/// +/// DataEncoder is a class that can encode binary data (swapping if needed) +/// to a data buffer. The data buffer can be caller owned, or can be +/// shared data that can be shared between multiple DataEncoder or +/// DataEncoder instances. +/// +/// @see DataBuffer +//---------------------------------------------------------------------- +class DataEncoder +{ +public: + //------------------------------------------------------------------ + /// Default constructor. + /// + /// Initialize all members to a default empty state. + //------------------------------------------------------------------ + DataEncoder (); + + //------------------------------------------------------------------ + /// Construct with a buffer that is owned by the caller. + /// + /// This constructor allows us to use data that is owned by the + /// caller. The data must stay around as long as this object is + /// valid. + /// + /// @param[in] data + /// A pointer to caller owned data. + /// + /// @param[in] data_length + /// The length in bytes of \a data. + /// + /// @param[in] byte_order + /// A byte order of the data that we are extracting from. + /// + /// @param[in] addr_size + /// A new address byte size value. + //------------------------------------------------------------------ + DataEncoder (void* data, uint32_t data_length, lldb::ByteOrder byte_order, uint8_t addr_size); + + //------------------------------------------------------------------ + /// Construct with shared data. + /// + /// Copies the data shared pointer which adds a reference to the + /// contained in \a data_sp. The shared data reference is reference + /// counted to ensure the data lives as long as anyone still has a + /// valid shared pointer to the data in \a data_sp. + /// + /// @param[in] data_sp + /// A shared pointer to data. + /// + /// @param[in] byte_order + /// A byte order of the data that we are extracting from. + /// + /// @param[in] addr_size + /// A new address byte size value. + //------------------------------------------------------------------ + DataEncoder (const lldb::DataBufferSP& data_sp, lldb::ByteOrder byte_order, uint8_t addr_size); + + //------------------------------------------------------------------ + /// Destructor + /// + /// If this object contains a valid shared data reference, the + /// reference count on the data will be decremented, and if zero, + /// the data will be freed. + //------------------------------------------------------------------ + ~DataEncoder (); + + //------------------------------------------------------------------ + /// Clears the object state. + /// + /// Clears the object contents back to a default invalid state, and + /// release any references to shared data that this object may + /// contain. + //------------------------------------------------------------------ + void + Clear (); + + //------------------------------------------------------------------ + /// Get the current address size. + /// + /// Return the size in bytes of any address values this object will + /// extract. + /// + /// @return + /// The size in bytes of address values that will be extracted. + //------------------------------------------------------------------ + uint8_t + GetAddressByteSize () const + { + return m_addr_size; + } + + + //------------------------------------------------------------------ + /// Get the number of bytes contained in this object. + /// + /// @return + /// The total number of bytes of data this object refers to. + //------------------------------------------------------------------ + size_t + GetByteSize () const + { + return m_end - m_start; + } + + //------------------------------------------------------------------ + /// Get the data end pointer. + /// + /// @return + /// Returns a pointer to the next byte contained in this + /// object's data, or NULL of there is no data in this object. + //------------------------------------------------------------------ + uint8_t * + GetDataEnd () + { + return m_end; + } + + const uint8_t * + GetDataEnd () const + { + return m_end; + } + + //------------------------------------------------------------------ + /// Get the shared data offset. + /// + /// Get the offset of the first byte of data in the shared data (if + /// any). + /// + /// @return + /// If this object contains shared data, this function returns + /// the offset in bytes into that shared data, zero otherwise. + //------------------------------------------------------------------ + size_t + GetSharedDataOffset () const; + + + //------------------------------------------------------------------ + /// Get the current byte order value. + /// + /// @return + /// The current byte order value from this object's internal + /// state. + //------------------------------------------------------------------ + lldb::ByteOrder + GetByteOrder() const + { + return m_byte_order; + } + + //------------------------------------------------------------------ + /// Get a the data start pointer. + /// + /// @return + /// Returns a pointer to the first byte contained in this + /// object's data, or NULL of there is no data in this object. + //------------------------------------------------------------------ + uint8_t * + GetDataStart () + { + return m_start; + } + + const uint8_t * + GetDataStart () const + { + return m_start; + } + + //------------------------------------------------------------------ + /// Encode unsigned integer values into the data at \a offset. + /// + /// @param[in] offset + /// The offset within the contained data at which to put the + /// data. + /// + /// @param[in] value + /// The value to encode into the data. + /// + /// @return + /// The next offset in the bytes of this data if the data + /// was successfully encoded, UINT32_MAX if the encoding failed. + //------------------------------------------------------------------ + uint32_t + PutU8 (uint32_t offset, uint8_t value); + + uint32_t + PutU16 (uint32_t offset, uint16_t value); + + uint32_t + PutU32 (uint32_t offset, uint32_t value); + + uint32_t + PutU64 (uint32_t offset, uint64_t value); + + //------------------------------------------------------------------ + /// Encode an unsigned integer of size \a byte_size to \a offset. + /// + /// Encode a single integer value at \a offset and return the offset + /// that follows the newly encoded integer when the data is successfully + /// encoded into the existing data. There must be enough room in the + /// data, else UINT32_MAX will be returned to indicate that encoding + /// failed. + /// + /// @param[in] offset + /// The offset within the contained data at which to put the + /// encoded integer. + /// + /// @param[in] byte_size + /// The size in byte of the integer to encode. + /// + /// @param[in] value + /// The integer value to write. The least significate bytes of + /// the integer value will be written if the size is less than + /// 8 bytes. + /// + /// @return + /// The next offset in the bytes of this data if the integer + /// was successfully encoded, UINT32_MAX if the encoding failed. + //------------------------------------------------------------------ + uint32_t + PutMaxU64 (uint32_t offset, uint32_t byte_size, uint64_t value); + + //------------------------------------------------------------------ + /// Encode an arbitrary number of bytes. + /// + /// @param[in] offset + /// The offset in bytes into the contained data at which to + /// start encoding. + /// + /// @param[int] src + /// The buffer that contains the the bytes to encode. + /// + /// @param[in] src_len + /// The number of bytes to encode. + /// + /// @return + /// The next valid offset within data if the put operation + /// was successful, else UINT32_MAX to indicate the put failed. + //------------------------------------------------------------------ + uint32_t + PutData (uint32_t offset, + const void *src, + uint32_t src_len); + + //------------------------------------------------------------------ + /// Encode an address in the existing buffer at \a offset bytes into + /// the buffer. + /// + /// Encode a single address (honoring the m_addr_size member) to + /// the data and return the next offset where subsequent data would + /// go. + /// pointed to by \a offset_ptr. The size of the extracted address + /// comes from the \a m_addr_size member variable and should be + /// set correctly prior to extracting any address values. + /// + /// @param[in,out] offset_ptr + /// A pointer to an offset within the data that will be advanced + /// by the appropriate number of bytes if the value is extracted + /// correctly. If the offset is out of bounds or there are not + /// enough bytes to extract this value, the offset will be left + /// unmodified. + /// + /// @return + /// The next valid offset within data if the put operation + /// was successful, else UINT32_MAX to indicate the put failed. + //------------------------------------------------------------------ + uint32_t + PutAddress (uint32_t offset, lldb::addr_t addr); + + //------------------------------------------------------------------ + /// Put a C string to \a offset. + /// + /// Encodes a C string into the existing data including the + /// terminating + /// + /// @param[in,out] offset_ptr + /// A pointer to an offset within the data that will be advanced + /// by the appropriate number of bytes if the value is extracted + /// correctly. If the offset is out of bounds or there are not + /// enough bytes to extract this value, the offset will be left + /// unmodified. + /// + /// @return + /// A pointer to the C string value in the data. If the offset + /// pointed to by \a offset_ptr is out of bounds, or if the + /// offset plus the length of the C string is out of bounds, + /// NULL will be returned. + //------------------------------------------------------------------ + uint32_t + PutCString (uint32_t offset_ptr, const char *cstr); + + lldb::DataBufferSP & + GetSharedDataBuffer () + { + return m_data_sp; + } + + //------------------------------------------------------------------ + /// Set the address byte size. + /// + /// Set the size in bytes that will be used when extracting any + /// address and pointer values from data contained in this object. + /// + /// @param[in] addr_size + /// The size in bytes to use when extracting addresses. + //------------------------------------------------------------------ + void + SetAddressByteSize (uint8_t addr_size) + { + m_addr_size = addr_size; + } + + //------------------------------------------------------------------ + /// Set data with a buffer that is caller owned. + /// + /// Use data that is owned by the caller when extracting values. + /// The data must stay around as long as this object, or any object + /// that copies a subset of this object's data, is valid. If \a + /// bytes is NULL, or \a length is zero, this object will contain + /// no data. + /// + /// @param[in] bytes + /// A pointer to caller owned data. + /// + /// @param[in] length + /// The length in bytes of \a bytes. + /// + /// @param[in] byte_order + /// A byte order of the data that we are extracting from. + /// + /// @return + /// The number of bytes that this object now contains. + //------------------------------------------------------------------ + uint32_t + SetData (const void *bytes, uint32_t length, lldb::ByteOrder byte_order); + + //------------------------------------------------------------------ + /// Adopt a subset of shared data in \a data_sp. + /// + /// Copies the data shared pointer which adds a reference to the + /// contained in \a data_sp. The shared data reference is reference + /// counted to ensure the data lives as long as anyone still has a + /// valid shared pointer to the data in \a data_sp. The byte order + /// and address byte size settings remain the same. If + /// \a offset is not a valid offset in \a data_sp, then no reference + /// to the shared data will be added. If there are not \a length + /// bytes available in \a data starting at \a offset, the length + /// will be truncated to contains as many bytes as possible. + /// + /// @param[in] data_sp + /// A shared pointer to data. + /// + /// @param[in] offset + /// The offset into \a data_sp at which the subset starts. + /// + /// @param[in] length + /// The length in bytes of the subset of \a data_sp. + /// + /// @return + /// The number of bytes that this object now contains. + //------------------------------------------------------------------ + uint32_t + SetData (const lldb::DataBufferSP& data_sp, uint32_t offset = 0, uint32_t length = UINT32_MAX); + + //------------------------------------------------------------------ + /// Set the byte_order value. + /// + /// Sets the byte order of the data to extract. Extracted values + /// will be swapped if necessary when decoding. + /// + /// @param[in] byte_order + /// The byte order value to use when extracting data. + //------------------------------------------------------------------ + void + SetByteOrder (lldb::ByteOrder byte_order) + { + m_byte_order = byte_order; + } + + + //------------------------------------------------------------------ + /// Test the validity of \a offset. + /// + /// @return + /// \b true if \a offset is a valid offset into the data in this + /// object, \b false otherwise. + //------------------------------------------------------------------ + bool + ValidOffset (uint32_t offset) const + { + return offset < GetByteSize(); + } + + //------------------------------------------------------------------ + /// Test the availability of \a length bytes of data from \a offset. + /// + /// @return + /// \b true if \a offset is a valid offset and there are \a + /// length bytes available at that offset, \b false otherwise. + //------------------------------------------------------------------ + bool + ValidOffsetForDataOfSize (uint32_t offset, uint32_t length) const; + +protected: + //------------------------------------------------------------------ + // Member variables + //------------------------------------------------------------------ + uint8_t *m_start; ///< A pointer to the first byte of data. + uint8_t *m_end; ///< A pointer to the byte that is past the end of the data. + lldb::ByteOrder m_byte_order; ///< The byte order of the data we are extracting from. + uint8_t m_addr_size; ///< The address size to use when extracting pointers or addresses + mutable lldb::DataBufferSP m_data_sp; ///< The shared pointer to data that can be shared among multilple instances + +private: + DISALLOW_COPY_AND_ASSIGN (DataEncoder); + +}; + +} // namespace lldb_private + +#endif // #if defined (__cplusplus) +#endif // #ifndef liblldb_DataEncoder_h_ Modified: lldb/trunk/lldb.xcodeproj/project.pbxproj URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/lldb.xcodeproj/project.pbxproj?rev=138949&r1=138948&r2=138949&view=diff ============================================================================== --- lldb/trunk/lldb.xcodeproj/project.pbxproj (original) +++ lldb/trunk/lldb.xcodeproj/project.pbxproj Thu Sep 1 13:10:09 2011 @@ -330,6 +330,7 @@ 2689FFFB13353DB600698AC0 /* BreakpointLocationList.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 26BC7E1010F1B83100F91463 /* BreakpointLocationList.cpp */; }; 2689FFFD13353DB600698AC0 /* BreakpointOptions.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 26BC7E1110F1B83100F91463 /* BreakpointOptions.cpp */; }; 2689FFFF13353DB600698AC0 /* BreakpointResolver.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 26BC7E1210F1B83100F91463 /* BreakpointResolver.cpp */; }; + 268ED0A5140FF54200DE830F /* DataEncoder.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 268ED0A4140FF54200DE830F /* DataEncoder.cpp */; }; 268F9D53123AA15200B91E9B /* SBSymbolContextList.h in Headers */ = {isa = PBXBuildFile; fileRef = 268F9D52123AA15200B91E9B /* SBSymbolContextList.h */; settings = {ATTRIBUTES = (Public, ); }; }; 268F9D55123AA16600B91E9B /* SBSymbolContextList.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 268F9D54123AA16600B91E9B /* SBSymbolContextList.cpp */; }; 2690B3711381D5C300ECFBAE /* Memory.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 2690B3701381D5C300ECFBAE /* Memory.cpp */; }; @@ -703,6 +704,8 @@ 268A813F115B19D000F645B0 /* UniqueCStringMap.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = UniqueCStringMap.h; path = include/lldb/Core/UniqueCStringMap.h; sourceTree = ""; }; 268DA871130095D000C9483A /* Terminal.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = Terminal.h; path = include/lldb/Host/Terminal.h; sourceTree = ""; }; 268DA873130095ED00C9483A /* Terminal.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = Terminal.cpp; sourceTree = ""; }; + 268ED0A2140FF52F00DE830F /* DataEncoder.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = DataEncoder.h; path = include/lldb/Core/DataEncoder.h; sourceTree = ""; }; + 268ED0A4140FF54200DE830F /* DataEncoder.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = DataEncoder.cpp; path = source/Core/DataEncoder.cpp; sourceTree = ""; }; 268F9D52123AA15200B91E9B /* SBSymbolContextList.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = SBSymbolContextList.h; path = include/lldb/API/SBSymbolContextList.h; sourceTree = ""; }; 268F9D54123AA16600B91E9B /* SBSymbolContextList.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = SBSymbolContextList.cpp; path = source/API/SBSymbolContextList.cpp; sourceTree = ""; }; 2690B36F1381D5B600ECFBAE /* Memory.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = Memory.h; path = include/lldb/Target/Memory.h; sourceTree = ""; }; @@ -1927,6 +1930,8 @@ 26BC7E7210F1B85900F91463 /* DataBufferHeap.cpp */, 26BC7D5C10F1B77400F91463 /* DataBufferMemoryMap.h */, 26BC7E7310F1B85900F91463 /* DataBufferMemoryMap.cpp */, + 268ED0A2140FF52F00DE830F /* DataEncoder.h */, + 268ED0A4140FF54200DE830F /* DataEncoder.cpp */, 26BC7D5A10F1B77400F91463 /* DataExtractor.h */, 26BC7E7110F1B85900F91463 /* DataExtractor.cpp */, 9470A8EE1402DF940056FF61 /* DataVisualization.h */, @@ -3302,6 +3307,7 @@ 9470A8F01402DFFB0056FF61 /* DataVisualization.cpp in Sources */, 26274FA214030EEF006BA130 /* OperatingSystemDarwinKernel.cpp in Sources */, 26274FA714030F79006BA130 /* DynamicLoaderDarwinKernel.cpp in Sources */, + 268ED0A5140FF54200DE830F /* DataEncoder.cpp in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; Added: lldb/trunk/source/Core/DataEncoder.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Core/DataEncoder.cpp?rev=138949&view=auto ============================================================================== --- lldb/trunk/source/Core/DataEncoder.cpp (added) +++ lldb/trunk/source/Core/DataEncoder.cpp Thu Sep 1 13:10:09 2011 @@ -0,0 +1,361 @@ +//===-- DataEncoder.cpp ---------------------------------------*- C++ -*-===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +#include "lldb/Core/DataEncoder.h" + +#include +#include + +#include "llvm/Support/MathExtras.h" + +#include "lldb/Core/DataBuffer.h" +#include "lldb/Host/Endian.h" + +using namespace lldb; +using namespace lldb_private; + +static inline void +WriteInt16(const unsigned char* ptr, unsigned offset, uint16_t value) +{ + *(uint16_t *)(ptr + offset) = value; +} +static inline void +WriteInt32 (const unsigned char* ptr, unsigned offset, uint32_t value) +{ + *(uint32_t *)(ptr + offset) = value; +} + +static inline void +WriteInt64(const unsigned char* ptr, unsigned offset, uint64_t value) +{ + *(uint64_t *)(ptr + offset) = value; +} + +static inline void +WriteSwappedInt16(const unsigned char* ptr, unsigned offset, uint16_t value) +{ + *(uint16_t *)(ptr + offset) = llvm::ByteSwap_16(value); +} + +static inline void +WriteSwappedInt32 (const unsigned char* ptr, unsigned offset, uint32_t value) +{ + *(uint32_t *)(ptr + offset) = llvm::ByteSwap_32(value); +} + +static inline void +WriteSwappedInt64(const unsigned char* ptr, unsigned offset, uint64_t value) +{ + *(uint64_t *)(ptr + offset) = llvm::ByteSwap_64(value); +} + +//---------------------------------------------------------------------- +// Default constructor. +//---------------------------------------------------------------------- +DataEncoder::DataEncoder () : + m_start (NULL), + m_end (NULL), + m_byte_order(lldb::endian::InlHostByteOrder()), + m_addr_size (sizeof(void*)), + m_data_sp () +{ +} + +//---------------------------------------------------------------------- +// This constructor allows us to use data that is owned by someone else. +// The data must stay around as long as this object is valid. +//---------------------------------------------------------------------- +DataEncoder::DataEncoder (void* data, uint32_t length, ByteOrder endian, uint8_t addr_size) : + m_start ((uint8_t*)data), + m_end ((uint8_t*)data + length), + m_byte_order(endian), + m_addr_size (addr_size), + m_data_sp () +{ +} + +//---------------------------------------------------------------------- +// Make a shared pointer reference to the shared data in "data_sp" and +// set the endian swapping setting to "swap", and the address size to +// "addr_size". The shared data reference will ensure the data lives +// as long as any DataEncoder objects exist that have a reference to +// this data. +//---------------------------------------------------------------------- +DataEncoder::DataEncoder (const DataBufferSP& data_sp, ByteOrder endian, uint8_t addr_size) : + m_start (NULL), + m_end (NULL), + m_byte_order(endian), + m_addr_size (addr_size), + m_data_sp () +{ + SetData (data_sp); +} + +//---------------------------------------------------------------------- +// Destructor +//---------------------------------------------------------------------- +DataEncoder::~DataEncoder () +{ +} + +//------------------------------------------------------------------ +// Clears the object contents back to a default invalid state, and +// release any references to shared data that this object may +// contain. +//------------------------------------------------------------------ +void +DataEncoder::Clear () +{ + m_start = NULL; + m_end = NULL; + m_byte_order = lldb::endian::InlHostByteOrder(); + m_addr_size = sizeof(void*); + m_data_sp.reset(); +} + +//------------------------------------------------------------------ +// If this object contains shared data, this function returns the +// offset into that shared data. Else zero is returned. +//------------------------------------------------------------------ +size_t +DataEncoder::GetSharedDataOffset () const +{ + if (m_start != NULL) + { + const DataBuffer * data = m_data_sp.get(); + if (data != NULL) + { + const uint8_t * data_bytes = data->GetBytes(); + if (data_bytes != NULL) + { + assert(m_start >= data_bytes); + return m_start - data_bytes; + } + } + } + return 0; +} + +//------------------------------------------------------------------ +// Returns true if there are LENGTH bytes availabe starting OFFSET +// into the data that is in this object. +//------------------------------------------------------------------ +bool +DataEncoder::ValidOffsetForDataOfSize (uint32_t offset, uint32_t length) const +{ + size_t size = GetByteSize(); + if (offset >= size) + return false; // offset isn't valid + + if (length == 0) + return true; // No bytes requested at this offset, return true + + // If we flip the bits in offset we can figure out how + // many bytes we have left before "offset + length" + // could overflow when doing unsigned arithmetic. + if (length > ~offset) + return false; // unsigned overflow + + // Make sure "offset + length" is a valid offset as well. + // length must be greater than zero for this to be a + // valid expression, and we have already checked for this. + return ((offset + length) <= size); +} + +//---------------------------------------------------------------------- +// Set the data with which this object will extract from to data +// starting at BYTES and set the length of the data to LENGTH bytes +// long. The data is externally owned must be around at least as +// long as this object points to the data. No copy of the data is +// made, this object just refers to this data and can extract from +// it. If this object refers to any shared data upon entry, the +// reference to that data will be released. Is SWAP is set to true, +// any data extracted will be endian swapped. +//---------------------------------------------------------------------- +uint32_t +DataEncoder::SetData (const void *bytes, uint32_t length, ByteOrder endian) +{ + m_byte_order = endian; + m_data_sp.reset(); + if (bytes == NULL || length == 0) + { + m_start = NULL; + m_end = NULL; + } + else + { + m_start = (uint8_t *)bytes; + m_end = m_start + length; + } + return GetByteSize(); +} + +//---------------------------------------------------------------------- +// Assign the data for this object to be a subrange of the shared +// data in "data_sp" starting "data_offset" bytes into "data_sp" +// and ending "data_length" bytes later. If "data_offset" is not +// a valid offset into "data_sp", then this object will contain no +// bytes. If "data_offset" is within "data_sp" yet "data_length" is +// too large, the length will be capped at the number of bytes +// remaining in "data_sp". A ref counted pointer to the data in +// "data_sp" will be made in this object IF the number of bytes this +// object refers to in greater than zero (if at least one byte was +// available starting at "data_offset") to ensure the data stays +// around as long as it is needed. The address size and endian swap +// settings will remain unchanged from their current settings. +//---------------------------------------------------------------------- +uint32_t +DataEncoder::SetData (const DataBufferSP& data_sp, uint32_t data_offset, uint32_t data_length) +{ + m_start = m_end = NULL; + + if (data_length > 0) + { + m_data_sp = data_sp; + if (data_sp.get()) + { + const size_t data_size = data_sp->GetByteSize(); + if (data_offset < data_size) + { + m_start = data_sp->GetBytes() + data_offset; + const size_t bytes_left = data_size - data_offset; + // Cap the length of we asked for too many + if (data_length <= bytes_left) + m_end = m_start + data_length; // We got all the bytes we wanted + else + m_end = m_start + bytes_left; // Not all the bytes requested were available in the shared data + } + } + } + + uint32_t new_size = GetByteSize(); + + // Don't hold a shared pointer to the data buffer if we don't share + // any valid bytes in the shared buffer. + if (new_size == 0) + m_data_sp.reset(); + + return new_size; +} + +//---------------------------------------------------------------------- +// Extract a single unsigned char from the binary data and update +// the offset pointed to by "offset_ptr". +// +// RETURNS the byte that was extracted, or zero on failure. +//---------------------------------------------------------------------- +uint32_t +DataEncoder::PutU8 (uint32_t offset, uint8_t value) +{ + if (ValidOffset(offset)) + { + m_start[offset] = value; + return offset + 1; + } + return UINT32_MAX; +} + +uint32_t +DataEncoder::PutU16 (uint32_t offset, uint16_t value) +{ + if (ValidOffsetForDataOfSize(offset, sizeof(value))) + { + if (m_byte_order != lldb::endian::InlHostByteOrder()) + WriteSwappedInt16 (m_start, offset, value); + else + WriteInt16 (m_start, offset, value); + + return offset + sizeof (value); + } + return UINT32_MAX; +} + +uint32_t +DataEncoder::PutU32 (uint32_t offset, uint32_t value) +{ + if (ValidOffsetForDataOfSize(offset, sizeof(value))) + { + if (m_byte_order != lldb::endian::InlHostByteOrder()) + WriteSwappedInt32 (m_start, offset, value); + else + WriteInt32 (m_start, offset, value); + + return offset + sizeof (value); + } + return UINT32_MAX; +} + +uint32_t +DataEncoder::PutU64 (uint32_t offset, uint64_t value) +{ + if (ValidOffsetForDataOfSize(offset, sizeof(value))) + { + if (m_byte_order != lldb::endian::InlHostByteOrder()) + WriteSwappedInt64 (m_start, offset, value); + else + WriteInt64 (m_start, offset, value); + + return offset + sizeof (value); + } + return UINT32_MAX; +} + +//---------------------------------------------------------------------- +// Extract a single integer value from the data and update the offset +// pointed to by "offset_ptr". The size of the extracted integer +// is specified by the "byte_size" argument. "byte_size" should have +// a value >= 1 and <= 8 since the return value is only 64 bits +// wide. Any "byte_size" values less than 1 or greater than 8 will +// result in nothing being extracted, and zero being returned. +// +// RETURNS the integer value that was extracted, or zero on failure. +//---------------------------------------------------------------------- +uint32_t +DataEncoder::PutMaxU64 (uint32_t offset, uint32_t byte_size, uint64_t value) +{ + switch (byte_size) + { + case 1: return PutU8 (offset, value); + case 2: return PutU16(offset, value); + case 4: return PutU32(offset, value); + case 8: return PutU64(offset, value); + default: + assert(!"GetMax64 unhandled case!"); + break; + } + return UINT32_MAX; +} + +uint32_t +DataEncoder::PutData (uint32_t offset, const void *src, uint32_t src_len) +{ + if (src == NULL || src_len == 0) + return offset; + + if (ValidOffsetForDataOfSize(offset, src_len)) + { + memcpy (m_start + offset, src, src_len); + return offset + src_len; + } + return UINT32_MAX; +} + +uint32_t +DataEncoder::PutAddress (uint32_t offset, lldb::addr_t addr) +{ + return PutMaxU64 (offset, GetAddressByteSize(), addr); +} + +uint32_t +DataEncoder::PutCString (uint32_t offset, const char *cstr) +{ + if (cstr) + return PutData (offset, cstr, strlen(cstr)); + return UINT32_MAX; +} From gclayton at apple.com Thu Sep 1 13:13:54 2011 From: gclayton at apple.com (Greg Clayton) Date: Thu, 01 Sep 2011 18:13:54 -0000 Subject: [Lldb-commits] [lldb] r138950 - in /lldb/trunk: include/lldb/lldb-forward.h source/Core/DataEncoder.cpp Message-ID: <20110901181354.A292F2A6C12C@llvm.org> Author: gclayton Date: Thu Sep 1 13:13:54 2011 New Revision: 138950 URL: http://llvm.org/viewvc/llvm-project?rev=138950&view=rev Log: Forgot to write out the NULL terminator when putting C string value into a data using DataEncoder. Added DataEncoder to the lldb-forward.h file. Modified: lldb/trunk/include/lldb/lldb-forward.h lldb/trunk/source/Core/DataEncoder.cpp Modified: lldb/trunk/include/lldb/lldb-forward.h URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/lldb-forward.h?rev=138950&r1=138949&r2=138950&view=diff ============================================================================== --- lldb/trunk/include/lldb/lldb-forward.h (original) +++ lldb/trunk/include/lldb/lldb-forward.h Thu Sep 1 13:13:54 2011 @@ -62,6 +62,7 @@ class DWARFCallFrameInfo; class DWARFExpression; class DataBuffer; +class DataEncoder; class DataExtractor; class Debugger; class Declaration; Modified: lldb/trunk/source/Core/DataEncoder.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Core/DataEncoder.cpp?rev=138950&r1=138949&r2=138950&view=diff ============================================================================== --- lldb/trunk/source/Core/DataEncoder.cpp (original) +++ lldb/trunk/source/Core/DataEncoder.cpp Thu Sep 1 13:13:54 2011 @@ -356,6 +356,6 @@ DataEncoder::PutCString (uint32_t offset, const char *cstr) { if (cstr) - return PutData (offset, cstr, strlen(cstr)); + return PutData (offset, cstr, strlen(cstr) + 1); return UINT32_MAX; } From gclayton at apple.com Thu Sep 1 18:16:13 2011 From: gclayton at apple.com (Greg Clayton) Date: Thu, 01 Sep 2011 23:16:13 -0000 Subject: [Lldb-commits] [lldb] r138979 - in /lldb/trunk: include/lldb/lldb-enumerations.h lldb.xcodeproj/project.pbxproj source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp source/Plugins/SymbolFile/DWARF/NameToDIE.cpp source/Plugins/SymbolFile/DWARF/NameToDIE.h source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.h source/Symbol/ObjectFile.cpp source/lldb.cpp Message-ID: <20110901231613.4CDA52A6C12E@llvm.org> Author: gclayton Date: Thu Sep 1 18:16:13 2011 New Revision: 138979 URL: http://llvm.org/viewvc/llvm-project?rev=138979&view=rev Log: Added support for accessing and loading our new .debug_names and .debug_types DWARF accelerator table sections to the DWARF parser. These sections are similar to the .debug_pubnames and .debug_pubtypes, but they are designed to be hash tables that are saved to disc in a way that the sections can just be loaded into memory and used without any work on the debugger side. The .debug_pubnames and .debug_pubtypes sections are not ordered, contain a copy of the name in the section itself which makes these sections quite large, they only include publicly exported names (so no static functions, no types defined inside functions), many compilers put different information in them making them very unreliable so most debugger ignore these sections and parse the DWARF on their own. The tables must also be parsed and sorted in order to be used effectively. The new sections can be quickly loaded and very efficiently be used to do name to DIE lookups with very little up front work. The format of these new sections will be changing while we work out the bugs, but we hope to have really fast name to DIE lookups soon. Modified: lldb/trunk/include/lldb/lldb-enumerations.h lldb/trunk/lldb.xcodeproj/project.pbxproj lldb/trunk/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp lldb/trunk/source/Plugins/SymbolFile/DWARF/NameToDIE.cpp lldb/trunk/source/Plugins/SymbolFile/DWARF/NameToDIE.h lldb/trunk/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp lldb/trunk/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.h lldb/trunk/source/Symbol/ObjectFile.cpp lldb/trunk/source/lldb.cpp Modified: lldb/trunk/include/lldb/lldb-enumerations.h URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/lldb-enumerations.h?rev=138979&r1=138978&r2=138979&view=diff ============================================================================== --- lldb/trunk/include/lldb/lldb-enumerations.h (original) +++ lldb/trunk/include/lldb/lldb-enumerations.h Thu Sep 1 18:16:13 2011 @@ -468,6 +468,8 @@ eSectionTypeDWARFDebugPubTypes, eSectionTypeDWARFDebugRanges, eSectionTypeDWARFDebugStr, + eSectionTypeDWARFDebugNames, + eSectionTypeDWARFDebugTypes, eSectionTypeEHFrame, eSectionTypeOther Modified: lldb/trunk/lldb.xcodeproj/project.pbxproj URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/lldb.xcodeproj/project.pbxproj?rev=138979&r1=138978&r2=138979&view=diff ============================================================================== --- lldb/trunk/lldb.xcodeproj/project.pbxproj (original) +++ lldb/trunk/lldb.xcodeproj/project.pbxproj Thu Sep 1 18:16:13 2011 @@ -340,6 +340,7 @@ 26957D9A13D381C900670048 /* RegisterContextDarwin_i386.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 26957D9413D381C900670048 /* RegisterContextDarwin_i386.cpp */; }; 26957D9C13D381C900670048 /* RegisterContextDarwin_x86_64.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 26957D9613D381C900670048 /* RegisterContextDarwin_x86_64.cpp */; }; 2697A54D133A6305004E4240 /* PlatformDarwin.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 2697A54B133A6305004E4240 /* PlatformDarwin.cpp */; }; + 26A0DA4E140F7226006DA411 /* HashedNameToDIE.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 26A0DA4C140F721D006DA411 /* HashedNameToDIE.cpp */; }; 26A69C5F137A17A500262477 /* RegisterValue.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 26C6886E137880C400407EDF /* RegisterValue.cpp */; }; 26A7A035135E6E4200FB369E /* NamedOptionValue.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 26A7A034135E6E4200FB369E /* NamedOptionValue.cpp */; }; 26B1FA1413380E61002886E2 /* LLDBWrapPython.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 26A4EEB511682AAC007A372A /* LLDBWrapPython.cpp */; }; @@ -729,6 +730,8 @@ 269FF08112494FC200225026 /* UnwindTable.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = UnwindTable.h; path = include/lldb/Symbol/UnwindTable.h; sourceTree = ""; }; 26A0604711A5BC7A00F75969 /* Baton.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = Baton.h; path = include/lldb/Core/Baton.h; sourceTree = ""; }; 26A0604811A5D03C00F75969 /* Baton.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = Baton.cpp; path = source/Core/Baton.cpp; sourceTree = ""; }; + 26A0DA4C140F721D006DA411 /* HashedNameToDIE.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = HashedNameToDIE.cpp; sourceTree = ""; }; + 26A0DA4D140F721D006DA411 /* HashedNameToDIE.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = HashedNameToDIE.h; sourceTree = ""; }; 26A3B4AC1181454800381BC2 /* ObjectContainerBSDArchive.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ObjectContainerBSDArchive.cpp; sourceTree = ""; }; 26A3B4AD1181454800381BC2 /* ObjectContainerBSDArchive.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ObjectContainerBSDArchive.h; sourceTree = ""; }; 26A4EEB511682AAC007A372A /* LLDBWrapPython.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; lineEnding = 0; name = LLDBWrapPython.cpp; path = source/LLDBWrapPython.cpp; sourceTree = ""; xcLanguageSpecificationIdentifier = xcode.lang.cpp; }; @@ -1559,6 +1562,8 @@ 260C89D610F57C5600BB2B04 /* DWARFLocationDescription.h */, 260C89D710F57C5600BB2B04 /* DWARFLocationList.cpp */, 260C89D810F57C5600BB2B04 /* DWARFLocationList.h */, + 26A0DA4C140F721D006DA411 /* HashedNameToDIE.cpp */, + 26A0DA4D140F721D006DA411 /* HashedNameToDIE.h */, 2618D9EA12406FE600F2B8FE /* NameToDIE.cpp */, 2618D957124056C700F2B8FE /* NameToDIE.h */, 260C89D910F57C5600BB2B04 /* SymbolFileDWARF.cpp */, @@ -3307,7 +3312,7 @@ 9470A8F01402DFFB0056FF61 /* DataVisualization.cpp in Sources */, 26274FA214030EEF006BA130 /* OperatingSystemDarwinKernel.cpp in Sources */, 26274FA714030F79006BA130 /* DynamicLoaderDarwinKernel.cpp in Sources */, - 268ED0A5140FF54200DE830F /* DataEncoder.cpp in Sources */, + 26A0DA4E140F7226006DA411 /* HashedNameToDIE.cpp in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; Modified: lldb/trunk/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp?rev=138979&r1=138978&r2=138979&view=diff ============================================================================== --- lldb/trunk/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp (original) +++ lldb/trunk/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp Thu Sep 1 18:16:13 2011 @@ -255,6 +255,8 @@ case eSectionTypeDWARFDebugPubTypes: return eAddressClassDebug; case eSectionTypeDWARFDebugRanges: return eAddressClassDebug; case eSectionTypeDWARFDebugStr: return eAddressClassDebug; + case eSectionTypeDWARFDebugNames: return eAddressClassDebug; + case eSectionTypeDWARFDebugTypes: return eAddressClassDebug; case eSectionTypeEHFrame: return eAddressClassRuntime; case eSectionTypeOther: return eAddressClassUnknown; } @@ -505,6 +507,8 @@ static ConstString g_sect_name_dwarf_debug_pubtypes ("__debug_pubtypes"); static ConstString g_sect_name_dwarf_debug_ranges ("__debug_ranges"); static ConstString g_sect_name_dwarf_debug_str ("__debug_str"); + static ConstString g_sect_name_dwarf_debug_names ("__debug_names"); + static ConstString g_sect_name_dwarf_debug_types ("__debug_types"); static ConstString g_sect_name_eh_frame ("__eh_frame"); static ConstString g_sect_name_DATA ("__DATA"); static ConstString g_sect_name_TEXT ("__TEXT"); @@ -533,6 +537,10 @@ sect_type = eSectionTypeDWARFDebugRanges; else if (section_name == g_sect_name_dwarf_debug_str) sect_type = eSectionTypeDWARFDebugStr; + else if (section_name == g_sect_name_dwarf_debug_names) + sect_type = eSectionTypeDWARFDebugNames; + else if (section_name == g_sect_name_dwarf_debug_types) + sect_type = eSectionTypeDWARFDebugTypes; else if (section_name == g_sect_name_objc_selrefs) sect_type = eSectionTypeDataCStringPointers; else if (section_name == g_sect_name_objc_msgrefs) Modified: lldb/trunk/source/Plugins/SymbolFile/DWARF/NameToDIE.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/SymbolFile/DWARF/NameToDIE.cpp?rev=138979&r1=138978&r2=138979&view=diff ============================================================================== --- lldb/trunk/source/Plugins/SymbolFile/DWARF/NameToDIE.cpp (original) +++ lldb/trunk/source/Plugins/SymbolFile/DWARF/NameToDIE.cpp Thu Sep 1 18:16:13 2011 @@ -9,17 +9,27 @@ #include "NameToDIE.h" #include "lldb/Core/ConstString.h" +#include "lldb/Core/DataExtractor.h" #include "lldb/Core/Stream.h" +#include "lldb/Core/StreamString.h" #include "lldb/Core/RegularExpression.h" +#include "lldb/Symbol/ObjectFile.h" + +#include "DWARFCompileUnit.h" +#include "DWARFDebugInfo.h" +#include "DWARFDebugInfoEntry.h" +#include "SymbolFileDWARF.h" +using namespace lldb; +using namespace lldb_private; void -NameToDIE::Insert (const lldb_private::ConstString& name, const Info &info) +NameToDIE::Insert (const ConstString& name, const Info &info) { m_collection.insert (std::make_pair(name.AsCString(), info)); } size_t -NameToDIE::Find (const lldb_private::ConstString &name, std::vector &info_array) const +NameToDIE::Find (const ConstString &name, std::vector &info_array) const { const char *name_cstr = name.AsCString(); const size_t initial_info_array_size = info_array.size(); @@ -32,7 +42,7 @@ } size_t -NameToDIE::Find (const lldb_private::RegularExpression& regex, std::vector &info_array) const +NameToDIE::Find (const RegularExpression& regex, std::vector &info_array) const { const size_t initial_info_array_size = info_array.size(); collection::const_iterator pos, end = m_collection.end(); @@ -58,7 +68,7 @@ } void -NameToDIE::Dump (lldb_private::Stream *s) +NameToDIE::Dump (Stream *s) { collection::const_iterator pos, end = m_collection.end(); for (pos = m_collection.begin(); pos != end; ++pos) @@ -85,13 +95,88 @@ uint32_t cu_idx; uint32_t die_idx; const char *name; + + bool + operator < (const HashEntry &rhs) const + { + return hash < rhs.hash; + } +}; + +struct HashHeader +{ + uint32_t version; + uint32_t bucket_info_size; // The fixed data associated with this bucket + uint32_t bucket_count; + uint32_t flags; +}; + +struct HashBucketInfo +{ + uint32_t offset; // Offset to the data for each bucket +}; + +struct HashBucketEntryStrp +{ + HashBucketEntryStrp () : + str_offset (0) + { + } + + HashBucketEntryStrp (uint32_t s, uint32_t d) : + str_offset (s) + { + } + + uint32_t + GetByteSize () + { + return sizeof(uint32_t) + // String offset in .debug_str + sizeof(uint32_t) + // Number of dies + die_array.size() * sizeof(uint32_t); + } + + uint32_t str_offset; + std::vector die_array; }; +typedef std::vector DIEArray; +typedef std::map NameToDIEArrayMap; + +struct HashBucketEntryCStr +{ + uint32_t + GetByteSize () const + { + uint32_t byte_size = 0; + NameToDIEArrayMap::const_iterator pos, end = name_to_die.end(); + for (pos = name_to_die.begin(); pos != end; ++pos) + { + // Include the size of the and a length for the dies, and all dies + byte_size += sizeof(uint32_t) + sizeof(uint32_t) * (pos->second.size() + 1); + } + return byte_size; + } + + NameToDIEArrayMap name_to_die; +}; + +static uint32_t +closest_power_2_less_than_n (uint32_t n) +{ + if (n) + return 0x80000000u >> __builtin_clz (n); + return 0; +} + typedef struct HashEntry HashEntryType; void -NameToDIE::Hash (lldb_private::Stream *s) +NameToDIE::Hash (Stream *s, SymbolFileDWARF *dwarf) { + if (m_collection.empty()) + return; + typedef std::vector hash_collection; hash_collection hash_entries; collection::const_iterator pos, end = m_collection.end(); @@ -101,42 +186,160 @@ hash_entries.push_back (entry); } - +// const DataExtractor &debug_str_data = dwarf->get_debug_str_data(); + const uint32_t hash_entries_size = hash_entries.size(); uint32_t i; + DWARFDebugInfo *debug_info = dwarf->DebugInfo(); - for (uint32_t power_2 = 0x10; power_2 <= hash_entries_size; power_2 <<= 1) + uint32_t num_buckets; + if (hash_entries_size > 1024) + num_buckets = closest_power_2_less_than_n (hash_entries_size/16); + else if (hash_entries_size > 128) + num_buckets = closest_power_2_less_than_n (hash_entries_size/8); + else + num_buckets = closest_power_2_less_than_n (hash_entries_size/4); + if (num_buckets == 0) + num_buckets = 1; + + //for (uint32_t power_2 = 0x10; power_2 <= hash_entries_size; power_2 <<= 1) { - const uint32_t size = power_2 - 1; - if (size > 0x10 && size > hash_entries_size) - break; +// if (num_buckets > 0x10 && num_buckets > hash_entries_size) +// break; - s->Printf ("\nTrying size of %u for %u items:\n", size, hash_entries_size); - std::vector indexes(size, 0); + typedef std::vector uint32_array; + typedef std::map HashBucketEntryMap; + std::vector hash_buckets; + hash_buckets.resize(num_buckets); + + uint32_t bucket_entry_empties = 0; + uint32_t bucket_entry_single = 0; + uint32_t bucket_entry_collisions = 0; + uint32_t names_entry_single = 0; + uint32_t names_entry_collisions = 0; + //StreamString hash_file_data(Stream::eBinary, dwarf->GetObjectFile()->GetAddressByteSize(), dwarf->GetObjectFile()->GetByteSize()); + + // Write hash table header +// hash_file_data.PutHex32 (1); // Version +// hash_file_data.PutHex32 (4); // Sizeof bucket data +// hash_file_data.PutHex32 (num_buckets); +// hash_file_data.PutHex32 (0); // Flags + + s->Printf("HashHeader = { version = %u, bucket_info_size = %u, bucket_count = %u, flags = 0x%8.8x }\n", 1, (uint32_t)sizeof(HashBucketInfo), num_buckets, 0); + for (i=0; iGetCompileUnitAtIndex (hash_entries[i].cu_idx); + cu->ExtractDIEsIfNeeded(false); + DWARFDebugInfoEntry *die = cu->GetDIEAtIndexUnchecked(hash_entries[i].die_idx); + hash_buckets[bucket_idx][hash].name_to_die[hash_entries[i].name].push_back(die->GetOffset()); } - const uint32_t indexes_size = indexes.size(); - uint32_t empties = 0; - uint32_t good = 0; - uint32_t collisions = 0; - uint64_t total = 0; - for (i=0; ifirst) + pos->second.GetByteSize(); + } + if (bucket_data_size > 0) + { + // Offset to bucket data +// hash_file_data.PutHex32 (data_offset); + s->Printf("bucket[%u] {0x%8.8x}\n", i, data_offset); + data_offset += bucket_data_size; + } else - ++collisions; + { + // Invalid offset that indicates an empty bucket +// hash_file_data.PutHex32 (UINT32_MAX); + s->Printf("bucket[%u] {0xFFFFFFFF}\n", i); + ++bucket_entry_empties; + } } - s->Printf ("good = %u\n", good); - s->Printf ("empties = %u\n", empties); - s->Printf ("collisions = %u\n", collisions); - s->Printf ("avg count = %llu\n", total / indexes_size); + + // Now we write the bucket data for each bucket that corresponds to each bucket + // offset from above. + data_offset = 0; + uint32_t total_num_name_entries = 0; + uint32_t total_num_bucket_entries = 0; + uint32_t total_non_empty_buckets = 0; + for (i=0; iPrintf("0x%8.8x: BucketEntry:\n", data_offset, num_bucket_entries); + bucket_data_size = 0; + uint32_t num_bucket_entries = 0; + HashBucketEntryMap::const_iterator pos, end = bucket_entry.end(); + for (pos = bucket_entry.begin(); pos != end; ++pos) + { + ++num_bucket_entries; + uint32_t hash_data_len = pos->second.GetByteSize(); + s->Printf(" hash = 0x%8.8x, length = 0x%8.8x:\n", pos->first, hash_data_len); +// hash_file_data.PutHex32 (pos->first); // Write the hash +// hash_file_data.PutHex32 (hash_data_len); // The length of the data for this hash not including the length itself + + const HashBucketEntryCStr &hash_entry = pos->second; + uint32_t num_name_entries = 0; + NameToDIEArrayMap::const_iterator name_pos, name_end = hash_entry.name_to_die.end(); + for (name_pos = hash_entry.name_to_die.begin(); name_pos != name_end; ++name_pos) + { + ++num_name_entries; + ++total_num_name_entries; + s->Printf(" name = %p '%s'\n", name_pos->first, name_pos->first); +// hash_file_data.PutHex32 (pos->first); // Write the hash +// hash_file_data.PutHex32 (hash_data_len); // The length of the data for this hash not including the length itself + + + const uint32_t num_dies = name_pos->second.size(); + s->Printf(" dies[%u] = { ", num_dies); + for (uint32_t j=0; j < num_dies; ++j) + s->Printf("0x%8.8x ", name_pos->second[j]); + s->PutCString("}\n"); + } + if (num_name_entries == 1) + ++names_entry_single; + else if (num_name_entries > 1) + ++names_entry_collisions; + bucket_data_size += sizeof(pos->first) + hash_data_len; + } + data_offset += bucket_data_size; + byte_size += bucket_data_size; + total_num_bucket_entries += num_bucket_entries; + if (num_bucket_entries == 1) + ++bucket_entry_single; + else if (num_bucket_entries > 1) + ++bucket_entry_collisions; + } + + s->Printf ("Trying size of %u buckets, %u items:\n", num_buckets, hash_entries_size); + s->Printf ("buckets: empty = %u (%%%f)\n", bucket_entry_empties, ((float)bucket_entry_empties/(float)num_buckets) * 100.0f); + s->Printf ("buckets: single = %u\n", bucket_entry_single); + s->Printf ("buckets: multiple = %u (avg = %f entries/bucket, avg = %f entries/non-empty bucket)\n", + bucket_entry_collisions, + (float)total_num_bucket_entries / (float)num_buckets, + (float)total_num_bucket_entries / (float)total_non_empty_buckets); + s->Printf ("names : single = %u of %u\n", names_entry_single, total_num_name_entries); + s->Printf ("names : multiple = %u of %u\n", names_entry_collisions, total_num_name_entries); + s->Printf ("total byte size = %u\n", byte_size); + s->PutCString ("\n----------------------------------------------------------------------\n\n"); } } Modified: lldb/trunk/source/Plugins/SymbolFile/DWARF/NameToDIE.h URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/SymbolFile/DWARF/NameToDIE.h?rev=138979&r1=138978&r2=138979&view=diff ============================================================================== --- lldb/trunk/source/Plugins/SymbolFile/DWARF/NameToDIE.h (original) +++ lldb/trunk/source/Plugins/SymbolFile/DWARF/NameToDIE.h Thu Sep 1 18:16:13 2011 @@ -14,6 +14,8 @@ #include #include "lldb/lldb-defines.h" +class SymbolFileDWARF; + class NameToDIE { public: @@ -52,7 +54,7 @@ std::vector &info_array) const; void - Hash (lldb_private::Stream *s); + Hash (lldb_private::Stream *s, SymbolFileDWARF *dwarf); protected: typedef std::multimap collection; Modified: lldb/trunk/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp?rev=138979&r1=138978&r2=138979&view=diff ============================================================================== --- lldb/trunk/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp (original) +++ lldb/trunk/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp Thu Sep 1 18:16:13 2011 @@ -168,6 +168,8 @@ m_data_debug_loc(), m_data_debug_ranges(), m_data_debug_str(), + m_data_debug_names (), + m_data_debug_types (), m_abbr(), m_aranges(), m_info(), @@ -441,6 +443,18 @@ return GetCachedSectionData (flagsGotDebugStrData, eSectionTypeDWARFDebugStr, m_data_debug_str); } +const DataExtractor& +SymbolFileDWARF::get_debug_names_data() +{ + return GetCachedSectionData (flagsGotDebugNamesData, eSectionTypeDWARFDebugNames, m_data_debug_names); +} + +const DataExtractor& +SymbolFileDWARF::get_debug_types_data() +{ + return GetCachedSectionData (flagsGotDebugTypesData, eSectionTypeDWARFDebugTypes, m_data_debug_types); +} + DWARFDebugAbbrev* SymbolFileDWARF::DebugAbbrev() @@ -1945,8 +1959,7 @@ #if defined (ENABLE_DEBUG_PRINTF) StreamFile s(stdout, false); - s.Printf ("DWARF index for (%s) '%s/%s':", - GetObjectFile()->GetModule()->GetArchitecture().AsCString(), + s.Printf ("DWARF index for '%s/%s':", GetObjectFile()->GetFileSpec().GetDirectory().AsCString(), GetObjectFile()->GetFileSpec().GetFilename().AsCString()); s.Printf("\nFunction basenames:\n"); m_function_basename_index.Dump (&s); Modified: lldb/trunk/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.h URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.h?rev=138979&r1=138978&r2=138979&view=diff ============================================================================== --- lldb/trunk/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.h (original) +++ lldb/trunk/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.h Thu Sep 1 18:16:13 2011 @@ -162,6 +162,8 @@ const lldb_private::DataExtractor& get_debug_loc_data(); const lldb_private::DataExtractor& get_debug_ranges_data(); const lldb_private::DataExtractor& get_debug_str_data(); + const lldb_private::DataExtractor& get_debug_names_data(); + const lldb_private::DataExtractor& get_debug_types_data(); DWARFDebugAbbrev* DebugAbbrev(); const DWARFDebugAbbrev* DebugAbbrev() const; @@ -229,7 +231,9 @@ flagsGotDebugPubNamesData = (1 << 7), flagsGotDebugPubTypesData = (1 << 8), flagsGotDebugRangesData = (1 << 9), - flagsGotDebugStrData = (1 << 10) + flagsGotDebugStrData = (1 << 10), + flagsGotDebugNamesData = (1 << 11), + flagsGotDebugTypesData = (1 << 12), }; DISALLOW_COPY_AND_ASSIGN (SymbolFileDWARF); @@ -371,6 +375,8 @@ lldb_private::DataExtractor m_data_debug_loc; lldb_private::DataExtractor m_data_debug_ranges; lldb_private::DataExtractor m_data_debug_str; + lldb_private::DataExtractor m_data_debug_names; + lldb_private::DataExtractor m_data_debug_types; // The auto_ptr items below are generated on demand if and when someone accesses // them through a non const version of this class. Modified: lldb/trunk/source/Symbol/ObjectFile.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Symbol/ObjectFile.cpp?rev=138979&r1=138978&r2=138979&view=diff ============================================================================== --- lldb/trunk/source/Symbol/ObjectFile.cpp (original) +++ lldb/trunk/source/Symbol/ObjectFile.cpp Thu Sep 1 18:16:13 2011 @@ -146,6 +146,8 @@ case eSectionTypeDWARFDebugPubTypes: return eAddressClassDebug; case eSectionTypeDWARFDebugRanges: return eAddressClassDebug; case eSectionTypeDWARFDebugStr: return eAddressClassDebug; + case eSectionTypeDWARFDebugNames: return eAddressClassDebug; + case eSectionTypeDWARFDebugTypes: return eAddressClassDebug; case eSectionTypeEHFrame: return eAddressClassRuntime; case eSectionTypeOther: return eAddressClassUnknown; } Modified: lldb/trunk/source/lldb.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/lldb.cpp?rev=138979&r1=138978&r2=138979&view=diff ============================================================================== --- lldb/trunk/source/lldb.cpp (original) +++ lldb/trunk/source/lldb.cpp Thu Sep 1 18:16:13 2011 @@ -258,6 +258,8 @@ case eSectionTypeDWARFDebugPubTypes: return "dwarf-pubtypes"; case eSectionTypeDWARFDebugRanges: return "dwarf-ranges"; case eSectionTypeDWARFDebugStr: return "dwarf-str"; + case eSectionTypeDWARFDebugNames: return "dwarf-names"; + case eSectionTypeDWARFDebugTypes: return "dwarf-types"; case eSectionTypeEHFrame: return "eh-frame"; case eSectionTypeOther: return "regular"; } From gclayton at apple.com Thu Sep 1 18:30:34 2011 From: gclayton at apple.com (Greg Clayton) Date: Thu, 01 Sep 2011 23:30:34 -0000 Subject: [Lldb-commits] [lldb] r138981 - in /lldb/trunk/source/Plugins/SymbolFile/DWARF: HashedNameToDIE.cpp HashedNameToDIE.h Message-ID: <20110901233034.901952A6C12C@llvm.org> Author: gclayton Date: Thu Sep 1 18:30:34 2011 New Revision: 138981 URL: http://llvm.org/viewvc/llvm-project?rev=138981&view=rev Log: Added files I forget to checkin with my last checkin. Added: lldb/trunk/source/Plugins/SymbolFile/DWARF/HashedNameToDIE.cpp lldb/trunk/source/Plugins/SymbolFile/DWARF/HashedNameToDIE.h Added: lldb/trunk/source/Plugins/SymbolFile/DWARF/HashedNameToDIE.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/SymbolFile/DWARF/HashedNameToDIE.cpp?rev=138981&view=auto ============================================================================== --- lldb/trunk/source/Plugins/SymbolFile/DWARF/HashedNameToDIE.cpp (added) +++ lldb/trunk/source/Plugins/SymbolFile/DWARF/HashedNameToDIE.cpp Thu Sep 1 18:30:34 2011 @@ -0,0 +1,136 @@ +//===-- HashedNameToDIE.cpp -------------------------------------------*- C++ -*-===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +#include "HashedNameToDIE.h" +#include "lldb/Core/ConstString.h" +#include "lldb/Core/DataExtractor.h" +#include "lldb/Core/Stream.h" +#include "lldb/Core/StreamString.h" +#include "lldb/Core/RegularExpression.h" +#include "lldb/Symbol/ObjectFile.h" + +#include "DWARFCompileUnit.h" +#include "DWARFDebugInfo.h" +#include "DWARFDebugInfoEntry.h" +#include "SymbolFileDWARF.h" +using namespace lldb; +using namespace lldb_private; + +static uint32_t +dl_new_hash (const char *s) +{ + uint32_t h = 5381; + + for (unsigned char c = *s; c; c = *++s) + h = ((h << 5) + h) + c; + + return h; +} + +HashedNameToDIE::HashedNameToDIE (SymbolFileDWARF *dwarf, const DataExtractor &data) : + m_dwarf (dwarf), + m_data (data), + m_header () +{ + uint32_t offset = 0; + m_header.version = m_data.GetU16(&offset); + m_header.hash_type = m_data.GetU8(&offset); + m_header.hash_index_bitsize = m_data.GetU8(&offset); + m_header.num_buckets = m_data.GetU32(&offset); + m_header.num_hashes = m_data.GetU32(&offset); + m_header.die_offset_base = m_data.GetU32(&offset); +} + + +size_t +HashedNameToDIE::Find (const ConstString &name, DIEArray &die_ofsets) const +{ + const size_t initial_size = die_ofsets.size(); + const char *name_cstr = name.GetCString(); + if (name_cstr && name_cstr[0]) + { + // Hash the C string + const uint32_t name_hash = dl_new_hash (name_cstr); + + // Find the correct bucket for the using the hash value + const uint32_t bucket_idx = name_hash % m_header.num_buckets; + + // Calculate the offset for the bucket entry for the bucket index + uint32_t offset = GetOffsetForBucket (bucket_idx); + + // Extract the bucket entry. + const uint32_t bucket_entry = m_data.GetU32 (&offset); + if (bucket_entry) + { + // The bucket entry is non-zero which means it isn't empty. + // The bucket entry is made up of a hash index whose bit width + // is m_header.hash_index_bitsize, and a hash count whose value + // is the remaining bits in the 32 bit value. Below we extract + // the hash index and the hash count + const uint32_t hash_idx = bucket_entry & GetHashIndexMask(); + const uint32_t hash_count = bucket_entry >> m_header.hash_index_bitsize; + const uint32_t hash_end_idx = hash_idx + hash_count; + // Figure out the offset to the hash value by index + uint32_t hash_offset = GetOffsetForHash (hash_idx); + for (uint32_t idx = hash_idx; idx < hash_end_idx; ++idx) + { + // Extract the hash value and see if it matches our string + const uint32_t hash = m_data.GetU32 (&hash_offset); + if (hash == name_hash) + { + // The hash matches, but we still need to verify that the + // C string matches in case we have a hash collision. Figure + // out the offset for the data associated with this hash entry + offset = GetOffsetForOffset (hash_idx); + // Extract the first 32 bit value which is the .debug_str offset + // of the string we need + const uint32_t str_offset = m_data.GetU32 (&offset); + // Extract the C string and comapare it + const char *cstr_name = m_dwarf->get_debug_str_data().PeekCStr(str_offset); + if (strcmp(name_cstr, cstr_name) == 0) + { + // We have a match, now extract the DIE count + const uint32_t die_count = m_data.GetU32 (&offset); + // Now extract "die_count" DIE offsets and put them into the + // results + for (uint32_t die_idx = 0; die_idx < die_count; ++die_idx) + die_ofsets.push_back(m_data.GetU32 (&offset)); + } + } + } + } + } + return die_ofsets.size() - initial_size; +} + +size_t +HashedNameToDIE::Find (const RegularExpression& regex, DIEArray &die_ofsets) const +{ +// const size_t initial_info_array_size = info_array.size(); +// collection::const_iterator pos, end = m_collection.end(); +// for (pos = m_collection.begin(); pos != end; ++pos) +// { +// if (regex.Execute(pos->first)) +// info_array.push_back (pos->second); +// } +// return info_array.size() - initial_info_array_size; + return 0; +} + +void +HashedNameToDIE::Dump (Stream *s) +{ +// collection::const_iterator pos, end = m_collection.end(); +// for (pos = m_collection.begin(); pos != end; ++pos) +// { +// s->Printf("%p: 0x%8.8x 0x%8.8x \"%s\"\n", pos->first, pos->second.cu_idx, pos->second.die_idx, pos->first); +// } +} + + Added: lldb/trunk/source/Plugins/SymbolFile/DWARF/HashedNameToDIE.h URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/SymbolFile/DWARF/HashedNameToDIE.h?rev=138981&view=auto ============================================================================== --- lldb/trunk/source/Plugins/SymbolFile/DWARF/HashedNameToDIE.h (added) +++ lldb/trunk/source/Plugins/SymbolFile/DWARF/HashedNameToDIE.h Thu Sep 1 18:30:34 2011 @@ -0,0 +1,99 @@ +//===-- HashedNameToDIE.h ---------------------------------------*- C++ -*-===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +#ifndef SymbolFileDWARF_HashedNameToDIE_h_ +#define SymbolFileDWARF_HashedNameToDIE_h_ + +#include +#include "lldb/lldb-defines.h" +#include "lldb/Core/dwarf.h" + +class SymbolFileDWARF; + +typedef std::vector DIEArray; + +class HashedNameToDIE +{ +public: + struct Header + { + uint16_t version; + uint8_t hash_type; + uint8_t hash_index_bitsize; + uint32_t num_buckets; + uint32_t num_hashes; + uint32_t die_offset_base; + + Header() : + version(1), + hash_type (0), + hash_index_bitsize (0), + num_buckets(0), + num_hashes (0), + die_offset_base(0) + { + } + }; + + + HashedNameToDIE (SymbolFileDWARF *dwarf, + const lldb_private::DataExtractor &data); + + ~HashedNameToDIE () + { + } + + uint32_t + GetHashIndexMask () const + { + return (1u << m_header.hash_index_bitsize) - 1u; + } + + uint32_t + GetOffsetForBucket (uint32_t idx) const + { + if (idx < m_header.num_buckets) + return sizeof(Header) + 4 * idx; + return UINT32_MAX; + } + + uint32_t + GetOffsetForHash (uint32_t idx) const + { + if (idx < m_header.num_hashes) + return sizeof(Header) + 4 * m_header.num_buckets + 4 * idx; + return UINT32_MAX; + } + + uint32_t + GetOffsetForOffset (uint32_t idx) const + { + if (idx < m_header.num_hashes) + return sizeof(Header) + 4 * m_header.num_buckets + 4 * m_header.num_hashes + 4 * idx; + return UINT32_MAX; + } + + void + Dump (lldb_private::Stream *s); + + size_t + Find (const lldb_private::ConstString &name, + DIEArray &die_ofsets) const; + + size_t + Find (const lldb_private::RegularExpression& regex, + DIEArray &die_ofsets) const; + +protected: + SymbolFileDWARF *m_dwarf; + const lldb_private::DataExtractor &m_data; + Header m_header; +}; + +#endif // SymbolFileDWARF_HashedNameToDIE_h_ From gclayton at apple.com Thu Sep 1 20:15:17 2011 From: gclayton at apple.com (Greg Clayton) Date: Fri, 02 Sep 2011 01:15:17 -0000 Subject: [Lldb-commits] [lldb] r138988 - in /lldb/trunk: include/lldb/Expression/DWARFExpression.h include/lldb/Symbol/DWARFCallFrameInfo.h include/lldb/Symbol/UnwindPlan.h source/Core/ValueObject.cpp source/Expression/DWARFExpression.cpp source/Plugins/Process/Utility/RegisterContextLLDB.cpp source/Plugins/SymbolFile/DWARF/NameToDIE.cpp source/Symbol/DWARFCallFrameInfo.cpp source/Symbol/Variable.cpp Message-ID: <20110902011517.6A7422A6C12C@llvm.org> Author: gclayton Date: Thu Sep 1 20:15:17 2011 New Revision: 138988 URL: http://llvm.org/viewvc/llvm-project?rev=138988&view=rev Log: Added the ability for DWARF locations to use the ABI plug-ins to resolve register names when dumping variable locations and location lists. Also did some cleanup where "int" types were being used for "lldb::RegisterKind" values. Modified: lldb/trunk/include/lldb/Expression/DWARFExpression.h lldb/trunk/include/lldb/Symbol/DWARFCallFrameInfo.h lldb/trunk/include/lldb/Symbol/UnwindPlan.h lldb/trunk/source/Core/ValueObject.cpp lldb/trunk/source/Expression/DWARFExpression.cpp lldb/trunk/source/Plugins/Process/Utility/RegisterContextLLDB.cpp lldb/trunk/source/Plugins/SymbolFile/DWARF/NameToDIE.cpp lldb/trunk/source/Symbol/DWARFCallFrameInfo.cpp lldb/trunk/source/Symbol/Variable.cpp Modified: lldb/trunk/include/lldb/Expression/DWARFExpression.h URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Expression/DWARFExpression.h?rev=138988&r1=138987&r2=138988&view=diff ============================================================================== --- lldb/trunk/include/lldb/Expression/DWARFExpression.h (original) +++ lldb/trunk/include/lldb/Expression/DWARFExpression.h Thu Sep 1 20:15:17 2011 @@ -88,11 +88,16 @@ /// different from the DWARF version of the location list base /// address which is compile unit relative. This base address /// is the address of the object that owns the location list. + /// + /// @param[in] abi + /// An optional ABI plug-in that can be used to resolve register + /// names. //------------------------------------------------------------------ void GetDescription (Stream *s, lldb::DescriptionLevel level, - lldb::addr_t location_list_base_addr) const; + lldb::addr_t location_list_base_addr, + ABI *abi) const; //------------------------------------------------------------------ /// Return true if the location expression contains data @@ -179,7 +184,7 @@ /// The register kind. //------------------------------------------------------------------ void - SetRegisterKind (int reg_kind); + SetRegisterKind (lldb::RegisterKind reg_kind); //------------------------------------------------------------------ /// Wrapper for the static evaluate function that accepts an @@ -315,7 +320,8 @@ DumpLocationForAddress (Stream *s, lldb::DescriptionLevel level, lldb::addr_t loclist_base_load_addr, - lldb::addr_t address); + lldb::addr_t address, + ABI *abi); protected: //------------------------------------------------------------------ @@ -332,12 +338,17 @@ /// /// @param[in] level /// The level of detail to use in pretty-printing. + /// + /// @param[in] abi + /// An optional ABI plug-in that can be used to resolve register + /// names. //------------------------------------------------------------------ void DumpLocation(Stream *s, uint32_t offset, uint32_t length, - lldb::DescriptionLevel level) const; + lldb::DescriptionLevel level, + ABI *abi) const; bool GetLocation (lldb::addr_t base_addr, @@ -350,7 +361,7 @@ //------------------------------------------------------------------ DataExtractor m_data; ///< A data extractor capable of reading opcode bytes - int m_reg_kind; ///< One of the defines that starts with LLDB_REGKIND_ + lldb::RegisterKind m_reg_kind; ///< One of the defines that starts with LLDB_REGKIND_ lldb::addr_t m_loclist_slide; ///< A value used to slide the location list offsets so that ///< they are relative to the object that owns the location list ///< (the function for frame base and variable location lists) Modified: lldb/trunk/include/lldb/Symbol/DWARFCallFrameInfo.h URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Symbol/DWARFCallFrameInfo.h?rev=138988&r1=138987&r2=138988&view=diff ============================================================================== --- lldb/trunk/include/lldb/Symbol/DWARFCallFrameInfo.h (original) +++ lldb/trunk/include/lldb/Symbol/DWARFCallFrameInfo.h Thu Sep 1 20:15:17 2011 @@ -34,7 +34,10 @@ { public: - DWARFCallFrameInfo (ObjectFile& objfile, lldb::SectionSP& section, uint32_t reg_kind, bool is_eh_frame); + DWARFCallFrameInfo (ObjectFile& objfile, + lldb::SectionSP& section, + lldb::RegisterKind reg_kind, + bool is_eh_frame); ~DWARFCallFrameInfo(); @@ -113,7 +116,7 @@ ObjectFile& m_objfile; lldb::SectionSP m_section; - uint32_t m_reg_kind; + lldb::RegisterKind m_reg_kind; Flags m_flags; cie_map_t m_cie_map; Modified: lldb/trunk/include/lldb/Symbol/UnwindPlan.h URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Symbol/UnwindPlan.h?rev=138988&r1=138987&r2=138988&view=diff ============================================================================== --- lldb/trunk/include/lldb/Symbol/UnwindPlan.h (original) +++ lldb/trunk/include/lldb/Symbol/UnwindPlan.h Thu Sep 1 20:15:17 2011 @@ -360,7 +360,7 @@ public: - UnwindPlan (uint32_t reg_kind) : + UnwindPlan (lldb::RegisterKind reg_kind) : m_row_list (), m_plan_valid_address_range (), m_register_kind (reg_kind), @@ -385,14 +385,14 @@ const Row* GetRowForFunctionOffset (int offset) const; - uint32_t + lldb::RegisterKind GetRegisterKind () const { return m_register_kind; } void - SetRegisterKind (uint32_t kind) + SetRegisterKind (lldb::RegisterKind kind) { m_register_kind = kind; } @@ -456,7 +456,7 @@ typedef std::vector collection; collection m_row_list; AddressRange m_plan_valid_address_range; - uint32_t m_register_kind; // The RegisterKind these register numbers are in terms of - will need to be + lldb::RegisterKind m_register_kind; // The RegisterKind these register numbers are in terms of - will need to be // translated to lldb native reg nums at unwind time lldb_private::ConstString m_source_name; // for logging, where this UnwindPlan originated from }; // class UnwindPlan Modified: lldb/trunk/source/Core/ValueObject.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Core/ValueObject.cpp?rev=138988&r1=138987&r2=138988&view=diff ============================================================================== --- lldb/trunk/source/Core/ValueObject.cpp (original) +++ lldb/trunk/source/Core/ValueObject.cpp Thu Sep 1 20:15:17 2011 @@ -53,7 +53,7 @@ using namespace lldb_private; using namespace lldb_utility; -static lldb::user_id_t g_value_obj_uid = 0; +static user_id_t g_value_obj_uid = 0; //---------------------------------------------------------------------- // ValueObject constructor @@ -125,7 +125,7 @@ m_deref_valobj(NULL), m_format (eFormatDefault), m_last_format_mgr_revision(0), - m_last_format_mgr_dynamic(lldb::eNoDynamicValues), + m_last_format_mgr_dynamic(eNoDynamicValues), m_last_summary_format(), m_forced_summary_format(), m_last_value_format(), @@ -162,7 +162,7 @@ } bool -ValueObject::UpdateValueIfNeeded (lldb::DynamicValueType use_dynamic, bool update_format) +ValueObject::UpdateValueIfNeeded (DynamicValueType use_dynamic, bool update_format) { if (update_format) @@ -217,7 +217,7 @@ } void -ValueObject::UpdateFormatsIfNeeded(lldb::DynamicValueType use_dynamic) +ValueObject::UpdateFormatsIfNeeded(DynamicValueType use_dynamic) { LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_TYPES)); if (log) @@ -242,7 +242,7 @@ m_synthetic_value = NULL; - DataVisualization::ValueFormats::Get(*this, lldb::eNoDynamicValues, m_last_value_format); + DataVisualization::ValueFormats::Get(*this, eNoDynamicValues, m_last_value_format); DataVisualization::GetSummaryFormat(*this, use_dynamic, m_last_summary_format); DataVisualization::GetSyntheticChildren(*this, use_dynamic, m_last_synthetic_filter); @@ -578,7 +578,7 @@ if (ClangASTContext::IsFunctionPointerType (clang_type)) { AddressType func_ptr_address_type = eAddressTypeInvalid; - lldb::addr_t func_ptr_address = GetPointerValue (func_ptr_address_type, true); + addr_t func_ptr_address = GetPointerValue (func_ptr_address_type, true); if (func_ptr_address != 0 && func_ptr_address != LLDB_INVALID_ADDRESS) { @@ -641,7 +641,7 @@ return true; if (type_flags.Test(ClangASTContext::eTypeIsArray)) return true; - lldb::addr_t cstr_address = LLDB_INVALID_ADDRESS; + addr_t cstr_address = LLDB_INVALID_ADDRESS; AddressType cstr_address_type = eAddressTypeInvalid; cstr_address = GetAddressOf (cstr_address_type, true); return (cstr_address != LLDB_INVALID_ADDRESS); @@ -652,7 +652,7 @@ Error& error, uint32_t max_length, bool honor_array, - lldb::Format item_format) + Format item_format) { if (max_length == 0) @@ -676,7 +676,7 @@ } else { - lldb::addr_t cstr_address = LLDB_INVALID_ADDRESS; + addr_t cstr_address = LLDB_INVALID_ADDRESS; AddressType cstr_address_type = eAddressTypeInvalid; size_t cstr_len = 0; @@ -711,7 +711,7 @@ if (cstr_len > 0 && honor_array) { data_buffer.resize(cstr_len); - data.SetData (&data_buffer.front(), data_buffer.size(), lldb::endian::InlHostByteOrder()); + data.SetData (&data_buffer.front(), data_buffer.size(), endian::InlHostByteOrder()); bytes_read = target->ReadMemory (cstr_so_addr, prefer_file_cache, &data_buffer.front(), @@ -821,7 +821,7 @@ StreamString s; - lldb::LanguageType language = GetObjectRuntimeLanguage(); + LanguageType language = GetObjectRuntimeLanguage(); LanguageRuntime *runtime = process->GetLanguageRuntime(language); if (runtime == NULL) @@ -834,7 +834,7 @@ if (ClangASTContext::IsIntegerType (opaque_qual_type, is_signed) || ClangASTContext::IsPointerType (opaque_qual_type)) { - runtime = process->GetLanguageRuntime(lldb::eLanguageTypeObjC); + runtime = process->GetLanguageRuntime(eLanguageTypeObjC); } } } @@ -953,12 +953,12 @@ bool ValueObject::GetPrintableRepresentation(Stream& s, ValueObjectRepresentationStyle val_obj_display, - lldb::Format custom_format) + Format custom_format) { RefCounter ref(&m_dump_printable_counter); - if (custom_format != lldb::eFormatInvalid) + if (custom_format != eFormatInvalid) SetFormat(custom_format); const char * return_value; @@ -1046,7 +1046,7 @@ // to checking this call result before trying to display special cases bool ValueObject::HasSpecialCasesForPrintableRepresentation(ValueObjectRepresentationStyle val_obj_display, - lldb::Format custom_format) + Format custom_format) { clang_type_t elem_or_pointee_type; Flags flags(ClangASTContext::GetTypeInfo(GetClangType(), GetClangAST(), &elem_or_pointee_type)); @@ -1055,30 +1055,30 @@ && val_obj_display == ValueObject::eDisplayValue) { if (IsCStringContainer(true) && - (custom_format == lldb::eFormatCString || - custom_format == lldb::eFormatCharArray || - custom_format == lldb::eFormatChar || - custom_format == lldb::eFormatVectorOfChar)) + (custom_format == eFormatCString || + custom_format == eFormatCharArray || + custom_format == eFormatChar || + custom_format == eFormatVectorOfChar)) return true; if (flags.Test(ClangASTContext::eTypeIsArray)) { - if ((custom_format == lldb::eFormatBytes) || - (custom_format == lldb::eFormatBytesWithASCII)) + if ((custom_format == eFormatBytes) || + (custom_format == eFormatBytesWithASCII)) return true; - if ((custom_format == lldb::eFormatVectorOfChar) || - (custom_format == lldb::eFormatVectorOfFloat32) || - (custom_format == lldb::eFormatVectorOfFloat64) || - (custom_format == lldb::eFormatVectorOfSInt16) || - (custom_format == lldb::eFormatVectorOfSInt32) || - (custom_format == lldb::eFormatVectorOfSInt64) || - (custom_format == lldb::eFormatVectorOfSInt8) || - (custom_format == lldb::eFormatVectorOfUInt128) || - (custom_format == lldb::eFormatVectorOfUInt16) || - (custom_format == lldb::eFormatVectorOfUInt32) || - (custom_format == lldb::eFormatVectorOfUInt64) || - (custom_format == lldb::eFormatVectorOfUInt8)) + if ((custom_format == eFormatVectorOfChar) || + (custom_format == eFormatVectorOfFloat32) || + (custom_format == eFormatVectorOfFloat64) || + (custom_format == eFormatVectorOfSInt16) || + (custom_format == eFormatVectorOfSInt32) || + (custom_format == eFormatVectorOfSInt64) || + (custom_format == eFormatVectorOfSInt8) || + (custom_format == eFormatVectorOfUInt128) || + (custom_format == eFormatVectorOfUInt16) || + (custom_format == eFormatVectorOfUInt32) || + (custom_format == eFormatVectorOfUInt64) || + (custom_format == eFormatVectorOfUInt8)) return true; } } @@ -1088,7 +1088,7 @@ bool ValueObject::DumpPrintableRepresentation(Stream& s, ValueObjectRepresentationStyle val_obj_display, - lldb::Format custom_format, + Format custom_format, bool only_special) { @@ -1102,29 +1102,29 @@ // try to "do the right thing" if (IsCStringContainer(true) && - (custom_format == lldb::eFormatCString || - custom_format == lldb::eFormatCharArray || - custom_format == lldb::eFormatChar || - custom_format == lldb::eFormatVectorOfChar)) // print char[] & char* directly + (custom_format == eFormatCString || + custom_format == eFormatCharArray || + custom_format == eFormatChar || + custom_format == eFormatVectorOfChar)) // print char[] & char* directly { Error error; ReadPointedString(s, error, 0, - (custom_format == lldb::eFormatVectorOfChar) || - (custom_format == lldb::eFormatCharArray)); + (custom_format == eFormatVectorOfChar) || + (custom_format == eFormatCharArray)); return !error.Fail(); } - if (custom_format == lldb::eFormatEnum) + if (custom_format == eFormatEnum) return false; // this only works for arrays, because I have no way to know when // the pointed memory ends, and no special \0 end of data marker if (flags.Test(ClangASTContext::eTypeIsArray)) { - if ((custom_format == lldb::eFormatBytes) || - (custom_format == lldb::eFormatBytesWithASCII)) + if ((custom_format == eFormatBytes) || + (custom_format == eFormatBytesWithASCII)) { uint32_t count = GetNumChildren(); @@ -1149,22 +1149,22 @@ return true; } - if ((custom_format == lldb::eFormatVectorOfChar) || - (custom_format == lldb::eFormatVectorOfFloat32) || - (custom_format == lldb::eFormatVectorOfFloat64) || - (custom_format == lldb::eFormatVectorOfSInt16) || - (custom_format == lldb::eFormatVectorOfSInt32) || - (custom_format == lldb::eFormatVectorOfSInt64) || - (custom_format == lldb::eFormatVectorOfSInt8) || - (custom_format == lldb::eFormatVectorOfUInt128) || - (custom_format == lldb::eFormatVectorOfUInt16) || - (custom_format == lldb::eFormatVectorOfUInt32) || - (custom_format == lldb::eFormatVectorOfUInt64) || - (custom_format == lldb::eFormatVectorOfUInt8)) // arrays of bytes, bytes with ASCII or any vector format should be printed directly + if ((custom_format == eFormatVectorOfChar) || + (custom_format == eFormatVectorOfFloat32) || + (custom_format == eFormatVectorOfFloat64) || + (custom_format == eFormatVectorOfSInt16) || + (custom_format == eFormatVectorOfSInt32) || + (custom_format == eFormatVectorOfSInt64) || + (custom_format == eFormatVectorOfSInt8) || + (custom_format == eFormatVectorOfUInt128) || + (custom_format == eFormatVectorOfUInt16) || + (custom_format == eFormatVectorOfUInt32) || + (custom_format == eFormatVectorOfUInt64) || + (custom_format == eFormatVectorOfUInt8)) // arrays of bytes, bytes with ASCII or any vector format should be printed directly { uint32_t count = GetNumChildren(); - lldb::Format format = FormatManager::GetSingleItemFormat(custom_format); + Format format = FormatManager::GetSingleItemFormat(custom_format); s << '['; for (uint32_t low = 0; low < count; low++) @@ -1188,23 +1188,23 @@ } } - if ((custom_format == lldb::eFormatBoolean) || - (custom_format == lldb::eFormatBinary) || - (custom_format == lldb::eFormatChar) || - (custom_format == lldb::eFormatCharPrintable) || - (custom_format == lldb::eFormatComplexFloat) || - (custom_format == lldb::eFormatDecimal) || - (custom_format == lldb::eFormatHex) || - (custom_format == lldb::eFormatFloat) || - (custom_format == lldb::eFormatOctal) || - (custom_format == lldb::eFormatOSType) || - (custom_format == lldb::eFormatUnicode16) || - (custom_format == lldb::eFormatUnicode32) || - (custom_format == lldb::eFormatUnsigned) || - (custom_format == lldb::eFormatPointer) || - (custom_format == lldb::eFormatComplexInteger) || - (custom_format == lldb::eFormatComplex) || - (custom_format == lldb::eFormatDefault)) // use the [] operator + if ((custom_format == eFormatBoolean) || + (custom_format == eFormatBinary) || + (custom_format == eFormatChar) || + (custom_format == eFormatCharPrintable) || + (custom_format == eFormatComplexFloat) || + (custom_format == eFormatDecimal) || + (custom_format == eFormatHex) || + (custom_format == eFormatFloat) || + (custom_format == eFormatOctal) || + (custom_format == eFormatOSType) || + (custom_format == eFormatUnicode16) || + (custom_format == eFormatUnicode32) || + (custom_format == eFormatUnsigned) || + (custom_format == eFormatPointer) || + (custom_format == eFormatComplexInteger) || + (custom_format == eFormatComplex) || + (custom_format == eFormatDefault)) // use the [] operator return false; } @@ -1249,7 +1249,7 @@ addr_t ValueObject::GetPointerValue (AddressType &address_type, bool scalar_is_load_address) { - lldb::addr_t address = LLDB_INVALID_ADDRESS; + addr_t address = LLDB_INVALID_ADDRESS; address_type = eAddressTypeInvalid; if (!UpdateValueIfNeeded(false)) @@ -1293,7 +1293,7 @@ return false; uint32_t count = 0; - lldb::Encoding encoding = ClangASTType::GetEncoding (GetClangType(), count); + Encoding encoding = ClangASTType::GetEncoding (GetClangType(), count); const size_t byte_size = GetByteSize(); @@ -1322,7 +1322,7 @@ ProcessSP process_sp = GetUpdatePoint().GetProcessSP(); if (process_sp) { - lldb::addr_t target_addr = m_value.GetScalar().GetRawBits64(LLDB_INVALID_ADDRESS); + addr_t target_addr = m_value.GetScalar().GetRawBits64(LLDB_INVALID_ADDRESS); size_t bytes_written = process_sp->WriteScalarToMemory (target_addr, new_scalar, byte_size, @@ -1374,7 +1374,7 @@ return true; } -lldb::LanguageType +LanguageType ValueObject::GetObjectRuntimeLanguage () { return ClangASTType::GetMinimumLanguage (GetClangAST(), @@ -1439,7 +1439,7 @@ return ClangASTContext::IsPossibleDynamicType (GetClangAST (), GetClangType()); } -lldb::ValueObjectSP +ValueObjectSP ValueObject::GetSyntheticArrayMember (int32_t index, bool can_create) { if (IsArrayType()) @@ -1568,7 +1568,7 @@ return synthetic_child_sp; } -lldb::ValueObjectSP +ValueObjectSP ValueObject::GetSyntheticArrayRangeChild (uint32_t from, uint32_t to, bool can_create) { ValueObjectSP synthetic_child_sp; @@ -1604,7 +1604,7 @@ return synthetic_child_sp; } -lldb::ValueObjectSP +ValueObjectSP ValueObject::GetSyntheticChildAtOffset(uint32_t offset, const ClangASTType& type, bool can_create) { @@ -1622,7 +1622,7 @@ return synthetic_child_sp; if (!can_create) - return lldb::ValueObjectSP(); + return ValueObjectSP(); ValueObjectChild *synthetic_child = new ValueObjectChild(*this, type.GetASTContext(), @@ -1661,7 +1661,7 @@ return expression; } -lldb::ValueObjectSP +ValueObjectSP ValueObject::GetSyntheticExpressionPathChild(const char* expression, bool can_create) { ValueObjectSP synthetic_child_sp; @@ -1687,9 +1687,9 @@ } void -ValueObject::CalculateSyntheticValue (lldb::SyntheticValueType use_synthetic) +ValueObject::CalculateSyntheticValue (SyntheticValueType use_synthetic) { - if (use_synthetic == lldb::eNoSyntheticFilter) + if (use_synthetic == eNoSyntheticFilter) return; UpdateFormatsIfNeeded(m_last_format_mgr_dynamic); @@ -1703,9 +1703,9 @@ } void -ValueObject::CalculateDynamicValue (lldb::DynamicValueType use_dynamic) +ValueObject::CalculateDynamicValue (DynamicValueType use_dynamic) { - if (use_dynamic == lldb::eNoDynamicValues) + if (use_dynamic == eNoDynamicValues) return; if (!m_dynamic_value && !IsDynamic()) @@ -1716,8 +1716,8 @@ // FIXME: Process should have some kind of "map over Runtimes" so we don't have to // hard code this everywhere. - lldb::LanguageType known_type = GetObjectRuntimeLanguage(); - if (known_type != lldb::eLanguageTypeUnknown && known_type != lldb::eLanguageTypeC) + LanguageType known_type = GetObjectRuntimeLanguage(); + if (known_type != eLanguageTypeUnknown && known_type != eLanguageTypeC) { LanguageRuntime *runtime = process->GetLanguageRuntime (known_type); if (runtime) @@ -1725,13 +1725,13 @@ } else { - LanguageRuntime *cpp_runtime = process->GetLanguageRuntime (lldb::eLanguageTypeC_plus_plus); + LanguageRuntime *cpp_runtime = process->GetLanguageRuntime (eLanguageTypeC_plus_plus); if (cpp_runtime) worth_having_dynamic_value = cpp_runtime->CouldHaveDynamicValue(*this); if (!worth_having_dynamic_value) { - LanguageRuntime *objc_runtime = process->GetLanguageRuntime (lldb::eLanguageTypeObjC); + LanguageRuntime *objc_runtime = process->GetLanguageRuntime (eLanguageTypeObjC); if (objc_runtime) worth_having_dynamic_value = objc_runtime->CouldHaveDynamicValue(*this); } @@ -1749,7 +1749,7 @@ ValueObjectSP ValueObject::GetDynamicValue (DynamicValueType use_dynamic) { - if (use_dynamic == lldb::eNoDynamicValues) + if (use_dynamic == eNoDynamicValues) return ValueObjectSP(); if (!IsDynamic() && m_dynamic_value == NULL) @@ -1769,7 +1769,7 @@ ValueObjectSP ValueObject::GetSyntheticValue (SyntheticValueType use_synthetic) { - if (use_synthetic == lldb::eNoSyntheticFilter) + if (use_synthetic == eNoSyntheticFilter) return GetSP(); UpdateFormatsIfNeeded(m_last_format_mgr_dynamic); @@ -1793,7 +1793,7 @@ if (m_last_synthetic_filter.get() == NULL) return false; - CalculateSyntheticValue(lldb::eUseSyntheticFilter); + CalculateSyntheticValue(eUseSyntheticFilter); if (m_synthetic_value) return true; @@ -1909,7 +1909,7 @@ } } -lldb::ValueObjectSP +ValueObjectSP ValueObject::GetValueForExpressionPath(const char* expression, const char** first_unparsed, ExpressionPathScanEndReason* reason_to_stop, @@ -1974,7 +1974,7 @@ int ValueObject::GetValuesForExpressionPath(const char* expression, - lldb::ValueObjectListSP& list, + ValueObjectListSP& list, const char** first_unparsed, ExpressionPathScanEndReason* reason_to_stop, ExpressionPathEndResultType* final_value_type, @@ -2058,7 +2058,7 @@ return 1; } -lldb::ValueObjectSP +ValueObjectSP ValueObject::GetValueForExpressionPath_Impl(const char* expression_cstr, const char** first_unparsed, ExpressionPathScanEndReason* reason_to_stop, @@ -2078,8 +2078,8 @@ const char* expression_cstr = *first_unparsed; // hide the top level expression_cstr - lldb::clang_type_t root_clang_type = root->GetClangType(); - lldb::clang_type_t pointee_clang_type; + clang_type_t root_clang_type = root->GetClangType(); + clang_type_t pointee_clang_type; Flags root_clang_type_info,pointee_clang_type_info; root_clang_type_info = Flags(ClangASTContext::GetTypeInfo(root_clang_type, GetClangAST(), &pointee_clang_type)); @@ -2149,7 +2149,7 @@ } else if (options.m_no_synthetic_children == false) // let's try with synthetic children { - child_valobj_sp = root->GetSyntheticValue(lldb::eUseSyntheticFilter)->GetChildMemberWithName(child_name, true); + child_valobj_sp = root->GetSyntheticValue(eUseSyntheticFilter)->GetChildMemberWithName(child_name, true); } // if we are here and options.m_no_synthetic_children is true, child_valobj_sp is going to be a NULL SP, @@ -2182,7 +2182,7 @@ } else if (options.m_no_synthetic_children == false) // let's try with synthetic children { - child_valobj_sp = root->GetSyntheticValue(lldb::eUseSyntheticFilter)->GetChildMemberWithName(child_name, true); + child_valobj_sp = root->GetSyntheticValue(eUseSyntheticFilter)->GetChildMemberWithName(child_name, true); } // if we are here and options.m_no_synthetic_children is true, child_valobj_sp is going to be a NULL SP, @@ -2287,8 +2287,8 @@ if (!child_valobj_sp) child_valobj_sp = root->GetSyntheticArrayMemberFromArray(index, true); if (!child_valobj_sp) - if (root->HasSyntheticValue() && root->GetSyntheticValue(lldb::eUseSyntheticFilter)->GetNumChildren() > index) - child_valobj_sp = root->GetSyntheticValue(lldb::eUseSyntheticFilter)->GetChildAtIndex(index, true); + if (root->HasSyntheticValue() && root->GetSyntheticValue(eUseSyntheticFilter)->GetNumChildren() > index) + child_valobj_sp = root->GetSyntheticValue(eUseSyntheticFilter)->GetChildAtIndex(index, true); if (child_valobj_sp) { root = child_valobj_sp; @@ -2327,7 +2327,7 @@ else { if (ClangASTType::GetMinimumLanguage(root->GetClangAST(), - root->GetClangType()) == lldb::eLanguageTypeObjC + root->GetClangType()) == eLanguageTypeObjC && ClangASTContext::IsPointerType(ClangASTType::GetPointeeType(root->GetClangType())) == false && @@ -2335,7 +2335,7 @@ && options.m_no_synthetic_children == false) { - root = root->GetSyntheticValue(lldb::eUseSyntheticFilter)->GetChildAtIndex(index, true); + root = root->GetSyntheticValue(eUseSyntheticFilter)->GetChildAtIndex(index, true); } else root = root->GetSyntheticArrayMemberFromPointer(index, true); @@ -2374,7 +2374,7 @@ } else if (root->HasSyntheticValue() && options.m_no_synthetic_children == false) { - root = root->GetSyntheticValue(lldb::eUseSyntheticFilter)->GetChildAtIndex(index, true); + root = root->GetSyntheticValue(eUseSyntheticFilter)->GetChildAtIndex(index, true); if (!root.get()) { *first_unparsed = expression_cstr; @@ -2484,8 +2484,8 @@ int ValueObject::ExpandArraySliceExpression(const char* expression_cstr, const char** first_unparsed, - lldb::ValueObjectSP root, - lldb::ValueObjectListSP& list, + ValueObjectSP root, + ValueObjectListSP& list, ExpressionPathScanEndReason* reason_to_stop, ExpressionPathEndResultType* final_result, const GetValueForExpressionPathOptions& options, @@ -2501,8 +2501,8 @@ const char* expression_cstr = *first_unparsed; // hide the top level expression_cstr - lldb::clang_type_t root_clang_type = root->GetClangType(); - lldb::clang_type_t pointee_clang_type; + clang_type_t root_clang_type = root->GetClangType(); + clang_type_t pointee_clang_type; Flags root_clang_type_info,pointee_clang_type_info; root_clang_type_info = Flags(ClangASTContext::GetTypeInfo(root_clang_type, GetClangAST(), &pointee_clang_type)); @@ -2789,7 +2789,7 @@ bool show_types, bool show_location, bool use_objc, - lldb::DynamicValueType use_dynamic, + DynamicValueType use_dynamic, bool use_synth, bool scope_already_checked, bool flat_output, @@ -2801,7 +2801,7 @@ { bool update_success = valobj->UpdateValueIfNeeded (use_dynamic, true); - if (update_success && use_dynamic != lldb::eNoDynamicValues) + if (update_success && use_dynamic != eNoDynamicValues) { ValueObject *dynamic_value = valobj->GetDynamicValue(use_dynamic).get(); if (dynamic_value) @@ -2832,9 +2832,9 @@ const char* typeName = valobj->GetTypeName().AsCString(""); s.Printf("(%s", typeName); // only show dynamic types if the user really wants to see types - if (show_types && use_dynamic != lldb::eNoDynamicValues && + if (show_types && use_dynamic != eNoDynamicValues && (/*strstr(typeName, "id") == typeName ||*/ - ClangASTType::GetMinimumLanguage(valobj->GetClangAST(), valobj->GetClangType()) == lldb::eLanguageTypeObjC)) + ClangASTType::GetMinimumLanguage(valobj->GetClangAST(), valobj->GetClangType()) == eLanguageTypeObjC)) { Process* process = valobj->GetUpdatePoint().GetProcessSP().get(); if (process == NULL) @@ -2969,8 +2969,8 @@ if (print_children && (!entry || entry->DoesPrintChildren() || !sum_cstr)) { ValueObjectSP synth_valobj = valobj->GetSyntheticValue(use_synth ? - lldb::eUseSyntheticFilter : - lldb::eNoSyntheticFilter); + eUseSyntheticFilter : + eNoSyntheticFilter); uint32_t num_children = synth_valobj->GetNumChildren(); bool print_dotdotdot = false; if (num_children) @@ -3095,7 +3095,7 @@ return valobj_sp; } -lldb::ValueObjectSP +ValueObjectSP ValueObject::Dereference (Error &error) { if (m_deref_valobj) @@ -3174,7 +3174,7 @@ } } -lldb::ValueObjectSP +ValueObjectSP ValueObject::AddressOf (Error &error) { if (m_addr_of_valobj_sp) @@ -3182,7 +3182,7 @@ AddressType address_type = eAddressTypeInvalid; const bool scalar_is_load_address = false; - lldb::addr_t addr = GetAddressOf (address_type, scalar_is_load_address); + addr_t addr = GetAddressOf (address_type, scalar_is_load_address); error.Clear(); if (addr != LLDB_INVALID_ADDRESS) { @@ -3223,13 +3223,13 @@ } -lldb::ValueObjectSP +ValueObjectSP ValueObject::CastPointerType (const char *name, ClangASTType &clang_ast_type) { - lldb::ValueObjectSP valobj_sp; + ValueObjectSP valobj_sp; AddressType address_type; const bool scalar_is_load_address = true; - lldb::addr_t ptr_value = GetPointerValue (address_type, scalar_is_load_address); + addr_t ptr_value = GetPointerValue (address_type, scalar_is_load_address); if (ptr_value != LLDB_INVALID_ADDRESS) { @@ -3243,13 +3243,13 @@ return valobj_sp; } -lldb::ValueObjectSP +ValueObjectSP ValueObject::CastPointerType (const char *name, TypeSP &type_sp) { - lldb::ValueObjectSP valobj_sp; + ValueObjectSP valobj_sp; AddressType address_type; const bool scalar_is_load_address = true; - lldb::addr_t ptr_value = GetPointerValue (address_type, scalar_is_load_address); + addr_t ptr_value = GetPointerValue (address_type, scalar_is_load_address); if (ptr_value != LLDB_INVALID_ADDRESS) { @@ -3465,7 +3465,7 @@ Thread *thread = exe_scope->CalculateThread(); if (thread != NULL) { - lldb::user_id_t new_thread_index = thread->GetIndexID(); + user_id_t new_thread_index = thread->GetIndexID(); if (new_thread_index != m_thread_id) { needs_update = true; Modified: lldb/trunk/source/Expression/DWARFExpression.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Expression/DWARFExpression.cpp?rev=138988&r1=138987&r2=138988&view=diff ============================================================================== --- lldb/trunk/source/Expression/DWARFExpression.cpp (original) +++ lldb/trunk/source/Expression/DWARFExpression.cpp Thu Sep 1 20:15:17 2011 @@ -30,6 +30,7 @@ #include "lldb/Symbol/ClangASTContext.h" #include "lldb/Symbol/Type.h" +#include "lldb/Target/ABI.h" #include "lldb/Target/ExecutionContext.h" #include "lldb/Target/Process.h" #include "lldb/Target/RegisterContext.h" @@ -264,7 +265,7 @@ } void -DWARFExpression::DumpLocation (Stream *s, uint32_t offset, uint32_t length, lldb::DescriptionLevel level) const +DWARFExpression::DumpLocation (Stream *s, uint32_t offset, uint32_t length, lldb::DescriptionLevel level, ABI *abi) const { if (!m_data.ValidOffsetForDataOfSize(offset, length)) return; @@ -409,7 +410,29 @@ case DW_OP_reg28: // 0x6C case DW_OP_reg29: // 0x6D case DW_OP_reg30: // 0x6E - case DW_OP_reg31: s->Printf("DW_OP_reg%i", op - DW_OP_reg0); break; // 0x6f + case DW_OP_reg31: // 0x6F + { + uint32_t reg_num = op - DW_OP_reg0; + if (abi) + { + RegisterInfo reg_info; + if (abi->GetRegisterInfoByKind(m_reg_kind, reg_num, reg_info)) + { + if (reg_info.name) + { + s->PutCString (reg_info.name); + break; + } + else if (reg_info.alt_name) + { + s->PutCString (reg_info.alt_name); + break; + } + } + } + s->Printf("DW_OP_reg%u", reg_num); break; + } + break; case DW_OP_breg0: case DW_OP_breg1: @@ -442,16 +465,80 @@ case DW_OP_breg28: case DW_OP_breg29: case DW_OP_breg30: - case DW_OP_breg31: s->Printf("DW_OP_breg%i(0x%x)", op - DW_OP_breg0, m_data.GetULEB128(&offset)); break; + case DW_OP_breg31: + { + uint32_t reg_num = op - DW_OP_breg0; + int64_t reg_offset = m_data.GetSLEB128(&offset); + if (abi) + { + RegisterInfo reg_info; + if (abi->GetRegisterInfoByKind(m_reg_kind, reg_num, reg_info)) + { + if (reg_info.name) + { + s->Printf("[%s%+lli]", reg_info.name, reg_offset); + break; + } + else if (reg_info.alt_name) + { + s->Printf("[%s%+lli]", reg_info.alt_name, reg_offset); + break; + } + } + } + s->Printf("DW_OP_breg%i(0x%llx)", reg_num, reg_offset); + } + break; case DW_OP_regx: // 0x90 1 ULEB128 register - s->Printf("DW_OP_regx(0x%x)", m_data.GetULEB128(&offset)); + { + uint64_t reg_num = m_data.GetULEB128(&offset); + if (abi) + { + RegisterInfo reg_info; + if (abi->GetRegisterInfoByKind(m_reg_kind, reg_num, reg_info)) + { + if (reg_info.name) + { + s->PutCString (reg_info.name); + break; + } + else if (reg_info.alt_name) + { + s->PutCString (reg_info.alt_name); + break; + } + } + } + s->Printf("DW_OP_regx(%llu)", reg_num); break; + } break; case DW_OP_fbreg: // 0x91 1 SLEB128 offset - s->Printf("DW_OP_fbreg(0x%x)",m_data.GetSLEB128(&offset)); + s->Printf("DW_OP_fbreg(%lli)",m_data.GetSLEB128(&offset)); break; case DW_OP_bregx: // 0x92 2 ULEB128 register followed by SLEB128 offset - s->Printf("DW_OP_bregx(0x%x, 0x%x)", m_data.GetULEB128(&offset), m_data.GetSLEB128(&offset)); + { + uint32_t reg_num = m_data.GetULEB128(&offset); + int64_t reg_offset = m_data.GetSLEB128(&offset); + if (abi) + { + RegisterInfo reg_info; + if (abi->GetRegisterInfoByKind(m_reg_kind, reg_num, reg_info)) + { + if (reg_info.name) + { + s->Printf("[%s%+lli]", reg_info.name, reg_offset); + break; + } + else if (reg_info.alt_name) + { + s->Printf("[%s%+lli]", reg_info.alt_name, reg_offset); + break; + } + } + } + s->Printf("DW_OP_bregx(reg=%u,offset=%lli)", reg_num, reg_offset); + } break; case DW_OP_piece: // 0x93 1 ULEB128 size of piece addressed s->Printf("DW_OP_piece(0x%x)", m_data.GetULEB128(&offset)); @@ -546,7 +633,7 @@ } void -DWARFExpression::SetRegisterKind (int reg_kind) +DWARFExpression::SetRegisterKind (RegisterKind reg_kind) { m_reg_kind = reg_kind; } @@ -558,7 +645,7 @@ } void -DWARFExpression::GetDescription (Stream *s, lldb::DescriptionLevel level, addr_t location_list_base_addr) const +DWARFExpression::GetDescription (Stream *s, lldb::DescriptionLevel level, addr_t location_list_base_addr, ABI *abi) const { if (IsLocationList()) { @@ -578,7 +665,7 @@ addr_range.Dump(s, 0, 8); s->PutChar('{'); uint32_t location_length = m_data.GetU16(&offset); - DumpLocation (s, offset, location_length, level); + DumpLocation (s, offset, location_length, level, abi); s->PutChar('}'); offset += location_length; } @@ -606,7 +693,7 @@ else { // We have a normal location that contains DW_OP location opcodes - DumpLocation (s, 0, m_data.GetByteSize(), level); + DumpLocation (s, 0, m_data.GetByteSize(), level, abi); } } @@ -791,7 +878,8 @@ DWARFExpression::DumpLocationForAddress (Stream *s, lldb::DescriptionLevel level, addr_t base_addr, - addr_t address) + addr_t address, + ABI *abi) { uint32_t offset = 0; uint32_t length = 0; @@ -800,7 +888,7 @@ { if (length > 0) { - DumpLocation(s, offset, length, level); + DumpLocation(s, offset, length, level, abi); return true; } } Modified: lldb/trunk/source/Plugins/Process/Utility/RegisterContextLLDB.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Process/Utility/RegisterContextLLDB.cpp?rev=138988&r1=138987&r2=138988&view=diff ============================================================================== --- lldb/trunk/source/Plugins/Process/Utility/RegisterContextLLDB.cpp (original) +++ lldb/trunk/source/Plugins/Process/Utility/RegisterContextLLDB.cpp Thu Sep 1 20:15:17 2011 @@ -815,7 +815,7 @@ UnwindPlan::Row::RegisterLocation unwindplan_regloc; bool have_unwindplan_regloc = false; - int unwindplan_registerkind = -1; + RegisterKind unwindplan_registerkind = (RegisterKind)-1; if (m_fast_unwind_plan_sp) { Modified: lldb/trunk/source/Plugins/SymbolFile/DWARF/NameToDIE.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/SymbolFile/DWARF/NameToDIE.cpp?rev=138988&r1=138987&r2=138988&view=diff ============================================================================== --- lldb/trunk/source/Plugins/SymbolFile/DWARF/NameToDIE.cpp (original) +++ lldb/trunk/source/Plugins/SymbolFile/DWARF/NameToDIE.cpp Thu Sep 1 20:15:17 2011 @@ -174,172 +174,184 @@ void NameToDIE::Hash (Stream *s, SymbolFileDWARF *dwarf) { - if (m_collection.empty()) - return; - - typedef std::vector hash_collection; - hash_collection hash_entries; - collection::const_iterator pos, end = m_collection.end(); - for (pos = m_collection.begin(); pos != end; ++pos) - { - HashEntry entry = { dl_new_hash (pos->first), pos->second.cu_idx, pos->second.die_idx, pos->first }; - hash_entries.push_back (entry); - } - -// const DataExtractor &debug_str_data = dwarf->get_debug_str_data(); - - const uint32_t hash_entries_size = hash_entries.size(); - - uint32_t i; - DWARFDebugInfo *debug_info = dwarf->DebugInfo(); - - uint32_t num_buckets; - if (hash_entries_size > 1024) - num_buckets = closest_power_2_less_than_n (hash_entries_size/16); - else if (hash_entries_size > 128) - num_buckets = closest_power_2_less_than_n (hash_entries_size/8); - else - num_buckets = closest_power_2_less_than_n (hash_entries_size/4); - if (num_buckets == 0) - num_buckets = 1; - - //for (uint32_t power_2 = 0x10; power_2 <= hash_entries_size; power_2 <<= 1) - { -// if (num_buckets > 0x10 && num_buckets > hash_entries_size) -// break; - - typedef std::vector uint32_array; - typedef std::map HashBucketEntryMap; - std::vector hash_buckets; - hash_buckets.resize(num_buckets); - - uint32_t bucket_entry_empties = 0; - uint32_t bucket_entry_single = 0; - uint32_t bucket_entry_collisions = 0; - uint32_t names_entry_single = 0; - uint32_t names_entry_collisions = 0; - //StreamString hash_file_data(Stream::eBinary, dwarf->GetObjectFile()->GetAddressByteSize(), dwarf->GetObjectFile()->GetByteSize()); - - // Write hash table header -// hash_file_data.PutHex32 (1); // Version -// hash_file_data.PutHex32 (4); // Sizeof bucket data -// hash_file_data.PutHex32 (num_buckets); -// hash_file_data.PutHex32 (0); // Flags - - s->Printf("HashHeader = { version = %u, bucket_info_size = %u, bucket_count = %u, flags = 0x%8.8x }\n", 1, (uint32_t)sizeof(HashBucketInfo), num_buckets, 0); - - for (i=0; iGetCompileUnitAtIndex (hash_entries[i].cu_idx); - cu->ExtractDIEsIfNeeded(false); - DWARFDebugInfoEntry *die = cu->GetDIEAtIndexUnchecked(hash_entries[i].die_idx); - hash_buckets[bucket_idx][hash].name_to_die[hash_entries[i].name].push_back(die->GetOffset()); - } - uint32_t byte_size = sizeof(HashHeader); // Header - uint32_t data_offset = 0; - uint32_t num_bucket_entries; - uint32_t bucket_data_size; - // Now for each bucket we write the offset to the data for each bucket - // The offset is currently a zero based offset from the end of this table - // which is header.num_buckets * sizeof(uint32_t) long. - for (i=0; ifirst) + pos->second.GetByteSize(); - } - if (bucket_data_size > 0) - { - // Offset to bucket data -// hash_file_data.PutHex32 (data_offset); - s->Printf("bucket[%u] {0x%8.8x}\n", i, data_offset); - data_offset += bucket_data_size; - } - else - { - // Invalid offset that indicates an empty bucket -// hash_file_data.PutHex32 (UINT32_MAX); - s->Printf("bucket[%u] {0xFFFFFFFF}\n", i); - ++bucket_entry_empties; - } - } - - // Now we write the bucket data for each bucket that corresponds to each bucket - // offset from above. - data_offset = 0; - uint32_t total_num_name_entries = 0; - uint32_t total_num_bucket_entries = 0; - uint32_t total_non_empty_buckets = 0; - for (i=0; iPrintf("0x%8.8x: BucketEntry:\n", data_offset, num_bucket_entries); - bucket_data_size = 0; - uint32_t num_bucket_entries = 0; - HashBucketEntryMap::const_iterator pos, end = bucket_entry.end(); - for (pos = bucket_entry.begin(); pos != end; ++pos) - { - ++num_bucket_entries; - uint32_t hash_data_len = pos->second.GetByteSize(); - s->Printf(" hash = 0x%8.8x, length = 0x%8.8x:\n", pos->first, hash_data_len); -// hash_file_data.PutHex32 (pos->first); // Write the hash -// hash_file_data.PutHex32 (hash_data_len); // The length of the data for this hash not including the length itself - - const HashBucketEntryCStr &hash_entry = pos->second; - uint32_t num_name_entries = 0; - NameToDIEArrayMap::const_iterator name_pos, name_end = hash_entry.name_to_die.end(); - for (name_pos = hash_entry.name_to_die.begin(); name_pos != name_end; ++name_pos) - { - ++num_name_entries; - ++total_num_name_entries; - s->Printf(" name = %p '%s'\n", name_pos->first, name_pos->first); -// hash_file_data.PutHex32 (pos->first); // Write the hash -// hash_file_data.PutHex32 (hash_data_len); // The length of the data for this hash not including the length itself - - - const uint32_t num_dies = name_pos->second.size(); - s->Printf(" dies[%u] = { ", num_dies); - for (uint32_t j=0; j < num_dies; ++j) - s->Printf("0x%8.8x ", name_pos->second[j]); - s->PutCString("}\n"); - } - if (num_name_entries == 1) - ++names_entry_single; - else if (num_name_entries > 1) - ++names_entry_collisions; - bucket_data_size += sizeof(pos->first) + hash_data_len; - } - data_offset += bucket_data_size; - byte_size += bucket_data_size; - total_num_bucket_entries += num_bucket_entries; - if (num_bucket_entries == 1) - ++bucket_entry_single; - else if (num_bucket_entries > 1) - ++bucket_entry_collisions; - } - - s->Printf ("Trying size of %u buckets, %u items:\n", num_buckets, hash_entries_size); - s->Printf ("buckets: empty = %u (%%%f)\n", bucket_entry_empties, ((float)bucket_entry_empties/(float)num_buckets) * 100.0f); - s->Printf ("buckets: single = %u\n", bucket_entry_single); - s->Printf ("buckets: multiple = %u (avg = %f entries/bucket, avg = %f entries/non-empty bucket)\n", - bucket_entry_collisions, - (float)total_num_bucket_entries / (float)num_buckets, - (float)total_num_bucket_entries / (float)total_non_empty_buckets); - s->Printf ("names : single = %u of %u\n", names_entry_single, total_num_name_entries); - s->Printf ("names : multiple = %u of %u\n", names_entry_collisions, total_num_name_entries); - s->Printf ("total byte size = %u\n", byte_size); - s->PutCString ("\n----------------------------------------------------------------------\n\n"); - } +// if (m_collection.empty()) +// return; +// +// typedef std::vector hash_collection; +// hash_collection hash_entries; +// collection::const_iterator pos, end = m_collection.end(); +// for (pos = m_collection.begin(); pos != end; ++pos) +// { +// HashEntry entry = { dl_new_hash (pos->first), pos->second.cu_idx, pos->second.die_idx, pos->first }; +// hash_entries.push_back (entry); +// } +// +//// const DataExtractor &debug_str_data = dwarf->get_debug_str_data(); +// +//// uint32_t collisions = 0; +//// for (i=1; iPrintf("count = %u, collisions = %u\n", hash_entries_size, collisions); +// +//// for (i=0; iPrintf("0x%8.8x: cu = %8u, die = %8u, name = '%s'\n", +//// hash_entries[i].hash, +//// hash_entries[i].cu_idx, +//// hash_entries[i].die_idx, +//// hash_entries[i].name); +// DWARFDebugInfo *debug_info = dwarf->DebugInfo(); +// +// uint32_t num_buckets; +// if (hash_entries_size > 1024) +// num_buckets = closest_power_2_less_than_n (hash_entries_size/16); +// else if (hash_entries_size > 128) +// num_buckets = closest_power_2_less_than_n (hash_entries_size/8); +// else +// num_buckets = closest_power_2_less_than_n (hash_entries_size/4); +// if (num_buckets == 0) +// num_buckets = 1; +// +// //for (uint32_t power_2 = 0x10; power_2 <= hash_entries_size; power_2 <<= 1) +// { +//// if (num_buckets > 0x10 && num_buckets > hash_entries_size) +//// break; +// +// typedef std::vector uint32_array; +// typedef std::map HashBucketEntryMap; +// std::vector hash_buckets; +// hash_buckets.resize(num_buckets); +// +// uint32_t bucket_entry_empties = 0; +// uint32_t bucket_entry_single = 0; +// uint32_t bucket_entry_collisions = 0; +// uint32_t names_entry_single = 0; +// uint32_t names_entry_collisions = 0; +// //StreamString hash_file_data(Stream::eBinary, dwarf->GetObjectFile()->GetAddressByteSize(), dwarf->GetObjectFile()->GetByteSize()); +// +// // Write hash table header +//// hash_file_data.PutHex32 (1); // Version +//// hash_file_data.PutHex32 (4); // Sizeof bucket data +//// hash_file_data.PutHex32 (num_buckets); +//// hash_file_data.PutHex32 (0); // Flags +// +// s->Printf("HashHeader = { version = %u, bucket_info_size = %u, bucket_count = %u, flags = 0x%8.8x }\n", 1, (uint32_t)sizeof(HashBucketInfo), num_buckets, 0); +// +// for (i=0; iGetCompileUnitAtIndex (hash_entries[i].cu_idx); +// cu->ExtractDIEsIfNeeded(false); +// DWARFDebugInfoEntry *die = cu->GetDIEAtIndexUnchecked(hash_entries[i].die_idx); +// hash_buckets[bucket_idx][hash].name_to_die[hash_entries[i].name].push_back(die->GetOffset()); +// } +// uint32_t byte_size = sizeof(HashHeader); // Header +// uint32_t data_offset = 0; +// uint32_t num_bucket_entries; +// uint32_t bucket_data_size; +// // Now for each bucket we write the offset to the data for each bucket +// // The offset is currently a zero based offset from the end of this table +// // which is header.num_buckets * sizeof(uint32_t) long. +// for (i=0; ifirst) + pos->second.GetByteSize(); +// } +// if (bucket_data_size > 0) +// { +// // Offset to bucket data +//// hash_file_data.PutHex32 (data_offset); +// s->Printf("bucket[%u] {0x%8.8x}\n", i, data_offset); +// data_offset += bucket_data_size; +// } +// else +// { +// // Invalid offset that indicates an empty bucket +//// hash_file_data.PutHex32 (UINT32_MAX); +// s->Printf("bucket[%u] {0xFFFFFFFF}\n", i); +// ++bucket_entry_empties; +// } +// } +// +// // Now we write the bucket data for each bucket that corresponds to each bucket +// // offset from above. +// data_offset = 0; +// uint32_t total_num_name_entries = 0; +// uint32_t total_num_bucket_entries = 0; +// uint32_t total_non_empty_buckets = 0; +// for (i=0; iPrintf("0x%8.8x: BucketEntry:\n", data_offset, num_bucket_entries); +// bucket_data_size = 0; +// uint32_t num_bucket_entries = 0; +// HashBucketEntryMap::const_iterator pos, end = bucket_entry.end(); +// for (pos = bucket_entry.begin(); pos != end; ++pos) +// { +// ++num_bucket_entries; +// uint32_t hash_data_len = pos->second.GetByteSize(); +// s->Printf(" hash = 0x%8.8x, length = 0x%8.8x:\n", pos->first, hash_data_len); +//// hash_file_data.PutHex32 (pos->first); // Write the hash +//// hash_file_data.PutHex32 (hash_data_len); // The length of the data for this hash not including the length itself +// +// const HashBucketEntryCStr &hash_entry = pos->second; +// uint32_t num_name_entries = 0; +// NameToDIEArrayMap::const_iterator name_pos, name_end = hash_entry.name_to_die.end(); +// for (name_pos = hash_entry.name_to_die.begin(); name_pos != name_end; ++name_pos) +// { +// ++num_name_entries; +// ++total_num_name_entries; +// s->Printf(" name = %p '%s'\n", name_pos->first, name_pos->first); +//// hash_file_data.PutHex32 (pos->first); // Write the hash +//// hash_file_data.PutHex32 (hash_data_len); // The length of the data for this hash not including the length itself +// +// +// const uint32_t num_dies = name_pos->second.size(); +// s->Printf(" dies[%u] = { ", num_dies); +// for (uint32_t j=0; j < num_dies; ++j) +// s->Printf("0x%8.8x ", name_pos->second[j]); +// s->PutCString("}\n"); +// } +// if (num_name_entries == 1) +// ++names_entry_single; +// else if (num_name_entries > 1) +// ++names_entry_collisions; +// bucket_data_size += sizeof(pos->first) + hash_data_len; +// } +// data_offset += bucket_data_size; +// byte_size += bucket_data_size; +// total_num_bucket_entries += num_bucket_entries; +// if (num_bucket_entries == 1) +// ++bucket_entry_single; +// else if (num_bucket_entries > 1) +// ++bucket_entry_collisions; +// } +// +// s->Printf ("Trying size of %u buckets, %u items:\n", num_buckets, hash_entries_size); +// s->Printf ("buckets: empty = %u (%%%f)\n", bucket_entry_empties, ((float)bucket_entry_empties/(float)num_buckets) * 100.0f); +// s->Printf ("buckets: single = %u\n", bucket_entry_single); +// s->Printf ("buckets: multiple = %u (avg = %f entries/bucket, avg = %f entries/non-empty bucket)\n", +// bucket_entry_collisions, +// (float)total_num_bucket_entries / (float)num_buckets, +// (float)total_num_bucket_entries / (float)total_non_empty_buckets); +// s->Printf ("names : single = %u of %u\n", names_entry_single, total_num_name_entries); +// s->Printf ("names : multiple = %u of %u\n", names_entry_collisions, total_num_name_entries); +// s->Printf ("total byte size = %u\n", byte_size); +// s->PutCString ("\n----------------------------------------------------------------------\n\n"); +// } } Modified: lldb/trunk/source/Symbol/DWARFCallFrameInfo.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Symbol/DWARFCallFrameInfo.cpp?rev=138988&r1=138987&r2=138988&view=diff ============================================================================== --- lldb/trunk/source/Symbol/DWARFCallFrameInfo.cpp (original) +++ lldb/trunk/source/Symbol/DWARFCallFrameInfo.cpp Thu Sep 1 20:15:17 2011 @@ -26,7 +26,7 @@ using namespace lldb; using namespace lldb_private; -DWARFCallFrameInfo::DWARFCallFrameInfo(ObjectFile& objfile, SectionSP& section, uint32_t reg_kind, bool is_eh_frame) : +DWARFCallFrameInfo::DWARFCallFrameInfo(ObjectFile& objfile, SectionSP& section, lldb::RegisterKind reg_kind, bool is_eh_frame) : m_objfile (objfile), m_section (section), m_reg_kind (reg_kind), // The flavor of registers that the CFI data uses (enum RegisterKind) Modified: lldb/trunk/source/Symbol/Variable.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Symbol/Variable.cpp?rev=138988&r1=138987&r2=138988&view=diff ============================================================================== --- lldb/trunk/source/Symbol/Variable.cpp (original) +++ lldb/trunk/source/Symbol/Variable.cpp Thu Sep 1 20:15:17 2011 @@ -18,6 +18,7 @@ #include "lldb/Symbol/SymbolContext.h" #include "lldb/Symbol/Type.h" #include "lldb/Symbol/VariableList.h" +#include "lldb/Target/ABI.h" #include "lldb/Target/Process.h" #include "lldb/Target/RegisterContext.h" #include "lldb/Target/StackFrame.h" @@ -130,7 +131,13 @@ if (variable_sc.function) loclist_base_addr = variable_sc.function->GetAddressRange().GetBaseAddress().GetFileAddress(); } - m_location.GetDescription(s, lldb::eDescriptionLevelBrief, loclist_base_addr); + ABI *abi = NULL; + if (m_owner_scope) + { + Module *module = m_owner_scope->CalculateSymbolContextModule(); + abi = ABI::FindPlugin (module->GetArchitecture()).get(); + } + m_location.GetDescription(s, lldb::eDescriptionLevelBrief, loclist_base_addr, abi); } if (m_external) @@ -463,6 +470,13 @@ CalculateSymbolContext(&sc); if (sc.module_sp.get() == address.GetModule()) { + ABI *abi = NULL; + if (m_owner_scope) + { + Module *module = m_owner_scope->CalculateSymbolContextModule(); + abi = ABI::FindPlugin (module->GetArchitecture()).get(); + } + const addr_t file_addr = address.GetFileAddress(); if (sc.function) { @@ -474,14 +488,15 @@ return m_location.DumpLocationForAddress (s, eDescriptionLevelBrief, loclist_base_file_addr, - file_addr); + file_addr, + abi); } } return m_location.DumpLocationForAddress (s, eDescriptionLevelBrief, LLDB_INVALID_ADDRESS, - file_addr); - + file_addr, + abi); } } return false; From gclayton at apple.com Thu Sep 1 23:03:59 2011 From: gclayton at apple.com (Greg Clayton) Date: Fri, 02 Sep 2011 04:03:59 -0000 Subject: [Lldb-commits] [lldb] r138996 - in /lldb/trunk/source: Breakpoint/BreakpointResolverName.cpp Plugins/SymbolFile/DWARF/HashedNameToDIE.cpp Plugins/SymbolFile/DWARF/HashedNameToDIE.h Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp Plugins/SymbolFile/DWARF/SymbolFileDWARF.h Message-ID: <20110902040359.50BB92A6C12C@llvm.org> Author: gclayton Date: Thu Sep 1 23:03:59 2011 New Revision: 138996 URL: http://llvm.org/viewvc/llvm-project?rev=138996&view=rev Log: Added alpha .debug_names and .debug_types support in the DWARF parser. Modified: lldb/trunk/source/Breakpoint/BreakpointResolverName.cpp lldb/trunk/source/Plugins/SymbolFile/DWARF/HashedNameToDIE.cpp lldb/trunk/source/Plugins/SymbolFile/DWARF/HashedNameToDIE.h lldb/trunk/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp lldb/trunk/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.h Modified: lldb/trunk/source/Breakpoint/BreakpointResolverName.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Breakpoint/BreakpointResolverName.cpp?rev=138996&r1=138995&r2=138996&view=diff ============================================================================== --- lldb/trunk/source/Breakpoint/BreakpointResolverName.cpp (original) +++ lldb/trunk/source/Breakpoint/BreakpointResolverName.cpp Thu Sep 1 23:03:59 2011 @@ -167,13 +167,15 @@ case Breakpoint::Exact: if (context.module_sp) { - if (m_func_name_type_mask & (eFunctionNameTypeBase | eFunctionNameTypeFull)) - context.module_sp->FindSymbolsWithNameAndType (m_func_name, eSymbolTypeCode, sym_list); - context.module_sp->FindFunctions (m_func_name, - m_func_name_type_mask, - include_symbols, - append, - func_list); + if (context.module_sp->FindFunctions (m_func_name, + m_func_name_type_mask, + include_symbols, + append, + func_list) == 0) + { + if (m_func_name_type_mask & (eFunctionNameTypeBase | eFunctionNameTypeFull)) + context.module_sp->FindSymbolsWithNameAndType (m_func_name, eSymbolTypeCode, sym_list); + } } break; case Breakpoint::Regexp: Modified: lldb/trunk/source/Plugins/SymbolFile/DWARF/HashedNameToDIE.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/SymbolFile/DWARF/HashedNameToDIE.cpp?rev=138996&r1=138995&r2=138996&view=diff ============================================================================== --- lldb/trunk/source/Plugins/SymbolFile/DWARF/HashedNameToDIE.cpp (original) +++ lldb/trunk/source/Plugins/SymbolFile/DWARF/HashedNameToDIE.cpp Thu Sep 1 23:03:59 2011 @@ -38,16 +38,23 @@ m_data (data), m_header () { +} + +void +HashedNameToDIE::Initialize() +{ uint32_t offset = 0; m_header.version = m_data.GetU16(&offset); - m_header.hash_type = m_data.GetU8(&offset); - m_header.hash_index_bitsize = m_data.GetU8(&offset); - m_header.num_buckets = m_data.GetU32(&offset); - m_header.num_hashes = m_data.GetU32(&offset); - m_header.die_offset_base = m_data.GetU32(&offset); + if (m_header.version) + { + m_header.hash_type = m_data.GetU8(&offset); + m_header.hash_index_bitsize = m_data.GetU8(&offset); + m_header.num_buckets = m_data.GetU32(&offset); + m_header.num_hashes = m_data.GetU32(&offset); + m_header.die_offset_base = m_data.GetU32(&offset); + } } - size_t HashedNameToDIE::Find (const ConstString &name, DIEArray &die_ofsets) const { @@ -62,7 +69,7 @@ const uint32_t bucket_idx = name_hash % m_header.num_buckets; // Calculate the offset for the bucket entry for the bucket index - uint32_t offset = GetOffsetForBucket (bucket_idx); + uint32_t offset = GetOffsetOfBucketEntry (bucket_idx); // Extract the bucket entry. const uint32_t bucket_entry = m_data.GetU32 (&offset); @@ -77,7 +84,7 @@ const uint32_t hash_count = bucket_entry >> m_header.hash_index_bitsize; const uint32_t hash_end_idx = hash_idx + hash_count; // Figure out the offset to the hash value by index - uint32_t hash_offset = GetOffsetForHash (hash_idx); + uint32_t hash_offset = GetOffsetOfHashValue (hash_idx); for (uint32_t idx = hash_idx; idx < hash_end_idx; ++idx) { // Extract the hash value and see if it matches our string @@ -87,20 +94,24 @@ // The hash matches, but we still need to verify that the // C string matches in case we have a hash collision. Figure // out the offset for the data associated with this hash entry - offset = GetOffsetForOffset (hash_idx); + offset = GetOffsetOfHashDataOffset (idx); // Extract the first 32 bit value which is the .debug_str offset // of the string we need - const uint32_t str_offset = m_data.GetU32 (&offset); + uint32_t hash_data_offset = m_data.GetU32 (&offset); + const uint32_t str_offset = m_data.GetU32 (&hash_data_offset); // Extract the C string and comapare it const char *cstr_name = m_dwarf->get_debug_str_data().PeekCStr(str_offset); - if (strcmp(name_cstr, cstr_name) == 0) + if (cstr_name) { - // We have a match, now extract the DIE count - const uint32_t die_count = m_data.GetU32 (&offset); - // Now extract "die_count" DIE offsets and put them into the - // results - for (uint32_t die_idx = 0; die_idx < die_count; ++die_idx) - die_ofsets.push_back(m_data.GetU32 (&offset)); + if (strcmp(name_cstr, cstr_name) == 0) + { + // We have a match, now extract the DIE count + const uint32_t die_count = m_data.GetU32 (&hash_data_offset); + // Now extract "die_count" DIE offsets and put them into the + // results + for (uint32_t die_idx = 0; die_idx < die_count; ++die_idx) + die_ofsets.push_back(m_data.GetU32 (&hash_data_offset)); + } } } } Modified: lldb/trunk/source/Plugins/SymbolFile/DWARF/HashedNameToDIE.h URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/SymbolFile/DWARF/HashedNameToDIE.h?rev=138996&r1=138995&r2=138996&view=diff ============================================================================== --- lldb/trunk/source/Plugins/SymbolFile/DWARF/HashedNameToDIE.h (original) +++ lldb/trunk/source/Plugins/SymbolFile/DWARF/HashedNameToDIE.h Thu Sep 1 23:03:59 2011 @@ -31,7 +31,7 @@ uint32_t die_offset_base; Header() : - version(1), + version(0), hash_type (0), hash_index_bitsize (0), num_buckets(0), @@ -49,6 +49,12 @@ { } + bool + IsValid () const + { + return m_header.version > 0; + } + uint32_t GetHashIndexMask () const { @@ -56,7 +62,7 @@ } uint32_t - GetOffsetForBucket (uint32_t idx) const + GetOffsetOfBucketEntry (uint32_t idx) const { if (idx < m_header.num_buckets) return sizeof(Header) + 4 * idx; @@ -64,18 +70,25 @@ } uint32_t - GetOffsetForHash (uint32_t idx) const + GetOffsetOfHashValue (uint32_t idx) const { if (idx < m_header.num_hashes) - return sizeof(Header) + 4 * m_header.num_buckets + 4 * idx; + return sizeof(Header) + + 4 * m_header.num_buckets + + 4 * idx; return UINT32_MAX; } uint32_t - GetOffsetForOffset (uint32_t idx) const + GetOffsetOfHashDataOffset (uint32_t idx) const { if (idx < m_header.num_hashes) - return sizeof(Header) + 4 * m_header.num_buckets + 4 * m_header.num_hashes + 4 * idx; + { + return sizeof(Header) + + 4 * m_header.num_buckets + + 4 * m_header.num_hashes + + 4 * idx; + } return UINT32_MAX; } @@ -90,6 +103,9 @@ Find (const lldb_private::RegularExpression& regex, DIEArray &die_ofsets) const; + void + Initialize(); + protected: SymbolFileDWARF *m_dwarf; const lldb_private::DataExtractor &m_data; Modified: lldb/trunk/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp?rev=138996&r1=138995&r2=138996&view=diff ============================================================================== --- lldb/trunk/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp (original) +++ lldb/trunk/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp Thu Sep 1 23:03:59 2011 @@ -174,6 +174,7 @@ m_aranges(), m_info(), m_line(), + m_debug_names (this, m_data_debug_names), m_function_basename_index(), m_function_fullname_index(), m_function_method_index(), @@ -187,6 +188,8 @@ m_ranges(), m_unique_ast_type_map () { + get_debug_names_data(); + m_debug_names.Initialize(); } SymbolFileDWARF::~SymbolFileDWARF() @@ -2075,6 +2078,76 @@ } +uint32_t +SymbolFileDWARF::ResolveFunctions (const DIEArray &die_offsets, + SymbolContextList& sc_list) +{ + DWARFDebugInfo* info = DebugInfo(); + if (info == NULL) + return 0; + + const uint32_t sc_list_initial_size = sc_list.GetSize(); + SymbolContext sc; + sc.module_sp = m_obj_file->GetModule()->GetSP(); + assert (sc.module_sp); + + DWARFCompileUnit* dwarf_cu = NULL; + const size_t num_matches = die_offsets.size(); + for (size_t i=0; iGetDIEPtrWithCompileUnitHint (die_offset, &dwarf_cu); + + const DWARFDebugInfoEntry* inlined_die = NULL; + if (die->Tag() == DW_TAG_inlined_subroutine) + { + inlined_die = die; + + while ((die = die->GetParent()) != NULL) + { + if (die->Tag() == DW_TAG_subprogram) + break; + } + } + assert (die->Tag() == DW_TAG_subprogram); + if (GetFunction (dwarf_cu, die, sc)) + { + Address addr; + // Parse all blocks if needed + if (inlined_die) + { + sc.block = sc.function->GetBlock (true).FindBlockByID (inlined_die->GetOffset()); + assert (sc.block != NULL); + if (sc.block->GetStartAddress (addr) == false) + addr.Clear(); + } + else + { + sc.block = NULL; + addr = sc.function->GetAddressRange().GetBaseAddress(); + } + + if (addr.IsValid()) + { + + // We found the function, so we should find the line table + // and line table entry as well + LineTable *line_table = sc.comp_unit->GetLineTable(); + if (line_table == NULL) + { + if (ParseCompileUnitLineTable(sc)) + line_table = sc.comp_unit->GetLineTable(); + } + if (line_table != NULL) + line_table->FindLineEntryByAddress (addr, sc.line_entry); + + sc_list.Append(sc); + } + } + } + return sc_list.GetSize() - sc_list_initial_size; +} + void SymbolFileDWARF::FindFunctions ( @@ -2253,7 +2326,19 @@ // Remember how many sc_list are in the list before we search in case // we are appending the results to a variable list. - uint32_t original_size = sc_list.GetSize(); + + if (m_debug_names.IsValid()) + { + DIEArray die_offsets; + const uint32_t num_matches = m_debug_names.Find(name, die_offsets); + if (num_matches > 0) + { + return ResolveFunctions (die_offsets, sc_list); + } + return 0; + } + + const uint32_t original_size = sc_list.GetSize(); // Index the DWARF if we haven't already if (!m_indexed) Modified: lldb/trunk/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.h URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.h?rev=138996&r1=138995&r2=138996&view=diff ============================================================================== --- lldb/trunk/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.h (original) +++ lldb/trunk/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.h Thu Sep 1 23:03:59 2011 @@ -32,6 +32,7 @@ // Project includes #include "DWARFDefines.h" +#include "HashedNameToDIE.h" #include "NameToDIE.h" #include "UniqueDWARFASTType.h" @@ -308,6 +309,10 @@ uint32_t& byte_stride, uint32_t& bit_stride); + uint32_t ResolveFunctions ( + const DIEArray &die_offsets, + lldb_private::SymbolContextList& sc_list); + void FindFunctions( const lldb_private::ConstString &name, const NameToDIE &name_to_die, @@ -384,6 +389,7 @@ std::auto_ptr m_aranges; std::auto_ptr m_info; std::auto_ptr m_line; + HashedNameToDIE m_debug_names; NameToDIE m_function_basename_index; // All concrete functions NameToDIE m_function_fullname_index; // All concrete functions NameToDIE m_function_method_index; // All inlined functions From johnny.chen at apple.com Fri Sep 2 16:13:08 2011 From: johnny.chen at apple.com (Johnny Chen) Date: Fri, 02 Sep 2011 21:13:08 -0000 Subject: [Lldb-commits] [lldb] r139034 - in /lldb/trunk/tools/debugserver/source: DNBArch.h MacOSX/i386/DNBArchImplI386.cpp MacOSX/i386/DNBArchImplI386.h MacOSX/x86_64/DNBArchImplX86_64.cpp MacOSX/x86_64/DNBArchImplX86_64.h Message-ID: <20110902211308.2F12B2A6C12C@llvm.org> Author: johnny Date: Fri Sep 2 16:13:07 2011 New Revision: 139034 URL: http://llvm.org/viewvc/llvm-project?rev=139034&view=rev Log: Watchpoint work in progress: Add a virtual method GetHardwareWatchpointHit() to the DNBArchProtocol base class which consults the architecture to return the watchpoint hit; otherwise return an invalid index. Add impl. of the method to X86_64 and I386 subclasses, plus reset the debug status register before we resume execution of the inferior thread. Modified: lldb/trunk/tools/debugserver/source/DNBArch.h lldb/trunk/tools/debugserver/source/MacOSX/i386/DNBArchImplI386.cpp lldb/trunk/tools/debugserver/source/MacOSX/i386/DNBArchImplI386.h lldb/trunk/tools/debugserver/source/MacOSX/x86_64/DNBArchImplX86_64.cpp lldb/trunk/tools/debugserver/source/MacOSX/x86_64/DNBArchImplX86_64.h Modified: lldb/trunk/tools/debugserver/source/DNBArch.h URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/tools/debugserver/source/DNBArch.h?rev=139034&r1=139033&r2=139034&view=diff ============================================================================== --- lldb/trunk/tools/debugserver/source/DNBArch.h (original) +++ lldb/trunk/tools/debugserver/source/DNBArch.h Fri Sep 2 16:13:07 2011 @@ -79,6 +79,7 @@ virtual uint32_t EnableHardwareWatchpoint (nub_addr_t addr, nub_size_t size, bool read, bool write) { return INVALID_NUB_HW_INDEX; } virtual bool DisableHardwareBreakpoint (uint32_t hw_index) { return false; } virtual bool DisableHardwareWatchpoint (uint32_t hw_index) { return false; } + virtual uint32_t GetHardwareWatchpointHit() { return INVALID_NUB_HW_INDEX; } virtual bool StepNotComplete () { return false; } }; Modified: lldb/trunk/tools/debugserver/source/MacOSX/i386/DNBArchImplI386.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/tools/debugserver/source/MacOSX/i386/DNBArchImplI386.cpp?rev=139034&r1=139033&r2=139034&view=diff ============================================================================== --- lldb/trunk/tools/debugserver/source/MacOSX/i386/DNBArchImplI386.cpp (original) +++ lldb/trunk/tools/debugserver/source/MacOSX/i386/DNBArchImplI386.cpp Fri Sep 2 16:13:07 2011 @@ -545,6 +545,17 @@ // This is the primary thread, let the arch do anything it needs EnableHardwareSingleStep(true); } + + // Reset the debug status register before we resume. + kern_return_t kret = GetDBGState(false); + DNBLogThreadedIf(LOG_WATCHPOINTS, "DNBArchImplI386::ThreadWillResume() GetDBGState() => 0x%8.8x.", kret); + if (kret == KERN_SUCCESS) + { + DBG debug_state = m_state.context.dbg; + ClearWatchpointHits(debug_state); + kret = SetDBGState(); + DNBLogThreadedIf(LOG_WATCHPOINTS, "DNBArchImplI386::ThreadWillResume() SetDBGState() => 0x%8.8x.", kret); + } } bool @@ -625,6 +636,29 @@ return false; } +// Iterate through the debug status register; return the index of the first hit. +uint32_t +DNBArchImplI386::GetHardwareWatchpointHit() +{ + // Read the debug state + kern_return_t kret = GetDBGState(false); + DNBLogThreadedIf(LOG_WATCHPOINTS, "DNBArchImplI386::GetHardwareWatchpointHit() GetDBGState() => 0x%8.8x.", kret); + if (kret == KERN_SUCCESS) + { + DBG debug_state = m_state.context.dbg; + uint32_t i, num = NumSupportedHardwareWatchpoints(); + for (i = 0; i < num; ++i) + { + if (IsWatchpointHit(debug_state, i)) + { + DNBLogThreadedIf(LOG_WATCHPOINTS, "DNBArchImplX86_64::GetHardwareWatchpointHit() found => %u.", i); + return i; + } + } + } + return INVALID_NUB_HW_INDEX; +} + uint32_t DNBArchImplI386::NumSupportedHardwareWatchpoints() { Modified: lldb/trunk/tools/debugserver/source/MacOSX/i386/DNBArchImplI386.h URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/tools/debugserver/source/MacOSX/i386/DNBArchImplI386.h?rev=139034&r1=139033&r2=139034&view=diff ============================================================================== --- lldb/trunk/tools/debugserver/source/MacOSX/i386/DNBArchImplI386.h (original) +++ lldb/trunk/tools/debugserver/source/MacOSX/i386/DNBArchImplI386.h Fri Sep 2 16:13:07 2011 @@ -54,6 +54,7 @@ virtual uint32_t NumSupportedHardwareWatchpoints(); virtual uint32_t EnableHardwareWatchpoint (nub_addr_t addr, nub_size_t size, bool read, bool write); virtual bool DisableHardwareWatchpoint (uint32_t hw_break_index); + virtual uint32_t GetHardwareWatchpointHit(); protected: kern_return_t EnableHardwareSingleStep (bool enable); Modified: lldb/trunk/tools/debugserver/source/MacOSX/x86_64/DNBArchImplX86_64.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/tools/debugserver/source/MacOSX/x86_64/DNBArchImplX86_64.cpp?rev=139034&r1=139033&r2=139034&view=diff ============================================================================== --- lldb/trunk/tools/debugserver/source/MacOSX/x86_64/DNBArchImplX86_64.cpp (original) +++ lldb/trunk/tools/debugserver/source/MacOSX/x86_64/DNBArchImplX86_64.cpp Fri Sep 2 16:13:07 2011 @@ -474,6 +474,17 @@ // This is the primary thread, let the arch do anything it needs EnableHardwareSingleStep(true); } + + // Reset the debug status register before we resume. + kern_return_t kret = GetDBGState(false); + DNBLogThreadedIf(LOG_WATCHPOINTS, "DNBArchImplX86_64::ThreadWillResume() GetDBGState() => 0x%8.8x.", kret); + if (kret == KERN_SUCCESS) + { + DBG debug_state = m_state.context.dbg; + ClearWatchpointHits(debug_state); + kret = SetDBGState(); + DNBLogThreadedIf(LOG_WATCHPOINTS, "DNBArchImplX86_64::ThreadWillResume() SetDBGState() => 0x%8.8x.", kret); + } } bool @@ -759,6 +770,29 @@ return false; } +// Iterate through the debug status register; return the index of the first hit. +uint32_t +DNBArchImplX86_64::GetHardwareWatchpointHit() +{ + // Read the debug state + kern_return_t kret = GetDBGState(false); + DNBLogThreadedIf(LOG_WATCHPOINTS, "DNBArchImplX86_64::GetHardwareWatchpointHit() GetDBGState() => 0x%8.8x.", kret); + if (kret == KERN_SUCCESS) + { + DBG debug_state = m_state.context.dbg; + uint32_t i, num = NumSupportedHardwareWatchpoints(); + for (i = 0; i < num; ++i) + { + if (IsWatchpointHit(debug_state, i)) + { + DNBLogThreadedIf(LOG_WATCHPOINTS, "DNBArchImplX86_64::GetHardwareWatchpointHit() found => %u.", i); + return i; + } + } + } + return INVALID_NUB_HW_INDEX; +} + // Set the single step bit in the processor status register. kern_return_t DNBArchImplX86_64::EnableHardwareSingleStep (bool enable) Modified: lldb/trunk/tools/debugserver/source/MacOSX/x86_64/DNBArchImplX86_64.h URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/tools/debugserver/source/MacOSX/x86_64/DNBArchImplX86_64.h?rev=139034&r1=139033&r2=139034&view=diff ============================================================================== --- lldb/trunk/tools/debugserver/source/MacOSX/x86_64/DNBArchImplX86_64.h (original) +++ lldb/trunk/tools/debugserver/source/MacOSX/x86_64/DNBArchImplX86_64.h Fri Sep 2 16:13:07 2011 @@ -53,6 +53,7 @@ virtual uint32_t NumSupportedHardwareWatchpoints(); virtual uint32_t EnableHardwareWatchpoint (nub_addr_t addr, nub_size_t size, bool read, bool write); virtual bool DisableHardwareWatchpoint (uint32_t hw_break_index); + virtual uint32_t GetHardwareWatchpointHit(); protected: kern_return_t EnableHardwareSingleStep (bool enable);