<table border="1" cellspacing="0" cellpadding="8">
    <tr>
        <th>Issue</th>
        <td>
            <a href=https://github.com/llvm/llvm-project/issues/57040>57040</a>
        </td>
    </tr>

    <tr>
        <th>Summary</th>
        <td>
            [llvm-debuginfo-analyzer] Weird output of `--compare`
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            new issue
      </td>
    </tr>

    <tr>
      <th>Assignees</th>
      <td>
      </td>
    </tr>

    <tr>
      <th>Reporter</th>
      <td>
          aheejin
      </td>
    </tr>
</table>

<pre>
    Hello. Thank you for making this tool available for LLVM!

I downloaded + applied all patches uploaded in Phabricator and tried to follow the user guide, and I have some questions. I'm following "Comparison Mode" section of `llvm-debuginfo-analyzer.rst`.

I built `test.cpp` with both g++ and clang++ instructed in the section. This is `test.cpp`, which is the same code in the instruction:
```cpp
using INTPTR = const int *;
int foo(INTPTR ParamPtr, unsigned ParamUnsigned, bool ParamBool) {
  if (ParamBool) {
    typedef int INTEGER;
    const INTEGER CONSTANT = 7;
    return CONSTANT;
  }
  return ParamUnsigned;
}
```

This is how I built the object files:
```
$ g++ -c -g -O0 test.cpp -o test-dwarf-gcc.o
$ clang++ -c -g -O0 test.cpp -o test-dwarf-clang.o
```

These are my clang++ and g++ versions:
```
$ g++ --version
g++ (Debian 11.3.0-3) 11.3.0
Copyright (C) 2021 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

$ clang++ --version
clang version 14.0.6
Target: x86_64-unknown-linux-gnu
Thread model: posix
```

---

This is the analyzer's output on each of the object files, separately:
```
$ llvm-debuginfo-analyzer --attribute=level --print=symbols,types test-dwarf-gcc.o

Logical View:
[000]           {File} 'test-dwarf-gcc.o'

[001]             {CompileUnit} 'test.cpp'
[002]     1         {TypeAlias} 'INTPTR' -> '* const int'
[002]     2         {Function} extern not_inlined 'foo' -> 'int'
[003]                 {Parameter} 'ParamBool' -> 'bool'
[003]                 {Parameter} 'ParamPtr' -> 'INTPTR'
[003]                 {Parameter} 'ParamUnsigned' -> 'unsigned int'
[003]                 {Block}
[004]     4             {TypeAlias} 'INTEGER' -> 'int'
[004]     5             {Variable} 'CONSTANT' -> 'const INTEGER'

$ llvm-debuginfo-analyzer --attribute=level --print=symbols,types test-dwarf-clang.o

Logical View:
[000]           {File} 'test-dwarf-clang.o'

[001]             {CompileUnit} 'test.cpp'
[002]     1         {TypeAlias} 'INTPTR' -> '* const int'
[002]     2         {Function} extern not_inlined 'foo' -> 'int'
[003]                 {Block}
[004]     5             {Variable} 'CONSTANT' -> 'const INTEGER'
[003]     2           {Parameter} 'ParamBool' -> 'bool'
[003]     2           {Parameter} 'ParamPtr' -> 'INTPTR'
[003]     2           {Parameter} 'ParamUnsigned' -> 'unsigned int'
[003]     4           {TypeAlias} 'INTEGER' -> 'int'
```
It looks gcc lacks debug info compared to clang. So the output here is little different from what the instruction expects, but I think that's fine and this is not what I'd like to ask about.

---

Then I ran the comparison mode as instructed in "Logical View" section:
```
$ llvm-debuginfo-analyzer --attribute=level --compare=types --report=view --print=symbols,types test-dwarf-clang.o test-dwarf-gcc.o

Reference: 'test-dwarf-clang.o'
Target:    'test-dwarf-gcc.o'

Logical View:
 [000]           {File} 'test-dwarf-clang.o'

 [001]             {CompileUnit} 'test.cpp'
-[002]     1         {TypeAlias} 'INTPTR' -> '* const int'
-[002]     2         {Function} extern not_inlined 'foo' -> 'int'
 [003]                 {Block}
 [004]     5             {Variable} 'CONSTANT' -> 'const INTEGER'
 [003]     2           {Parameter} 'ParamBool' -> 'bool'
 [003]     2           {Parameter} 'ParamPtr' -> 'INTPTR'
 [003]     2           {Parameter} 'ParamUnsigned' -> 'unsigned int'
-[003]     4           {TypeAlias} 'INTEGER' -> 'int'
+[002]     2         {Function} extern not_inlined 'foo' -> 'int'
 [003]                 {Parameter} 'ParamBool' -> 'bool'
 [003]                 {Parameter} 'ParamPtr' -> 'INTPTR'
 [003]                 {Parameter} 'ParamUnsigned' -> 'unsigned int'
 [003]                 {Block}
+[004]     4             {TypeAlias} 'INTEGER' -> 'int'
 [004]     5             {Variable} 'CONSTANT' -> 'const INTEGER'
+[002]     1         {TypeAlias} 'INTPTR' -> '* const int'
```

This looks weird. Both files have `[002]     2         {Function} extern not_inlined 'foo' -> 'int'` line but somehow it is prepended with `-` in one line and `+` with another. Also `test-dwarf-clang.o` has more debug info on `{Parameter}` lines, but they are not listed as differences, i.e., not prepended with `+` or `-`.

---

And then I ran the commands in "Logical Elements" section:
```
$ llvm-debuginfo-analyzer --attribute=level --compare=types --report=list --print=symbols,types,summary test-dwarf-clang.o test-dwarf-gcc.o

Reference: 'test-dwarf-clang.o'
Target:    'test-dwarf-gcc.o'

(1) Missing Scopes:
-[002]     2     {Function} extern not_inlined 'foo' -> 'int'

(2) Missing Types:
-[003]     4     {TypeAlias} 'INTEGER' -> 'int'
-[002]     1     {TypeAlias} 'INTPTR' -> '* const int'

(1) Added Scopes:
+[002]     2     {Function} extern not_inlined 'foo' -> 'int'

(2) Added Types:
+[002]     1     {TypeAlias} 'INTPTR' -> '* const int'
+[004]     4     {TypeAlias} 'INTEGER' -> 'int'

----------------------------------------
Element   Expected    Missing      Added
----------------------------------------
Scopes           4          1          1
Symbols          0          0          0
Types            2          2          2
Lines            0          0          0
----------------------------------------
Total            6          3          3
```

It's very confusing here. As I noted, `[002]     2     {Function} extern not_inlined 'foo' -> 'int'` line is not different in the two files, but it is listed in both "Missing Scopes" and "Added Scopes" section. Also `[002]     1     {TypeAlias} 'INTPTR' -> '* const int'` line also occurs in the both files but listed in both "Missing Types" and "Added Types" section.

---

A few more unrelated misc. questions: I'd like to know how high/low the debug info coverage is and any gaps or missing debug info, and I tried `--attribute=coverage,gaps`, but not sure if I am doing it correctly.
```
llvm-debuginfo-analyzer --attribute=coverage,gaps --print=all test.o
```
I tried something like this but I couldn't find the relevant info. It's possible that I just don't know how to use the tool. Is this a correct way of getting this information?

Thank you!
cc @CarlosAlbertoEnciso
</pre>
<img width="1px"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