Skip to content

Commit aad25b3

Browse files
committed
cl_options: add -fdebug-prefix-map
Try to follow clang, accepting pairs of <old>=<new> paths.
1 parent 3dd59d0 commit aad25b3

File tree

2 files changed

+29
-0
lines changed

2 files changed

+29
-0
lines changed

driver/cl_options.cpp

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,32 @@ cl::opt<bool> emitDwarfDebugInfo(
223223
"gdwarf", cl::ZeroOrMore,
224224
cl::desc("Emit DWARF debuginfo (instead of CodeView) for MSVC targets"));
225225

226+
// Prefix map for filenames in DWARF debuginfo
227+
std::map<std::string, std::string> debugPrefixMap;
228+
229+
struct DwarfPrefixParser : public cl::parser<std::string> {
230+
explicit DwarfPrefixParser(cl::Option &O) : cl::parser<std::string>(O) {}
231+
232+
bool parse(cl::Option &O, llvm::StringRef /*ArgName*/, llvm::StringRef Arg,
233+
std::string & /*Val*/) {
234+
auto [from, to] = Arg.split('=');
235+
if (from.empty() || to.empty()) {
236+
return O.error("invalid debug prefix map: " + Arg);
237+
}
238+
auto fromStr = std::string(from);
239+
if (debugPrefixMap.find(fromStr) != debugPrefixMap.end()) {
240+
return O.error("debug prefix map already contains: " + fromStr);
241+
}
242+
debugPrefixMap[fromStr] = std::string(to);
243+
return false;
244+
}
245+
};
246+
247+
static cl::opt<std::string, false, DwarfPrefixParser> fdebugPrefixMap(
248+
"fdebug-prefix-map", cl::ZeroOrMore,
249+
cl::desc("Prefix map for filenames in DWARF debuginfo"),
250+
cl::value_desc("<old>=<new>"));
251+
226252
cl::opt<bool> noAsm("noasm", cl::desc("Disallow use of inline assembler"),
227253
cl::ZeroOrMore);
228254

driver/cl_options.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#include "llvm/ADT/SmallVector.h"
2121
#include "llvm/Support/CodeGen.h"
2222
#include "llvm/Support/CommandLine.h"
23+
#include <map>
2324
#include <deque>
2425
#include <vector>
2526

@@ -149,4 +150,6 @@ extern cl::opt<bool> dynamicCompileTlsWorkaround;
149150
#else
150151
constexpr bool enableDynamicCompile = false;
151152
#endif
153+
// Prefix map for filenames in DWARF debuginfo
154+
extern std::map<std::string, std::string> debugPrefixMap;
152155
}

0 commit comments

Comments
 (0)