[PATCH] D147620: [DebugInfo] Keep the CU consistent for operating `DISubprogram`.

DianQK via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Apr 19 08:09:37 PDT 2023


DianQK added a comment.

In D147620#4279004 <https://reviews.llvm.org/D147620#4279004>, @dblaikie wrote:

> Also the LLVM UIR in the test case seems strange to me.

I read `2.3 Relationship of Debugging Information Entries` in DWARF5. There don't seem to be any constraints on the relationship of DIEs. So I guess the structure of this debugging info is at least reasonably present?
I do not know Rust and Swift's debugging information generation. But these languages all seem to generate similar debugging message structures. Maybe having LTO could improve the structure here?

Alternatively, we can use this patch to remove the changes to D135114 <https://reviews.llvm.org/D135114> and D136039 <https://reviews.llvm.org/D136039>.



================
Comment at: llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp:1275-1278
+  DwarfCompileUnit *ContextCU = CUMap.lookup(SP->getUnit());
+  DIE *ContextDIE = ContextCU->getOrCreateContextDIE(SP->getScope());
+  ContextCU = static_cast<DwarfCompileUnit *>(ContextDIE->getUnit());
+  return *ContextCU;
----------------
dblaikie wrote:
> Could you explain more about when/how/why these are ever different CUs? (when would the scope have a different CU from the subprogram itself)
Let's see `llvm/test/DebugInfo/Generic/cross-cu.ll`.
The first key point is that `beginModule` is executed before `beginFunctionImpl`.
The second key point is **the creation of the global** at `beginModule`.

Follow the creation chain of Global:

1. `!4 CU` via `global` create `!8 DIGlobalVariable`
2. `!4 CU` in `!8 DIGlobalVariable` via `type` create `!10 DICompositeType`
3. `!4 CU` in `!10` via `vtableHolder` create `!11`
4. `!4 CU` in `!11` via `baseType` create `!12` 
5. `!4 CU` in `!12` via `elements` create `!15=!{!16}`
6. `!4 CU` in `!16` via `baseType` create `!17`
7. `!4 CU` in `!17` via `templateParams` create `!19=!{!20}` 
8. `!4 CU` in `!20` via `type` create `!21`

Now `!21` belongs to `!4`!
But the `!23` is `distinct !DISubprogram(name: "alloc_impl", scope: !21, unit: !1)`.

The previous `llvm/test/DebugInfo/Generic/cross-cu-inlining-2.ll` and `llvm/test/DebugInfo/Generic/cross-cu-inlining-ranges.ll` were in a similar case.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D147620/new/

https://reviews.llvm.org/D147620



More information about the llvm-commits mailing list