[PATCH] D28581: Change DWARFDie::getAttributeValue() to DWARFDie::find(), add DWARFDie::findRecurse() and dwarf::toString() helper functions.

Greg Clayton via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Jan 11 15:33:52 PST 2017


clayborg added a comment.

I do kind of agree with Adrian that this new code isn't as readable (see the "CallFile =" code...).

If we return a DWARFFormValue that is potentially invalid we would get:

  void DWARFDie::getCallerFrame(uint32_t &CallFile, uint32_t &CallLine,
                                uint32_t &CallColumn) const {
    CallFile = find(DW_AT_call_file).toUnsigned(0);
    CallLine = find(DW_AT_call_line).toUnsigned(0);
    CallColumn = find(DW_AT_call_column).toUnsigned(0);
  }



================
Comment at: include/llvm/DebugInfo/DWARF/DWARFFormValue.h:187
+  inline const char*
+  toString(const Optional<DWARFFormValue>& V, const char *Default) {
+    if (V) {
----------------
This code:

```
void DWARFDie::getCallerFrame(uint32_t &CallFile, uint32_t &CallLine,
                              uint32_t &CallColumn) const {
  CallFile = getAttributeValueAsUnsignedConstant(DW_AT_call_file).getValueOr(0);
  CallLine = getAttributeValueAsUnsignedConstant(DW_AT_call_line).getValueOr(0);
  CallColumn =
      getAttributeValueAsUnsignedConstant(DW_AT_call_column).getValueOr(0);
}
```

would become:

```
void DWARFDie::getCallerFrame(uint32_t &CallFile, uint32_t &CallLine,
                              uint32_t &CallColumn) const {
  CallFile = toUnsigned(find(DW_AT_call_file), 0);
  CallLine = toUnsigned(find(DW_AT_call_line, 0);
  CallColumn = toUnsigned(find(DW_AT_call_column, 0);
}
```



https://reviews.llvm.org/D28581





More information about the llvm-commits mailing list