[llvm-commits] [PATCH] Fix emission of debug data for global variables

James Molloy James.Molloy at arm.com
Mon Sep 26 09:03:49 PDT 2011


Hi,

With the new debug information changes, global variables aren't emitted properly to DWARF. The DW_AT_decl_file field is incorrect.

This stems from DwarfCompileUnit.cpp:138:

  unsigned FileID = DD->GetOrCreateSourceID(G.getContext().getFilename(),
                                            G.getContext().getDirectory());

G.getContext() returns a NULL metadatum for the new metadata format (it used to return the CompileUnit). This causes a new SourceID to be generated for the "null" file, and the global is assigned this incorrect SourceID.

Attached is a testcase and proposed patch. It inlines getFilename() and getDirectory() into DIGlobalVariable, returning the original getContext().getFilename() for old versions of the debug info and getFieldAs<DIFile>(6).getFilename() for new versions.

I've implemented it this way so that the old code path is identical to before. I'm not sure if this is the most perfect fix - as getFieldAs<DIFile>(6) is valid (seemingly) for all debug info versions, perhaps the best idea would be to remove the conditionalization and always return getFieldAs<DIFile>(6).getFilename/getDirectory() ?


Cheers,

James


-- IMPORTANT NOTICE: The contents of this email and any attachments are confidential and may also be privileged. If you are not the intended recipient, please notify the sender immediately and do not disclose the contents to any other person, use it for any purpose, or store or copy the information in any medium.  Thank you.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 2011-09-26-GlobalVarContext.patch
Type: application/octet-stream
Size: 4837 bytes
Desc: 2011-09-26-GlobalVarContext.patch
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20110926/97849988/attachment.obj>


More information about the llvm-commits mailing list