On Sat, 24 Oct 2026 09:12:33 GMT, Dingli Zhang <[email protected]> wrote:

>> I have examined how GDB operates; this is not necessarily an authoritative 
>> conclusion.
>> 
>> GDB 18.1 follows this workflow:
>> 1. Read the original frame PC using get_frame_pc().
>> 2. Choose the lookup address using get_frame_address_in_block():
>>   - Ordinary caller return address → PC−1.
>>   - Top-frame or signal-restored execution PC → exact PC.
>> 3. Select the FDE using that lookup address.
>> 4. Interpret the CFI rules up to the same address, using fs->pc <= pc.
>> 
>> PC−1 is a lookup adjustment; it does not replace the original frame PC.
>> 
>> 
>> 
>> get_frame_address_in_block() // gdb/frame.c:2855–2904, see the comments
>> ...
>>  if ((get_frame_type (next_frame) == NORMAL_FRAME
>>       || get_frame_type (next_frame) == TAILCALL_FRAME)
>>      && (get_frame_type (this_frame) == NORMAL_FRAME
>>          || get_frame_type (this_frame) == TAILCALL_FRAME
>>          || get_frame_type (this_frame) == INLINE_FRAME))
>>    return pc - 1;
>> 
>>  return pc;
>> ...
>> 
>> dwarf2_frame_find_fde
>> 
>> execute_cfa_program
>> 
>> // The interpreter uses an inclusive comparison (gdb/dwarf2/frame.c:257)
>> while (insn_ptr < insn_end && fs->pc <= pc)
>> ...
>> 
>> 
>> My RISC-V implementation follows the same principle: exact PCs for 
>> top/signal-restored frames, and PC−1 lookup for ordinary native caller 
>> frames.
>
>> Thanks @yanglong1010 for sharing GDB implementation! I think it makes sense 
>> to follow this - using "PC - 1" in SA for both amd64 and aarrch64. However I 
>> think it is better to tackle in another issue. Could you file it and create 
>> PR after this? I'm happy to review it.
> 
> Thanks! That works for me.

Thanks @DingliZhang.

My patch modifies the shared `dwarf.cpp`, which could potentially affect 
existing behavior on amd64/aarch64. Since @YaSuenag suggested handling amd64 
and aarch64 in a separate issue, I see two possible ways to move forward with 
my patch:
1. Add architecture-specific macros to `dwarf.cpp` so that the inclusive PC 
condition applies only to riscv64.
2. Wait until the patch that changes amd64/aarch64 to a PC-selection mechanism 
similar to GDB’s are merged, and then merge my patch.

What do you think?

-------------

PR Comment: https://git.openjdk.org/jdk/pull/33374#issuecomment-6406742344

Reply via email to