[Lldb-commits] [PATCH] D56537: ObjectFilePECOFF: Create a "container" section spanning the entire module image

Pavel Labath via Phabricator via lldb-commits lldb-commits at lists.llvm.org
Thu Jan 10 04:02:22 PST 2019


labath created this revision.
labath added reviewers: zturner, amccarth, stella.stamenova, clayborg.
Herald added subscribers: abidh, JDevlieghere.

This is coming from the discussion in D55356 <https://reviews.llvm.org/D55356> (the most interesting part
happened on the mailing list, so it isn't reflected on the review page).

In short the issue is that lldb assumes that all bytes of a module image
in memory will be backed by a "section". This isn't the case for PECOFF
files because the initial bytes of the module image will contain the
file header, which does not correspond to any normal section in the
file. In particular, this means it is not possible to implement
GetBaseAddress function for PECOFF files, because that's supposed point
to the first byte of that header.

If my (limited) understanding of how PECOFF files work is correct, then
the OS is expecded to load the entire module into one continuous chunk
of memory. The address of that chunk (+/- ASLR) is given by the "image
base" field in the COFF header, and it's size by "image size". All of
the COFF sections are then loaded into this range.

If that's true, then we can model this behavior in lldb by creating a
"container" section to represent the entire module image, and then place
other sections inside that. This would make be consistent with how MachO
and ELF files are modelled (except that those can have multiple
top-level containers as they can be loaded into multiple discontinuous
chunks of memory).

This change required a small number of fixups in the PDB plugins, which
assumed a certain order of sections within the object file (which
obivously changes now). I fix this by changing the lookup code to use
section IDs (which are unchanged) instead of indexes. This has the nice
benefit of removing spurious -1s in the plugins as the section IDs in
the pdbs match the 1-based section IDs in the COFF plugin.

Besides making the implementation of GetBaseAddress possible, this also
improves the lookup of addresses in the gaps between the object file
sections, which will now be correctly resolved as belonging to the
object file.


Repository:
  rLLDB LLDB

https://reviews.llvm.org/D56537

Files:
  lit/Modules/PECOFF/export-dllfunc.yaml
  lit/Modules/PECOFF/subsections.yaml
  source/Plugins/ObjectFile/PECOFF/ObjectFilePECOFF.cpp
  source/Plugins/SymbolFile/NativePDB/DWARFLocationExpression.cpp
  source/Plugins/SymbolFile/PDB/PDBLocationToDWARFExpression.cpp
  source/Plugins/SymbolFile/PDB/SymbolFilePDB.cpp

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D56537.181022.patch
Type: text/x-patch
Size: 8164 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/lldb-commits/attachments/20190110/b52188c0/attachment-0001.bin>


More information about the lldb-commits mailing list