[Dwarf-Discuss] Why "DW_LNS_advance_pc" is needed and when it be generated ?

Cary Coutant ccoutant@gmail.com
Thu Aug 7 06:43:30 GMT 2008


> I am working a compiler bug that relative to DW_LNS_advance_pc. In  
> the piece
> of C language code of "switch/case", when I send "next" to gdb for the
> compiled binaray (with -g option) on statement "switch (n)", the PC  
> move to
> next function that defined next to the "switch/case" function.
>
> When I compare the line number information with the gcc output. I  
> found
> there are extra "Advance PC by 36 to 214170" statement in Line Number
> Statements at the end of the "switch/case" function.
>
> I wonder when and why the statement is generated.  As far as I know,  
> the
> compiler only generate ".loc " in ".s" file. Then how and when the  
> "as"
> translates it. Also, why "DW_LNS_advance_pc" is needed and when it be
> generated.


Normally, the DWARF line number program can encode a small PC  
increment and a small source line number increment in a single-byte  
special opcode. There are only about 240 or so such special opcodes,  
and depending on the line_base, line_range, and opcode_base parameters  
in the line number program header, these special opcodes are capable  
of representing combinations of increments only within certain bounds.

If, for example, opcode_base is 13, line_base is -2, and line_range is  
5 (allowing special opcodes to represent line number deltas between -2  
and +2), then the largest PC increment that can be represented in a  
special opcode is (255 - 13) / 5 = ~48.

The DW_LNS_advance_pc opcode is needed when the gap between two PC  
values in the line number table exceeds that maximum increment  
available with special opcodes. This can happen when the code  
generated for a particular source line is large, or it could happen if  
the compiler drops a big jump table into the middle of the code.  
Generally in such cases, you'll see a DW_LNS_advance_pc to move the PC  
forward part or all of the way followed by a special opcode that  
covers both the remaining PC increment and the source line number  
increment. If there's a large increment in the line number, too, you  
may also see a DW_LNS_advance_line.

The assembler generates these opcodes automatically based on the .loc  
directives in the source. I'd think it's unlikely that this is your  
problem.

-cary





More information about the Dwarf-discuss mailing list