<div dir="ltr"><div>I came across a PDB that caused llvm-pdbdump to crash.  I tracked it down to a missing overload for a data type in the variable printer.  When I tried to provide an implementation, I discovered that there were some bugs in the existing overloads and it was easy to come up with combinations of types that weren't being dumped right.  I created some test cases and tried to fix these problems but realized that there's a limitation to how printing the type information is structured.</div><div><br></div><div>The cause of the difficulty is the conflict between these two facts:</div><div><br></div><div>1.  C and C++ variable declarations are described inside-out</div><div>2.  Printing with color requires printing left-to-right</div><div><br></div><div>Simple types generally work, because all the type information is on the left side, so VariableDumper can just work left-to-right.  To handle more complex types (like arrays and function signatures), VariableDumper attempts to special case the complex types.  Unfortunately, the special cases can't be combined generally (e.g., making an array of pointers to functions), so it's always possible to find a new bug by adding an extra layer of type information.</div><div><br></div><div>I'm proposing a restructure of VariableDumper (PrettyVariableDumper.cpp) that I think should allow for pretty-printing of all types and actually simplify away most of the special-case code.</div><div><br></div><div>The existing approach is to emit the type information for a symbol and then the identifier, using recursion as necessary to emit the type information of subtypes.  For example, if foo is a pointer to an int, it's dumped by first recursively dumping the pointee type (int), then the '*', and then the name (foo).  But if bar is a pointer to an array of ints, this breaks down.</div><div><br></div><div>My proposal is to extend this slightly by having dumpers for the "left-side" and the "right-side" of the type information.  The pattern for printing a variable them becomes:</div><div><br></div><div>    call dumpLeft with the symbol type</div><div>    emit the symbol name</div><div>    call dumpRight with the symbol type</div><div><br></div><div>Most of the dumpLeft implementations would be identical to the current dump implementations.  The default for a dumpRight implementation would be to emit nothing, but for arrays and function signatures, dumpRight would print the bracketed array size and argument lists.  This depth-first order of the recursion should produce the necessary output in order, which means there should be no change to how we stream the output in color.</div><div><br></div><div>Any questions, comments, objections?</div></div>