Bug 16481

Summary: Python finish breakpoint does not work with a mix of inlined and tailcalled functions
Product: gdb Reporter: Simon Marchi <simon.marchi>
Component: pythonAssignee: Not yet assigned to anyone <unassigned>
Status: RESOLVED FIXED    
Severity: normal CC: ssbssa
Priority: P2    
Version: HEAD   
Target Milestone: 15.1   
Host: Target:
Build: Last reconfirmed:
Project(s) to access: ssh public key:

Description Simon Marchi 2014-01-21 22:51:46 UTC
This may seem a little far fetched, but I hit this while trying to track memory allocations with a python script. I put a Python breakpoint on __libc_malloc, which in turn sets a finish breakpoint so that I can get the pointer to the allocated region. I noticed that some times, the finish breakpoint is never hit.

I put up a very simple test case here:
  https://gist.github.com/simark/8548964

Compile with
  $ gcc -g test.c -O3

Run with
  $ gdb -x finish.py a.out

As the name describe, hopefully_inlined is inlined, hopefully_tailcalled is tailcalled (did I just invent a verb?).

The python script sets a breakpoint on the hopefully_notinlined function, which instanciantes a finish breakpoint. On exit of the function, we should see "I am here", but we don't.

I diagnosed the problem, and something wrong seems to happen here:
  https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;a=blob;f=gdb/breakpoint.c;h=c8e7e8842e2ed418d78b23c466018c88bb5e2aae;hb=HEAD#l5172

From what I understand, for kinds of breakpoints where it makes sens, GDB checks that the current stack frame is the same as when the breakpoint was set. For the breakpoint to cause a stop, they have to match. The comparison in this case returns false. One of the frames has its artifical_depth to zero while the other has it to one. I am not sure which one is right, but I think that they should be equal...
Comment 1 Hannes Domani 2023-12-15 19:59:08 UTC
I didn't know about this bug report, but I fixed this a few days ago with this commit:
https://sourceware.org/git/?p=binutils-gdb.git;a=commit;h=80ffe7226459e3edf840d0c23462d93cb560d2de