[PATCH] IR: Make MDNode::dump() useful by adding addresses

Duncan P. N. Exon Smith dexonsmith at apple.com
Fri Dec 12 16:14:58 PST 2014


> On 2014 Dec 12, at 15:59, Frédéric Riss <friss at apple.com> wrote:
> 
>> 
>> On Dec 12, 2014, at 2:37 PM, Duncan P. N. Exon Smith <dexonsmith at apple.com> wrote:
>> 
>> It's horrible to inspect `MDNode`s in a debugger.  All of their operands
>> that are `MDNode`s get dumped as `<badref>`, since we can't assign
>> metadata slots in the context of a `Metadata::dump()`.  (Why not?  Why
>> not assign numbers lazily?  Because then each time you called `dump()`,
>> a given `MDNode` could have a different lazily assigned number.)
>> 
>> Fortunately, the C memory model gives us perfectly good identifiers for
>> `MDNode`.  Add pointer addresses to the dumps, transforming this:
>> 
>>   (lldb) e N->dump()
>>   metadata !{i32 662302, i32 26, metadata <badref>, null}
>> 
>>   (lldb) e ((MDNode*)N->getOperand(2))->dump()
>>   metadata !{i32 4, metadata !"foo"}
>> 
>> into:
>> 
>>   (lldb) e N->dump()
>>   metadata !{i32 662302, i32 26, metadata <badref:0x100706ee0>, null}
>> 
>>   (lldb) e ((MDNode*)0x100706ee0)->dump()
>>   metadata !{i32 4, metadata !"foo”}
> 
> If it were only for debugger consumption, I’d make it totally copy-pastable:
> 
> <badref:((MDNode*)0x100706ee0)>
> 
> Not sure this is acceptable in textual IR though.
> 
> FRed

Okay, so I hadn't thought of that option.  I see two problems with it though.

First, it's *really* verbose.  The lines will get much longer.  Maybe that's
okay?  Second, it's not just for debugger consumption.  If you add
`DEBUG(dbgs() << "N = " << *N)` somewhere, you don't really want that boiler-
plate.  We don't seem to use `DEBUG` much with `MDNode`s, but I assume that's
just because it's been useless until now.

I could probably be convinced if everyone else jumps on board though...



More information about the llvm-commits mailing list