27 changes: 13 additions & 14 deletions lldb/source/Plugins/Process/Windows/Common/ProcessDebugger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ lldb::pid_t ProcessDebugger::GetDebuggedProcessId() const {
}

Status ProcessDebugger::DetachProcess() {
Log *log = ProcessWindowsLog::GetLogIfAny(WINDOWS_LOG_PROCESS);
Log *log = GetLog(WindowsLog::Process);
DebuggerThreadSP debugger_thread;
{
// Acquire the lock only long enough to get the DebuggerThread.
Expand Down Expand Up @@ -108,7 +108,7 @@ Status ProcessDebugger::LaunchProcess(ProcessLaunchInfo &launch_info,
// thread has been kicked off. So there's no race conditions, and it
// shouldn't be necessary to acquire the mutex.

Log *log = ProcessWindowsLog::GetLogIfAny(WINDOWS_LOG_PROCESS);
Log *log = GetLog(WindowsLog::Process);
Status result;

FileSpec working_dir = launch_info.GetWorkingDirectory();
Expand Down Expand Up @@ -171,7 +171,7 @@ Status ProcessDebugger::LaunchProcess(ProcessLaunchInfo &launch_info,
Status ProcessDebugger::AttachProcess(lldb::pid_t pid,
const ProcessAttachInfo &attach_info,
DebugDelegateSP delegate) {
Log *log = ProcessWindowsLog::GetLogIfAny(WINDOWS_LOG_PROCESS);
Log *log = GetLog(WindowsLog::Process);
m_session_data.reset(
new ProcessWindowsData(!attach_info.GetContinueOnceAttached()));
DebuggerThreadSP debugger(new DebuggerThread(delegate));
Expand Down Expand Up @@ -209,7 +209,7 @@ Status ProcessDebugger::AttachProcess(lldb::pid_t pid,
}

Status ProcessDebugger::DestroyProcess(const lldb::StateType state) {
Log *log = ProcessWindowsLog::GetLogIfAny(WINDOWS_LOG_PROCESS);
Log *log = GetLog(WindowsLog::Process);
DebuggerThreadSP debugger_thread;
{
// Acquire this lock inside an inner scope, only long enough to get the
Expand Down Expand Up @@ -245,7 +245,7 @@ Status ProcessDebugger::DestroyProcess(const lldb::StateType state) {
}

Status ProcessDebugger::HaltProcess(bool &caused_stop) {
Log *log = ProcessWindowsLog::GetLogIfAny(WINDOWS_LOG_PROCESS);
Log *log = GetLog(WindowsLog::Process);
Status error;
llvm::sys::ScopedLock lock(m_mutex);
caused_stop = ::DebugBreakProcess(m_session_data->m_debugger->GetProcess()
Expand All @@ -263,7 +263,7 @@ Status ProcessDebugger::ReadMemory(lldb::addr_t vm_addr, void *buf, size_t size,
size_t &bytes_read) {
Status error;
bytes_read = 0;
Log *log = ProcessWindowsLog::GetLogIfAny(WINDOWS_LOG_MEMORY);
Log *log = GetLog(WindowsLog::Memory);
llvm::sys::ScopedLock lock(m_mutex);

if (!m_session_data) {
Expand Down Expand Up @@ -297,7 +297,7 @@ Status ProcessDebugger::WriteMemory(lldb::addr_t vm_addr, const void *buf,
size_t size, size_t &bytes_written) {
Status error;
bytes_written = 0;
Log *log = ProcessWindowsLog::GetLogIfAny(WINDOWS_LOG_MEMORY);
Log *log = GetLog(WindowsLog::Memory);
llvm::sys::ScopedLock lock(m_mutex);
LLDB_LOG(log, "attempting to write {0} bytes into address {1:x}", size,
vm_addr);
Expand Down Expand Up @@ -327,7 +327,7 @@ Status ProcessDebugger::AllocateMemory(size_t size, uint32_t permissions,
lldb::addr_t &addr) {
Status error;
addr = LLDB_INVALID_ADDRESS;
Log *log = ProcessWindowsLog::GetLogIfAny(WINDOWS_LOG_MEMORY);
Log *log = GetLog(WindowsLog::Memory);
llvm::sys::ScopedLock lock(m_mutex);
LLDB_LOG(log, "attempting to allocate {0} bytes with permissions {1}", size,
permissions);
Expand Down Expand Up @@ -355,7 +355,7 @@ Status ProcessDebugger::AllocateMemory(size_t size, uint32_t permissions,
Status ProcessDebugger::DeallocateMemory(lldb::addr_t vm_addr) {
Status result;

Log *log = ProcessWindowsLog::GetLogIfAny(WINDOWS_LOG_MEMORY);
Log *log = GetLog(WindowsLog::Memory);
llvm::sys::ScopedLock lock(m_mutex);
LLDB_LOG(log, "attempting to deallocate bytes at address {0}", vm_addr);

Expand All @@ -379,7 +379,7 @@ Status ProcessDebugger::DeallocateMemory(lldb::addr_t vm_addr) {

Status ProcessDebugger::GetMemoryRegionInfo(lldb::addr_t vm_addr,
MemoryRegionInfo &info) {
Log *log = ProcessWindowsLog::GetLogIfAny(WINDOWS_LOG_MEMORY);
Log *log = GetLog(WindowsLog::Memory);
Status error;
llvm::sys::ScopedLock lock(m_mutex);
info.Clear();
Expand Down Expand Up @@ -484,7 +484,7 @@ void ProcessDebugger::OnDebuggerConnected(lldb::addr_t image_base) {}
ExceptionResult
ProcessDebugger::OnDebugException(bool first_chance,
const ExceptionRecord &record) {
Log *log = ProcessWindowsLog::GetLogIfAny(WINDOWS_LOG_EXCEPTION);
Log *log = GetLog(WindowsLog::Exception);
llvm::sys::ScopedLock lock(m_mutex);
// FIXME: Without this check, occasionally when running the test suite
// there is an issue where m_session_data can be null. It's not clear how
Expand Down Expand Up @@ -538,7 +538,7 @@ void ProcessDebugger::OnDebugString(const std::string &string) {}

void ProcessDebugger::OnDebuggerError(const Status &error, uint32_t type) {
llvm::sys::ScopedLock lock(m_mutex);
Log *log = ProcessWindowsLog::GetLogIfAny(WINDOWS_LOG_PROCESS);
Log *log = GetLog(WindowsLog::Process);

if (m_session_data->m_initial_stop_received) {
// This happened while debugging. Do we shutdown the debugging session,
Expand All @@ -564,8 +564,7 @@ void ProcessDebugger::OnDebuggerError(const Status &error, uint32_t type) {
Status ProcessDebugger::WaitForDebuggerConnection(DebuggerThreadSP debugger,
HostProcess &process) {
Status result;
Log *log = ProcessWindowsLog::GetLogIfAny(WINDOWS_LOG_PROCESS |
WINDOWS_LOG_BREAKPOINTS);
Log *log = GetLog(WindowsLog::Process | WindowsLog::Breakpoints);
LLDB_LOG(log, "Waiting for loader breakpoint.");

// Block this function until we receive the initial stop from the process.
Expand Down
20 changes: 10 additions & 10 deletions lldb/source/Plugins/Process/Windows/Common/ProcessWindows.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ Status ProcessWindows::EnableBreakpointSite(BreakpointSite *bp_site) {
if (bp_site->HardwareRequired())
return Status("Hardware breakpoints are not supported.");

Log *log = ProcessWindowsLog::GetLogIfAny(WINDOWS_LOG_BREAKPOINTS);
Log *log = GetLog(WindowsLog::Breakpoints);
LLDB_LOG(log, "bp_site = {0:x}, id={1}, addr={2:x}", bp_site,
bp_site->GetID(), bp_site->GetLoadAddress());

Expand All @@ -152,7 +152,7 @@ Status ProcessWindows::EnableBreakpointSite(BreakpointSite *bp_site) {
}

Status ProcessWindows::DisableBreakpointSite(BreakpointSite *bp_site) {
Log *log = ProcessWindowsLog::GetLogIfAny(WINDOWS_LOG_BREAKPOINTS);
Log *log = GetLog(WindowsLog::Breakpoints);
LLDB_LOG(log, "bp_site = {0:x}, id={1}, addr={2:x}", bp_site,
bp_site->GetID(), bp_site->GetLoadAddress());

Expand All @@ -165,7 +165,7 @@ Status ProcessWindows::DisableBreakpointSite(BreakpointSite *bp_site) {

Status ProcessWindows::DoDetach(bool keep_stopped) {
Status error;
Log *log = ProcessWindowsLog::GetLogIfAny(WINDOWS_LOG_PROCESS);
Log *log = GetLog(WindowsLog::Process);
StateType private_state = GetPrivateState();
if (private_state != eStateExited && private_state != eStateDetached) {
error = DetachProcess();
Expand Down Expand Up @@ -203,7 +203,7 @@ ProcessWindows::DoAttachToProcessWithID(lldb::pid_t pid,
}

Status ProcessWindows::DoResume() {
Log *log = ProcessWindowsLog::GetLogIfAny(WINDOWS_LOG_PROCESS);
Log *log = GetLog(WindowsLog::Process);
llvm::sys::ScopedLock lock(m_mutex);
Status error;

Expand Down Expand Up @@ -349,7 +349,7 @@ DumpAdditionalExceptionInformation(llvm::raw_ostream &stream,
}

void ProcessWindows::RefreshStateAfterStop() {
Log *log = ProcessWindowsLog::GetLogIfAny(WINDOWS_LOG_EXCEPTION);
Log *log = GetLog(WindowsLog::Exception);
llvm::sys::ScopedLock lock(m_mutex);

if (!m_session_data) {
Expand Down Expand Up @@ -520,7 +520,7 @@ bool ProcessWindows::CanDebug(lldb::TargetSP target_sp,

bool ProcessWindows::DoUpdateThreadList(ThreadList &old_thread_list,
ThreadList &new_thread_list) {
Log *log = ProcessWindowsLog::GetLogIfAny(WINDOWS_LOG_THREAD);
Log *log = GetLog(WindowsLog::Thread);
// Add all the threads that were previously running and for which we did not
// detect a thread exited event.
int new_size = 0;
Expand Down Expand Up @@ -625,7 +625,7 @@ DynamicLoaderWindowsDYLD *ProcessWindows::GetDynamicLoader() {

void ProcessWindows::OnExitProcess(uint32_t exit_code) {
// No need to acquire the lock since m_session_data isn't accessed.
Log *log = ProcessWindowsLog::GetLogIfAny(WINDOWS_LOG_PROCESS);
Log *log = GetLog(WindowsLog::Process);
LLDB_LOG(log, "Process {0} exited with code {1}", GetID(), exit_code);

TargetSP target = CalculateTarget();
Expand All @@ -644,7 +644,7 @@ void ProcessWindows::OnExitProcess(uint32_t exit_code) {

void ProcessWindows::OnDebuggerConnected(lldb::addr_t image_base) {
DebuggerThreadSP debugger = m_session_data->m_debugger;
Log *log = ProcessWindowsLog::GetLogIfAny(WINDOWS_LOG_PROCESS);
Log *log = GetLog(WindowsLog::Process);
LLDB_LOG(log, "Debugger connected to process {0}. Image base = {1:x}",
debugger->GetProcess().GetProcessId(), image_base);

Expand Down Expand Up @@ -692,7 +692,7 @@ void ProcessWindows::OnDebuggerConnected(lldb::addr_t image_base) {
ExceptionResult
ProcessWindows::OnDebugException(bool first_chance,
const ExceptionRecord &record) {
Log *log = ProcessWindowsLog::GetLogIfAny(WINDOWS_LOG_EXCEPTION);
Log *log = GetLog(WindowsLog::Exception);
llvm::sys::ScopedLock lock(m_mutex);

// FIXME: Without this check, occasionally when running the test suite there
Expand Down Expand Up @@ -809,7 +809,7 @@ void ProcessWindows::OnDebugString(const std::string &string) {}

void ProcessWindows::OnDebuggerError(const Status &error, uint32_t type) {
llvm::sys::ScopedLock lock(m_mutex);
Log *log = ProcessWindowsLog::GetLogIfAny(WINDOWS_LOG_PROCESS);
Log *log = GetLog(WindowsLog::Process);

if (m_session_data->m_initial_stop_received) {
// This happened while debugging. Do we shutdown the debugging session,
Expand Down
11 changes: 0 additions & 11 deletions lldb/source/Plugins/Process/Windows/Common/ProcessWindowsLog.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,21 +25,10 @@ enum class WindowsLog : Log::MaskType {
LLVM_MARK_AS_BITMASK_ENUM(Thread)
};

#define WINDOWS_LOG_PROCESS ::lldb_private::WindowsLog::Process
#define WINDOWS_LOG_EXCEPTION ::lldb_private::WindowsLog::Exception
#define WINDOWS_LOG_THREAD ::lldb_private::WindowsLog::Thread
#define WINDOWS_LOG_MEMORY ::lldb_private::WindowsLog::Memory
#define WINDOWS_LOG_BREAKPOINTS ::lldb_private::WindowsLog::Breakpoints
#define WINDOWS_LOG_STEP ::lldb_private::WindowsLog::Step
#define WINDOWS_LOG_REGISTERS ::lldb_private::WindowsLog::Registers
#define WINDOWS_LOG_EVENT ::lldb_private::WindowsLog::Event

class ProcessWindowsLog {
public:
static void Initialize();
static void Terminate();

static Log *GetLogIfAny(WindowsLog mask) { return GetLog(mask); }
};

template <> Log::Channel &LogChannelFor<WindowsLog>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ bool RegisterContextWindows::AddHardwareBreakpoint(uint32_t slot,
return ApplyAllRegisterValues();

#else
Log *log = ProcessWindowsLog::GetLogIfAny(WINDOWS_LOG_REGISTERS);
Log *log = GetLog(WindowsLog::Registers);
LLDB_LOG(log, "hardware breakpoints not currently supported on this arch");
return false;
#endif
Expand Down Expand Up @@ -149,7 +149,7 @@ uint32_t RegisterContextWindows::GetTriggeredHardwareBreakpointSlotId() {
}

bool RegisterContextWindows::CacheAllRegisterValues() {
Log *log = ProcessWindowsLog::GetLogIfAny(WINDOWS_LOG_REGISTERS);
Log *log = GetLog(WindowsLog::Registers);
if (!m_context_stale)
return true;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ bool RegisterContextWindows_x86::ReadRegister(const RegisterInfo *reg_info,
return ReadRegisterHelper(CONTEXT_CONTROL, "EFLAGS", m_context.EFlags,
reg_value);
default:
Log *log = ProcessWindowsLog::GetLogIfAny(WINDOWS_LOG_REGISTERS);
Log *log = GetLog(WindowsLog::Registers);
LLDB_LOG(log, "Requested unknown register {0}", reg);
break;
}
Expand All @@ -208,7 +208,7 @@ bool RegisterContextWindows_x86::WriteRegister(const RegisterInfo *reg_info,
if (!CacheAllRegisterValues())
return false;

Log *log = ProcessWindowsLog::GetLogIfAny(WINDOWS_LOG_REGISTERS);
Log *log = GetLog(WindowsLog::Registers);
uint32_t reg = reg_info->kinds[eRegisterKindLLDB];
switch (reg) {
case lldb_eax_i386:
Expand Down Expand Up @@ -263,7 +263,7 @@ bool RegisterContextWindows_x86::WriteRegister(const RegisterInfo *reg_info,
bool RegisterContextWindows_x86::ReadRegisterHelper(
DWORD flags_required, const char *reg_name, DWORD value,
RegisterValue &reg_value) const {
Log *log = ProcessWindowsLog::GetLogIfAny(WINDOWS_LOG_REGISTERS);
Log *log = GetLog(WindowsLog::Registers);
if ((m_context.ContextFlags & flags_required) != flags_required) {
LLDB_LOG(log, "Thread context doesn't have {0}", reg_name);
return false;
Expand Down
2 changes: 1 addition & 1 deletion lldb/source/Plugins/SymbolFile/DWARF/NameToDIE.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ using namespace lldb;
using namespace lldb_private;

void NameToDIE::Finalize() {
m_map.Sort();
m_map.Sort(std::less<DIERef>());
m_map.SizeToFit();
}

Expand Down
14 changes: 0 additions & 14 deletions lldb/test/Shell/SymbolFile/DWARF/x86/gnu-style-compression.cpp

This file was deleted.

56 changes: 56 additions & 0 deletions lldb/test/Shell/SymbolFile/DWARF/x86/gnu-style-compression.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
## NB: This is a yaml file because llvm gnu-style writing support in 14.0
## (2022, D117744). In due time we may want to remove it from lldb as well.

## Debug info generated from the following sources using clang-13
## struct A {
## long a = 42;
## };
## extern constexpr short s = 47;
## extern constexpr A a{};

# REQUIRES: zlib

# RUN: yaml2obj %s > %t
# RUN: %lldb %t -o "target var s a" -b | FileCheck %s

# CHECK: (const short) s = 47
# CHECK: (const A) a = (a = 42)

--- !ELF
FileHeader:
Class: ELFCLASS64
Data: ELFDATA2LSB
Type: ET_EXEC
Machine: EM_X86_64
Entry: 0x401000
Sections:
- Name: .rodata
Type: SHT_PROGBITS
Flags: [ SHF_ALLOC ]
Address: 0x401000
AddressAlign: 0x8
Offset: 0x1000
Content: 2F000000000000002A00000000000000
- Name: .debug_info
Type: SHT_PROGBITS
AddressAlign: 0x1
Content: 20000000040000000000080100000000000000001A000000C088361D3BC5B7B700000000
- Name: .debug_abbrev
Type: SHT_PROGBITS
AddressAlign: 0x1
Content: 01110010171B0EB44219B0420EB14207B34217000000
- Name: .debug_line
Type: SHT_PROGBITS
AddressAlign: 0x1
Content: 7100000004006B000000010101FB0E0D0001010101000000010000012F686F6D652F706176656C6F2F6C6C00006D6F6E6F2F6C6C64622F746573742F5368656C6C2F53796D626F6C46696C652F44574152462F7838362F676E752D7374796C652D636F6D7072657373696F6E2E6370700001000000
- Name: .zdebug_str
Type: SHT_PROGBITS
Flags: [ SHF_MERGE, SHF_STRINGS ]
AddressAlign: 0x1
EntSize: 0x1
Content: 5A4C49420000000000000084789C75C9310E82401005502E04BF33B62686D6440A6B979DC826B3FC89332B727BB980ED7B585805F6FC8812AA48AD68062D3AFC1B04A97E504E08F1C0B4C8F1D35E13752C2AB83E2EF711DFF309B716D602AFB5F51EBB4A3FB3DA5BDC0BD761361BF2C6EE0781C8302C
- Name: .debug_addr
Type: SHT_PROGBITS
AddressAlign: 0x1
Content: '00104000000000000810400000000000'
...
15 changes: 15 additions & 0 deletions lldb/unittests/Core/UniqueCStringMapTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,3 +51,18 @@ TEST(UniqueCStringMap, NoDefaultConstructor) {
EXPECT_THAT(Map.GetValues(Bar, Values), 0);
EXPECT_THAT(Values, testing::IsEmpty());
}

TEST(UniqueCStringMap, ValueCompare) {
UniqueCStringMap<int> Map;

ConstString Foo("foo");

Map.Append(Foo, 0);
Map.Append(Foo, 5);
Map.Append(Foo, -5);

Map.Sort(std::less<int>());
std::vector<int> Values;
EXPECT_THAT(Map.GetValues(Foo, Values), 3);
EXPECT_THAT(Values, testing::ElementsAre(-5, 0, 5));
}