plasma-umass / coz

Coz: Causal Profiling

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

coz does not start: terminate called after throwing an instance of 'std::out_of_range'

hunger opened this issue · comments

I have a litte rust program that I wanted to use coz with. It builds and runs fine without coz (using the arguments "--some --arguments").

Starting it with

coz run --- target/release/program --some --arguments

That gets me the following output:

[libcoz.cpp:100] bootstrapping coz
[libcoz.cpp:128] Including MAIN, which is /full/path/target/release/program

followed by lots of lines similar to this one:

[inspect.cpp:525] Included source file /rustc/6ef275e6c3cb1384ec78128eceeb4963ff788dca/src/libcore/unicode/tables.rs

Then the execution terminates with this message:

terminate called after throwing an instance of 'std::out_of_range'
  what():  file name index 23 exceeds file table size of 11

This is using coz from git with SHA: 5e0550c

Any ideas?

Here is the upstream libelfin issue: aclements/libelfin#40

@ArniDagur : I am not sure whether this is a bug in coz or libelfin yet.

AFAICT libelfin never calls get_file(...). So libcoz might just get the index wrong or something that it passes to libelfin, in which case libelfin is doing exactly what it should do.

Line 385 in libcoz/inspect.cc triggers this issue:

decl_file = table.get_file(decl_file_val.as_uconstant())->path;

decl_file_val is found via find_attribute. find_attribute does something that looks a bit similar to what die::resolve does in libelfin (should elfin's method get used here?) and will check child dies for the actual values when applicable.

When this crashes, decl_file_val is taken from the DW_AT::abstract_origin die.

Is the line_table maybe specific to one die? Then coz would use the wrong line_table for the die the value is actually taken from.

From all I know line_tables are compilation unit specific. So let's add some debugging output to find_attribute(...) and let's check whether the units of the die that returned the value matches up
with the die that was passed into find_attributes:

  try {
    if(d.has(attr)) {
      WARNING << "find_attribute: Found in die!";
      return d[attr];
    }

    if(d.has(dwarf::DW_AT::abstract_origin)) {
      const dwarf::die child = d.resolve(dwarf::DW_AT::abstract_origin).as_reference();
      dwarf::value v = find_attribute(child, attr);
      if(v.valid()) {
        if (&child.get_unit() != &d.get_unit())
             WARNING << "UNIT MISMATCH!";
        WARNING << "find_attribute: Found in abstract_origin die";
        return v;
      }
    }

I do get a lot of "UNIT MISMATCH!" warnings, one right before the exception is thrown.

To me it looks a lot like coz is using an index from one compilation unit to access the line_table from another unit.

I am on coz version 0.1.0-2 as provided on Ubuntu 18.04. And I am seeing the same error as above.

What fixed it for me, was to disable LTO.

I hope this is useful for others with a similar old version of coz.