Skip to content

Errata: Chapter 12, Debug Information: conversion from file_addr to uint64_t in die::high_pc #39

@danilopiazza

Description

@danilopiazza

Chapter: 12
Description: In the Extracting DIE Address Ranges section, Contiguous subsection on page 321, there is a possible type conversion error in high_pc; as_address returns a file_addr, which is being assigned to an uint64_t:

std::uint64_t addr;
if (attr.form() == DW_FORM_addr) {
    addr = attr.as_address();
}
else {
    addr = low_pc() + attr.as_int();
}

Reproduction steps: Building the project after completing the Contiguous subsection results in the following compile errors:

sdb/src/dwarf.cpp: In member function ‘sdb::file_addr sdb::die::high_pc() const’:
sdb/src/dwarf.cpp:390:31: error: cannot convert ‘sdb::file_addr’ to ‘uint64_t’ {aka ‘long unsigned int’} in assignment
  390 |         addr = attr.as_address();
      |                ~~~~~~~~~~~~~~~^~
      |                               |
      |                               sdb::file_addr
sdb/src/dwarf.cpp:393:25: error: cannot convert ‘sdb::file_addr’ to ‘uint64_t’ {aka ‘long unsigned int’} in assignment
  393 |         addr = low_pc() + attr.as_int();
      |                ~~~~~~~~~^~~~~~~~~~~~~~~
      |                         |
      |                         sdb::file_addr

This gets fixed on page 329, when high_pc is updated to account for range lists.

A possible fix for page 321,following how the function is implemented on page 329, would be:

 sdb::file_addr sdb::die::high_pc() const {
     auto attr = (*this)[DW_AT_high_pc];
-    std::uint64_t addr;
     if (attr.form() == DW_FORM_addr) {
-        addr = attr.as_address();
+        return attr.as_address();
     }
     else {
-        addr = low_pc() + attr.as_int();
+        return low_pc() + attr.as_int();
     }
-    return file_addr{
-        *cu_->dwarf_info()->elf_file(),
-        addr
-    };
 }

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions