From 1256125fb73169b8a8a940bce05dd04622955edc Mon Sep 17 00:00:00 2001 From: David Majnemer Date: Sun, 13 Mar 2016 10:53:30 +0000 Subject: [CodeView] Truncate display names Fundamentally, the length of a variable or function name is bound by the maximum size of a record: 0xffff. However, the name doesn't live in a vacuum; other data is associated with the name, lowering the bound further. We would naively attempt to emit the name, causing us to assert because the record would no-longer fit in 16-bits. Instead, truncate the name but preserve as much as we can. While I have tested this locally, I've decided to not commit it due to the test's size. N.B. While this behavior is undesirable, it is better than MSVC's behavior. They seem to truncate to ~4000 characters. llvm-svn: 263378 --- llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) (limited to 'llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp') diff --git a/llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp b/llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp index 622d169..233bce4 100644 --- a/llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp +++ b/llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp @@ -397,10 +397,11 @@ void CodeViewDebug::emitInlinedCallSite(const FunctionInfo &FI, OS.EmitIntValue(SymbolRecordKind::S_INLINESITE_END, 2); // RecordKind } -static void emitNullTerminatedString(MCStreamer &OS, StringRef S) { +static void emitNullTerminatedString(MCStreamer &OS, StringRef S, + size_t MaxSize) { + S = S.substr(0, MaxSize); SmallString<32> NullTerminatedString(S); - if (NullTerminatedString.empty() || NullTerminatedString.back() != '\0') - NullTerminatedString.push_back('\0'); + NullTerminatedString.push_back('\0'); OS.EmitBytes(NullTerminatedString); } @@ -462,7 +463,8 @@ void CodeViewDebug::emitDebugInfoForFunction(const Function *GV, OS.EmitIntValue(0, 1); // Emit the function display name as a null-terminated string. OS.AddComment("Function name"); - emitNullTerminatedString(OS, FuncName); + // Truncate the name so we won't overflow the record length field. + emitNullTerminatedString(OS, FuncName, 0xffd9); OS.EmitLabel(ProcRecordEnd); for (const LocalVariable &Var : FI.Locals) @@ -706,7 +708,8 @@ void CodeViewDebug::emitLocalVariable(const LocalVariable &Var) { OS.EmitIntValue(TypeIndex::Int32().getIndex(), 4); OS.AddComment("Flags"); OS.EmitIntValue(Flags, 2); - emitNullTerminatedString(OS, Var.DIVar->getName()); + // Truncate the name so we won't overflow the record length field. + emitNullTerminatedString(OS, Var.DIVar->getName(), 0xfff6); OS.EmitLabel(LocalEnd); // Calculate the on disk prefix of the appropriate def range record. The -- cgit v1.1