stephenrkell / libdwarfpp

A high-level API for accessing DWARF debugging information, in C++
http://www.cl.cam.ac.uk/~srk31/
Other
23 stars 12 forks source link

FDE empty when NOP only #20

Open RYDB3RG opened 3 years ago

RYDB3RG commented 3 years ago

Hi,

when an FDE contains only the initial instructions from CIE and NOPs otherwise, libdwarfpp's FDE won't contain any rows, but i would have expected the CIE row. Is this expected?

00013238 00000010 0001323c FDE cie=00000000 pc=00116ec0...00116ef2
  Format:       DWARF32
  DW_CFA_nop:
  DW_CFA_nop:
  DW_CFA_nop:

  0x116ec0: CFA=RSP+8: RIP=[CFA-8]

with CIE:

00000000 00000014 00000000 CIE
  Format:                DWARF32
  Version:               1
  Augmentation:          "zR"
  Code alignment factor: 1
  Data alignment factor: -8
  Return address column: 16
  Augmentation data:     1B

  DW_CFA_def_cfa: RSP +8
  DW_CFA_offset: RIP -8
  DW_CFA_nop:
  DW_CFA_nop:

  CFA=RSP+8: RIP=[CFA-8]
stephenrkell commented 3 years ago

Thanks for this. That looks like a real bug.

In fact I have a vague memory of having fixed this in some tree or other, but maybe not having pushed it here yet. I'm doing some cleanups this summer which should find that tree if it exists. Though a patch is welcome if you happen to have one ready. If I don't update this issue in the next ~8 weeks, we can assume I don't in fact have a fix currently.

RYDB3RG commented 3 years ago

I was looking at the code, trying to fix it I was wondering if a fix would be to just use initial_result as final_result in such case in: https://github.com/stephenrkell/libdwarfpp/blob/master/src/frame.cpp#L776-L787

but then I wasnt sure how to deal with this unfinished_row stuff here: https://github.com/stephenrkell/libdwarfpp/blob/master/src/frame.cpp#L785

stephenrkell commented 3 years ago

As far as I remember, unfinished_row is just the state left behind by whatever instructions we have processed without moving to a new address. That may be the state from interpreting the CIE instructions, if the FDE ones never advance the program counter.

So maybe the right fix is just to delete the guard if (final_result.rows.size() > 0) and unconditionally add the final row?

Haven't tried it myself, but I am getting closer....