This is an archive of the discontinued LLVM Phabricator instance.

Add a LineTable class to GSYM and test it.
ClosedPublic

Authored by clayborg on Aug 22 2019, 10:22 AM.

Details

Summary

The full GSYM patch started with: https://reviews.llvm.org/D53379

This patch adds the ability to create a gsym::LineTable object, populate it, encode and decode it and test all functionality.

The full format of the LineTable encoding is specified in the header file LineTable.h.

Diff Detail

Event Timeline

clayborg created this revision.Aug 22 2019, 10:22 AM
clayborg updated this revision to Diff 218961.Sep 5 2019, 11:50 AM
clayborg retitled this revision from Add a LineTable class and test it. to Add a LineTable class to GSYM and test it..

Add full error handling to encoding and decoding in the same way that I did it in https://reviews.llvm.org/D66600.

Does anyone have a chance to look at this? Full documentation on the line table encoding is in the LineTable.h header file in the comments.

aprantl added inline comments.Sep 9 2019, 3:28 PM
include/llvm/DebugInfo/GSYM/FunctionInfo.h
47

I know I'm asking this at every patch, but: Why isn't this an Optional<LineTable> and why does it have to have a clear() method?

lib/DebugInfo/GSYM/LineTable.cpp
6

Wrong license.

19

I think the LTOC_ prefix is redundant?

36

LLVM wants camel case

124

Could this return an Expected<LineTable> instead?

clayborg marked 3 inline comments as done.Sep 10 2019, 6:30 PM
clayborg added inline comments.
include/llvm/DebugInfo/GSYM/FunctionInfo.h
47

If LineTable and Inline are optional is really complicated the operator == and operator < functions. Also we populate a FunctionInfo object from debug info so it is nice to just use the objects that are in the FunctionInfo and not have to make a temp and move it into the FunctionInfo object. So it was to keep the code simpler. If you really want the optionals here I can add them, but it does make the operator functions less readable and harder to implement.

lib/DebugInfo/GSYM/LineTable.cpp
19

will remove.

124

This is the encoding function. It takes an existing LineTable objects and encodes it. The decode function is static and does return a Expected<LineTable>. So we only need an error back if it fails to encode right?

clayborg updated this revision to Diff 219649.Sep 10 2019, 6:32 PM
  • Fixed license on LineTable.h/.cpp
  • Fixed camel case on encode_special
  • Remote LTOC_ prefix from LineTableOpCode enumerators
clayborg marked 3 inline comments as done.Sep 10 2019, 6:32 PM
aprantl added inline comments.Sep 11 2019, 9:28 AM
include/llvm/DebugInfo/GSYM/FunctionInfo.h
47

If LineTable and Inline are optional is really complicated the operator == and operator < functions.

operator== should fall out automatically out of Optional's operator== implementation, same for operator<.

Also we populate a FunctionInfo object from debug info so it is nice to just use the objects that are in the FunctionInfo and not have to make a temp and move it into the FunctionInfo object.

Are you worried about an extra copy operation? Couldn't you still construct it in-place through RVO?

My meta point here is that we have an abstraction for things that may be invalid in LLVM (and C++17) and that is Optional. When classes roll their own implementation of Optional via isValid() methods then users of these objects need to know about it and will almost inevitably forget the check validity at some point in the future, whereas Optional forces them to think about this when they write code that uses the class.

clayborg updated this revision to Diff 219748.Sep 11 2019, 11:13 AM
clayborg marked an inline comment as done.

Switch LineTable and InlineInfo inside of FunctionInfo to be Optional<T>.

aprantl accepted this revision.Sep 11 2019, 1:01 PM

Thanks!

include/llvm/DebugInfo/GSYM/FunctionInfo.h
70

Obviously it would be great if FunctionInfo itself could also be all-or-nothing (ie.. Optional).

lib/DebugInfo/GSYM/LineTable.cpp
226

.

230

.

232

. (etc)

This revision is now accepted and ready to land.Sep 11 2019, 1:01 PM
clayborg closed this revision.Sep 11 2019, 1:49 PM

$ svn commit
Sending include/llvm/DebugInfo/GSYM/FunctionInfo.h
Adding include/llvm/DebugInfo/GSYM/LineTable.h
Sending lib/DebugInfo/GSYM/CMakeLists.txt
Sending lib/DebugInfo/GSYM/FunctionInfo.cpp
Adding lib/DebugInfo/GSYM/LineTable.cpp
Sending unittests/DebugInfo/GSYM/GSYMTest.cpp
Transmitting file data ......done
Committing transaction...
Committed revision 371657.

include/llvm/DebugInfo/GSYM/FunctionInfo.h
47

Sounds good. I will make the changes.

This broke the build for me locally:

In file included from /home/keno/llvm-project/llvm/lib/DebugInfo/GSYM/FunctionInfo.cpp:10:0:
/home/keno/llvm-project/llvm/include/llvm/DebugInfo/GSYM/FunctionInfo.h:36:29: error: declaration of ‘llvm::Optional<llvm::gsym::LineTable> llvm::gsym::FunctionInfo::LineTable’ [-fpermissive]
   llvm::Optional<LineTable> LineTable;
                             ^~~~~~~~~
In file included from /home/keno/llvm-project/llvm/include/llvm/DebugInfo/GSYM/FunctionInfo.h:14:0,
                 from /home/keno/llvm-project/llvm/lib/DebugInfo/GSYM/FunctionInfo.cpp:10:
/home/keno/llvm-project/llvm/include/llvm/DebugInfo/GSYM/LineTable.h:118:7: error: changes meaning of ‘LineTable’ from ‘class llvm::gsym::LineTable’ [-fpermissive]
 class LineTable {
       ^~~~~~~~~
[720/3364] Building CXX object lib/Analysis/CMakeFiles/LLVMAnalysis.dir/ScalarEvolution.cpp.o