Bug 30929

Summary: 'frame function' fails when call is the last instruction
Product: gdb Reporter: Alexander Monakov <amonakov>
Component: backtraceAssignee: Not yet assigned to anyone <unassigned>
Status: NEW ---    
Severity: normal CC: tromey
Priority: P2    
Version: unknown   
Target Milestone: ---   
Host: Target:
Build: Last reconfirmed: 2023-10-01 00:00:00
Bug Depends on:    
Bug Blocks: 8416    

Description Alexander Monakov 2023-10-01 15:51:45 UTC
int main()
{
        __builtin_abort();
}

gcc -g test.c

gdb ./a.out

(gdb) start
Temporary breakpoint 1 at 0x40113a: file t.c, line 3.

Temporary breakpoint 1, main () at t.c:3
3               __builtin_abort();
(gdb) f f main
#0  main () at t.c:3
3               __builtin_abort();
(gdb) c
Continuing.

Program received signal SIGABRT, Aborted.
0x00007ffff7e4d47c in __pthread_kill_implementation () from /lib64/libc.so.6
(gdb) bt
#0  0x00007ffff7e4d47c in __pthread_kill_implementation () from /lib64/libc.so.6
#1  0x00007ffff7dfae16 in raise () from /lib64/libc.so.6
#2  0x00007ffff7de389c in abort () from /lib64/libc.so.6
#3  0x000000000040113f in main () at t.c:3
(gdb) f f main
No frame for function "main".


Compiling to an intermediate assembly file and adding a nop after 'call abort' is sufficient to make it work. Apparently 'frame function' doesn't work in the corner case when return address is exactly past the end of a function (the last instruction was a call).

In practice this breaks the following snippet:

catch signal SIGABRT
commands
f f __assert_fail
up
end

which is supposed to automatically select the frame of the failing assert.
Comment 1 Tom Tromey 2023-10-01 16:40:48 UTC
Can you try git master gdb?
I suspect this is a dup of bug#29074.

If not, then it is probably another instance of bug#8416 -
same idea, just need to track down the spot with the incorrect call.
Comment 2 Alexander Monakov 2023-10-01 17:13:03 UTC
No, I don't have a git build of GDB. The instructions should be straightforward to follow for any active GDB developer (who presumably has a git build at hand).
Comment 3 Tom Tromey 2023-10-06 12:33:26 UTC
Confirmed.