Skip to content

Commit 8407d7f

Browse files
committed
Properly handle file names with spaces or special characters in it
1 parent 5793ba2 commit 8407d7f

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

core/adapters/dbgengadapter.cpp

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -637,15 +637,24 @@ DebugBreakpoint DbgEngAdapter::AddBreakpoint(const std::uintptr_t address, unsig
637637
return new_breakpoint;
638638
}
639639

640+
static std::string EscapeModuleName(const std::string& name)
641+
{
642+
std::string result = name;
643+
const std::string charsToEscape = " -'~`";
644+
auto shouldReplace = [&](char c) -> bool { return charsToEscape.find(c) != std::string::npos; };
645+
std::replace_if(result.begin(), result.end(), shouldReplace, '_');
646+
return result;
647+
}
648+
640649
DebugBreakpoint DbgEngAdapter::AddBreakpoint(const ModuleNameAndOffset& address, unsigned long breakpoint_type)
641650
{
642651
// If the backend has been created, we add the breakpoints directly. Otherwise, keep track of the breakpoints,
643652
// and add them when we launch/attach the target.
644653
if (m_debugActive)
645654
{
646655
// DbgEng does not take a full path. It can take "hello.exe", or simply "hello". E.g., "bp helloworld+0x1338"
647-
auto fileName = std::filesystem::path(address.module).filename();
648-
std::string breakpointCommand = fmt::format("bp {}+0x{:x}", fileName.string(), address.offset);
656+
auto fileName = std::filesystem::path(address.module).stem();
657+
std::string breakpointCommand = fmt::format("bp {}+0x{:x}", EscapeModuleName(fileName.string()), address.offset);
649658
auto ret = InvokeBackendCommand(breakpointCommand);
650659
}
651660
else

core/adapters/lldbadapter.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -314,7 +314,7 @@ DebugBreakpoint LldbAdapter::AddBreakpoint(const std::uintptr_t address, unsigne
314314
DebugBreakpoint LldbAdapter::AddBreakpoint(const ModuleNameAndOffset& address, unsigned long breakpoint_type)
315315
{
316316
uint64_t addr = address.offset + m_data->GetStart();
317-
std::string entryBreakpointCommand = fmt::format("b -s {} -a 0x{:x}", address.module, addr);
317+
std::string entryBreakpointCommand = fmt::format("b -s \"{}\" -a 0x{:x}", address.module, addr);
318318
auto ret = InvokeBackendCommand(entryBreakpointCommand);
319319

320320
return DebugBreakpoint{};

0 commit comments

Comments
 (0)