<div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote">On Sun, Mar 13, 2016 at 12:51 PM, David Blaikie <span dir="ltr"><<a href="mailto:dblaikie@gmail.com" target="_blank">dblaikie@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote"><span>On Sun, Mar 13, 2016 at 3:53 AM, David Majnemer via llvm-commits <span dir="ltr"><<a href="mailto:llvm-commits@lists.llvm.org" target="_blank">llvm-commits@lists.llvm.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Author: majnemer<br>
Date: Sun Mar 13 05:53:30 2016<br>
New Revision: 263378<br>
<br>
URL: <a href="http://llvm.org/viewvc/llvm-project?rev=263378&view=rev" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project?rev=263378&view=rev</a><br>
Log:<br>
[CodeView] Truncate display names<br>
<br>
Fundamentally, the length of a variable or function name is bound by the<br>
maximum size of a record: 0xffff.  However, the name doesn't live in a<br>
vacuum; other data is associated with the name, lowering the bound<br>
further.<br>
<br>
We would naively attempt to emit the name, causing us to assert because<br>
the record would no-longer fit in 16-bits.  Instead, truncate the name<br>
but preserve as much as we can.<br>
<br>
While I have tested this locally, I've decided to not commit it due to<br>
the test's size.<br></blockquote><div><br></div></span><div>^ Did you change your mind? or unintentionally commit it? (or am I misunderstanding this comment?)</div></div></div></div></blockquote><div><br></div><div>I believe there is a misunderstanding here.  I decided to omit the test due to it's size.</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><div><div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<br>
N.B.  While this behavior is undesirable, it is better than MSVC's<br>
behavior.  They seem to truncate to ~4000 characters.<br>
<br>
Modified:<br>
    llvm/trunk/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp<br>
<br>
Modified: llvm/trunk/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp?rev=263378&r1=263377&r2=263378&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp?rev=263378&r1=263377&r2=263378&view=diff</a><br>
==============================================================================<br>
--- llvm/trunk/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp (original)<br>
+++ llvm/trunk/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp Sun Mar 13 05:53:30 2016<br>
@@ -397,10 +397,11 @@ void CodeViewDebug::emitInlinedCallSite(<br>
   OS.EmitIntValue(SymbolRecordKind::S_INLINESITE_END, 2); // RecordKind<br>
 }<br>
<br>
-static void emitNullTerminatedString(MCStreamer &OS, StringRef S) {<br>
+static void emitNullTerminatedString(MCStreamer &OS, StringRef S,<br>
+                                     size_t MaxSize) {<br>
+  S = S.substr(0, MaxSize);<br>
   SmallString<32> NullTerminatedString(S);<br>
-  if (NullTerminatedString.empty() || NullTerminatedString.back() != '\0')<br>
-    NullTerminatedString.push_back('\0');<br>
+  NullTerminatedString.push_back('\0');<br>
   OS.EmitBytes(NullTerminatedString);<br>
 }<br>
<br>
@@ -462,7 +463,8 @@ void CodeViewDebug::emitDebugInfoForFunc<br>
     OS.EmitIntValue(0, 1);<br>
     // Emit the function display name as a null-terminated string.<br>
     OS.AddComment("Function name");<br>
-    emitNullTerminatedString(OS, FuncName);<br>
+    // Truncate the name so we won't overflow the record length field.<br>
+    emitNullTerminatedString(OS, FuncName, 0xffd9);<br>
     OS.EmitLabel(ProcRecordEnd);<br>
<br>
     for (const LocalVariable &Var : FI.Locals)<br>
@@ -706,7 +708,8 @@ void CodeViewDebug::emitLocalVariable(co<br>
   OS.EmitIntValue(TypeIndex::Int32().getIndex(), 4);<br>
   OS.AddComment("Flags");<br>
   OS.EmitIntValue(Flags, 2);<br>
-  emitNullTerminatedString(OS, Var.DIVar->getName());<br>
+  // Truncate the name so we won't overflow the record length field.<br>
+  emitNullTerminatedString(OS, Var.DIVar->getName(), 0xfff6);<br>
   OS.EmitLabel(LocalEnd);<br>
<br>
   // Calculate the on disk prefix of the appropriate def range record. The<br>
<br>
<br>
_______________________________________________<br>
llvm-commits mailing list<br>
<a href="mailto:llvm-commits@lists.llvm.org" target="_blank">llvm-commits@lists.llvm.org</a><br>
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits</a><br>
</blockquote></div></div></div><br></div></div>
</blockquote></div><br></div></div>